2022-01-23 08:15 AM
I am trying to customize the boot script which is used to boot my STM32MP157 Avenger96 board. I want to include some u-boot variables and alter the boot process.
Current boot script:
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
#New variables I want to include bootlimit rootfspart
setenv bootlimit 5
setenv rootfspart 4
setenv bootargs "${bootargs} root=PARTUUID=${uuid} rw rootwait consoleblank=0"
#Pass bootargs like this
setenv bootargs "${bootargs} root=/dev/mmcblk0p${rootfspart} rdinit=/bin/kinit rw single\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 the custom DTO loader script
#
# In case 'loaddtos' variable is set, then the 'fdt' command is already
# configured to point to a DT, on top of which all the DTOs present in
# the fitImage and selected by the 'loaddtos' are applied. Hence, the
# user is now free to apply any additional custom DTOs loaded from any
# other source.
#
# In case 'loaddtos' variable is not set, the 'loaddtoscustom' script
# must configure the 'fdt' command to point to the custom DT.
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 bootlimit and rootfspart to above script and also to pass bootargs
as setenv bootargs "${bootargs} root=/dev/mmcblk0p${rootfspart} rdinit=/bin/kinit rw single\0".
The config file is in include/configs/dh_stm32mp1.h
#ifndef __CONFIG_DH_STM32MP1_H__
#define __CONFIG_DH_STM32MP1_H__
#include <configs/stm32mp1.h>
#define CONFIG_BOOTCOUNT_LIMIT
#define CONFIG_BOOTCOUNT_ENV
#define CONFIG_SPL_TARGET "u-boot.itb"
#undef STM32MP_BOOTCMD
#define STM32MP_BOOTCMD "bootcmd_stm32mp=" \
"if run load_bootenv; then run importbootenv;fi;" \
"echo \"Boot over ${boot_device}${boot_instance}!\";" \
"if test ${boot_device} = serial || test ${boot_device} = usb;" \
"then stm32prog ${boot_device} ${boot_instance}; " \
"else " \
"run env_check;" \
"if test ${boot_device} = mmc;" \
"then env set boot_targets \"mmc${boot_instance}\"; fi;" \
"if test ${boot_device} = nand ||" \
" test ${boot_device} = spi-nand ;" \
"then env set boot_targets ubifs0; fi;" \
"run distro_bootcmd;" \
"fi;\0"
#undef CONFIG_EXTRA_ENV_SETTINGS
#define CONFIG_EXTRA_ENV_SETTINGS \
"bootdelay=1\0" \
"bootlimit=5\0" \
"rootfspart=4\0" \
"bootargs=root=/dev/mmcblk0p${rootfspart} rdinit=/bin/kinit rw single\0" \
"kernel_addr_r=0xc2000000\0" \
"fdt_addr_r=0xc4000000\0" \
"scriptaddr=0xc4100000\0" \
"pxefile_addr_r=0xc4200000\0" \
"splashimage=0xc4300000\0" \
"ramdisk_addr_r=0xc4400000\0" \
/*"altbootcmd=run bootcmd\0" \ */
"env_default=1\0" \
"env_check=if test $env_default -eq 1;"\
" then env set env_default 0;env save;fi\0" \
STM32MP_BOOTCMD \
BOOTENV \
"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" \
"boot_net_usb_start=true\0" \
"usb_pgood_delay=1000\0" \
"update_sf=" /* Erase SPI NOR and install U-Boot from SD */ \
"setexpr loadaddr1 ${loadaddr} + 0x1000000 && " \
"load mmc 0:4 ${loadaddr1} /boot/u-boot-spl.stm32 && " \
"env set filesize1 ${filesize} && " \
"load mmc 0:4 ${loadaddr} /boot/u-boot.itb && " \
"sf probe && sf erase 0 0x200000 && " \
"sf update ${loadaddr1} 0 ${filesize1} && " \
"sf update ${loadaddr1} 0x40000 ${filesize1} && " \
"sf update ${loadaddr} 0x80000 ${filesize} && " \
"env set filesize1 && env set loadaddr1\0" \
"load_bootenv="\
"usb stop; usb start; if load usb ${usbdev}:${usbpart} ${loadaddr} DHupdate.ini;" \
"then echo \"--> Update: found DHupdate.ini (${filesize} bytes)\"; fi;\0"\
"importbootenv=echo Importing environment from DHupdate.ini...; env import -t ${loadaddr} ${filesize}\0"\
"usbdev=0\0"\
"usbpart=1\0"
#endif
I have also included bootlimit and rootfspart and passed bootargs in above file. My question is:
Can anyone please let me know what am I doing wrong and how to make this work?
Your help will be much appreciated.
Thanks in advance.
P.S: I am new to U-boot and learning to use it. I am using Yocto as build system with Ubuntu 20.04. Please let me know if you need any further info.