Skip to content

Commit

Permalink
rename DBL_TAP_REG to TINYUF2_DBL_TAP_REG
Browse files Browse the repository at this point in the history
  • Loading branch information
hathach committed Jun 4, 2024
1 parent f0929f8 commit bb2d563
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 61 deletions.
2 changes: 1 addition & 1 deletion apps/erase_firmware/erase_firmware.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int main(void) {
printf("Erase Application Firmware\r\n");

// set magic then reset
DBL_TAP_REG = DBL_TAP_MAGIC_ERASE_APP;
TINYUF2_DBL_TAP_REG = DBL_TAP_MAGIC_ERASE_APP;

board_reset();

Expand Down
2 changes: 1 addition & 1 deletion ports/ch32v20x/boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

#include "board.h"

#define TINYUF2_DBL_TAP_DFU 0
#define TINYUF2_DBL_TAP_DFU 1

// symbol from linker
extern uint32_t __flash_size[];
Expand Down
2 changes: 1 addition & 1 deletion ports/espressif/boards/board_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void board_flash_read(uint32_t addr, void* buffer, uint32_t len) {
void board_flash_flush(void) {
if (_fl_addr == FLASH_CACHE_INVALID_ADDR) return;

TUF2_LOG1("Erase and Write at 0x%08X", _fl_addr);
TUF2_LOG1("Erase and Write at 0x%08lX", _fl_addr);

// Check if contents already matched
bool content_matches = true;
Expand Down
2 changes: 1 addition & 1 deletion ports/kinetis_k32l2/boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "fsl_rtc.h"

#define TINYUF2_DBL_TAP_DFU 1
#define DBL_TAP_REG RTC->TAR
#define TINYUF2_DBL_TAP_REG RTC->TAR
#define BOARD_FLASH_APP_START 0x8000
//#define BOARD_FLASH_SIZE (BOARD_FLASH_TOTAL - BOARD_FLASH_APP_START)

Expand Down
2 changes: 1 addition & 1 deletion ports/lpc55/boards.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ void board_init(void)
// Init 96 MHz clock
BOARD_BootClockFROHF96M();

// Init RTC for access to DBL_TAP_REG
// Init RTC for access to TINYUF2_DBL_TAP_REG
RTC_Init(RTC);

// disable systick
Expand Down
2 changes: 1 addition & 1 deletion ports/lpc55/boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#define BOARD_FLASH_APP_START 0x10000

#define TINYUF2_DBL_TAP_DFU 1
#define DBL_TAP_REG RTC->GPREG[7]
#define TINYUF2_DBL_TAP_REG RTC->GPREG[7]

#ifdef __cplusplus
}
Expand Down
4 changes: 3 additions & 1 deletion ports/mimxrt10xx/board_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void board_flash_flush(void)
_flash_page_addr = NO_CACHE;
}

void board_flash_write (uint32_t addr, void const *src, uint32_t len)
bool board_flash_write (uint32_t addr, void const *src, uint32_t len)
{
uint32_t const page_addr = addr & ~(SECTOR_SIZE - 1);

Expand All @@ -198,6 +198,8 @@ void board_flash_write (uint32_t addr, void const *src, uint32_t len)

// Overwrite part or all of the page cache with the src data.
memcpy(_flash_cache + (addr & (SECTOR_SIZE - 1)), src, len);

return true;
}

void board_flash_erase_app(void)
Expand Down
6 changes: 3 additions & 3 deletions ports/mimxrt10xx/boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ extern uint32_t _board_boot_length[];

// Double Reset tap to enter DFU
#define TINYUF2_DBL_TAP_DFU 1
#define DBL_TAP_REG SNVS->LPGPR[3]
#define TINYUF2_DBL_TAP_REG SNVS->LPGPR[3]

// Brightness percentage from 1 to 255
#ifndef NEOPIXEL_BRIGHTNESS
#define NEOPIXEL_BRIGHTNESS 0x10
#define NEOPIXEL_BRIGHTNESS 0x10
#endif

#ifdef LED_PIN
#define TINYUF2_LED 1
#define TINYUF2_LED 1
#endif

#ifdef __cplusplus
Expand Down
18 changes: 9 additions & 9 deletions ports/stm32h7/board_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,10 @@ void board_flash_read(uint32_t addr, void * data, uint32_t len)
}
}

void board_flash_write(uint32_t addr, void const * data, uint32_t len)
bool board_flash_write(uint32_t addr, void const * data, uint32_t len)
{
TUF2_LOG1("Programming %lu byte(s) at 0x%08lx\r\n", len, addr);

// For external flash, W25Qx
// TODO: these should be configurable parameters
// Page size = 256 bytes
Expand All @@ -163,7 +164,7 @@ void board_flash_write(uint32_t addr, void const * data, uint32_t len)
if (IS_SPI_ADDR(addr) && IS_SPI_ADDR(addr + len - 1))
{
W25Qx_Write((uint8_t *) data, (addr - SPI_BASE_ADDR), len);
return;
return true;
}
#endif

Expand All @@ -176,7 +177,7 @@ void board_flash_write(uint32_t addr, void const * data, uint32_t len)
{
__asm("bkpt #9");
}
return;
return true;
}
#endif

Expand All @@ -186,7 +187,7 @@ void board_flash_write(uint32_t addr, void const * data, uint32_t len)
// This memory is cached, DCache is cleaned in dfu_complete
SET_BOOT_ADDR(BOARD_AXISRAM_APP_ADDR);
memcpy((void *) addr, data, len);
return;
return true;
}
#endif // BOARD_AXISRAM_EN

Expand All @@ -198,13 +199,12 @@ void board_flash_write(uint32_t addr, void const * data, uint32_t len)
{
// TODO: Implement this
// SET_BOOT_ADDR(BOARD_PFLASH_APP_ADDR);
return;
return false;
}

{
// Invalid address write
__asm("bkpt #4");
}
// Invalid address write
__asm("bkpt #4");
return false;
}

void board_flash_erase_app(void)
Expand Down
52 changes: 26 additions & 26 deletions ports/test_ghostfat/boards.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,46 +27,46 @@
uint32_t board_flash_size(void) { return CFG_UF2_FLASH_SIZE; }

// not supported
void board_flash_write(uint32_t addr, void const *data, uint32_t len) {
(void)addr;
(void)data;
(void)len;
bool board_flash_write(uint32_t addr, void const* data, uint32_t len) {
(void) addr;
(void) data;
(void) len;
return true;
}

// not supported
void board_self_update(const uint8_t * bootloader_bin, uint32_t bootloader_len) {
(void)bootloader_bin;
(void)bootloader_len;
void board_self_update(const uint8_t* bootloader_bin, uint32_t bootloader_len) {
(void) bootloader_bin;
(void) bootloader_len;
}

// not supported
void board_flash_flush(void) {}
void board_flash_flush(void) {}

// not supported
bool board_flash_protect_bootloader(bool protect)
{
bool board_flash_protect_bootloader(bool protect) {
(void) protect;
return false;
}

//------------- Interesting part of flash support for this test -------------//
void board_flash_read (uint32_t addr, void* buffer, uint32_t len) {
if ((addr & 7) != 0) {
// TODO - need to copy part of the first eight bytes
exit(1); // failure exit
addr += 8 - (addr & 7);
}
void board_flash_read(uint32_t addr, void* buffer, uint32_t len) {
if ((addr & 7) != 0) {
// TODO - need to copy part of the first eight bytes
exit(1); // failure exit
addr += 8 - (addr & 7);
}

// EMBED address in each 32 bits of the FLASH
uint32_t * dest = buffer;
size_t incBytes = sizeof(*dest);
uint32_t currentAddress = addr;
// EMBED address in each 32 bits of the FLASH
uint32_t* dest = buffer;
size_t incBytes = sizeof(*dest);
uint32_t currentAddress = addr;

while (len >= incBytes) {
memcpy(dest, &currentAddress, incBytes); // unaligned memory possible
while (len >= incBytes) {
memcpy(dest, &currentAddress, incBytes); // unaligned memory possible

len -= incBytes;
dest++;
currentAddress += incBytes;
}
len -= incBytes;
dest++;
currentAddress += incBytes;
}
}
13 changes: 6 additions & 7 deletions src/board_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@
#define TINYUF2_DBL_TAP_DELAY 500
#endif

#ifndef TINYUF2_DBL_TAP_REG
// defined by linker script
extern uint32_t _board_dfu_dbl_tap[];
#define TINYUF2_DBL_TAP_REG _board_dfu_dbl_tap[0]
#endif

// Use Display to draw DFU image
#ifndef TINYUF2_DISPLAY
#define TINYUF2_DISPLAY 0
Expand Down Expand Up @@ -91,13 +97,6 @@
#define DBL_TAP_MAGIC_QUICK_BOOT 0xf02669ef // Skip double tap delay detection
#define DBL_TAP_MAGIC_ERASE_APP 0xf5e80ab4 // Erase entire application !!

#ifndef DBL_TAP_REG
// defined by linker script
extern uint32_t _board_dfu_dbl_tap[];
#define DBL_TAP_REG _board_dfu_dbl_tap[0]
#endif


//--------------------------------------------------------------------+
// Basic API
//--------------------------------------------------------------------+
Expand Down
18 changes: 9 additions & 9 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ static bool check_dfu_mode(void) {
if (board_app_valid2 && !board_app_valid2()) return true;

#if TINYUF2_DBL_TAP_DFU
// TUF2_LOG1_HEX(&DBL_TAP_REG);
TUF2_LOG1_HEX(&TINYUF2_DBL_TAP_REG);

// Erase application
if (DBL_TAP_REG == DBL_TAP_MAGIC_ERASE_APP) {
DBL_TAP_REG = 0;
if (TINYUF2_DBL_TAP_REG == DBL_TAP_MAGIC_ERASE_APP) {
TINYUF2_DBL_TAP_REG = 0;

indicator_set(STATE_WRITING_STARTED);
board_flash_erase_app();
Expand All @@ -111,20 +111,20 @@ static bool check_dfu_mode(void) {
}

// App want to reboot quickly
if (DBL_TAP_REG == DBL_TAP_MAGIC_QUICK_BOOT) {
DBL_TAP_REG = 0;
if (TINYUF2_DBL_TAP_REG == DBL_TAP_MAGIC_QUICK_BOOT) {
TINYUF2_DBL_TAP_REG = 0;
return false;
}

if (DBL_TAP_REG == DBL_TAP_MAGIC) {
if (TINYUF2_DBL_TAP_REG == DBL_TAP_MAGIC) {
// Double tap occurred
DBL_TAP_REG = 0;
TINYUF2_DBL_TAP_REG = 0;
TU_LOG1("Double Tap Reset\r\n");
return true;
}

// Register our first reset for double reset detection
DBL_TAP_REG = DBL_TAP_MAGIC;
TINYUF2_DBL_TAP_REG = DBL_TAP_MAGIC;

_timer_count = 0;
board_timer_start(1);
Expand All @@ -144,7 +144,7 @@ static bool check_dfu_mode(void) {
board_rgb_write(RGB_OFF);
board_led_write(0x00);

DBL_TAP_REG = 0;
TINYUF2_DBL_TAP_REG = 0;
#endif

return false;
Expand Down

0 comments on commit bb2d563

Please sign in to comment.