devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chris Packham <chris.packham@alliedtelesis.co.nz>
To: tglx@linutronix.de, robh@kernel.org, krzk+dt@kernel.org,
	conor+dt@kernel.org, tsbogend@alpha.franken.de,
	daniel.lezcano@linaro.org, paulburton@kernel.org,
	peterz@infradead.org, mail@birger-koblitz.de, bert@biot.com,
	john@phrozen.org, sander@svanheule.net
Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	linux-mips@vger.kernel.org, kabel@kernel.org,
	ericwouds@gmail.com,
	Chris Packham <chris.packham@alliedtelesis.co.nz>
Subject: [PATCH v3 8/9] mips: generic: add fdt fixup for Realtek reference board
Date: Thu, 27 Jun 2024 16:33:16 +1200	[thread overview]
Message-ID: <20240627043317.3751996-9-chris.packham@alliedtelesis.co.nz> (raw)
In-Reply-To: <20240627043317.3751996-1-chris.packham@alliedtelesis.co.nz>

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>
---

Notes:
    Changes in v3:
    - None
    Changes in v2:
    - update compatible string

 arch/mips/generic/Makefile        |  1 +
 arch/mips/generic/board-realtek.c | 81 +++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+)
 create mode 100644 arch/mips/generic/board-realtek.c

diff --git a/arch/mips/generic/Makefile b/arch/mips/generic/Makefile
index 56011d738441..ea0e4ad5e600 100644
--- a/arch/mips/generic/Makefile
+++ b/arch/mips/generic/Makefile
@@ -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
index 000000000000..cd83fbf1968c
--- /dev/null
+++ b/arch/mips/generic/board-realtek.c
@@ -0,0 +1,81 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 Allied Telesis
+ */
+
+#include <linux/errno.h>
+#include <linux/libfdt.h>
+#include <linux/of_address.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",
+	},
+	{}
+};
+
+MIPS_MACHINE(realtek) = {
+	.matches = realtek_of_match,
+	.fixup_fdt = realtek_fixup_fdt,
+};
-- 
2.45.2


  parent reply	other threads:[~2024-06-27  4:33 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-27  4:33 [PATCH v3 0/9] mips: Support for RTL9302C Chris Packham
2024-06-27  4:33 ` [PATCH v3 1/9] mips: dts: realtek: use "serial" instead of "uart" in node name Chris Packham
2024-06-27 10:59   ` Marek Behún
2024-06-27  4:33 ` [PATCH v3 2/9] mips: dts: realtek: add device_type property to cpu node Chris Packham
2024-06-27 11:01   ` Marek Behún
2024-06-27  4:33 ` [PATCH v3 3/9] dt-bindings: vendor-prefixes: Add Cameo Communications Chris Packham
2024-06-27  7:39   ` Krzysztof Kozlowski
2024-06-27  4:33 ` [PATCH v3 4/9] dt-bindings: mips: realtek: Add rtl930x-soc compatible Chris Packham
2024-06-27  7:39   ` Krzysztof Kozlowski
2024-06-27  4:33 ` [PATCH v3 5/9] dt-bindings: timer: Add schema for realtek,otto-timer Chris Packham
2024-06-27  7:40   ` Krzysztof Kozlowski
2024-06-29 20:40   ` Sander Vanheule
2024-07-01  2:15     ` Chris Packham
2024-06-27  4:33 ` [PATCH v3 6/9] dt-bindings: interrupt-controller: realtek,rtl-intc: Add rtl9300-intc Chris Packham
2024-06-27  5:37   ` Rob Herring (Arm)
2024-06-27  7:41   ` Krzysztof Kozlowski
2024-06-30 22:12     ` Chris Packham
2024-07-01  3:02       ` Chris Packham
2024-06-27  4:33 ` [PATCH v3 7/9] clocksource: realtek: Add timer driver for rtl-otto platforms Chris Packham
2024-06-27 11:17   ` Marek Behún
2024-07-01  4:41     ` Chris Packham
2024-06-29 21:03   ` Sander Vanheule
2024-07-01  2:07     ` Chris Packham
2024-06-30  1:10   ` kernel test robot
2024-06-27  4:33 ` Chris Packham [this message]
2024-06-27 11:19   ` [PATCH v3 8/9] mips: generic: add fdt fixup for Realtek reference board Marek Behún
2024-06-27 17:48   ` Rob Herring
2024-06-30 22:39     ` Chris Packham
2024-06-27  4:33 ` [PATCH v3 9/9] mips: dts: realtek: Add RTL9302C board Chris Packham
2024-06-27 14:42 ` [PATCH v3 0/9] mips: Support for RTL9302C Rob Herring
2024-06-30 23:43   ` Chris Packham
2024-07-01  3:26     ` Chris Packham

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240627043317.3751996-9-chris.packham@alliedtelesis.co.nz \
    --to=chris.packham@alliedtelesis.co.nz \
    --cc=bert@biot.com \
    --cc=conor+dt@kernel.org \
    --cc=daniel.lezcano@linaro.org \
    --cc=devicetree@vger.kernel.org \
    --cc=ericwouds@gmail.com \
    --cc=john@phrozen.org \
    --cc=kabel@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=mail@birger-koblitz.de \
    --cc=paulburton@kernel.org \
    --cc=peterz@infradead.org \
    --cc=robh@kernel.org \
    --cc=sander@svanheule.net \
    --cc=tglx@linutronix.de \
    --cc=tsbogend@alpha.franken.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).