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

Simon Glass sjg at chromium.org
Mon Oct 10 20:22:13 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 set 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 or
type 'reset' 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.


Checkpatch notes:
The first patch generates a list of 34 checkpatch warnings.

warning: arch/sandbox/include/asm/global_data.h,38: do not add new typedefs

(This is the typedef for gd_t which I think is needed.)

warning: arch/sandbox/include/asm/global_data.h,64: storage class should be at the beginning of the declaration

(This line is:

which I need to keep, so that various files can declare that pointer.)

warning: arch/sandbox/include/asm/posix_types.h,22: do not add new typedefs
warning: arch/sandbox/include/asm/posix_types.h,23: do not add new typedefs
warning: arch/sandbox/include/asm/posix_types.h,24: do not add new typedefs
warning: arch/sandbox/include/asm/posix_types.h,25: do not add new typedefs
warning: arch/sandbox/include/asm/posix_types.h,26: do not add new typedefs
warning: arch/sandbox/include/asm/posix_types.h,27: do not add new typedefs
warning: arch/sandbox/include/asm/posix_types.h,28: do not add new typedefs
warning: arch/sandbox/include/asm/posix_types.h,29: do not add new typedefs
warning: arch/sandbox/include/asm/posix_types.h,30: do not add new typedefs
warning: arch/sandbox/include/asm/posix_types.h,32: do not add new typedefs
warning: arch/sandbox/include/asm/posix_types.h,33: do not add new typedefs
warning: arch/sandbox/include/asm/posix_types.h,34: do not add new typedefs
warning: arch/sandbox/include/asm/posix_types.h,36: do not add new typedefs
warning: arch/sandbox/include/asm/posix_types.h,37: do not add new typedefs
warning: arch/sandbox/include/asm/posix_types.h,38: do not add new typedefs
warning: arch/sandbox/include/asm/posix_types.h,40: do not add new typedefs
warning: arch/sandbox/include/asm/posix_types.h,41: do not add new typedefs
warning: arch/sandbox/include/asm/posix_types.h,42: do not add new typedefs
warning: arch/sandbox/include/asm/posix_types.h,43: do not add new typedefs
warning: arch/sandbox/include/asm/posix_types.h,44: do not add new typedefs
warning: arch/sandbox/include/asm/posix_types.h,45: do not add new typedefs
warning: arch/sandbox/include/asm/posix_types.h,46: do not add new typedefs
warning: arch/sandbox/include/asm/posix_types.h,47: do not add new typedefs
warning: arch/sandbox/include/asm/posix_types.h,48: do not add new typedefs
warning: arch/sandbox/include/asm/posix_types.h,50: do not add new typedefs
warning: arch/sandbox/include/asm/posix_types.h,51: do not add new typedefs
warning: arch/sandbox/include/asm/posix_types.h,54: do not add new typedefs

(These are things like:

typedef unsigned short		__kernel_dev_t;

and I believe they are needed.)

warning: arch/sandbox/include/asm/types.h,26: do not add new typedefs
warning: arch/sandbox/include/asm/types.h,66: do not add new typedefs
warning: arch/sandbox/include/asm/types.h,67: do not add new typedefs
warning: arch/sandbox/include/asm/types.h,68: do not add new typedefs
warning: arch/sandbox/include/asm/u-boot.h,39: do not add new typedefs

(These are similar, and common with other architectures, so I think they
are needed.)

Changes in v2:
- Rebase to master
- Tidy top-level Makefile to minimise changes
- 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'

Changes in v3:
- Change U-Boot's dependency generation to permit per-file flags
- Add os_exit() which always exits with success for now
- Add function comments to header file
- Call os_exit() in do_reset()
- Move cpu files into arch/sandbox/cpu
- Change do_reset() back to what it was
- Add architecture image support for sandbox

Changes in v4:
- Drop board/sandbox/common/board.c for now (no board_init() needed)
- Move main() into start.c to remove one ifdef from the top level Makefile
- Fix up Makefile for non-sandbox builds
- 'Improve' dependency generation to deal with source files containing paths
- Make sure that clobber target removes all dependency files
- Add CONFIG_SYS_SDRAM_SIZE for size of emulated SDRAM
- Add #ifdef protection around sandbox.h header file
- Remove serial_exit()
- Move main() into arch/sandbox/cpu/start.c
- Allow os_exit() to exit with a non-zero return code
- Add more info to command section alignment commit
- Remove board/sandbox/common directory as it is not used
- Drop CONFIG_POST support
- Drop call to board_init()
- Remove printing of memory setup which is meaningless in sandbox

Changes in v5:
- Move the introduction of include/asm-generic/gpio.h into a separate commit
- Add comments to GPIO functions
- Fix dependency output to include $(obj) for out-of-tree builds
- Simplify the declaration of gd_t in sandbox's board.c
- Define IH_ARCH_DEFAULT which is now required

Changes in v6:
- Remove volatile keyword from arch/sandbox/include/asm/bitops.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 main program
  sandbox: Add serial uart
  sandbox: Add basic config file
  Use uintptr_t for 32/64-bit compatibility
  Adjust dependency rules to permit per-file flags
  Add generic gpio.h in asm-generic
  sandbox: Makefile changes to build sandbox architecture

 .gitignore                                |    2 +-
 Makefile                                  |   19 ++-
 arch/sandbox/config.mk                    |   20 ++
 arch/sandbox/cpu/Makefile                 |   50 +++++
 arch/sandbox/cpu/cpu.c                    |   62 +++++++
 arch/sandbox/cpu/os.c                     |   55 ++++++
 arch/sandbox/cpu/start.c                  |   33 ++++
 arch/sandbox/cpu/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    |   66 +++++++
 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         |   64 +++++++
 arch/sandbox/include/asm/unaligned.h      |   23 +++
 arch/sandbox/lib/Makefile                 |   51 ++++++
 arch/sandbox/lib/board.c                  |  276 +++++++++++++++++++++++++++++
 arch/sandbox/lib/interrupts.c             |   39 ++++
 board/sandbox/sandbox/Makefile            |   42 +++++
 board/sandbox/sandbox/sandbox.c           |   49 +++++
 boards.cfg                                |    1 +
 common/Makefile                           |    2 +
 common/cmd_bdinfo.c                       |   34 +++-
 common/cmd_bootm.c                        |    7 +-
 common/cmd_mem.c                          |    2 +-
 common/fdt_support.c                      |    8 +-
 common/image.c                            |    4 +-
 config.mk                                 |    7 +
 doc/README.sandbox                        |   53 ++++++
 drivers/serial/Makefile                   |    1 +
 drivers/serial/sandbox.c                  |   63 +++++++
 include/asm-generic/gpio.h                |   74 ++++++++
 include/command.h                         |    3 +-
 include/common.h                          |    3 +
 include/compiler.h                        |   12 ++-
 include/configs/sandbox.h                 |   85 +++++++++
 include/image.h                           |    1 +
 include/os.h                              |   73 ++++++++
 rules.mk                                  |   44 ++++--
 45 files changed, 1862 insertions(+), 33 deletions(-)
 create mode 100644 arch/sandbox/config.mk
 create mode 100644 arch/sandbox/cpu/Makefile
 create mode 100644 arch/sandbox/cpu/cpu.c
 create mode 100644 arch/sandbox/cpu/os.c
 create mode 100644 arch/sandbox/cpu/start.c
 create mode 100644 arch/sandbox/cpu/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/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