U Boot
U Boot
March, 2018
Marek Vasut
I Software engineer
I Versatile Linux kernel hacker
I Custodian at U-Boot bootloader
I OE-core contributor (Yocto. . . )
I FPGA enthusiast
Booting a computer
I Multi-stage bootloader
I First stage on reset vector
I Often a BootROM
I Inits HW, loads next stage
I OS kernel
I Userspace
U-Boot bootloader
I Boot loader
I First1 -ish code that runs on a system
I Responsible for some HW initialization and starting OS
I Boot monitor
I Debug tool
1
There are exceptions, ie. Boot ROMs
U-Boot example
1 => help
2 ? - alias for 'help'
3 bdinfo - print Board Info structure
4 bootm - boot application image from memory
5 cmp - memory compare
6 coninfo - print console devices and information
7 crc32 - checksum calculation
8 dhcp - boot image via network using DHCP/TFTP protocol
9 echo - echo args to console
10 go - start application at address 'addr'
11 help - print command description/usage
12 i2c - I2C sub-system
13 load - load binary file from a filesystem
14 usb - USB sub-system
Getting further help
1 => bdinfo
2 arch_number = 0x00000E05
3 boot_params = 0x80000100
4 DRAM bank = 0x00000000
5 -> start = 0x80000000
6 -> size = 0x20000000
7 eth0name = usb_ether
8 ethaddr = 60:64:05:f4:79:7f
9 current eth = usb_ether
10 ip_addr = 192.168.1.2
11 baudrate = 115200 bps
12 TLB addr = 0x9FFF0000
13 relocaddr = 0x9FF44000
14 reloc off = 0x1F744000
15 irq_sp = 0x9DF23EC0
16 sp start = 0x9DF23EB0
17 Early malloc usage: 2a8 / 400
Memory access commands, ’mw’, ’md’
I Useful for reading/writing memory and registers
I Support for byte/word/long/quad register access using
suffixes (.b, .w, .l, .q)
I Default access width is long, 32bit (md = md.l)
I Support for reading multiple units at a time (default 0x40)
I Default for read is updated if number of units specified
I Can read subsequent addresses if no address specified
1 => mm 0x4804c134
2 4804c134: ffffffff ? fe1fffff
3 4804c138: f0002300 ?
4 4804c13c: 00000000 ? 00400000
5 4804c140: 00000000 ? q
6 =>
Memory access commands, ’cp’, ’cmp’
I cp – copy memory
I cmp – compare memory
I Same properties as md/mw above apply
I key-value storage
I Can contain values or even scripts
I Default env built into U-Boot binary
I Optional custom env loaded from storage
I Live copy in RAM
I Can be accessed as variables
I Can be modified
I Can be made persistent
The ’printenv’ command
1 => md 0x9ff4e000 1
2 9ff4e000: ea0000b8
3 => setexpr foo *0x9ff4e000
4 => env print foo
5 foo=ea0000b8
6
7 => setenv foo 1 ; setenv bar 2
8 => setexpr baz $foo + $bar
9 => env print baz
10 baz=3
11
12 => setexpr foo gsub ab+ x "aabbcc"
13 foo=axcc
The ’true’/’false’ commands
1 => true
2 => echo $?
3 0
4 => false
5 => echo $?
6 1
Conditional expressions
1 => loady
2 <send file over ymodem protocol>
Booting the kernel
There are many image formats
I (z)Image
I Linux binary with decompressor
I No protection against bitrot
I Just set up registers and jump to it
I uImage
I Legacy since forever
I Wrapper around arbitrary binary
I CRC32 checksum and small amount of metadata
I Wraps single file only
I Optional separate DT
I fitImage – multi-component image
I Based on DT
I Supports multiple files
I Configurable checksum algorithm per entry
I Supports digital signatures
Booting kernel image
I bootz – (z)Image
I booti – ARM64 Image
I bootm – fitImage, uImage
I $bootcmd – default boot command
4 Usage:
5 bootz [addr [initrd[:size]] [fdt]]
6 - boot Linux zImage stored in memory
7 The argument 'initrd' is optional... The optional arg
8 ':size' allows specifying the size of RAW initrd.
9
1 /dts-v1/;
2
3 / {
4 description = "Linux kernel and FDT blob for sockit";
5
6 images {
7 kernel@1 {
8 description = "Linux kernel";
9 data = /incbin/("./arch/arm/boot/zImage");
10 type = "kernel";
11 arch = "arm";
12 os = "linux";
13 compression = "none";
14 load = <0x00008000>;
15 entry = <0x00008000>;
16 hash@1 {
17 algo = "crc32";
18 };
19 };
fitImage
1 fdt@1 {
2 description = "Flattened Device Tree blob";
3 data = /incbin/("./arch/arm/boot/dts/socfpga....dtb");
4 type = "flat_dt";
5 arch = "arm";
6 compression = "none";
7 hash@1 {
8 algo = "crc32";
9 };
10 };
11 };
fitImage
1 configurations {
2 default = "conf@1";
3 conf@1 {
4 description = "Boot Linux kernel with FDT blob";
5 kernel = "kernel@1";
6 fdt = "fdt@1";
7 hash@1 {
8 algo = "crc32";
9 };
10 };
11 };
12 };
Compile with
Partical part
Task 0
Button input
I HINT: ’gpio input’ command
I HINT: 0x4804c138 is the offset of the GPIO input register
I HINT: gpio 45 is the USR button GPIO
Task 4
Barcode reader
I U-Boot queries ethernet MAC address from barcode reader,
which does not necessarily use ASCII. Filter the MAC out and
ignore the separators (ie. 00xaaxbbxccxddxee becomes
00:aa:bb:cc:dd:ee). Assume the list of separators is known and
fixed (ie. xyz).
I HINT: env ask and setexpr
Task 5
Recovery system
I Check if USB stick is plugged in and contains kernel image
and DT. If so, boot those, otherwise boot the images on SD
card.
I HINT: usb reset, load, bootz commands
Task 6
Compiling U-Boot
I Clone U-Boot sources, configure them, adjust bootdelay to 30
seconds, compile U-Boot and install on the board.
I HINT: U-Boot sources are provided on the USB stick
I HINT:
1 export ARCH=arm
2 export CROSS_COMPILE=arm-linux-gnueabi-
3 make am335x_pocketbeagle_defconfig
4 make menuconfig # locate CONFIG_BOOTDELAY
5 make
6 dd if=MLO of=/dev/sdg bs=128k count=1 seek=1
7 dd if=u-boot.img of=/dev/sdg bs=384k seek=1 count=2
Task 7
1 $ make am335x_pocketbeagle_defconfig
2 #
3 # configuration written to .config
4 #
5
6 $ make
7 scripts/kconfig/conf --silentoldconfig Kconfig
8 CHK include/config.h
9 CFG u-boot.cfg
10 GEN include/autoconf.mk
11 ...
Task 8
Accelerometer
I Read out the MMA8452Q accelerometer data
I HINT: i2c commands
I HINT: Accelerometer is on bus 2
Use i2c dev 2 to select bus 2
I HINT: Accelerometer has I2C address 0x1c
Try: i2c md 0x1c 0 0x10
I HINT: Accelerometer is in standby, wake it up with
i2c mw 0x1c 0x2a 0x1
then try reading samples at offset 0x1..0x6 again
Task 9
DT
I Load DT from SD/MMC, add property to it, boot Linux and
check it’s presence
I HINT: fdt commands , /proc/devicetree
The End