aboutsummaryrefslogtreecommitdiff
path: root/bootstrap
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2022-09-28 07:03:59 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2022-10-04 06:17:08 +0200
commit4ae045d72d710a25ecdbe2c71499ac05f7bcfa47 (patch)
tree076fa0149f9e1cc3bc923f1709e14f0dba5beca5 /bootstrap
parentd916317c8c5c0093978a13495c17cf8b319d3ad9 (diff)
Add support for --arch-variant, --kernel-source
Diffstat (limited to 'bootstrap')
-rwxr-xr-xbootstrap120
1 files changed, 88 insertions, 32 deletions
diff --git a/bootstrap b/bootstrap
index 773b379..5d560b7 100755
--- a/bootstrap
+++ b/bootstrap
@@ -28,8 +28,22 @@
# 5 - create footfs
# 6 - create kernel image and initrd
#
+# --arch-variant
+# Architecture variant, for example, m1 for aarch64-m1.
+#
+# --kernel-source
+# Pre-configured Linux kernel source .tar.* archive. If unspecified, Debian
+# source/configuration will be used.
+#
usage="usage: $0"
+owd="$(pwd)"
+trap "{ cd '$owd'; exit 1; }" ERR
+set -o errtrace # Trap in functions.
+
+function info () { echo "$*" 1>&2; }
+function error () { info "$*"; exit 1; }
+
id="$(id -un)"
btrfs=/btrfs
root="$btrfs/$id/buildos"
@@ -98,15 +112,12 @@ esac
extra_pkgs=""
-owd="$(pwd)"
-trap "{ cd '$owd'; exit 1; }" ERR
-set -o errtrace # Trap in functions.
-
-function info () { echo "$*" 1>&2; }
-function error () { info "$*"; exit 1; }
-
-stage="1"
-stage_max="6"
+# Options.
+#
+stage=1
+stage_max=6
+arch_variant=
+kernel_source=
while [ "$#" -gt 0 ]; do
case "$1" in
@@ -115,6 +126,16 @@ while [ "$#" -gt 0 ]; do
stage="$1"
shift
;;
+ --arch-variant)
+ shift
+ arch_variant="$1"
+ shift
+ ;;
+ --kernel-source)
+ shift
+ kernel_source="$1"
+ shift
+ ;;
-*)
error "unknown option: $1"
;;
@@ -128,6 +149,11 @@ if [ "$stage" -lt "1" -o "$stage" -gt "$stage_max" ]; then
error "invalid stage number $stage"
fi
+arch_with_variant="$arch"
+if [ -n "$arch_variant" ]; then
+ arch_with_variant="$arch_with_variant-$arch_variant"
+fi
+
# Extract version.
#
version="$(sed -n -re 's/^version: ([0-9]+\.[0-9]+\.[0-9]+).*$/\1/p' ./manifest)"
@@ -410,6 +436,12 @@ EOF
subvol_delete "$root-3-kernel"
subvol_snapshot "$root" "$root-3-kernel"
+ # Copy custom kernel source.
+ #
+ if [ -n "$kernel_source" ]; then
+ sudo install -m 644 "$kernel_source" "$root-3-kernel/usr/src/"
+ fi
+
# Copy patches.
#
#sudo cp ./patches/tftp-hpa-partial-upload.patch "$root-3-kernel/bootstrap/"
@@ -450,20 +482,33 @@ fi
# kernel with adjusted configuration. Taken from the Debian Kernel Handbook.
#
apt-get update
-apt-get install -y linux-source
+apt-get install -y bc
apt-get install -y bison flex
apt-get install -y libelf-dev
apt-get install -y libssl-dev
-apt-get install -y rsync
+apt-get install -y cpio rsync
apt-get install -y dwarves
+apt-get install -y device-tree-compiler
+
cd /usr/src
-tar xf linux-source-*
-mv linux-source-*/ linux
-xzcat linux-config-*/config.${debian_arch}_none_${debian_arch}.xz >linux/.config
+
+if [ -z "$kernel_source" ]; then
+ apt-get install -y linux-source
+ tar xf linux-source-*
+ mv linux-source-*/ linux
+ xzcat linux-config-*/config.${debian_arch}_none_${debian_arch}.xz >linux/.config
+else
+ kernel_source=\$(basename $kernel_source)
+ tar xf \$kernel_source
+ mv \$(sed -re 's/(.+)\.tar\..+/\1/' <<<\$kernel_source) linux
+fi
+
cd linux
# Adjust configuration.
#
+# Note that we do some of these even for the pre-configured kernel.
+#
# Note that SECURITY_LOCKDOWN_LSM forces MODULE_SIG ('select' in Kconfig).
#
# Generally, if you disable an option but it still appears enabled after
@@ -487,25 +532,30 @@ scripts/config --disable DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT
#
scripts/config --disable KCOV
scripts/config --disable SHADOW_CALL_STACK
+scripts/config --disable ZERO_CALL_USED_REGS
scripts/config --disable VIDEO_ADV7511
-# Disable sound subsystem/drivers.
-#
-sed -i -re '/^CONFIG_SND_.+/d' .config
-sed -i -re '/^CONFIG_SOUND_.+/d' .config
-scripts/config --disable CONFIG_SOUND
-scripts/config --disable CONFIG_SND
+if [ -z "$kernel_source" ]; then
-# Disable GPU subsystem/drivers.
-#
-# NOTE: this seems to have killed the high-resolution console.
-#
-sed -i -re '/^CONFIG_DRM_.+/d' .config
-scripts/config --disable CONFIG_DRM
+ # Disable sound subsystem/drivers.
+ #
+ sed -i -re '/^CONFIG_SND_.+/d' .config
+ sed -i -re '/^CONFIG_SOUND_.+/d' .config
+ scripts/config --disable CONFIG_SOUND
+ scripts/config --disable CONFIG_SND
-# Disable wireless network drivers.
-#
-scripts/config --disable CONFIG_WLAN
+ # Disable GPU subsystem/drivers.
+ #
+ # NOTE: this seems to have killed the high-resolution console.
+ #
+ sed -i -re '/^CONFIG_DRM_.+/d' .config
+ scripts/config --disable CONFIG_DRM
+
+ # Disable wireless network drivers.
+ #
+ scripts/config --disable CONFIG_WLAN
+
+fi
# Adjust kernel command line size limit.
#
@@ -690,6 +740,11 @@ if [ "$stage" -le "6" ]; then
sudo ln -sf "$root/usr/lib/systemd/system/buildos.service" \
"$root/etc/systemd/system/multi-user.target.wants/buildos.service"
+ # Patch in the arch variant.
+ #
+ sudo sed -i -e "s/^arch_variant=.*/arch_variant=$arch_variant/" \
+ "$root/usr/sbin/buildos"
+
info "generating buildos-init.cpio.xz..."
cd "$root"
@@ -703,12 +758,13 @@ etc/systemd/system/multi-user.target.wants/buildos.service
EOF
cd "$owd"
- cat buildos-rootfs.cpio.xz buildos-init.cpio.xz >"buildos-initrd-$arch"
+ cat buildos-rootfs.cpio.xz \
+ buildos-init.cpio.xz >"buildos-initrd-$arch_with_variant"
# Copy the kernel image next to the initramfs for convenience.
#
- cp "$root/vmlinuz" "buildos-image-$arch"
- echo "$buildid" >"buildos-buildid-$arch"
+ cp "$root/vmlinuz" "buildos-image-$arch_with_variant"
+ echo "$buildid" >"buildos-buildid-$arch_with_variant"
subvol_snapshot -r "$root" "$root-6"
fi