public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: "Łukasz Stelmach" <l.stelmach@samsung.com>
To: linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-samsung-soc@vger.kernel.org
Cc: "Łukasz Stelmach" <l.stelmach@samsung.com>
Subject: [RFC PATCH 0/4] boot/loader: Load kernel directly from firmware
Date: Thu, 30 Jan 2020 13:39:34 +0100	[thread overview]
Message-ID: <20200130123934.3900-1-l.stelmach@samsung.com> (raw)
In-Reply-To: CGME20200130124000eucas1p137943be0fe3e5e1eb45e705dc5c46431@eucas1p1.samsung.com

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


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

       reply	other threads:[~2020-01-30 12:40 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20200130124000eucas1p137943be0fe3e5e1eb45e705dc5c46431@eucas1p1.samsung.com>
2020-01-30 12:39 ` Łukasz Stelmach [this message]
2020-01-30 12:42   ` [RFC PATCH 1/4] scripts/dtc: update fdtget.c to upstream version v1.4.7-57-gf267e674d145 Łukasz Stelmach
2020-01-30 12:42     ` [RFC PATCH 2/4] scripts: add get_console_base.pl Łukasz Stelmach
2020-01-30 12:42     ` [RFC PATCH 3/4] Add tools/hsinit Łukasz Stelmach
2020-01-30 12:42     ` [RFC PATCH 4/4] boot/loader: Enable building bootloader replacement for Odroid XU4 Łukasz Stelmach
2020-01-30 12:47     ` [RFC PATCH 1/4] scripts/dtc: update fdtget.c to upstream version v1.4.7-57-gf267e674d145 Russell King - ARM Linux admin
2020-01-30 12:55       ` Łukasz Stelmach
2020-01-30 14:16     ` Rob Herring
2020-02-06 13:17       ` Łukasz Stelmach

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200130123934.3900-1-l.stelmach@samsung.com \
    --to=l.stelmach@samsung.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox