xref: /openbmc/u-boot/board/sandbox/README.sandbox (revision 3ea143abe957cd771582fcde33e5fb8096bd826e)
12dabac13SMasahiro Yamada/*
22dabac13SMasahiro Yamada * Copyright (c) 2014 The Chromium OS Authors.
32dabac13SMasahiro Yamada *
42dabac13SMasahiro Yamada * SPDX-License-Identifier:	GPL-2.0+
52dabac13SMasahiro Yamada */
62dabac13SMasahiro Yamada
72dabac13SMasahiro YamadaNative Execution of U-Boot
82dabac13SMasahiro Yamada==========================
92dabac13SMasahiro Yamada
102dabac13SMasahiro YamadaThe 'sandbox' architecture is designed to allow U-Boot to run under Linux on
112dabac13SMasahiro Yamadaalmost any hardware. To achieve this it builds U-Boot (so far as possible)
122dabac13SMasahiro Yamadaas a normal C application with a main() and normal C libraries.
132dabac13SMasahiro Yamada
142dabac13SMasahiro YamadaAll of U-Boot's architecture-specific code therefore cannot be built as part
152dabac13SMasahiro Yamadaof the sandbox U-Boot. The purpose of running U-Boot under Linux is to test
162dabac13SMasahiro Yamadaall the generic code, not specific to any one architecture. The idea is to
172dabac13SMasahiro Yamadacreate unit tests which we can run to test this upper level code.
182dabac13SMasahiro Yamada
192dabac13SMasahiro YamadaCONFIG_SANDBOX is defined when building a native board.
202dabac13SMasahiro Yamada
219b250ac4SSimon GlassThe board name is 'sandbox' but the vendor name is unset, so there is a
229b250ac4SSimon Glasssingle board in board/sandbox.
232dabac13SMasahiro Yamada
242dabac13SMasahiro YamadaCONFIG_SANDBOX_BIG_ENDIAN should be defined when running on big-endian
252dabac13SMasahiro Yamadamachines.
262dabac13SMasahiro Yamada
272dabac13SMasahiro YamadaNote that standalone/API support is not available at present.
282dabac13SMasahiro Yamada
292dabac13SMasahiro Yamada
302dabac13SMasahiro YamadaBasic Operation
312dabac13SMasahiro Yamada---------------
322dabac13SMasahiro Yamada
332dabac13SMasahiro YamadaTo run sandbox U-Boot use something like:
342dabac13SMasahiro Yamada
356b1978f8SJagannadha Sutradharudu Teki   make sandbox_defconfig all
362dabac13SMasahiro Yamada   ./u-boot
372dabac13SMasahiro Yamada
382dabac13SMasahiro YamadaNote:
392dabac13SMasahiro Yamada   If you get errors about 'sdl-config: Command not found' you may need to
402dabac13SMasahiro Yamada   install libsdl1.2-dev or similar to get SDL support. Alternatively you can
412dabac13SMasahiro Yamada   build sandbox without SDL (i.e. no display/keyboard support) by removing
422dabac13SMasahiro Yamada   the CONFIG_SANDBOX_SDL line in include/configs/sandbox.h or using:
432dabac13SMasahiro Yamada
446b1978f8SJagannadha Sutradharudu Teki      make sandbox_defconfig all NO_SDL=1
452dabac13SMasahiro Yamada      ./u-boot
462dabac13SMasahiro Yamada
472dabac13SMasahiro Yamada
482dabac13SMasahiro YamadaU-Boot will start on your computer, showing a sandbox emulation of the serial
492dabac13SMasahiro Yamadaconsole:
502dabac13SMasahiro Yamada
512dabac13SMasahiro Yamada
522dabac13SMasahiro YamadaU-Boot 2014.04 (Mar 20 2014 - 19:06:00)
532dabac13SMasahiro Yamada
542dabac13SMasahiro YamadaDRAM:  128 MiB
552dabac13SMasahiro YamadaUsing default environment
562dabac13SMasahiro Yamada
572dabac13SMasahiro YamadaIn:    serial
582dabac13SMasahiro YamadaOut:   lcd
592dabac13SMasahiro YamadaErr:   lcd
602dabac13SMasahiro Yamada=>
612dabac13SMasahiro Yamada
622dabac13SMasahiro YamadaYou can issue commands as your would normally. If the command you want is
632dabac13SMasahiro Yamadanot supported you can add it to include/configs/sandbox.h.
642dabac13SMasahiro Yamada
652dabac13SMasahiro YamadaTo exit, type 'reset' or press Ctrl-C.
662dabac13SMasahiro Yamada
672dabac13SMasahiro Yamada
682dabac13SMasahiro YamadaConsole / LCD support
692dabac13SMasahiro Yamada---------------------
702dabac13SMasahiro Yamada
712dabac13SMasahiro YamadaAssuming that CONFIG_SANDBOX_SDL is defined when building, you can run the
722dabac13SMasahiro Yamadasandbox with LCD and keyboard emulation, using something like:
732dabac13SMasahiro Yamada
742dabac13SMasahiro Yamada   ./u-boot -d u-boot.dtb -l
752dabac13SMasahiro Yamada
762dabac13SMasahiro YamadaThis will start U-Boot with a window showing the contents of the LCD. If
772dabac13SMasahiro Yamadathat window has the focus then you will be able to type commands as you
782dabac13SMasahiro Yamadawould on the console. You can adjust the display settings in the device
792dabac13SMasahiro Yamadatree file - see arch/sandbox/dts/sandbox.dts.
802dabac13SMasahiro Yamada
812dabac13SMasahiro Yamada
822dabac13SMasahiro YamadaCommand-line Options
832dabac13SMasahiro Yamada--------------------
842dabac13SMasahiro Yamada
852dabac13SMasahiro YamadaVarious options are available, mostly for test purposes. Use -h to see
862dabac13SMasahiro Yamadaavailable options. Some of these are described below.
872dabac13SMasahiro Yamada
882dabac13SMasahiro YamadaThe terminal is normally in what is called 'raw-with-sigs' mode. This means
892dabac13SMasahiro Yamadathat you can use arrow keys for command editing and history, but if you
902dabac13SMasahiro Yamadapress Ctrl-C, U-Boot will exit instead of handling this as a keypress.
912dabac13SMasahiro Yamada
922dabac13SMasahiro YamadaOther options are 'raw' (so Ctrl-C is handled within U-Boot) and 'cooked'
932dabac13SMasahiro Yamada(where the terminal is in cooked mode and cursor keys will not work, Ctrl-C
942dabac13SMasahiro Yamadawill exit).
952dabac13SMasahiro Yamada
962dabac13SMasahiro YamadaAs mentioned above, -l causes the LCD emulation window to be shown.
972dabac13SMasahiro Yamada
982dabac13SMasahiro YamadaA device tree binary file can be provided with -d. If you edit the source
992dabac13SMasahiro Yamada(it is stored at arch/sandbox/dts/sandbox.dts) you must rebuild U-Boot to
1002dabac13SMasahiro Yamadarecreate the binary file.
1012dabac13SMasahiro Yamada
1022dabac13SMasahiro YamadaTo execute commands directly, use the -c option. You can specify a single
1032dabac13SMasahiro Yamadacommand, or multiple commands separated by a semicolon, as is normal in
1042dabac13SMasahiro YamadaU-Boot. Be careful with quoting as the shall will normally process and
1052dabac13SMasahiro Yamadaswallow quotes. When -c is used, U-Boot exists after the command is complete,
1062dabac13SMasahiro Yamadabut you can force it to go to interactive mode instead with -i.
1072dabac13SMasahiro Yamada
1082dabac13SMasahiro Yamada
1092dabac13SMasahiro YamadaMemory Emulation
1102dabac13SMasahiro Yamada----------------
1112dabac13SMasahiro Yamada
1122dabac13SMasahiro YamadaMemory emulation is supported, with the size set by CONFIG_SYS_SDRAM_SIZE.
1132dabac13SMasahiro YamadaThe -m option can be used to read memory from a file on start-up and write
1142dabac13SMasahiro Yamadait when shutting down. This allows preserving of memory contents across
1152dabac13SMasahiro Yamadatest runs. You can tell U-Boot to remove the memory file after it is read
1162dabac13SMasahiro Yamada(on start-up) with the --rm_memory option.
1172dabac13SMasahiro Yamada
1182dabac13SMasahiro YamadaTo access U-Boot's emulated memory within the code, use map_sysmem(). This
1192dabac13SMasahiro Yamadafunction is used throughout U-Boot to ensure that emulated memory is used
1202dabac13SMasahiro Yamadarather than the U-Boot application memory. This provides memory starting
1212dabac13SMasahiro Yamadaat 0 and extending to the size of the emulation.
1222dabac13SMasahiro Yamada
1232dabac13SMasahiro Yamada
1242dabac13SMasahiro YamadaStoring State
1252dabac13SMasahiro Yamada-------------
1262dabac13SMasahiro Yamada
1272dabac13SMasahiro YamadaWith sandbox you can write drivers which emulate the operation of drivers on
1282dabac13SMasahiro Yamadareal devices. Some of these drivers may want to record state which is
1292dabac13SMasahiro Yamadapreserved across U-Boot runs. This is particularly useful for testing. For
1302dabac13SMasahiro Yamadaexample, the contents of a SPI flash chip should not disappear just because
1312dabac13SMasahiro YamadaU-Boot exits.
1322dabac13SMasahiro Yamada
1332dabac13SMasahiro YamadaState is stored in a device tree file in a simple format which is driver-
1342dabac13SMasahiro Yamadaspecific. You then use the -s option to specify the state file. Use -r to
1352dabac13SMasahiro Yamadamake U-Boot read the state on start-up (otherwise it starts empty) and -w
1362dabac13SMasahiro Yamadato write it on exit (otherwise the stored state is left unchanged and any
1372dabac13SMasahiro Yamadachanges U-Boot made will be lost). You can also use -n to tell U-Boot to
1382dabac13SMasahiro Yamadaignore any problems with missing state. This is useful when first running
1392dabac13SMasahiro Yamadasince the state file will be empty.
1402dabac13SMasahiro Yamada
1412dabac13SMasahiro YamadaThe device tree file has one node for each driver - the driver can store
1422dabac13SMasahiro Yamadawhatever properties it likes in there. See 'Writing Sandbox Drivers' below
1432dabac13SMasahiro Yamadafor more details on how to get drivers to read and write their state.
1442dabac13SMasahiro Yamada
1452dabac13SMasahiro Yamada
1462dabac13SMasahiro YamadaRunning and Booting
1472dabac13SMasahiro Yamada-------------------
1482dabac13SMasahiro Yamada
1492dabac13SMasahiro YamadaSince there is no machine architecture, sandbox U-Boot cannot actually boot
1502dabac13SMasahiro Yamadaa kernel, but it does support the bootm command. Filesystems, memory
1512dabac13SMasahiro Yamadacommands, hashing, FIT images, verified boot and many other features are
1522dabac13SMasahiro Yamadasupported.
1532dabac13SMasahiro Yamada
1542dabac13SMasahiro YamadaWhen 'bootm' runs a kernel, sandbox will exit, as U-Boot does on a real
1552dabac13SMasahiro Yamadamachine. Of course in this case, no kernel is run.
1562dabac13SMasahiro Yamada
1572dabac13SMasahiro YamadaIt is also possible to tell U-Boot that it has jumped from a temporary
1582dabac13SMasahiro Yamadaprevious U-Boot binary, with the -j option. That binary is automatically
1592dabac13SMasahiro Yamadaremoved by the U-Boot that gets the -j option. This allows you to write
1602dabac13SMasahiro Yamadatests which emulate the action of chain-loading U-Boot, typically used in
1612dabac13SMasahiro Yamadaa situation where a second 'updatable' U-Boot is stored on your board. It
1622dabac13SMasahiro Yamadais very risky to overwrite or upgrade the only U-Boot on a board, since a
1632dabac13SMasahiro Yamadapower or other failure will brick the board and require return to the
1642dabac13SMasahiro Yamadamanufacturer in the case of a consumer device.
1652dabac13SMasahiro Yamada
1662dabac13SMasahiro Yamada
1672dabac13SMasahiro YamadaSupported Drivers
1682dabac13SMasahiro Yamada-----------------
1692dabac13SMasahiro Yamada
1702dabac13SMasahiro YamadaU-Boot sandbox supports these emulations:
1712dabac13SMasahiro Yamada
1722dabac13SMasahiro Yamada- Block devices
1732dabac13SMasahiro Yamada- Chrome OS EC
1742dabac13SMasahiro Yamada- GPIO
1752dabac13SMasahiro Yamada- Host filesystem (access files on the host from within U-Boot)
176*3ea143abSJoe Hershberger- I2C
1772dabac13SMasahiro Yamada- Keyboard (Chrome OS)
1782dabac13SMasahiro Yamada- LCD
179*3ea143abSJoe Hershberger- Network
1802dabac13SMasahiro Yamada- Serial (for console only)
1812dabac13SMasahiro Yamada- Sound (incomplete - see sandbox_sdl_sound_init() for details)
1822dabac13SMasahiro Yamada- SPI
1832dabac13SMasahiro Yamada- SPI flash
1842dabac13SMasahiro Yamada- TPM (Trusted Platform Module)
1852dabac13SMasahiro Yamada
1862dabac13SMasahiro YamadaA wide range of commands is implemented. Filesystems which use a block
1872dabac13SMasahiro Yamadadevice are supported.
1882dabac13SMasahiro Yamada
1892dabac13SMasahiro YamadaAlso sandbox uses generic board (CONFIG_SYS_GENERIC_BOARD) and supports
1902dabac13SMasahiro Yamadadriver model (CONFIG_DM) and associated commands.
1912dabac13SMasahiro Yamada
1922dabac13SMasahiro Yamada
1932dabac13SMasahiro YamadaSPI Emulation
1942dabac13SMasahiro Yamada-------------
1952dabac13SMasahiro Yamada
1962dabac13SMasahiro YamadaSandbox supports SPI and SPI flash emulation.
1972dabac13SMasahiro Yamada
1982dabac13SMasahiro YamadaThis is controlled by the spi_sf argument, the format of which is:
1992dabac13SMasahiro Yamada
2002dabac13SMasahiro Yamada   bus:cs:device:file
2012dabac13SMasahiro Yamada
2022dabac13SMasahiro Yamada   bus    - SPI bus number
2032dabac13SMasahiro Yamada   cs     - SPI chip select number
2042dabac13SMasahiro Yamada   device - SPI device emulation name
2052dabac13SMasahiro Yamada   file   - File on disk containing the data
2062dabac13SMasahiro Yamada
2072dabac13SMasahiro YamadaFor example:
2082dabac13SMasahiro Yamada
2092dabac13SMasahiro Yamada dd if=/dev/zero of=spi.bin bs=1M count=4
2102dabac13SMasahiro Yamada ./u-boot --spi_sf 0:0:M25P16:spi.bin
2112dabac13SMasahiro Yamada
2122dabac13SMasahiro YamadaWith this setup you can issue SPI flash commands as normal:
2132dabac13SMasahiro Yamada
2142dabac13SMasahiro Yamada=>sf probe
2152dabac13SMasahiro YamadaSF: Detected M25P16 with page size 64 KiB, total 2 MiB
2162dabac13SMasahiro Yamada=>sf read 0 0 10000
2172dabac13SMasahiro YamadaSF: 65536 bytes @ 0x0 Read: OK
2182dabac13SMasahiro Yamada=>
2192dabac13SMasahiro Yamada
2202dabac13SMasahiro YamadaSince this is a full SPI emulation (rather than just flash), you can
2212dabac13SMasahiro Yamadaalso use low-level SPI commands:
2222dabac13SMasahiro Yamada
2232dabac13SMasahiro Yamada=>sspi 0:0 32 9f
2242dabac13SMasahiro YamadaFF202015
2252dabac13SMasahiro Yamada
2262dabac13SMasahiro YamadaThis is issuing a READ_ID command and getting back 20 (ST Micro) part
2272dabac13SMasahiro Yamada0x2015 (the M25P16).
2282dabac13SMasahiro Yamada
2292dabac13SMasahiro YamadaDrivers are connected to a particular bus/cs using sandbox's state
2302dabac13SMasahiro Yamadastructure (see the 'spi' member). A set of operations must be provided
2312dabac13SMasahiro Yamadafor each driver.
2322dabac13SMasahiro Yamada
2332dabac13SMasahiro Yamada
2342dabac13SMasahiro YamadaConfiguration settings for the curious are:
2352dabac13SMasahiro Yamada
2362dabac13SMasahiro YamadaCONFIG_SANDBOX_SPI_MAX_BUS
2372dabac13SMasahiro Yamada	The maximum number of SPI buses supported by the driver (default 1).
2382dabac13SMasahiro Yamada
2392dabac13SMasahiro YamadaCONFIG_SANDBOX_SPI_MAX_CS
2402dabac13SMasahiro Yamada	The maximum number of chip selects supported by the driver
2412dabac13SMasahiro Yamada	(default 10).
2422dabac13SMasahiro Yamada
2432dabac13SMasahiro YamadaCONFIG_SPI_IDLE_VAL
2442dabac13SMasahiro Yamada	The idle value on the SPI bus
2452dabac13SMasahiro Yamada
2462dabac13SMasahiro Yamada
2472dabac13SMasahiro YamadaWriting Sandbox Drivers
2482dabac13SMasahiro Yamada-----------------------
2492dabac13SMasahiro Yamada
2502dabac13SMasahiro YamadaGenerally you should put your driver in a file containing the word 'sandbox'
2512dabac13SMasahiro Yamadaand put it in the same directory as other drivers of its type. You can then
2522dabac13SMasahiro Yamadaimplement the same hooks as the other drivers.
2532dabac13SMasahiro Yamada
2542dabac13SMasahiro YamadaTo access U-Boot's emulated memory, use map_sysmem() as mentioned above.
2552dabac13SMasahiro Yamada
2562dabac13SMasahiro YamadaIf your driver needs to store configuration or state (such as SPI flash
2572dabac13SMasahiro Yamadacontents or emulated chip registers), you can use the device tree as
2582dabac13SMasahiro Yamadadescribed above. Define handlers for this with the SANDBOX_STATE_IO macro.
2592dabac13SMasahiro YamadaSee arch/sandbox/include/asm/state.h for documentation. In short you provide
2602dabac13SMasahiro Yamadaa node name, compatible string and functions to read and write the state.
2612dabac13SMasahiro YamadaSince writing the state can expand the device tree, you may need to use
2622dabac13SMasahiro Yamadastate_setprop() which does this automatically and avoids running out of
2632dabac13SMasahiro Yamadaspace. See existing code for examples.
2642dabac13SMasahiro Yamada
2652dabac13SMasahiro Yamada
2662dabac13SMasahiro YamadaTesting
2672dabac13SMasahiro Yamada-------
2682dabac13SMasahiro Yamada
2692dabac13SMasahiro YamadaU-Boot sandbox can be used to run various tests, mostly in the test/
2702dabac13SMasahiro Yamadadirectory. These include:
2712dabac13SMasahiro Yamada
2722dabac13SMasahiro Yamada  command_ut
2732dabac13SMasahiro Yamada     - Unit tests for command parsing and handling
2742dabac13SMasahiro Yamada  compression
2752dabac13SMasahiro Yamada     - Unit tests for U-Boot's compression algorithms, useful for
2762dabac13SMasahiro Yamada       security checking. It supports gzip, bzip2, lzma and lzo.
2772dabac13SMasahiro Yamada  driver model
2782dabac13SMasahiro Yamada     - test/dm/test-dm.sh to run these.
2792dabac13SMasahiro Yamada  image
2802dabac13SMasahiro Yamada     - Unit tests for images:
2812dabac13SMasahiro Yamada          test/image/test-imagetools.sh - multi-file images
2822dabac13SMasahiro Yamada          test/image/test-fit.py        - FIT images
2832dabac13SMasahiro Yamada  tracing
2842dabac13SMasahiro Yamada     - test/trace/test-trace.sh tests the tracing system (see README.trace)
2852dabac13SMasahiro Yamada  verified boot
2862dabac13SMasahiro Yamada      - See test/vboot/vboot_test.sh for this
2872dabac13SMasahiro Yamada
2882dabac13SMasahiro YamadaIf you change or enhance any of the above subsystems, you shold write or
2892dabac13SMasahiro Yamadaexpand a test and include it with your patch series submission. Test
2902dabac13SMasahiro Yamadacoverage in U-Boot is limited, as we need to work to improve it.
2912dabac13SMasahiro Yamada
2922dabac13SMasahiro YamadaNote that many of these tests are implemented as commands which you can
2932dabac13SMasahiro Yamadarun natively on your board if desired (and enabled).
2942dabac13SMasahiro Yamada
2952dabac13SMasahiro YamadaIt would be useful to have a central script to run all of these.
2962dabac13SMasahiro Yamada
2972dabac13SMasahiro Yamada--
2982dabac13SMasahiro YamadaSimon Glass <sjg@chromium.org>
2992dabac13SMasahiro YamadaUpdated 22-Mar-14
300