From 0bfad1caf7bd92496b9e388f97dd928bcaa8573b Mon Sep 17 00:00:00 2001 From: laokz Date: Sat, 25 Jun 2022 18:31:15 +0800 Subject: [PATCH] feat(arm-virt/liteos-a): change rootfs and root device * system storate_type change to emmc from spinor * virtio block device change to eMMC from MMC and act as root device * remove all CFI flash code * drivers Kconfig add DRIVERS_EMMC to mimic hispark_taurus and disable DRIVERS_MTD by default Signed-off-by: laokz Change-Id: Ief906b18aa9dc7fae76b5271f56be1168fa96d7e --- arm_virt/liteos_a/README.md | 31 +- arm_virt/liteos_a/README_zh.md | 34 +- arm_virt/liteos_a/config.gni | 2 +- .../hdf_config/cfiflash/cfi_config.hcs | 12 - .../hdf_config/device_info/device_info.hcs | 10 - arm_virt/liteos_a/hdf_config/hdf.hcs | 1 - drivers/BUILD.gn | 2 - drivers/Kconfig | 6 +- drivers/cfiflash/BUILD.gn | 42 -- drivers/cfiflash/Makefile | 7 - drivers/cfiflash/cfiflash.c | 384 ------------------ drivers/cfiflash/cfiflash.h | 36 -- drivers/cfiflash/cfiflash_internal.h | 69 ---- drivers/cfiflash/hdf_cfi.c | 86 ---- drivers/lite.mk | 3 +- drivers/virtio/virtblock.c | 4 +- 16 files changed, 22 insertions(+), 707 deletions(-) delete mode 100644 arm_virt/liteos_a/hdf_config/cfiflash/cfi_config.hcs delete mode 100644 drivers/cfiflash/BUILD.gn delete mode 100644 drivers/cfiflash/Makefile delete mode 100644 drivers/cfiflash/cfiflash.c delete mode 100644 drivers/cfiflash/cfiflash.h delete mode 100644 drivers/cfiflash/cfiflash_internal.h delete mode 100644 drivers/cfiflash/hdf_cfi.c diff --git a/arm_virt/liteos_a/README.md b/arm_virt/liteos_a/README.md index 6fccc8a..42bc84f 100644 --- a/arm_virt/liteos_a/README.md +++ b/arm_virt/liteos_a/README.md @@ -34,7 +34,7 @@ Run the following build command: hb build ``` -After this command is executed, the image files `OHOS_Image.bin`, `rootfs_jffs2.img`, and `userfs_jffs2.img` are generated in out/arm_virt/qemu_small_system_demo/ directory. +After this command is executed, the result files are generated in out/arm_virt/qemu_small_system_demo/ directory. ## 5. Running an Image in QEMU @@ -46,29 +46,11 @@ b) Create and run an image. After the source code is built, the **qemu-run** script is generated in the root directory of the code. You can run the script to create and run an image as prompted. -Run the `./qemu-run --help` command. The following information is displayed: +Run `./qemu-run --help` to get help. -``` -Usage: ./qemu-run [OPTION]... -Make a qemu image(flash.img) for OHOS, and run the image in qemu according -to the options. - - Options: - - -f, --force rebuild flash.img - -n, --net-enable enable net - -l, --local-desktop no VNC - -b, --bootargs additional boot arguments(-bk1=v1,k2=v2...) - -g, --gdb enable gdb for kernel - -h, --help print help info - - By default, flash.img will not be rebuilt if exists, and net will not - be enabled, gpu enabled and waiting for VNC connection at port 5920. -``` - -Simulated network interface is wireless card wlan0, but has no real wifi functions. By default, the network will not be automatically configured if no parameter is specified. If the root directory image file **flash.img** exists, the image will not be re-created. +Simulated network interface is wireless card wlan0, but has no real wifi functions. By default, the network will not be automatically configured if no parameter is specified. -Note: On the first run, script will also create a MMC image mainly for system and user data files. The 1st partition will be mounted at /sdcard, 2nd at /userdata, and 3rd is reserved. It is stored at OHOS source tree 'out' sub-directory, named 'smallmmc.img'. Whenever it exists, script will never try to touch it again. More information please refer to `vendor/ohemu/qemu_small_system_demo/qemu_run.sh`. +If the image file **out/smallmmc.img** exists, the image will not be re-created by default. MMC image mainly for rootfs and userfs. The 1st partition is rootfs, 2nd is userfs and mounted at /userdata, 3rd is for user data and mounted at /userdata. c) Exit QEMU. @@ -171,8 +153,8 @@ More GDB related debugging can refer to [GDB instruction manual](https://sourcew ``` qemu-system-arm -M virt,gic-version=2,secure=on -cpu cortex-a7 -smp cpus=1 -m 1G \ - -drive if=pflash,file=flash.img,format=raw \ - -drive if=none,file=./out/smallmmc.img,format=qcow2,id=mmc + -bios out/arm_virt/qemu_small_system_demo/OHOS_Image.bin \ + -drive if=none,file=out/smallmmc.img,format=raw,id=mmc -device virtio-blk-device,drive=mmc \ -netdev bridge,id=net0 \ -device virtio-net-device,netdev=net0,mac=12:22:33:44:55:66 \ @@ -189,7 +171,6 @@ More GDB related debugging can refer to [GDB instruction manual](https://sourcew -cpu CPU model -smp SMP setting, single core -m Maximum memory size that can be used by the virtual machines - -drive if=pflash CFI flash drive setting -drive if=none Block device image setting -netdev [optional] NIC bridge type -device virtio-blk-device Block device diff --git a/arm_virt/liteos_a/README_zh.md b/arm_virt/liteos_a/README_zh.md index 2e72b60..538b42c 100644 --- a/arm_virt/liteos_a/README_zh.md +++ b/arm_virt/liteos_a/README_zh.md @@ -35,9 +35,7 @@ hb set hb build ``` -这个命令构建会产生 `OHOS_Image.bin`、`rootfs_jffs2.img` 和 `userfs_jffs2.img` 的镜像文件。 - -在构建完成之后,对应的镜像文件在out/arm_virt/qemu_small_system_demo/目录。 +在构建完成之后,对应的结果文件在out/arm_virt/qemu_small_system_demo/目录。 ## 5. 在Qemu中运行镜像 @@ -51,29 +49,11 @@ b) 制作以及运行镜像 在代码根目录下,编译后会生成qemu-run脚本,可直接运行该脚本,根据脚本提示制作、运行镜像。 -执行`./qemu-run --help`提示如下: - -``` -Usage: ./qemu-run [OPTION]... -Make a qemu image(flash.img) for OHOS, and run the image in qemu according -to the options. - - Options: - - -f, --force rebuild flash.img - -n, --net-enable enable net - -l, --local-desktop no VNC - -b, --bootargs additional boot arguments(-bk1=v1,k2=v2...) - -g, --gdb enable gdb for kernel - -h, --help print help info - - By default, flash.img will not be rebuilt if exists, and net will not - be enabled, gpu enabled and waiting for VNC connection at port 5920. -``` +执行`./qemu-run --help`获取帮助。 -网卡模拟的是无线网卡wlan0,但无真的wifi功能;默认不加参数的情况下,网络不会自动配置。当根目录镜像文件flash.img存在时,镜像不会被重新制作。 +网卡模拟的是无线网卡wlan0,但无真的wifi功能;默认不加参数的情况下,网络不会自动配置。 -提示:初次运行脚本时,系统还会生成MMC镜像,主要内容为系统和用户数据文件,第1个分区将安装在/sdcard目录,第2个分区安装在/userdata目录,第3个分区保留。镜像存放在OHOS源码树的out目录下,文件名为smallmmc.img。只要不被删除,后续就不再重新制作该镜像。具体请见vendor/ohemu/qemu_small_system_demo/qemu_run.sh。 +当镜像文件out/smallmmc.img存在时,默认不会被重新制作。MMC镜像主要内容为rootfs和userfs,第1个分区为rootfs,第2个分区为userfs,安装在/storage目录,第3个分区为用户数据,安装在/userdata目录。 c) 退出qemu环境 @@ -176,8 +156,8 @@ gdb-multiarch out/arm_virt/qemu_small_system_demo/OHOS_Image ``` qemu-system-arm -M virt,gic-version=2,secure=on -cpu cortex-a7 -smp cpus=1 -m 1G \ - -drive if=pflash,file=flash.img,format=raw \ - -drive if=none,file=./out/smallmmc.img,format=qcow2,id=mmc + -bios out/arm_virt/qemu_small_system_demo/OHOS_Image.bin \ + -drive if=none,file=out/smallmmc.img,format=raw,id=mmc -device virtio-blk-device,drive=mmc \ -netdev bridge,id=net0 \ -device virtio-net-device,netdev=net0,mac=12:22:33:44:55:66 \ @@ -194,7 +174,7 @@ gdb-multiarch out/arm_virt/qemu_small_system_demo/OHOS_Image -cpu CPU型号 -smp SMP设置,单核 -m 虚拟机可使用的内存限制 - -drive if=pflash CFI闪存盘设置 + -bios 内核启动映像 -drive if=none 块设备映像文件设置 -netdev [可选]网卡后端设置,桥接类型 -device virtio-blk-device 块存储设备 diff --git a/arm_virt/liteos_a/config.gni b/arm_virt/liteos_a/config.gni index a023998..be2e5b8 100644 --- a/arm_virt/liteos_a/config.gni +++ b/arm_virt/liteos_a/config.gni @@ -58,4 +58,4 @@ board_adapter_dir = "//device/qemu/hardware" board_configed_sysroot = "" # Board storage type, it used for file system generation. -storage_type = "spinor" +storage_type = "emmc" diff --git a/arm_virt/liteos_a/hdf_config/cfiflash/cfi_config.hcs b/arm_virt/liteos_a/hdf_config/cfiflash/cfi_config.hcs deleted file mode 100644 index af8bcf7..0000000 --- a/arm_virt/liteos_a/hdf_config/cfiflash/cfi_config.hcs +++ /dev/null @@ -1,12 +0,0 @@ -root { - storage { - template cfi_flash_attr { - match_attr = ""; - pbase0 = 0x00000000; // slot0 jffs2 - pbase1 = 0x04000000; // slot1 vfat - } - cfiflash0 :: cfi_flash_attr { - match_attr = "qemu_virt_cfi_0"; - } - } -} diff --git a/arm_virt/liteos_a/hdf_config/device_info/device_info.hcs b/arm_virt/liteos_a/hdf_config/device_info/device_info.hcs index 4cea075..6ab0c2a 100644 --- a/arm_virt/liteos_a/hdf_config/device_info/device_info.hcs +++ b/arm_virt/liteos_a/hdf_config/device_info/device_info.hcs @@ -99,16 +99,6 @@ } storage :: host { hostName = "storage_host"; - cfi_flash :: device { - cfi_flash0 :: deviceNode { - policy = 0; - priority = 50; - permission = 0660; - moduleName = "cfi_flash_driver"; - serviceName = "HDF_PLATFORM_CFI_0"; - deviceMatchAttr = "qemu_virt_cfi_0"; - } - } device_mmc:: device { device0 :: deviceNode { policy = 1; diff --git a/arm_virt/liteos_a/hdf_config/hdf.hcs b/arm_virt/liteos_a/hdf_config/hdf.hcs index 23d6815..9f1d7be 100644 --- a/arm_virt/liteos_a/hdf_config/hdf.hcs +++ b/arm_virt/liteos_a/hdf_config/hdf.hcs @@ -1,6 +1,5 @@ #include "device_info/device_info.hcs" #include "uart/uart_config.hcs" -#include "cfiflash/cfi_config.hcs" #include "sdio/sdio_config.hcs" #include "wifi/wlan_platform.hcs" #include "mmc/mmc_config.hcs" diff --git a/drivers/BUILD.gn b/drivers/BUILD.gn index 2d1b025..d85ccf5 100644 --- a/drivers/BUILD.gn +++ b/drivers/BUILD.gn @@ -31,7 +31,6 @@ import("//drivers/hdf_core/adapter/khdf/liteos/hdf.gni") group("drivers") { deps = [ - "cfiflash", "char", "uart", "virtio", @@ -39,5 +38,4 @@ group("drivers") { } config("public") { - configs = [ "cfiflash:public" ] } diff --git a/drivers/Kconfig b/drivers/Kconfig index 7aa54be..54dd9a9 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -43,7 +43,7 @@ config DRIVERS_NETDEV # mtd configs tart config DRIVERS_MTD bool "Enable MTD" - default y + default n depends on DRIVERS && FS_VFS help Answer Y to enable LiteOS support jffs2 multipartion. @@ -80,3 +80,7 @@ config DRIVERS_MTD_NAND Answer Y to support nandflash. # mtd configs end + +config DRIVERS_EMMC + bool "Enable MMC" + default y diff --git a/drivers/cfiflash/BUILD.gn b/drivers/cfiflash/BUILD.gn deleted file mode 100644 index 24216a5..0000000 --- a/drivers/cfiflash/BUILD.gn +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. -# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. -# -# 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 of the copyright holder 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 HOLDER 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. - -import("//drivers/hdf_core/adapter/khdf/liteos/hdf.gni") - -module_name = get_path_info(rebase_path("."), "name") -hdf_driver(module_name) { - sources = [ - "cfiflash.c", - "hdf_cfi.c", - ] -} - -config("public") { - include_dirs = [ "." ] -} diff --git a/drivers/cfiflash/Makefile b/drivers/cfiflash/Makefile deleted file mode 100644 index 43858e2..0000000 --- a/drivers/cfiflash/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -include $(LITEOSTOPDIR)/../../drivers/hdf_core/adapter/khdf/liteos/lite.mk -MODULE_NAME := $(notdir $(shell pwd)) -#LOCAL_INCLUDE := -I $(LITEOSTOPDIR)/ -LOCAL_SRCS := cfiflash.c hdf_cfi.c -LOCAL_CFLAGS += $(LOCAL_INCLUDE) - -include $(HDF_DRIVER) diff --git a/drivers/cfiflash/cfiflash.c b/drivers/cfiflash/cfiflash.c deleted file mode 100644 index c88da9c..0000000 --- a/drivers/cfiflash/cfiflash.c +++ /dev/null @@ -1,384 +0,0 @@ -/* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. - * 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. - */ -/* - * simple CFI flash driver for QEMU arm 'virt' machine, with: - * - * 64M = 1 region * 256 Erase Blocks * 256K(2 banks: 64 pages * 4096B) - * 32 bits, Intel command set - */ - -#include "user_copy.h" -#include "disk.h" -#include "cfiflash.h" -#include "cfiflash_internal.h" - -#define BIT_SHIFT8 8 -#define WORD_ALIGN 4 -#define BYTE_WORD_SHIFT 2 - -static inline unsigned CfiFlashSec2Bytes(unsigned sector) -{ - return sector << CFIFLASH_SEC_SIZE_BITS; -} - -static inline unsigned CfiFlashPageWordOffset(unsigned wordOffset) -{ - return wordOffset & CFIFLASH_PAGE_WORDS_MASK; -} - -static inline unsigned CfiFlashEraseBlkWordAddr(unsigned wordOffset) -{ - return wordOffset & CFIFLASH_ERASEBLK_WORDMASK; -} - -static inline unsigned W2B(unsigned words) -{ - return words << BYTE_WORD_SHIFT; -} - -static inline unsigned B2W(unsigned bytes) -{ - return bytes >> BYTE_WORD_SHIFT; -} - -static inline int CfiFlashQueryQRY(uint8_t *p) -{ - unsigned wordOffset = CFIFLASH_QUERY_QRY; - - if (p[W2B(wordOffset++)] == 'Q') { - if (p[W2B(wordOffset++)] == 'R') { - if (p[W2B(wordOffset)] == 'Y') { - return 0; - } - } - } - return -1; -} - -static inline int CfiFlashQueryUint8(unsigned wordOffset, uint8_t expect, uint8_t *p) -{ - if (p[W2B(wordOffset)] != expect) { - return -1; - } - return 0; -} - -static inline int CfiFlashQueryUint16(unsigned wordOffset, uint16_t expect, uint8_t *p) -{ - uint16_t v; - - v = (p[W2B(wordOffset + 1)] << BIT_SHIFT8) + p[W2B(wordOffset)]; - if (v != expect) { - return -1; - } - return 0; -} - -static inline int CfiFlashIsReady(unsigned wordOffset, uint32_t *p) -{ - DSB; - p[wordOffset] = CFIFLASH_CMD_READ_STATUS; - DSB; - return p[wordOffset] & CFIFLASH_STATUS_READY_MASK; -} - -/* all in word(4 bytes) measure */ -static void CfiFlashWriteBuf(unsigned wordOffset, const uint32_t *buffer, size_t words, uint32_t *p) -{ - unsigned i, blkAddr, wordCount; - - /* first write might not be Page aligned */ - i = CFIFLASH_PAGE_WORDS - CfiFlashPageWordOffset(wordOffset); - wordCount = (i > words) ? words : i; - - while (words) { - /* command buffer-write begin to Erase Block address */ - blkAddr = CfiFlashEraseBlkWordAddr(wordOffset); - p[blkAddr] = CFIFLASH_CMD_BUFWRITE; - - /* write words count, 0-based */ - DSB; - p[blkAddr] = wordCount - 1; - - /* program word data to actual address */ - for (i = 0; i < wordCount; i++, wordOffset++, buffer++) { - p[wordOffset] = *buffer; - } - - /* command buffer-write end to Erase Block address */ - p[blkAddr] = CFIFLASH_CMD_CONFIRM; - while (!CfiFlashIsReady(blkAddr, p)) { } - - words -= wordCount; - wordCount = (words >= CFIFLASH_PAGE_WORDS) ? CFIFLASH_PAGE_WORDS : words; - } - - p[0] = CFIFLASH_CMD_CLEAR_STATUS; -} - -static int CfiFlashQuery(uint8_t *p) -{ - uint32_t *base = (uint32_t *)p; - base[CFIFLASH_QUERY_BASE] = CFIFLASH_QUERY_CMD; - - if (CfiFlashQueryQRY(p)) { - goto ERR_OUT; - } - - if (CfiFlashQueryUint16(CFIFLASH_QUERY_VENDOR, CFIFLASH_EXPECT_VENDOR, p)) { - goto ERR_OUT; - } - - if (CfiFlashQueryUint8(CFIFLASH_QUERY_SIZE, CFIFLASH_ONE_BANK_BITS, p)) { - goto ERR_OUT; - } - - if (CfiFlashQueryUint16(CFIFLASH_QUERY_PAGE_BITS, CFIFLASH_EXPECT_PAGE_BITS, p)) { - goto ERR_OUT; - } - - if (CfiFlashQueryUint8(CFIFLASH_QUERY_ERASE_REGION, CFIFLASH_EXPECT_ERASE_REGION, p)) { - goto ERR_OUT; - } - - if (CfiFlashQueryUint16(CFIFLASH_QUERY_BLOCKS, CFIFLASH_EXPECT_BLOCKS, p)) { - goto ERR_OUT; - } - - if (CfiFlashQueryUint16(CFIFLASH_QUERY_BLOCK_SIZE, CFIFLASH_EXPECT_BLOCK_SIZE, p)) { - goto ERR_OUT; - } - - base[0] = CFIFLASH_CMD_RESET; - return 0; - -ERR_OUT: - dprintf("[%s]not supported CFI flash\n", __FUNCTION__); - return -1; -} - -int CfiFlashInit(uint8_t *p) -{ - struct MtdDev *slot = GetCfiMtdDev(); - - dprintf("[%s]CFI flash init start ...\n", __FUNCTION__); - if (CfiFlashQuery(p)) { - return -1; - } - - /* slot 0 used as MTD device for jffs2 rootfs, slot 1 as block device */ - if (slot->priv == NULL) { - slot->priv = p; - } else if (*(uint16_t *)&p[BS_SIG55AA] == BS_SIG55AA_VALUE) { - int id = los_alloc_diskid_byname(CFI_BLK_DRIVER); - (void)los_disk_init(CFI_BLK_DRIVER, GetCfiBlkOps(), p, id, NULL); - } else { - return 0; - } - - dprintf("[%s]CFI flash init end ...\n", __FUNCTION__); - return 0; -} - -int CfiBlkOpen(struct Vnode *vnode) -{ - return 0; -} - -int CfiBlkClose(struct Vnode *vnode) -{ - return 0; -} - -static ssize_t CfiPreRead(char *buffer, unsigned bytes, char **newbuf) -{ - if (LOS_IsUserAddressRange((VADDR_T)buffer, bytes)) { - *newbuf = LOS_MemAlloc(m_aucSysMem0, bytes); - if (*newbuf == NULL) { - dprintf("[%s]fatal memory allocation error\n", __FUNCTION__); - return -ENOMEM; - } - } else if ((VADDR_T)buffer + bytes < (VADDR_T)buffer) { - dprintf("[%s]invalid argument: buffer=%#x, size=%#x\n", __FUNCTION__, buffer, bytes); - return -EFAULT; - } else { - *newbuf = buffer; - } - return 0; -} - -static ssize_t CfiPostRead(char *buffer, char *newbuf, unsigned bytes, ssize_t ret) -{ - if (newbuf != buffer) { - if (LOS_ArchCopyToUser(buffer, newbuf, bytes) != 0) { - dprintf("[%s]LOS_ArchCopyToUser error\n", __FUNCTION__); - ret = -EFAULT; - } - - if (LOS_MemFree(m_aucSysMem0, newbuf) != 0) { - dprintf("[%s]LOS_MemFree error\n", __FUNCTION__); - ret = -EFAULT; - } - } - return ret; -} - -ssize_t CfiBlkRead(struct Vnode *vnode, unsigned char *buffer, - unsigned long long startSector, unsigned int nSectors) -{ - unsigned int i, wordOffset, bytes; - uint32_t *p; - uint32_t *base = ((struct drv_data*)(vnode->data))->priv; - ssize_t ret; - - bytes = CfiFlashSec2Bytes(nSectors); - wordOffset = B2W(CfiFlashSec2Bytes(startSector)); - - if ((ret = CfiPreRead((char*)buffer, bytes, (char**)&p))) { - return ret; - } - - for (i = 0; i < B2W(bytes); i++) { - p[i] = base[wordOffset + i]; - } - ret = nSectors; - - return CfiPostRead((char*)buffer, (char*)p, bytes, ret); -} - -static ssize_t CfiPreWrite(const char *buffer, unsigned bytes, char **newbuf) -{ - if (LOS_IsUserAddressRange((VADDR_T)buffer, bytes)) { - *newbuf = LOS_MemAlloc(m_aucSysMem0, bytes); - if (*newbuf == NULL) { - dprintf("[%s]fatal memory allocation error\n", __FUNCTION__); - return -ENOMEM; - } - - if (LOS_ArchCopyFromUser(*newbuf, buffer, bytes)) { - dprintf("[%s]LOS_ArchCopyFromUser error\n", __FUNCTION__); - LOS_MemFree(m_aucSysMem0, *newbuf); - return -EFAULT; - } - } else if ((VADDR_T)buffer + bytes < (VADDR_T)buffer) { - dprintf("[%s]invalid argument\n", __FUNCTION__); - return -EFAULT; - } else { - *newbuf = (char*)buffer; - } - return 0; -} - -static ssize_t CfiPostWrite(const char *buffer, char *newbuf, ssize_t ret) -{ - if (newbuf != buffer) { - if (LOS_MemFree(m_aucSysMem0, newbuf) != 0) { - dprintf("[%s]LOS_MemFree error\n", __FUNCTION__); - return -EFAULT; - } - } - return ret; -} - -ssize_t CfiBlkWrite(struct Vnode *vnode, const unsigned char *buffer, - unsigned long long startSector, unsigned int nSectors) -{ - unsigned int wordOffset, bytes; - unsigned char *p; - ssize_t ret; - - bytes = CfiFlashSec2Bytes(nSectors); - wordOffset = B2W(CfiFlashSec2Bytes(startSector)); - - if ((ret = CfiPreWrite((const char*)buffer, bytes, (char**)&p))) { - return ret; - } - - CfiFlashWriteBuf(wordOffset, (uint32_t *)p, B2W(bytes), ((struct drv_data*)(vnode->data))->priv); - ret = nSectors; - - return CfiPostWrite((const char*)buffer, (char*)p, ret); -} - -int CfiBlkGeometry(struct Vnode *vnode, struct geometry *geometry) -{ - geometry->geo_available = TRUE, - geometry->geo_mediachanged = FALSE; - geometry->geo_writeenabled = TRUE; - geometry->geo_nsectors = CFIFLASH_SECTORS; - geometry->geo_sectorsize = CFIFLASH_SEC_SIZE; - - return 0; -} - -int CfiMtdErase(struct MtdDev *mtd, UINT64 start, UINT64 bytes, UINT64 *failAddr) -{ - uint32_t blkAddr, count, i; - uint32_t *p = mtd->priv; - - blkAddr = CfiFlashEraseBlkWordAddr(B2W(start)); - count = (CfiFlashEraseBlkWordAddr(B2W(start + bytes - 1)) - blkAddr) / CFIFLASH_ERASEBLK_WORDS + 1; - - for (i = 0; i < count; i++) { - p[blkAddr] = CFIFLASH_CMD_ERASE; - DSB; - p[blkAddr] = CFIFLASH_CMD_CONFIRM; - while (!CfiFlashIsReady(blkAddr, p)) { } - - blkAddr += CFIFLASH_ERASEBLK_WORDS; - } - - p[0] = CFIFLASH_CMD_CLEAR_STATUS; - return 0; -} - -int CfiMtdRead(struct MtdDev *mtd, UINT64 start, UINT64 bytes, const char *buf) -{ - UINT64 i; - char *p; - ssize_t ret; - uint8_t *base = mtd->priv; - - if ((ret = CfiPreRead((char*)buf, bytes, &p))) { - return ret; - } - - for (i = 0; i < bytes; i++) { - p[i] = base[start + i]; - } - ret = (int)bytes; - - return CfiPostRead((char*)buf, p, bytes, ret); -} - -int CfiMtdWrite(struct MtdDev *mtd, UINT64 start, UINT64 bytes, const char *buf) -{ - char *p; - ssize_t ret; - - if (!IS_ALIGNED(start, WORD_ALIGN) || !IS_ALIGNED(bytes, WORD_ALIGN)) { - dprintf("[%s]not aligned with 4B: start=%#0llx, bytes=%#0llx\n", __FUNCTION__, start, bytes); - return -EINVAL; - } - - if ((ret = CfiPreWrite(buf, bytes, &p))) { - return ret; - } - - CfiFlashWriteBuf((int)B2W(start), (uint32_t *)p, (size_t)B2W(bytes), mtd->priv); - ret = (int)bytes; - - return CfiPostWrite(buf, p, ret); -} diff --git a/drivers/cfiflash/cfiflash.h b/drivers/cfiflash/cfiflash.h deleted file mode 100644 index 8477e4f..0000000 --- a/drivers/cfiflash/cfiflash.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. - * 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 __CFIFLASH_H__ -#define __CFIFLASH_H__ - -#include "fs/driver.h" -#include "mtd_dev.h" - -#define CFI_DRIVER "/dev/cfiflash" -#define CFI_BLK_DRIVER "/dev/cfiblk" -#define FLASH_TYPE "cfi-flash" - -#define CFIFLASH_CAPACITY (64 * 1024 * 1024) -#define CFIFLASH_ERASEBLK_SIZE (128 * 1024 * 2) /* fit QEMU of 2 banks */ -#define CFIFLASH_ERASEBLK_WORDS (CFIFLASH_ERASEBLK_SIZE / sizeof(uint32_t)) -#define CFIFLASH_ERASEBLK_WORDMASK (~(CFIFLASH_ERASEBLK_WORDS - 1)) - -#define CFIFLASH_ROOT_ADDR (10 * 1024 * 1024) -#define CFIFLASH_BOOTARGS_ADDR (CFIFLASH_ROOT_ADDR - CFIFLASH_ERASEBLK_SIZE) - -struct block_operations *GetCfiBlkOps(void); -struct MtdDev *GetCfiMtdDev(void); - -#endif diff --git a/drivers/cfiflash/cfiflash_internal.h b/drivers/cfiflash/cfiflash_internal.h deleted file mode 100644 index b995099..0000000 --- a/drivers/cfiflash/cfiflash_internal.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. - * 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 __CFIFLASH_INTERNAL_H__ -#define __CFIFLASH_INTERNAL_H__ - -#include "cfiflash.h" - -#define HDF_LOG_TAG cfi_flash_driver - -#define CFIFLASH_ONE_BANK_BITS 25 - -#define CFIFLASH_SEC_SIZE 512 -#define CFIFLASH_SEC_SIZE_BITS 9 -#define CFIFLASH_SECTORS (CFIFLASH_CAPACITY / CFIFLASH_SEC_SIZE) - -#define CFIFLASH_PAGE_SIZE (2048 * 2) /* fit QEMU of 2 banks */ -#define CFIFLASH_PAGE_WORDS (CFIFLASH_PAGE_SIZE / sizeof(uint32_t)) -#define CFIFLASH_PAGE_WORDS_MASK (CFIFLASH_PAGE_WORDS - 1) - -#define CFIFLASH_QUERY_CMD 0x98 -#define CFIFLASH_QUERY_BASE 0x55 -#define CFIFLASH_QUERY_QRY 0x10 -#define CFIFLASH_QUERY_VENDOR 0x13 -#define CFIFLASH_QUERY_SIZE 0x27 -#define CFIFLASH_QUERY_PAGE_BITS 0x2A -#define CFIFLASH_QUERY_ERASE_REGION 0x2C -#define CFIFLASH_QUERY_BLOCKS 0x2D -#define CFIFLASH_QUERY_BLOCK_SIZE 0x2F -#define CFIFLASH_EXPECT_VENDOR 1 /* Intel command set */ -#define CFIFLASH_EXPECT_PAGE_BITS 11 -#define CFIFLASH_EXPECT_BLOCKS 255 /* plus 1: # of blocks */ -#define CFIFLASH_EXPECT_BLOCK_SIZE 512 /* times 256: block size */ -#define CFIFLASH_EXPECT_ERASE_REGION 1 - -#define CFIFLASH_CMD_ERASE 0x20 -#define CFIFLASH_CMD_CLEAR_STATUS 0x50 -#define CFIFLASH_CMD_READ_STATUS 0x70 -#define CFIFLASH_CMD_CONFIRM 0xD0 -#define CFIFLASH_CMD_BUFWRITE 0xE8 -#define CFIFLASH_CMD_RESET 0xFF - -#define CFIFLASH_STATUS_READY_MASK 0x80 - -int CfiFlashInit(uint8_t *p); -int CfiBlkOpen(struct Vnode *vnode); -int CfiBlkClose(struct Vnode *vnode); -ssize_t CfiBlkRead(struct Vnode *vnode, unsigned char *buffer, - unsigned long long start_sector, unsigned int nsectors); -ssize_t CfiBlkWrite(struct Vnode *vnode, const unsigned char *buffer, - unsigned long long start_sector, unsigned int nsectors); -int CfiBlkGeometry(struct Vnode *vnode, struct geometry *geometry); - -int CfiMtdErase(struct MtdDev *mtd, UINT64 start, UINT64 bytes, UINT64 *failAddr); -int CfiMtdRead(struct MtdDev *mtd, UINT64 start, UINT64 bytes, const char *buf); -int CfiMtdWrite(struct MtdDev *mtd, UINT64 start, UINT64 bytes, const char *buf); - -#endif diff --git a/drivers/cfiflash/hdf_cfi.c b/drivers/cfiflash/hdf_cfi.c deleted file mode 100644 index 8a54788..0000000 --- a/drivers/cfiflash/hdf_cfi.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. - * 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 "hdf_log.h" -#include "hdf_base.h" -#include "hdf_device_desc.h" -#include "device_resource_if.h" -#include "los_vm_zone.h" -#include "cfiflash_internal.h" - -static struct block_operations g_cfiBlkops = { - CfiBlkOpen, - CfiBlkClose, - CfiBlkRead, - CfiBlkWrite, - CfiBlkGeometry, - NULL, /* int (*ioctl)(struct Vnode *vnode, int cmd, unsigned long arg); */ - NULL, /* int (*unlink)(struct Vnode *vnode); */ -}; - -struct block_operations *GetCfiBlkOps() -{ - return &g_cfiBlkops; -} - -static struct MtdDev g_cfiMtdDev = { - .priv = NULL, - .type = MTD_NORFLASH, - .size = CFIFLASH_CAPACITY, - .eraseSize = CFIFLASH_ERASEBLK_SIZE, - .erase = CfiMtdErase, - .read = CfiMtdRead, - .write = CfiMtdWrite, -}; - -struct MtdDev *GetCfiMtdDev() -{ - return &g_cfiMtdDev; -} - -int HdfCfiDriverInit(struct HdfDeviceObject *deviceObject) -{ - int ret; - uint32_t pbase; - struct DeviceResourceIface *p = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE); - - if (deviceObject == NULL || deviceObject->property == NULL) { - HDF_LOGE("[%s]deviceObject or property is null", __func__); - return HDF_ERR_INVALID_PARAM; - } - - if ((ret = p->GetUint32(deviceObject->property, "pbase0", &pbase, 0))) { - HDF_LOGE("[%s]GetUint32 error:%d", __func__, ret); - return HDF_FAILURE; - } - if(CfiFlashInit((uint8_t *)IO_DEVICE_ADDR(pbase))) { - return HDF_ERR_NOT_SUPPORT; - } - - if (p->GetUint32(deviceObject->property, "pbase1", &pbase, 0) == 0) { - (void)CfiFlashInit((uint8_t *)IO_DEVICE_ADDR(pbase)); - } - - return HDF_SUCCESS; -} - -struct HdfDriverEntry g_cfiDriverEntry = { - .moduleVersion = 1, - .moduleName = "cfi_flash_driver", - .Bind = NULL, - .Init = HdfCfiDriverInit, - .Release = NULL, -}; - -HDF_INIT(g_cfiDriverEntry); diff --git a/drivers/lite.mk b/drivers/lite.mk index aef511f..313d9ed 100644 --- a/drivers/lite.mk +++ b/drivers/lite.mk @@ -17,8 +17,7 @@ SOC_PLATFORM := $(subst $\",,$(LOSCFG_PLATFORM)) DRIVERS_ROOT := $(LITEOSTOPDIR)/../../device/$(SOC_COMPANY)/drivers/ ###################### SELF-DEVELOPED DRIVER ###################### -LITEOS_BASELIB += -lcfiflash -lvirtio -lplatform_char -LIB_SUBDIRS += $(DRIVERS_ROOT)/cfiflash +LITEOS_BASELIB += -lvirtio -lplatform_char LIB_SUBDIRS += $(DRIVERS_ROOT)/virtio LIB_SUBDIRS += $(DRIVERS_ROOT)/char diff --git a/drivers/virtio/virtblock.c b/drivers/virtio/virtblock.c index 94d13a2..b94c03c 100644 --- a/drivers/virtio/virtblock.c +++ b/drivers/virtio/virtblock.c @@ -298,8 +298,8 @@ static void VirtMmcFillRespCid(struct MmcCmd *cmd, const struct Virtblk *blk) { uint8_t *b = (uint8_t *)cmd->resp; - /* removable card, so OHOS will auto-detect partitions */ - FillCidCsdBits(cmd->resp, MMC_CID_CBX_SBIT, MMC_CID_CBX_WIDTH, 0); + /* embedded card, so can leverage kernel eMMC rootfs support */ + FillCidCsdBits(cmd->resp, MMC_CID_CBX_SBIT, MMC_CID_CBX_WIDTH, 1); (void)memcpy_s(&b[MMC_CID_PNM_SBYTE], MMC_CID_PNM_BYTES, VIRTMMIO_BLK_NAME, MMC_CID_PNM_BYTES); *(uint32_t *)&b[MMC_CID_PSN_SBYTE] = (uint32_t)blk; /* unique sn */ -- Gitee