aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2023-10-07 15:49:43 +0200
committerFelix Morgner <felix.morgner@ost.ch>2023-10-07 15:49:43 +0200
commita5a1c6c55aeb9db352d116806ab01477e6dec344 (patch)
tree66949b7ac2da113db764dc9f10d66ee00aa29a39 /source
parent60f8108324dcc3859640799168fb33ea865cf815 (diff)
downloadteachos-a5a1c6c55aeb9db352d116806ab01477e6dec344.tar.xz
teachos-a5a1c6c55aeb9db352d116806ab01477e6dec344.zip
x86_64: add support for bootable image generation
Diffstat (limited to 'source')
-rw-r--r--source/cmake/Modules/Findgrub-mkrescue.cmake10
-rw-r--r--source/kernel/arch/x86_64/CMakeLists.txt29
-rw-r--r--source/kernel/arch/x86_64/support/grub.cfg.in7
3 files changed, 46 insertions, 0 deletions
diff --git a/source/cmake/Modules/Findgrub-mkrescue.cmake b/source/cmake/Modules/Findgrub-mkrescue.cmake
new file mode 100644
index 0000000..036b4fa
--- /dev/null
+++ b/source/cmake/Modules/Findgrub-mkrescue.cmake
@@ -0,0 +1,10 @@
+include("FindPackageHandleStandardArgs")
+
+find_program(GRUB_MKRESCUE_EXE "grub-mkrescue")
+find_program(MTOOLS_MFORMAT_EXE "mformat")
+
+find_package_handle_standard_args("grub-mkrescue"
+ DEFAULT_MSG
+ GRUB_MKRESCUE_EXE
+ MTOOLS_MFORMAT_EXE
+)
diff --git a/source/kernel/arch/x86_64/CMakeLists.txt b/source/kernel/arch/x86_64/CMakeLists.txt
index fe067ef..303ae1f 100644
--- a/source/kernel/arch/x86_64/CMakeLists.txt
+++ b/source/kernel/arch/x86_64/CMakeLists.txt
@@ -26,3 +26,32 @@ target_link_libraries("kernel" PRIVATE
set_target_properties("kernel" PROPERTIES
LINK_DEPENDS "${TEACHOS_KERNEL_LINKER_SCRIPT}"
)
+
+#[============================================================================[
+# Bootable ISO image generation
+#]============================================================================]
+
+find_package("grub-mkrescue")
+
+if(grub-mkrescue_FOUND)
+ set(ISO_FILE "${PROJECT_BINARY_DIR}/teachos-${PROJECT_VERSION}.iso")
+
+ file(GENERATE
+ OUTPUT "isofs/boot/grub/grub.cfg"
+ INPUT "support/grub.cfg.in"
+ )
+
+ add_custom_target("bootable-iso"
+ COMMAND "${GRUB_MKRESCUE_EXE}"
+ "-o"
+ "${ISO_FILE}"
+ "${CMAKE_CURRENT_BINARY_DIR}/isofs"
+ "$<TARGET_FILE:kernel>"
+ "2>/dev/null"
+ SOURCES
+ "$<TARGET_FILE:kernel>"
+ "isofs/boot/grub/grub.cfg"
+ BYPRODUCTS "${ISO_FILE}"
+ COMMENT "Creating bootable ISO image"
+ )
+endif() \ No newline at end of file
diff --git a/source/kernel/arch/x86_64/support/grub.cfg.in b/source/kernel/arch/x86_64/support/grub.cfg.in
new file mode 100644
index 0000000..49f19ce
--- /dev/null
+++ b/source/kernel/arch/x86_64/support/grub.cfg.in
@@ -0,0 +1,7 @@
+timeout=2
+default=0
+
+menuentry "TeachOS" {
+ multiboot2 /$<TARGET_FILE_NAME:kernel>
+ boot
+} \ No newline at end of file