Files
makronix/mobile/tools/mkinitramfs.sh
T
lotherkandClaude Sonnet 5.5 73c9de51a6 licence: the CNCL line in every file Makronix wrote (tools, docs, www, mobile, top level)
consmirror.c: the BSD notice is replaced (Makronix's own file).  Files with
changes of other sessions pending are left for their commit.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-14 11:50:26 +00:00

34 lines
1.2 KiB
Bash

#!/bin/sh
# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
#
# Build the initramfs of Makronix Mobile: base/initramfs/init and our static
# busybox (tools/build-busybox.sh), as a gzip'd newc cpio owned by root.
#
# Usage: mkinitramfs.sh BUSYBOX OUT.cpio.gz
#
# Nothing in it comes from a distribution, so one initramfs serves every base
# of an architecture. No device nodes are needed in the archive: the
# kernel's built-in initramfs already holds /dev/console, and /init mounts
# devtmpfs. Reproducible: fixed mtimes, sorted entries, gzip -n.
set -eu
. "$(dirname "$0")/lib.sh"
[ $# -eq 2 ] || { echo "usage: $0 BUSYBOX OUT.cpio.gz" >&2; exit 2; }
busybox=$1 out=$2
file "$busybox" | grep -q 'statically linked' || die "$busybox is not a static binary"
work=$ROOT/build/initramfs-work.$$
trap 'rm -rf "$work"' EXIT
mkdir -p "$work/root/bin"
cp "$busybox" "$work/root/bin/busybox"
chmod 755 "$work/root/bin/busybox"
cp "$ROOT/base/initramfs/init" "$work/root/init"
chmod 755 "$work/root/init"
find "$work/root" -exec touch -h -d @0 {} +
(cd "$work/root" && find . | LC_ALL=C sort |
cpio --quiet -o -H newc -R 0:0 --reproducible) | gzip -n -9 > "$out.tmp"
mv "$out.tmp" "$out"
echo "$out: $(wc -c < "$out" | tr -d ' ') bytes"