Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[RFC] NuttX use littlefs for F-RAM parameter storage #18958

Closed
wants to merge 1 commit into from

Conversation

dagar
Copy link
Member

@dagar dagar commented Jan 5, 2022

  • currently for parameter storage on F-RAM (aka ramtron) we export parameters as bson saved to a character device ramtron partition
  • the file is overwritten in place and there's no checksum
  • littlefs is a fail-safe filesystem designed to handle random power failures
    • all file operations have strong copy-on-write guarantees and if power is lost the filesystem will fall back to the last known good state
nsh> df -h
  Filesystem    Size      Used  Available Mounted on
  binfs           0B        0B         0B /bin
  cromfs        280K      280K         0B /etc
  vfat         7388M      800K      7387M /fs/microsd
  littlefs       32K        2K        30K /fs/mtd_params
  procfs          0B        0B         0B /proc


nsh> param dump
[param] reading from /fs/mtd_params/parameters.bson

BSON document size 814
BSON_INT32:  CAL_ACC0_ID = 2424858
BSON_INT32:  CAL_ACC0_PRIO = 50
BSON_DOUBLE: CAL_ACC0_TEMP = 45.680267
BSON_DOUBLE: CAL_ACC0_XOFF = -0.025817
BSON_DOUBLE: CAL_ACC0_YOFF = 0.005446
BSON_DOUBLE: CAL_ACC0_ZOFF = -0.433016
BSON_INT32:  CAL_ACC1_ID = 2490386
BSON_INT32:  CAL_ACC1_PRIO = 50
BSON_DOUBLE: CAL_ACC1_TEMP = 41.005436
BSON_DOUBLE: CAL_ACC1_XOFF = -0.203097
BSON_DOUBLE: CAL_ACC1_YOFF = 0.076597
BSON_DOUBLE: CAL_ACC1_ZOFF = -0.179166
BSON_INT32:  CAL_ACC2_ID = 3670026
BSON_INT32:  CAL_ACC2_PRIO = 50
BSON_DOUBLE: CAL_ACC2_TEMP = 45.096695
BSON_DOUBLE: CAL_ACC2_XOFF = -0.003840
BSON_DOUBLE: CAL_ACC2_YOFF = 0.106350
BSON_DOUBLE: CAL_ACC2_ZOFF = -0.199815
BSON_INT32:  CAL_GYRO0_ID = 2424858
BSON_INT32:  CAL_GYRO0_PRIO = 50
BSON_DOUBLE: CAL_GYRO0_TEMP = 45.850945
BSON_DOUBLE: CAL_GYRO0_XOFF = -0.010202
BSON_DOUBLE: CAL_GYRO0_YOFF = 0.014070
BSON_DOUBLE: CAL_GYRO0_ZOFF = -0.011514
BSON_INT32:  CAL_GYRO1_ID = 2490386
BSON_INT32:  CAL_GYRO1_PRIO = 50
BSON_DOUBLE: CAL_GYRO1_TEMP = 40.992916
BSON_DOUBLE: CAL_GYRO1_XOFF = -0.002029
BSON_DOUBLE: CAL_GYRO1_YOFF = 0.013790
BSON_DOUBLE: CAL_GYRO1_ZOFF = -0.000258
BSON_INT32:  CAL_GYRO2_ID = 3670026
BSON_INT32:  CAL_GYRO2_PRIO = 50
BSON_DOUBLE: CAL_GYRO2_TEMP = 45.104542
BSON_DOUBLE: CAL_GYRO2_XOFF = -0.010561
BSON_DOUBLE: CAL_GYRO2_YOFF = -0.018770
BSON_DOUBLE: CAL_GYRO2_ZOFF = -0.002687
BSON_DOUBLE: EKF2_MAG_DECL = -6.149145
BSON_EOO
BSON decoded 814 bytes (double:25, string:0, bin:0, bool:0, int32:12, int64:0)


nsh> ls -ls /fs/mtd_params
/fs/mtd_params:
 drwxrwxrwx       0 .
 drwxrwxrwx       0 ..
 -rwxrwxrwx     814 parameters.bson

nsh> cp /fs/mtd_params/parameters.bson /fs/mtd_params/parameters_backup.bson

nsh> ls -ls /fs/mtd_params
/fs/mtd_params:
 drwxrwxrwx134378631 .
 drwxrwxrwx       0 ..
 -rwxrwxrwx     814 parameters.bson
 -rwxrwxrwx     814 parameters_backup.bson

nsh> df -h
  Filesystem    Size      Used  Available Mounted on
  binfs           0B        0B         0B /bin
  cromfs        281K      281K         0B /etc
  vfat         7388M      800K      7387M /fs/microsd
  littlefs       32K        3K        29K /fs/mtd_params
  procfs          0B        0B         0B /proc

TODO:

  • how would we handle migration?
    • first try to import any valid data from ramtron as character device, then stop bch and instead mount as littlefs
    • explicitly format littlefs only after successful import
    • automatically try to mount littlefs (with no autoformat) first going forward
  • update parameter system to export to new file each time
    • auto delete previous exports as needed to free up space

@dagar dagar force-pushed the pr-nuttx_littlefs branch from ddffdab to 89b9701 Compare January 9, 2022 01:31
@dagar
Copy link
Member Author

dagar commented Jan 17, 2022

Once this is in place we can also start using this safe storage area for things like the UAVCAN database rather than have an SD card dependency.

@dagar
Copy link
Member Author

dagar commented Sep 20, 2023

Continuing in #21134.

@dagar dagar closed this Sep 20, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants