From f46959cef4360960103d84467b82a56d56152fe4 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Fri, 7 May 2021 14:50:33 +0200 Subject: image-fdt: save no-map parameter of reserve-memory Save the 'no-map' information present in 'reserved-memory' node to allow correct handling when the MMU is configured in board to avoid speculative access. This binding is defined in doc/device-tree-bindings/reserved-memory/reserved-memory.txt Additional properties: ... no-map (optional) - empty property - Indicates the operating system must not create a virtual mapping of the region as part of its standard mapping of system memory, nor permit speculative access to it under any circumstances other than under the control of the device driver using the region. Signed-off-by: Patrick Delaunay --- common/image-fdt.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'common') diff --git a/common/image-fdt.c b/common/image-fdt.c index d50e1ba..06dce92 100644 --- a/common/image-fdt.c +++ b/common/image-fdt.c @@ -75,18 +75,20 @@ static const image_header_t *image_get_fdt(ulong fdt_addr) #endif static void boot_fdt_reserve_region(struct lmb *lmb, uint64_t addr, - uint64_t size) + uint64_t size, enum lmb_flags flags) { long ret; - ret = lmb_reserve(lmb, addr, size); + ret = lmb_reserve_flags(lmb, addr, size, flags); if (ret >= 0) { - debug(" reserving fdt memory region: addr=%llx size=%llx\n", - (unsigned long long)addr, (unsigned long long)size); + debug(" reserving fdt memory region: addr=%llx size=%llx flags=%x\n", + (unsigned long long)addr, + (unsigned long long)size, flags); } else { puts("ERROR: reserving fdt memory region failed "); - printf("(addr=%llx size=%llx)\n", - (unsigned long long)addr, (unsigned long long)size); + printf("(addr=%llx size=%llx flags=%x)\n", + (unsigned long long)addr, + (unsigned long long)size, flags); } } @@ -106,6 +108,7 @@ void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob) int i, total, ret; int nodeoffset, subnode; struct fdt_resource res; + enum lmb_flags flags; if (fdt_check_header(fdt_blob) != 0) return; @@ -115,7 +118,7 @@ void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob) for (i = 0; i < total; i++) { if (fdt_get_mem_rsv(fdt_blob, i, &addr, &size) != 0) continue; - boot_fdt_reserve_region(lmb, addr, size); + boot_fdt_reserve_region(lmb, addr, size, LMB_NONE); } /* process reserved-memory */ @@ -127,9 +130,13 @@ void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob) ret = fdt_get_resource(fdt_blob, subnode, "reg", 0, &res); if (!ret && fdtdec_get_is_enabled(fdt_blob, subnode)) { + flags = LMB_NONE; + if (fdtdec_get_bool(fdt_blob, subnode, + "no-map")) + flags = LMB_NOMAP; addr = res.start; size = res.end - res.start + 1; - boot_fdt_reserve_region(lmb, addr, size); + boot_fdt_reserve_region(lmb, addr, size, flags); } subnode = fdt_next_subnode(fdt_blob, subnode); -- cgit v1.1 From c1a2bb4f836a1c96c8e39a67be9795d462ec3356 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 8 May 2021 06:59:56 -0600 Subject: console: Report an error when output buffer is exhausted If the console output buffer is exhausted, characters are silently dropped from the end. Detect this condition and report an error when reading back the characters. Signed-off-by: Simon Glass --- common/console.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'common') diff --git a/common/console.c b/common/console.c index 561cdf3..73edb28 100644 --- a/common/console.c +++ b/common/console.c @@ -95,16 +95,22 @@ static void console_record_putc(const char c) { if (!(gd->flags & GD_FLG_RECORD)) return; - if (gd->console_out.start) - membuff_putbyte((struct membuff *)&gd->console_out, c); + if (gd->console_out.start && + !membuff_putbyte((struct membuff *)&gd->console_out, c)) + gd->flags |= GD_FLG_RECORD_OVF; } static void console_record_puts(const char *s) { if (!(gd->flags & GD_FLG_RECORD)) return; - if (gd->console_out.start) - membuff_put((struct membuff *)&gd->console_out, s, strlen(s)); + if (gd->console_out.start) { + int len = strlen(s); + + if (membuff_put((struct membuff *)&gd->console_out, s, len) != + len) + gd->flags |= GD_FLG_RECORD_OVF; + } } static int console_record_getc(void) @@ -742,6 +748,7 @@ void console_record_reset(void) { membuff_purge((struct membuff *)&gd->console_out); membuff_purge((struct membuff *)&gd->console_in); + gd->flags &= ~GD_FLG_RECORD_OVF; } int console_record_reset_enable(void) @@ -754,6 +761,9 @@ int console_record_reset_enable(void) int console_record_readline(char *str, int maxlen) { + if (gd->flags & GD_FLG_RECORD_OVF) + return -ENOSPC; + return membuff_readline((struct membuff *)&gd->console_out, str, maxlen, ' '); } -- cgit v1.1 From 58b4b7133aba6fbb2409a975478157f9277c2e91 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Sat, 8 May 2021 07:00:06 -0600 Subject: log: Add support for logging a buffer The print_buffer() function is very useful for debugging. Add a version of this in the log system also. Signed-off-by: Simon Glass --- common/log.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'common') diff --git a/common/log.c b/common/log.c index ea407c6..1aaa6c1 100644 --- a/common/log.c +++ b/common/log.c @@ -284,6 +284,36 @@ int _log(enum log_category_t cat, enum log_level_t level, const char *file, return 0; } +#define MAX_LINE_LENGTH_BYTES 64 +#define DEFAULT_LINE_LENGTH_BYTES 16 + +int _log_buffer(enum log_category_t cat, enum log_level_t level, + const char *file, int line, const char *func, ulong addr, + const void *data, uint width, uint count, uint linelen) +{ + if (linelen * width > MAX_LINE_LENGTH_BYTES) + linelen = MAX_LINE_LENGTH_BYTES / width; + if (linelen < 1) + linelen = DEFAULT_LINE_LENGTH_BYTES / width; + + while (count) { + uint thislinelen; + char buf[HEXDUMP_MAX_BUF_LENGTH(width * linelen)]; + + thislinelen = hexdump_line(addr, data, width, count, linelen, + buf, sizeof(buf)); + assert(thislinelen >= 0); + _log(cat, level, file, line, func, "%s\n", buf); + + /* update references */ + data += thislinelen * width; + addr += thislinelen * width; + count -= thislinelen; + } + + return 0; +} + int log_add_filter_flags(const char *drv_name, enum log_category_t cat_list[], enum log_level_t level, const char *file_list, int flags) -- cgit v1.1 From 481d394e77915201e4ecc2d98e9cc2fbc3224991 Mon Sep 17 00:00:00 2001 From: Lokesh Vutla Date: Fri, 11 Jun 2021 11:45:05 +0300 Subject: common: fit: Update board_fit_image_post_process() to pass fit and node_offset board_fit_image_post_process() passes only start and size of the image, but type of the image is not passed. So pass fit and node_offset, to derive information about image to be processed. Signed-off-by: Lokesh Vutla Reviewed-by: Tom Rini Signed-off-by: Tero Kristo --- common/image-fit.c | 2 +- common/spl/spl_fit.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'common') diff --git a/common/image-fit.c b/common/image-fit.c index e614643..0c5a059 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -2143,7 +2143,7 @@ int fit_image_load(bootm_headers_t *images, ulong addr, /* perform any post-processing on the image data */ if (!host_build() && IS_ENABLED(CONFIG_FIT_IMAGE_POST_PROCESS)) - board_fit_image_post_process(&buf, &size); + board_fit_image_post_process(fit, noffset, &buf, &size); len = (ulong)size; diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index caddf51..57d621d 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -320,7 +320,7 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector, } if (CONFIG_IS_ENABLED(FIT_IMAGE_POST_PROCESS)) - board_fit_image_post_process(&src, &length); + board_fit_image_post_process(fit, node, &src, &length); load_ptr = map_sysmem(load_addr, length); if (IS_ENABLED(CONFIG_SPL_GZIP) && image_comp == IH_COMP_GZIP) { -- cgit v1.1 From be2d1a87c73b3f722fc5b0438d780014579a43de Mon Sep 17 00:00:00 2001 From: Michal Simek Date: Thu, 27 May 2021 11:40:09 +0200 Subject: spl: fit: Also record architecture in /fit-images On ARM64 secure OS can run as 64bit or 32bit that's why it is necessary to record information about architecture that other code can read it and properly pass it to TF-A and start in 64bit or 32bit mode. Signed-off-by: Michal Simek Reviewed-by: Simon Glass --- common/fdt_support.c | 4 +++- common/spl/spl_fit.c | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'common') diff --git a/common/fdt_support.c b/common/fdt_support.c index a9a32df..240f1e5 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -594,7 +594,7 @@ void fdt_fixup_ethernet(void *fdt) int fdt_record_loadable(void *blob, u32 index, const char *name, uintptr_t load_addr, u32 size, uintptr_t entry_point, - const char *type, const char *os) + const char *type, const char *os, const char *arch) { int err, node; @@ -622,6 +622,8 @@ int fdt_record_loadable(void *blob, u32 index, const char *name, fdt_setprop_string(blob, node, "type", type); if (os) fdt_setprop_string(blob, node, "os", os); + if (arch) + fdt_setprop_string(blob, node, "arch", arch); return node; } diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index caddf51..f6c4753 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -480,7 +480,8 @@ static int spl_fit_record_loadable(const struct spl_fit_info *ctx, int index, ret = fdt_record_loadable(blob, index, name, image->load_addr, image->size, image->entry_point, fdt_getprop(ctx->fit, node, "type", NULL), - fdt_getprop(ctx->fit, node, "os", NULL)); + fdt_getprop(ctx->fit, node, "os", NULL), + fdt_getprop(ctx->fit, node, "arch", NULL)); return ret; } -- cgit v1.1