From a2e54b19aaa6fc67e5c1a835b95ddac00904ea56 Mon Sep 17 00:00:00 2001 From: Heesub Shin Date: Sat, 18 Mar 2017 19:35:19 +0900 Subject: [PATCH] sidk_s5jt200: configure partitions at boot This commit introduces several Kconfig entries for configurting partitions and adds a function that configures flash partitions dynamically at boot time. However, there will be no functional differences yet unless we turn it on. So, don't worry. Change-Id: I3f10491c6f0c753b2c874310ebfe70596ce0e3c6 Signed-off-by: Heesub Shin --- os/arch/arm/src/sidk_s5jt200/Kconfig | 37 +++++++++++ os/arch/arm/src/sidk_s5jt200/src/s5jt200_tash.c | 84 +++++++++++++++++++++++++ 2 files changed, 121 insertions(+) diff --git a/os/arch/arm/src/sidk_s5jt200/Kconfig b/os/arch/arm/src/sidk_s5jt200/Kconfig index 4140f88..bc6067e 100644 --- a/os/arch/arm/src/sidk_s5jt200/Kconfig +++ b/os/arch/arm/src/sidk_s5jt200/Kconfig @@ -22,4 +22,41 @@ config SIDK_S5JT200_FLASH_PAGE_SIZE on the SIDK S5JT200 evaluation board. It can be the size of erase unit flash memory supports. +config SIDK_S5JT200_FLASH_MINOR + int "Minor number for the FLASH /dev/smart entry" + default 0 + depends on S5J_SFLASH + ---help--- + Sets the minor number for /dev node of the external flash + device. + +config SIDK_S5JT200_FLASH_PART + bool "Enable partition support on FLASH" + default n + depends on S5J_SFLASH + ---help--- + Enables creation of partitions on the FLASH + +config SIDK_S5JT200_FLASH_PART_LIST + string "Flash partition size list (in KBytes)" + default "8192," + depends on SIDK_S5JT200_FLASH_PART + ---help--- + Comma separated list of partition sizes in KB. + +config SIDK_S5JT200_FLASH_PART_TYPE + string "Flash partition type list" + default "none," + ---help--- + Comma separated list of partition types that can be + one of followings: none, smartfs + +config SIDK_S5JT200_FLASH_PART_NAME + string "FLash partition name list" + default "mx25," + depends on SIDK_S5JT200_FLASH_PART + depends on MTD_PARTITION_NAMES + ---help--- + Comma separated list of partition names. + endif diff --git a/os/arch/arm/src/sidk_s5jt200/src/s5jt200_tash.c b/os/arch/arm/src/sidk_s5jt200/src/s5jt200_tash.c index ff4c011..7b00351 100644 --- a/os/arch/arm/src/sidk_s5jt200/src/s5jt200_tash.c +++ b/os/arch/arm/src/sidk_s5jt200/src/s5jt200_tash.c @@ -68,6 +68,8 @@ #include "s5j_rtc.h" #include "up_internal.h" +#include + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -112,6 +114,86 @@ static void scsc_wpa_ctrl_iface_init(void) #endif } +static void sidk_s5jt200_configure_partitions(void) +{ +#if defined(CONFIG_SIDK_S5JT200_FLASH_PART) + int partno; + int partoffset; + const char *parts = CONFIG_SIDK_S5JT200_FLASH_PART_LIST; + const char *types = CONFIG_SIDK_S5JT200_FLASH_PART_TYPE; +#if defined(CONFIG_MTD_PARTITION_NAMES) + const char *names = CONFIG_SIDK_S5JT200_FLASH_PART_NAME; +#endif + FAR struct mtd_dev_s *mtd; + FAR struct mtd_geometry_s geo; + + mtd = progmem_initialize(); + if (!mtd) { + lldbg("ERROR: progmem_initialize failed\n"); + return; + } + + if (mtd->ioctl(mtd, MTDIOC_GEOMETRY, (unsigned long)&geo) < 0) { + lldbg("ERROR: mtd->ioctl failed\n"); + return; + } + + partno = 0; + partoffset = 0; + + while (*parts) { + FAR struct mtd_dev_s *mtd_part; + int partsize; + + partsize = strtoul(parts, NULL, 0) << 10; + + if (partsize < geo.erasesize) { + lldbg("ERROR: Partition size is lesser than erasesize\n"); + return; + } + + if (partsize % geo.erasesize != 0) { + lldbg("ERROR: Partition size is not multiple of erasesize\n"); + return; + } + + mtd_part = mtd_partition(mtd, partoffset, + partsize / geo.erasesize, 0); + partoffset += partsize / geo.erasesize; + + if (!mtd_part) { + lldbg("ERROR: failed to create partition.\n"); + return; + } + +#if defined(CONFIG_MTD_SMART) && defined(CONFIG_FS_SMARTFS) + if (!strncmp(types, "smartfs,", 8)) { + char partref[4]; + sprintf(partref, "p%d", partno); + smart_initialize(CONFIG_SIDK_S5JT200_FLASH_MINOR, + mtd_part, partref); + } +#endif + +#if defined(CONFIG_MTD_PARTITION_NAMES) + if (strcmp(names, "")) + mtd_setpartitionname(mtd_part, names); + + while (*names != ',' && *names) names++; + if (*names == ',') names++; +#endif + + while (*parts != ',' && *parts) parts++; + if (*parts == ',') parts++; + + while (*types != ',' && *types) types++; + if (*types == ',') types++; + + partno++; + } +#endif /* CONFIG_SIDK_S5JT200_FLASH_PART */ +} + /**************************************************************************** * Name: board_app_initialize * @@ -127,6 +209,8 @@ int board_app_initialize(void) FAR struct tm tp; #endif + sidk_s5jt200_configure_partitions(); + #ifdef CONFIG_S5J_I2C s5j_i2c_register(0); s5j_i2c_register(1); -- 2.7.4