aboutsummaryrefslogtreecommitdiff
path: root/test/test_dt.c
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2024-11-20 11:43:08 +0100
committerMiquel Sabaté Solà <mikisabate@gmail.com>2024-11-20 11:43:08 +0100
commitfb9627cc985912a57de8b4bedc98991e290e4075 (patch)
treeb7f0f72df6c6feb6beb672523afde5f793c87755 /test/test_dt.c
parentd3afdd9284f7e9838fbde4c941193ec2032d6a26 (diff)
downloadfbos-fb9627cc985912a57de8b4bedc98991e290e4075.tar.gz
fbos-fb9627cc985912a57de8b4bedc98991e290e4075.zip
Fetch the initrd address from the DTB blob
The kernel entry has a pointer to the DTB blob as a parameter. From this pointer we can parse the the DTB blob to find the properties "chosen->linux,initrd-start" and "chosen->linux,initrd-start". These properties are guaranteed to have 64-bit addresses which point where the initrd is in memory, which we need to fetch the binaries to be loaded. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'test/test_dt.c')
-rw-r--r--test/test_dt.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/test_dt.c b/test/test_dt.c
new file mode 100644
index 0000000..31f729f
--- /dev/null
+++ b/test/test_dt.c
@@ -0,0 +1,29 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include <fbos/dt.h>
+
+int main(void)
+{
+ FILE *fh = fopen("./test/testdata/qemu.dtb", "rb");
+ assert(fh);
+
+ fseek(fh, 0, SEEK_END);
+ long fsize = ftell(fh);
+ rewind(fh);
+
+ uint32_t *contents = malloc((unsigned long)fsize + 1);
+ fread(contents, (unsigned long)fsize, sizeof(uint32_t *), fh);
+ fclose(fh);
+
+ contents[fsize] = 0;
+
+ struct initrd_addr addr = find_dt_initrd_addr(contents);
+ free(contents);
+
+ assert(addr.start == 0x84200000);
+ assert(addr.end == 0x84200c00);
+
+ exit(0);
+}