This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 278a0c46d7f907cac13550e86c6a094950477bc8 Author: Daniel P. Carvalho <[email protected]> AuthorDate: Sun Oct 18 16:15:22 2026 -0300 boards/ev49n51a: support the program flash storage. Check in the linker script that the program image stays below the pages of PIC32MZ_PROGMEM (the symbol is defined by the build when the option is enabled, and is the end of the flash otherwise), and register the pages as /dev/mtdblock1 when MTD_PROGMEM is enabled. Tested on an EV49N51A with PIC32MZ_PROGMEM and MTD_PROGMEM: the image ends at 0x9009ab1c and the pages start at 0x900fe000; dd writes and reads of /dev/mtdblock1 return the data, also after a reset. Assisted-by: Claude Code:claude-sonnet-5-5 Signed-off-by: Daniel P. Carvalho <[email protected]> --- boards/mips/pic32mz/ev49n51a/scripts/mips-debug.ld | 10 +++++++++ boards/mips/pic32mz/ev49n51a/src/ev49n51a.h | 6 ++++++ boards/mips/pic32mz/ev49n51a/src/pic32mz_bringup.c | 25 +++++++++++++++++++++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/boards/mips/pic32mz/ev49n51a/scripts/mips-debug.ld b/boards/mips/pic32mz/ev49n51a/scripts/mips-debug.ld index 12e2f495c4e..345a3790d18 100644 --- a/boards/mips/pic32mz/ev49n51a/scripts/mips-debug.ld +++ b/boards/mips/pic32mz/ev49n51a/scripts/mips-debug.ld @@ -240,6 +240,16 @@ SECTIONS _edata = ABSOLUTE(.); } >kseg0_datamem AT>kseg0_progmem + /* End of the program image in the program flash. The last pages of the + * flash belong to PIC32MZ_PROGMEM when it is enabled (the symbol is + * then defined by the build, at the start of the pages). + */ + + _eimage = LOADADDR(.lit4) + SIZEOF(.lit4); + PROVIDE(PIC32MZ_PROGMEM_START = ORIGIN(kseg0_progmem) + LENGTH(kseg0_progmem)); + ASSERT(_eimage <= PIC32MZ_PROGMEM_START, + "The program image overlaps the PIC32MZ_PROGMEM pages") + .sbss : { . = ALIGN(16); diff --git a/boards/mips/pic32mz/ev49n51a/src/ev49n51a.h b/boards/mips/pic32mz/ev49n51a/src/ev49n51a.h index 23f28b93aae..93075a9b597 100644 --- a/boards/mips/pic32mz/ev49n51a/src/ev49n51a.h +++ b/boards/mips/pic32mz/ev49n51a/src/ev49n51a.h @@ -69,6 +69,12 @@ #define SST26_MTD_MINOR 0 +/* The program flash pages of PIC32MZ_PROGMEM are exported as + * /dev/mtdblock<PROGMEM_MTD_MINOR> + */ + +#define PROGMEM_MTD_MINOR 1 + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/boards/mips/pic32mz/ev49n51a/src/pic32mz_bringup.c b/boards/mips/pic32mz/ev49n51a/src/pic32mz_bringup.c index 1987ff66670..c7520a3ebba 100644 --- a/boards/mips/pic32mz/ev49n51a/src/pic32mz_bringup.c +++ b/boards/mips/pic32mz/ev49n51a/src/pic32mz_bringup.c @@ -31,8 +31,11 @@ #include <nuttx/fs/fs.h> -#ifdef CONFIG_MTD_SST26 +#if defined(CONFIG_MTD_SST26) || defined(CONFIG_MTD_PROGMEM) # include <nuttx/mtd/mtd.h> +#endif + +#ifdef CONFIG_MTD_SST26 # include "pic32mz_spi.h" #endif @@ -112,6 +115,26 @@ int pic32mz_bringup(void) } #endif +#ifdef CONFIG_MTD_PROGMEM + struct mtd_dev_s *progmem; + + /* Pages at the end of the program flash, reserved by PIC32MZ_PROGMEM */ + + progmem = progmem_initialize(); + if (progmem == NULL) + { + syslog(LOG_ERR, "ERROR: Failed to initialize the program flash MTD\n"); + } + else + { + ret = ftl_initialize(PROGMEM_MTD_MINOR, progmem); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: ftl_initialize() failed: %d\n", ret); + } + } +#endif + UNUSED(ret); #ifdef CONFIG_PIC32MZ_W1_WLAN ret = pic32mz_wlan_initialize();
