From e750481d12717305a17165d36f97c888b5a31085 Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Thu, 5 Nov 2020 00:59:32 +0100 Subject: [PATCH] Fix multiple issues with reported flash memory usage: - Remove unused next_free_memory=BigBuf_get_addr() - Fix size retrieval of compressed data section by chance the corrupted value was > than correct value so decompression was taking place, but was returning an error instead of the decompressed size - Fix reporting of compressed size into common_area returned value of LZ4_decompress_safe is the decompressed size while we needed to report the compressed size - Fix common_area late initialization common_area was initialized (and zeroed) after uncompress_data_section() had reported the compressed size in common_area, so compressed size was erased Compressed size is used in the computation of the used and available flash memory, which is now correct (it was wrongly telling about 6kb were free while they weren't). --- armsrc/appmain.c | 8 -------- armsrc/start.c | 15 +++++++++++---- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/armsrc/appmain.c b/armsrc/appmain.c index 51cbb2770..c870a7dba 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -2299,14 +2299,6 @@ void __attribute__((noreturn)) AppMain(void) { *p = 0xdeadbeef; } - if (common_area.magic != COMMON_AREA_MAGIC || common_area.version != 1) { - /* Initialize common area */ - memset(&common_area, 0, sizeof(common_area)); - common_area.magic = COMMON_AREA_MAGIC; - common_area.version = 1; - } - common_area.flags.osimage_present = 1; - LEDsoff(); // The FPGA gets its clock from us from PCK0 output, so set that up. diff --git a/armsrc/start.c b/armsrc/start.c index e2904f6e1..70eee5063 100644 --- a/armsrc/start.c +++ b/armsrc/start.c @@ -18,14 +18,13 @@ #include "BigBuf.h" #include "string.h" -static uint8_t *next_free_memory; extern struct common_area common_area; extern char __data_src_start__, __data_start__, __data_end__, __bss_start__, __bss_end__; + static void uncompress_data_section(void) { - next_free_memory = BigBuf_get_addr(); int avail_in; - memcpy(&avail_in, &__data_start__, sizeof(int)); + memcpy(&avail_in, &__data_src_start__, sizeof(int)); int avail_out = &__data_end__ - &__data_start__; // uncompressed size. Correct. // uncompress data segment to RAM uintptr_t p = (uintptr_t)&__data_src_start__; @@ -34,13 +33,21 @@ static void uncompress_data_section(void) { if (res < 0) return; // save the size of the compressed data section - common_area.arg1 = res; + common_area.arg1 = avail_in; } void __attribute__((section(".startos"))) Vector(void); void Vector(void) { /* Stack should have been set up by the bootloader */ + if (common_area.magic != COMMON_AREA_MAGIC || common_area.version != 1) { + /* Initialize common area */ + memset(&common_area, 0, sizeof(common_area)); + common_area.magic = COMMON_AREA_MAGIC; + common_area.version = 1; + } + common_area.flags.osimage_present = 1; + uncompress_data_section(); /* Set up (that is: clear) BSS. */