Skip to content

Commit 0c1c3ba

Browse files
committed
Working wolfBoot test-app startup!
1 parent e142332 commit 0c1c3ba

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

hal/nxp_t2080.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,16 @@ int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
10061006
* in command mode (e.g. after a timeout or incomplete operation) */
10071007
FLASH_IO8_WRITE(0, 0, AMD_CMD_RESET);
10081008
ram_udelay(50);
1009-
ram_putchar('r'); /* checkpoint: reset done, starting loop */
1009+
ram_putchar('r'); /* checkpoint: reset done */
1010+
1011+
/* Diagnostic: read erased data before write to verify both chips respond.
1012+
* Expected 0xFFFF after erase. If high byte != 0xFF, chip may be dead. */
1013+
{
1014+
uint16_t erased = FLASH_IO16_READ(address / FLASH_SECTOR_SIZE, 0);
1015+
ram_putchar('{');
1016+
ram_puthex16(erased);
1017+
ram_putchar('}');
1018+
}
10101019

10111020
pos = 0;
10121021
while (len > 0) {
@@ -1058,13 +1067,27 @@ int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
10581067
}
10591068
if (ret != 0) {
10601069
uint16_t readback;
1061-
/* Reset flash to read-array mode BEFORE reading back data */
1070+
/* Write-to-Buffer-Abort-Reset: plain AMD_CMD_RESET (0xF0) is
1071+
* IGNORED during an active WBP or WBP-abort state. Must use
1072+
* the unlock + reset sequence per S29GL01GS datasheet. */
1073+
hal_flash_unlock_sector(sector);
10621074
FLASH_IO8_WRITE(sector, 0, AMD_CMD_RESET);
10631075
ram_udelay(50);
10641076
/* Read back offset 0 to see if data was actually written */
10651077
readback = FLASH_IO16_READ(sector, 0);
10661078
ram_putchar('=');
10671079
ram_puthex16(readback);
1080+
/* Verify flash exited command mode (second read should match) */
1081+
{
1082+
uint16_t verify = FLASH_IO16_READ(sector, 0);
1083+
if (readback != verify) {
1084+
ram_putchar('!'); /* still in command mode */
1085+
/* Try one more reset */
1086+
hal_flash_unlock_sector(sector);
1087+
FLASH_IO8_WRITE(sector, 0, AMD_CMD_RESET);
1088+
ram_udelay(50);
1089+
}
1090+
}
10681091
wolfBoot_printf("\nFlash Write: %s at sector %d (ret %d)\n",
10691092
ret == -2 ? "DQ5 error" : "Timeout", sector, ret);
10701093
break;

0 commit comments

Comments
 (0)