From fc4c6b5e51868b8df3bbfa53e52899123b891769 Mon Sep 17 00:00:00 2001 From: ading2210 Date: Sun, 1 Oct 2023 23:08:31 -0700 Subject: [PATCH] patch shim initramfs --- bootloader/bootstrap.sh | 44 +++++++++++++++++++++++++++++++++++++++++ bootloader/init.sh | 30 ++++++++++++++++++++++++++++ build.sh | 5 ++++- patch_initramfs.sh | 15 ++++++++++++++ 4 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 bootloader/bootstrap.sh create mode 100644 bootloader/init.sh create mode 100755 patch_initramfs.sh diff --git a/bootloader/bootstrap.sh b/bootloader/bootstrap.sh new file mode 100644 index 0000000..df30f4d --- /dev/null +++ b/bootloader/bootstrap.sh @@ -0,0 +1,44 @@ +#!/bin/busybox sh +# Copyright 2015 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +# +# To bootstrap the factory installer on rootfs. This file must be executed as +# PID=1 (exec). +# Note that this script uses the busybox shell (not bash, not dash). + +#original: https://chromium.googlesource.com/chromiumos/platform/initramfs/+/refs/heads/main/factory_shim/bootstrap.sh + +set +x + +invoke_terminal() { + local tty="$1" + local title="$2" + shift + shift + # Copied from factory_installer/factory_shim_service.sh. + echo "${title}" >>${tty} + setsid sh -c "exec script -afqc '$*' /dev/null <${tty} >>${tty} 2>&1 &" +} + +enable_debug_console() { + local tty="$1" + info -e '\033[1;33m[cros_debug] enabled on '${tty}'.\033[m' + invoke_terminal "${tty}" "[Bootstrap Debug Console]" "/bin/busybox sh" +} + + +main() { + # Setup environment. + #kill_frecon + #tty_init + + info "...:::||| Bootstrapping ChromeOS Factory Shim |||:::..." + info "TTY: ${TTY}, LOG: ${LOG_TTY}, INFO: ${INFO_TTY}, DEBUG: ${DEBUG_TTY}" + echo "idk please work" + + enable_debug_console "/dev/pts/0" +} + +main "$@" +sleep 1d \ No newline at end of file diff --git a/bootloader/init.sh b/bootloader/init.sh new file mode 100644 index 0000000..878181f --- /dev/null +++ b/bootloader/init.sh @@ -0,0 +1,30 @@ +#!/bin/busybox sh +# Copyright 2015 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +# +# /init script for use in factory install shim. +# Note that this script uses the busybox shell (not bash, not dash). + +#original: https://chromium.googlesource.com/chromiumos/platform/initramfs/+/refs/heads/main/factory_shim/init + +set -x + +. /lib/init.sh + +setup_environment() { + initialize + + # Install additional utility programs. + /bin/busybox --install /bin || true +} + +main() { + setup_environment + # In case an error is not handled by bootstrapping, stop here + # so that an operator can see installation stop. + exec bootstrap.sh || sleep 1d +} + +main "$@" +exit 1 \ No newline at end of file diff --git a/build.sh b/build.sh index dcab437..8bf94b2 100755 --- a/build.sh +++ b/build.sh @@ -56,10 +56,13 @@ echo "extracting initramfs cpio archive" initramfs_dir=/tmp/shim_initramfs rm -rf $initramfs_dir cat $cpio_file | cpio -D $initramfs_dir -imd --quiet - echo "shim initramfs extracted to ${initramfs_dir}" +#leave /tmp cd $previous_dir +echo "patching initramfs" +exec ./patch_initramfs.sh $initramfs_dir + echo "cleaning up loop devices" losetup -d $shim_loop \ No newline at end of file diff --git a/patch_initramfs.sh b/patch_initramfs.sh new file mode 100755 index 0000000..7f795d6 --- /dev/null +++ b/patch_initramfs.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +#patch the shim initramfs to add the bootloader + +set -e +if [ "$DEBUG" ]; then + set -x +fi + +initramfs_path=$(realpath $1) + +rm "${initramfs_path}/init" -f +cp bootloader/init.sh "${initramfs_path}/sbin/init" +cp bootloader/bootstrap.sh "${initramfs_path}/sbin/bootstrap.sh" +chmod +x "${initramfs_path}/sbin/*.sh" \ No newline at end of file