feat(boards_v6s): add NOR flash

This commit is contained in:
alexcekay authored and Alexander Lerach committed 2026-06-25 16:20:19 +02:00
1 parent 4065b05930
commit c92a7e2bd2
4 files changed
+202 -57

No files matched your search

@@ -96,7 +96,6 @@ CONFIG_FS_CROMFS=y
CONFIG_FS_FAT=y
CONFIG_FS_FATTIME=y
CONFIG_FS_LITTLEFS=y
CONFIG_FS_LITTLEFS_BLOCK_CYCLE=-1
CONFIG_FS_LITTLEFS_BLOCK_SIZE_FACTOR=4
CONFIG_FS_LITTLEFS_LOOKAHEAD_SIZE=64
CONFIG_FS_LITTLEFS_PROGRAM_SIZE_FACTOR=1
@@ -128,6 +127,8 @@ CONFIG_MEMSET_OPTSPEED=y
CONFIG_MM_REGIONS=4
CONFIG_MTD=y
CONFIG_MTD_BYTE_WRITE=y
CONFIG_MTD_MX25L=y
CONFIG_MX25L_SPIFREQUENCY=86000000
CONFIG_MTD_PARTITION=y
CONFIG_MTD_PROGMEM=y
CONFIG_MTD_RAMTRON=y
+8 -2
View File
@@ -202,8 +202,14 @@ extern void stm32_spiinitialize(void);
extern void board_peripheral_reset(int ms);
/* Initialise the FRAM MTD. */
extern void board_configure_fram(void);
/* Sets EEPROM manifest based on chip size. */
extern void board_set_eeprom_manifest(bool small_eeprom);
/* Initialise the FRAM MTD and update the manifest. Returns OK on success. */
extern int board_configure_fram(void);
/* Initialise the NOR flash MTD and update the manifest. Returns OK on success. */
extern int board_configure_nor(void);
#include <px4_platform_common/board_common.h>
+69 -31
View File
@@ -87,6 +87,9 @@
/* Configuration ************************************************************/
/* Minimum HW revision (lower rev byte) indicating NOR FLASH being used. */
#define BOARD_HW_REV_NOR 0x0018
/*
* Ideally we'd be able to get these from arm_internal.h,
* but since we want to be able to disable the NuttX use
@@ -199,37 +202,38 @@ static bool eeprom_read_and_check_mft(struct i2c_master_s *i2c, uint16_t address
}
/****************************************************************************
* Name: detect_layout_is_fram
* Name: detect_eeprom_is_small
*
* Description:
* Determine which EEPROM layout is present by reading MTD_MFT_VER from
* the two possible byte offsets and validating its CRC.
* Returns true if the EEPROM has the small (64Kbit) layout used by FRAM
* and NOR boards. Returns false for the large (128Kbit) EEPROM-only layout
* where MTD_MFT_VER is at offset 0.
****************************************************************************/
static bool detect_layout_is_fram(void)
static bool detect_eeprom_is_small(void)
{
struct i2c_master_s *i2c = px4_i2cbus_initialize(4);
bool ret;
if (!i2c) {
syslog(LOG_WARNING, "[boot] EEPROM I2C init failed, defaulting to FRAM layout\n");
syslog(LOG_WARNING, "[boot] EEPROM I2C init failed, assuming small layout\n");
ret = true;
goto out;
}
/* FRAM-variant: MTD_MFT_VER after MTD_CALDATA (224 blocks x 32 B). */
/* Small layout: MTD_MFT_VER follows MTD_CALDATA (224 blocks x 32 B). */
if (eeprom_read_and_check_mft(i2c, 224u * 32u)) {
ret = true;
goto out;
}
/* EEPROM-only: MTD_MFT_VER is the first partition (0 blocks x 32 B)*/
/* Large layout: MTD_MFT_VER is at offset 0. */
if (eeprom_read_and_check_mft(i2c, 0u)) {
ret = false;
goto out;
}
/* Neither offset contains a valid record, default to FRAM layout. */
/* Neither offset valid, assume small layout. */
ret = true;
out:
@@ -273,13 +277,10 @@ __EXPORT int board_app_initialize(uintptr_t arg)
* buses/devices can be used. */
stm32_spiinitialize();
bool fram_available = detect_layout_is_fram();
bool small_eeprom = detect_eeprom_is_small();
board_set_eeprom_manifest(small_eeprom);
if (fram_available) {
board_configure_fram();
}
/* Configure the HW based on the manifest */
/* Mount EEPROM only, SPI storage is detected and added later. */
px4_platform_configure();
if (OK == board_determine_hw_info()) {
@@ -290,12 +291,35 @@ __EXPORT int board_app_initialize(uintptr_t arg)
syslog(LOG_ERR, "[boot] Failed to read HW revision and version\n");
}
/* Identify SPI storage from the HW revision written at provisioning time.
* EEPROM is already mounted so the revision is available. */
bool storage_configured = true;
bool fram_available = false;
bool nor_available = false;
if ((board_get_hw_revision() & 0xFF) >= BOARD_HW_REV_NOR) {
if (board_configure_nor() == OK) {
nor_available = true;
} else {
storage_configured = false;
}
} else if (small_eeprom) {
if (board_configure_fram() == OK) {
fram_available = true;
} else {
storage_configured = false;
}
}
/* EEPROM-only boards use a 128Kbit chip: 512 pages × 32 B = 16 KB.
* FRAM boards use a 64Kbit EEPROM: 256 pages × 32 B = 8 KB.
* FRAM / NOR boards use a 64Kbit EEPROM: 256 pages × 32 B = 8 KB.
* Always use 32-byte page writes (safe for 64-byte page chips too). */
unsigned int mtd_count = 0;
mtd_instance_s **instances = px4_mtd_get_instances(&mtd_count);
uint16_t eeprom_npages = fram_available ? 256 : 512;
uint16_t eeprom_npages = small_eeprom ? 256 : 512;
/* instances[0] is always EEPROM on both board variants. */
if (mtd_count > 0 && instances[0]->mtd_dev != NULL) {
@@ -329,31 +353,45 @@ __EXPORT int board_app_initialize(uintptr_t arg)
}
/* Mount LittleFS as /fs/microsd:
* FRAM boards: EEPROM->mtdblock0-4, FRAM->mtdblock5 (LittleFS).
* EEPROM-only: EEPROM->mtdblock0-2, FTL on free EEPROM region mtdblock3 (LittleFS). */
const char *lfs_dev;
* FRAM boards: EEPROM->mtdblock0-4, FRAM->mtdblock5 (LittleFS).
* NOR flash boards: EEPROM->mtdblock0-4, NOR->MTD direct at /mnt/microsd (LittleFS).
* EEPROM-only: EEPROM->mtdblock0-2, FTL on free EEPROM region mtdblock3 (LittleFS). */
const char *lfs_dev = NULL;
if (fram_available) {
lfs_dev = "/dev/mtdblock5";
if (storage_configured) {
if (nor_available) {
lfs_dev = "/mnt/microsd";
} else {
if (mtd_count > 0 && instances[0]->mtd_dev != NULL) {
FAR struct mtd_dev_s *eeprom_fs = mtd_partition(instances[0]->mtd_dev, 3, eeprom_npages - 3);
} else if (fram_available) {
lfs_dev = "/dev/mtdblock5";
if (!eeprom_fs || ftl_initialize(3, eeprom_fs) != 0) {
syslog(LOG_ERR, "[boot] EEPROM: FTL init failed\n");
} else {
if (mtd_count > 0 && instances[0]->mtd_dev != NULL) {
FAR struct mtd_dev_s *eeprom_fs = mtd_partition(instances[0]->mtd_dev, 3, eeprom_npages - 3);
if (!eeprom_fs || ftl_initialize(3, eeprom_fs) != 0) {
syslog(LOG_ERR, "[boot] EEPROM: FTL init failed\n");
led_on(LED_RED);
}
} else {
syslog(LOG_ERR, "[boot] EEPROM not found\n");
led_on(LED_RED);
}
} else {
syslog(LOG_ERR, "[boot] EEPROM not found\n");
led_on(LED_RED);
lfs_dev = "/dev/mtdblock3";
}
lfs_dev = "/dev/mtdblock3";
} else {
syslog(LOG_ERR, "[boot] Storage init failed\n");
led_on(LED_RED);
}
if (nx_mount(lfs_dev, "/fs/microsd", "littlefs", 0, "autoformat") != 0) {
/* NOR flash has native 4KB erase blocks — use factor=1 so littlefs drives
* them directly (512 blocks) instead of the Kconfig default of 4 (128 blocks). */
const char *lfs_opts = nor_available ? "autoformat,block_size_factor=1" : "autoformat";
if (lfs_dev != NULL && nx_mount(lfs_dev, "/fs/microsd", "littlefs", 0, lfs_opts) != 0) {
syslog(LOG_ERR, "[boot] failed to mount /fs/microsd\n");
led_on(LED_RED);
}
+123 -23
View File
@@ -36,18 +36,43 @@
#include <nuttx/spi/spi.h>
#include <px4_platform_common/px4_manifest.h>
#include <px4_platform_common/mtd_manifest.h>
static const px4_mft_device_t spi4 = { // MB85RS1MT on FMUM native: 1Mbit, emulated as (1024 Blocks of 32)
.bus_type = px4_mft_device_t::SPI,
.devid = SPIDEV_FLASH(0)
/* Physical bus devices */
static const px4_mft_device_t spi4_fram = { // MB85RS1MT on FMUM native: 1Mbit, emulated as (1024 Blocks of 32)
.bus_type = px4_mft_device_t::SPI,
.spi_driver = px4_mft_device_t::SPI_DRIVER_DEFAULT,
.devid = SPIDEV_FLASH(0)
};
static const px4_mft_device_t spi4_nor = { // MX25L1606EZUI-12G-TR: 16Mbit NOR flash (512 sectors x 4KB, 8192 pages x 256B)
.bus_type = px4_mft_device_t::SPI,
.spi_driver = px4_mft_device_t::SPI_DRIVER_MX25L,
.devid = SPIDEV_FLASH(0)
};
static const px4_mft_device_t i2c4 = { // 24LC64T 8K 32 X 256 or 16K for EEPROM only boards
.bus_type = px4_mft_device_t::I2C,
.devid = PX4_MK_I2C_DEVID(4, 0x50)
};
/* MTD partition entries */
static const px4_mtd_entry_t fmum_nor = { // MX25L1606E: 2MB / 256-byte page = 8192 blocks
.device = &spi4_nor,
.npart = 1,
.bulk_erase = true,
.partd = {
{
.type = MTD_PARAMETERS,
.path = "/mnt/microsd",
.nblocks = (2097152 / 256),
.bypass_ftl = true
}
},
};
static const px4_mtd_entry_t fmum_fram = {
.device = &spi4,
.device = &spi4_fram,
.npart = 1,
.partd = {
{
@@ -61,7 +86,7 @@ static const px4_mtd_entry_t fmum_fram = {
/* EEPROM layout for EEPROM-only boards (128Kbit, 512 pages x 32B = 16KB). */
static constexpr uint32_t kEepromParts = 3;
static const px4_mtd_entry_t fmum_eeprom = {
static const px4_mtd_entry_t fmum_eeprom_large = {
.device = &i2c4,
.npart = kEepromParts,
.partd = {
@@ -85,9 +110,8 @@ static const px4_mtd_entry_t fmum_eeprom = {
static_assert(kEepromParts == 3,
"EEPROM partition count changed: update init.c accordingly");
/* EEPROM layout for FRAM boards (64Kbit, 256 pages x 32B = 8KB).
* Matches existing layout for backwards compatibility reasons. */
static const px4_mtd_entry_t fmum_eeprom_fram = {
/* EEPROM layout for FRAM/NOR boards (64Kbit, 256 pages x 32B = 8KB). */
static const px4_mtd_entry_t fmum_eeprom_small = {
.device = &i2c4,
.npart = 5,
.partd = {
@@ -119,19 +143,55 @@ static const px4_mtd_entry_t fmum_eeprom_fram = {
},
};
static const px4_mtd_manifest_t board_mtd_config = {
/* MTD manifests */
static const px4_mtd_manifest_t board_mtd_config_eeprom_small = {
.nconfigs = 1,
.entries = { &fmum_eeprom }
.entries = { &fmum_eeprom_small }
};
static const px4_mtd_manifest_t board_mtd_config_eeprom_large = {
.nconfigs = 1,
.entries = { &fmum_eeprom_large }
};
static const px4_mtd_manifest_t board_mtd_config_spi_fram = {
.nconfigs = 1,
.entries = { &fmum_fram }
};
static const px4_mtd_manifest_t board_mtd_config_spi_nor = {
.nconfigs = 1,
.entries = { &fmum_nor }
};
/* Full description FRAM manifest, set after complete init. */
static const px4_mtd_manifest_t board_mtd_config_fram = {
.nconfigs = 2,
.entries = { &fmum_eeprom_fram, &fmum_fram }
.entries = { &fmum_eeprom_small, &fmum_fram }
};
static const px4_mft_entry_s mtd_mft = {
/* Full description NOR manifest, set after complete init. */
static const px4_mtd_manifest_t board_mtd_config_nor = {
.nconfigs = 2,
.entries = { &fmum_eeprom_small, &fmum_nor }
};
/* MFT entries */
static const px4_mft_entry_s mft_mft = {
.type = MFT,
.pmft = (void *) system_query_manifest,
};
static const px4_mft_entry_s mtd_mft_eeprom_small = {
.type = MTD,
.pmft = (void *) &board_mtd_config,
.pmft = (void *) &board_mtd_config_eeprom_small,
};
static const px4_mft_entry_s mtd_mft_eeprom_large = {
.type = MTD,
.pmft = (void *) &board_mtd_config_eeprom_large,
};
static const px4_mft_entry_s mtd_mft_fram = {
@@ -139,31 +199,71 @@ static const px4_mft_entry_s mtd_mft_fram = {
.pmft = (void *) &board_mtd_config_fram,
};
static const px4_mft_entry_s mft_mft = {
.type = MFT,
.pmft = (void *) system_query_manifest,
static const px4_mft_entry_s mtd_mft_nor = {
.type = MTD,
.pmft = (void *) &board_mtd_config_nor,
};
/* Manifest for EEPROM only boards */
static const px4_mft_s mft = {
/* MFT manifests */
/* Intermediate manifest while SPI storage is not yet detected (FRAM/NOR boards) */
static const px4_mft_s mft_eeprom_small = {
.nmft = 2,
.mfts = { &mtd_mft, &mft_mft }
.mfts = { &mtd_mft_eeprom_small, &mft_mft }
};
/* Manifest for EEPROM + FRAM boards */
/* Final manifest for EEPROM-only boards */
static const px4_mft_s mft_eeprom_large = {
.nmft = 2,
.mfts = { &mtd_mft_eeprom_large, &mft_mft }
};
/* Final manifest for FRAM boards */
static const px4_mft_s mft_fram = {
.nmft = 2,
.mfts = { &mtd_mft_fram, &mft_mft }
};
static const px4_mft_s *g_manifest = &mft;
/* Final manifest for NOR flash boards */
static const px4_mft_s mft_nor = {
.nmft = 2,
.mfts = { &mtd_mft_nor, &mft_mft }
};
static const px4_mft_s *g_manifest = &mft_eeprom_small;
const px4_mft_s *board_get_manifest(void)
{
return g_manifest;
}
void board_configure_fram()
void board_set_eeprom_manifest(bool small_eeprom)
{
g_manifest = &mft_fram;
g_manifest = small_eeprom ? &mft_eeprom_small : &mft_eeprom_large;
}
int board_configure_fram()
{
/* Configure the FRAM (EEPROM already initialized) */
int ret = px4_mtd_config(&board_mtd_config_spi_fram);
/* Set complete manifest (EEPROM + FRAM)*/
if (ret == OK) {
g_manifest = &mft_fram;
}
return ret;
}
int board_configure_nor()
{
/* Configure the NOR (EEPROM already initialized) */
int ret = px4_mtd_config(&board_mtd_config_spi_nor);
/* Set complete manifest (EEPROM + NOR)*/
if (ret == OK) {
g_manifest = &mft_nor;
}
return ret;
}