Build bootable image

This commit is contained in:
2026-08-25 19:49:03 +03:00
parent 7499dd1b2b
commit d8c5492e6c
3 changed files with 31 additions and 2 deletions
+27 -2
View File
@@ -106,8 +106,8 @@ bool clean_dir(const char *dir_path) {
const char *full_path = nob_temp_sprintf("%s/%s", dir_path, name); const char *full_path = nob_temp_sprintf("%s/%s", dir_path, name);
if (!nob_delete_file(full_path)) { if (!nob_delete_file(full_path)) {
nob_log(NOB_ERROR, "could not delete %s", full_path); clean_dir(full_path);
ok = false; nob_delete_file(full_path);
} }
} }
@@ -115,6 +115,29 @@ bool clean_dir(const char *dir_path) {
return ok; return ok;
} }
bool build_bootable_image(Nob_Cmd *cmd) {
if (!nob_mkdir_if_not_exists(BUILD_FOLDER "isodir"))
return false;
if (!nob_mkdir_if_not_exists(BUILD_FOLDER "isodir/boot"))
return false;
if (!nob_mkdir_if_not_exists(BUILD_FOLDER "isodir/boot/grub"))
return false;
nob_cmd_append(cmd, "cp", BUILD_FOLDER "kernel", BUILD_FOLDER "isodir/boot/kernel");
if (!nob_cmd_run(cmd))
return false;
nob_cmd_append(cmd, "cp", SRC_FOLDER "grub.cfg", BUILD_FOLDER "isodir/boot/grub/grub.cfg");
if (!nob_cmd_run(cmd))
return false;
nob_cmd_append(cmd, "grub-mkrescue", "-o", BUILD_FOLDER "kernel.iso", BUILD_FOLDER "isodir");
if (!nob_cmd_run(cmd))
return false;
return true;
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
NOB_GO_REBUILD_URSELF(argc, argv); NOB_GO_REBUILD_URSELF(argc, argv);
@@ -144,6 +167,8 @@ int main(int argc, char **argv) {
return 1; return 1;
if (!check_kernel(&cmd)) if (!check_kernel(&cmd))
return 1; return 1;
if (!build_bootable_image(&cmd))
return 1;
return 0; return 0;
} }
+1
View File
@@ -7,6 +7,7 @@ pkgs.mkShell {
pkgsCross.i686-embedded.buildPackages.binutils pkgsCross.i686-embedded.buildPackages.binutils
gdb gdb
grub2 grub2
xorriso
]; ];
shellHook = '' shellHook = ''
+3
View File
@@ -0,0 +1,3 @@
menuentry "kernel" {
multiboot /boot/kernel
}