2 years ago

#60202

test-img

Preeti

Configure U-boot using Yocto

I am new to U-boot and trying to modify some configuration in the U-boot. I am using STM32MP1 based Avenger96 boiard with Yocto Project and U-boot bootloader. Now I want to modify some U-boot variables like bootcount and bootlimit. For example I want to set bootlimit variable to 4 and if limit is reached, u-boot should run the altbootcmd instead of usual bootcmd.

To make this work I need to edit CONFIG_EXTRA_ENV_SETTINGS statement in the u-boot sources. But I am not sure how to find the location of this file to be modified.

After spending some time to know about boot process to bring up the board I got to know that it uses boot.cmd file. It contains:

if test -n "${distro_bootpart}"; then
  setenv partition "${distro_bootpart}"
else
  setenv partition "${bootpart}"
fi

if test ! -e ${devtype} ${devnum}:${partition} boot/fitImage; then
  echo "This boot medium does not contain a suitable fitImage file   for this system."
  echo "devtype=${devtype} devnum=${devnum} partition=${partition}     loadaddr=${loadaddr}"
  echo "Aborting boot process."
  exit 1
fi

part uuid ${devtype} ${devnum}:${partition} uuid

# Some STM32MP1-based systems do not encode the baudrate in the  console variable
if test "${console}" = "ttySTM0" && test -n "${baudrate}"; then
  setenv console "${console},${baudrate}"
fi

if test -n "${console}"; then
  setenv bootargs "${bootargs} console=${console}"
fi

setenv bootargs "${bootargs} root=PARTUUID=${uuid} rw rootwait   consoleblank=0"

load ${devtype} ${devnum}:${partition} ${loadaddr} boot/fitImage
if test $? != 0 ; then
  echo "Failed to load fitImage file for this system from boot  medium."
  echo "devtype=${devtype} devnum=${devnum}  partition=${partition} loadaddr=${loadaddr}"
  echo "Aborting boot process."
  exit 2
fi

# A custom script exists to load DTOs
if test -n "${loaddtoscustom}" ; then
  # Pull DTOs from fitImage and manually apply them to base DT
  if test -n "${loaddtos}" ; then
    # Matches UBOOT_DTB_LOADADDRESS in OE layer machine config
    setexpr loadaddrdtb 0xcff00000
    # Matches UBOOT_DTBO_LOADADDRESS in OE layer machine config
    setexpr loadaddrdtbo 0xcff80000

    setexpr loaddtossep gsub '#conf' ' fdt' "${loaddtos}"
    setexpr loaddtb 1

    for i in ${loaddtossep} ; do
      if test ${loaddtb} = 1 ; then
        echo "Using base DT ${i}"
        imxtract ${loadaddr} ${i} ${loadaddrdtb} ;
        fdt addr ${loadaddrdtb}
        fdt resize
        setenv loaddtb 0
      else
        echo "Applying DTO ${i}"
        imxtract ${loadaddr} ${i} ${loadaddrdtbo} ;
        fdt apply ${loadaddrdtbo}
      fi
    done

    setenv loaddtb
    setenv loaddtossep
    setenv loadaddrdtbo
    setenv loadaddrdtb
  fi

  run loaddtoscustom
  if test -z "${bootm_args}" ; then
    setenv bootm_args "${loadaddr} - ${fdtaddr}"
  fi
else
  setenv bootm_args "${loadaddr}${loaddtos}"
fi

echo "Booting the Linux kernel..." \
&& bootm ${bootm_args}

Now I want to add something like

bootlimit=5\0" \
rootfspart=4\0" \
bootargs=root=/dev/mmcblk0p${rootfspart} rdinit=/bin/kinit rw  single\0" \
 altbootcmd=" \
   echo Rollback to previous RootFs; "
   if test ${rootfspart} = 4; " \
     then setenv rootfspart 5; " \
   else " \
      setenv rootfspart 4; " \
   fi; setenv bootcount 0; saveenv; " \
   bootcmd\0" \

Can anyone please let me know how can I achieve this? Do I need to create a config fragment to the u-boot recipe or do I need to add patch file? Or is there a better way to implement?

Please let me know if further details are required.

Your help will be much appreciated.

Thanks in advance.

embedded-linux

yocto

u-boot

0 Answers

Your Answer

Accepted video resources