]> git.ipfire.org Git - people/ms/u-boot.git/blob - board/sandbox/README.sandbox
Merge git://git.denx.de/u-boot-dm
[people/ms/u-boot.git] / board / sandbox / README.sandbox
1 /*
2 * Copyright (c) 2014 The Chromium OS Authors.
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7 Native Execution of U-Boot
8 ==========================
9
10 The 'sandbox' architecture is designed to allow U-Boot to run under Linux on
11 almost any hardware. To achieve this it builds U-Boot (so far as possible)
12 as a normal C application with a main() and normal C libraries.
13
14 All of U-Boot's architecture-specific code therefore cannot be built as part
15 of the sandbox U-Boot. The purpose of running U-Boot under Linux is to test
16 all the generic code, not specific to any one architecture. The idea is to
17 create unit tests which we can run to test this upper level code.
18
19 CONFIG_SANDBOX is defined when building a native board.
20
21 The board name is 'sandbox' but the vendor name is unset, so there is a
22 single board in board/sandbox.
23
24 CONFIG_SANDBOX_BIG_ENDIAN should be defined when running on big-endian
25 machines.
26
27 There are two versions of the sandbox: One using 32-bit-wide integers, and one
28 using 64-bit-wide integers. The 32-bit version can be build and run on either
29 32 or 64-bit hosts by either selecting or deselecting CONFIG_SANDBOX_32BIT; by
30 default, the sandbox it built for a 32-bit host. The sandbox using 64-bit-wide
31 integers can only be built on 64-bit hosts.
32
33 Note that standalone/API support is not available at present.
34
35
36 Basic Operation
37 ---------------
38
39 To run sandbox U-Boot use something like:
40
41 make sandbox_defconfig all
42 ./u-boot
43
44 Note:
45 If you get errors about 'sdl-config: Command not found' you may need to
46 install libsdl1.2-dev or similar to get SDL support. Alternatively you can
47 build sandbox without SDL (i.e. no display/keyboard support) by removing
48 the CONFIG_SANDBOX_SDL line in include/configs/sandbox.h or using:
49
50 make sandbox_defconfig all NO_SDL=1
51 ./u-boot
52
53 U-Boot will start on your computer, showing a sandbox emulation of the serial
54 console:
55
56
57 U-Boot 2014.04 (Mar 20 2014 - 19:06:00)
58
59 DRAM: 128 MiB
60 Using default environment
61
62 In: serial
63 Out: lcd
64 Err: lcd
65 =>
66
67 You can issue commands as your would normally. If the command you want is
68 not supported you can add it to include/configs/sandbox.h.
69
70 To exit, type 'reset' or press Ctrl-C.
71
72
73 Console / LCD support
74 ---------------------
75
76 Assuming that CONFIG_SANDBOX_SDL is defined when building, you can run the
77 sandbox with LCD and keyboard emulation, using something like:
78
79 ./u-boot -d u-boot.dtb -l
80
81 This will start U-Boot with a window showing the contents of the LCD. If
82 that window has the focus then you will be able to type commands as you
83 would on the console. You can adjust the display settings in the device
84 tree file - see arch/sandbox/dts/sandbox.dts.
85
86
87 Command-line Options
88 --------------------
89
90 Various options are available, mostly for test purposes. Use -h to see
91 available options. Some of these are described below.
92
93 The terminal is normally in what is called 'raw-with-sigs' mode. This means
94 that you can use arrow keys for command editing and history, but if you
95 press Ctrl-C, U-Boot will exit instead of handling this as a keypress.
96
97 Other options are 'raw' (so Ctrl-C is handled within U-Boot) and 'cooked'
98 (where the terminal is in cooked mode and cursor keys will not work, Ctrl-C
99 will exit).
100
101 As mentioned above, -l causes the LCD emulation window to be shown.
102
103 A device tree binary file can be provided with -d. If you edit the source
104 (it is stored at arch/sandbox/dts/sandbox.dts) you must rebuild U-Boot to
105 recreate the binary file.
106
107 To execute commands directly, use the -c option. You can specify a single
108 command, or multiple commands separated by a semicolon, as is normal in
109 U-Boot. Be careful with quoting as the shall will normally process and
110 swallow quotes. When -c is used, U-Boot exists after the command is complete,
111 but you can force it to go to interactive mode instead with -i.
112
113
114 Memory Emulation
115 ----------------
116
117 Memory emulation is supported, with the size set by CONFIG_SYS_SDRAM_SIZE.
118 The -m option can be used to read memory from a file on start-up and write
119 it when shutting down. This allows preserving of memory contents across
120 test runs. You can tell U-Boot to remove the memory file after it is read
121 (on start-up) with the --rm_memory option.
122
123 To access U-Boot's emulated memory within the code, use map_sysmem(). This
124 function is used throughout U-Boot to ensure that emulated memory is used
125 rather than the U-Boot application memory. This provides memory starting
126 at 0 and extending to the size of the emulation.
127
128
129 Storing State
130 -------------
131
132 With sandbox you can write drivers which emulate the operation of drivers on
133 real devices. Some of these drivers may want to record state which is
134 preserved across U-Boot runs. This is particularly useful for testing. For
135 example, the contents of a SPI flash chip should not disappear just because
136 U-Boot exits.
137
138 State is stored in a device tree file in a simple format which is driver-
139 specific. You then use the -s option to specify the state file. Use -r to
140 make U-Boot read the state on start-up (otherwise it starts empty) and -w
141 to write it on exit (otherwise the stored state is left unchanged and any
142 changes U-Boot made will be lost). You can also use -n to tell U-Boot to
143 ignore any problems with missing state. This is useful when first running
144 since the state file will be empty.
145
146 The device tree file has one node for each driver - the driver can store
147 whatever properties it likes in there. See 'Writing Sandbox Drivers' below
148 for more details on how to get drivers to read and write their state.
149
150
151 Running and Booting
152 -------------------
153
154 Since there is no machine architecture, sandbox U-Boot cannot actually boot
155 a kernel, but it does support the bootm command. Filesystems, memory
156 commands, hashing, FIT images, verified boot and many other features are
157 supported.
158
159 When 'bootm' runs a kernel, sandbox will exit, as U-Boot does on a real
160 machine. Of course in this case, no kernel is run.
161
162 It is also possible to tell U-Boot that it has jumped from a temporary
163 previous U-Boot binary, with the -j option. That binary is automatically
164 removed by the U-Boot that gets the -j option. This allows you to write
165 tests which emulate the action of chain-loading U-Boot, typically used in
166 a situation where a second 'updatable' U-Boot is stored on your board. It
167 is very risky to overwrite or upgrade the only U-Boot on a board, since a
168 power or other failure will brick the board and require return to the
169 manufacturer in the case of a consumer device.
170
171
172 Supported Drivers
173 -----------------
174
175 U-Boot sandbox supports these emulations:
176
177 - Block devices
178 - Chrome OS EC
179 - GPIO
180 - Host filesystem (access files on the host from within U-Boot)
181 - I2C
182 - Keyboard (Chrome OS)
183 - LCD
184 - Network
185 - Serial (for console only)
186 - Sound (incomplete - see sandbox_sdl_sound_init() for details)
187 - SPI
188 - SPI flash
189 - TPM (Trusted Platform Module)
190
191 A wide range of commands is implemented. Filesystems which use a block
192 device are supported.
193
194 Also sandbox supports driver model (CONFIG_DM) and associated commands.
195
196
197 Linux RAW Networking Bridge
198 ---------------------------
199
200 The sandbox_eth_raw driver bridges traffic between the bottom of the network
201 stack and the RAW sockets API in Linux. This allows much of the U-Boot network
202 functionality to be tested in sandbox against real network traffic.
203
204 For Ethernet network adapters, the bridge utilizes the RAW AF_PACKET API. This
205 is needed to get access to the lowest level of the network stack in Linux. This
206 means that all of the Ethernet frame is included. This allows the U-Boot network
207 stack to be fully used. In other words, nothing about the Linux network stack is
208 involved in forming the packets that end up on the wire. To receive the
209 responses to packets sent from U-Boot the network interface has to be set to
210 promiscuous mode so that the network card won't filter out packets not destined
211 for its configured (on Linux) MAC address.
212
213 The RAW sockets Ethernet API requires elevated privileges in Linux. You can
214 either run as root, or you can add the capability needed like so:
215
216 sudo /sbin/setcap "CAP_NET_RAW+ep" /path/to/u-boot
217
218 The default device tree for sandbox includes an entry for eth0 on the sandbox
219 host machine whose alias is "eth1". The following are a few examples of network
220 operations being tested on the eth0 interface.
221
222 sudo /path/to/u-boot -D
223
224 DHCP
225 ....
226
227 set autoload no
228 set ethact eth1
229 dhcp
230
231 PING
232 ....
233
234 set autoload no
235 set ethact eth1
236 dhcp
237 ping $gatewayip
238
239 TFTP
240 ....
241
242 set autoload no
243 set ethact eth1
244 dhcp
245 set serverip WWW.XXX.YYY.ZZZ
246 tftpboot u-boot.bin
247
248 The bridge also support (to a lesser extent) the localhost inderface, 'lo'.
249
250 The 'lo' interface cannot use the RAW AF_PACKET API because the lo interface
251 doesn't support Ethernet-level traffic. It is a higher-level interface that is
252 expected only to be used at the AF_INET level of the API. As such, the most raw
253 we can get on that interface is the RAW AF_INET API on UDP. This allows us to
254 set the IP_HDRINCL option to include everything except the Ethernet header in
255 the packets we send and receive.
256
257 Because only UDP is supported, ICMP traffic will not work, so expect that ping
258 commands will time out.
259
260 The default device tree for sandbox includes an entry for lo on the sandbox
261 host machine whose alias is "eth5". The following is an example of a network
262 operation being tested on the lo interface.
263
264 TFTP
265 ....
266
267 set ethact eth5
268 tftpboot u-boot.bin
269
270
271 SPI Emulation
272 -------------
273
274 Sandbox supports SPI and SPI flash emulation.
275
276 This is controlled by the spi_sf argument, the format of which is:
277
278 bus:cs:device:file
279
280 bus - SPI bus number
281 cs - SPI chip select number
282 device - SPI device emulation name
283 file - File on disk containing the data
284
285 For example:
286
287 dd if=/dev/zero of=spi.bin bs=1M count=4
288 ./u-boot --spi_sf 0:0:M25P16:spi.bin
289
290 With this setup you can issue SPI flash commands as normal:
291
292 =>sf probe
293 SF: Detected M25P16 with page size 64 KiB, total 2 MiB
294 =>sf read 0 0 10000
295 SF: 65536 bytes @ 0x0 Read: OK
296 =>
297
298 Since this is a full SPI emulation (rather than just flash), you can
299 also use low-level SPI commands:
300
301 =>sspi 0:0 32 9f
302 FF202015
303
304 This is issuing a READ_ID command and getting back 20 (ST Micro) part
305 0x2015 (the M25P16).
306
307 Drivers are connected to a particular bus/cs using sandbox's state
308 structure (see the 'spi' member). A set of operations must be provided
309 for each driver.
310
311
312 Configuration settings for the curious are:
313
314 CONFIG_SANDBOX_SPI_MAX_BUS
315 The maximum number of SPI buses supported by the driver (default 1).
316
317 CONFIG_SANDBOX_SPI_MAX_CS
318 The maximum number of chip selects supported by the driver
319 (default 10).
320
321 CONFIG_SPI_IDLE_VAL
322 The idle value on the SPI bus
323
324
325 Block Device Emulation
326 ----------------------
327
328 U-Boot can use raw disk images for block device emulation. To e.g. list
329 the contents of the root directory on the second partion of the image
330 "disk.raw", you can use the following commands:
331
332 =>host bind 0 ./disk.raw
333 =>ls host 0:2
334
335 A disk image can be created using the following commands:
336
337 $> truncate -s 1200M ./disk.raw
338 $> echo -e "label: gpt\n,64M,U\n,,L" | /usr/sbin/sgdisk ./disk.raw
339 $> lodev=`sudo losetup -P -f --show ./disk.raw`
340 $> sudo mkfs.vfat -n EFI -v ${lodev}p1
341 $> sudo mkfs.ext4 -L ROOT -v ${lodev}p2
342
343 or utilize the device described in test/py/make_test_disk.py:
344
345 #!/usr/bin/python
346 import make_test_disk
347 make_test_disk.makeDisk()
348
349 Writing Sandbox Drivers
350 -----------------------
351
352 Generally you should put your driver in a file containing the word 'sandbox'
353 and put it in the same directory as other drivers of its type. You can then
354 implement the same hooks as the other drivers.
355
356 To access U-Boot's emulated memory, use map_sysmem() as mentioned above.
357
358 If your driver needs to store configuration or state (such as SPI flash
359 contents or emulated chip registers), you can use the device tree as
360 described above. Define handlers for this with the SANDBOX_STATE_IO macro.
361 See arch/sandbox/include/asm/state.h for documentation. In short you provide
362 a node name, compatible string and functions to read and write the state.
363 Since writing the state can expand the device tree, you may need to use
364 state_setprop() which does this automatically and avoids running out of
365 space. See existing code for examples.
366
367
368 Testing
369 -------
370
371 U-Boot sandbox can be used to run various tests, mostly in the test/
372 directory. These include:
373
374 command_ut
375 - Unit tests for command parsing and handling
376 compression
377 - Unit tests for U-Boot's compression algorithms, useful for
378 security checking. It supports gzip, bzip2, lzma and lzo.
379 driver model
380 - Run this pytest
381 ./test/py/test.py --bd sandbox --build -k ut_dm -v
382 image
383 - Unit tests for images:
384 test/image/test-imagetools.sh - multi-file images
385 test/image/test-fit.py - FIT images
386 tracing
387 - test/trace/test-trace.sh tests the tracing system (see README.trace)
388 verified boot
389 - See test/vboot/vboot_test.sh for this
390
391 If you change or enhance any of the above subsystems, you shold write or
392 expand a test and include it with your patch series submission. Test
393 coverage in U-Boot is limited, as we need to work to improve it.
394
395 Note that many of these tests are implemented as commands which you can
396 run natively on your board if desired (and enabled).
397
398 It would be useful to have a central script to run all of these.
399
400 --
401 Simon Glass <sjg@chromium.org>
402 Updated 22-Mar-14