xref: /openbmc/u-boot/board/sandbox/README.sandbox (revision 2dabac1337facbdef20d1a9bf54b68225d2518dc)
1*2dabac13SMasahiro Yamada/*
2*2dabac13SMasahiro Yamada * Copyright (c) 2014 The Chromium OS Authors.
3*2dabac13SMasahiro Yamada *
4*2dabac13SMasahiro Yamada * SPDX-License-Identifier:	GPL-2.0+
5*2dabac13SMasahiro Yamada */
6*2dabac13SMasahiro Yamada
7*2dabac13SMasahiro YamadaNative Execution of U-Boot
8*2dabac13SMasahiro Yamada==========================
9*2dabac13SMasahiro Yamada
10*2dabac13SMasahiro YamadaThe 'sandbox' architecture is designed to allow U-Boot to run under Linux on
11*2dabac13SMasahiro Yamadaalmost any hardware. To achieve this it builds U-Boot (so far as possible)
12*2dabac13SMasahiro Yamadaas a normal C application with a main() and normal C libraries.
13*2dabac13SMasahiro Yamada
14*2dabac13SMasahiro YamadaAll of U-Boot's architecture-specific code therefore cannot be built as part
15*2dabac13SMasahiro Yamadaof the sandbox U-Boot. The purpose of running U-Boot under Linux is to test
16*2dabac13SMasahiro Yamadaall the generic code, not specific to any one architecture. The idea is to
17*2dabac13SMasahiro Yamadacreate unit tests which we can run to test this upper level code.
18*2dabac13SMasahiro Yamada
19*2dabac13SMasahiro YamadaCONFIG_SANDBOX is defined when building a native board.
20*2dabac13SMasahiro Yamada
21*2dabac13SMasahiro YamadaThe chosen vendor and board names are also 'sandbox', so there is a single
22*2dabac13SMasahiro Yamadaboard in board/sandbox/sandbox.
23*2dabac13SMasahiro Yamada
24*2dabac13SMasahiro YamadaCONFIG_SANDBOX_BIG_ENDIAN should be defined when running on big-endian
25*2dabac13SMasahiro Yamadamachines.
26*2dabac13SMasahiro Yamada
27*2dabac13SMasahiro YamadaNote that standalone/API support is not available at present.
28*2dabac13SMasahiro Yamada
29*2dabac13SMasahiro Yamada
30*2dabac13SMasahiro YamadaBasic Operation
31*2dabac13SMasahiro Yamada---------------
32*2dabac13SMasahiro Yamada
33*2dabac13SMasahiro YamadaTo run sandbox U-Boot use something like:
34*2dabac13SMasahiro Yamada
35*2dabac13SMasahiro Yamada   make sandbox_config all
36*2dabac13SMasahiro Yamada   ./u-boot
37*2dabac13SMasahiro Yamada
38*2dabac13SMasahiro YamadaNote:
39*2dabac13SMasahiro Yamada   If you get errors about 'sdl-config: Command not found' you may need to
40*2dabac13SMasahiro Yamada   install libsdl1.2-dev or similar to get SDL support. Alternatively you can
41*2dabac13SMasahiro Yamada   build sandbox without SDL (i.e. no display/keyboard support) by removing
42*2dabac13SMasahiro Yamada   the CONFIG_SANDBOX_SDL line in include/configs/sandbox.h or using:
43*2dabac13SMasahiro Yamada
44*2dabac13SMasahiro Yamada      make sandbox_config all NO_SDL=1
45*2dabac13SMasahiro Yamada      ./u-boot
46*2dabac13SMasahiro Yamada
47*2dabac13SMasahiro Yamada
48*2dabac13SMasahiro YamadaU-Boot will start on your computer, showing a sandbox emulation of the serial
49*2dabac13SMasahiro Yamadaconsole:
50*2dabac13SMasahiro Yamada
51*2dabac13SMasahiro Yamada
52*2dabac13SMasahiro YamadaU-Boot 2014.04 (Mar 20 2014 - 19:06:00)
53*2dabac13SMasahiro Yamada
54*2dabac13SMasahiro YamadaDRAM:  128 MiB
55*2dabac13SMasahiro YamadaUsing default environment
56*2dabac13SMasahiro Yamada
57*2dabac13SMasahiro YamadaIn:    serial
58*2dabac13SMasahiro YamadaOut:   lcd
59*2dabac13SMasahiro YamadaErr:   lcd
60*2dabac13SMasahiro Yamada=>
61*2dabac13SMasahiro Yamada
62*2dabac13SMasahiro YamadaYou can issue commands as your would normally. If the command you want is
63*2dabac13SMasahiro Yamadanot supported you can add it to include/configs/sandbox.h.
64*2dabac13SMasahiro Yamada
65*2dabac13SMasahiro YamadaTo exit, type 'reset' or press Ctrl-C.
66*2dabac13SMasahiro Yamada
67*2dabac13SMasahiro Yamada
68*2dabac13SMasahiro YamadaConsole / LCD support
69*2dabac13SMasahiro Yamada---------------------
70*2dabac13SMasahiro Yamada
71*2dabac13SMasahiro YamadaAssuming that CONFIG_SANDBOX_SDL is defined when building, you can run the
72*2dabac13SMasahiro Yamadasandbox with LCD and keyboard emulation, using something like:
73*2dabac13SMasahiro Yamada
74*2dabac13SMasahiro Yamada   ./u-boot -d u-boot.dtb -l
75*2dabac13SMasahiro Yamada
76*2dabac13SMasahiro YamadaThis will start U-Boot with a window showing the contents of the LCD. If
77*2dabac13SMasahiro Yamadathat window has the focus then you will be able to type commands as you
78*2dabac13SMasahiro Yamadawould on the console. You can adjust the display settings in the device
79*2dabac13SMasahiro Yamadatree file - see arch/sandbox/dts/sandbox.dts.
80*2dabac13SMasahiro Yamada
81*2dabac13SMasahiro Yamada
82*2dabac13SMasahiro YamadaCommand-line Options
83*2dabac13SMasahiro Yamada--------------------
84*2dabac13SMasahiro Yamada
85*2dabac13SMasahiro YamadaVarious options are available, mostly for test purposes. Use -h to see
86*2dabac13SMasahiro Yamadaavailable options. Some of these are described below.
87*2dabac13SMasahiro Yamada
88*2dabac13SMasahiro YamadaThe terminal is normally in what is called 'raw-with-sigs' mode. This means
89*2dabac13SMasahiro Yamadathat you can use arrow keys for command editing and history, but if you
90*2dabac13SMasahiro Yamadapress Ctrl-C, U-Boot will exit instead of handling this as a keypress.
91*2dabac13SMasahiro Yamada
92*2dabac13SMasahiro YamadaOther options are 'raw' (so Ctrl-C is handled within U-Boot) and 'cooked'
93*2dabac13SMasahiro Yamada(where the terminal is in cooked mode and cursor keys will not work, Ctrl-C
94*2dabac13SMasahiro Yamadawill exit).
95*2dabac13SMasahiro Yamada
96*2dabac13SMasahiro YamadaAs mentioned above, -l causes the LCD emulation window to be shown.
97*2dabac13SMasahiro Yamada
98*2dabac13SMasahiro YamadaA device tree binary file can be provided with -d. If you edit the source
99*2dabac13SMasahiro Yamada(it is stored at arch/sandbox/dts/sandbox.dts) you must rebuild U-Boot to
100*2dabac13SMasahiro Yamadarecreate the binary file.
101*2dabac13SMasahiro Yamada
102*2dabac13SMasahiro YamadaTo execute commands directly, use the -c option. You can specify a single
103*2dabac13SMasahiro Yamadacommand, or multiple commands separated by a semicolon, as is normal in
104*2dabac13SMasahiro YamadaU-Boot. Be careful with quoting as the shall will normally process and
105*2dabac13SMasahiro Yamadaswallow quotes. When -c is used, U-Boot exists after the command is complete,
106*2dabac13SMasahiro Yamadabut you can force it to go to interactive mode instead with -i.
107*2dabac13SMasahiro Yamada
108*2dabac13SMasahiro Yamada
109*2dabac13SMasahiro YamadaMemory Emulation
110*2dabac13SMasahiro Yamada----------------
111*2dabac13SMasahiro Yamada
112*2dabac13SMasahiro YamadaMemory emulation is supported, with the size set by CONFIG_SYS_SDRAM_SIZE.
113*2dabac13SMasahiro YamadaThe -m option can be used to read memory from a file on start-up and write
114*2dabac13SMasahiro Yamadait when shutting down. This allows preserving of memory contents across
115*2dabac13SMasahiro Yamadatest runs. You can tell U-Boot to remove the memory file after it is read
116*2dabac13SMasahiro Yamada(on start-up) with the --rm_memory option.
117*2dabac13SMasahiro Yamada
118*2dabac13SMasahiro YamadaTo access U-Boot's emulated memory within the code, use map_sysmem(). This
119*2dabac13SMasahiro Yamadafunction is used throughout U-Boot to ensure that emulated memory is used
120*2dabac13SMasahiro Yamadarather than the U-Boot application memory. This provides memory starting
121*2dabac13SMasahiro Yamadaat 0 and extending to the size of the emulation.
122*2dabac13SMasahiro Yamada
123*2dabac13SMasahiro Yamada
124*2dabac13SMasahiro YamadaStoring State
125*2dabac13SMasahiro Yamada-------------
126*2dabac13SMasahiro Yamada
127*2dabac13SMasahiro YamadaWith sandbox you can write drivers which emulate the operation of drivers on
128*2dabac13SMasahiro Yamadareal devices. Some of these drivers may want to record state which is
129*2dabac13SMasahiro Yamadapreserved across U-Boot runs. This is particularly useful for testing. For
130*2dabac13SMasahiro Yamadaexample, the contents of a SPI flash chip should not disappear just because
131*2dabac13SMasahiro YamadaU-Boot exits.
132*2dabac13SMasahiro Yamada
133*2dabac13SMasahiro YamadaState is stored in a device tree file in a simple format which is driver-
134*2dabac13SMasahiro Yamadaspecific. You then use the -s option to specify the state file. Use -r to
135*2dabac13SMasahiro Yamadamake U-Boot read the state on start-up (otherwise it starts empty) and -w
136*2dabac13SMasahiro Yamadato write it on exit (otherwise the stored state is left unchanged and any
137*2dabac13SMasahiro Yamadachanges U-Boot made will be lost). You can also use -n to tell U-Boot to
138*2dabac13SMasahiro Yamadaignore any problems with missing state. This is useful when first running
139*2dabac13SMasahiro Yamadasince the state file will be empty.
140*2dabac13SMasahiro Yamada
141*2dabac13SMasahiro YamadaThe device tree file has one node for each driver - the driver can store
142*2dabac13SMasahiro Yamadawhatever properties it likes in there. See 'Writing Sandbox Drivers' below
143*2dabac13SMasahiro Yamadafor more details on how to get drivers to read and write their state.
144*2dabac13SMasahiro Yamada
145*2dabac13SMasahiro Yamada
146*2dabac13SMasahiro YamadaRunning and Booting
147*2dabac13SMasahiro Yamada-------------------
148*2dabac13SMasahiro Yamada
149*2dabac13SMasahiro YamadaSince there is no machine architecture, sandbox U-Boot cannot actually boot
150*2dabac13SMasahiro Yamadaa kernel, but it does support the bootm command. Filesystems, memory
151*2dabac13SMasahiro Yamadacommands, hashing, FIT images, verified boot and many other features are
152*2dabac13SMasahiro Yamadasupported.
153*2dabac13SMasahiro Yamada
154*2dabac13SMasahiro YamadaWhen 'bootm' runs a kernel, sandbox will exit, as U-Boot does on a real
155*2dabac13SMasahiro Yamadamachine. Of course in this case, no kernel is run.
156*2dabac13SMasahiro Yamada
157*2dabac13SMasahiro YamadaIt is also possible to tell U-Boot that it has jumped from a temporary
158*2dabac13SMasahiro Yamadaprevious U-Boot binary, with the -j option. That binary is automatically
159*2dabac13SMasahiro Yamadaremoved by the U-Boot that gets the -j option. This allows you to write
160*2dabac13SMasahiro Yamadatests which emulate the action of chain-loading U-Boot, typically used in
161*2dabac13SMasahiro Yamadaa situation where a second 'updatable' U-Boot is stored on your board. It
162*2dabac13SMasahiro Yamadais very risky to overwrite or upgrade the only U-Boot on a board, since a
163*2dabac13SMasahiro Yamadapower or other failure will brick the board and require return to the
164*2dabac13SMasahiro Yamadamanufacturer in the case of a consumer device.
165*2dabac13SMasahiro Yamada
166*2dabac13SMasahiro Yamada
167*2dabac13SMasahiro YamadaSupported Drivers
168*2dabac13SMasahiro Yamada-----------------
169*2dabac13SMasahiro Yamada
170*2dabac13SMasahiro YamadaU-Boot sandbox supports these emulations:
171*2dabac13SMasahiro Yamada
172*2dabac13SMasahiro Yamada- Block devices
173*2dabac13SMasahiro Yamada- Chrome OS EC
174*2dabac13SMasahiro Yamada- GPIO
175*2dabac13SMasahiro Yamada- Host filesystem (access files on the host from within U-Boot)
176*2dabac13SMasahiro Yamada- Keyboard (Chrome OS)
177*2dabac13SMasahiro Yamada- LCD
178*2dabac13SMasahiro Yamada- Serial (for console only)
179*2dabac13SMasahiro Yamada- Sound (incomplete - see sandbox_sdl_sound_init() for details)
180*2dabac13SMasahiro Yamada- SPI
181*2dabac13SMasahiro Yamada- SPI flash
182*2dabac13SMasahiro Yamada- TPM (Trusted Platform Module)
183*2dabac13SMasahiro Yamada
184*2dabac13SMasahiro YamadaNotable omissions are networking and I2C.
185*2dabac13SMasahiro Yamada
186*2dabac13SMasahiro YamadaA wide range of commands is implemented. Filesystems which use a block
187*2dabac13SMasahiro Yamadadevice are supported.
188*2dabac13SMasahiro Yamada
189*2dabac13SMasahiro YamadaAlso sandbox uses generic board (CONFIG_SYS_GENERIC_BOARD) and supports
190*2dabac13SMasahiro Yamadadriver model (CONFIG_DM) and associated commands.
191*2dabac13SMasahiro Yamada
192*2dabac13SMasahiro Yamada
193*2dabac13SMasahiro YamadaSPI Emulation
194*2dabac13SMasahiro Yamada-------------
195*2dabac13SMasahiro Yamada
196*2dabac13SMasahiro YamadaSandbox supports SPI and SPI flash emulation.
197*2dabac13SMasahiro Yamada
198*2dabac13SMasahiro YamadaThis is controlled by the spi_sf argument, the format of which is:
199*2dabac13SMasahiro Yamada
200*2dabac13SMasahiro Yamada   bus:cs:device:file
201*2dabac13SMasahiro Yamada
202*2dabac13SMasahiro Yamada   bus    - SPI bus number
203*2dabac13SMasahiro Yamada   cs     - SPI chip select number
204*2dabac13SMasahiro Yamada   device - SPI device emulation name
205*2dabac13SMasahiro Yamada   file   - File on disk containing the data
206*2dabac13SMasahiro Yamada
207*2dabac13SMasahiro YamadaFor example:
208*2dabac13SMasahiro Yamada
209*2dabac13SMasahiro Yamada dd if=/dev/zero of=spi.bin bs=1M count=4
210*2dabac13SMasahiro Yamada ./u-boot --spi_sf 0:0:M25P16:spi.bin
211*2dabac13SMasahiro Yamada
212*2dabac13SMasahiro YamadaWith this setup you can issue SPI flash commands as normal:
213*2dabac13SMasahiro Yamada
214*2dabac13SMasahiro Yamada=>sf probe
215*2dabac13SMasahiro YamadaSF: Detected M25P16 with page size 64 KiB, total 2 MiB
216*2dabac13SMasahiro Yamada=>sf read 0 0 10000
217*2dabac13SMasahiro YamadaSF: 65536 bytes @ 0x0 Read: OK
218*2dabac13SMasahiro Yamada=>
219*2dabac13SMasahiro Yamada
220*2dabac13SMasahiro YamadaSince this is a full SPI emulation (rather than just flash), you can
221*2dabac13SMasahiro Yamadaalso use low-level SPI commands:
222*2dabac13SMasahiro Yamada
223*2dabac13SMasahiro Yamada=>sspi 0:0 32 9f
224*2dabac13SMasahiro YamadaFF202015
225*2dabac13SMasahiro Yamada
226*2dabac13SMasahiro YamadaThis is issuing a READ_ID command and getting back 20 (ST Micro) part
227*2dabac13SMasahiro Yamada0x2015 (the M25P16).
228*2dabac13SMasahiro Yamada
229*2dabac13SMasahiro YamadaDrivers are connected to a particular bus/cs using sandbox's state
230*2dabac13SMasahiro Yamadastructure (see the 'spi' member). A set of operations must be provided
231*2dabac13SMasahiro Yamadafor each driver.
232*2dabac13SMasahiro Yamada
233*2dabac13SMasahiro Yamada
234*2dabac13SMasahiro YamadaConfiguration settings for the curious are:
235*2dabac13SMasahiro Yamada
236*2dabac13SMasahiro YamadaCONFIG_SANDBOX_SPI_MAX_BUS
237*2dabac13SMasahiro Yamada	The maximum number of SPI buses supported by the driver (default 1).
238*2dabac13SMasahiro Yamada
239*2dabac13SMasahiro YamadaCONFIG_SANDBOX_SPI_MAX_CS
240*2dabac13SMasahiro Yamada	The maximum number of chip selects supported by the driver
241*2dabac13SMasahiro Yamada	(default 10).
242*2dabac13SMasahiro Yamada
243*2dabac13SMasahiro YamadaCONFIG_SPI_IDLE_VAL
244*2dabac13SMasahiro Yamada	The idle value on the SPI bus
245*2dabac13SMasahiro Yamada
246*2dabac13SMasahiro Yamada
247*2dabac13SMasahiro YamadaWriting Sandbox Drivers
248*2dabac13SMasahiro Yamada-----------------------
249*2dabac13SMasahiro Yamada
250*2dabac13SMasahiro YamadaGenerally you should put your driver in a file containing the word 'sandbox'
251*2dabac13SMasahiro Yamadaand put it in the same directory as other drivers of its type. You can then
252*2dabac13SMasahiro Yamadaimplement the same hooks as the other drivers.
253*2dabac13SMasahiro Yamada
254*2dabac13SMasahiro YamadaTo access U-Boot's emulated memory, use map_sysmem() as mentioned above.
255*2dabac13SMasahiro Yamada
256*2dabac13SMasahiro YamadaIf your driver needs to store configuration or state (such as SPI flash
257*2dabac13SMasahiro Yamadacontents or emulated chip registers), you can use the device tree as
258*2dabac13SMasahiro Yamadadescribed above. Define handlers for this with the SANDBOX_STATE_IO macro.
259*2dabac13SMasahiro YamadaSee arch/sandbox/include/asm/state.h for documentation. In short you provide
260*2dabac13SMasahiro Yamadaa node name, compatible string and functions to read and write the state.
261*2dabac13SMasahiro YamadaSince writing the state can expand the device tree, you may need to use
262*2dabac13SMasahiro Yamadastate_setprop() which does this automatically and avoids running out of
263*2dabac13SMasahiro Yamadaspace. See existing code for examples.
264*2dabac13SMasahiro Yamada
265*2dabac13SMasahiro Yamada
266*2dabac13SMasahiro YamadaTesting
267*2dabac13SMasahiro Yamada-------
268*2dabac13SMasahiro Yamada
269*2dabac13SMasahiro YamadaU-Boot sandbox can be used to run various tests, mostly in the test/
270*2dabac13SMasahiro Yamadadirectory. These include:
271*2dabac13SMasahiro Yamada
272*2dabac13SMasahiro Yamada  command_ut
273*2dabac13SMasahiro Yamada     - Unit tests for command parsing and handling
274*2dabac13SMasahiro Yamada  compression
275*2dabac13SMasahiro Yamada     - Unit tests for U-Boot's compression algorithms, useful for
276*2dabac13SMasahiro Yamada       security checking. It supports gzip, bzip2, lzma and lzo.
277*2dabac13SMasahiro Yamada  driver model
278*2dabac13SMasahiro Yamada     - test/dm/test-dm.sh to run these.
279*2dabac13SMasahiro Yamada  image
280*2dabac13SMasahiro Yamada     - Unit tests for images:
281*2dabac13SMasahiro Yamada          test/image/test-imagetools.sh - multi-file images
282*2dabac13SMasahiro Yamada          test/image/test-fit.py        - FIT images
283*2dabac13SMasahiro Yamada  tracing
284*2dabac13SMasahiro Yamada     - test/trace/test-trace.sh tests the tracing system (see README.trace)
285*2dabac13SMasahiro Yamada  verified boot
286*2dabac13SMasahiro Yamada      - See test/vboot/vboot_test.sh for this
287*2dabac13SMasahiro Yamada
288*2dabac13SMasahiro YamadaIf you change or enhance any of the above subsystems, you shold write or
289*2dabac13SMasahiro Yamadaexpand a test and include it with your patch series submission. Test
290*2dabac13SMasahiro Yamadacoverage in U-Boot is limited, as we need to work to improve it.
291*2dabac13SMasahiro Yamada
292*2dabac13SMasahiro YamadaNote that many of these tests are implemented as commands which you can
293*2dabac13SMasahiro Yamadarun natively on your board if desired (and enabled).
294*2dabac13SMasahiro Yamada
295*2dabac13SMasahiro YamadaIt would be useful to have a central script to run all of these.
296*2dabac13SMasahiro Yamada
297*2dabac13SMasahiro Yamada--
298*2dabac13SMasahiro YamadaSimon Glass <sjg@chromium.org>
299*2dabac13SMasahiro YamadaUpdated 22-Mar-14
300