skycoin / services

Incubator repo for various services
16 stars 25 forks source link

[Hardware-wallet]: flash memory lock #108

Closed mpsido closed 6 years ago

mpsido commented 6 years ago

The hardware devices displays a "Storage failure detected" message when the device is plugged in.

Using debugger it appeared svc_flash_lock() returns a status where FLASH_SR_PGPERR flag is raised.

git log HEAD at the time the error was noticed: dedf49c15b53305e63aafaea21b065f2f44a1815

mpsido commented 6 years ago

gdb backtrace:

0 storage_show_error () at firmware/storage.c:115

1 0x0801531c in storage_check_flash_errors (status=) at firmware/storage.c:123

2 storage_wipe () at firmware/storage.c:743

3 0x080153a0 in storage_init () at firmware/storage.c:226

4 0x080140ca in main () at firmware/trezor.c:120

mpsido commented 6 years ago

Quote from the datasheet of the microcontroller: https://www.st.com/content/ccc/resource/technical/document/programming_manual/f7/7e/b9/a8/31/58/41/7b/CD00233952.pdf/files/CD00233952.pdf/jcr:content/translations/en.CD00233952.pdf

"The write access type (byte, half-word, word or double word) must correspond to the type of parallelism chosen (x8, x16, x32 or x64). If no t, the write operation is not performed and a program parallelism error flag (PGPERR) is set in the FLASH_SR register."

rngadam commented 6 years ago

where is

configured?

rngadam commented 6 years ago

can you explain these diffs from git diff 88c1b0d699076ce15f8cf7b27c50d4bbc0346f76 firmware/storage.c?


        // fill remainder with zero for future extensions
        while (flash < FLASH_STORAGE_PINAREA) {
-               flash_program_word(flash, 0);
+               flash_write32(flash, 0);
                flash += sizeof(uint32_t);
        }

and

 static uint32_t storage_flash_words(uint32_t addr, const uint32_t *src, int nwords) {
        for (int i = 0; i < nwords; i++) {
-               flash_program_word(addr, *src++);
+               flash_write32(addr, *src++);
                addr += sizeof(uint32_t);
        }
        return addr;
mpsido commented 6 years ago

solved