From 32ec57d62ddf533bfb713b5223bafc94ad1defb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Wed, 20 Oct 2021 21:11:48 +0100 Subject: [PATCH] Unhardcode x86 from initial steps. --- lib/sysgeneral.py | 4 ++++ rootfs.py | 5 ++++- sysa.py | 10 +++++++--- sysa/after.kaem.amd64 | 9 +++++++++ sysa/after.kaem.x86 | 9 +++++++++ sysa/{after.kaem => run.kaem} | 32 +++++++++++++++----------------- 6 files changed, 48 insertions(+), 21 deletions(-) create mode 100644 sysa/after.kaem.amd64 create mode 100644 sysa/after.kaem.x86 rename sysa/{after.kaem => run.kaem} (77%) diff --git a/lib/sysgeneral.py b/lib/sysgeneral.py index 8ef332b..edc094b 100644 --- a/lib/sysgeneral.py +++ b/lib/sysgeneral.py @@ -165,3 +165,7 @@ class SysGeneral: "--directory", self.tmp_dir], stdin=subprocess.PIPE, stdout=initramfs) cpio.communicate(input='\n'.join(file_list).encode()) + +stage0_arch_map = { + "amd64": "AMD64", +} diff --git a/rootfs.py b/rootfs.py index 3c88746..fe00adf 100755 --- a/rootfs.py +++ b/rootfs.py @@ -20,6 +20,7 @@ from sysa import SysA from sysb import SysB from sysc import SysC from lib.utils import run +from lib.sysgeneral import stage0_arch_map def create_configuration_file(args): """ @@ -123,8 +124,10 @@ print(shutil.which('chroot')) """ chroot_binary = run('sudo', 'python3', '-c', find_chroot, capture_output=True).stdout.decode().strip() + # sysa - init = os.path.join(os.sep, 'bootstrap-seeds', 'POSIX', args.arch, 'kaem-optional-seed') + arch = stage0_arch_map.get(args.arch, args.arch) + init = os.path.join(os.sep, 'bootstrap-seeds', 'POSIX', arch, 'kaem-optional-seed') run('sudo', 'env', '-i', 'PATH=/bin', chroot_binary, system_a.tmp_dir, init) elif args.minikernel: diff --git a/sysa.py b/sysa.py index 65c2209..945fe13 100755 --- a/sysa.py +++ b/sysa.py @@ -9,7 +9,7 @@ import os from distutils.dir_util import copy_tree import shutil -from lib.sysgeneral import SysGeneral +from lib.sysgeneral import SysGeneral, stage0_arch_map # pylint: disable=consider-using-with class SysA(SysGeneral): @@ -72,14 +72,18 @@ class SysA(SysGeneral): stage0_posix_base_dir = os.path.join(self.sys_dir, 'stage0-posix', 'src') copy_tree(stage0_posix_base_dir, self.tmp_dir) + arch = stage0_arch_map.get(self.arch, self.arch) kaem_optional_seed = os.path.join(self.sys_dir, 'stage0-posix', 'src', 'bootstrap-seeds', - 'POSIX', self.arch, 'kaem-optional-seed') + 'POSIX', arch, 'kaem-optional-seed') shutil.copy2(kaem_optional_seed, os.path.join(self.tmp_dir, 'init')) # stage0-posix hook to continue running live-bootstrap - shutil.copy2(os.path.join(self.sys_dir, 'after.kaem'), + shutil.copy2(os.path.join(self.sys_dir, f"after.kaem.{self.arch}"), os.path.join(self.tmp_dir, 'after.kaem')) + shutil.copy2(os.path.join(self.sys_dir, 'run.kaem'), + os.path.join(self.tmp_dir, 'run.kaem')) + def after(self): """ Prepare sources in /after directory. diff --git a/sysa/after.kaem.amd64 b/sysa/after.kaem.amd64 new file mode 100644 index 0000000..cec8e3f --- /dev/null +++ b/sysa/after.kaem.amd64 @@ -0,0 +1,9 @@ +#!/bin/sh + +# SPDX-FileCopyrightText: 2021 Andrius Štikonas +# +# SPDX-License-Identifier: GPL-3.0-or-later + +ARCH=amd64 +STAGE0_ARCH=AMD64 +exec /${STAGE0_ARCH}/bin/kaem --verbose --file run.kaem diff --git a/sysa/after.kaem.x86 b/sysa/after.kaem.x86 new file mode 100644 index 0000000..d2c07eb --- /dev/null +++ b/sysa/after.kaem.x86 @@ -0,0 +1,9 @@ +#!/bin/sh + +# SPDX-FileCopyrightText: 2021 Andrius Štikonas +# +# SPDX-License-Identifier: GPL-3.0-or-later + +ARCH=x86 +STAGE0_ARCH=x86 +exec /${ARCH}/bin/kaem --verbose --file run.kaem diff --git a/sysa/after.kaem b/sysa/run.kaem similarity index 77% rename from sysa/after.kaem rename to sysa/run.kaem index 94d24eb..59aaaa7 100755 --- a/sysa/after.kaem +++ b/sysa/run.kaem @@ -8,9 +8,7 @@ set -ex -ARCH=x86 - -PATH=/${ARCH}/bin +PATH=/${STAGE0_ARCH}/bin # Set commonly used variables sources=/after @@ -29,20 +27,20 @@ mkdir ${prefix} ${bindir} ${libdir} ${incdir} ${tmpdir} cd ${prefix} # Remove remaining dependencies on /bin (stage0-posix directory) -cp /${ARCH}/bin/blood-elf bin/blood-elf -cp /${ARCH}/bin/catm bin/catm -cp /${ARCH}/bin/chmod bin/chmod -cp /${ARCH}/bin/get_machine bin/get_machine -cp /${ARCH}/bin/hex2 bin/hex2 -cp /${ARCH}/bin/kaem bin/kaem -cp /${ARCH}/bin/match bin/match -cp /${ARCH}/bin/M1 bin/M1 -cp /${ARCH}/bin/M2-Planet bin/M2-Planet -cp /${ARCH}/bin/mkdir bin/mkdir -cp /${ARCH}/bin/sha256sum bin/sha256sum -cp /${ARCH}/bin/ungz bin/ungz -cp /${ARCH}/bin/untar bin/untar -cp /${ARCH}/bin/cp bin/cp +cp /${STAGE0_ARCH}/bin/blood-elf bin/blood-elf +cp /${STAGE0_ARCH}/bin/catm bin/catm +cp /${STAGE0_ARCH}/bin/chmod bin/chmod +cp /${STAGE0_ARCH}/bin/get_machine bin/get_machine +cp /${STAGE0_ARCH}/bin/hex2 bin/hex2 +cp /${STAGE0_ARCH}/bin/kaem bin/kaem +cp /${STAGE0_ARCH}/bin/match bin/match +cp /${STAGE0_ARCH}/bin/M1 bin/M1 +cp /${STAGE0_ARCH}/bin/M2-Planet bin/M2-Planet +cp /${STAGE0_ARCH}/bin/mkdir bin/mkdir +cp /${STAGE0_ARCH}/bin/sha256sum bin/sha256sum +cp /${STAGE0_ARCH}/bin/ungz bin/ungz +cp /${STAGE0_ARCH}/bin/untar bin/untar +cp /${STAGE0_ARCH}/bin/cp bin/cp chmod 755 bin/blood-elf chmod 755 bin/catm