1.. SPDX-License-Identifier: GPL-2.0+
2.. Copyright 2020 Google LLC
3.. sectionauthor:: Simon Glass <sjg@chromium.org>
4
5
6Running U-Boot with Chromium OS verified boot
7=============================================
8
9Note: Once you use the source below you can obtain extra documentation with
10'make htmldocs'. See the 'Internal Documentation' link, under
11'Chromium OS-specific doc'.
12
13To obtain::
14
15   git clone https://github.com/sjg20/u-boot.git
16   cd u-boot
17   git checkout cros-2021.04
18
19   cd ..
20   git clone https://chromium.googlesource.com/chromiumos/platform/vboot_reference
21   cd vboot_reference
22   git checkout 45964294
23   #  futility: updater: Correct output version for Snow
24
25To build for sandbox::
26
27   UB=/tmp/b/chromeos_sandbox    # U-Boot build directory
28   cd u-boot
29   make O=$UB chromeos_sandbox_defconfig
30   make O=$UB -j20 -s VBOOT_SOURCE=/path/to/vboot_reference \
31     MAKEFLAGS_VBOOT=DEBUG=1 QUIET=1
32
33Replace sandbox with another supported target.
34
35This produces $UB/image.bin which contains the firmware binaries in a SPI
36flash image.
37
38To run on sandbox::
39
40   CROS=~/cosarm
41   IMG=$CROS/src/build/images/coral/latest/chromiumos_image.bin
42   $UB/tpl/u-boot-tpl -d $UB/u-boot.dtb.out \
43     -L6 -c "host bind 0 $IMG; vboot go auto" \
44     -l -w -s state.dtb -r -n -m $UB/ram
45
46   $UB/tpl/u-boot-tpl -d $UB/u-boot.dtb.out -L6 -l \
47     -c "host bind 0 $IMG; vboot go auto" -w -s $UB/state.dtb -r -n -m $UB/mem
48
49
50To run on other boards:
51
52   - Install image.bin in the SPI flash of your device
53   - Boot your system
54
55
56Sandbox
57-------
58
59Most Chromium OS development with U-Boot is undertaken using sandbox. There is
60a sandbox target available (chromeos_sandbox) which allows running U-Boot on
61a Linux machine completion with emulations of the display, TPM, disk, etc.
62
63Running sandbox starts TPL, which contains the first phase of vboot, providing
64a device tree and binding a Chromium OS disk image for use to find kernels
65(any Chromium OS image will do). It also saves driver state between U-Boot
66phases into state.dtb and will automatically ensure that memory is shared
67between all phases. TPL will jump to SPL and then on to U-Boot proper.
68
69It is possible to run with debugging on, e.g.::
70
71   gdb --args $UB/tpl/u-boot-tpl -d ....
72
73Breakpoints can be set in any U-Boot phase. Overall this is a good debugging
74environment for new verified-boot features.
75
76
77Samus
78-----
79
80Basic support is available for samus, using the chromeos_samus target. If you
81have an em100, use::
82
83   sudo em100 -s -c W25Q128FW -d $UB/image.bin -t -r
84
85to write the image and then boot samus (Power-Refresh).
86
87
88Boot flow
89---------
90
91Verified boot starts in TPL, which selects the A or B SPL, which in turn selects
92the A or B U-Boot. Then this jumps to the selected kernel. If anything goes
93wrong, the device reboots and the recovery SPL and U-Boot are used instead.
94
95More details are available here:
96
97   https://www.chromium.org/chromium-os/chromiumos-design-docs/firmware-boot-and-recovery
98
99
100New uclasses
101------------
102
103Several uclasses are provided in cros/:
104
105UCLASS_CROS_AUX_FW
106   Chrome OS auxiliary firmware
107
108UCLASS_CROS_FWSTORE
109   Chrome OS firmware storage
110
111UCLASS_CROS_NVDATA
112   Chrome OS non-volatile data device
113
114UCLASS_CROS_VBOOT_EC
115   Chrome OS vboot EC operations
116
117UCLASS_CROS_VBOOT_FLAG
118   Chrome OS verified boot flag
119
120The existing UCLASS_CROS_EC is also used.
121
122
123Commands
124--------
125
126A new 'vboot' command is provided to run particular vboot stages. The most
127useful command is 'vboot go auto', which continues where the last stage left
128off.
129
130Note that TPL and SPL do not supports commands as yet, so the vboot code is
131called directly from the SPL boot devices (BOOT_DEVICE_CROS_VBOOT). See
132cros_load_image_tpl() and cros_load_image_spl() which both call
133vboot_run_auto().
134
135
136Config options
137--------------
138
139The main option is CONFIG_CHROMEOS, which enables a wide array of other options
140so that the required features are present.
141
142
143Device-tree config
144------------------
145
146Various options are available which control the operation of verified boot.
147See cros/dts/bindings/config.txt for details. Most config is handled at run-
148time, although build-time config (with Kconfig) could also be added fairly
149easily.
150
151
152Porting to other hardware
153-------------------------
154
155A basic port to samus (Chromebook Pixel 2015) is in a basic working state,
156using the chromeos_samus target. Patches will likely be forthcoming in early
1572019. Ports to an ARM board and coreboot (for x86 Chromebooks) are in the
158dreaming state.
159
160
161Tests
162-----
163
164Chromium OS firmware has a very limited set of tests. The tests that originally
165existed in U-Boot were not brought over to coreboot or depthcharge.
166
167The U-Boot tests ('make check') do operate, but at present there are no
168Chromium OS tests available. These will hopefully come together over time. Of
169course the above sandbox feature provides a sort of functional test and can
170detect problems that affect the flow or particular vboot features.
171
172
173U-Boot without Chromium OS verified boot
174----------------------------------------
175
176The following script can be used to boot a Chrome OS image on coral. It is
177defined as the boot command in mainline::
178
179   # Read the image header and obtain the address of the kernel
180   # The offset 4f0 is defined by verified boot and may change for other
181   # Chromebooks
182   read mmc 2:2 100000 0 80; setexpr loader *001004f0;
183
184   # Get the kernel size and calculate the number of blocks (0x200 bytes each)
185   setexpr size *00100518; setexpr blocks $size / 200;
186
187   # Read the full kernel and calculate the address of the setup block
188   read mmc 2:2 100000 80 $blocks; setexpr setup $loader - 1000;
189
190   # Locate the command line
191   setexpr cmdline $loader - 2000;
192
193   # Start the zboot process with the loaded kernel, setup block and cmdline
194   zboot start 100000 0 0 0 $setup $cmdline;
195
196   # Load the kernel, fix up the 'setup' block, dump information
197   zboot load; zboot setup; zboot dump
198
199   # Boot into Chrome OS
200   zboot go
201
202
2037 October 2018
204