s5j/sss: supports SSSRO read()
authorJunyeon LEE <junyeon2.lee@samsung.com>
Wed, 29 Mar 2017 07:22:17 +0000 (16:22 +0900)
committerHeesub Shin <heesub.shin@samsung.com>
Tue, 18 Apr 2017 03:02:04 +0000 (12:02 +0900)
This commit supports read and write function for SSSRO mtdftl.
And adds sss_driver_io.c file for portability

Change-Id: Iacb463c138e19955c990a4a7cc69715cff7f6d05
Signed-off-by: Junyeon LEE <junyeon2.lee@samsung.com>
os/arch/arm/src/s5j/Make.defs
os/arch/arm/src/s5j/soc/sss/sss_driver_io.c [new file with mode: 0644]
os/arch/arm/src/s5j/soc/sss/sss_driver_io.h [new file with mode: 0644]

index 0504ca4..a749675 100644 (file)
@@ -214,6 +214,7 @@ endif
 CHIP_CSRCS += s5j_watchdog.c
 
 ifeq ($(CONFIG_S5J_SSS),y)
+CHIP_CSRCS += chip/soc/sss/sss_driver_io.c
 EXTRA_LIBS += chip/soc/sss/libispdriver.a
 endif
 
diff --git a/os/arch/arm/src/s5j/soc/sss/sss_driver_io.c b/os/arch/arm/src/s5j/soc/sss/sss_driver_io.c
new file mode 100644 (file)
index 0000000..fad2573
--- /dev/null
@@ -0,0 +1,111 @@
+/****************************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
+ *
+ ****************************************************************************/
+
+#include <tinyara/config.h>
+#include <stdio.h>
+
+#include <tinyara/fs/fs.h>
+#include <tinyara/fs/mtd.h>
+#include <tinyara/fs/ioctl.h>
+
+#include "isp_driver_error.h"
+#include "sss_driver_io.h"
+
+#define S5J_SSS_RO_DEVICE_NAME "/dev/mtdblock1"
+
+char *sss_get_flash_device_name(void)
+{
+       return S5J_SSS_RO_DEVICE_NAME;
+}
+
+int sss_ro_read(unsigned int start_offset, unsigned char *buf, unsigned int byte_size)
+{
+       int ret = OK;
+#if defined(SSS_OVER_MTDFTL)
+       struct mtd_geometry_s geo;
+       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 end_offset = start_offset + byte_size;
+
+       /* Check input bound */
+       if (buf == NULL) {
+               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) {
+               fdbg("Fail to open %s errno = %d\n", devname, errno);
+               return ERROR_SSTORAGE_SFS_FOPEN;
+       }
+
+       ret = pnode->u.i_bops->ioctl(pnode, MTDIOC_GEOMETRY, (unsigned long)&geo);
+       if (ret < 0) {
+               fdbg("Fail to ioctl %s errno = %d\n", devname, errno);
+               ret = ERROR_SSTORAGE_SFS_FOPEN;
+               goto read_out;
+       }
+
+       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);
+       if (read_buf == NULL) {
+               fdbg("Fail to allocate memory\n");
+               ret = ERROR_SSTORAGE_SFS_FREAD;
+               goto read_out;
+       }
+
+       /* Read data */
+       ret = pnode->u.i_bops->read(pnode, read_buf, start_sector, nsector);
+       if (ret < 0) {
+               fdbg("Fail to read start_sector = %d, nsector = %d, errno = %d\n", start_sector, nsector, errno);
+               ret = ERROR_SSTORAGE_SFS_FREAD;
+               goto read_out;
+       }
+       memcpy(buf, read_buf + (start_offset % CONFIG_S5J_FLASH_SECTOR_SIZE), byte_size);
+
+read_out:
+       if (close_blockdriver(pnode)) {
+               fdbg("Fail to close errno = %d\n", errno);
+               ret = ERROR_SSTORAGE_SFS_FREAD;
+       }
+
+       if (read_buf) {
+               free(read_buf);
+       }
+#endif
+       return ret;
+}
+
+int sss_ro_write(unsigned int start_offset, unsigned char *buf, unsigned int byte_size)
+{
+       // Do not support yet.
+       return OK;
+}
diff --git a/os/arch/arm/src/s5j/soc/sss/sss_driver_io.h b/os/arch/arm/src/s5j/soc/sss/sss_driver_io.h
new file mode 100644 (file)
index 0000000..168ca83
--- /dev/null
@@ -0,0 +1,31 @@
+/****************************************************************************
+ *
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
+ *
+ ****************************************************************************/
+
+#ifndef DRIVER_IO_H_
+#define DRIVER_IO_H_
+
+#ifndef SSS_OVER_MTDFTL
+#define SSS_OVER_MTDFTL
+#endif
+
+char *sss_get_flash_device_name(void);
+
+int sss_ro_read(unsigned int start_offset, unsigned char *buf, unsigned int byte_size);
+int sss_ro_write(unsigned int start_offset, unsigned char *buf, unsigned int byte_size);
+
+#endif /* DRIVER_IO_H_ */