183d290c5STom Rini/* SPDX-License-Identifier: GPL-2.0+ */ 22dabac13SMasahiro Yamada/* 32dabac13SMasahiro Yamada * Copyright (c) 2014 The Chromium OS Authors. 42dabac13SMasahiro Yamada */ 52dabac13SMasahiro Yamada 62dabac13SMasahiro YamadaNative Execution of U-Boot 72dabac13SMasahiro Yamada========================== 82dabac13SMasahiro Yamada 92dabac13SMasahiro YamadaThe 'sandbox' architecture is designed to allow U-Boot to run under Linux on 102dabac13SMasahiro Yamadaalmost any hardware. To achieve this it builds U-Boot (so far as possible) 112dabac13SMasahiro Yamadaas a normal C application with a main() and normal C libraries. 122dabac13SMasahiro Yamada 132dabac13SMasahiro YamadaAll of U-Boot's architecture-specific code therefore cannot be built as part 142dabac13SMasahiro Yamadaof the sandbox U-Boot. The purpose of running U-Boot under Linux is to test 152dabac13SMasahiro Yamadaall the generic code, not specific to any one architecture. The idea is to 162dabac13SMasahiro Yamadacreate unit tests which we can run to test this upper level code. 172dabac13SMasahiro Yamada 182dabac13SMasahiro YamadaCONFIG_SANDBOX is defined when building a native board. 192dabac13SMasahiro Yamada 209b250ac4SSimon GlassThe board name is 'sandbox' but the vendor name is unset, so there is a 219b250ac4SSimon Glasssingle board in board/sandbox. 222dabac13SMasahiro Yamada 232dabac13SMasahiro YamadaCONFIG_SANDBOX_BIG_ENDIAN should be defined when running on big-endian 242dabac13SMasahiro Yamadamachines. 252dabac13SMasahiro Yamada 26c6b89f31SMario SixThere are two versions of the sandbox: One using 32-bit-wide integers, and one 27c6b89f31SMario Sixusing 64-bit-wide integers. The 32-bit version can be build and run on either 28c6b89f31SMario Six32 or 64-bit hosts by either selecting or deselecting CONFIG_SANDBOX_32BIT; by 29c6b89f31SMario Sixdefault, the sandbox it built for a 32-bit host. The sandbox using 64-bit-wide 30c6b89f31SMario Sixintegers can only be built on 64-bit hosts. 31226b50bbSBin Meng 322dabac13SMasahiro YamadaNote that standalone/API support is not available at present. 332dabac13SMasahiro Yamada 342dabac13SMasahiro Yamada 352dabac13SMasahiro YamadaBasic Operation 362dabac13SMasahiro Yamada--------------- 372dabac13SMasahiro Yamada 382dabac13SMasahiro YamadaTo run sandbox U-Boot use something like: 392dabac13SMasahiro Yamada 406b1978f8SJagannadha Sutradharudu Teki make sandbox_defconfig all 412dabac13SMasahiro Yamada ./u-boot 422dabac13SMasahiro Yamada 432dabac13SMasahiro YamadaNote: 442dabac13SMasahiro Yamada If you get errors about 'sdl-config: Command not found' you may need to 452dabac13SMasahiro Yamada install libsdl1.2-dev or similar to get SDL support. Alternatively you can 462dabac13SMasahiro Yamada build sandbox without SDL (i.e. no display/keyboard support) by removing 472dabac13SMasahiro Yamada the CONFIG_SANDBOX_SDL line in include/configs/sandbox.h or using: 482dabac13SMasahiro Yamada 496b1978f8SJagannadha Sutradharudu Teki make sandbox_defconfig all NO_SDL=1 502dabac13SMasahiro Yamada ./u-boot 512dabac13SMasahiro Yamada 522dabac13SMasahiro YamadaU-Boot will start on your computer, showing a sandbox emulation of the serial 532dabac13SMasahiro Yamadaconsole: 542dabac13SMasahiro Yamada 552dabac13SMasahiro Yamada 562dabac13SMasahiro YamadaU-Boot 2014.04 (Mar 20 2014 - 19:06:00) 572dabac13SMasahiro Yamada 582dabac13SMasahiro YamadaDRAM: 128 MiB 592dabac13SMasahiro YamadaUsing default environment 602dabac13SMasahiro Yamada 612dabac13SMasahiro YamadaIn: serial 622dabac13SMasahiro YamadaOut: lcd 632dabac13SMasahiro YamadaErr: lcd 642dabac13SMasahiro Yamada=> 652dabac13SMasahiro Yamada 662dabac13SMasahiro YamadaYou can issue commands as your would normally. If the command you want is 672dabac13SMasahiro Yamadanot supported you can add it to include/configs/sandbox.h. 682dabac13SMasahiro Yamada 692dabac13SMasahiro YamadaTo exit, type 'reset' or press Ctrl-C. 702dabac13SMasahiro Yamada 712dabac13SMasahiro Yamada 722dabac13SMasahiro YamadaConsole / LCD support 732dabac13SMasahiro Yamada--------------------- 742dabac13SMasahiro Yamada 752dabac13SMasahiro YamadaAssuming that CONFIG_SANDBOX_SDL is defined when building, you can run the 762dabac13SMasahiro Yamadasandbox with LCD and keyboard emulation, using something like: 772dabac13SMasahiro Yamada 782dabac13SMasahiro Yamada ./u-boot -d u-boot.dtb -l 792dabac13SMasahiro Yamada 802dabac13SMasahiro YamadaThis will start U-Boot with a window showing the contents of the LCD. If 812dabac13SMasahiro Yamadathat window has the focus then you will be able to type commands as you 822dabac13SMasahiro Yamadawould on the console. You can adjust the display settings in the device 832dabac13SMasahiro Yamadatree file - see arch/sandbox/dts/sandbox.dts. 842dabac13SMasahiro Yamada 852dabac13SMasahiro Yamada 862dabac13SMasahiro YamadaCommand-line Options 872dabac13SMasahiro Yamada-------------------- 882dabac13SMasahiro Yamada 892dabac13SMasahiro YamadaVarious options are available, mostly for test purposes. Use -h to see 902dabac13SMasahiro Yamadaavailable options. Some of these are described below. 912dabac13SMasahiro Yamada 922dabac13SMasahiro YamadaThe terminal is normally in what is called 'raw-with-sigs' mode. This means 932dabac13SMasahiro Yamadathat you can use arrow keys for command editing and history, but if you 942dabac13SMasahiro Yamadapress Ctrl-C, U-Boot will exit instead of handling this as a keypress. 952dabac13SMasahiro Yamada 962dabac13SMasahiro YamadaOther options are 'raw' (so Ctrl-C is handled within U-Boot) and 'cooked' 972dabac13SMasahiro Yamada(where the terminal is in cooked mode and cursor keys will not work, Ctrl-C 982dabac13SMasahiro Yamadawill exit). 992dabac13SMasahiro Yamada 1002dabac13SMasahiro YamadaAs mentioned above, -l causes the LCD emulation window to be shown. 1012dabac13SMasahiro Yamada 1022dabac13SMasahiro YamadaA device tree binary file can be provided with -d. If you edit the source 1032dabac13SMasahiro Yamada(it is stored at arch/sandbox/dts/sandbox.dts) you must rebuild U-Boot to 1042dabac13SMasahiro Yamadarecreate the binary file. 1052dabac13SMasahiro Yamada 1062dabac13SMasahiro YamadaTo execute commands directly, use the -c option. You can specify a single 1072dabac13SMasahiro Yamadacommand, or multiple commands separated by a semicolon, as is normal in 1081f154a63STrevor WoernerU-Boot. Be careful with quoting as the shell will normally process and 1091f154a63STrevor Woernerswallow quotes. When -c is used, U-Boot exits after the command is complete, 1102dabac13SMasahiro Yamadabut you can force it to go to interactive mode instead with -i. 1112dabac13SMasahiro Yamada 1122dabac13SMasahiro Yamada 1132dabac13SMasahiro YamadaMemory Emulation 1142dabac13SMasahiro Yamada---------------- 1152dabac13SMasahiro Yamada 1162dabac13SMasahiro YamadaMemory emulation is supported, with the size set by CONFIG_SYS_SDRAM_SIZE. 1172dabac13SMasahiro YamadaThe -m option can be used to read memory from a file on start-up and write 1182dabac13SMasahiro Yamadait when shutting down. This allows preserving of memory contents across 1192dabac13SMasahiro Yamadatest runs. You can tell U-Boot to remove the memory file after it is read 1202dabac13SMasahiro Yamada(on start-up) with the --rm_memory option. 1212dabac13SMasahiro Yamada 1222dabac13SMasahiro YamadaTo access U-Boot's emulated memory within the code, use map_sysmem(). This 1232dabac13SMasahiro Yamadafunction is used throughout U-Boot to ensure that emulated memory is used 1242dabac13SMasahiro Yamadarather than the U-Boot application memory. This provides memory starting 1252dabac13SMasahiro Yamadaat 0 and extending to the size of the emulation. 1262dabac13SMasahiro Yamada 1272dabac13SMasahiro Yamada 1282dabac13SMasahiro YamadaStoring State 1292dabac13SMasahiro Yamada------------- 1302dabac13SMasahiro Yamada 1312dabac13SMasahiro YamadaWith sandbox you can write drivers which emulate the operation of drivers on 1322dabac13SMasahiro Yamadareal devices. Some of these drivers may want to record state which is 1332dabac13SMasahiro Yamadapreserved across U-Boot runs. This is particularly useful for testing. For 1342dabac13SMasahiro Yamadaexample, the contents of a SPI flash chip should not disappear just because 1352dabac13SMasahiro YamadaU-Boot exits. 1362dabac13SMasahiro Yamada 1372dabac13SMasahiro YamadaState is stored in a device tree file in a simple format which is driver- 1382dabac13SMasahiro Yamadaspecific. You then use the -s option to specify the state file. Use -r to 1392dabac13SMasahiro Yamadamake U-Boot read the state on start-up (otherwise it starts empty) and -w 1402dabac13SMasahiro Yamadato write it on exit (otherwise the stored state is left unchanged and any 1412dabac13SMasahiro Yamadachanges U-Boot made will be lost). You can also use -n to tell U-Boot to 1422dabac13SMasahiro Yamadaignore any problems with missing state. This is useful when first running 1432dabac13SMasahiro Yamadasince the state file will be empty. 1442dabac13SMasahiro Yamada 1452dabac13SMasahiro YamadaThe device tree file has one node for each driver - the driver can store 1462dabac13SMasahiro Yamadawhatever properties it likes in there. See 'Writing Sandbox Drivers' below 1472dabac13SMasahiro Yamadafor more details on how to get drivers to read and write their state. 1482dabac13SMasahiro Yamada 1492dabac13SMasahiro Yamada 1502dabac13SMasahiro YamadaRunning and Booting 1512dabac13SMasahiro Yamada------------------- 1522dabac13SMasahiro Yamada 1532dabac13SMasahiro YamadaSince there is no machine architecture, sandbox U-Boot cannot actually boot 1542dabac13SMasahiro Yamadaa kernel, but it does support the bootm command. Filesystems, memory 1552dabac13SMasahiro Yamadacommands, hashing, FIT images, verified boot and many other features are 1562dabac13SMasahiro Yamadasupported. 1572dabac13SMasahiro Yamada 1582dabac13SMasahiro YamadaWhen 'bootm' runs a kernel, sandbox will exit, as U-Boot does on a real 1592dabac13SMasahiro Yamadamachine. Of course in this case, no kernel is run. 1602dabac13SMasahiro Yamada 1612dabac13SMasahiro YamadaIt is also possible to tell U-Boot that it has jumped from a temporary 1622dabac13SMasahiro Yamadaprevious U-Boot binary, with the -j option. That binary is automatically 1632dabac13SMasahiro Yamadaremoved by the U-Boot that gets the -j option. This allows you to write 1642dabac13SMasahiro Yamadatests which emulate the action of chain-loading U-Boot, typically used in 1652dabac13SMasahiro Yamadaa situation where a second 'updatable' U-Boot is stored on your board. It 1662dabac13SMasahiro Yamadais very risky to overwrite or upgrade the only U-Boot on a board, since a 1672dabac13SMasahiro Yamadapower or other failure will brick the board and require return to the 1682dabac13SMasahiro Yamadamanufacturer in the case of a consumer device. 1692dabac13SMasahiro Yamada 1702dabac13SMasahiro Yamada 1712dabac13SMasahiro YamadaSupported Drivers 1722dabac13SMasahiro Yamada----------------- 1732dabac13SMasahiro Yamada 1742dabac13SMasahiro YamadaU-Boot sandbox supports these emulations: 1752dabac13SMasahiro Yamada 1762dabac13SMasahiro Yamada- Block devices 1772dabac13SMasahiro Yamada- Chrome OS EC 1782dabac13SMasahiro Yamada- GPIO 1792dabac13SMasahiro Yamada- Host filesystem (access files on the host from within U-Boot) 1803ea143abSJoe Hershberger- I2C 1812dabac13SMasahiro Yamada- Keyboard (Chrome OS) 1822dabac13SMasahiro Yamada- LCD 1833ea143abSJoe Hershberger- Network 1842dabac13SMasahiro Yamada- Serial (for console only) 1852dabac13SMasahiro Yamada- Sound (incomplete - see sandbox_sdl_sound_init() for details) 1862dabac13SMasahiro Yamada- SPI 1872dabac13SMasahiro Yamada- SPI flash 1882dabac13SMasahiro Yamada- TPM (Trusted Platform Module) 1892dabac13SMasahiro Yamada 1901f154a63STrevor WoernerA wide range of commands are implemented. Filesystems which use a block 1912dabac13SMasahiro Yamadadevice are supported. 1922dabac13SMasahiro Yamada 19389b199c3SSimon GlassAlso sandbox supports driver model (CONFIG_DM) and associated commands. 1942dabac13SMasahiro Yamada 1952dabac13SMasahiro Yamada 196969c8f4dSSimon GlassSandbox Variants 197969c8f4dSSimon Glass---------------- 198969c8f4dSSimon Glass 199969c8f4dSSimon GlassThere are unfortunately quite a few variants at present: 200969c8f4dSSimon Glass 201969c8f4dSSimon Glasssandbox - should be used for most tests 202969c8f4dSSimon Glasssandbox64 - special build that forces a 64-bit host 203969c8f4dSSimon Glasssandbox_flattree - builds with dev_read_...() functions defined as inline. 204969c8f4dSSimon Glass We need this build so that we can test those inline functions, and we 205969c8f4dSSimon Glass cannot build with both the inline functions and the non-inline functions 206969c8f4dSSimon Glass since they are named the same. 207969c8f4dSSimon Glasssandbox_noblk - builds without CONFIG_BLK, which means the legacy block 208969c8f4dSSimon Glass drivers are used. We cannot use both the legacy and driver-model block 209969c8f4dSSimon Glass drivers since they implement the same functions 210969c8f4dSSimon Glasssandbox_spl - builds sandbox with SPL support, so you can run spl/u-boot-spl 211969c8f4dSSimon Glass and it will start up and then load ./u-boot. It is also possible to 212969c8f4dSSimon Glass run ./u-boot directly. 213969c8f4dSSimon Glass 214969c8f4dSSimon GlassOf these sandbox_noblk can be removed once CONFIG_BLK is used everwhere, and 215969c8f4dSSimon Glasssandbox_spl can probably be removed since it is a superset of sandbox. 216969c8f4dSSimon Glass 217969c8f4dSSimon GlassMost of the config options should be identical between these variants. 218969c8f4dSSimon Glass 219969c8f4dSSimon Glass 220a346ca79SJoe HershbergerLinux RAW Networking Bridge 221a346ca79SJoe Hershberger--------------------------- 222a346ca79SJoe Hershberger 223a346ca79SJoe HershbergerThe sandbox_eth_raw driver bridges traffic between the bottom of the network 224a346ca79SJoe Hershbergerstack and the RAW sockets API in Linux. This allows much of the U-Boot network 225a346ca79SJoe Hershbergerfunctionality to be tested in sandbox against real network traffic. 226a346ca79SJoe Hershberger 227a346ca79SJoe HershbergerFor Ethernet network adapters, the bridge utilizes the RAW AF_PACKET API. This 228a346ca79SJoe Hershbergeris needed to get access to the lowest level of the network stack in Linux. This 229a346ca79SJoe Hershbergermeans that all of the Ethernet frame is included. This allows the U-Boot network 230a346ca79SJoe Hershbergerstack to be fully used. In other words, nothing about the Linux network stack is 231a346ca79SJoe Hershbergerinvolved in forming the packets that end up on the wire. To receive the 232a346ca79SJoe Hershbergerresponses to packets sent from U-Boot the network interface has to be set to 233a346ca79SJoe Hershbergerpromiscuous mode so that the network card won't filter out packets not destined 234a346ca79SJoe Hershbergerfor its configured (on Linux) MAC address. 235a346ca79SJoe Hershberger 236a346ca79SJoe HershbergerThe RAW sockets Ethernet API requires elevated privileges in Linux. You can 237a346ca79SJoe Hershbergereither run as root, or you can add the capability needed like so: 238a346ca79SJoe Hershberger 239a346ca79SJoe Hershbergersudo /sbin/setcap "CAP_NET_RAW+ep" /path/to/u-boot 240a346ca79SJoe Hershberger 241a346ca79SJoe HershbergerThe default device tree for sandbox includes an entry for eth0 on the sandbox 242a346ca79SJoe Hershbergerhost machine whose alias is "eth1". The following are a few examples of network 243a346ca79SJoe Hershbergeroperations being tested on the eth0 interface. 244a346ca79SJoe Hershberger 245a346ca79SJoe Hershbergersudo /path/to/u-boot -D 246a346ca79SJoe Hershberger 247a346ca79SJoe HershbergerDHCP 248a346ca79SJoe Hershberger.... 249a346ca79SJoe Hershberger 2506c6260ecSHeinrich Schuchardtsetenv autoload no 2510c943e5dSHeinrich Schuchardtsetenv ethrotate no 2526c6260ecSHeinrich Schuchardtsetenv ethact eth1 253a346ca79SJoe Hershbergerdhcp 254a346ca79SJoe Hershberger 255a346ca79SJoe HershbergerPING 256a346ca79SJoe Hershberger.... 257a346ca79SJoe Hershberger 2586c6260ecSHeinrich Schuchardtsetenv autoload no 2590c943e5dSHeinrich Schuchardtsetenv ethrotate no 2606c6260ecSHeinrich Schuchardtsetenv ethact eth1 261a346ca79SJoe Hershbergerdhcp 262a346ca79SJoe Hershbergerping $gatewayip 263a346ca79SJoe Hershberger 264a346ca79SJoe HershbergerTFTP 265a346ca79SJoe Hershberger.... 266a346ca79SJoe Hershberger 2676c6260ecSHeinrich Schuchardtsetenv autoload no 2680c943e5dSHeinrich Schuchardtsetenv ethrotate no 2696c6260ecSHeinrich Schuchardtsetenv ethact eth1 270a346ca79SJoe Hershbergerdhcp 2716c6260ecSHeinrich Schuchardtsetenv serverip WWW.XXX.YYY.ZZZ 272a346ca79SJoe Hershbergertftpboot u-boot.bin 273a346ca79SJoe Hershberger 2741f154a63STrevor WoernerThe bridge also supports (to a lesser extent) the localhost interface, 'lo'. 27522f68524SJoe Hershberger 27622f68524SJoe HershbergerThe 'lo' interface cannot use the RAW AF_PACKET API because the lo interface 27722f68524SJoe Hershbergerdoesn't support Ethernet-level traffic. It is a higher-level interface that is 27822f68524SJoe Hershbergerexpected only to be used at the AF_INET level of the API. As such, the most raw 27922f68524SJoe Hershbergerwe can get on that interface is the RAW AF_INET API on UDP. This allows us to 28022f68524SJoe Hershbergerset the IP_HDRINCL option to include everything except the Ethernet header in 28122f68524SJoe Hershbergerthe packets we send and receive. 28222f68524SJoe Hershberger 28322f68524SJoe HershbergerBecause only UDP is supported, ICMP traffic will not work, so expect that ping 28422f68524SJoe Hershbergercommands will time out. 28522f68524SJoe Hershberger 28622f68524SJoe HershbergerThe default device tree for sandbox includes an entry for lo on the sandbox 28722f68524SJoe Hershbergerhost machine whose alias is "eth5". The following is an example of a network 28822f68524SJoe Hershbergeroperation being tested on the lo interface. 28922f68524SJoe Hershberger 29022f68524SJoe HershbergerTFTP 29122f68524SJoe Hershberger.... 29222f68524SJoe Hershberger 2930c943e5dSHeinrich Schuchardtsetenv ethrotate no 2946c6260ecSHeinrich Schuchardtsetenv ethact eth5 29522f68524SJoe Hershbergertftpboot u-boot.bin 29622f68524SJoe Hershberger 297a346ca79SJoe Hershberger 2982dabac13SMasahiro YamadaSPI Emulation 2992dabac13SMasahiro Yamada------------- 3002dabac13SMasahiro Yamada 3012dabac13SMasahiro YamadaSandbox supports SPI and SPI flash emulation. 3022dabac13SMasahiro Yamada 3032dabac13SMasahiro YamadaThis is controlled by the spi_sf argument, the format of which is: 3042dabac13SMasahiro Yamada 3052dabac13SMasahiro Yamada bus:cs:device:file 3062dabac13SMasahiro Yamada 3072dabac13SMasahiro Yamada bus - SPI bus number 3082dabac13SMasahiro Yamada cs - SPI chip select number 3092dabac13SMasahiro Yamada device - SPI device emulation name 3102dabac13SMasahiro Yamada file - File on disk containing the data 3112dabac13SMasahiro Yamada 3122dabac13SMasahiro YamadaFor example: 3132dabac13SMasahiro Yamada 3142dabac13SMasahiro Yamada dd if=/dev/zero of=spi.bin bs=1M count=4 3152dabac13SMasahiro Yamada ./u-boot --spi_sf 0:0:M25P16:spi.bin 3162dabac13SMasahiro Yamada 3172dabac13SMasahiro YamadaWith this setup you can issue SPI flash commands as normal: 3182dabac13SMasahiro Yamada 3192dabac13SMasahiro Yamada=>sf probe 3202dabac13SMasahiro YamadaSF: Detected M25P16 with page size 64 KiB, total 2 MiB 3212dabac13SMasahiro Yamada=>sf read 0 0 10000 3222dabac13SMasahiro YamadaSF: 65536 bytes @ 0x0 Read: OK 3232dabac13SMasahiro Yamada=> 3242dabac13SMasahiro Yamada 3252dabac13SMasahiro YamadaSince this is a full SPI emulation (rather than just flash), you can 3262dabac13SMasahiro Yamadaalso use low-level SPI commands: 3272dabac13SMasahiro Yamada 3282dabac13SMasahiro Yamada=>sspi 0:0 32 9f 3292dabac13SMasahiro YamadaFF202015 3302dabac13SMasahiro Yamada 3312dabac13SMasahiro YamadaThis is issuing a READ_ID command and getting back 20 (ST Micro) part 3322dabac13SMasahiro Yamada0x2015 (the M25P16). 3332dabac13SMasahiro Yamada 3342dabac13SMasahiro YamadaDrivers are connected to a particular bus/cs using sandbox's state 3352dabac13SMasahiro Yamadastructure (see the 'spi' member). A set of operations must be provided 3362dabac13SMasahiro Yamadafor each driver. 3372dabac13SMasahiro Yamada 3382dabac13SMasahiro Yamada 3392dabac13SMasahiro YamadaConfiguration settings for the curious are: 3402dabac13SMasahiro Yamada 3412dabac13SMasahiro YamadaCONFIG_SANDBOX_SPI_MAX_BUS 3422dabac13SMasahiro Yamada The maximum number of SPI buses supported by the driver (default 1). 3432dabac13SMasahiro Yamada 3442dabac13SMasahiro YamadaCONFIG_SANDBOX_SPI_MAX_CS 3452dabac13SMasahiro Yamada The maximum number of chip selects supported by the driver 3462dabac13SMasahiro Yamada (default 10). 3472dabac13SMasahiro Yamada 3482dabac13SMasahiro YamadaCONFIG_SPI_IDLE_VAL 3492dabac13SMasahiro Yamada The idle value on the SPI bus 3502dabac13SMasahiro Yamada 3512dabac13SMasahiro Yamada 3522945eb73SStefan BrünsBlock Device Emulation 3532945eb73SStefan Brüns---------------------- 3542945eb73SStefan Brüns 3552945eb73SStefan BrünsU-Boot can use raw disk images for block device emulation. To e.g. list 3562945eb73SStefan Brünsthe contents of the root directory on the second partion of the image 3572945eb73SStefan Brüns"disk.raw", you can use the following commands: 3582945eb73SStefan Brüns 3592945eb73SStefan Brüns=>host bind 0 ./disk.raw 3602945eb73SStefan Brüns=>ls host 0:2 3612945eb73SStefan Brüns 3622945eb73SStefan BrünsA disk image can be created using the following commands: 3632945eb73SStefan Brüns 3642945eb73SStefan Brüns$> truncate -s 1200M ./disk.raw 3656b20c347SAlison Chaiken$> echo -e "label: gpt\n,64M,U\n,,L" | /usr/sbin/sgdisk ./disk.raw 3662945eb73SStefan Brüns$> lodev=`sudo losetup -P -f --show ./disk.raw` 3672945eb73SStefan Brüns$> sudo mkfs.vfat -n EFI -v ${lodev}p1 3682945eb73SStefan Brüns$> sudo mkfs.ext4 -L ROOT -v ${lodev}p2 3692945eb73SStefan Brüns 370bf6d76b8SAlison Chaikenor utilize the device described in test/py/make_test_disk.py: 371bf6d76b8SAlison Chaiken 372bf6d76b8SAlison Chaiken #!/usr/bin/python 373bf6d76b8SAlison Chaiken import make_test_disk 374bf6d76b8SAlison Chaiken make_test_disk.makeDisk() 3752945eb73SStefan Brüns 3762dabac13SMasahiro YamadaWriting Sandbox Drivers 3772dabac13SMasahiro Yamada----------------------- 3782dabac13SMasahiro Yamada 3792dabac13SMasahiro YamadaGenerally you should put your driver in a file containing the word 'sandbox' 3802dabac13SMasahiro Yamadaand put it in the same directory as other drivers of its type. You can then 3812dabac13SMasahiro Yamadaimplement the same hooks as the other drivers. 3822dabac13SMasahiro Yamada 3832dabac13SMasahiro YamadaTo access U-Boot's emulated memory, use map_sysmem() as mentioned above. 3842dabac13SMasahiro Yamada 3852dabac13SMasahiro YamadaIf your driver needs to store configuration or state (such as SPI flash 3862dabac13SMasahiro Yamadacontents or emulated chip registers), you can use the device tree as 3872dabac13SMasahiro Yamadadescribed above. Define handlers for this with the SANDBOX_STATE_IO macro. 3882dabac13SMasahiro YamadaSee arch/sandbox/include/asm/state.h for documentation. In short you provide 3892dabac13SMasahiro Yamadaa node name, compatible string and functions to read and write the state. 3902dabac13SMasahiro YamadaSince writing the state can expand the device tree, you may need to use 3912dabac13SMasahiro Yamadastate_setprop() which does this automatically and avoids running out of 3922dabac13SMasahiro Yamadaspace. See existing code for examples. 3932dabac13SMasahiro Yamada 3942dabac13SMasahiro Yamada 3952dabac13SMasahiro YamadaTesting 3962dabac13SMasahiro Yamada------- 3972dabac13SMasahiro Yamada 3982dabac13SMasahiro YamadaU-Boot sandbox can be used to run various tests, mostly in the test/ 3992dabac13SMasahiro Yamadadirectory. These include: 4002dabac13SMasahiro Yamada 4012dabac13SMasahiro Yamada command_ut 4022dabac13SMasahiro Yamada - Unit tests for command parsing and handling 4032dabac13SMasahiro Yamada compression 4042dabac13SMasahiro Yamada - Unit tests for U-Boot's compression algorithms, useful for 4052dabac13SMasahiro Yamada security checking. It supports gzip, bzip2, lzma and lzo. 4062dabac13SMasahiro Yamada driver model 4077b3dc45eSJagan Teki - Run this pytest 4087b3dc45eSJagan Teki ./test/py/test.py --bd sandbox --build -k ut_dm -v 4092dabac13SMasahiro Yamada image 4102dabac13SMasahiro Yamada - Unit tests for images: 4112dabac13SMasahiro Yamada test/image/test-imagetools.sh - multi-file images 4122dabac13SMasahiro Yamada test/image/test-fit.py - FIT images 4132dabac13SMasahiro Yamada tracing 4142dabac13SMasahiro Yamada - test/trace/test-trace.sh tests the tracing system (see README.trace) 4152dabac13SMasahiro Yamada verified boot 4162dabac13SMasahiro Yamada - See test/vboot/vboot_test.sh for this 4172dabac13SMasahiro Yamada 4182dabac13SMasahiro YamadaIf you change or enhance any of the above subsystems, you shold write or 4192dabac13SMasahiro Yamadaexpand a test and include it with your patch series submission. Test 4202dabac13SMasahiro Yamadacoverage in U-Boot is limited, as we need to work to improve it. 4212dabac13SMasahiro Yamada 4222dabac13SMasahiro YamadaNote that many of these tests are implemented as commands which you can 4232dabac13SMasahiro Yamadarun natively on your board if desired (and enabled). 4242dabac13SMasahiro Yamada 425*9946d557SSimon GlassTo run all tests use "make check". 426*9946d557SSimon Glass 427*9946d557SSimon Glass 428*9946d557SSimon GlassMemory Map 429*9946d557SSimon Glass---------- 430*9946d557SSimon Glass 431*9946d557SSimon GlassSandbox has its own emulated memory starting at 0. Here are some of the things 432*9946d557SSimon Glassthat are mapped into that memory: 433*9946d557SSimon Glass 434*9946d557SSimon Glass 0 CONFIG_SYS_FDT_LOAD_ADDR Device tree 435*9946d557SSimon Glass e000 CONFIG_BLOBLIST_ADDR Blob list 436*9946d557SSimon Glass 10000 CONFIG_MALLOC_F_ADDR Early memory allocation 437*9946d557SSimon Glass 4382dabac13SMasahiro Yamada 4392dabac13SMasahiro Yamada-- 4402dabac13SMasahiro YamadaSimon Glass <sjg@chromium.org> 4412dabac13SMasahiro YamadaUpdated 22-Mar-14 442