Merge pull request #295 from rick-masters/kernel-bootstrap-phase2-v1

Kernel bootstrap phase2 v1
This commit is contained in:
Andrius Štikonas 2023-05-21 01:26:04 +01:00 committed by GitHub
commit 87e9d7db9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 454 additions and 305 deletions

View file

@ -11,13 +11,15 @@
bootstrap-seeds bootstrap-seeds
=============== ===============
This is where it all begins. We start with the two raw binary seeds ``hex0-seed`` and ``kaem-optional-seed``. This is where it all begins.
First, we use those seeds to rebuild themselves. A kernel bootstrapping option is used by default at the beginning. The tiny ``builder-hex0-x86-stage1`` binary seed boots, builds and runs the ``builder-hex0-x86-stage2`` kernel. The ``builder-hex0-x86-stage1`` and ``builder-hex0-x86-stage2`` kernels are written in ``hex0``. The stage2 kernel has its own built-in shell, the ``hex0`` compiler and the ``src`` tool to load files into its memory file system. In this case the first step is to build the ``hex0-seed`` and ``kaem-optional-seed`` binaries from ``hex0`` source.
Note that all early compilers before ``mes`` are part of `stage0-posix <https://github.com/oriansj/stage0-posix>`_. Note that all early shells and compilers before ``mes`` are part of `stage0-posix <https://github.com/oriansj/stage0-posix>`_.
A kernel bootstrapping option is used by default at the beginning. ``hex0-seed`` can be used to compile the ``builder-hex0`` kernel which has its own built-in shell, the ``hex0`` compiler and the ``src`` tool to load files into its file system. ``builder-hex0`` runs stage0-posix and then builds ``mes`` and ``tcc``. It then builds and launches the `Fiwix <https://github.com/mikaku/Fiwix>` kernel which runs the build until Linux takes over. ``builder-hex0-x86-stage2`` runs as the kernel for building the stage0-posix compilers and then ``mes`` and ``tcc``. Then the `Fiwix <https://github.com/mikaku/Fiwix>` kernel is built and launched. Then Fiwix runs the build until Linux takes over.
If chroot or bwrap is specified or if a pre-existing kernel is provided then we start with the two raw binary seeds ``hex0-seed`` and ``kaem-optional-seed``. We use those seeds to rebuild themselves.
hex0 hex0
@ -39,9 +41,16 @@ In the first steps we use initial ``hex0`` binary seed to rebuild ``kaem-optiona
``hex0`` can be approximated with: ``sed 's/[;#].*$//g' $input_file | xxd -r -p > $output_file`` ``hex0`` can be approximated with: ``sed 's/[;#].*$//g' $input_file | xxd -r -p > $output_file``
builder-hex0 builder-hex0-x86-stage1
============ =======================
By default (when kernel bootstrap is enabled), the ``builder-hex0`` kernel boots from a hard drive and loads an enormous shell script which embeds files (loaded with the ``src`` command) and the initial commands to build ``hex0-seed``, ``kaem-optional-seed``, and the command which launches stage0-posix using ``kaem-optional-seed`` and the stage0-posix launch script ``kaem.x86``. Builder-hex0 is written in hex0 and can be compiled with any one of ``hex0-seed``, ``sed``, the tiny ``builder-hex0-mini`` boot kernel or it can build itself.
By default (when kernel bootstrap is enabled), the ``builder-hex0-x86-stage1`` boot loader/compiler boots from a hard drive and loads ``hex0`` source code from disk, compiles, and runs the ``builder-hex0-x86-stage2`` kernel. ``builder-hex0-x86-stage1`` is written in ``hex0`` and can be compiled with any one of ``hex0-seed``, ``sed``, or the tiny ``builder-hex0-mini`` binary.
builder-hex0-x86-stage2
=======================
When kernel bootstrap is enabled, the ``builder-hex0-x86-stage2`` kernel loads an enormous shell script which embeds files (loaded with the ``src`` command) and the initial commands to build ``hex0-seed``, ``kaem-optional-seed``, and the command which launches stage0-posix using ``kaem-optional-seed`` and the stage0-posix launch script ``kaem.x86``.
kaem-optional kaem-optional
@ -222,6 +231,12 @@ kexec-fiwix
If the kernel bootstrap option is enabled then a C program `kexec-fiwix` is compiled If the kernel bootstrap option is enabled then a C program `kexec-fiwix` is compiled
and run which places the Fiwix ram drive in memory and launches the Fiwix kernel. and run which places the Fiwix ram drive in memory and launches the Fiwix kernel.
kexec-linux
===========
If the kernel bootstrap option is enabled then a C program `kexec-linux` is compiled.
This is used as part of the go_sysb step later to launch the Linux kernel.
make 3.82 make 3.82
========= =========
@ -686,11 +701,6 @@ The next step is not a package, but the creation of the sysb rootfs, containing
all of the scripts for sysb (which merely move to sysc). Again, this is only all of the scripts for sysb (which merely move to sysc). Again, this is only
done in non-chroot mode, because sysb does not exist in chroot mode. done in non-chroot mode, because sysb does not exist in chroot mode.
musl 1.2.3
==========
Prior to building and booting Linux, musl is rebuilt yet again with syscalls
``clone`` and ``set_thread_area`` enabled for Linux thread support.
Linux kernel 4.9.10 Linux kernel 4.9.10
=================== ===================
@ -711,6 +721,11 @@ subsequent systems, and we do not have ``modprobe``. Lastly,
the initramfs of sysb is generated in this stage, using ``gen_init_cpio`` within the initramfs of sysb is generated in this stage, using ``gen_init_cpio`` within
the Linux kernel tree. This avoids the compilation of ``cpio`` as well. the Linux kernel tree. This avoids the compilation of ``cpio`` as well.
musl 1.2.3
==========
Prior to booting Linux, musl is rebuilt yet again with syscalls
``clone`` and ``set_thread_area`` enabled for Linux thread support.
go_sysb go_sysb
======= =======

View file

@ -35,11 +35,12 @@ def create_configuration_file(args):
config.write(f"CHROOT_ONLY_SYSA={args.bwrap}\n") config.write(f"CHROOT_ONLY_SYSA={args.bwrap}\n")
config.write(f"UPDATE_CHECKSUMS={args.update_checksums}\n") config.write(f"UPDATE_CHECKSUMS={args.update_checksums}\n")
config.write(f"JOBS={args.cores}\n") config.write(f"JOBS={args.cores}\n")
config.write("DISK=sda1\n")
config.write(f"INTERNAL_CI={args.internal_ci}\n") config.write(f"INTERNAL_CI={args.internal_ci}\n")
if (args.bare_metal or args.qemu) and not args.kernel: if (args.bare_metal or args.qemu) and not args.kernel:
config.write("DISK=sda\n")
config.write("KERNEL_BOOTSTRAP=True\n") config.write("KERNEL_BOOTSTRAP=True\n")
else: else:
config.write("DISK=sda1\n")
config.write("KERNEL_BOOTSTRAP=False\n") config.write("KERNEL_BOOTSTRAP=False\n")
config.write(f"BUILD_KERNELS={args.update_checksums or args.build_kernels}\n") config.write(f"BUILD_KERNELS={args.update_checksums or args.build_kernels}\n")

21
sysa.py
View file

@ -13,7 +13,6 @@ import shutil
import tarfile import tarfile
from lib.sysgeneral import SysGeneral, stage0_arch_map from lib.sysgeneral import SysGeneral, stage0_arch_map
from lib.utils import run
# pylint: disable=consider-using-with # pylint: disable=consider-using-with
# pylint: disable=too-many-instance-attributes # pylint: disable=too-many-instance-attributes
@ -113,6 +112,8 @@ class SysA(SysGeneral):
for root, _, filepaths in os.walk(dirpath): for root, _, filepaths in os.walk(dirpath):
if 'stage0-posix' in root: if 'stage0-posix' in root:
continue continue
if root == os.path.join('sysc', 'distfiles'):
continue
with open(file_list_path, 'a', encoding="utf-8") as file_list: with open(file_list_path, 'a', encoding="utf-8") as file_list:
for filepath in filepaths: for filepath in filepaths:
file_list.write(f"/{os.path.join(root, filepath)}\n") file_list.write(f"/{os.path.join(root, filepath)}\n")
@ -193,12 +194,20 @@ class SysA(SysGeneral):
def create_builder_hex0_disk_image(self, image_file_name): def create_builder_hex0_disk_image(self, image_file_name):
"""Create builder-hex0 disk image""" """Create builder-hex0 disk image"""
run(os.path.join('sysa', 'stage0-posix', 'src', shutil.copyfile(os.path.join('sysa', 'stage0-posix', 'src', 'bootstrap-seeds',
'bootstrap-seeds', 'POSIX', 'x86', 'hex0-seed'), 'NATIVE', 'x86', 'builder-hex0-x86-stage1.img'),
os.path.join('kernel-bootstrap', 'builder-hex0-x86.hex0'), image_file_name)
image_file_name)
with open(image_file_name, 'ab') as image_file: with open(image_file_name, 'ab') as image_file:
# Append stage2 hex0 source
with open(os.path.join('kernel-bootstrap', 'builder-hex0-x86-stage2.hex0'),
encoding="utf-8") as infile:
image_file.write(infile.read().encode())
# Pad to next sector
current_size = os.stat(image_file_name).st_size
while current_size % 512 != 0:
image_file.write(b'\0')
current_size += 1
self.append_srcfs(image_file) self.append_srcfs(image_file)
current_size = os.stat(image_file_name).st_size current_size = os.stat(image_file_name).st_size
@ -213,6 +222,6 @@ class SysA(SysGeneral):
# fill file with zeros up to desired size, one megabyte at a time # fill file with zeros up to desired size, one megabyte at a time
with open(image_file_name, 'ab') as image_file: with open(image_file_name, 'ab') as image_file:
while current_size < 1008 * megabyte: while current_size < 16384 * megabyte:
image_file.write(b'\0' * megabyte) image_file.write(b'\0' * megabyte)
current_size += megabyte current_size += megabyte

View file

@ -40,7 +40,7 @@ d7d0a5fc9117f9b3ebd287851a48716c96a3c11991365edb8890f0e203d3b810 curl-7.88.1_1.
ed1581d1ef5d42c809a7db1c27614e0a900076e7ce08349ea4797944d41c7bc7 dhcpcd-10.0.1_0.tar.bz2 ed1581d1ef5d42c809a7db1c27614e0a900076e7ce08349ea4797944d41c7bc7 dhcpcd-10.0.1_0.tar.bz2
c4008ae6b168aee4120b0f3624a1875f9e413d8f0c637708b8b04a1fb5be173c diffutils-2.7_0.tar.bz2 c4008ae6b168aee4120b0f3624a1875f9e413d8f0c637708b8b04a1fb5be173c diffutils-2.7_0.tar.bz2
bda6afcd3a390a34a57443269a4857ccc470129f7a557981778c145fd841cbd1 dist-3.5-236_0.tar.bz2 bda6afcd3a390a34a57443269a4857ccc470129f7a557981778c145fd841cbd1 dist-3.5-236_0.tar.bz2
c0514138e251062c9ac2ff1e432e01a541777bfd61480c77479ea55f5b75cdd1 e2fsprogs-1.45.7_0.tar.bz2 5a5923e9dcbec079b032a349471627460f553a430c82bc9b4b6c0bd34ae97547 e2fsprogs-1.45.7_0.tar.bz2
d7b7453ad400eac1ba39f99971afdc392cb8a92c557ef5d6fd9fa2625124de4a ed-1.4_0.tar.bz2 d7b7453ad400eac1ba39f99971afdc392cb8a92c557ef5d6fd9fa2625124de4a ed-1.4_0.tar.bz2
258282c136145d8fba4d66f7e150800e7ca33e024483083a15d0dba3aeb5e86b file-5.44_0.tar.bz2 258282c136145d8fba4d66f7e150800e7ca33e024483083a15d0dba3aeb5e86b file-5.44_0.tar.bz2
5984d3f2d5513dd04dc97619e2809d634fc7e3692f36f770e0202a61b6b2921d findutils-4.2.33_0.tar.bz2 5984d3f2d5513dd04dc97619e2809d634fc7e3692f36f770e0202a61b6b2921d findutils-4.2.33_0.tar.bz2
@ -62,6 +62,7 @@ d85cff8f9ff76533287891ec2019416fa585815e514743e5b76efd9f17f5ef5c grep-3.7_0.tar
b38422d646590600444f0ff12fee6fd738baaf471338aa67899db950d3521127 guile-3.0.9_0.tar.bz2 b38422d646590600444f0ff12fee6fd738baaf471338aa67899db950d3521127 guile-3.0.9_0.tar.bz2
8d2015b87337abbf287f7a39ee4cf53514120b5d3e90a93fe7d533dcc43f14fa help2man-1.36.4_0.tar.bz2 8d2015b87337abbf287f7a39ee4cf53514120b5d3e90a93fe7d533dcc43f14fa help2man-1.36.4_0.tar.bz2
3f06d1a7f1b1770d4550ff6316c7f06fd26e30bddad7c1b665f1fae80e409c8c kbd-1.15_0.tar.bz2 3f06d1a7f1b1770d4550ff6316c7f06fd26e30bddad7c1b665f1fae80e409c8c kbd-1.15_0.tar.bz2
d23886557310f7ff2c98898eac24b4fe8704b22e88d094e96ff996cf0d2635a4 kexec-linux-1.0.0_0.tar.bz2
2a661da13801028f5af98e5d9f6de417c21c90df1bcef4809caf0c2094fdd8f4 kexec-tools-2.0.22_0.tar.bz2 2a661da13801028f5af98e5d9f6de417c21c90df1bcef4809caf0c2094fdd8f4 kexec-tools-2.0.22_0.tar.bz2
e89e4fc8ba4f917f4f609ba781fc13e43d31479d47a9da2ba3bc7ce5fcbbe6b3 libarchive-3.5.2_0.tar.bz2 e89e4fc8ba4f917f4f609ba781fc13e43d31479d47a9da2ba3bc7ce5fcbbe6b3 libarchive-3.5.2_0.tar.bz2
36550df491767bb24d2ccab304ce70a3b4956e7c0c0e0c343d922fd57cdafbdd libatomic_ops-7.6.10_0.tar.bz2 36550df491767bb24d2ccab304ce70a3b4956e7c0c0e0c343d922fd57cdafbdd libatomic_ops-7.6.10_0.tar.bz2

View file

@ -30,6 +30,7 @@ src_prepare() {
src_configure() { src_configure() {
./configure --prefix="${PREFIX}" \ ./configure --prefix="${PREFIX}" \
--sbindir="${PREFIX}/bin" \ --sbindir="${PREFIX}/bin" \
--disable-tls \
with_udev_rules_dir=no \ with_udev_rules_dir=no \
with_systemd_unit_dir=no with_systemd_unit_dir=no
} }

View file

@ -1 +0,0 @@
dd9e799311b3c505fa8efe045b969b851c60499ab41db546e5c8b545b3e19ec8 /boot/fiwix

View file

@ -1 +0,0 @@
https://github.com/rick-masters/Fiwix/releases/download/v1.4.0-lb1/fiwix-1.4.0-lb1.tar.gz ff57d1fbf0547a27dec4d7146eb9c17d01158ca5886de54e5b9bac2bec473ef3

View file

@ -0,0 +1 @@
0de298be5c0b00654ddb226c2e657d4fdd2fa0c613ffb3bb32c23c65d2257bf0 /boot/fiwix

View file

@ -18,9 +18,9 @@ cd build
untar --file ../src/${pkg}.tar untar --file ../src/${pkg}.tar
cd ${pkg} cd ${pkg}
alias as="tcc -m32 -march=i386 -std=c89 -D__KERNEL__ -DMAX_PID_VALUE=64000000 -DCONFIG_MMAP2 -DCONFIG_64BIT_SYSCALLS -DNR_PROCS=4096 -DCHILD_MAX=4096 -DOPEN_MAX=1536 -DNR_OPENS=1536 -DINIT_PROGRAM=\"/init\" -DUTS_SYSNAME=\"Linux\" -D__VERSION__=\"tcc\" -traditional -I/sysa/fiwix-1.4.0-lb1/build/fiwix-1.4.0-lb1/include" alias as="tcc -m32 -march=i386 -std=c89 -D__KERNEL__ -DMAX_PID_VALUE=64000000 -DCONFIG_MMAP2 -DCONFIG_64BIT_SYSCALLS -DCONFIG_KEXEC -DNR_PROCS=4096 -DCHILD_MAX=4096 -DOPEN_MAX=1536 -DNR_OPENS=1536 -DINIT_PROGRAM=\"/init\" -DUTS_SYSNAME=\"Linux\" -D__VERSION__=\"tcc\" -traditional -I/sysa/fiwix-1.4.0-lb2/build/fiwix-1.4.0-lb2/include"
alias cc="tcc -m32 -march=i386 -std=c89 -D__KERNEL__ -DMAX_PID_VALUE=64000000 -DCONFIG_MMAP2 -DCONFIG_64BIT_SYSCALLS -DNR_PROCS=4096 -DCHILD_MAX=4096 -DOPEN_MAX=1536 -DNR_OPENS=1536 -DINIT_PROGRAM=\"/init\" -DUTS_SYSNAME=\"Linux\" -D__VERSION__=\"tcc\" -I/sysa/fiwix-1.4.0-lb1/build/fiwix-1.4.0-lb1/include -O2 -fno-pie -fno-common -ffreestanding -Wall -Wstrict-prototypes" alias cc="tcc -m32 -march=i386 -std=c89 -D__KERNEL__ -DMAX_PID_VALUE=64000000 -DCONFIG_MMAP2 -DCONFIG_64BIT_SYSCALLS -DCONFIG_KEXEC -DNR_PROCS=4096 -DCHILD_MAX=4096 -DOPEN_MAX=1536 -DNR_OPENS=1536 -DINIT_PROGRAM=\"/init\" -DUTS_SYSNAME=\"Linux\" -D__VERSION__=\"tcc\" -I/sysa/fiwix-1.4.0-lb2/build/fiwix-1.4.0-lb2/include -O2 -fno-pie -fno-common -ffreestanding -Wall -Wstrict-prototypes"
cd kernel cd kernel
as -c -o boot.o boot.S as -c -o boot.o boot.S
@ -42,6 +42,7 @@ cc -c -o sleep.o sleep.c
cc -c -o signal.o signal.c cc -c -o signal.o signal.c
cc -c -o process.o process.c cc -c -o process.o process.c
cc -c -o multiboot.o multiboot.c cc -c -o multiboot.o multiboot.c
cc -c -o kexec.o kexec.c
cd syscalls cd syscalls
cc -c -o umount.o umount.c cc -c -o umount.o umount.c
@ -278,6 +279,7 @@ cc -c -o floppy.o floppy.c
cc -c -o part.o part.c cc -c -o part.o part.c
cc -c -o ata.o ata.c cc -c -o ata.o ata.c
cc -c -o ata_hd.o ata_hd.c cc -c -o ata_hd.o ata_hd.c
cc -c -o ata_pci.o ata_pci.c
cc -c -o atapi.o atapi.c cc -c -o atapi.o atapi.c
cc -c -o atapi_cd.o atapi_cd.c cc -c -o atapi_cd.o atapi_cd.c
cc -c -o ramdisk.o ramdisk.c cc -c -o ramdisk.o ramdisk.c
@ -321,6 +323,7 @@ tcc -m32 -Wl,-Ttext=0xC0100000 -static -nostdlib -nostdinc \
kernel/signal.o \ kernel/signal.o \
kernel/process.o \ kernel/process.o \
kernel/multiboot.o \ kernel/multiboot.o \
kernel/kexec.o \
kernel/syscalls/umount.o \ kernel/syscalls/umount.o \
kernel/syscalls/getgid.o \ kernel/syscalls/getgid.o \
kernel/syscalls/getppid.o \ kernel/syscalls/getppid.o \
@ -529,6 +532,7 @@ tcc -m32 -Wl,-Ttext=0xC0100000 -static -nostdlib -nostdinc \
drivers/block/part.o \ drivers/block/part.o \
drivers/block/ata.o \ drivers/block/ata.o \
drivers/block/ata_hd.o \ drivers/block/ata_hd.o \
drivers/block/ata_pci.o \
drivers/block/atapi.o \ drivers/block/atapi.o \
drivers/block/atapi_cd.o \ drivers/block/atapi_cd.o \
drivers/block/ramdisk.o \ drivers/block/ramdisk.o \

View file

@ -0,0 +1 @@
https://github.com/rick-masters/Fiwix/releases/download/v1.4.0-lb2/fiwix-1.4.0-lb2.tar.gz 44fb14fb666dcf4f5abf7f49eb3f1d92436b9d7353daa23138ff21e9ec78e30f

View file

@ -1 +1 @@
afb30f2e80adefc979bdffdb525cf2862897f0beefbb0740fbd05ab3246a32c9 /usr/bin/kexec-fiwix 4f78914aef30b569a531102998e52a0514d8836204d57ff42bf0a3324968f247 /usr/bin/kexec-fiwix

View file

@ -77,10 +77,10 @@ int main() {
puts("Preparing multiboot info for kernel..."); puts("Preparing multiboot info for kernel...");
char cmdline[256]; char cmdline[256];
sprintf(cmdline, "fiwix console=/dev/ttyS0 root=/dev/ram0 ramdisksize=%d initrd=sysa.ext2", INITRD_MB * 1024); sprintf(cmdline, "fiwix console=/dev/ttyS0 root=/dev/ram0 ramdisksize=%d initrd=sysa.ext2 kexec_proto=linux kexec_size=67000 kexec_cmdline=\"init=/init console=ttyS0\"", INITRD_MB * 1024);
char * boot_loader_name = "kexec-fiwix"; char * boot_loader_name = "kexec-fiwix";
unsigned int next_avail_mem = 0x8000; unsigned int next_avail_mem = 0x9800;
multiboot_info_t * pmultiboot_info = (multiboot_info_t *) next_avail_mem; multiboot_info_t * pmultiboot_info = (multiboot_info_t *) next_avail_mem;
memset(pmultiboot_info, 0, sizeof(multiboot_info_t)); memset(pmultiboot_info, 0, sizeof(multiboot_info_t));

View file

@ -0,0 +1,82 @@
/* SPDX-FileCopyrightText: 2023 Richard Masters <grick23@gmail.com> */
/* SPDX-License-Identifier: MIT */
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/reboot.h>
#include <sys/stat.h>
#include <time.h>
int append_file(FILE *dst_file, char *src_file_name);
int main(int argc, char **argv) {
char *ramdrive_file_name, *kernel_file_name, *initramfs_file_name;
FILE *ramdrive_file;
struct stat stats;
uint32_t size;
if (argc < 3) {
puts("Usage: fiwix-kexec-linux <ram-drive-name> <kernel-file-name> <initramfs-file-name>");
exit(1);
}
ramdrive_file_name = argv[1];
kernel_file_name = argv[2];
initramfs_file_name = argv[3];
ramdrive_file = fopen(ramdrive_file_name, "wb");
/* Write length of kernel */
if (stat(kernel_file_name, &stats) == 0) {
size = (uint32_t) stats.st_size;
fwrite(&size, sizeof(size), 1, ramdrive_file);
} else {
fprintf(stderr, "Cannot stat kernel file '%s'\n", kernel_file_name);
exit(1);
}
/* Write length of initramfs */
if (stat(initramfs_file_name, &stats) == 0) {
size = (uint32_t) stats.st_size;
fwrite(&size, sizeof(size), 1, ramdrive_file);
} else {
fprintf(stderr, "Cannot stat initramfs file '%s'\n", initramfs_file_name);
exit(1);
}
if (append_file(ramdrive_file, kernel_file_name)) {
fprintf(stderr, "Cannot append kernel '%s'\n", kernel_file_name);
exit(1);
}
if (append_file(ramdrive_file, initramfs_file_name)) {
fprintf(stderr, "Cannot append initramfs '%s'\n", initramfs_file_name);
exit(1);
}
fclose(ramdrive_file);
/* Flush ram drive writes to device */
sync();
/* Perform syscall reboot to initiate kexec */
reboot(RB_HALT_SYSTEM);
}
int append_file(FILE *dst_file, char *src_file_name) {
FILE *src_file;
char buff[BUFSIZ];
size_t n;
if (src_file = fopen(src_file_name, "rb")) {
while ((n = fread(buff, 1, BUFSIZ, src_file)) != 0) {
fwrite(buff, 1, n, dst_file );
}
fclose(src_file);
return 0;
} else {
printf("Cannot open file '%s'\n", src_file_name);
return 1;
}
}

View file

@ -0,0 +1,15 @@
#!/bin/bash
# SPDX-FileCopyrightText: 2023 Richard Masters <grick23@gmail.com>
# SPDX-License-Identifier: MIT
src_get() {
:
}
src_unpack() {
dirname=kexec-linux-1.0.0
mkdir ${dirname}
}
src_install() {
install -D "kexec-linux" "${DESTDIR}${PREFIX}/bin/kexec-linux"
}

View file

@ -0,0 +1,4 @@
# SPDX-FileCopyrightText: 2023 Richard Masters <grick23@gmail.com>
# SPDX-License-Identifier: MIT
kexec-linux: kexec-linux.c
gcc -static -m32 -march=i386 -o $@ $^

View file

@ -21,6 +21,7 @@
/usr/bin/checksum-transcriber /usr/bin/checksum-transcriber
/usr/bin/tcc /usr/bin/tcc
/usr/bin/tcc-0.9.26 /usr/bin/tcc-0.9.26
/usr/bin/kexec-linux
/usr/lib/mes/libc.a /usr/lib/mes/libc.a
/usr/lib/mes/libgetopt.a /usr/lib/mes/libgetopt.a
/usr/lib/mes/crt1.o /usr/lib/mes/crt1.o

View file

@ -71,7 +71,7 @@ static bool open_filedev(void)
file_dev_name_set(input_name); file_dev_name_set(input_name);
bd = file_dev_get(); bd = file_dev_get();
if (!bd) { if (!bd) {
printf("open_filedev: fail\n"); puts("open_filedev: fail");
return false; return false;
} }
return true; return true;
@ -85,7 +85,7 @@ bool lwext4_mount(struct ext4_blockdev *bdev, struct ext4_bcache *bcache)
bd = bdev; bd = bdev;
if (!bd) { if (!bd) {
printf("lwext4_mount: no block device\n"); puts("lwext4_mount: no block device");
return false; return false;
} }
@ -155,21 +155,21 @@ bool copy_file(char *src_path, char *dest_path)
err = ext4_fopen(&dest_file, dest_path, "wb"); err = ext4_fopen(&dest_file, dest_path, "wb");
if (err != EOK) { if (err != EOK) {
printf("ext4_open error: %d \n", err); printf("ext4_open error: %d\n", err);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (src_len > 0) { if (src_len > 0) {
err = ext4_fwrite(&dest_file, src_mem, src_len, 0); err = ext4_fwrite(&dest_file, src_mem, src_len, 0);
if (err != EOK) { if (err != EOK) {
printf("ext4_fwrite error: %d \n", err); printf("ext4_fwrite error: %d\n", err);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
} }
err = ext4_fclose(&dest_file); err = ext4_fclose(&dest_file);
if (err != EOK) { if (err != EOK) {
printf("ext4_fclose error: %d \n", err); printf("ext4_fclose error: %d\n", err);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -226,7 +226,7 @@ int main(int argc, char **argv)
err = ext4_mkfs(&fs, bd, &info, F_SET_EXT2_V0); err = ext4_mkfs(&fs, bd, &info, F_SET_EXT2_V0);
if (err != EOK) { if (err != EOK) {
printf("ext4_mkfs error: %d \n", err); printf("ext4_mkfs error: %d\n", err);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -255,32 +255,44 @@ int main(int argc, char **argv)
if (!lwext4_mount(bd, bc)) if (!lwext4_mount(bd, bc))
return EXIT_FAILURE; return EXIT_FAILURE;
printf("ext4_dir_mk /mp/dev\n"); puts("ext4_dir_mk /mp/dev");
err = ext4_dir_mk("/mp/dev"); err = ext4_dir_mk("/mp/dev");
if (err != EOK) { if (err != EOK) {
printf("ext4_dir_mk error: %d \n", err); printf("ext4_dir_mk error: %d\n", err);
} }
printf("ext4_mknod /mp/dev/console\n"); puts("ext4_mknod /mp/dev/console");
err = ext4_mknod("/mp/dev/console", EXT4_DE_CHRDEV, MKDEV(5, 1)); err = ext4_mknod("/mp/dev/console", EXT4_DE_CHRDEV, MKDEV(5, 1));
if (err != EOK) { if (err != EOK) {
printf("ext4_mknod error: %d \n", err); printf("ext4_mknod error: %d\n", err);
return EXIT_FAILURE;
}
puts("ext4_mknod /mp/dev/ram0");
err = ext4_mknod("/mp/dev/ram0", EXT4_DE_BLKDEV, MKDEV(1, 0));
if (err != EOK) {
printf("ext4_mknod error: %d\n", err);
return EXIT_FAILURE;
}
puts("ext4_mknod /mp/dev/ram1");
err = ext4_mknod("/mp/dev/ram1", EXT4_DE_BLKDEV, MKDEV(1, 1));
if (err != EOK) {
printf("ext4_mknod error: %d\n", err);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
copy_file("/usr/bin/kaem", "/mp/init"); copy_file("/usr/bin/kaem", "/mp/init");
copy_file("/sysa/after2.kaem", "/mp/kaem.run"); copy_file("/sysa/after2.kaem", "/mp/kaem.run");
copy_file_list("/sysa/lwext4-1.0.0-lb1/files/fiwix-file-list.txt"); copy_file_list("/sysa/lwext4-1.0.0-lb1/files/fiwix-file-list.txt");
printf("ext4_dir_mk /mp/tmp\n"); puts("ext4_dir_mk /mp/tmp");
ext4_dir_mk("/mp/tmp"); ext4_dir_mk("/mp/tmp");
printf("ext4_dir_mk /mp/usr\n"); puts("ext4_dir_mk /mp/usr");
ext4_dir_mk("/mp/usr"); ext4_dir_mk("/mp/usr");
printf("ext4_dir_mk /mp/usr/src\n"); puts("ext4_dir_mk /mp/usr/src");
ext4_dir_mk("/mp/usr/src"); ext4_dir_mk("/mp/usr/src");
if (!lwext4_umount()) if (!lwext4_umount())
return EXIT_FAILURE; return EXIT_FAILURE;
printf("Fiwix ext2 initrd created successfully.\n"); puts("Fiwix ext2 initrd created successfully.");
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -1 +1 @@
0a3f0012c01cb5aee0643f1674f265e68b5eeadb37596bcc4fe60aad55c9d3d7 /usr/bin/make_fiwix_initrd 7b65748dd946f1a5266b2e6d0c9cf7143b4722dae0dd4a02b89d6fba9909e2bd /usr/bin/make_fiwix_initrd

View file

@ -57,7 +57,7 @@ fi
if match x${BUILD_FIWIX} xTrue; then if match x${BUILD_FIWIX} xTrue; then
# The Fiwix kernel # The Fiwix kernel
pkg="fiwix-1.4.0-lb1" pkg="fiwix-1.4.0-lb2"
cd ${pkg} cd ${pkg}
kaem --verbose --file ${pkg}.kaem kaem --verbose --file ${pkg}.kaem
cd .. cd ..

View file

@ -25,16 +25,20 @@ create_sysb() {
} }
go_sysb() { go_sysb() {
# Mount proc for kexec if [ "${KERNEL_BOOTSTRAP}" = True ]; then
mkdir /proc /etc kexec-linux "/dev/ram1" "/boot/linux-4.9.10" "/boot/initramfs-sysb.cpio.gz"
mount -t proc proc /proc else
# kexec time # Mount proc for kexec
echo "Loading kernel + sysb initramfs using kexec" mkdir /proc /etc
kexec -l "/boot/linux-4.9.10" --console-serial \ mount -t proc proc /proc
--initrd="/boot/initramfs-sysb.cpio.gz" \ # kexec time
--append="init=/init console=ttyS0" echo "Loading kernel + sysb initramfs using kexec"
echo "kexecing into sysb" kexec -l "/boot/linux-4.9.10" --console-serial \
kexec -e --initrd="/boot/initramfs-sysb.cpio.gz" \
--append="init=/init console=ttyS0"
echo "kexecing into sysb"
kexec -e
fi
} }
build automake-1.15.1 build automake-1.15.1
@ -87,6 +91,8 @@ grep --no-filename '^build' "${SOURCES}"/run*.sh | grep -v musl-1.2.3 | sed "s/b
done done
if [ "${CHROOT}" = False ] || [ "${BUILD_KERNELS}" = True ]; then if [ "${CHROOT}" = False ] || [ "${BUILD_KERNELS}" = True ]; then
build kexec-linux-1.0.0
build kexec-tools-2.0.22 build kexec-tools-2.0.22
build linux-4.9.10 build linux-4.9.10
@ -96,12 +102,7 @@ build musl-1.2.3 '' no-patches
if [ "${CHROOT}" = False ]; then if [ "${CHROOT}" = False ]; then
create_sysb create_sysb
if [ "${KERNEL_BOOTSTRAP}" = True ]; then go_sysb
echo "Kernel bootstrapping successful."
echo "NOTE: Transition to Linux and building remaining packages is under development."
else
go_sysb
fi
else else
# In chroot mode transition directly into System C. # In chroot mode transition directly into System C.
SYSC=/sysc_image SYSC=/sysc_image

@ -1 +1 @@
Subproject commit fe529ef2e1053cb0551fb71276f9ced9fe229d87 Subproject commit 5805beef1754945e280a07f193346710ba2b4d32

View file

@ -65,15 +65,15 @@ if [ -z "${DISK}" ] || ! [ -e "/dev/${DISK}" ]; then
echo "DISK=${DISK}" >> /usr/src/bootstrap.cfg echo "DISK=${DISK}" >> /usr/src/bootstrap.cfg
fi fi
# Is it a full disk, and not a partition # Is it a full disk, and not a partition?
# shellcheck disable=SC2012 # shellcheck disable=SC2012
if [ $(($(ls -l "/dev/${DISK}" | sed "s/.*, *//" | sed "s/ .*//") % 8)) -eq 0 ]; then if [ $(($(ls -l "/dev/${DISK}" | sed "s/.*, *//" | sed "s/ .*//") % 8)) -eq 0 ]; then
if ! fdisk -l "/dev/${DISK}" | grep -qE "${DISK}p?[0-9]" ; then echo "Creating partition table..."
echo "Creating partition table and partition" echo ";" | sfdisk "/dev/${DISK}"
echo ";" | sfdisk "/dev/${DISK}" fdisk -l "/dev/${DISK}"
mkfs.ext4 "/dev/${DISK}1" echo "Creating ext4 partition..."
DISK="${DISK}1" mkfs.ext4 "/dev/${DISK}1"
fi DISK="${DISK}1"
fi fi
echo "export DISK=${DISK}" >> /usr/src/bootstrap.cfg echo "export DISK=${DISK}" >> /usr/src/bootstrap.cfg