[go: up one dir, main page]

0% found this document useful (0 votes)
301 views80 pages

Introduction To U-Boot 2020

This document provides a 3 sentence summary of the given document on the U-Boot bootloader: The document introduces the multi-stage U-Boot bootloader, describing the U-Boot SPL first stage loader that performs hardware initialization and loads U-Boot, and the main U-Boot stage which provides an interactive shell and commands for booting Linux. It provides examples of common U-Boot commands for accessing memory, modifying the environment variables, and running scripts to demonstrate basic functionality of the U-Boot bootloader.

Uploaded by

elwwardi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
301 views80 pages

Introduction To U-Boot 2020

This document provides a 3 sentence summary of the given document on the U-Boot bootloader: The document introduces the multi-stage U-Boot bootloader, describing the U-Boot SPL first stage loader that performs hardware initialization and loads U-Boot, and the main U-Boot stage which provides an interactive shell and commands for booting Linux. It provides examples of common U-Boot commands for accessing memory, modifying the environment variables, and running scripts to demonstrate basic functionality of the U-Boot bootloader.

Uploaded by

elwwardi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 80

Introduction to U-Boot bootloader

Behan Webster <behanw@converseincode.com>

June, 2020
This Talk originally written by Marek Vašut

Marek Vašut <marek.vasut+eale19@gmail.com>


This talk is licensed as CC BY-SA 2.0
Behan Webster

I Embedded Linux consultant


I Linux kernel engineer
I Trainer and Course Author for the Linux Foundation
Booting a computer

Multi-stage bootloader
First stage bootloader
I Resides on reset vector
I Often on-chip BootROM
I Initializes HW and loads the next stage

User bootloader
I First user-controlled code

Linux kernel

Userspace
U-Boot bootloader
First stage bootloader

U-Boot SPL
I First user-controlled code
I Responsible for additional HW initialization
I Loads U-Boot or Linux directly

U-Boot
I Bootloader with interactive shell
I Boot monitor
I Debug tool

Linux kernel
Userspace
U-Boot example

1 U-Boot SPL 2018.01-00002-g9aa111a004 (Jan 20 2018 - 12:45:29)


2 Trying to boot from MMC1
3
4

5 U-Boot 2018.01-00002-g9aa111a004 (Jan 20 2018 - 12:45:29 -0600)


6
7 CPU : AM335X-GP rev 2.1
8 I2C: ready
9 DRAM: 512 MiB
10 Reset Source: Global warm SW reset has occurred.
11 Reset Source: Power-on reset has occurred.
12 MMC: OMAP SD/MMC: 0, OMAP SD/MMC: 1
13
14 Model: BeagleBoard.org PocketBeagle
15 Net: usb_ether
16 Press SPACE to abort autoboot in 2 seconds
17 =>
U-Boot SPL vs U-Boot

SPL – Secondary Program Loader


I Built from the same source as U-Boot
I Significantly reduced size and feature set
I Used to init system and start U-Boot or Linux
TPL – Tertiary program loader
I Built from the same source as U-Boot
I Even smaller than SPL
I Almost never used
I Used on severely limited system (ie. OneNAND)
Basic U-Boot commands
U-Boot shell

I There are two shell choices


1. original old shell (which has no name)
2. HUSH shell (which has more features)
I For most situations HUSH is the better choice
I Similar to bourne shell
I Persistent environment support
I Scripting support
The ’help’ command
I Provides detailed built-in help text
I Can provide further details on specific command

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
Running ’help’ on a command

I Just run help on any command for more information

1 => help echo


2 echo - echo args to console
3
4 Usage:
5 echo [args..]
6 - echo args to console; \c suppresses newline
7

8 => help bdinfo


9 bdinfo - print Board Info structure
10
11 Usage:
12 bdinfo
help on sub-commands

1 => help usb


2 usb - USB sub-system
3
4 Usage:
5 usb start - start (scan) USB controller
6 usb reset - reset (rescan) USB controller
7 usb stop [f] - stop USB [f]=force stop
8 usb tree - show USB device tree
9 usb info [dev] - show available USB devices
10 usb test [dev] [port] [mode] - set USB 2.0 test mode
11 (specify port 0 to indicate the device's upstream port)
12 Available modes: J, K, S[E0_NAK], P[acket], F[orce_Enable]
The ’echo’ command

I Useful for printing text


I It does NOT interpret control sequences
(except for \\c to suppress newline)

1 => echo hello world


2 hello world
3 => echo foo\\c ; echo bar
4 foobar
The ’bdinfo’ command
I Probing system info

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
Getting further help

I Source, documentation in doc/


https://git.denx.de/?p=u-boot.git;a=tree;f=doc
I IRC: irc.freenode.net #u-boot
I Mailing list: u-boot@lists.denx.de
U-Boot memory access
commands
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 => mw 0x81000000 0x1234abcd


2 => md.l 0x81000000 0x8
3 81000000: 1234abcd 00000000 00000000 00000000 ..4.............
4 81000010: 00000000 00000000 00000000 00000000 ................
5 => md.w 0x81000000 0x8
6 81000000: abcd 1234 0000 0000 0000 0000 0000 0000 ..4...........
7 => md.b 0x81000000 0x8
8 81000000: cd ab 34 12 00 00 00 00 ..4.....
9 =>
10 81000008: 00 00 00 00 00 00 00 00 ........
Memory access commands, ’mw’, ’md’

I Try toggling GPIOs the hard way


I Note on used bitfields:
|xxxx|xxx0|000x|xxxx|xxxx|xxxx|xxxx|xxxx|
I Expected result: Two Blue LEDs ON/OFF

1 => echo "Try toggling GPIOs the hard way"


2 => md 0x4804c130 4
3 4804c130: 00000002 ffffffff f0000300 00000000 ................
4 => mw 0x4804c134 0xfe1fffff
5 => mw 0x4804c13c 0x00a00000
6 => mw 0x4804c13c 0x01400000
7 => md 0x4804c130 4
8 4804c130: 00000002 fe1fffff f1400300 01400000 ..........@...@.
Memory modification commands, ’mm’, ’nm’

I Useful for interactively modifying registers


I Same properties as for md/mw apply
I mm autoincrements address, nm does not
I Use ’q’ to drop back to U-Boot shell
I Use ’-’ to return to previous address
I Press ’Enter’ without value to skip current address

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

1 => mw 0x81000000 0x1234abcd 0x10


2 => cp 0x81000000 0x82000000 0x8
3 => cmp 0x81000000 0x82000000 0x8
4 Total of 8 word(s) were the same
5 => cmp 0x81000000 0x82000000 0x9
6 word at 0x81000020 (0x1234abcd) != word at 0x82000020 \
7 (0xea000003)
8 Total of 8 word(s) were the same
U-Boot environment and
scripting commands
U-Boot environment

I The environment uses key-value storage


I Can contain values or 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

I For printing the environment


I Legacy alias for ’env print’

1 => env print


2 arch=arm
3 ...
4 Environment size: 26907/131068 bytes
5 =>
6 => env print arch
7 arch=arm
8 => printenv arch
9 arch=arm
10 => echo "$arch"
11 arm
The ’setenv’/’askenv’/’editenv’ command
I For modifying the environment
I Legacy alias for ’env set’/’env ask’/’env edit’

1 => env set foo bar


2 => env print foo
3 foo=bar
4
5 => env ask quux "Set quux to ?"
6 Set quux to ? 1234
7 => env print quux
8 quux=1234
9
10 => env edit quux
11 edit: 24
12 => env print quux
13 quux=24
Removing variables

I Set variables to empty to remove them from the environment

1 => env print foo


2 ## Error: "foo" not defined
3 => env set foo bar
4 => env print foo
5 foo=bar
6 => env set foo
7 => env print foo
8 ## Error: "foo" not defined
The ’saveenv’ command
I For environment persistency
I Environment is not persistent across reboots by default
I Any changes to environment are done to the live copy

1 => env set foo bar


2 => env print foo
3 foo=bar
4 => reset
5 => env print foo
6 ## Error: "foo" not defined
7
8 => env set foo bar
9 => saveenv
10 => reset
11 => env print foo
12 bar
The ’run’ command

I For running scripts in the environment


I Chaining commands with ’;’ is possible
I Note that ’;’ ignores return value

1 => env set foo 'echo hello'


2 => run foo
3 hello
4
5 => env set foo 'echo hello ; echo world'
6 => run foo
7 hello
8 world
Variables in environment

I Proper escaping is important on U-Boot shell


I Be careful with variable expansion

1 => env set foo bar


2 => env set quux echo $foo
3 => env set foo baz
4 => run quux
5 bar
6 => env print quux
7 quux=echo bar
8
9 => env set quux echo \$foo
10 => env print quux
11 => env set quux 'echo $foo'
12 => env print quux
Special variables

Certain variables have special meaning/function


I ver – U-Boot version
I stdin, stdout, stderr – Redirection of STDIO. Setting
these has immediate impact, also see coninfo command.
I loadaddr – Default load address
I filesize – Size of the loaded file
I bootargs – Boot arguments passed to Linux command line
I bootcmd – Default boot command (see boot command and
autoboot)
I preboot – Script executed before autoboot
I ipaddr, netmask, serverip, gatewayip – Network
settings
I ethaddr, eth1addr, ... – Ethernet MAC address
The ’setexpr’ command
I Environment manipulation multi-tool
I Supports loading memory content into variables
I Supports arithmetic operations on both variables and memory
(AND, OR, XOR, +, -, *, /, MOD)
I Supports basic regex manipulation on strings and variables

1 => md 0x9ff4e000 1
2 9ff4e000: ea0000b8
3 => setexpr foo *0x9ff4e000
4 => env print foo
5 foo=ea0000b8
6
7 => env set foo 1 ; env set 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
U-Boot shell conditional
expressions and loops
The ’true’/’false’ commands

I Return 0 (true) / non-zero (false) return values


I U-Boot supports handling return values of commands
I Automatic variables are supported too

1 => true
2 => echo $?
3 0
4 => false
5 => echo $?
6 1
Conditional expressions

I The if conditional is supported


I Shorthand || and && expressions also supported
I Warning, the "if ! foo ; then ... fi" is not supported, use ie.
"if foo ; then false ; else ... fi" as a workaround

1 => if true ; then echo "hello" ; else echo "bye" ; fi


2 hello
3 => false || echo "false!"
4 false!
5

6 => env set foo 'true && echo "true!"'


7 => run foo
8 true!
The ’test’ command

I Minimal test command from HUSH

1 => env set i 4


2 => test $i -lt 5
3 => echo $?
4 0
5 => env set i 6
6 => test $i -lt 5
7 => echo $?
8 1
9
10 => env set i 6
11 => if test $i -lt 5 ; then echo "Less then 5" ; \
12 else echo "More than 5" ; fi
13 More than 5
The ’for’ loop

I The for loop over a list of elements

1 => for i in a b c d ; do echo "$i" ; done


2 a
3 b
4 c
5 d
The ’while’ loop

I The while loop with a condition


I Ctrl-c can be used to break an endless loop

1 => while true ; do echo hello ; done


2 hello
3 hello
4 hello
5 Ctrl-c
6 =>
U-Boot data loading
commands
Loading from storage

I U-Boot supports loading from various storage types


I SD/MMC – mmc command
I USB – usb command
I SATA – sata command
I NAND – nand command
I ...
I Both RAW storage and filesystems are supported
I Universal FS access – ’ls’, ’load’ commands
I ExtFS – legacy ’extls’/’extload’ command
I VFAT – legacy ’fatls’/’fatload’ command
I UBI/UBIFS – ’ubi’ command
I ...
Loading from SD card

1 => mmc rescan


2 => mmc part
3
4 Partition Map for MMC device 0 -- Partition Type: DOS
5
6 Part Start Sector Num Sectors UUID Type
7 1 8192 6955008 1147c091-01 83 Boot
8
9 => ls mmc 0:1
10 <DIR> 4096 .
11 <DIR> 4096 ..
12 40 ID.txt
13 ...
14 => load mmc 0:1 $loadaddr ID.txt
15 => md.b $loadaddr $filesize
16 82000000: 42 65 61 67 6c 65 42 6f 61 72 ... BeagleBoard.org
17 82000010: 44 65 62 69 61 6e 20 49 6d 61 ... Debian Image 201
18 82000020: 38 2d 30 31 2d 32 38 0a 8-01-28.
Loading from network

I U-Boot network stack is UDP-only (no TCP)


I Support for TFTP, NFS (over UDP), DHCP/BOOTP, . . .
I ping – ICMP Echo
I tftp – TFTP download (tftpput for upload)
I dhcp – Obtain settings from DHCP and ev. load file

1 => env set ethaddr 00:aa:bb:cc:dd:ee # optional!


2 => env set ipaddr 192.168.1.300
3 => env set netmask 255.255.255.0
4 => env set serverip 192.168.1.1
5 => ping $serverip
6 => tftp $loadaddr $serverip:somefile
7 => dhcp $loadaddr $serverip:somefile
Loading over serial port
I When nothing else, UART is available
I U-Boot supports X/Y modem, Srecord and kermit protocol

1 U-Boot> loady
2 <send file over ymodem protocol, e.g. sb -T>

I Example with GNU screen

1 $ screen /dev/ttyUSB0 115200


2 => loady
3 ctrl-a:exec !! sb -T yourbinary.bin
4
5 or from another shell on the same host computer:
6
7 $ screen -x -r -X exec \!\! sb -T yourbinary.bin
Booting the kernel
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 Optional separate Device Tree
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 Device Tree
I fitImage – multi-component image
I Based on Device Tree
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

1 => help bootz


2 bootz - boot Linux zImage image from memory
3

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

10 When booting a Linux kernel which requires a flat


11 device-tree a third argument is required which is
12 the address of the device-tree blob.
Booting kernel image

1 => env set bootargs console=ttyO0,115200


2 => load mmc 0:1 0x82000000 boot/zImage-4.9.82-ti-r102
3 9970640 bytes read in 673 ms (14.1 MiB/s)
4 => load mmc 0:1 0x88000000 boot/dtbs/4.9.82-ti-r102/\
5 am335x-pocketbeagle.dtb
6 132769 bytes read in 180 ms (719.7 KiB/s)
7 => bootz 0x82000000 - 0x88000000
8 ## Flattened Device Tree blob at 88000000
9 Booting using the fdt blob at 0x88000000
10 Loading Device Tree to 8ffdc000, end 8ffff6a0 ... OK
11
12 Starting kernel ...
13
14 [ 0.000000] Booting Linux on physical CPU 0x0
15 [ 0.000000] Linux version 4.9.82-ti-r102 \
16 (root@b2-am57xx-beagle-x15-2gb) (gcc version 6.3.0 20170516
17 (Debian 6.3.0-18) ) #1 SMP PREEMPT Thu Feb 22 01:16:12 UTC 2
18 [ 0.000000] CPU: ARMv7 Processor [413fc082] revision 2 (ARMv7
Device Tree

I Data structure describing the hardware


I Usually passed to OS to provide information about HW
topology where it cannot be detected or probed
I An acyclic graph, made of named nodes containing properties
I Nodes can contain properties and child nodes
I Properties are a name-value pairs
I See https://en.wikipedia.org/wiki/Device_tree
I Device Tree properties can refer to other nodes by the used of
phandles (references to other nodes)
I phandles provide simple references to device node labels
(e.g. "<&L2>" is reference to L2 cache node)
I phandles can be used to reference nodes anywhere in the
device tree
Device Tree example

1 /dts-v1/;
2 #include "arm-realview-eb-mp.dtsi"
3 / {
4 model = "ARM RealView EB Cortex A9 MPCore";
5 [...]
6 cpus {
7 #address-cells = <1>;
8 #size-cells = <0>;
9 enable-method = "arm,realview-smp";
10 A9_0: cpu@0 {
11 device_type = "cpu";
12 compatible = "arm,cortex-a9";
13 reg = <0>;
14 next-level-cache = <&L2>;
15 };
16 [...]
17 pmu: pmu@0 {
18 interrupt-affinity = <&A9_0>, <&A9_1>, <&A9_2>, <&A9_3>;
19 }; };
fitImage example (1)

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 example (2)

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 example (3)

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

1 mkimage -f fit-image.its fitImage


fitImage commands
I bootm $fitimageaddr – boot fitImage/uImage
I iminfo – print image information
I imxtract – extract file from fitImage/uImage
1 => iminfo $loadaddr
2
3 ## Checking Image at 82000000 ...
4 FIT image found
5 FIT description: Linux kernel and FDT blob for am335x-pocketbeagle
6 Created: 2018-09-03 0:46:36 UTC
7 Image 0 (kernel@1)
8 Description: Linux kernel (Mon Sep 3 02:46:36 CEST 2018)
9 Created: 2018-09-03 0:46:36 UTC
10 Type: Kernel Image
11 Compression: uncompressed
12 Data Start: 0x82000154
13 Data Size: 5665328 Bytes = 5.4 MiB
14 Architecture: ARM
15 OS: Linux
16 Load Address: 0x80008000
17 Entry Point: 0x80008000
18 Hash algo: crc32
19 Hash value: 1a1062ee
20 ...
21 => imxtract $loadaddr kernel@1 0x8a000000
22 ## Copying 'kernel@1' subimage from FIT image at 82000000 ...
23 crc32+ Loading part 0 ... OK
24 => md 0x8a000000
25 8a000000: e1a00000 e1a00000 e1a00000 e1a00000 ................
26 8a000010: e1a00000 e1a00000 e1a00000 e1a00000 ................
27 8a000020: ea000005 016f2818 00000000 00567230 .....(o.....0rV.
The ’fdt’ command

I FDT manipulation
I fdt addr – Tell U-Boot where the FDT is
I fdt resize – Add extra space to FDT
I fdt print – Print DT path
I fdt set – Add or change DT entry

1 => load mmc 0:1 0x88000000 boot/dtbs/4.9.82-ti-r102/am335x-pocketbeagle.dtb


2 132769 bytes read in 180 ms (719.7 KiB/s)
3 => fdt addr 0x88000000
4 => fdt resize
5 => fdt print /chosen
6 chosen {
7 stdout-path = "/ocp/serial@44e09000";
8 };
9 => fdt set /chosen/ foo bar
10 => fdt print /chosen
11 chosen {
12 foo = "bar";
13 stdout-path = "/ocp/serial@44e09000";
14 };
15 => bootz 0x82000000 - 0x88000000
Miscellaneous U-Boot
commands
The ’gpio’ command

I Useful for toggling/sampling GPIOs


I GPIO input sets return value
I gpio input - to read a gpio
I gpio set - to set a gpio
I gpio clear - to clear a gpio
I gpio toggle - to toggle a gpio

1 => gpio input 45


2 gpio: pin 45 (gpio 45) value is 1
3 => echo $?
4 1
5 => gpio set 53
6 gpio: pin 53 (gpio 53) value is 1
The ’i2c’ command
I Useful for accessing I2C bus
I i2c bus – lists available I2C busses
I i2c dev – select an I2C bus
I i2c md – read registers from I2C device
I i2c mw – write registers to I2C device
I i2c probe – probe for devices on I2C
I i2c speed – set I2C bus speed

1 => i2c dev 2


2 Setting bus to 2
3 => i2c probe
4 Valid chip addresses: 1C
5 => i2c md 0x1c 0x0 0x8
6 0000: 00 41 ac 01 fc 7f 10 00 .A......
Compiling U-Boot from source
U-Boot sources

I Git master at:


http://git.denx.de/?p=u-boot.git;a=summary
I on Github:
https://github.com/u-boot/u-boot
I Custodian subtrees at:
http://git.denx.de/?p=u-boot.git;a=forks
I Available via Git and HTTP protocols
Building the sources

1 $ git clone git://git.denx.de/u-boot.git


2 $ cd u-boot
3 $ export CROSS_COMPILE=arm-linux-gnueabihf- # optional, set cross compiler
4 $ make am335x_evm_defconfig
5 $ make

I U-Boot sandbox target (sandbox_defconfig)


U-Boot running as userspace application
I U-Boot QEMU targets, (qemu_defconfig)
U-Boot running in QEMU as "BIOS"
qemu-system-arm -M virt -bios u-boot.bin
Labs

Practical labs

I Examples work with a PocketBeagle and Techlab


I https://beagleboard.org/pocket
I https://beagleboard.org/techlab
Task 0

Enter U-Boot prompt


I HINT: Press SPACE to stop autoboot
Task 0

1 Model: BeagleBoard.org PocketBeagle


2 <ethaddr> not set. Validating first E-fuse MAC
3 Net: No ethernet found.
4 Press SPACE to abort autoboot in 2 seconds
5 =>
Task 1

Boot kernel from SD card


I Check if SD card contains zImage and DTB.
I Load both into memory
I Set $bootargs
I Boot the kernel with DT
I HINT: mmc rescan, ls, load, bootz commands
Task 1

1 => env set bootargs root=/dev/mmcblk0p1 rootfstype=ext4 rootwait \


2 console=ttyO0,115200
3 => mmc rescan
4 => load mmc 0:1 0x82000000 boot/vmlinuz-4.14.91-ti-r90
5 => load mmc 0:1 0x88000000 boot/dtbs/4.14.91-ti-r90/\
6 am335x-pocketbeagle-techlab.dtb
7 => bootz 0x82000000 - 0x88000000
8 9970640 bytes read in 6594 ms (1.4 MiB/s)
9 132769 bytes read in 123 ms (1 MiB/s)
10 ## Flattened Device Tree blob at 88000000
11 Booting using the fdt blob at 0x88000000
12 Loading Device Tree to 8ffdc000, end 8ffff6a0 ... OK
13
14 Starting kernel ...
15
16 [ 0.000000] Booting Linux on physical CPU 0x0
Task 2

Boot kernel from SD card with adjusted DT


I Change /model property in DT and boot kernel with it
I HINT: mmc rescan, load, fdt addr, fdt set, bootz commands
I HINT: in Linux see cat /proc/device-tree/model
Task 2
1 => env set bootargs root=/dev/mmcblk0p1 rootfstype=ext4 rootwait \
2 console=ttyO0,115200
3 => mmc rescan
4 => load mmc 0:1 0x82000000 boot/vmlinuz-4.14.91-ti-r90
5 => load mmc 0:1 0x88000000 boot/dtbs/4.14.91-ti-r90/\
6 am335x-pocketbeagle-techlab.dtb
7 => fdt addr 0x88000000
8 => fdt set / model "Something"
9 => fdt list
10 / {
11 ...
12 compatible = "ti,am335x-pocketbeagle", "ti,am335x-bone", "ti,am33xx";
13 model = "Something";
14 chosen {
15 ...
16 };
17 => bootz 0x82000000 - 0x88000000
18 ...
19 [ 0.000000] OF: fdt: Machine model: Something
20 ...
21 beaglebone login:debian
22 debian@beaglebone:~$ dmesg | grep model
23 [ 0.000000] OF: fdt: Machine model: Something
Task 3

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 3

1 => if gpio input 45 ; then


2 echo "Button pressed" ;
3 else
4 echo "Button not pressed" ;
5 fi
Task 4

Blink USR LED using direct HW IO


I HINT: for or while commands
I HINT: 0x4804c134 is the offset of the GPIO direction register
Use the following to set the four pins as outputs
mw 0x4804c134 0xfe1fffff
I HINT: 0x4804c13c is the offset of the GPIO value register
Use the following to set LED 0 on
mw 0x4804c13c 0x00200000
I HINT: sleep 1 waits 1 second
I HINT: look at ’base’ command
Task 4

1 => mw 0x4804c134 0xfe1fffff


2 => while true ; do
3 mw 0x4804c13c 0x00200000 ;
4 sleep 1 ;
5 mw 0x4804c13c 0x00000000 ;
6 sleep 1 ;
7 done
Task 5

Implement moving light using USR LEDs using GPIO command


I HINT: for or while commands
I HINT: LEDs are GPIO 53, 54, 55, 56
I HINT: sleep 1 waits 1 second
I HINT: look at ’base’ command
Task 5

1 => while true ; do


2 for i in 53 54 55 56 ; do
3 gpio set $i ;
4 sleep 1 ;
5 gpio clear $i ;
6 done ;
7 done
Task 6

Conveniently load custom environment using Ymodem


I HINT: loady and env import commands
Task 6

1 linux$ cat << EOF > /tmp/env.txt


2 > hello=world
3 > foo=bar
4 > EOF
5
6 => loady
7 ## Ready for binary (ymodem) download to 0x82000000 at 115200 bps...
8 ctrl-a:exec !! sb -T /tmp/env.txt
9 C## Total Size = 0x00000014 = 20 Bytes
10 => md.b $loadaddr $filesize
11 82000000: 68 65 6c 6c 6f 3d 77 6f 72 6c 64 0a 66 6f 6f 3d hello=world.foo=
12 82000010: 62 61 72 0a bar.
13 => env import $loadaddr $filesize
14 ## Warning: defaulting to text format
15 => env print hello
16 hello=world
Task 7

Compiling U-Boot to run in sandbox mode


I Clone U-Boot sources, configure them for sandbox, compile
U-Boot.
I HINT: On your host machine

1 $ git clone git://git.denx.de/u-boot.git


2 $ cd u-boot
3 $ make sandbox_defconfig
4 $ make -j $(nproc)
5 $ ./u-boot
Task 7

1 $ make sandbox_defconfig
2 HOSTCC scripts/basic/fixdep
3 ...
4 #
5 # configuration written to .config
6 #
7
8 $ make -j $(nproc)
9 scripts/kconfig/conf --syncconfig Kconfig
10 CHK include/config.h
11 UPD include/config.h
12 ...
13 CFGCHK u-boot.cfg
14 $ ./u-boot
15
16 U-Boot 2018.11-rc1-00033-ga16accc9fb (Oct 07 2018 - 17:13:29 +0200)
17
18 Model: sandbox
19 DRAM: 128 MiB
20 ...
21 =>
Task 8

Barcode reader example


I Imagine that an ethernet MAC address is entered into U-Boot
from a barcode reader which is formatted incorrectly.
I Filter the MAC address out and ignore the separators
I The input should read with "env ask" and be somthing like
"00xaaxbbxccxddxee"
I USe setexpr to change the input into a proper MAC address
(i.e. "00:aa:bb:cc:dd:ee").
I Assume the list of separators is known and fixed as "xyz".
Task 8

1 => env ask mac 'MAC address ?'


2 MAC address ? 00xaaxbbxccxddxee
3 => setexpr myethaddr gsub '\\(..\\)[xyz]' '\\\\1:' $mac
4 myethaddr=00:aa:bb:cc:dd:ee
Task 9
Playing with the Techlab Accelerometer
I Read out the MMA8452Q accelerometer data
I HINT: i2c commands
I HINT: Accelerometer is on bus 2, select bus 2

1 => i2c dev 2

I HINT: Accelerometer has I2C address 0x1c, try

1 => i2c md 0x1c 0 0x10

I HINT: Accelerometer is in standby, wake it up with

1 => i2c mw 0x1c 0x2a 0x1

then try reading samples at offset 0x1..0x6 again


Task 9

1 => i2c dev 2


2 => i2c md 0x1c 0 0x10
3 => i2c mw 0x1c 0x2a 0x1
4 => while true ; do i2c md 0x1c 0x2a 0x3; done

bjs
Questions

Thank you. Questions?


Contact: Behan Webster <behanw@converseincode.com>

You might also like