Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run u-boot command at startup

Tags:

u-boot

yocto

I have a custom board running Yocto (Jethro) and would like to run a single u-boot command, preboot. Obviously, breaking the boot sequence with space and running it manually works. How do I get it to run automatically? More specifically, where is the startup command sequence, by default?

Edit: Also, I am aware I can edit the environment at runtime. However, I am trying to build this change into the image so I can distribute it.

like image 421
James Howard Avatar asked Sep 05 '25 03:09

James Howard


2 Answers

When you are in the uboot environment. Enter printenv, it will list the environment variables that uboot uses.

There is a variable name bootcmd. Currently, mine contain a bunch of if else command. Similarly, add your prefer function there for boot.

And after it is finished and tested. Use saveenv to store the edit

Here is a syntax for uboot.

Edit:

U-Boot allows to store commands or command sequences in a plain text file. Using the mkimage tool you can then convert this file into a script image which can be executed using U-Boot's autoscr command. U-boot Scripting Capabilities

like image 52
Charles C. Avatar answered Sep 07 '25 22:09

Charles C.


Typically, your U-Boot recipe will build U-Boot for a single machine, in that case, I'd normally just patch the compiled in, default, U-Boot environment to do the right thing. This is achieved by

 SRC_URI_machine += "file://mydefenv.patch"

Or (even better) use your own git tree. This would also have the additional benefit that your system might be able to boot up and to something useful, even if the environment would be totally corrupted.

Another possibility is to do it like Charles suggested in a comment to another answer, create an environment offline, and have U-Boot load it, see denx.de/wiki/view/DULG/UBootScripts

A third possibility, that I've also used sometimes, is to construct the environment offline (possibly using the same or a similar mechanism as in the link above), and the flash the environment to flash during the normal flash programming process. Though, most of the time I've done this on AT91's, using a tcl script similar to at91 Sam-Ba TCL script

No matter which method you chose, the bootcmd variable in U-Boot should hold your boot script.

like image 31
Anders Avatar answered Sep 08 '25 00:09

Anders