From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>, rcz@pengutronix.de
Subject: [PATCH 4/4] of: request reserved memory regions so other code can't
Date: Thu, 9 Jun 2022 07:43:42 +0200 [thread overview]
Message-ID: <20220609054342.661505-5-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20220609054342.661505-1-a.fatoum@pengutronix.de>
From: Rouven Czerwinski <r.czerwinski@pengutronix.de>
Add a reserved_mem_read initcall which parses the reserved-memory
entries and adds barebox of reserve entries. This avoids e.g. bootm
trying to place the kernel into a reserved region.
Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
Compared with Rouven's v2, rename OF_RESERVE_ENTRY_FLAG_NO_RESERVE
to NO_FIXUP and read both /reserved-memory and /memreserve
to request memory regions.
---
common/memory.c | 21 +++++++++++++++++++--
drivers/of/Makefile | 1 +
drivers/of/fdt.c | 12 ++++++++----
include/of.h | 2 ++
4 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/common/memory.c b/common/memory.c
index 95995bb6e310..b40c74bfe97f 100644
--- a/common/memory.c
+++ b/common/memory.c
@@ -12,6 +12,7 @@
#include <asm-generic/memory_layout.h>
#include <asm/sections.h>
#include <malloc.h>
+#include <of.h>
/*
* Begin and End of memory area for malloc(), and current "brk"
@@ -53,9 +54,12 @@ void mem_malloc_init(void *start, void *end)
mem_malloc_initialized = 1;
}
-#if !defined __SANDBOX__
static int mem_malloc_resource(void)
{
+ struct of_reserve_map *map;
+ int i;
+
+#if !defined __SANDBOX__
/*
* Normally it's a bug when one of these fails,
* but we have some setups where some of these
@@ -80,10 +84,23 @@ static int mem_malloc_resource(void)
#ifdef STACK_BASE
request_sdram_region("stack", STACK_BASE, STACK_SIZE);
#endif
+#endif
+
+ map = of_get_reserve_map();
+ if (!map)
+ return 0;
+
+ for (i = 0; i < map->num_entries; i++) {
+ const char *name;
+
+ name = map->runtime_fw & BIT(i) ? "protected code" : "protected data";
+ request_sdram_region(name, map->start[i],
+ map->end[i] - map->start[i] + 1);
+ }
+
return 0;
}
coredevice_initcall(mem_malloc_resource);
-#endif
static void *sbrk_no_zero(ptrdiff_t increment)
{
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index ca8da71cb4f0..99b610cba85e 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -5,6 +5,7 @@ obj-$(CONFIG_OF_GPIO) += of_gpio.o
obj-$(CONFIG_OF_PCI) += of_pci.o
obj-y += partition.o
obj-y += of_net.o
+obj-$(CONFIG_OFDEVICE) += reserved-mem.o
obj-$(CONFIG_MTD) += of_mtd.o
obj-$(CONFIG_OF_BAREBOX_DRIVERS) += barebox.o
obj-$(CONFIG_OF_OVERLAY) += overlay.o resolver.o of_firmware.o
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index 4a4eeba24bc3..ee875f5787b1 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -551,6 +551,9 @@ int of_add_reserve_entry(resource_size_t start, resource_size_t end,
if (flags & OF_RESERVE_ENTRY_FLAG_RUNTIME_FW)
of_reserve_map.runtime_fw |= BIT(e);
+ if (flags & OF_RESERVE_ENTRY_FLAG_NO_FIXUP)
+ of_reserve_map.no_fixup |= BIT(e);
+
return 0;
}
@@ -592,11 +595,12 @@ void fdt_add_reserve_map(void *__fdt)
fdt_res += n;
- for (i = 0; i < res->num_entries; i++) {
+ for (i = 0; i < res->num_entries; i++, fdt_res++) {
+ if (BIT(i) & res->no_fixup)
+ continue;
+
of_write_number(&fdt_res->address, res->start[i], 2);
- of_write_number(&fdt_res->size, res->end[i] - res->start[i] + 1,
- 2);
- fdt_res++;
+ of_write_number(&fdt_res->size, res->end[i] - res->start[i] + 1, 2);
}
of_write_number(&fdt_res->address, (unsigned long)__fdt, 2);
diff --git a/include/of.h b/include/of.h
index d55016f1e372..c2a0cdae8dc2 100644
--- a/include/of.h
+++ b/include/of.h
@@ -56,9 +56,11 @@ struct of_reserve_map {
uint64_t end[OF_MAX_RESERVE_MAP];
int num_entries;
u16 runtime_fw : OF_MAX_RESERVE_MAP;
+ u16 no_fixup : OF_MAX_RESERVE_MAP;
};
#define OF_RESERVE_ENTRY_FLAG_RUNTIME_FW BIT(0)
+#define OF_RESERVE_ENTRY_FLAG_NO_FIXUP BIT(1)
int of_add_reserve_entry(resource_size_t start, resource_size_t end,
int flags);
--
2.30.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2022-06-09 5:45 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-09 5:43 [PATCH 0/4] " Ahmad Fatoum
2022-06-09 5:43 ` [PATCH 1/4] nvmem: rmem: get, don't request, memory region Ahmad Fatoum
2022-06-09 5:43 ` [PATCH 2/4] of: reserve: mark runtime firmware code regions specially Ahmad Fatoum
2022-06-09 8:05 ` Sascha Hauer
2022-06-09 8:17 ` Ahmad Fatoum
2022-06-09 5:43 ` [PATCH 3/4] of: add of_get_reserve_map stub for !CONFIG_OFTREE Ahmad Fatoum
2022-06-09 9:14 ` Sascha Hauer
2022-06-09 5:43 ` Ahmad Fatoum [this message]
2022-06-09 8:31 ` [PATCH] fixup! of: request reserved memory regions so other code can't Ahmad Fatoum
2022-06-09 8:31 ` [PATCH 4/4] " Sascha Hauer
2022-06-09 8:36 ` Ahmad Fatoum
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=20220609054342.661505-5-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=rcz@pengutronix.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