Skip to content

Commit

Permalink
protos/limine: Filter memory@... nodes from device trees
Browse files Browse the repository at this point in the history
  • Loading branch information
marv7000 committed Oct 18, 2024
1 parent 4cdda6a commit a3c9596
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
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
4 changes: 2 additions & 2 deletions test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ ovmf-loongarch64:
test.hdd:
rm -f test.hdd
dd if=/dev/zero bs=1M count=0 seek=64 of=test.hdd
parted -s test.hdd mklabel gpt
parted -s test.hdd mkpart primary 2048s 100%
sudo parted -s test.hdd mklabel gpt
sudo parted -s test.hdd mkpart primary 2048s 100%

.PHONY: mbrtest.hdd
mbrtest.hdd:
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 a3c9596

Please sign in to comment.