From fb9627cc985912a57de8b4bedc98991e290e4075 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Wed, 20 Nov 2024 11:43:08 +0100 Subject: Fetch the initrd address from the DTB blob MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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à --- test/test_dt.c | 29 +++++++++++++++++++++++++++++ test/testdata/qemu.dtb | Bin 0 -> 4864 bytes 2 files changed, 29 insertions(+) create mode 100644 test/test_dt.c create mode 100644 test/testdata/qemu.dtb (limited to 'test') 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 +#include +#include + +#include + +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); +} diff --git a/test/testdata/qemu.dtb b/test/testdata/qemu.dtb new file mode 100644 index 0000000..cd3d066 Binary files /dev/null and b/test/testdata/qemu.dtb differ -- cgit v1.2.3