summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/sf.c8
-rw-r--r--include/lmb.h5
2 files changed, 13 insertions, 0 deletions
diff --git a/cmd/sf.c b/cmd/sf.c
index f43a2e08b31..08e364e1914 100644
--- a/cmd/sf.c
+++ b/cmd/sf.c
@@ -10,6 +10,7 @@
#include <div64.h>
#include <dm.h>
#include <log.h>
+#include <lmb.h>
#include <malloc.h>
#include <mapmem.h>
#include <spi.h>
@@ -317,6 +318,13 @@ static int do_spi_flash_read_write(int argc, char *const argv[])
strncmp(argv[0], "write", 5) == 0) {
int read;
+ if (CONFIG_IS_ENABLED(LMB)) {
+ if (lmb_read_check(addr, len)) {
+ printf("ERROR: trying to overwrite reserved memory...\n");
+ return CMD_RET_FAILURE;
+ }
+ }
+
read = strncmp(argv[0], "read", 4) == 0;
if (read)
ret = spi_flash_read(flash, offset, len, buf);
diff --git a/include/lmb.h b/include/lmb.h
index fc2daaa7bfc..aee2f9fcdaa 100644
--- a/include/lmb.h
+++ b/include/lmb.h
@@ -111,6 +111,11 @@ struct lmb *lmb_get(void);
int lmb_push(struct lmb *store);
void lmb_pop(struct lmb *store);
+static inline int lmb_read_check(phys_addr_t addr, phys_size_t len)
+{
+ return lmb_alloc_addr(addr, len) == addr ? 0 : -1;
+}
+
#endif /* __KERNEL__ */
#endif /* _LINUX_LMB_H */