kumquat-buildroot/board/canaan/k210-soc/rootfs_overlay/sbin/init
Damien Le Moal 6939b5cacf board: Add common support for Canaan K210 SoC-based boards
The Linux environment for all boards using the Canaan Kendryte K210 SoC
can be built with the same process, using configurations that differ
only by the device tree used for the build. This patch add the
shared configurations, rootfs overlay and scripts used for all
K210-based boards.

Since the K210 SoC only has 8 MB of SRAM, a special busybox
configuration and rootfs overlay are added to save memory at runtime:
* For configurations using direct kernel boot (no boot loader), the
  default busybox configuration busybox-minimal.config is modified
  using the fragment file board/canaan/k210-soc/busybox-tiny.config.
  This reduces the size of the busybox executable to save memory when
  executing shell commands.
* Busybox init system is not used and a special init scripts is provided
  using the rootfs_overlay root file system overlay. This init script
  simply mounts devtmpfs, /proc and /sys, and exec an interactive shell
  after printing a logo. This avoids (1) boot failures due to large
  memory allocations by the regular busybox init system (these
  allocations fail on the K210 for lack of enough memory) and avoids
  (2) keeping the init process sleeping in the background (wasted
  memory).

The board/canaan/k210-soc/busybox-tiny.config and the rootfs overlay
files in board/canaan/k210-soc/rootfs_overlay are used for all Canaan
K210 SoC based boards.

For board configurations booting using the U-Boot boot loader, a common
set of linux kernel configuration parameters is provided by the file
board/canaan/k210-soc/linux-sdcard.config. In addition, the post build
script board/canaan/k210-soc/post-build.sh file and U-Boot image
generation configuration file board/canaan/k210-soc/genimage.cfg are
provided. The post-build script creates a generic "k210.dtb" symlink to
the compiled device tree file for the target board. This symlink is used
by the genimage.cfg configuration, making this file common for all
boards.

Signed-off-by: Niklas Cassel <niklas.cassel@wdc.com>
Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
2022-07-23 16:38:54 +02:00

42 lines
1.2 KiB
Bash
Executable File

#!/bin/sh
# This script replaces the default busybox init process to avoid having that
# process staying alive and sleeping in the background, (uselessly) consuming
# precious memory.
# Mount procfs and sysfs
/bin/mount -t proc proc /proc
/bin/mount -t sysfs sysfs /sys
# When the kernel is directly booted, devtmpfs is not automatically mounted.
# Manually mount it if needed.
devmnt=$(mount | grep -c devtmpfs)
if [ ${devmnt} -eq 0 ]; then
/bin/mount -t devtmpfs devtmpfs /dev
fi
# Use the /dev/console device node from devtmpfs if possible to not
# confuse glibc's ttyname_r().
# This may fail (E.G. booted with console=), and errors from exec will
# terminate the shell, so use a subshell for the test
if (exec 0</dev/console) 2>/dev/null; then
exec 0</dev/console
exec 1>/dev/console
exec 2>/dev/console
fi
# Clear memory to reduce page fragmentation
echo 3 > /proc/sys/vm/drop_caches
# Print a fun logo :)
echo " __ _"
echo " / / (_) ____ _ _ __ __"
echo " / / | || _ \\ | | | |\\ \\/ /"
echo " / /___| || | | || |_| | > < "
echo " /_____/|_||_| |_| \\____|/_/\\_\\"
echo " 64-bits RISC-V Kendryte K210 NOMMU"
echo ""
# Finally, let's start an interactive shell
exec /bin/sh