xflash_layout.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * @file
  3. * @author leptun
  4. */
  5. /** \ingroup xflash_layout */
  6. //! This is the layout of the XFLASH (external SPI flash) in Prusa firmware (dynamically generated from doxygen).
  7. /** @defgroup xflash_layout XFLASH Layout
  8. *
  9. ---------------------------------------------------------------------------------
  10. The XFLASH has the following alignment requirements:
  11. - 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.
  12. - Block erase of 32KB. Not used.
  13. - 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.
  14. - Page write of 256B. Lower access can be used, but care must be used since the address wraps at the page boundary when writing.
  15. - Read has no alignment requirements.
  16. The following items are found in the xflash:
  17. ### 1. Languages (R)
  18. This is a variable size region that is built by the lang build scripts. More info can be found in those scripts.
  19. It is aligned at the beginning of xflash, offset 0.
  20. ### 2. MMU Firmware update files (64KB, R)
  21. This space is reserved for the two MMU firmware files:
  22. - The MMU firmware v2.0.0+.
  23. - The Bootloader self update file.
  24. It is aligned at the end of xflash, before xflash_dump
  25. ### 3. xflash_dump (12KB, RW)
  26. The crash dump structure is defined as dump_t.
  27. It composes of:
  28. - A header with some information such as crash reason and what info was dumped.
  29. - 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.
  30. Even though the dump needs around 9KB of storage, 12KB is used because of the sector erase size.
  31. It is aligned at the end of xflash.
  32. */
  33. // XFLASH memory layout
  34. #pragma once
  35. #include <stdint.h>
  36. #include "bootapp.h" // for RAMSIZE
  37. #include "config.h"
  38. #define XFLASH_SIZE 0x40000ul // size of XFLASH
  39. #define LANG_OFFSET 0x0 // offset for language data
  40. #ifndef XFLASH_DUMP
  41. #define LANG_SIZE XFLASH_SIZE
  42. #else
  43. #define DUMP_MAGIC 0x55525547ul
  44. struct dump_header_t
  45. {
  46. // start with a magic value to indicate the presence of a dump, so that clearing
  47. // a single page is sufficient for resetting the state
  48. uint32_t magic;
  49. uint8_t regs_present; // true when the lower segment containing registers is present
  50. uint8_t crash_reason; // uses values from dump_crash_source
  51. uint32_t pc; // PC nearby the crash location
  52. uint16_t sp; // SP nearby the crash location
  53. };
  54. struct dump_data_t
  55. {
  56. // contiguous region containing all addressable ranges
  57. uint8_t regs[RAMSTART];
  58. uint8_t sram[RAMSIZE];
  59. };
  60. struct dump_t
  61. {
  62. struct dump_header_t header;
  63. // data is page aligned (no real space waste, due to the larger
  64. // alignment required for the whole dump)
  65. struct dump_data_t __attribute__((aligned(256))) data;
  66. };
  67. // dump offset must be aligned to lower 4kb sector boundary
  68. #define DUMP_OFFSET ((XFLASH_SIZE - sizeof(dump_t)) & ~0xFFFul)
  69. #define DUMP_SIZE (XFLASH_SIZE - DUMP_OFFSET) // effective dump size area
  70. #define LANG_SIZE DUMP_OFFSET // available language space
  71. #endif