From b72c027924a3fc6f9cff703f254cfcf3afd7ded9 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Mon, 17 Jan 2022 11:45:22 +0100 Subject: [PATCH 1/3] XFLASH layout explained --- Firmware/xflash_layout.h | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/Firmware/xflash_layout.h b/Firmware/xflash_layout.h index 5d92d6e6c..305846298 100644 --- a/Firmware/xflash_layout.h +++ b/Firmware/xflash_layout.h @@ -1,3 +1,50 @@ + +/** + * @file + * @author leptun + */ + /** \ingroup xflash_layout */ + + //! This is the layout of the XFLASH (external SPI flash) in Prusa firmware (dynamically generated from doxygen). + + +/** @defgroup xflash_layout XFLASH Layout + * + + --------------------------------------------------------------------------------- + The XFLASH has the following alignment requirements: + - Block erase of 64KB. This is what the second bootloader uses. If anything even starts writing to a block, the entire block is erased by the bootloader. It will cause loss of crash dump on firmware upload. Nothing more than that. + - Block erase of 32KB. Not used. + - Sector erase of 4KB. Used by the xflash_dump. This is the minimum size for erasing and as such the dump is 4KB aligned as to not erase other stuff unintentionally. + - Page write of 256B. Lower access can be used, but care must be used since the address wraps at the page boundary when writing. + - Read has no alignment requirements. + + The following items are found in the xflash: + + ### 1. Languages (R) + This is a variable size region that is built by the lang build scripts. More info can be found in those scripts. + + It is aligned at the beginning of xflash, offset 0. + + ### 2. MMU Firmware update files (64KB, R) + This space is reserved for the two MMU firmware files: + - The MMU firmware v2.0.0+. + - The Bootloader self update file. + + It is aligned at the end of xflash, before xflash_dump + + ### 3. xflash_dump (12KB, RW) + The crash dump structure is defined as dump_t. + It composes of: + - A header with some information such as crash reason and what info was dumped. + - The dump itself. This is composed of the entire memory space from address 0 to the end of SRAM. So it includes also the registers (useless), the IO and extended IO (useful) and all RAM. + + Even though the dump needs around 9KB of storage, 12KB is used because of the sector erase size. + + It is aligned at the end of xflash. +*/ + + // XFLASH memory layout #pragma once #include From c09b73252244b93188a518d4df9a2a8782dcc65d Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Mon, 17 Jan 2022 12:03:12 +0100 Subject: [PATCH 2/3] Reserve xflash space for the mmu update files --- Firmware/xflash_layout.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Firmware/xflash_layout.h b/Firmware/xflash_layout.h index 305846298..1e4a620c2 100644 --- a/Firmware/xflash_layout.h +++ b/Firmware/xflash_layout.h @@ -52,10 +52,14 @@ #include "config.h" #define XFLASH_SIZE 0x40000ul // size of XFLASH -#define LANG_OFFSET 0x0 // offset for language data #ifndef XFLASH_DUMP -#define LANG_SIZE XFLASH_SIZE +#define MMU_BOOTLOADER_UPDATE_OFFSET (XFLASH_SIZE - 32768) // 32KB of MMU bootloader self update. +#define MMU_FW_UPDATE_OFFSET (MMU_BOOTLOADER_UPDATE_OFFSET - 32768) // 32KB of MMU fw. +#define LANG_OFFSET 0x0 // offset for language data + +#define LANG_SIZE (MMU_FW_UPDATE_OFFSET - LANG_OFFSET) // available language space + #else #define DUMP_MAGIC 0x55525547ul @@ -89,10 +93,12 @@ struct dump_t struct dump_data_t __attribute__((aligned(256))) data; }; -// dump offset must be aligned to lower 4kb sector boundary -#define DUMP_OFFSET ((XFLASH_SIZE - sizeof(dump_t)) & ~0xFFFul) +#define DUMP_OFFSET ((XFLASH_SIZE - sizeof(dump_t)) & ~0xFFFul) // dump offset must be aligned to lower 4kb sector boundary +#define MMU_BOOTLOADER_UPDATE_OFFSET (DUMP_OFFSET - 32768) // 32KB of MMU bootloader self update. +#define MMU_FW_UPDATE_OFFSET (MMU_BOOTLOADER_UPDATE_OFFSET - 32768) // 32KB of MMU fw. +#define LANG_OFFSET 0x0 // offset for language data -#define DUMP_SIZE (XFLASH_SIZE - DUMP_OFFSET) // effective dump size area -#define LANG_SIZE DUMP_OFFSET // available language space +#define LANG_SIZE (MMU_FW_UPDATE_OFFSET - LANG_OFFSET) // available language space +#define DUMP_SIZE (XFLASH_SIZE - DUMP_OFFSET) // effective dump size area #endif From 52b464688f6d8ec714b4850bf9ec53711c6fbc8a Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Thu, 17 Feb 2022 09:34:09 +0100 Subject: [PATCH 3/3] Make layout static regardless of what is enabled --- Firmware/xflash_layout.h | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/Firmware/xflash_layout.h b/Firmware/xflash_layout.h index 1e4a620c2..48d947f69 100644 --- a/Firmware/xflash_layout.h +++ b/Firmware/xflash_layout.h @@ -53,15 +53,6 @@ #define XFLASH_SIZE 0x40000ul // size of XFLASH -#ifndef XFLASH_DUMP -#define MMU_BOOTLOADER_UPDATE_OFFSET (XFLASH_SIZE - 32768) // 32KB of MMU bootloader self update. -#define MMU_FW_UPDATE_OFFSET (MMU_BOOTLOADER_UPDATE_OFFSET - 32768) // 32KB of MMU fw. -#define LANG_OFFSET 0x0 // offset for language data - -#define LANG_SIZE (MMU_FW_UPDATE_OFFSET - LANG_OFFSET) // available language space - -#else - #define DUMP_MAGIC 0x55525547ul struct dump_header_t @@ -100,5 +91,3 @@ struct dump_t #define LANG_SIZE (MMU_FW_UPDATE_OFFSET - LANG_OFFSET) // available language space #define DUMP_SIZE (XFLASH_SIZE - DUMP_OFFSET) // effective dump size area - -#endif