Skip to content

Commit

Permalink
protos/limine: Filter memory@... nodes from device trees (#421)
Browse files Browse the repository at this point in the history
* protos/limine: Filter `memory@...` nodes from device trees

* docs: Mention removal of `memory@...` nodes for the DTB response
  • Loading branch information
marv7000 authored Oct 18, 2024
1 parent 6d2995a commit af488d6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions PROTOCOL.md
Original file line number Diff line number Diff line change
Expand Up @@ -1289,3 +1289,6 @@ Note: If the DTB cannot be found, the response will *not* be generated.
Note: Information contained in the `/chosen` node may not reflect the information
given by bootloader tags, and as such the `/chosen` node properties should be ignored.
Note: If the DTB contained `memory@...` nodes, they will get removed.
Kernels may not rely on these nodes and should use the Memory Map feature instead.
21 changes: 21 additions & 0 deletions common/protos/limine.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <lib/real.h>
#include <lib/libc.h>
#include <lib/gterm.h>
#include <lib/fdt.h>
#include <libfdt/libfdt.h>
#include <lib/uri.h>
#include <sys/smp.h>
#include <sys/cpu.h>
Expand Down Expand Up @@ -1017,6 +1019,25 @@ FEAT_START
}

if (dtb) {
// Delete all /memory@... nodes.
// The kernel must use the given UEFI memory map instead.
while (true) {
int offset = fdt_subnode_offset_namelen(dtb, 0, "memory@", 7);

if (offset == -FDT_ERR_NOTFOUND) {
break;
}

if (offset < 0) {
panic(true, "limine: failed to find node: '%s'", fdt_strerror(offset));
}

int ret = fdt_del_node(dtb, offset);
if (ret < 0) {
panic(true, "limine: failed to delete memory node: '%s'", fdt_strerror(ret));
}
}

struct limine_dtb_response *dtb_response =
ext_mem_alloc(sizeof(struct limine_dtb_response));
dtb_response->dtb_ptr = reported_addr(dtb);
Expand Down
6 changes: 5 additions & 1 deletion test/device_tree.dts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

/ {
soc {
limine_node: limine-node@deadbeef {
limine_node: limine@deadbeef {
reg = <0xdeadbeef 0x1000>;
label = "KANKER";
};
fake_memory: memory@ffff0000 {
reg = <0xffff0000 0xffff>;
label = "This node will be removed by Limine.";
};
};
};

0 comments on commit af488d6

Please sign in to comment.