mirror of
https://github.com/fosslinux/live-bootstrap.git
synced 2026-03-10 21:35:24 +01:00
Complete the kernel bootstrap by adding kexec of Linux from Fiwix.
A tiny bootloader bootstrap has been added to compile the builder-hex0 kernel from hex0 source. The boot compiler is builder-hex0-x86-stage1.hex0 and builder-hex0-x86-stage1.bin. The builder-hex0 kernel is now named builder-hex0-x86-stage2.hex0. The inclusion of a binary seed resolves the problem with the previous strategy which used an architecture-specific hex0 compiler. If sysb detects a full disk (i.e. DISK=sda) it now partitions the disk unconditionally because previously fdisk was reporting existing but empty partitions which resulted in no parititions being created. e2fsprogs is now built with --disable-tls because musl was built on Fiwix without full threading support and mkfs.ext4 was crashing without disabling thread local storage. kexec-linux writes the linux kernel and initramfs to a RAM drive on Fiwix which ensure a pre-allocated contiguous memory block. The following is written to the ram drive: a 32-bit number which is the size of the kernel in bytes, a 32-bit number which is the size of the initramfs in bytes, followed by the Linux kernel image, followed by the initramfs. kexec-fiwix invokes a sync syscall to ensure all writes are flushed to the ram drive and then initiates the kexec by shutting down Fiwix with a reboot syscall. Fiwix knows whether and how to perform the kexec based on kernel parameters passed to it.
This commit is contained in:
parent
e86db47b6e
commit
a2fcf1ced9
23 changed files with 633 additions and 277 deletions
|
|
@ -40,7 +40,7 @@ d7d0a5fc9117f9b3ebd287851a48716c96a3c11991365edb8890f0e203d3b810 curl-7.88.1_1.
|
|||
ed1581d1ef5d42c809a7db1c27614e0a900076e7ce08349ea4797944d41c7bc7 dhcpcd-10.0.1_0.tar.bz2
|
||||
c4008ae6b168aee4120b0f3624a1875f9e413d8f0c637708b8b04a1fb5be173c diffutils-2.7_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
|
||||
258282c136145d8fba4d66f7e150800e7ca33e024483083a15d0dba3aeb5e86b file-5.44_0.tar.bz2
|
||||
5984d3f2d5513dd04dc97619e2809d634fc7e3692f36f770e0202a61b6b2921d findutils-4.2.33_0.tar.bz2
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ src_prepare() {
|
|||
src_configure() {
|
||||
./configure --prefix="${PREFIX}" \
|
||||
--sbindir="${PREFIX}/bin" \
|
||||
--disable-tls \
|
||||
with_udev_rules_dir=no \
|
||||
with_systemd_unit_dir=no
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +0,0 @@
|
|||
dd9e799311b3c505fa8efe045b969b851c60499ab41db546e5c8b545b3e19ec8 /boot/fiwix
|
||||
|
|
@ -1 +0,0 @@
|
|||
https://github.com/rick-masters/Fiwix/releases/download/v1.4.0-lb1/fiwix-1.4.0-lb1.tar.gz ff57d1fbf0547a27dec4d7146eb9c17d01158ca5886de54e5b9bac2bec473ef3
|
||||
1
sysa/fiwix-1.4.0-lb2/fiwix-1.4.0-lb2.checksums
Normal file
1
sysa/fiwix-1.4.0-lb2/fiwix-1.4.0-lb2.checksums
Normal file
|
|
@ -0,0 +1 @@
|
|||
0de298be5c0b00654ddb226c2e657d4fdd2fa0c613ffb3bb32c23c65d2257bf0 /boot/fiwix
|
||||
|
|
@ -18,9 +18,9 @@ cd build
|
|||
untar --file ../src/${pkg}.tar
|
||||
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
|
||||
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 process.o process.c
|
||||
cc -c -o multiboot.o multiboot.c
|
||||
cc -c -o kexec.o kexec.c
|
||||
|
||||
cd syscalls
|
||||
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 ata.o ata.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_cd.o atapi_cd.c
|
||||
cc -c -o ramdisk.o ramdisk.c
|
||||
|
|
@ -321,6 +323,7 @@ tcc -m32 -Wl,-Ttext=0xC0100000 -static -nostdlib -nostdinc \
|
|||
kernel/signal.o \
|
||||
kernel/process.o \
|
||||
kernel/multiboot.o \
|
||||
kernel/kexec.o \
|
||||
kernel/syscalls/umount.o \
|
||||
kernel/syscalls/getgid.o \
|
||||
kernel/syscalls/getppid.o \
|
||||
|
|
@ -529,6 +532,7 @@ tcc -m32 -Wl,-Ttext=0xC0100000 -static -nostdlib -nostdinc \
|
|||
drivers/block/part.o \
|
||||
drivers/block/ata.o \
|
||||
drivers/block/ata_hd.o \
|
||||
drivers/block/ata_pci.o \
|
||||
drivers/block/atapi.o \
|
||||
drivers/block/atapi_cd.o \
|
||||
drivers/block/ramdisk.o \
|
||||
1
sysa/fiwix-1.4.0-lb2/sources
Normal file
1
sysa/fiwix-1.4.0-lb2/sources
Normal file
|
|
@ -0,0 +1 @@
|
|||
https://github.com/rick-masters/Fiwix/releases/download/v1.4.0-lb2/fiwix-1.4.0-lb2.tar.gz 44fb14fb666dcf4f5abf7f49eb3f1d92436b9d7353daa23138ff21e9ec78e30f
|
||||
|
|
@ -1 +1 @@
|
|||
afb30f2e80adefc979bdffdb525cf2862897f0beefbb0740fbd05ab3246a32c9 /usr/bin/kexec-fiwix
|
||||
4f78914aef30b569a531102998e52a0514d8836204d57ff42bf0a3324968f247 /usr/bin/kexec-fiwix
|
||||
|
|
|
|||
|
|
@ -77,10 +77,10 @@ int main() {
|
|||
puts("Preparing multiboot info for kernel...");
|
||||
|
||||
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";
|
||||
|
||||
unsigned int next_avail_mem = 0x8000;
|
||||
unsigned int next_avail_mem = 0x9800;
|
||||
multiboot_info_t * pmultiboot_info = (multiboot_info_t *) next_avail_mem;
|
||||
memset(pmultiboot_info, 0, sizeof(multiboot_info_t));
|
||||
|
||||
|
|
|
|||
1
sysa/kexec-linux/kexec-linux.checksums
Normal file
1
sysa/kexec-linux/kexec-linux.checksums
Normal file
|
|
@ -0,0 +1 @@
|
|||
c0993adf00bd2c110539a310246f0e50d727e09701ed187827c71c64021431f4 /usr/bin/kexec-linux
|
||||
16
sysa/kexec-linux/kexec-linux.kaem
Executable file
16
sysa/kexec-linux/kexec-linux.kaem
Executable file
|
|
@ -0,0 +1,16 @@
|
|||
# SPDX-FileCopyrightText: 2023 Richard Masters <grick23@gmail.com>
|
||||
# SPDX-License-Identifier: MIT
|
||||
cd src
|
||||
tcc -static -m32 -march=i386 -std=c89 -I../../tcc/tcc-0.9.27/include -o ${bindir}/kexec-linux kexec-linux.c
|
||||
cd ..
|
||||
|
||||
# Checksums
|
||||
if match x${UPDATE_CHECKSUMS} xTrue; then
|
||||
sha256sum /usr/bin/kexec-linux
|
||||
sha256sum -o ${pkg}.checksums \
|
||||
/usr/bin/kexec-linux
|
||||
|
||||
cp ${pkg}.checksums ${srcdir}
|
||||
else
|
||||
sha256sum -c ${pkg}.checksums
|
||||
fi
|
||||
91
sysa/kexec-linux/src/kexec-linux.c
Normal file
91
sysa/kexec-linux/src/kexec-linux.c
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
/* SPDX-FileCopyrightText: 2023 Richard Masters <grick23@gmail.com> */
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.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;
|
||||
|
||||
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) {
|
||||
fwrite(&stats.st_size, sizeof(stats.st_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) {
|
||||
fwrite(&stats.st_size, sizeof(stats.st_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);
|
||||
|
||||
/* Perform syscall sync */
|
||||
__asm__ __volatile__(
|
||||
"movl $0x00000024, %%eax\n\t"
|
||||
"int $0x80\n\t"
|
||||
: /* no output */
|
||||
: /* no input */
|
||||
);
|
||||
|
||||
/* Perform syscall reboot to initiate kexec */
|
||||
__asm__ __volatile__(
|
||||
"movl $0x58, %%eax\n\t"
|
||||
"movl $0xfee1dead, %%ebx\n\t"
|
||||
"movl $0x28121969, %%ecx\n\t"
|
||||
"movl $0xcdef0123, %%edx\n\t"
|
||||
"movl $0x00, %%esi\n\t"
|
||||
"int $0x80\n\t"
|
||||
: /* no output */
|
||||
: /* no input */
|
||||
);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -21,6 +21,7 @@
|
|||
/usr/bin/checksum-transcriber
|
||||
/usr/bin/tcc
|
||||
/usr/bin/tcc-0.9.26
|
||||
/usr/bin/kexec-linux
|
||||
/usr/lib/mes/libc.a
|
||||
/usr/lib/mes/libgetopt.a
|
||||
/usr/lib/mes/crt1.o
|
||||
|
|
|
|||
|
|
@ -267,6 +267,18 @@ int main(int argc, char **argv)
|
|||
printf("ext4_mknod error: %d \n", err);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
printf("ext4_mknod /mp/dev/ram0\n");
|
||||
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;
|
||||
}
|
||||
printf("ext4_mknod /mp/dev/ram1\n");
|
||||
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;
|
||||
}
|
||||
|
||||
copy_file("/usr/bin/kaem", "/mp/init");
|
||||
copy_file("/sysa/after2.kaem", "/mp/kaem.run");
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
0a3f0012c01cb5aee0643f1674f265e68b5eeadb37596bcc4fe60aad55c9d3d7 /usr/bin/make_fiwix_initrd
|
||||
4135d55c65ba001b98804425de67907ba92d281a0582dfd8861d728d19da9e7d /usr/bin/make_fiwix_initrd
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ fi
|
|||
|
||||
if match x${BUILD_FIWIX} xTrue; then
|
||||
# The Fiwix kernel
|
||||
pkg="fiwix-1.4.0-lb1"
|
||||
pkg="fiwix-1.4.0-lb2"
|
||||
cd ${pkg}
|
||||
kaem --verbose --file ${pkg}.kaem
|
||||
cd ..
|
||||
|
|
@ -73,6 +73,12 @@ if match x${BUILD_FIWIX} xTrue; then
|
|||
cd ${pkg}
|
||||
kaem --verbose --file ${pkg}.kaem
|
||||
cd ..
|
||||
|
||||
# Live boot loader for Fiwix to Linux
|
||||
pkg="kexec-linux"
|
||||
cd ${pkg}
|
||||
kaem --verbose --file ${pkg}.kaem
|
||||
cd ..
|
||||
fi
|
||||
|
||||
if match x${KERNEL_BOOTSTRAP} xTrue; then
|
||||
|
|
|
|||
31
sysa/run2.sh
31
sysa/run2.sh
|
|
@ -25,16 +25,20 @@ create_sysb() {
|
|||
}
|
||||
|
||||
go_sysb() {
|
||||
# Mount proc for kexec
|
||||
mkdir /proc /etc
|
||||
mount -t proc proc /proc
|
||||
# kexec time
|
||||
echo "Loading kernel + sysb initramfs using kexec"
|
||||
kexec -l "/boot/linux-4.9.10" --console-serial \
|
||||
--initrd="/boot/initramfs-sysb.cpio.gz" \
|
||||
--append="init=/init console=ttyS0"
|
||||
echo "kexecing into sysb"
|
||||
kexec -e
|
||||
if [ "${KERNEL_BOOTSTRAP}" = True ]; then
|
||||
kexec-linux "/dev/ram1" "/boot/linux-4.9.10" "/boot/initramfs-sysb.cpio.gz"
|
||||
else
|
||||
# Mount proc for kexec
|
||||
mkdir /proc /etc
|
||||
mount -t proc proc /proc
|
||||
# kexec time
|
||||
echo "Loading kernel + sysb initramfs using kexec"
|
||||
kexec -l "/boot/linux-4.9.10" --console-serial \
|
||||
--initrd="/boot/initramfs-sysb.cpio.gz" \
|
||||
--append="init=/init console=ttyS0"
|
||||
echo "kexecing into sysb"
|
||||
kexec -e
|
||||
fi
|
||||
}
|
||||
|
||||
build automake-1.15.1
|
||||
|
|
@ -96,12 +100,7 @@ build musl-1.2.3 '' no-patches
|
|||
|
||||
if [ "${CHROOT}" = False ]; then
|
||||
create_sysb
|
||||
if [ "${KERNEL_BOOTSTRAP}" = True ]; then
|
||||
echo "Kernel bootstrapping successful."
|
||||
echo "NOTE: Transition to Linux and building remaining packages is under development."
|
||||
else
|
||||
go_sysb
|
||||
fi
|
||||
go_sysb
|
||||
else
|
||||
# In chroot mode transition directly into System C.
|
||||
SYSC=/sysc_image
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue