Files
makronix/mobile/tools/mkroottar.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

65 lines
2.6 KiB
Bash
Executable File

#!/bin/sh
# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
#
# Assemble one device's system tree as a tar, for tools/update-root.sh: the
# same tree tools/mkrootimg.sh puts into an image as /system/current, without
# the image around it. An update unpacks it into /system/<version>/ on the
# phone and switches /system/current to it; /data is not touched.
#
# Usage: mkroottar.sh DEVICEDIR ROOTFS.tar KERNEL_TREE OUT.tar ROOT_PASSWORD
#
# No root: assembled inside a user namespace, where the tar's files are owned
# by 0 and stay 0 in the new tar.
set -eu
. "$(dirname "$0")/lib.sh"
PATH=$PATH:/sbin:/usr/sbin
[ $# -eq 5 ] || { echo "usage: $0 DEVICEDIR ROOTFS.tar KERNEL_TREE OUT.tar ROOT_PASSWORD" >&2; exit 2; }
load_device "$1"
abs() { echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"; }
tarball=$(abs "$2") tree=$(cd "$3" && pwd) out=$(abs "$4") password=$5
[ -f "$tarball" ] || die "no rootfs $tarball (make rootfs BASE=...)"
[ -n "$password" ] || die "empty ROOT_PASSWORD"
base=$(basename "$tarball" .tar)
base=${base#rootfs-}
base=${base%-"$(basename "$DEVDIR")"}
[ -f "$ROOT/base/$base/base.conf" ] || die "cannot tell the base from $tarball"
work=$ROOT/build/roottar-work.$$
mkdir -p "$work"
trap 'unshare --map-root-user --map-auto rm -rf "$work"' EXIT
release=$(cat "$tree/include/config/kernel.release")
kernel_make "$tree" -s \
INSTALL_MOD_PATH="$work/modules" INSTALL_MOD_STRIP=1 modules_install
[ -d "$work/modules/lib/modules/$release" ] || die "modules_install wrote no $release"
"${CROSS_COMPILE}gcc" -static -Os -Wall -Werror -o "$work/reboot2" \
"$ROOT/base/reboot2.c" || die "cannot build base/reboot2.c"
"${CROSS_COMPILE}strip" "$work/reboot2"
# the NetBSD userland, staged outside the namespace (tools/lib.sh)
userland_stage "$(basename "$DEVDIR")" "$work/userland"
pwhash=$(openssl passwd -6 "$password")
makronix_version
export MRI_WORK="$work" MRI_TAR="$tarball" MRI_OUT="$out" MRI_PWHASH="$pwhash" \
MRI_UUID="${ROOT_UUID:-}" MRI_RELEASE="$release" \
MRI_MXRELEASE="Makronix $MX_RELEASE $MX_CODENAME ($MX_CHANNEL)" \
MRI_SOCDIR="$ROOT/soc/$SOC" MRI_BASE="$base" \
MRI_BASEDIR="$ROOT/base/$base" MRI_ASM="$ROOT/tools/assemble-rootfs.sh" \
MRI_USERLAND="$work/userland"
unshare --map-root-user --map-auto sh -eu -c '
mkdir -p "$MRI_WORK/tree"
sh "$MRI_ASM" "$MRI_WORK/tree" "$MRI_TAR" \
"$MRI_WORK/modules/lib/modules" "$MRI_RELEASE" "$MRI_BASEDIR" \
"$MRI_SOCDIR" "$MRI_BASE" "$MRI_WORK/reboot2" "$MRI_PWHASH" \
"$MRI_UUID" "$MRI_MXRELEASE" "$MRI_USERLAND"
rm -f "$MRI_OUT"
tar -C "$MRI_WORK/tree" -cf "$MRI_OUT" .
'
echo "$out: $(wc -c < "$out" | tr -d ' ') bytes, modules $release"