Customize uboot to run an uboot command every time

I’m able to create a custom release of Torizon OS and I see that inside the image there is a file u-boot-initial-env-sd that contains a set of enviroment variables for u-boot.
Can I use this file to customize u-boot so that it executes a given command at every boot?
Or is a rebuild of uboot necessary to get this behavior?

Hi, I’m the Toradex AI Assistant. I’m in early beta, and I would appreciate your feedback.
The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


Certainly, if you wish to have U-Boot execute a specific command at every boot, modifying the u-boot-initial-env-sd file within your Torizon OS image is a viable approach. This file contains the default environment variables for U-Boot, and by altering it, you can change the behavior of U-Boot without needing to rebuild it.

To execute a given command at every boot, you can modify the bootcmd environment variable within the u-boot-initial-env-sd file to include your desired command. The bootcmd is executed by U-Boot automatically at boot time. By appending your command to the existing bootcmd value or creating a custom boot sequence that includes your command, you can achieve the desired behavior.

For example, if you want U-Boot to execute a custom command such as my_custom_command at every boot, you would modify the bootcmd like so:

setenv bootcmd 'run my_custom_command; run original_bootcmd'

In this example, my_custom_command is your custom command, and original_bootcmd represents the original boot command sequence that U-Boot was configured to execute. Ensure to replace my_custom_command with the actual command you wish to execute and original_bootcmd with the original bootcmd content if you’re appending to it.

Remember, after modifying the u-boot-initial-env-sd file, you should use the TorizonCore Builder tool or the Toradex Easy Installer to deploy your modified Torizon OS image to your device.

This method allows you to customize the boot process without the complexity of rebuilding U-Boot, making it suitable for both development and production purposes, provided the changes are tested thoroughly.

Best regards, Toradex AI Assistant

Please, also check if these links can help you solve your problem:

Device Tree Technical Overview | Toradex Developer Center.

I tested, adding

run mw.l 0x303d0474 0x0f

but I see that the register value has not changed.
If I set it manually from the uboot console it works.

What can be the reason?

run is meant to invoke commands from the contents of a variable, e.g. if you have an environment variable my_var in u-boot set to mw.l ... then run my_var will execute the mw.l command.

If you are providing the command directly, then the run directive is not needed.

hi @bw908
I haven’t explain very well what I did.
In u-boot-initial-env-sd there is
bootcmd=run m4boot; run bootcmd_mmc2
and I chaged it into
bootcmd=run mw.l 0x303d0474 0x0f; run m4boot; run bootcmd_mmc2

Is this ok?

Try
bootcmd=mw.l 0x303d0474 0x0f; run m4boot; run bootcmd_mmc2
instead.

in your case, m4boot and bootcmd_mmc2 are u-boot variables containing other commands and this is why they need the run directive. mw.l ... is not a variable but a direct command and therefore run is not required (and will not work).

1 Like

Thanks @bw908 for helping here! Your suggestions sound about right. Did this help you @vix ?

1 Like