Custom Scripts in U-Boot

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Custom Scripts in U-Boot

Custom Scripts in U-Boot

Hello there.

Here is a good way to use U-boot in an efficient way with custom scripts.

The bootscript is an script that is automatically executed when the boot loader starts, and before
the OS auto boot process.
The bootscript allows the user to execute a set of predefined U-Boot commands automatically
before proceeding with normal OS boot. This is especially useful for production environments and
targets which don’t have an available serial port for showing the U-Boot monitor.

This information can be find in U-Boot Reference Manual.

 

I will take the example load a binary file in CORTEX M4 of IMX8MM-EVK.

In my case, I have the binary file in MMC 2:1 called gpio.bin and I will skip those steps because that is not the goal.

 

First, you need the u-boot-tools installed in your Linux machine:

sudo apt install u-boot-tools

 

That package provide to us the tool mkimage to convert a text file (.src, .txt) file to a bootscript file for U-Boot.

 

Now, create your custom script, in this case a simple script for load binary file in Cortex M4:

nano mycustomscript.scr

 and write your U-Boot commands:

fatload mmc 2:1 0x80000000 gpio.bin
cp.b 0x80000000 0x7e0000 0x10000
bootaux 0x7e0000
Alejandro_Salas_0-1705729663162.png

 

Now we can convert the text file to bootscript with mkimage.

Syntax:

mkimage -T script -n "Bootscript" -C none -d <input_file> <output_file>

mkimage -T script -n "Bootscript" -C none -d mycustomscript.scr LCM4-bootscript

 

This will create a file called LCM4-bootscript (Or as your called it).
 

A way to load this bootscript file to U-Boot is using the UUU tool, in U-Boot set the device in fastboot with command:

u-boot=> fastboot 0

Then in linux with the board connected through USB to PC run the command:

sudo uuu -b fat_write LCM4-bootscript mmc 2:1 LCM4-bootscript

 

Now we have our bootscript in U-Boot in MMC 2:1.

 

Finally, we can run the bootscript in U-Boot:

u-boot=> load mmc 2:1 ${loadaddr} LCM4-bootscript
158 bytes read in 2 ms (77.1 KiB/s)

u-boot=> source ${loadaddr}
## Executing script at 40400000
6656 bytes read in 5 ms (1.3 MiB/s)
## No elf image at address 0x007e0000
## Starting auxiliary core stack = 0x20020000, pc = 0x1FFE02CD...

 

And the Cortex M4 booted successfully:

Alejandro_Salas_1-1705730669972.png

 

 I hope this can helps to you.

 

Best regards.

 

Salas.

 

Comments

@Alejandro_Salas  This is very helpful, but how can we include this custom script to run automatically before the autoboot timer and kernel loading starts. Like if we wanna run a custom script along with the default <machine>_boot.scr script during uboot execution.

 

And also where does the default boot script lie in the nxp yocto-sdk

Very useful information. I'm pretty much after the same information as @pvsnsubhash is. How can we include such a custom script to run automatically as a part of the created Yocto image?

100% helpful (1/1)
Version history
Last update:
‎01-19-2024 11:11 PM
Updated by: