[U-Boot] [RFC PATCH v2 0/20] New 'sandbox' test architecture for U-Boot

Simon Glass sjg at chromium.org
Fri Sep 23 18:22:02 CEST 2011


This patch set points towards a possible way to improve the test
infrastructure in U-Boot. The goal is to have a test suite that can run in
a minute or two on a Linux PC and test all non-platform code.

This RFC aims to be just enough boot to U-Boot to a command prompt. You
can type help; anything else will probably segfault :-) Press Ctrl-C to
exit.

This patch set does not include some other code I have been playing around
with, like a SPI flash driver and sandbox 'state' (so the state can be
examined and modified to test failure modes and the like).

$ ./u-boot

U-Boot 2011.09-rc1-00041-ge50de7d-dirty (Sep 17 2011 - 08:17:40)

DRAM:  128 MiB
Using default environment

In:    serial
Out:   serial
Err:   serial

Detail
======
We can break the U-Boot code base into two parts:

1. Platform code, which is SOC-specifc. At present this is the CPU
init (arch/xxx/cpu/...) and SOC-specific drivers (mostly in the
drivers directory). There is also a small amount of generic CPU code
in arch/xxx/lib and some board-specific code/drivers (e.g. drivers not
within the SOC).

2. Portable/Generic U-Boot code, which is cross-platform. This
includes many drivers, the various commands, file system support,
things like the MMC, USB and network stacks, etc.

My focus in this patch set is the second part of the code base - all the
code which is not platform-specific, but can still have bugs.

Proposal
========
To a large extent, testing of this part of the code base could simply
be built on one or more of the available platforms. We could then run
the tests on that platform, and announce that the code base works fine
on that platform. Obviously the platform needs to support all possible
features of U-Boot.

However, this approach fails to take advantage of two useful
properties of this code:

- It is cross-platform, and even runs on x86
- It is standalone, requiring no OS libraries to run

For speed, debugging and convenience, it would be nice to run U-Boot
under a generic Linux environment on a workstation, and test all the
generic non-platform code. The basic problem with this is that the
non-platform code requires the platform code to operate. Even the x86
platform code is designed for standalone operation on a particular x86
board, and is not suitable for running under x86 Linux.

To get around this I propose that we create a new ‘sandbox’
architecture. We write code in ‘arch/sandbox’ which can run under
Linux. Since all the non-platform code will happily run under this new
‘architecture’, we can then write tests which run quickly under x86
Linux (or another Linux for that matter). This U-Boot 'architecture'
should build natively on any 32/64-bit Linux machine since it just
uses standard Linux system calls. Calls to Linux would be entirely
within this arch/sandbox subdirectory.

Benefit
=======
What will this buy us? Well we can do things like:

- Create a test SPI flash device, which is file-backed. Use this to
write a test of the cmd_sf layer by issuing a series of commands and
making sure that the correct SPI flash contents is obtained

- Create a test MMC or IDE device, backed by a file. Use this to issue
ext2 and fat commands to manipulate the filesystem. Then loopback
mount the file and check from Linux that U-Boot did the right thing

- Create a test Ethernet device with a mocked remote host attached.
Use this to issue network commands like bootp and tftp and check that
the correct results are obtained.

Ultimately (one day) we might have a set of unit tests for U-Boot
which can run to very quickly check that a patch does not break the
core U-Boot code.

Building
========

make ARCH=sandbox sandbox_config
make ARCH=sandbox all

(The lds script is targeted for bfd and might not work with the gold linker)

Comments
========
Comments are welcome and I have cc'd those who showed an interest to my
initial email. My goal is to create a real patch set in the next few weeks.

Please excuse the checkpatch violations, many of which seem to be less than
useful. This code is a bit rough in places, but I want comments on it before
polishing. There are a few strange things needed in the build as well, which
I hope to improve.

Changes in v2:
- Rebase to master
- Tidy top-level Makefile to minimise changes
- Try to avoid needing __attribute__((unused)) by assigning to an existing var
- Remove CONFIG_SYS_SDRAM_BASE which is always 0 for sandbox boards
- Fix #define<tab>
- Remove CONFIG_LMB
- Move os layer into arch/sandbox
- Remove clean and dist-clean targets from Makefile
- Try and fail to remove the global -I/usr/include
- Fix cast of int to pointer instead of just removing the code
- Move lds script out of the board directory
- Fix commit message typo, sadly
- Remove ARM cruft from Makefile
- Remove version_string and make display_banner() call display_options()
- Tidy up DRAM logic (but I think it is still needed to fit in with U-Boot)
- Remove use of CONFIG_SYS_NO_FLASH
- Make board_init_f() call board_init_r() for now
- Make board_init_r() call main_loop() for now
- Remove setting of LDSCRIPT (top level Makefile does this anyway)
- Add comment to do_reset() to justify the sandbox implementation
- Move lds script into cpu/sandbox
- Update commit message to remove 'temporary'
- Allow __WORDSIZE to be defined in Makefile / elsewhere
- Split this change out from 'Add architecture image support'
- Removed unneeded clock.h
- Moved gpio.h to asm-generic, removed GPIO_COUNT
- Removed kernel cruft from posix_types.h
- Removed dummy field from struct pt_regs
- Remove contents of string.h; instead include linux/string.h
- Remove unneeded functions in u-boot-sandbox.h
- Remove contents of unaligned.h; instead include asm-generic/unaligned.h

Simon Glass (20):
  sandbox: Add architecture header files
  Fix use of int as pointer in image.c
  sandbox: Add architecture image support
  sandbox: Add compiler defines to support a 64-bit x86_64 platform
  sandbox: Add cpu files
  sandbox: Add architecture lib files
  sandbox: Add sandbox board
  sandbox: Add board info for architecture
  sandbox: Add bootm support
  sandbox: Disable built-in malloc
  sandbox: Disable standalone/API support
  sandbox: Force command sections to be 4-byte aligned
  sandbox: Add OS dependent layer
  sandbox: Add board_init()
  sandbox: Add main program
  sandbox: Add serial uart
  sandbox: Add basic config file
  Remove unused variable warnings in cmd_mem, cmd_nvedit
  Use uintptr_t for 32/64-bit compatibility
  sandbox: Makefile changes to build sandbox architecture

 Makefile                                  |   23 ++-
 arch/sandbox/config.mk                    |   23 +++
 arch/sandbox/cpu/sandbox/Makefile         |   52 +++++
 arch/sandbox/cpu/sandbox/cpu.c            |   59 ++++++
 arch/sandbox/cpu/sandbox/os.c             |   49 +++++
 arch/sandbox/cpu/sandbox/u-boot.lds       |   34 ++++
 arch/sandbox/include/asm/bitops.h         |  162 ++++++++++++++++
 arch/sandbox/include/asm/byteorder.h      |   40 ++++
 arch/sandbox/include/asm/config.h         |   26 +++
 arch/sandbox/include/asm/global_data.h    |   68 +++++++
 arch/sandbox/include/asm/io.h             |   41 ++++
 arch/sandbox/include/asm/posix_types.h    |   57 ++++++
 arch/sandbox/include/asm/ptrace.h         |   38 ++++
 arch/sandbox/include/asm/string.h         |   23 +++
 arch/sandbox/include/asm/system.h         |   36 ++++
 arch/sandbox/include/asm/types.h          |   72 +++++++
 arch/sandbox/include/asm/u-boot-sandbox.h |   38 ++++
 arch/sandbox/include/asm/u-boot.h         |   61 ++++++
 arch/sandbox/include/asm/unaligned.h      |   23 +++
 arch/sandbox/lib/Makefile                 |   51 +++++
 arch/sandbox/lib/board.c                  |  288 +++++++++++++++++++++++++++++
 arch/sandbox/lib/interrupts.c             |   39 ++++
 board/sandbox/common/Makefile             |   41 ++++
 board/sandbox/common/board.c              |   25 +++
 board/sandbox/common/main.c               |   33 ++++
 board/sandbox/sandbox/Makefile            |   44 +++++
 board/sandbox/sandbox/sandbox.c           |   54 ++++++
 boards.cfg                                |    1 +
 common/Makefile                           |    2 +
 common/cmd_bdinfo.c                       |   34 +++-
 common/cmd_bootm.c                        |    9 +-
 common/cmd_mem.c                          |   10 +-
 common/cmd_nvedit.c                       |    3 +-
 common/fdt_support.c                      |    8 +-
 common/image.c                            |    4 +-
 doc/README.sandbox                        |   47 +++++
 drivers/serial/Makefile                   |    1 +
 drivers/serial/sandbox.c                  |   67 +++++++
 include/asm-generic/gpio.h                |   25 +++
 include/command.h                         |   16 ++-
 include/common.h                          |    3 +
 include/compiler.h                        |   12 +-
 include/configs/sandbox.h                 |   77 ++++++++
 include/image.h                           |    3 +
 include/linux/string.h                    |    2 +
 include/os.h                              |   27 +++
 46 files changed, 1821 insertions(+), 30 deletions(-)
 create mode 100644 arch/sandbox/config.mk
 create mode 100644 arch/sandbox/cpu/sandbox/Makefile
 create mode 100644 arch/sandbox/cpu/sandbox/cpu.c
 create mode 100644 arch/sandbox/cpu/sandbox/os.c
 create mode 100644 arch/sandbox/cpu/sandbox/u-boot.lds
 create mode 100644 arch/sandbox/include/asm/bitops.h
 create mode 100644 arch/sandbox/include/asm/byteorder.h
 create mode 100644 arch/sandbox/include/asm/config.h
 create mode 100644 arch/sandbox/include/asm/global_data.h
 create mode 100644 arch/sandbox/include/asm/io.h
 create mode 100644 arch/sandbox/include/asm/posix_types.h
 create mode 100644 arch/sandbox/include/asm/ptrace.h
 create mode 100644 arch/sandbox/include/asm/string.h
 create mode 100644 arch/sandbox/include/asm/system.h
 create mode 100644 arch/sandbox/include/asm/types.h
 create mode 100644 arch/sandbox/include/asm/u-boot-sandbox.h
 create mode 100644 arch/sandbox/include/asm/u-boot.h
 create mode 100644 arch/sandbox/include/asm/unaligned.h
 create mode 100644 arch/sandbox/lib/Makefile
 create mode 100644 arch/sandbox/lib/board.c
 create mode 100644 arch/sandbox/lib/interrupts.c
 create mode 100644 board/sandbox/common/Makefile
 create mode 100644 board/sandbox/common/board.c
 create mode 100644 board/sandbox/common/main.c
 create mode 100644 board/sandbox/sandbox/Makefile
 create mode 100644 board/sandbox/sandbox/sandbox.c
 create mode 100644 doc/README.sandbox
 create mode 100644 drivers/serial/sandbox.c
 create mode 100644 include/asm-generic/gpio.h
 create mode 100644 include/configs/sandbox.h
 create mode 100644 include/os.h

-- 
1.7.3.1



More information about the U-Boot mailing list