aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2024-11-29 22:17:13 +0100
committerMiquel Sabaté Solà <mikisabate@gmail.com>2024-11-29 22:17:13 +0100
commitd51665904faa31c39106e4b2afa7541615072e72 (patch)
tree01c355472bcca04f59980d961dca0bc46c9b429b /include
parent010888de490ab1fafc0200c37cd09d57a0ff1e9f (diff)
downloadfbos-d51665904faa31c39106e4b2afa7541615072e72.tar.gz
fbos-d51665904faa31c39106e4b2afa7541615072e72.zip
Allow the kernel to run as a Linux image
In order to run on real hardware, it's actually easier to re-use workflows from existing bootloaders than loading things in memory manually. In order to achieve this two things had to be settled: 1. The image has to have a Linux header as defined in the RISC-V port. This header will be taken into consideration by bootloaders in order to know where to jump, the image offset, the endianness of the image, etc. 2. The image cannot just be an ELF executable. Rather, we must translate it into binary form via `objcopy`. With all of this at hand, I was able to make the kernel run on a Starfive VisionFive 2 board, and I have recorded an example so it's available as documentation. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'include')
-rw-r--r--include/fbos/image.h23
-rw-r--r--include/fbos/mm.h3
2 files changed, 25 insertions, 1 deletions
diff --git a/include/fbos/image.h b/include/fbos/image.h
new file mode 100644
index 0000000..c217c36
--- /dev/null
+++ b/include/fbos/image.h
@@ -0,0 +1,23 @@
+#ifndef __FBOS_IMAGE_H
+#define __FBOS_IMAGE_H
+
+/*
+ * General definitions for building up an image that is suitable on real
+ * hardware that expect a Linux kernel header.
+ */
+
+// Deprecated image magic.
+#define RISCV_IMAGE_MAGIC "RISCV\0\0\0"
+
+// Image magic that the bootloader expects. It's placed at the same position as
+// ARM64, which is why the previous 'RISCV_IMAGE_MAGIC' has been deprecated in
+// favour of this one.
+#define RISCV_IMAGE_MAGIC2 "RSC\x05"
+
+// Image header version as defined by Linux in the format of
+// u32: MSB| u16: major | u16: minor |LSB
+#define RISCV_HEADER_VERSION_MAJOR 0
+#define RISCV_HEADER_VERSION_MINOR 2
+#define RISCV_HEADER_VERSION (RISCV_HEADER_VERSION_MAJOR << 16 | RISCV_HEADER_VERSION_MINOR)
+
+#endif /* __FBOS_IMAGE */
diff --git a/include/fbos/mm.h b/include/fbos/mm.h
index 25d18ce..e913fa7 100644
--- a/include/fbos/mm.h
+++ b/include/fbos/mm.h
@@ -17,7 +17,8 @@
* The code will be linked to start at the first page, which will have a given
* offset.
*/
+
#define PAGE_OFFSET 0x80200000
-#define LINK_ADDR PAGE_OFFSET
+#define LOAD_OFFSET PAGE_OFFSET
#endif /* __FBOS_MM_H */