* [PATCH 1/2] ARM: cpu: board-dt-2nd: rename of_find_mem for more generic use
@ 2021-02-22 6:30 Ahmad Fatoum
2021-02-22 6:30 ` [PATCH 2/2] pbl: provide externally visible fdt_find_mem Ahmad Fatoum
2021-02-22 7:59 ` [PATCH 1/2] ARM: cpu: board-dt-2nd: rename of_find_mem for more generic use Sascha Hauer
0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2021-02-22 6:30 UTC (permalink / raw)
To: barebox
of_find_mem can be used for generic DT images for other architectures as
well. Prepare for the move by giving it a more descriptive name and
type to reflect that it operates read-only on a FDT.
Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
arch/arm/cpu/board-dt-2nd.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/arm/cpu/board-dt-2nd.c b/arch/arm/cpu/board-dt-2nd.c
index 4e7d575e8a71..7a8155b7b01b 100644
--- a/arch/arm/cpu/board-dt-2nd.c
+++ b/arch/arm/cpu/board-dt-2nd.c
@@ -10,7 +10,7 @@
#include <asm/sections.h>
#include <linux/libfdt.h>
-static void of_find_mem(void *fdt, unsigned long *membase, unsigned long *memsize)
+static void fdt_find_mem(const void *fdt, unsigned long *membase, unsigned long *memsize)
{
const __be32 *nap, *nsp, *reg;
uint32_t na, ns;
@@ -85,7 +85,7 @@ static noinline void dt_2nd_continue_aarch64(void *fdt)
if (!fdt)
hang();
- of_find_mem(fdt, &membase, &memsize);
+ fdt_find_mem(fdt, &membase, &memsize);
barebox_arm_entry(membase, memsize, fdt);
}
@@ -114,7 +114,7 @@ static noinline void dt_2nd_continue(void *fdt)
if (!fdt)
hang();
- of_find_mem(fdt, &membase, &memsize);
+ fdt_find_mem(fdt, &membase, &memsize);
barebox_arm_entry(membase, memsize, fdt);
}
--
2.30.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] pbl: provide externally visible fdt_find_mem
2021-02-22 6:30 [PATCH 1/2] ARM: cpu: board-dt-2nd: rename of_find_mem for more generic use Ahmad Fatoum
@ 2021-02-22 6:30 ` Ahmad Fatoum
2021-02-22 7:59 ` [PATCH 1/2] ARM: cpu: board-dt-2nd: rename of_find_mem for more generic use Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2021-02-22 6:30 UTC (permalink / raw)
To: barebox
of_find_mem can be used for generic DT images for other architectures as
well. To support this, move the definition, so it can be used by others
in the future.
Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
arch/arm/cpu/board-dt-2nd.c | 68 +----------------------------------
include/pbl.h | 2 ++
pbl/Makefile | 1 +
pbl/fdt.c | 70 +++++++++++++++++++++++++++++++++++++
4 files changed, 74 insertions(+), 67 deletions(-)
create mode 100644 pbl/fdt.c
diff --git a/arch/arm/cpu/board-dt-2nd.c b/arch/arm/cpu/board-dt-2nd.c
index 7a8155b7b01b..bb131807859c 100644
--- a/arch/arm/cpu/board-dt-2nd.c
+++ b/arch/arm/cpu/board-dt-2nd.c
@@ -8,73 +8,7 @@
#include <debug_ll.h>
#include <asm/cache.h>
#include <asm/sections.h>
-#include <linux/libfdt.h>
-
-static void fdt_find_mem(const void *fdt, unsigned long *membase, unsigned long *memsize)
-{
- const __be32 *nap, *nsp, *reg;
- uint32_t na, ns;
- uint64_t memsize64, membase64;
- int node, size, i;
-
- /* Make sure FDT blob is sane */
- if (fdt_check_header(fdt) != 0) {
- pr_err("Invalid device tree blob\n");
- goto err;
- }
-
- /* Find the #address-cells and #size-cells properties */
- node = fdt_path_offset(fdt, "/");
- if (node < 0) {
- pr_err("Cannot find root node\n");
- goto err;
- }
-
- nap = fdt_getprop(fdt, node, "#address-cells", &size);
- if (!nap || (size != 4)) {
- pr_err("Cannot find #address-cells property");
- goto err;
- }
- na = fdt32_to_cpu(*nap);
-
- nsp = fdt_getprop(fdt, node, "#size-cells", &size);
- if (!nsp || (size != 4)) {
- pr_err("Cannot find #size-cells property");
- goto err;
- }
- ns = fdt32_to_cpu(*nap);
-
- /* Find the memory range */
- node = fdt_node_offset_by_prop_value(fdt, -1, "device_type",
- "memory", sizeof("memory"));
- if (node < 0) {
- pr_err("Cannot find memory node\n");
- goto err;
- }
-
- reg = fdt_getprop(fdt, node, "reg", &size);
- if (size < (na + ns) * sizeof(u32)) {
- pr_err("cannot get memory range\n");
- goto err;
- }
-
- membase64 = 0;
- for (i = 0; i < na; i++)
- membase64 = (membase64 << 32) | fdt32_to_cpu(*reg++);
-
- /* get the memsize and truncate it to under 4G on 32 bit machines */
- memsize64 = 0;
- for (i = 0; i < ns; i++)
- memsize64 = (memsize64 << 32) | fdt32_to_cpu(*reg++);
-
- *membase = membase64;
- *memsize = memsize64;
-
- return;
-err:
- pr_err("No memory, cannot continue\n");
- while (1);
-}
+#include <pbl.h>
#ifdef CONFIG_CPU_V8
diff --git a/include/pbl.h b/include/pbl.h
index 5e971f865675..194d5e750839 100644
--- a/include/pbl.h
+++ b/include/pbl.h
@@ -32,4 +32,6 @@ ssize_t pbl_fat_load(struct pbl_bio *, const char *filename, void *dest, size_t
#define IN_PBL 0
#endif
+void fdt_find_mem(const void *fdt, unsigned long *membase, unsigned long *memsize);
+
#endif /* __PBL_H__ */
diff --git a/pbl/Makefile b/pbl/Makefile
index c5a08c135421..9faa56ac91d1 100644
--- a/pbl/Makefile
+++ b/pbl/Makefile
@@ -4,4 +4,5 @@
pbl-y += misc.o
pbl-y += string.o
pbl-y += decomp.o
+pbl-$(CONFIG_LIBFDT) += fdt.o
pbl-$(CONFIG_PBL_CONSOLE) += console.o
diff --git a/pbl/fdt.c b/pbl/fdt.c
new file mode 100644
index 000000000000..b4a40a514b8b
--- /dev/null
+++ b/pbl/fdt.c
@@ -0,0 +1,70 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/libfdt.h>
+#include <pbl.h>
+#include <printk.h>
+
+void fdt_find_mem(const void *fdt, unsigned long *membase, unsigned long *memsize)
+{
+ const __be32 *nap, *nsp, *reg;
+ uint32_t na, ns;
+ uint64_t memsize64, membase64;
+ int node, size, i;
+
+ /* Make sure FDT blob is sane */
+ if (fdt_check_header(fdt) != 0) {
+ pr_err("Invalid device tree blob\n");
+ goto err;
+ }
+
+ /* Find the #address-cells and #size-cells properties */
+ node = fdt_path_offset(fdt, "/");
+ if (node < 0) {
+ pr_err("Cannot find root node\n");
+ goto err;
+ }
+
+ nap = fdt_getprop(fdt, node, "#address-cells", &size);
+ if (!nap || (size != 4)) {
+ pr_err("Cannot find #address-cells property");
+ goto err;
+ }
+ na = fdt32_to_cpu(*nap);
+
+ nsp = fdt_getprop(fdt, node, "#size-cells", &size);
+ if (!nsp || (size != 4)) {
+ pr_err("Cannot find #size-cells property");
+ goto err;
+ }
+ ns = fdt32_to_cpu(*nap);
+
+ /* Find the memory range */
+ node = fdt_node_offset_by_prop_value(fdt, -1, "device_type",
+ "memory", sizeof("memory"));
+ if (node < 0) {
+ pr_err("Cannot find memory node\n");
+ goto err;
+ }
+
+ reg = fdt_getprop(fdt, node, "reg", &size);
+ if (size < (na + ns) * sizeof(u32)) {
+ pr_err("cannot get memory range\n");
+ goto err;
+ }
+
+ membase64 = 0;
+ for (i = 0; i < na; i++)
+ membase64 = (membase64 << 32) | fdt32_to_cpu(*reg++);
+
+ /* get the memsize and truncate it to under 4G on 32 bit machines */
+ memsize64 = 0;
+ for (i = 0; i < ns; i++)
+ memsize64 = (memsize64 << 32) | fdt32_to_cpu(*reg++);
+
+ *membase = membase64;
+ *memsize = memsize64;
+
+ return;
+err:
+ pr_err("No memory, cannot continue\n");
+ while (1);
+}
--
2.30.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] ARM: cpu: board-dt-2nd: rename of_find_mem for more generic use
2021-02-22 6:30 [PATCH 1/2] ARM: cpu: board-dt-2nd: rename of_find_mem for more generic use Ahmad Fatoum
2021-02-22 6:30 ` [PATCH 2/2] pbl: provide externally visible fdt_find_mem Ahmad Fatoum
@ 2021-02-22 7:59 ` Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2021-02-22 7:59 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: barebox
On Mon, Feb 22, 2021 at 07:30:51AM +0100, Ahmad Fatoum wrote:
> of_find_mem can be used for generic DT images for other architectures as
> well. Prepare for the move by giving it a more descriptive name and
> type to reflect that it operates read-only on a FDT.
>
> Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
> ---
> arch/arm/cpu/board-dt-2nd.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
Applied, thanks
Sascha
>
> diff --git a/arch/arm/cpu/board-dt-2nd.c b/arch/arm/cpu/board-dt-2nd.c
> index 4e7d575e8a71..7a8155b7b01b 100644
> --- a/arch/arm/cpu/board-dt-2nd.c
> +++ b/arch/arm/cpu/board-dt-2nd.c
> @@ -10,7 +10,7 @@
> #include <asm/sections.h>
> #include <linux/libfdt.h>
>
> -static void of_find_mem(void *fdt, unsigned long *membase, unsigned long *memsize)
> +static void fdt_find_mem(const void *fdt, unsigned long *membase, unsigned long *memsize)
> {
> const __be32 *nap, *nsp, *reg;
> uint32_t na, ns;
> @@ -85,7 +85,7 @@ static noinline void dt_2nd_continue_aarch64(void *fdt)
> if (!fdt)
> hang();
>
> - of_find_mem(fdt, &membase, &memsize);
> + fdt_find_mem(fdt, &membase, &memsize);
>
> barebox_arm_entry(membase, memsize, fdt);
> }
> @@ -114,7 +114,7 @@ static noinline void dt_2nd_continue(void *fdt)
> if (!fdt)
> hang();
>
> - of_find_mem(fdt, &membase, &memsize);
> + fdt_find_mem(fdt, &membase, &memsize);
>
> barebox_arm_entry(membase, memsize, fdt);
> }
> --
> 2.30.0
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-02-22 7:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-22 6:30 [PATCH 1/2] ARM: cpu: board-dt-2nd: rename of_find_mem for more generic use Ahmad Fatoum
2021-02-22 6:30 ` [PATCH 2/2] pbl: provide externally visible fdt_find_mem Ahmad Fatoum
2021-02-22 7:59 ` [PATCH 1/2] ARM: cpu: board-dt-2nd: rename of_find_mem for more generic use Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox