From 768e01aedcc12585325bccb10cbd993793597d27 Mon Sep 17 00:00:00 2001 From: Heesub Shin Date: Fri, 7 Apr 2017 17:20:55 +0900 Subject: [PATCH] s5j/sss: do not use Kconfig constants Instead of using constants that are defined by Kconfig, use geometry information provided by underlying MTD device. This is a prepration step for removing CONFIG_S5J_FLASH_XXX that are not actually configurable, but in Kconfig so making people confused. Change-Id: I02dd1e39e8e642a0eceeda72e217b5a7b376f85b Signed-off-by: Heesub Shin --- os/arch/arm/src/s5j/sss/sss_driver_io.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/os/arch/arm/src/s5j/sss/sss_driver_io.c b/os/arch/arm/src/s5j/sss/sss_driver_io.c index fad2573..c8e5bee 100644 --- a/os/arch/arm/src/s5j/sss/sss_driver_io.c +++ b/os/arch/arm/src/s5j/sss/sss_driver_io.c @@ -41,8 +41,8 @@ int sss_ro_read(unsigned int start_offset, unsigned char *buf, unsigned int byte FAR struct inode *pnode = NULL; char *devname = sss_get_flash_device_name(); unsigned char *read_buf = NULL; - unsigned int start_sector = 0, end_sector = 0; - unsigned int nsector = 0; + unsigned int start_sector, end_sector; + unsigned int nsector; unsigned int end_offset = start_offset + byte_size; /* Check input bound */ @@ -50,11 +50,6 @@ int sss_ro_read(unsigned int start_offset, unsigned char *buf, unsigned int byte return ERROR_SSTORAGE_SFS_FREAD; } - /* Calculate the sector number what we sholuld read */ - start_sector = start_offset / CONFIG_S5J_FLASH_SECTOR_SIZE; - end_sector = end_offset / CONFIG_S5J_FLASH_SECTOR_SIZE; - nsector = end_sector - start_sector + ((end_offset % CONFIG_S5J_FLASH_SECTOR_SIZE) ? (1) : (0)); - /* Open the mtd block device */ ret = open_blockdriver(devname, 0, &pnode); if (ret < 0) { @@ -69,13 +64,18 @@ int sss_ro_read(unsigned int start_offset, unsigned char *buf, unsigned int byte goto read_out; } + /* Calculate the sector number what we sholuld read */ + start_sector = start_offset / geo.erasesize; + end_sector = end_offset / geo.erasesize; + nsector = end_sector - start_sector + ((end_offset % geo.erasesize) ? (1) : (0)); + if (geo.erasesize * geo.neraseblocks < end_offset) { ret = ERROR_SSTORAGE_INVALID_DATA_LEN; goto read_out; } /* Allocate temporary read buffer */ - read_buf = (unsigned char *)malloc(nsector * CONFIG_S5J_FLASH_SECTOR_SIZE); + read_buf = (unsigned char *)malloc(nsector * geo.erasesize); if (read_buf == NULL) { fdbg("Fail to allocate memory\n"); ret = ERROR_SSTORAGE_SFS_FREAD; @@ -89,7 +89,7 @@ int sss_ro_read(unsigned int start_offset, unsigned char *buf, unsigned int byte ret = ERROR_SSTORAGE_SFS_FREAD; goto read_out; } - memcpy(buf, read_buf + (start_offset % CONFIG_S5J_FLASH_SECTOR_SIZE), byte_size); + memcpy(buf, read_buf + (start_offset % geo.erasesize), byte_size); read_out: if (close_blockdriver(pnode)) { -- 2.7.4