]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mips: generic: add fdt fixup for Realtek reference board
authorChris Packham <chris.packham@alliedtelesis.co.nz>
Wed, 10 Jul 2024 04:35:23 +0000 (16:35 +1200)
committerThomas Bogendoerfer <tsbogend@alpha.franken.de>
Fri, 12 Jul 2024 11:12:13 +0000 (13:12 +0200)
The bootloader used on the Realtek RTL9302C boards is an ancient vendor
fork of U-Boot that doesn't understand device trees. So to run a modern
kernel it is necessary use one of the APPENDED_DTB options.

When appending the DTB the inintrd information, if present, needs to be
inserted into the /chosen device tree node. The bootloader provides the
initrd start/size via the firmware environment. Add a fdt fixup that
will update the device tree with the initrd information.

Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
arch/mips/generic/Makefile
arch/mips/generic/board-realtek.c [new file with mode: 0644]

index 56011d738441fc7f2bb6722e86b9edeca9584e20..ea0e4ad5e6007c941e328191b155a83edc808146 100644 (file)
@@ -13,3 +13,4 @@ obj-$(CONFIG_LEGACY_BOARD_SEAD3)      += board-sead3.o
 obj-$(CONFIG_LEGACY_BOARD_OCELOT)      += board-ocelot.o
 obj-$(CONFIG_MACH_INGENIC)                     += board-ingenic.o
 obj-$(CONFIG_VIRT_BOARD_RANCHU)                += board-ranchu.o
+obj-$(CONFIG_MACH_REALTEK_RTL)         += board-realtek.o
diff --git a/arch/mips/generic/board-realtek.c b/arch/mips/generic/board-realtek.c
new file mode 100644 (file)
index 0000000..9cce610
--- /dev/null
@@ -0,0 +1,79 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2024 Allied Telesis
+ */
+
+#include <linux/errno.h>
+#include <linux/libfdt.h>
+#include <linux/printk.h>
+#include <linux/types.h>
+
+#include <asm/fw/fw.h>
+#include <asm/machine.h>
+
+static __init int realtek_add_initrd(void *fdt)
+{
+       int node, err;
+       u32 start, size;
+
+       node = fdt_path_offset(fdt, "/chosen");
+       if (node < 0) {
+               pr_err("/chosen node not found\n");
+               return -ENOENT;
+       }
+
+       start = fw_getenvl("initrd_start");
+       size = fw_getenvl("initrd_size");
+
+       if (start == 0 && size == 0)
+               return 0;
+
+       pr_info("Adding initrd info from environment\n");
+
+       err = fdt_setprop_u32(fdt, node, "linux,initrd-start", start);
+       if (err) {
+               pr_err("unable to set initrd-start: %d\n", err);
+               return err;
+       }
+
+       err = fdt_setprop_u32(fdt, node, "linux,initrd-end", start + size);
+       if (err) {
+               pr_err("unable to set initrd-end: %d\n", err);
+               return err;
+       }
+
+       return 0;
+}
+
+static const struct mips_fdt_fixup realtek_fdt_fixups[] __initconst = {
+       { realtek_add_initrd, "add initrd" },
+       {},
+};
+
+static __init const void *realtek_fixup_fdt(const void *fdt, const void *match_data)
+{
+       static unsigned char fdt_buf[16 << 10] __initdata;
+       int err;
+
+       if (fdt_check_header(fdt))
+               panic("Corrupt DT");
+
+       fw_init_cmdline();
+
+       err = apply_mips_fdt_fixups(fdt_buf, sizeof(fdt_buf), fdt, realtek_fdt_fixups);
+       if (err)
+               panic("Unable to fixup FDT: %d", err);
+
+       return fdt_buf;
+
+}
+
+static const struct of_device_id realtek_of_match[] __initconst = {
+       { .compatible = "realtek,rtl9302-soc" },
+       {}
+};
+
+MIPS_MACHINE(realtek) = {
+       .matches = realtek_of_match,
+       .fixup_fdt = realtek_fixup_fdt,
+};