From 93f8a57dcb90b00f233b1012459fc03fc5340c98 Mon Sep 17 00:00:00 2001 From: Heesub Shin Date: Sun, 19 Mar 2017 14:41:43 +0900 Subject: [PATCH] s5j: sidk_s5jt200: rework nvram support Current design associated with NVRAM support is a mess, accessing to the flash memory directly in Nv_Read/Write/Erase(). All flash accesses to flash memory should be done through MTD interface. Any direct access is invalid and breaks the design. This commit fixes it by inroducing a new implementation of Nv_xxx() which is based on MTD config device. It manages NVRAM data from WiFi application stack. Change-Id: I6674a982895d13884b7f10db3b417e37acb9ca27 Signed-off-by: Heesub Shin --- .../configs/sidk_s5jt200/hello_with_tash/defconfig | 9 +- build/configs/sidk_s5jt200/kernel_sample/defconfig | 9 +- .../configs/sidk_s5jt200/sidk_tash_wlan/defconfig | 9 +- build/configs/sidk_s5jt200/tc/defconfig | 9 +- os/arch/arm/src/s5j/Make.defs | 1 - os/arch/arm/src/s5j/s5j_nvram.c | 198 --------------------- os/arch/arm/src/sidk_s5jt200/src/Makefile | 2 +- .../src/s5jt200_nvram.c} | 94 ++++++++-- os/arch/arm/src/sidk_s5jt200/src/sidk_s5jt200.h | 5 + 9 files changed, 115 insertions(+), 221 deletions(-) delete mode 100644 os/arch/arm/src/s5j/s5j_nvram.c rename os/arch/arm/src/{s5j/s5j_nvram.h => sidk_s5jt200/src/s5jt200_nvram.c} (64%) diff --git a/build/configs/sidk_s5jt200/hello_with_tash/defconfig b/build/configs/sidk_s5jt200/hello_with_tash/defconfig index 684a97c..e7903e2 100644 --- a/build/configs/sidk_s5jt200/hello_with_tash/defconfig +++ b/build/configs/sidk_s5jt200/hello_with_tash/defconfig @@ -637,7 +637,14 @@ CONFIG_MTD=y CONFIG_MTD_PARTITION=y CONFIG_MTD_PARTITION_NAMES=y CONFIG_MTD_PROGMEM=y -# CONFIG_MTD_CONFIG is not set +CONFIG_MTD_CONFIG=y +# CONFIG_MTD_BYTE_WRITE is not set + +# +# MTD Configurations +# +# CONFIG_MTD_CONFIG_RAM_CONSOLIDATE is not set +CONFIG_MTD_CONFIG_ERASEDVALUE=0xff # CONFIG_MTD_BYTE_WRITE is not set # diff --git a/build/configs/sidk_s5jt200/kernel_sample/defconfig b/build/configs/sidk_s5jt200/kernel_sample/defconfig index 2fd5371..e83cc97 100644 --- a/build/configs/sidk_s5jt200/kernel_sample/defconfig +++ b/build/configs/sidk_s5jt200/kernel_sample/defconfig @@ -641,7 +641,14 @@ CONFIG_MTD=y CONFIG_MTD_PARTITION=y CONFIG_MTD_PARTITION_NAMES=y CONFIG_MTD_PROGMEM=y -# CONFIG_MTD_CONFIG is not set +CONFIG_MTD_CONFIG=y +# CONFIG_MTD_BYTE_WRITE is not set + +# +# MTD Configurations +# +# CONFIG_MTD_CONFIG_RAM_CONSOLIDATE is not set +CONFIG_MTD_CONFIG_ERASEDVALUE=0xff # CONFIG_MTD_BYTE_WRITE is not set # diff --git a/build/configs/sidk_s5jt200/sidk_tash_wlan/defconfig b/build/configs/sidk_s5jt200/sidk_tash_wlan/defconfig index 878b9ec..bbd2068 100755 --- a/build/configs/sidk_s5jt200/sidk_tash_wlan/defconfig +++ b/build/configs/sidk_s5jt200/sidk_tash_wlan/defconfig @@ -717,7 +717,14 @@ CONFIG_MTD=y CONFIG_MTD_PARTITION=y CONFIG_MTD_PARTITION_NAMES=y CONFIG_MTD_PROGMEM=y -# CONFIG_MTD_CONFIG is not set +CONFIG_MTD_CONFIG=y +# CONFIG_MTD_BYTE_WRITE is not set + +# +# MTD Configurations +# +# CONFIG_MTD_CONFIG_RAM_CONSOLIDATE is not set +CONFIG_MTD_CONFIG_ERASEDVALUE=0xff # CONFIG_MTD_BYTE_WRITE is not set # diff --git a/build/configs/sidk_s5jt200/tc/defconfig b/build/configs/sidk_s5jt200/tc/defconfig index 31de839..7a9488f 100644 --- a/build/configs/sidk_s5jt200/tc/defconfig +++ b/build/configs/sidk_s5jt200/tc/defconfig @@ -641,7 +641,14 @@ CONFIG_MTD=y CONFIG_MTD_PARTITION=y CONFIG_MTD_PARTITION_NAMES=y CONFIG_MTD_PROGMEM=y -# CONFIG_MTD_CONFIG is not set +CONFIG_MTD_CONFIG=y +# CONFIG_MTD_BYTE_WRITE is not set + +# +# MTD Configurations +# +# CONFIG_MTD_CONFIG_RAM_CONSOLIDATE is not set +CONFIG_MTD_CONFIG_ERASEDVALUE=0xff # CONFIG_MTD_BYTE_WRITE is not set # diff --git a/os/arch/arm/src/s5j/Make.defs b/os/arch/arm/src/s5j/Make.defs index 97b211b..e195035 100644 --- a/os/arch/arm/src/s5j/Make.defs +++ b/os/arch/arm/src/s5j/Make.defs @@ -158,7 +158,6 @@ endif ifeq ($(CONFIG_S5J_SFLASH),y) CHIP_CSRCS += s5j_sflash.c CHIP_CSRCS += s5j_qspi.c -CHIP_CSRCS += s5j_nvram.c endif ifeq ($(CONFIG_ARCH_IDLE_CUSTOM),y) diff --git a/os/arch/arm/src/s5j/s5j_nvram.c b/os/arch/arm/src/s5j/s5j_nvram.c deleted file mode 100644 index 8f21497..0000000 --- a/os/arch/arm/src/s5j/s5j_nvram.c +++ /dev/null @@ -1,198 +0,0 @@ -/**************************************************************************** - * - * 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. - * - ****************************************************************************/ -/**************************************************************************** - * arch/arm/src/s5j/s5j_nvram.c - * - * Copyright (C) 2009-2010, 2014-2015 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include -#include - -#include -#include -#include -#include - -#include - -#include -#include -#include - -#include "chip.h" -#include "up_arch.h" -#include "cache.h" -#include "mpu.h" - -#include -#include -#include -#include -#include - -/**************************************************************************** - * Private Functions Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Types - ****************************************************************************/ - -/**************************************************************************** - * Static Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ -/**************************************************************************** - * Private Types - ****************************************************************************/ -/**************************************************************************** - * Public Functions - ****************************************************************************/ -unsigned int Nv_Write(unsigned int target_addr, unsigned int source_addr, unsigned int sizebyte) -{ - int ret; - - ret = false; - if ((target_addr < CONFIG_NVRAM_WIFI_START) - || ((target_addr + sizebyte) > (CONFIG_NVRAM_WIFI_START + 8 * 1024)) - || (sizebyte > (8 * 1024))) { - lldbg("Unable to access\n"); - return false; - } - - s5j_qspi_disable_wp(); - - //Page Programming - SetBits(rSF_CON, 15, 0x1, 1); - - // Checks Address range (16MB) - if (((target_addr - CONFIG_S5J_FLASH_BASE) >> 24) > 0) { // 16MB - lldbg("Flash Address range over!(24bit range)\n"); - goto err; - } - - memcpy((void *)target_addr, (void *)source_addr, sizebyte); - arch_flush_dcache(CONFIG_NVRAM_WIFI_START, CONFIG_NVRAM_WIFI_START + 8 * 1024); - - ret = true; -err: - s5j_qspi_enable_wp(); - return ret; -} - -unsigned int Nv_Read(unsigned int target_addr, unsigned int source_addr, unsigned int sizebyte) -{ - if ((source_addr < CONFIG_NVRAM_WIFI_START) - || ((source_addr + sizebyte) > (CONFIG_NVRAM_WIFI_START + 8 * 1024)) - || (sizebyte > (8 * 1024))) { - lldbg("Unable to access\n"); - return false; - } - - memcpy((void *)target_addr, (void *)source_addr, sizebyte); - return true; -} - -unsigned int Nv_Erase(unsigned int target_addr, unsigned int sizebyte) -{ - if ((target_addr < CONFIG_NVRAM_WIFI_START) - || ((target_addr + sizebyte) > (CONFIG_NVRAM_WIFI_START + 8 * 1024)) - || (sizebyte > (8 * 1024))) { - lldbg("Unable to access\n"); - return false; - } - //Disable WP(Write Protect) - SetBits(rSF_CON, 31, 0x1U, 1U); - - //Page Programming - SetBits(rSF_CON, 15, 0x1, 1); - - // Checks Address range (16MB) - if (((target_addr - CONFIG_S5J_FLASH_BASE) >> 24) > 0) { // 16MB - lldbg("Flash Address range over!(24bit range)\n"); - return false; - } - //Checks sector(4KB) align - if ((target_addr & 0xFFF) != 0) { - lldbg("4KB alignment failure\n"); - return false; - } - - arch_flush_dcache(CONFIG_NVRAM_WIFI_START, CONFIG_NVRAM_WIFI_START + 8 * 1024); - - //should be erased before writing. - if (s5j_qspi_erase(target_addr, sizebyte) == false) { - lldbg("Erase Failure\n"); - return false; - } - - return true; -} - -unsigned int s5j_nvram_write(unsigned int target_addr, unsigned int source_addr, unsigned int sizebyte) -{ - return Nv_Write(target_addr, source_addr, sizebyte); -} - -unsigned int s5j_nvram_read(unsigned int target_addr, unsigned int source_addr, unsigned int sizebyte) -{ - return Nv_Read(target_addr, source_addr, sizebyte); -} - -unsigned int s5j_nvram_erase(unsigned int target_addr, unsigned int sizebyte) -{ - return Nv_Erase(target_addr, sizebyte); -} diff --git a/os/arch/arm/src/sidk_s5jt200/src/Makefile b/os/arch/arm/src/sidk_s5jt200/src/Makefile index 25ae3a2..18cc64c 100644 --- a/os/arch/arm/src/sidk_s5jt200/src/Makefile +++ b/os/arch/arm/src/sidk_s5jt200/src/Makefile @@ -55,7 +55,7 @@ CFLAGS += -I$(TOPDIR)/sched ASRCS = -CSRCS = s5jt200_boot.c s5jt200_tash.c +CSRCS = s5jt200_boot.c s5jt200_tash.c s5jt200_nvram.c ifeq ($(CONFIG_ARCH_BUTTONS),y) CSRCS += s5j_buttons.c diff --git a/os/arch/arm/src/s5j/s5j_nvram.h b/os/arch/arm/src/sidk_s5jt200/src/s5jt200_nvram.c similarity index 64% rename from os/arch/arm/src/s5j/s5j_nvram.h rename to os/arch/arm/src/sidk_s5jt200/src/s5jt200_nvram.c index 41a7e27..d838427 100644 --- a/os/arch/arm/src/s5j/s5j_nvram.h +++ b/os/arch/arm/src/sidk_s5jt200/src/s5jt200_nvram.c @@ -1,6 +1,6 @@ /**************************************************************************** * - * Copyright 2016 Samsung Electronics All Rights Reserved. + * Copyright 2017 Samsung Electronics Co., LTD. 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. @@ -16,10 +16,10 @@ * ****************************************************************************/ /**************************************************************************** - * arch/arm/src/s5j/s5j_nvram.h + * arch/arm/src/sidk_s5jt200/sidk200_nvram.c * - * Copyright (C) 2009, 2014 Gregory Nutt. All rights reserved. - * Author: + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -31,7 +31,7 @@ * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be + * 3. Neither the name tinyara nor the names of its contributors may be * used to endorse or promote products derived from this software * without specific prior written permission. * @@ -49,19 +49,79 @@ * POSSIBILITY OF SUCH DAMAGE. * ****************************************************************************/ -#ifndef __ARCH_ARM_SRC_S5J_S5J_NVRAM_H -#define __ARCH_ARM_SRC_S5J_S5J_NVRAM_H -/**************************************************************************** - * Included Files - ****************************************************************************/ +#include + +#include +#include +#include + +#include + +#include "sidk_s5jt200.h" + /**************************************************************************** * Public Functions ****************************************************************************/ -unsigned int Nv_Write(unsigned int target_addr, unsigned int source_addr, unsigned int sizebyte); -unsigned int Nv_Read(unsigned int target_addr, unsigned int source_addr, unsigned int sizebyte); -unsigned int Nv_Erase(unsigned int target_addr, unsigned int sizebyte); -unsigned int s5j_nvram_write(unsigned int target_addr, unsigned int source_addr, unsigned int sizebyte); -unsigned int s5j_nvram_read(unsigned int target_addr, unsigned int source_addr, unsigned int sizebyte); -unsigned int s5j_nvram_erase(unsigned int target_addr, unsigned int sizebyte); -#endif /* __ARCH_ARM_SRC_S5J_S5J_NVRAM_H */ +unsigned int Nv_Write(unsigned int target_addr, unsigned int source_addr, + unsigned int sizebyte) +{ +#if defined(CONFIG_MTD_CONFIG) + int fd; + struct config_data_s config; + + fd = open("/dev/config", O_RDOK); + if (fd < 0) { + lldbg("Failed to open /dev/config\n"); + return false; + } + + config.id = SIDK_S5JT200_CONFIGDATA_WIFI_NVRAM; + config.instance = 0; + config.configdata = (unsigned char *)source_addr; + config.len = sizebyte; + + ioctl(fd, CFGDIOC_SETCONFIG, &config); + close(fd); + + return true; +#else + return false; +#endif +} + +unsigned int Nv_Read(unsigned int target_addr, unsigned int source_addr, + unsigned int sizebyte) +{ +#if defined(CONFIG_MTD_CONFIG) + int fd; + struct config_data_s config; + + fd = open("/dev/config", O_RDOK); + if (fd < 0) { + lldbg("Failed to open /dev/config\n"); + return false; + } + + config.id = SIDK_S5JT200_CONFIGDATA_WIFI_NVRAM; + config.instance = 0; + config.configdata = (unsigned char *)target_addr; + config.len = sizebyte; + + ioctl(fd, CFGDIOC_GETCONFIG, &config); + close(fd); + + return true; +#else + return false; +#endif +} + +unsigned int Nv_Erase(unsigned int target_addr, unsigned int sizebyte) +{ +#if defined(CONFIG_MTD_CONFIG) + return true; +#else + return false; +#endif +} diff --git a/os/arch/arm/src/sidk_s5jt200/src/sidk_s5jt200.h b/os/arch/arm/src/sidk_s5jt200/src/sidk_s5jt200.h index 9a100c1..73438e0 100644 --- a/os/arch/arm/src/sidk_s5jt200/src/sidk_s5jt200.h +++ b/os/arch/arm/src/sidk_s5jt200/src/sidk_s5jt200.h @@ -63,4 +63,9 @@ #define SIDK_S5JT200_PROCFS_MOUNTPOINT "/proc" #endif +enum configdata_id { + SIDK_S5JT200_CONFIGDATA_PLATFORM = 0xff00, + SIDK_S5JT200_CONFIGDATA_WIFI_NVRAM, +}; + #endif /* __ARCH_ARM_SRC_SIDK_S5JT200_SRC_SIDK_S5JT200_H__ */ -- 2.7.4