@@ -35,6 +35,24 @@ uint32_t ext_cache;
3535#define PART_BOOT_ENDFLAGS ((WOLFBOOT_PARTITION_BOOT_ADDRESS + WOLFBOOT_PARTITION_SIZE) - TRAILER_SKIP)
3636#define PART_UPDATE_ENDFLAGS ((WOLFBOOT_PARTITION_UPDATE_ADDRESS + WOLFBOOT_PARTITION_SIZE) - TRAILER_SKIP)
3737
38+ #ifdef NVM_FLASH_WRITEONCE
39+ static uint8_t NVM_CACHE [WOLFBOOT_SECTOR_SIZE ];
40+ int hal_trailer_write (uint32_t addr , uint8_t val ) {
41+ uint32_t addr_align = addr & (~(WOLFBOOT_SECTOR_SIZE - 1 ));
42+ uint32_t addr_off = addr & (WOLFBOOT_SECTOR_SIZE - 1 );
43+ int ret = 0 ;
44+ memcpy (NVM_CACHE , (void * )addr_align , WOLFBOOT_SECTOR_SIZE );
45+ ret = hal_flash_erase (addr_align , WOLFBOOT_SECTOR_SIZE );
46+ if (ret != 0 )
47+ return ret ;
48+ NVM_CACHE [addr_off ] = val ;
49+ ret = hal_flash_write (addr_align , NVM_CACHE , WOLFBOOT_SECTOR_SIZE );
50+ return ret ;
51+ }
52+ #else
53+ # define hal_trailer_write (addr , val ) hal_flash_write(addr, (void *)&val, 1)
54+ #endif
55+
3856#if defined PART_UPDATE_EXT
3957static uint8_t * get_trailer_at (uint8_t part , uint32_t at )
4058{
@@ -50,7 +68,7 @@ static uint8_t *get_trailer_at(uint8_t part, uint32_t at)
5068static void set_trailer_at (uint8_t part , uint32_t at , uint8_t val )
5169{
5270 if (part == PART_BOOT ) {
53- hal_flash_write (PART_BOOT_ENDFLAGS - (sizeof (uint32_t ) + at ), ( void * ) & val , 1 );
71+ hal_trailer_write (PART_BOOT_ENDFLAGS - (sizeof (uint32_t ) + at ), val );
5472 }
5573 else if (part == PART_UPDATE ) {
5674 ext_flash_write (PART_UPDATE_ENDFLAGS - (sizeof (uint32_t ) + at ), (void * )& val , 1 );
@@ -82,10 +100,10 @@ static uint8_t *get_trailer_at(uint8_t part, uint32_t at)
82100static void set_trailer_at (uint8_t part , uint32_t at , uint8_t val )
83101{
84102 if (part == PART_BOOT ) {
85- hal_flash_write (PART_BOOT_ENDFLAGS - (sizeof (uint32_t ) + at ), ( void * ) & val , 1 );
103+ hal_trailer_write (PART_BOOT_ENDFLAGS - (sizeof (uint32_t ) + at ), val );
86104 }
87105 else if (part == PART_UPDATE ) {
88- hal_flash_write (PART_UPDATE_ENDFLAGS - (sizeof (uint32_t ) + at ), ( void * ) & val , 1 );
106+ hal_trailer_write (PART_UPDATE_ENDFLAGS - (sizeof (uint32_t ) + at ), val );
89107 }
90108}
91109
0 commit comments