Skip to content

Commit c089b6d

Browse files
authored
Allow user row to be repaired on previous flash failure (#78)
1 parent e4f9774 commit c089b6d

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616

1717
strategy:
1818
matrix:
19-
os: [macos-latest, windows-2016, ubuntu-latest]
19+
os: [macos-latest, windows-2019, ubuntu-latest]
2020

2121
steps:
2222
- uses: actions/checkout@v2

mdloader_common.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ INCBIN(applet, "applet-mdflash.bin");
2525
#include "mdloader_common.h"
2626
#include "mdloader_parser.h"
2727

28+
#define SMARTEEPROM_CONFIG 0xaeecffb1
29+
#define USER_ROW_INVALID 0xFFFFFFFF
30+
#define USER_ROW_REPAIR 0xfe9a9239
31+
2832
char verbose;
2933
char testmode;
3034
char first_device;
@@ -479,27 +483,35 @@ uint8_t configure_smarteeprom(void)
479483
for (int i = 0; i < 4; i++)
480484
{
481485
user_row[i] = read_word(NVMCTRL_USER + i * 4);
486+
if (verbose) printf("SmartEEPROM: config - NVMCTRL_USER: 0x%u - 0x%08x.\n", i, user_row[i]);
482487
}
483488

484489
NVMCTRL_USER_ROW_MAPPING1_Type* puser_row1 = (NVMCTRL_USER_ROW_MAPPING1_Type*)(&user_row[1]);
485490

486491
if (verbose) printf("SmartEEPROM: config - SBLK: 0x%04x - PSZ: 0x%03x.\n", puser_row1->bit.SBLK, puser_row1->bit.PSZ);
487492

488-
if(puser_row1->bit.SBLK == SMARTEEPROM_TARGET_SBLK && puser_row1->bit.PSZ == SMARTEEPROM_TARGET_PSZ)
493+
if ((puser_row1->reg == SMARTEEPROM_CONFIG) && (user_row[0] != USER_ROW_INVALID))
489494
{
490495
if (verbose) printf("SmartEEPROM: Configured!\n");
491496
return 1;
492497
}
493498

494499
if(ignore_smarteeprom_config)
495500
{
496-
printf("SmartEEPROM: Your settings do not match the recommended values - Some functionality may not work as expected!");
501+
printf("SmartEEPROM: Your settings do not match the recommended values - Some functionality may not work as expected!\n");
497502
return 1;
498503
}
499504

500505
// Set SmartEEPROM Virtual Size.
501-
puser_row1->bit.SBLK = SMARTEEPROM_TARGET_SBLK;
502-
puser_row1->bit.PSZ = SMARTEEPROM_TARGET_PSZ;
506+
puser_row1->reg = SMARTEEPROM_CONFIG;
507+
508+
// Repair if we have a previous failure
509+
if(user_row[0] == USER_ROW_INVALID)
510+
{
511+
printf("SmartEEPROM: Setting additional user row.\n");
512+
user_row[0] = USER_ROW_REPAIR;
513+
}
514+
503515
return write_user_row(user_row);
504516
}
505517

mdloader_common.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,6 @@ void strlower(char *str);
204204

205205
#define SLEEP_BETWEEN_WRITES 200
206206

207-
// Configured for 4096 bytes - DS60001507E-page 653
208-
#define SMARTEEPROM_TARGET_SBLK 1 // 1 block
209-
#define SMARTEEPROM_TARGET_PSZ 3 // 32 bytes
210-
211207
typedef union {
212208
struct {
213209
uint32_t SBLK : 4; /* bit: 35:32 - Number of NVM Blocks composing a SmartEEPROM sector */

0 commit comments

Comments
 (0)