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

Discussion and questions about boards that can run MicroPython but don't have a dedicated forum.
Target audience: Everyone interested in running MicroPython on other hardware.
Post Reply
User avatar
Angainor
Posts: 15
Joined: Thu Sep 24, 2020 9:14 am

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

Post by Angainor » Fri Nov 06, 2020 9:43 am

Hi,

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 https://github.com/micropython/micropython/pull/5472

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)
16
nrf.flashbdev.ioctl(5, 0)
4096

but trying to mkfs fails
uos.VfsLfs2.mkfs(nrf.flashbdev)
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)
https://github.com/daniel-thompson/wasp-os
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?

c45713
Posts: 51
Joined: Fri Dec 09, 2016 7:09 pm

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

Post by c45713 » Sun Nov 15, 2020 8:09 pm

Hi Angainor,

I'm picking up the work again on https://github.com/micropython/micropython/pull/5472 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.

User avatar
Angainor
Posts: 15
Joined: Thu Sep 24, 2020 9:14 am

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

Post by Angainor » Mon Nov 16, 2020 9:28 am

Hi,

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.
https://developer.nordicsemi.com/nRF_Co ... 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);
    APP_ERROR_CHECK(ret_val);
    ret_val = nrf_bootloader_flash_protect(BOOTLOADER_START_ADDR, BOOTLOADER_SIZE, false);
    APP_ERROR_CHECK(ret_val);
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.
Attachments
firmware_800K_LTO0.map.gz
(79.22 KiB) Downloaded 214 times

c45713
Posts: 51
Joined: Fri Dec 09, 2016 7:09 pm

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

Post by c45713 » Wed Nov 18, 2020 8:01 pm

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:
https://github.com/micropython/micropython/pull/6252

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 mpconfigboard.mk in the same way as for the nrf52840-mdk-usb-dongle:
https://github.com/micropython/micropyt ... 411815dbf7

Post Reply