Uboot sandbox

印飞捷
2023-12-01
  • 学习uboot sandbox

1.Sandbox

  The ‘sandbox’ architecture is designed to allow U-Boot to run under Linux on almost any hardware. To achieve this it builds U-Boot (so far as possible) as a normal C application with a main() and normal C libraries.

  All of U-Boot’s architecture-specific code therefore cannot be built as part of the sandbox U-Boot. The purpose of running U-Boot under Linux is to test all the generic code, not specific to any one architecture. The idea is to create unit tests which we can run to test this upper level code.

Sandbox configurations includes:

  • CONFIG_SANDBOX
  • CONFIG_SANDBOX_BIG_ENDIAN

There are two versions of the sandbox:

  • 32-bit-wide integers
  • 64-bit-wide integers.

  Note:by default, the sandbox it built for a 32-bit host. The sandbox using 64-bit-wide integers can only be built on 64-bit hosts.

2.Basic Operation

  To run sandbox U-Boot use something like:

 $make sandbox_defconfig all
 $./u-boot

Note: If you get errors about ‘sdl-config: Command not found’ you may need to install libsdl1.2-dev or similar to get SDL support. Alternatively you can build sandbox without SDL (i.e. no display/keyboard support) by removing the CONFIG_SANDBOX_SDL line in include/configs/sandbox.h or using:

#Some machines do not have SDL libraries installed, and it is still useful to build sandbox without LCD/keyboard support.
$sudo apt-get install libsdl1.2-dev
$make sandbox_defconfig all NO_SDL=1
$./u-boot
U-Boot will start on your computer, showing a sandbox emulation of the serial
console:
U-Boot 2014.04 (Mar 20 2014 - 19:06:00)
DRAM:  128 MiB
Using default environment

In:    serial
Out:   lcd
Err:   lcd
=>

  You can issue commands as your would normally. If the command you want is not supported you can add it to include/configs/sandbox.h.

  To exit, type ‘reset’ or press Ctrl-C.

  You can use the test-dm.sh

  1 #!/bin/sh
  2 
  3 die() {
  4     echo $1
  5     exit 1
  6 }
  7 
  8 NUM_CPUS=$(cat /proc/cpuinfo |grep -c processor)
  9 make O=sandbox sandbox_config  || die "Cannot configure U-Boot"
 10 make O=sandbox -s -j${NUM_CPUS} || die "Cannot build U-Boot"
 11 
 12 dd if=/dev/zero of=spi.bin bs=1M count=2
 13 echo -n "this is a test" > testflash.bin
 14 dd if=/dev/zero bs=1M count=4 >>testflash.bin
 17 ./sandbox/u-boot -d sandbox/arch/sandbox/dts/test.dtb -i "dm test"        
 18 #./sandbox/u-boot -d sandbox/arch/sandbox/dts/test.dtb -c "dm test"                                                                                    
 19 rm -f spi.bin
 20 rm -f testflash.bin

Note:
  To execute commands directly, use the -c option. When -c is used, U-Boot exits after the command is complete,but you can force it to go to interactive mode instead with -i.

You can use the command below:

Documents/work/code/u-boot/u-boot$ ./sandbox/u-boot -help
U-Boot 2019.07-rc3-dirty (May 31 2019 - 19:10:05 +0800)

u-boot, a command line test interface to U-Boot

Usage: u-boot [options]
Options:
      --show_of_platdata         Show of-platdata in SPL
  -L, --log_level        <arg>   Set log level (0=panic, 7=debug)
  -v, --verbose                  Show test output
  -t, --terminal         <arg>   Set terminal to raw/cooked mode
  -l, --show_lcd                 Show the sandbox LCD display
  -n, --ignore_missing           Ignore missing state on read
  -w, --write                    Write state FDT on exit
  -r, --read                     Read the state FDT on startup
  -s, --state            <arg>   Specify the sandbox state FDT
      --rm_memory                Remove memory file after reading
  -m, --memory           <arg>   Read/write ram_buf memory contents from file
  -j, --jump             <arg>   Jumped from previous U-Boot
  -i, --interactive              Enter interactive mode
  -D, --default_fdt              Use the default u-boot.dtb control FDT in U-Boot directory
  -d, --fdt              <arg>   Specify U-Boot's control FDT
  -c, --command          <arg>   Execute U-Boot command
  -b, --boot                     Run distro boot commands
  -h, --help                     Display help

2.1.Console / LCD support

  Assuming that CONFIG_SANDBOX_SDL is defined when building, you can run the sandbox with LCD and keyboard emulation, using something like:

./u-boot -d u-boot.dtb -l
Note : -l causes the LCD emulation window to be shown.

  This will start U-Boot with a window showing the contents of the LCD. If that window has the focus then you will be able to type commands as you would on the console. You can adjust display settings in the device tree file - arch/sandbox/dts/sandbox.dts.

3.Supported Drivers

 174U-Boot sandbox supports these emulations:
 175
 176- Block devices
 177- Chrome OS EC
 178- GPIO
 179- Host filesystem (access files on the host from within U-Boot)
 180- I2C
 181- Keyboard (Chrome OS)
 182- LCD
 183- Network
 184- Serial (for console only)
 185- Sound (incomplete - see sandbox_sdl_sound_init() for details)
 186- SPI
 187- SPI flash
 188- TPM (Trusted Platform Module)

There are unfortunately quite a few variants at present:

There are unfortunately quite a few variants at present:
 200
 201 sandbox - should be used for most tests
 202 sandbox64 - special build that forces a 64-bit host
 203 sandbox_flattree - builds with dev_read_...() functions defined as inline.
 204    We need this build so that we can test those inline functions, and we
 205    cannot build with both the inline functions and the non-inline functions
 206    since they are named the same.
 207 sandbox_noblk - builds without CONFIG_BLK, which means the legacy block
 208    drivers are used. We cannot use both the legacy and driver-model block
 209    drivers since they implement the same functions
 210 sandbox_spl - builds sandbox with SPL support, so you can run spl/u-boot-spl
 211    and it will start up and then load ./u-boot. It is also possible to
 212    run ./u-boot directly.

4.Testing

  U-Boot sandbox can be used to run various tests, mostly in the test/ directory. These include:

 401  command_ut
 402     - Unit tests for command parsing and handling
 403  compression
 404     - Unit tests for U-Boot's compression algorithms, useful for
 405       security checking. It supports gzip, bzip2, lzma and lzo.
 406  driver model
 407     - Run this pytest
 408          ./test/py/test.py --bd sandbox --build -k ut_dm -v
 409  image
 410     - Unit tests for images:
 411          test/image/test-imagetools.sh - multi-file images
 412          test/image/test-fit.py        - FIT images
 413  tracing
 414     - test/trace/test-trace.sh tests the tracing system (see README.trace)
 415  verified boot
 416      - See test/vboot/vboot_test.sh for this
 417

Note: To run all tests use “make check”.

5.Related code about the sandbox:

  • include/configs/sandbox.h
  • arch/sandbox/
  • board/sandbox/
  • test/dm/

参考资料:
https://lxr.missinglinkelectronics.com/uboot/board/sandbox/README.sandbox

 类似资料:

相关阅读

相关文章

相关问答