From c089b6df4c32c3075266d754ae5a63239e7fcde8 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Fri, 15 Jul 2022 05:44:51 +0100 Subject: [PATCH] Allow user row to be repaired on previous flash failure (#78) --- .github/workflows/build.yml | 2 +- mdloader_common.c | 20 ++++++++++++++++---- mdloader_common.h | 4 ---- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 25880bf..fcfd956 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: - os: [macos-latest, windows-2016, ubuntu-latest] + os: [macos-latest, windows-2019, ubuntu-latest] steps: - uses: actions/checkout@v2 diff --git a/mdloader_common.c b/mdloader_common.c index a60d7f9..2ce3087 100644 --- a/mdloader_common.c +++ b/mdloader_common.c @@ -25,6 +25,10 @@ INCBIN(applet, "applet-mdflash.bin"); #include "mdloader_common.h" #include "mdloader_parser.h" +#define SMARTEEPROM_CONFIG 0xaeecffb1 +#define USER_ROW_INVALID 0xFFFFFFFF +#define USER_ROW_REPAIR 0xfe9a9239 + char verbose; char testmode; char first_device; @@ -479,13 +483,14 @@ uint8_t configure_smarteeprom(void) for (int i = 0; i < 4; i++) { user_row[i] = read_word(NVMCTRL_USER + i * 4); + if (verbose) printf("SmartEEPROM: config - NVMCTRL_USER: 0x%u - 0x%08x.\n", i, user_row[i]); } NVMCTRL_USER_ROW_MAPPING1_Type* puser_row1 = (NVMCTRL_USER_ROW_MAPPING1_Type*)(&user_row[1]); if (verbose) printf("SmartEEPROM: config - SBLK: 0x%04x - PSZ: 0x%03x.\n", puser_row1->bit.SBLK, puser_row1->bit.PSZ); - if(puser_row1->bit.SBLK == SMARTEEPROM_TARGET_SBLK && puser_row1->bit.PSZ == SMARTEEPROM_TARGET_PSZ) + if ((puser_row1->reg == SMARTEEPROM_CONFIG) && (user_row[0] != USER_ROW_INVALID)) { if (verbose) printf("SmartEEPROM: Configured!\n"); return 1; @@ -493,13 +498,20 @@ uint8_t configure_smarteeprom(void) if(ignore_smarteeprom_config) { - printf("SmartEEPROM: Your settings do not match the recommended values - Some functionality may not work as expected!"); + printf("SmartEEPROM: Your settings do not match the recommended values - Some functionality may not work as expected!\n"); return 1; } // Set SmartEEPROM Virtual Size. - puser_row1->bit.SBLK = SMARTEEPROM_TARGET_SBLK; - puser_row1->bit.PSZ = SMARTEEPROM_TARGET_PSZ; + puser_row1->reg = SMARTEEPROM_CONFIG; + + // Repair if we have a previous failure + if(user_row[0] == USER_ROW_INVALID) + { + printf("SmartEEPROM: Setting additional user row.\n"); + user_row[0] = USER_ROW_REPAIR; + } + return write_user_row(user_row); } diff --git a/mdloader_common.h b/mdloader_common.h index 5025eef..0df8a06 100644 --- a/mdloader_common.h +++ b/mdloader_common.h @@ -204,10 +204,6 @@ void strlower(char *str); #define SLEEP_BETWEEN_WRITES 200 -// Configured for 4096 bytes - DS60001507E-page 653 -#define SMARTEEPROM_TARGET_SBLK 1 // 1 block -#define SMARTEEPROM_TARGET_PSZ 3 // 32 bytes - typedef union { struct { uint32_t SBLK : 4; /* bit: 35:32 - Number of NVM Blocks composing a SmartEEPROM sector */