Page 1 of 1

[nRF52] pca10059 Flash FS not available - MBFS as well as VFS/LFS

Posted: Fri Nov 06, 2020 9:43 am
by Angainor

Encountering a weird issue I can't troubleshoot after days of attempts and much reading.
Tried with many firmware versions. I have no issue building, flashing and getting various MicroPython running on my dongle, but no file system is available ever.

I'm using a Minew C2 dongle, which is the same hardware as pca10059, nRF52840, just in a nice case.
The dongle comes flashed with Nordic default bootloader, can be programmed with nRF Connect.

Detailling this since this may be part of the issue, I don't want to use a JTAG, ST-link aso to program the dongle.
I need a regular user to be able to flash a stock dongle with only nRF Connect USB SDFU, no hardware.
This bootloader is signed, there is no way to update the bootloader (0x000E0000 - 0x000FDFFF) without hardware.

Programming workflow:
- build micropython with SD=s140
- use nRF Connect programmer, drop soft device hex (MBR+SD 0x00001000 - 0x00025DE7) and firmware.hex (0x00026000 - )
- Write

MicroPython boots up, REPL works fine except flash fs.

1 - Default firmware, current 1.13 with default MBFS:
No error, I can open with 'w' and write a file (returns number of bytes written)
but nothing is written, listdir() remains empty, file can't be read back.

2 - Firmware with LFS support, built from this PR

file = open("test.txt", "w")
OSError: 1

uos has VfsLfs2, nrf has flashbdev
flashbdev reports the 64K FS I config'd
nrf.flashbdev.ioctl(4, 0)
nrf.flashbdev.ioctl(5, 0)

but trying to mkfs fails
OSError: 28

other ioctl calls (init device, sync, erase a block) return 0

3 - Firmware build from a LFS enabled fork: WaspOs, targetting nrf watches (tested myself, working on several watches 52x)
Same as 2

What am I missing?

After many tests, only difference I can see with working setup is the uploading process, that does not fully erase the flash beforehand.
May that be the cause?
Is there another way to have the flash FS available, like uploading the FS as .hex as well?

Re: [nRF52] pca10059 Flash FS not available - MBFS as well as VFS/LFS

Posted: Sun Nov 15, 2020 8:09 pm
by c45713
Hi Angainor,

I'm picking up the work again on and will test the pca10059 explicitly.

Could you try to set the available flash size in ports/nrf/nrf52840_1M_256K.ld from 1M to 800K. Just to see if there is anything about the bootloader that might corrupt things?

Could you also try to compile it with LTO=0, i guess it would not work differently, but i would be interested in the .map file from that compilation.

Re: [nRF52] pca10059 Flash FS not available - MBFS as well as VFS/LFS

Posted: Mon Nov 16, 2020 9:28 am
by Angainor

Would need to try again from a clean state to make extra sure, but looks like you nailed it!

LFS working on first run with 800K instead of 1M.
(Default LTO)

I previously checked the open bootloader code, that is flash protecting MBR as well as Bootloader zones, but I surely missed something. ... ect-readme
From bootloader, main.c:

Code: Select all

    // Protect MBR and bootloader code from being overwritten.
    ret_val = nrf_bootloader_flash_protect(0, MBR_SIZE, false);
    ret_val = nrf_bootloader_flash_protect(BOOTLOADER_START_ADDR, BOOTLOADER_SIZE, false);
I'm attaching the map for compilation with LTO=0, LFS branch, 64K fs_size

Thanks a lot!!!

Will now check if this solves as well for MBFS
Edit: MBFS working with 800K flash max.

Re: [nRF52] pca10059 Flash FS not available - MBFS as well as VFS/LFS

Posted: Wed Nov 18, 2020 8:01 pm
by c45713
Great to hear that something is working :)

I did not look at the .map file yet as it seems to work for you.

If you want to, you can try this PR:

This will provide the framework to shrink the available flash for micropython due to presence of a bootloader in the tail (and the head in case you also run SoftDevice with an MBR you want to keep). Internal flash file system will then be in front of this Bootloader region, not overlapping with it. It looks like the addresses you list, 0x000E0000 - 0x000FDFFF, match the nrf52840_open_bootloader_1.2.x.ld.

You will have to update your board's in the same way as for the nrf52840-mdk-usb-dongle: ... 411815dbf7