[RFC PATCH 0/4] boot/loader: Load kernel directly from firmware

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patchset is a PoC showing, it is possible and advantageous to
integrate platform setup code in the kernel tree instead of maintaining
it in a separate bootloader project.

Bringing up a new ARM platform today requires developing the following
pieces code in both bootloader and kernel:

+ platform setup (DRAM, minimal set of clocks and PMICs etc)
  - minimal setup in bootloader
  - full setup in kernel
+ device drivers (storage, network interface, display)
  - in both bootloader and kernel

We've noticed that most code required in bootloader can be ported from
Linux. This isn't, however, effortless. We also consider further
maintenance of two copies of code an unnecessary burden. Making platform
setup code a part of kernel source tree makes it possible to reuse existing
Linux drivers in bootloading environment as well as to avoid creating
and maintainig two different drivers for new devices.

The following patches enables building Linux image that is loadable
directly by Odroid XU4's firmware (bl2). The goal for such arrangement
is to use Linux as a boot loader that later runs a full OS using kexec.

Hardkernel, the vendor of Odroid XU4, provides signed, and thus,
cumbersome to replace, platform setup code (bl1 and bl2). We decided not
to replace them, but rather make the kernel loadable by the bl2 code by
adding only a tiny amount of code to set up the consol. The kernel
needs, however, to be small enough to be loaded succesfully (1 MiB).

The patchset also provides hsinit (in tools/hsinit) userland program,
which is a tiny init program that extracts designated archive to
initramfs and executes /init. At the moment any initramfs image can be
used at this stage.

Although hsinit can be linked against glibc it makes little sense
because together with the kernel it wont fit in 1 MiB. Instead it is
recommended to link hsinit against musl libc. Install musl from your OS
vendor or follow the upstream instructions. With musl available enter
tools/hsinit and run the following commands.

--8<---------------cut here---------------start------------->8---
wget -P vendor/ https://libarchive.org/downloads/libarchive-3.3.2.tar.gz
wget -P vendor/ http://prdownloads.sourceforge.net/libpng/zlib-1.2.11.tar.gz

./bootstrap

MUSL_DIR=/usr/lib/arm-linux-musleabi/ \
GCC_CROSS_DIR=/usr/lib/gcc-cross/arm-linux-gnueabi/8/ \
CPPFLAGS='-nostdinc -isystem /usr/include/arm-linux-musleabi/' \
CFLAGS='-mthumb -Os -ffunction-sections -fdata-sections' \
LIBARCHIVE_CPP_FLAGS=-I/usr/include/arm-linux-musleabi/ \
LIBARCHIVE_C_FLAGS=$CFLAGS \
ZLIB_C_FLAGS=$CFLAGS \
LDFLAGS="-nostdlib -L${MUSL_DIR}/ -L${GCC_CROSS_DIR}/ ${MUSL_DIR}/crt1.o  ${MUSL_DIR}/crti.o  ${GCC_CROSS_DIR}/crtbegin.o -Wl,--gc-sections -Wl,--start-group  ${GCC_CROSS_DIR}/libgcc.a  ${GCC_CROSS_DIR}/libgcc_eh.a -Wl,--end-group ${GCC_CROSS_DIR}/crtend.o  ${MUSL_DIR}/crtn.o -s"  \
LIBS="-lc -lgcc" \
./configure --enable-local-libraries --host=arm-linux-gnueabi --enable-static

make
--8<---------------cut here---------------end--------------->8---

To build bootImage file that is loadable by Odroid XU4's bl2 the following
commands need to be issued (CROSS_COMPILE and ARCH ommited)

--8<---------------cut here---------------start------------->8---
make odroidxu4_bootloader_defconfig
make dtbs
make bootImage
--8<---------------cut here---------------end--------------->8---

The resulting arch/arm/boot/bootImage should be renamed to u-boot-mmc.bin and
flashed onto an SD or eMMC card with sd_fusing scritp.




Łukasz Stelmach (4):
  scripts/dtc: update fdtget.c to upstream version v1.4.7-57-gf267e674d145
  scripts: add get_console_base.pl
  Add tools/hsinit
  boot/loader: Enable building bootloader replacement for Odroid XU4

 arch/arm/Kconfig                              |   8 +
 arch/arm/Makefile                             |   8 +-
 arch/arm/boot/Makefile                        |  17 +
 arch/arm/boot/loader/Kconfig                  |  23 ++
 arch/arm/boot/loader/Makefile                 |  42 +++
 arch/arm/boot/loader/odroid-console.c         | 136 ++++++++
 arch/arm/boot/loader/odroid-crt0.S            |  40 +++
 arch/arm/boot/loader/piggy.S                  |  14 +
 arch/arm/boot/loader/vectors.S                | 112 +++++++
 arch/arm/boot/loader/vmlinux.lds              |  17 +
 .../configs/odroidxu4_bootloader_defconfig    | 127 ++++++++
 scripts/dtc/.gitignore                        |   4 +
 scripts/dtc/Makefile                          |   5 +
 scripts/dtc/fdtget.c                          | 125 ++++----
 scripts/dtc/update-dtc-source.sh              |   4 +-
 scripts/get_console_base.pl                   |  26 ++
 tools/hsinit/Makefile.am                      |  29 ++
 tools/hsinit/README.org                       |  56 ++++
 tools/hsinit/bootstrap                        |   7 +
 tools/hsinit/configure.ac                     | 128 ++++++++
 tools/hsinit/hsinit.c                         | 299 ++++++++++++++++++
 tools/hsinit/vendor/.gitignore                |   5 +
 tools/hsinit/vendor/SHA256SUMS                |   2 +
 23 files changed, 1177 insertions(+), 57 deletions(-)
 create mode 100644 arch/arm/boot/loader/Kconfig
 create mode 100644 arch/arm/boot/loader/Makefile
 create mode 100644 arch/arm/boot/loader/odroid-console.c
 create mode 100644 arch/arm/boot/loader/odroid-crt0.S
 create mode 100644 arch/arm/boot/loader/piggy.S
 create mode 100644 arch/arm/boot/loader/vectors.S
 create mode 100644 arch/arm/boot/loader/vmlinux.lds
 create mode 100644 arch/arm/configs/odroidxu4_bootloader_defconfig
 create mode 100755 scripts/get_console_base.pl
 create mode 100644 tools/hsinit/Makefile.am
 create mode 100644 tools/hsinit/README.org
 create mode 100755 tools/hsinit/bootstrap
 create mode 100644 tools/hsinit/configure.ac
 create mode 100644 tools/hsinit/hsinit.c
 create mode 100644 tools/hsinit/vendor/.gitignore
 create mode 100644 tools/hsinit/vendor/SHA256SUMS

-- 
2.20.1




[Index of Archives]     [Linux SoC Development]     [Linux Rockchip Development]     [Linux for Synopsys ARC Processors]    
  • [Linux on Unisoc (RDA Micro) SoCs]     [Linux Actions SoC]     [Linux USB Development]     [Video for Linux]     [Linux Audio Users]     [Linux SCSI]     [Yosemite News]

  •   Powered by Linux