boards/arm/samv7: define MTD progmem partitions at board level
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
This commit is contained in:
parent
fe0fbdc088
commit
2af9b574f6
|
@ -21,16 +21,32 @@
|
|||
#ifndef __BOARDS_ARM_SAMV7_COMMON_INCLUDE_BOARD_PROGMEM_H
|
||||
#define __BOARDS_ARM_SAMV7_COMMON_INCLUDE_BOARD_PROGMEM_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <nuttx/mtd/mtd.h>
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
struct mtd_partition_s
|
||||
{
|
||||
size_t offset; /* Partition offset from the beginning of MTD */
|
||||
size_t size; /* Partition size in bytes */
|
||||
const char *devpath; /* Partition device path */
|
||||
struct mtd_dev_s *mtd; /* Pointer to allocated MTD partition */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
|
@ -52,6 +68,8 @@ extern "C"
|
|||
*
|
||||
* Input Parameters:
|
||||
* minor - The starting minor number for progmem MTD partitions.
|
||||
* table - Progmem MTD partition table
|
||||
* count - Number of element in progmem MTD partition table
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero is returned on success. Otherwise, a negated errno value is
|
||||
|
@ -59,7 +77,8 @@ extern "C"
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_progmem_init(int minor);
|
||||
int board_progmem_init(int minor, struct mtd_partition_s *table,
|
||||
size_t count);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
|
|
|
@ -41,50 +41,6 @@
|
|||
#include "sam_progmem.h"
|
||||
#include "board_progmem.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define ARRAYSIZE(x) (sizeof((x)) / sizeof((x)[0]))
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
struct mcuboot_partition_s
|
||||
{
|
||||
uint32_t offset; /* Partition offset from the beginning of MTD */
|
||||
uint32_t size; /* Partition size in bytes */
|
||||
const char *devpath; /* Partition device path */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static FAR struct mtd_dev_s *g_samv7_progmem_mtd;
|
||||
|
||||
#if defined(CONFIG_SAMV7_PROGMEM_OTA_PARTITION)
|
||||
static const struct mcuboot_partition_s g_mcuboot_partition_table[] =
|
||||
{
|
||||
{
|
||||
.offset = CONFIG_SAMV7_OTA_PRIMARY_SLOT_OFFSET,
|
||||
.size = CONFIG_SAMV7_OTA_SLOT_SIZE,
|
||||
.devpath = CONFIG_SAMV7_OTA_PRIMARY_SLOT_DEVPATH
|
||||
},
|
||||
{
|
||||
.offset = CONFIG_SAMV7_OTA_SECONDARY_SLOT_OFFSET,
|
||||
.size = CONFIG_SAMV7_OTA_SLOT_SIZE,
|
||||
.devpath = CONFIG_SAMV7_OTA_SECONDARY_SLOT_DEVPATH
|
||||
},
|
||||
{
|
||||
.offset = CONFIG_SAMV7_OTA_SCRATCH_OFFSET,
|
||||
.size = CONFIG_SAMV7_OTA_SCRATCH_SIZE,
|
||||
.devpath = CONFIG_SAMV7_OTA_SCRATCH_DEVPATH
|
||||
}
|
||||
};
|
||||
#endif /* CONFIG_SAMV7_PROGMEM_OTA_PARTITION */
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
@ -146,7 +102,6 @@ static int sam_progmem_register_driver(int minor, FAR struct mtd_dev_s *mtd,
|
|||
return ret;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_SAMV7_PROGMEM_OTA_PARTITION)
|
||||
/****************************************************************************
|
||||
* Name: sam_progmem_alloc_mtdpart
|
||||
*
|
||||
|
@ -154,6 +109,7 @@ static int sam_progmem_register_driver(int minor, FAR struct mtd_dev_s *mtd,
|
|||
* Allocate an MTD partition from FLASH.
|
||||
*
|
||||
* Input Parameters:
|
||||
* mtd - The MTD device to be partitioned
|
||||
* mtd_offset - MTD Partition offset from the base address in FLASH.
|
||||
* mtd_size - Size for the MTD partition.
|
||||
*
|
||||
|
@ -162,19 +118,20 @@ static int sam_progmem_register_driver(int minor, FAR struct mtd_dev_s *mtd,
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
static struct mtd_dev_s *sam_progmem_alloc_mtdpart(uint32_t mtd_offset,
|
||||
uint32_t mtd_size)
|
||||
static struct mtd_dev_s *sam_progmem_alloc_mtdpart(FAR struct mtd_dev_s *mtd,
|
||||
size_t mtd_offset,
|
||||
size_t mtd_size)
|
||||
{
|
||||
uint32_t blocks;
|
||||
uint32_t startblock;
|
||||
ssize_t startblock;
|
||||
size_t blocks;
|
||||
|
||||
ASSERT((mtd_offset + mtd_size) <= up_progmem_neraseblocks() *
|
||||
up_progmem_pagesize(0));
|
||||
ASSERT((mtd_offset % up_progmem_pagesize(0)) == 0);
|
||||
ASSERT((mtd_size % up_progmem_pagesize(0)) == 0);
|
||||
|
||||
finfo("\tMTD offset = 0x%" PRIx32 "\n", mtd_offset);
|
||||
finfo("\tMTD size = 0x%" PRIx32 "\n", mtd_size);
|
||||
finfo("\tMTD offset = 0x%zx\n", mtd_offset);
|
||||
finfo("\tMTD size = %zu\n", mtd_size);
|
||||
|
||||
startblock = up_progmem_getpage(mtd_offset);
|
||||
if (startblock < 0)
|
||||
|
@ -184,50 +141,9 @@ static struct mtd_dev_s *sam_progmem_alloc_mtdpart(uint32_t mtd_offset,
|
|||
|
||||
blocks = mtd_size / up_progmem_pagesize(0);
|
||||
|
||||
return mtd_partition(g_samv7_progmem_mtd, startblock, blocks);
|
||||
return mtd_partition(mtd, startblock, blocks);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: init_mcuboot_partitions
|
||||
*
|
||||
* Description:
|
||||
* Initialize partitions that are dedicated to firmware MCUBOOT update.
|
||||
*
|
||||
* Input Parameters:
|
||||
* minor - The starting minor number for progmem MTD partitions.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int init_mcuboot_partitions(int minor)
|
||||
{
|
||||
FAR struct mtd_dev_s *mtd;
|
||||
int ret = OK;
|
||||
|
||||
for (int i = 0; i < ARRAYSIZE(g_mcuboot_partition_table); ++i)
|
||||
{
|
||||
const struct mcuboot_partition_s *part = &g_mcuboot_partition_table[i];
|
||||
mtd = sam_progmem_alloc_mtdpart(part->offset, part->size);
|
||||
|
||||
if (mtd == NULL)
|
||||
{
|
||||
ferr("ERROR: create MTD OTA partition %s", part->devpath);
|
||||
continue;
|
||||
}
|
||||
|
||||
ret = sam_progmem_register_driver(minor + i, mtd, part->devpath);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* CONFIG_SAMV7_PROGMEM_OTA_PARTITION */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
@ -240,6 +156,8 @@ static int init_mcuboot_partitions(int minor)
|
|||
*
|
||||
* Input Parameters:
|
||||
* minor - The starting minor number for progmem MTD partitions.
|
||||
* table - Progmem MTD partition table
|
||||
* count - Number of element in progmem MTD partition table
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero is returned on success. Otherwise, a negated errno value is
|
||||
|
@ -247,8 +165,11 @@ static int init_mcuboot_partitions(int minor)
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_progmem_init(int minor)
|
||||
int board_progmem_init(int minor, struct mtd_partition_s *table,
|
||||
size_t count)
|
||||
{
|
||||
FAR struct mtd_dev_s *progmem_mtd;
|
||||
size_t i;
|
||||
int ret = OK;
|
||||
|
||||
/* Initialize the SAMV7 FLASH programming memory library */
|
||||
|
@ -257,25 +178,44 @@ int board_progmem_init(int minor)
|
|||
|
||||
/* Create an instance of the SAMV7 FLASH program memory device driver */
|
||||
|
||||
g_samv7_progmem_mtd = progmem_initialize();
|
||||
if (g_samv7_progmem_mtd == NULL)
|
||||
progmem_mtd = progmem_initialize();
|
||||
if (progmem_mtd == NULL)
|
||||
{
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_SAMV7_PROGMEM_OTA_PARTITION)
|
||||
ret = init_mcuboot_partitions(minor);
|
||||
if (ret < 0)
|
||||
if (table == NULL || count == 0)
|
||||
{
|
||||
return ret;
|
||||
ret = sam_progmem_register_driver(minor, progmem_mtd, NULL);
|
||||
}
|
||||
#else
|
||||
ret = sam_progmem_register_driver(minor, g_samv7_progmem_mtd, NULL);
|
||||
if (ret < 0)
|
||||
else
|
||||
{
|
||||
return ret;
|
||||
for (i = 0; i < count; ++i)
|
||||
{
|
||||
struct mtd_partition_s *part = &table[i];
|
||||
|
||||
part->mtd = sam_progmem_alloc_mtdpart(progmem_mtd, part->offset,
|
||||
part->size);
|
||||
if (part->mtd != NULL)
|
||||
{
|
||||
if (part->devpath != NULL)
|
||||
{
|
||||
ret = sam_progmem_register_driver(minor + i, part->mtd,
|
||||
part->devpath);
|
||||
if (ret < 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ferr("Failed to allocate MTD partition %d", i);
|
||||
ret = -ENOMEM;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -72,10 +72,43 @@
|
|||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
#define NSECTORS(n) \
|
||||
(((n)+CONFIG_SAME70QMTECH_ROMFS_ROMDISK_SECTSIZE-1) / \
|
||||
CONFIG_SAME70QMTECH_ROMFS_ROMDISK_SECTSIZE)
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_SAMV7_PROGMEM_OTA_PARTITION)
|
||||
static struct mtd_partition_s g_mtd_partition_table[] =
|
||||
{
|
||||
{
|
||||
.offset = CONFIG_SAMV7_OTA_PRIMARY_SLOT_OFFSET,
|
||||
.size = CONFIG_SAMV7_OTA_SLOT_SIZE,
|
||||
.devpath = CONFIG_SAMV7_OTA_PRIMARY_SLOT_DEVPATH
|
||||
},
|
||||
{
|
||||
.offset = CONFIG_SAMV7_OTA_SECONDARY_SLOT_OFFSET,
|
||||
.size = CONFIG_SAMV7_OTA_SLOT_SIZE,
|
||||
.devpath = CONFIG_SAMV7_OTA_SECONDARY_SLOT_DEVPATH
|
||||
},
|
||||
{
|
||||
.offset = CONFIG_SAMV7_OTA_SCRATCH_OFFSET,
|
||||
.size = CONFIG_SAMV7_OTA_SCRATCH_SIZE,
|
||||
.devpath = CONFIG_SAMV7_OTA_SCRATCH_DEVPATH
|
||||
}
|
||||
};
|
||||
|
||||
static const size_t g_mtd_partition_table_size =
|
||||
ARRAY_SIZE(g_mtd_partition_table);
|
||||
#else
|
||||
# define g_mtd_partition_table NULL
|
||||
# define g_mtd_partition_table_size 0
|
||||
#endif /* CONFIG_SAMV7_PROGMEM_OTA_PARTITION */
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
@ -195,7 +228,8 @@ int sam_bringup(void)
|
|||
#ifdef HAVE_PROGMEM_CHARDEV
|
||||
/* Initialize the SAME70 FLASH programming memory library */
|
||||
|
||||
ret = board_progmem_init(PROGMEM_MTD_MINOR);
|
||||
ret = board_progmem_init(PROGMEM_MTD_MINOR, g_mtd_partition_table,
|
||||
g_mtd_partition_table_size);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: Failed to initialize progmem: %d\n", ret);
|
||||
|
@ -227,8 +261,8 @@ int sam_bringup(void)
|
|||
ret = sam_dacdev_initialize();
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR,
|
||||
"ERROR: Initialization of the DAC module failed: %d\n", ret);
|
||||
syslog(LOG_ERR, "ERROR: Initialization of the DAC module failed: %d\n",
|
||||
ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -65,10 +65,43 @@
|
|||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
#define NSECTORS(n) \
|
||||
(((n)+CONFIG_SAME70XPLAINED_ROMFS_ROMDISK_SECTSIZE-1) / \
|
||||
CONFIG_SAME70XPLAINED_ROMFS_ROMDISK_SECTSIZE)
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_SAMV7_PROGMEM_OTA_PARTITION)
|
||||
static struct mtd_partition_s g_mtd_partition_table[] =
|
||||
{
|
||||
{
|
||||
.offset = CONFIG_SAMV7_OTA_PRIMARY_SLOT_OFFSET,
|
||||
.size = CONFIG_SAMV7_OTA_SLOT_SIZE,
|
||||
.devpath = CONFIG_SAMV7_OTA_PRIMARY_SLOT_DEVPATH
|
||||
},
|
||||
{
|
||||
.offset = CONFIG_SAMV7_OTA_SECONDARY_SLOT_OFFSET,
|
||||
.size = CONFIG_SAMV7_OTA_SLOT_SIZE,
|
||||
.devpath = CONFIG_SAMV7_OTA_SECONDARY_SLOT_DEVPATH
|
||||
},
|
||||
{
|
||||
.offset = CONFIG_SAMV7_OTA_SCRATCH_OFFSET,
|
||||
.size = CONFIG_SAMV7_OTA_SCRATCH_SIZE,
|
||||
.devpath = CONFIG_SAMV7_OTA_SCRATCH_DEVPATH
|
||||
}
|
||||
};
|
||||
|
||||
static const size_t g_mtd_partition_table_size =
|
||||
ARRAY_SIZE(g_mtd_partition_table);
|
||||
#else
|
||||
# define g_mtd_partition_table NULL
|
||||
# define g_mtd_partition_table_size 0
|
||||
#endif /* CONFIG_SAMV7_PROGMEM_OTA_PARTITION */
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
@ -97,8 +130,8 @@ static void sam_i2c_register(int bus)
|
|||
ret = i2c_register(i2c, bus);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR,
|
||||
"ERROR: Failed to register I2C%d driver: %d\n", bus, ret);
|
||||
syslog(LOG_ERR, "ERROR: Failed to register I2C%d driver: %d\n",
|
||||
bus, ret);
|
||||
sam_i2cbus_uninitialize(i2c);
|
||||
}
|
||||
}
|
||||
|
@ -256,7 +289,8 @@ int sam_bringup(void)
|
|||
#ifdef HAVE_PROGMEM_CHARDEV
|
||||
/* Initialize the SAME70 FLASH programming memory library */
|
||||
|
||||
ret = board_progmem_init(PROGMEM_MTD_MINOR);
|
||||
ret = board_progmem_init(PROGMEM_MTD_MINOR, g_mtd_partition_table,
|
||||
g_mtd_partition_table_size);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: Failed to initialize progmem: %d\n", ret);
|
||||
|
@ -340,8 +374,8 @@ int sam_bringup(void)
|
|||
ret = sam_dacdev_initialize();
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR,
|
||||
"ERROR: Initialization of the DAC module failed: %d\n", ret);
|
||||
syslog(LOG_ERR, "ERROR: Initialization of the DAC module failed: %d\n",
|
||||
ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -32,14 +32,13 @@
|
|||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/fs/fs.h>
|
||||
|
||||
#ifdef CONFIG_USBMONITOR
|
||||
# include <nuttx/usb/usbmonitor.h>
|
||||
#endif
|
||||
|
||||
#include <nuttx/drivers/drivers.h>
|
||||
#include <nuttx/drivers/ramdisk.h>
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/fs/nxffs.h>
|
||||
#include <nuttx/i2c/i2c_master.h>
|
||||
#include <nuttx/video/fb.h>
|
||||
|
@ -91,10 +90,43 @@
|
|||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
||||
|
||||
#define NSECTORS(n) \
|
||||
(((n)+CONFIG_SAMV71XULT_ROMFS_ROMDISK_SECTSIZE-1) / \
|
||||
CONFIG_SAMV71XULT_ROMFS_ROMDISK_SECTSIZE)
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_SAMV7_PROGMEM_OTA_PARTITION)
|
||||
static struct mtd_partition_s g_mtd_partition_table[] =
|
||||
{
|
||||
{
|
||||
.offset = CONFIG_SAMV7_OTA_PRIMARY_SLOT_OFFSET,
|
||||
.size = CONFIG_SAMV7_OTA_SLOT_SIZE,
|
||||
.devpath = CONFIG_SAMV7_OTA_PRIMARY_SLOT_DEVPATH
|
||||
},
|
||||
{
|
||||
.offset = CONFIG_SAMV7_OTA_SECONDARY_SLOT_OFFSET,
|
||||
.size = CONFIG_SAMV7_OTA_SLOT_SIZE,
|
||||
.devpath = CONFIG_SAMV7_OTA_SECONDARY_SLOT_DEVPATH
|
||||
},
|
||||
{
|
||||
.offset = CONFIG_SAMV7_OTA_SCRATCH_OFFSET,
|
||||
.size = CONFIG_SAMV7_OTA_SCRATCH_SIZE,
|
||||
.devpath = CONFIG_SAMV7_OTA_SCRATCH_DEVPATH
|
||||
}
|
||||
};
|
||||
|
||||
static const size_t g_mtd_partition_table_size =
|
||||
ARRAY_SIZE(g_mtd_partition_table);
|
||||
#else
|
||||
# define g_mtd_partition_table NULL
|
||||
# define g_mtd_partition_table_size 0
|
||||
#endif /* CONFIG_SAMV7_PROGMEM_OTA_PARTITION */
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
@ -453,7 +485,8 @@ int sam_bringup(void)
|
|||
#ifdef HAVE_PROGMEM_CHARDEV
|
||||
/* Initialize the SAMV71 FLASH programming memory library */
|
||||
|
||||
ret = board_progmem_init(PROGMEM_MTD_MINOR);
|
||||
ret = board_progmem_init(PROGMEM_MTD_MINOR, g_mtd_partition_table,
|
||||
g_mtd_partition_table_size);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: Failed to initialize progmem: %d\n", ret);
|
||||
|
|
Loading…
Reference in New Issue