mirror of
https://github.com/fosslinux/live-bootstrap.git
synced 2026-03-17 16:55:25 +01:00
Build kexec-linux later as a package for musl lib calls instead of asm.
This commit is contained in:
parent
8604871997
commit
0d4394aa0d
8 changed files with 28 additions and 42 deletions
78
sysa/kexec-linux-1.0.0/files/kexec-linux.c
Normal file
78
sysa/kexec-linux-1.0.0/files/kexec-linux.c
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
/* SPDX-FileCopyrightText: 2023 Richard Masters <grick23@gmail.com> */
|
||||
/* SPDX-License-Identifier: MIT */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.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;
|
||||
|
||||
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, 4, 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, 4, 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;
|
||||
}
|
||||
}
|
||||
15
sysa/kexec-linux-1.0.0/kexec-linux-1.0.0.sh
Executable file
15
sysa/kexec-linux-1.0.0/kexec-linux-1.0.0.sh
Executable 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"
|
||||
}
|
||||
4
sysa/kexec-linux-1.0.0/mk/main.mk
Normal file
4
sysa/kexec-linux-1.0.0/mk/main.mk
Normal 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 $@ $^
|
||||
Loading…
Add table
Add a link
Reference in a new issue