Skip to content

Commit

Permalink
Allow user row to be repaired on previous flash failure (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
zvecr authored Jul 15, 2022
1 parent e4f9774 commit c089b6d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 16 additions & 4 deletions mdloader_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -479,27 +483,35 @@ 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;
}

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);
}

Expand Down
4 changes: 0 additions & 4 deletions mdloader_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit c089b6d

Please sign in to comment.