Uboot.scr UBOOT SCRIPT

this is the script used to by u-boot in my image using the toradex bsp 6.7 on apalis imx8qm:

51+1 records in
51+1 records out
3285 bytes (3.3 kB, 3.2 KiB) copied, 0.000143364 s, 22.9 MB/s

SPDX-License-Identifier: GPL-2.0+ OR MIT

Copyright 2020 Toradex

Toradex boot script.

With Mender integration.

Only supports booting from mmc

if test ${devtype} = “ubi”; then
echo “This script is not meant to distro boot from raw NAND flash.”
exit
test -n ${m4boot} || env set m4boot ‘;’
test -n ${fdtfile} || env set fdtfile ${fdt_file}
test -n ${kernel_image} || env set kernel_image fitImage
test -n ${overlays_file} || env set overlays_file “overlays.txt”
test -n ${overlays_prefix} || env set overlays_prefix “overlays/”

Set dynamic commands

env set load_prefix ‘boot/’
env set load_cmd ‘load ${mender_uboot_root}’
env set load_cmd_boot ‘load ${mender_uboot_root}’
env set set_bootcmd_kernel ‘env set bootcmd_kernel “${load_cmd} \${kernel_addr_load} \${load_prefix}\${kernel_image}”’
env set set_load_overlays_file ‘env set load_overlays_file “${load_cmd_boot} \${loadaddr} \${overlays_file}; env import -t \${loadaddr} \${filesize}”’
env set fdt_resize ‘fdt addr ${fdt_addr_r} && fdt resize 0x20000’
env set set_bootcmd_dtb ‘env set bootcmd_dtb “echo Loading DeviceTree: \${fdtfile}; ${load_cmd} \${fdt_addr_r} \${load_prefix}\${fdtfile}”’
env set set_apply_overlays ‘env set apply_overlays “for overlay_file in \${fdt_overlays}; do echo Applying Overlay: \${overlay_file} && ${load_cmd_boot} \${loadaddr} \${overlays_prefix}\${overlay_file} && fdt apply \${loadaddr}; env set overlay_file; done; true”’
env set bootcmd_boot ‘echo “Bootargs: ${bootargs}” && booti ${kernel_addr_r} - ${fdt_addr_r}’
if test -n ${setup}; then
run setup
else
env set setupargs console=tty1 console=${console},${baudrate} consoleblank=0
if test ${kernel_image} = “fitImage”; then
env set kernel_addr_load ${ramdisk_addr_r}
env set bootcmd_unzip ‘;’
else
if test -n ${kernel_comp_addr_r}; then

use booti automatic decompression

env set kernel_addr_load ${loadaddr}
env set bootcmd_unzip ‘;’
else
if test ${kernel_image} = “Image.gz”; then
env set kernel_addr_load ${loadaddr}
env set bootcmd_unzip ‘unzip ${kernel_addr_load} ${kernel_addr_r}’
else
env set kernel_addr_load ${kernel_addr_r}
env set bootcmd_unzip ‘;’
fi
fi
env set rootfsargs_set ‘env set rootfsargs root=${mender_kernel_root} ro rootwait’
env set bootcmd_args ‘run rootfsargs_set && env set bootargs ${defargs} ${rootfsargs} ${setupargs} ${vidargs} ${tdxargs}’
if test ${skip_fdt_overlays} != 1; then
env set bootcmd_overlays ‘run load_overlays_file && run fdt_resize && run apply_overlays’
else
env set bootcmd_overlays true
env set bootcmd_prepare ‘run set_bootcmd_kernel; run set_bootcmd_dtb; run set_load_overlays_file; run set_apply_overlays’
env set bootcmd_run ‘run m4boot; run bootcmd_dtb && run bootcmd_overlays && run bootcmd_args && run bootcmd_kernel && run bootcmd_unzip && run bootcmd_boot; echo “Booting from ${devtype} failed!” && false’
env set bootcmd_run ‘run m4boot; run bootcmd_dtb && run bootcmd_overlays && run bootcmd_args && run bootcmd_kernel && run bootcmd_unzip && run bootcmd_boot; echo “Booting from ${devtype} failed!”’
run bootcmd_prepare
run mender_setup
run bootcmd_run

the script is from u-boot distro boot influenced by mender,so i want to know if this script can load a fit image, because the bootcmd_boot command is hardcoded to booti even if its a fitimage only the load adress changes

Hi, I’m the Toradex AI Assistant.

I might make mistakes or occasionally get you wrong. Our support team will step in if needed.


Based on your U-Boot script analysis, there’s an issue with the hardcoded booti command for FIT image support. Looking at the script logic, you’re correct that while the kernel load address changes for FIT images, the boot command remains booti (1).

Script Analysis

The script sets different load addresses based on image type:

if test ${kernel_image} = "fitImage"; then
    env set kernel_addr_load ${ramdisk_addr_r}
    env set bootcmd_unzip ';'

However, the bootcmd_boot command is hardcoded as:

env set bootcmd_boot 'echo "Bootargs: ${bootargs}" && booti ${kernel_addr_r} - ${fdt_addr_r}'

The Issue

For FIT images, U-Boot should use bootm instead of booti. The booti command is designed for raw kernel images, while bootm handles FIT images properly (1).

Solution

To properly support FIT images, the script should conditionally set the boot command based on the kernel image type. You would need to modify the script to use something like:

if test ${kernel_image} = "fitImage"; then
    env set bootcmd_boot 'echo "Bootargs: ${bootargs}" && bootm ${kernel_addr_r}'
else
    env set bootcmd_boot 'echo "Bootargs: ${bootargs}" && booti ${kernel_addr_r} - ${fdt_addr_r}'
fi

This would ensure that FIT images use the correct bootm command while maintaining booti for raw kernel images.

You can modify environment variables using the setenv command in U-Boot console to test this behavior before making permanent changes to your boot script (1).

Best regards, Toradex AI Assistant.


Did you like my answer? :+1: :-1:

If I answered your question, please tick the “Solution” checkbox.

For follow-up questions to me, please use @ToradexAI in your post.

Hi @anmsn44!

Sorry for the delayed response.

The answer given by Toradex AI seems to be a good starting point.
Were you able to resolve this issue?

Best regards.