diff --git a/README.en.md b/README.en.md index 21ff349feda0ab124cd1e68d73460a4175b0b398..bc589664f627255753d63475d3cb79d1f1810e75 100644 --- a/README.en.md +++ b/README.en.md @@ -15,3 +15,6 @@ The qemu repository is to use QEMU to emulate different hardware platforms. ``` +#### HOWTOs + +[QEMU ARM Virt](https://gitee.com/openharmony/device_qemu/blob/master/arm/virt/README.en.md) diff --git a/arm/arm_init/virt/BUILD.gn b/arm/arm_init/virt/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..072201c00a93a7a471a52b248bd2c1b06944dcf5 --- /dev/null +++ b/arm/arm_init/virt/BUILD.gn @@ -0,0 +1,10 @@ +# Copyright (c) 2020 Huawei Device Co., Ltd. All rights reserved. + +import("//build/lite/config/component/lite_component.gni") + +build_ext_component("virt_make_kernel") { + exec_path = rebase_path(".", root_build_dir) + outdir = rebase_path("$root_out_dir") + command = "./build.sh ${outdir} ${board_name} ${ohos_kernel_type} ${ohos_build_compiler}" + deps = ["//kernel/liteos_a:kernel"] +} diff --git a/arm/arm_init/virt/Makefile b/arm/arm_init/virt/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..f2efd59965ad6d629475e6228780286c7dd35acd --- /dev/null +++ b/arm/arm_init/virt/Makefile @@ -0,0 +1,12 @@ + +LITEOSTOPDIR := $(shell pwd)/../../../../../kernel/liteos_a +CONFIG_FILE := $(LITEOSTOPDIR)/.config + +ifeq ($(wildcard $(CONFIG_FILE)), ) +$(error "########################kernel is not compiled################################") +endif +include $(LITEOSTOPDIR)/config.mk + +MPP_DIR := $(shell pwd)/../../virt/module_init/ + +include virt.mak diff --git a/arm/arm_init/virt/build.sh b/arm/arm_init/virt/build.sh new file mode 100755 index 0000000000000000000000000000000000000000..50ea38958035e0a9ae17aed1c8d7898db7877557 --- /dev/null +++ b/arm/arm_init/virt/build.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# Copyright (c) 2020 Huawei Device Co., Ltd. All rights reserved. +# +# Compile mpp/sample project, this is the entrance script + +# error out on errors +set -e +OUT_DIR="$1" + +function main(){ + ROOT_DIR=$(cd $(dirname "$0");pwd) + cd "$ROOT_DIR" + make clean && make -j16 OUTDIR=$OUT_DIR + cp OHOS_Image* $OUT_DIR/ +} +main "$@" diff --git a/arm/arm_init/virt/virt.mak b/arm/arm_init/virt/virt.mak new file mode 100644 index 0000000000000000000000000000000000000000..950aa922b269bbedc3189ca9721c014b98e3233b --- /dev/null +++ b/arm/arm_init/virt/virt.mak @@ -0,0 +1,46 @@ +# Qemu ARM Virtual Platform +REL_LIB := $(MPP_DIR)/lib +REL_INC := $(MPP_DIR)/include +ARCH_LIBNAME := virt + +######################################################################### + +TARGET := OHOS_Image + +TARGET_PATH := $(PWD) + +# compile OHOS +# TODO + +LITEOS_LIBDEPS = --start-group $(LITEOS_LIBDEP) --end-group $(LITEOS_TABLES_LDFLAGS) + +LDFLAGS := -L$(OUTDIR)/obj/kernel/liteos_a/lib $(LITEOS_LDFLAGS) --gc-sections + +# target source +SRCS := $(MPP_DIR)/src/system_init.c + +OBJS := $(SRCS:%.c=%.o) +OBJS += $(COMM_OBJ) + +BIN := $(TARGET_PATH)/$(TARGET).bin +MAP := $(TARGET_PATH)/$(TARGET).map + +all: $(BIN) + +$(BIN):$(TARGET) + @$(OBJCOPY) -O binary $(TARGET_PATH)/$(TARGET) $(BIN) + cp $(TARGET_PATH)/$(TARGET)* $(OUTDIR) + +$(TARGET): $(OBJS) + $(LD) $(LDFLAGS) -Map=$(MAP) -o $(TARGET_PATH)/$(TARGET) $(OBJS) $(LITEOS_LIBDEPS) + @$(OBJDUMP) -d $(TARGET_PATH)/$(TARGET) > $(TARGET_PATH)/$(TARGET).asm + +$(OBJS):%.o:%.c + @$(CC) $(CFLAGS) $(LITEOS_CFLAGS) -c $< -o $@ + +clean: + @rm -f $(TARGET_PATH)/$(TARGET) $(BIN) $(MAP) $(TARGET_PATH)/*.asm + @rm -f $(OBJS) + +.PHONY : clean all + diff --git a/arm/platform/Kconfig b/arm/platform/Kconfig new file mode 100644 index 0000000000000000000000000000000000000000..8d8b443bffe066a7910cc5dacfbc6915a0e72a19 --- /dev/null +++ b/arm/platform/Kconfig @@ -0,0 +1,7 @@ +config DRIVERS_HDF_PLATFORM + bool "Enable HDF platform driver" + default n + depends on DRIVERS_HDF + help + Answer Y to enable HDF platform driver. + diff --git a/arm/platform/LICENSE b/arm/platform/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..8f4e29934050fbd54304ff7039dde3036a42491c --- /dev/null +++ b/arm/platform/LICENSE @@ -0,0 +1,63 @@ +End User License Agreement + +THIS END USER LICENSE AGREEMENT (“AGREEMENT”) IS A LEGAL AGREEMENT BETWEEN YOU (EITHER A SINGLE INDIVIDUAL, OR SINGLE LEGAL ENTITY) AND HISILICON (SHANGHAI) TECHNOLOGIES CO., LTD. ("HISILICON") FOR THE USE OF THE SOFTWARE ACCOMPANYING THIS AGREEMENT. HISILICON IS ONLY WILLING TO LICENSE THE SOFTWARE TO YOU ON CONDITION THAT YOU ACCEPT ALL OF THE TERMS IN THIS AGREEMENT. BY CLICKING “I AGREE” OR BY INSTALLING OR OTHERWISE USING OR COPYING THE SOFTWARE YOU INDICATE THAT YOU AGREE TO BE BOUND BY ALL OF THE TERMS OF THIS AGREEMENT. IF YOU DO NOT AGREE TO THE TERMS OF THIS AGREEMENT, HISILICON IS UNWILLING TO LICENSE THE SOFTWARE TO YOU AND YOU MAY NOT INSTALL, USE OR COPY THE SOFTWARE, AND YOU SHALL PROMPTLY DESTROY, DELETE, OR RETURN THE SOFTWARE TO YOUR SUPPLIER. + +“SOFTWARE” means the software in object code provided under the terms of this Agreement. + +Shenzhen Longgang District is the signing place of this Agreement. + +1. GRANT OF LICENSE +In consideration of your agreement to abide by the following terms, and subject to the terms and conditions of this Agreement, HISILICON hereby grants YOU, a non-transferable, non-exclusive, royalty-free, revocable, worldwide copyright license (without the right to sublicense) to use and copy the SOFTWARE solely for the purpose of designing or developing applications for use in conjunction with Hisilicon chip. +. + +All rights to the SOFTWARE and all intellectual property rights contained therein shall remain the sole and exclusive property of HISILICON. The SOFTWARE is licensed not sold. Except as expressly licensed in Clause 1, in no event shall the license granted in this Clause 1 be construed as granting YOU expressly or by implication, estoppels or otherwise, licenses to any intellectual property rights, including but not limited to patent rights, copyrights, trademark or trade secret in the SOFTWARE. + +No right is granted to YOU under this Agreement to manufacture, have manufactured, or sell, supply or distribute any products which have taken into use or which embody any of the SOFTWARE or any of the intellectual property rights embodied therein. + +2. RESTRICTIONS +This Agreement does not prevent YOU from using the SOFTWARE for internal benchmarking purposes. + +However, YOU shall treat any and all benchmarking data relating to the SOFTWARE, and any other results of your use or testing of the SOFTWARE which are indicative of its performance, efficacy, reliability or quality, as confidential information and YOU shall not disclose such information to any third party without the express written permission of HISILICON. + +YOU shall reproduce and not remove or obscure any notice incorporated by HISILICON in the SOFTWARE to protect HISILICON’s intellectual property rights embodied therein. + +YOU shall not decompile, disassemble, or reverse engineer the SOFTWARE. + +YOU shall not distribute the SOFTWARE under an open source license as listed by the Open Source Initiative (a non-profit corporation whose website is www.opensource.org), or other license which requires the source code or object code of the SOFTWARE to be licensed or otherwise shared with any third party. + +3. FEEDBACK +YOU may choose to provide suggestions, comments, feedback, ideas, modifications or know-how (whether in oral or written form) relating to the use of the SOFTWARE ("Feedback") to HISILICON under the terms of this Agreement. YOU hereby grants to HISILICON and its affiliates, under all of you and your affiliates’ (as applicable) intellectual property rights, a perpetual, irrevocable, royalty free, non-exclusive, worldwide license to (i) use, copy and modify the Feedback; (ii) sell, supply, or otherwise distribute the Feedback; (iii) design, have designed, manufacture, have manufactured, use, import, sell, and otherwise distribute and dispose of products that incorporate the Feedback; and (iv) sublicense (together with the rights to further sublicense) the rights granted in this paragraph to any third party. + +4. NO WARRANTY +YOU AGREE THAT THE SOFTWARE IS PROVIDED BY HISILICON ON AN "AS IS" BASIS. HISILICON MAKES NO WARRANTY, EXPRESSED OR IMPLIED OR STATUTORY, WITH RESPECT TO ANY OF THE SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. + +YOU EXPRESSLY ASSUME ALL LIABILITIES AND RISKS, FOR USE OR OPERATION OF THE SOFTWARE, INCLUDING WITHOUT LIMITATION, SOFTWARE APPLICATIONS DESIGNED OR INTENDED FOR MISSION CRITICAL APPLICATIONS, SUCH AS PACEMAKERS, WEAPONRY, AIRCRAFT NAVIGATION, FACTORY CONTROL SYSTEMS, ETC. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE ENTIRE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +5. NO LIABILITY +PLEASE READ THE INSTRUCTIONS COMPLETELY, AND PLEASE NOTE THAT YOU SHOULD USE THE SOFTWARE AT YOUR OWN RISK. + +IN NO EVENT SHALL HISILICON BE LIABLE FOR ANY DIRECT OR INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE OF OR INABILITY TO USE THE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHER LEGAL THEORY, EVEN IF HISILICON HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. EVEN IF THE SOFTWARE HAS ANY MATERIAL, VERIFIABLE, AND REPRODUCIBLE PROGRAM ERRORS, HISILICON SHALL HAVE NO LIABILITY TO MODIFY SUCH ERRORS. + +NOTWITHSTANDING ANYTHING TO THE CONTRARY CONTAINED IN THIS AGREEMENT, THE MAXIMUM LIABILITY OF HISILICON TO YOU IN AGGREGATE FOR ALL CLAIMS MADE AGAINST HISILICON IN CONTRACT TORT OR OTHERWISE UNDER OR IN CONNECTION WITH THE SUBJECT MATTER OF THIS AGREEMENT SHALL NOT EXCEED THE TOTAL OF SUMS RECEIVED BY HISILICON FROM YOU FOR THIS AGREEMENT. THE EXISTENCE OF MORE THAN ONE CLAIM WILL NOT ENLARGE OR EXTEND THE LIMIT. + +6. CONFIDENTIALITY +YOU acknowledge and agree that the SOFTWARE and any benchmarking data and related information provided under this Agreement contain trade secrets and confidential material of HISILICON and YOU agree to maintain all such information in confidence and apply security measures no less stringent than the measures which YOU apply to protect your own like information, but not less than a reasonable degree of care, to prevent their unauthorized disclosure and use. The period of confidentiality shall be indefinite. YOU agree not to use any such information other than in normal use of the SOFTWARE under the license granted in this Agreement. + +7. TERM AND TERMINATION +This Agreement shall remain in force until terminated. HISILICON may terminate this Agreement at any time with or without any cause. Upon termination of this Agreement, YOU shall immediately stop using the SOFTWARE and confidential information and destroy all copies of the SOFTWARE and confidential information in your possession, together with all documentation and related materials. The provisions of clauses 3, 4, 5, 6, 7 and 8 shall survive termination of this Agreement. + +8. GENERAL +Any provision of this Agreement which is prohibited or unenforceable in any jurisdiction shall be ineffective to the extent of such prohibition or unenforceability without affecting, impairing or invalidating the remaining provisions hereof. + +The failure by HISILICON to enforce any of the provisions of this Agreement, unless waived in writing, shall not constitute a waiver of HISILICON's rights to enforce such provision or any other provision of this Agreement in the future. +At HISILICON’s request, YOU agree to check your computers for installations of the SOFTWARE and any other information requested by HISILICON relating to SOFTWARE installation and to provide this information to HISILICON. YOU agree that employees or auditors nominated by HISILICON may also perform such checking and reporting on behalf of HISILICON by prior appointment during your normal business hours on seven (7) days’ notice. HISILICON shall bear the auditors’ costs for that audit unless it reveals unlicensed usage in which case YOU shall promptly reimburse HISILICON for all reasonable costs and expenses, including professional fees, relating to such audit. + +The SOFTWARE provided under this Agreement is subject to U.S. export control laws, including the U.S. Export Administration Act and its associated regulations, and may be subject to export or import regulations in other countries. YOU agree to comply fully with all laws and regulations of the United States and other countries ("Export Laws") to assure that the SOFTWARE, is not (1) exported, directly or indirectly, in violation of Export Laws, either to any countries that are subject to U.S.A. export restrictions or to any end user who has been prohibited from participating in the U.S.A. export transactions by any federal agency of the U.S.A. government; or (2) intended to be used for any purpose prohibited by Export Laws, including, without limitation, nuclear, chemical, or biological weapons proliferation. + +This Agreement shall be governed by and construed in accordance with the laws of People’s Republic of China, without reference to the principles of conflicts of laws. Any dispute arising out of or relating to this Agreement shall be submitted to Shenzhen Longgang District People’s court and the parties waive all objections to that jurisdiction and venue. + +Some open-source software components may be used in the Software. If the applicable licenses of these open-source software components conflict with the content in this Agreement, the licenses of the open-source software components will prevail. + +--------------------------------------------------------------------- +Copyright (C) 2020 Hisilicon (Shanghai) Technologies Co., Ltd. All rights reserved. + diff --git a/arm/platform/libs/virt/libhdf_uart.a b/arm/platform/libs/virt/libhdf_uart.a new file mode 100644 index 0000000000000000000000000000000000000000..ae4c9f1eed3da63759d4e886b31da19f1d58f400 Binary files /dev/null and b/arm/platform/libs/virt/libhdf_uart.a differ diff --git a/arm/platform/uart/Kconfig b/arm/platform/uart/Kconfig new file mode 100644 index 0000000000000000000000000000000000000000..be74626317aa9753f0b02c74e6e430274a4ccad0 --- /dev/null +++ b/arm/platform/uart/Kconfig @@ -0,0 +1,5 @@ +config DRIVERS_HDF_PLATFORM_UART + bool "Enable HDF platform uart driver" + depends on DRIVERS_HDF_PLATFORM + help + Answer Y to enable HDF platform uart driver. diff --git a/arm/virt/README.en.md b/arm/virt/README.en.md new file mode 100644 index 0000000000000000000000000000000000000000..95e3186337bb2f322b071d30ab3bea3caa2fb5fb --- /dev/null +++ b/arm/virt/README.en.md @@ -0,0 +1,64 @@ +### Qemu ARM Virt HOWTO + +#### 1. Brief introduction +`arm/` subdirectory contains part of the OpenHarmony LiteOS demonstration support for Qemu ARM Virtual Platform, +here called *virt*. +ARM Virtual platform is a `qemu-system-arm` machine target that provides emulation +for a generic, ARM-based board. Virt is somehow configurable, for example +user can select core type, number of cores, amount of memory, security features +as well as, to some extent, on-chip device configuration. + +Introduced functionality adds support for Cortex-A7 (1 CPU with security extensions), +GICv2, 1024MB memory virtual platform. + +Note: System memory size is hard-coded to 32MB. + +#### 2. Setting up environment + +Refer to HOWTO guide: [Setting up a development environment](https://gitee.com/openharmony/docs/blob/master/docs-en/quick-start/setting-up-a-development-environment-1.md) + +#### 3. Code acquisition + +Refer to HOWTO guide: [Code acquisition](https://gitee.com/openharmony/docs/blob/master/docs-en/get-code/source-code-acquisition.md) +Note: One can use `repo` to fetch code in a straightforward manner. + +#### 4. Building from sources + +While being in the fetched source tree root directory, please type: +``` +./build.py qemu_arm_virt_ca7 -b debug +``` +This will build `OHOS_Image` for Qemu ARM virt machine. +Note: "debug" type of build is currently a default type since, as for other supported debug targets, it incorporates Shell app. + There is no release build available at this time. + +After build is finished, the resulting image can be found in: +``` +out/qemu_arm_virt_ca7/OHOS_Image +``` +#### 5. Running image in Qemu + +a) If not installed, please install `qemu-system-arm` +For details, please refer to the HOWTO: [Qemu installation](https://www.qemu.org/download/) + +Note: The introduced functionality was tested on virt-5.1 target machine. It is not guaranteed to work with any other version + so make sure that your qemu-system-arm emulator is up to date. + +b) Run `qemu-system-arm` + +``` +qemu-system-arm -M virt,gic-version=2,secure -cpu cortex-a7 -smp cpus=1 -nographic -kernel ./out/qemu_arm_virt_ca7/OHOS_Image -m 1G +``` + + +``` +Explanation for our system configuration: +-M virt,gic-version=2,secure : runs ARM virtual platform with ARM Generic Interrupt Controller version 2 and security extensions enabled +-smp cpus=1 : defines 1 CPU system +-m 1G : defines system memory to be 1024MB. This limitation will be removed in the future but now, + more memory will simply not be visible in the system. +``` + + +Note: OHOS build target name `qemu_arm_virt_ca7` is derived from the above mentioned command. + diff --git a/arm/virt/config/Makefile b/arm/virt/config/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..5e4fab452cb3b8384ea468419db6fee2aff5212f --- /dev/null +++ b/arm/virt/config/Makefile @@ -0,0 +1,9 @@ +# Copyright (c) 2020 Huawei Device Co., Ltd. All rights reserved. + +include $(LITEOSTOPDIR)/../../drivers/hdf/lite/lite.mk + +MODULE_NAME := hdf_config + +LOCAL_PLATFORM_HCS_SRC := hdf.hcs + +include $(HDF_DRIVER) \ No newline at end of file diff --git a/arm/virt/config/board/include/asm/hal_platform_ints.h b/arm/virt/config/board/include/asm/hal_platform_ints.h new file mode 100644 index 0000000000000000000000000000000000000000..e84c417b14333593555df5bfacbf4bdad44acce0 --- /dev/null +++ b/arm/virt/config/board/include/asm/hal_platform_ints.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. + * 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 PLATFORM_HAL_PLATFORM_INTS_H +#define PLATFORM_HAL_PLATFORM_INTS_H + +#include"los_typedef.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +/** + * Maximum number of supported hardware devices that generate hardware interrupts. + * The maximum number of hardware devices that generate hardware interrupts is 128. + */ +#define OS_HWI_MAX_NUM 96 + +/** + * Maximum interrupt number. + */ + +#define OS_HWI_MAX ((OS_HWI_MAX_NUM) - 1) + +/** + * Minimum interrupt number. + */ + +#define OS_HWI_MIN 0 + +/** + * Maximum usable interrupt number. + */ + +#define OS_USER_HWI_MAX OS_HWI_MAX + +/** + * Minimum usable interrupt number. + */ + +#define OS_USER_HWI_MIN OS_HWI_MIN + +#define IRQ_SGI_BASE 0 +#define IRQ_PPI_BASE 16 +#define IRQ_SPI_BASE 32 + +#define NUM_HAL_INTERRUPT_CNTPSIRQ (IRQ_PPI_BASE + 13) +#define NUM_HAL_INTERRUPT_CNTPNSIRQ (IRQ_PPI_BASE + 14) +#define OS_TICK_INT_NUM NUM_HAL_INTERRUPT_CNTPSIRQ // use secure physical timer for now + +#define NUM_HAL_INTERRUPT_UART0 (IRQ_SPI_BASE + 1) +#define NUM_HAL_INTERRUPT_UART1 (IRQ_SPI_BASE + 8) + +#define NUM_HAL_INTERRUPT_NONE -1 + +#define NUM_HAL_ISR_MIN OS_HWI_MIN +#define NUM_HAL_ISR_MAX 1020 +#define NUM_HAL_ISR_COUNT (NUM_HAL_ISR_MAX - NUM_HAL_ISR_MIN + 1) + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ +#endif // PLATFORM_HAL_PLATFORM_INTS_H diff --git a/arm/virt/config/board/include/asm/platform.h b/arm/virt/config/board/include/asm/platform.h new file mode 100644 index 0000000000000000000000000000000000000000..37d183f046257be2d0d873f266145684a8855f12 --- /dev/null +++ b/arm/virt/config/board/include/asm/platform.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. + * 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 __ASM_PLATFORM_H__ +#define __ASM_PLATFORM_H__ + +#include "menuconfig.h" +#include "asm/hal_platform_ints.h" +#include "hisoc/timer.h" +#include "hisoc/uart.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +/*------------------------------------------------ + * GIC reg base address + *------------------------------------------------*/ +#define GIC_BASE_ADDR IO_DEVICE_ADDR(0x08000000) +#define GICD_OFFSET 0x00000 /* interrupt distributor offset */ +#define GICC_OFFSET 0x10000 /* CPU interface register offset */ + +#define UART0_REG_BASE IO_DEVICE_ADDR(0x09000000) + +#if (CONSOLE_UART == UART0) + #define UART_BASE UART0_REG_BASE + #define UART0_INT_NUM NUM_HAL_INTERRUPT_UART0 +#endif + +#define DDR_MEM_BASE 0x40000000 + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif + diff --git a/arm/virt/config/board/include/board.h b/arm/virt/config/board/include/board.h new file mode 100644 index 0000000000000000000000000000000000000000..e1e18251323c3858a6a375ad9193a5fd643d3319 --- /dev/null +++ b/arm/virt/config/board/include/board.h @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. + * 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 __BOARD_CONFIG_H__ +#define __BOARD_CONFIG_H__ + +#include "menuconfig.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +/* physical memory base and size */ +#define DDR_MEM_ADDR 0x40000000 +#define DDR_MEM_SIZE 0x40000000 +/** + * Memory map is as follows: + * ADDR SIZE + * 0x00000000 ; 0x08000000 Flash + * 0x08000000 ; 0x01000000 GIC (all variants' registers) + * 0x09000000 ; 0x00001000 UART + * 0x09010000 ; 0x00001000 RTC + * 0x09020000 ; 0x00000018 FW Config + * 0x09030000 ; 0x00001000 GPIO + * 0x09040000 ; 0x00001000 Secure UART + * 0x09050000 ; 0x00020000 SMMU + * 0x09070000 ; 0x00000018 PCDIMM ACPI + * 0x09080000 ; 0x00000004 ACPI GED + * 0x09090000 ; 0x00000004 NVDIMM ACPI + * 0x0a000000 ; 0x00000200 MMIO + * 0x0c000000 ; 0x02000000 Platform Bus + * 0x0e000000 ; 0x01000000 Secure Mem + * 0x10000000 ; 0x2eff0000 PCIe MMIO + * 0x3eff0000 ; 0x00010000 PCIe PIO + * 0x3f000000 ; 0x01000000 PCIe ECAM + * 0x40000000 ; 0xXXXXXXXX RAM + */ + +/* Peripheral register address base and size */ +#define PERIPH_PMM_BASE 0x00000000 +/* Note: Size ranges to the end of Secure Mem */ +#define PERIPH_PMM_SIZE 0x0F000000 + +#define KERNEL_VADDR_BASE 0x40000000 +#define KERNEL_VADDR_SIZE DDR_MEM_SIZE + +#define SYS_MEM_BASE DDR_MEM_ADDR +#define SYS_MEM_SIZE_DEFAULT 0x02000000 +#define SYS_MEM_END (SYS_MEM_BASE + SYS_MEM_SIZE_DEFAULT) + +#define EXC_INTERACT_MEM_SIZE 0x100000 + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif diff --git a/arm/virt/config/board/include/hisoc/clock.h b/arm/virt/config/board/include/hisoc/clock.h new file mode 100644 index 0000000000000000000000000000000000000000..14ffc3493f6b8ae91b2f6eb6b7f310a1a2960bfe --- /dev/null +++ b/arm/virt/config/board/include/hisoc/clock.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. + * 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 __HISOC_CLOCK_H__ +#define __HISOC_CLOCK_H__ + +#include "asm/platform.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C"{ +#endif +#endif /* __cplusplus */ + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif /* __cplusplus */ + +#endif + diff --git a/arm/virt/config/board/include/hisoc/timer.h b/arm/virt/config/board/include/hisoc/timer.h new file mode 100644 index 0000000000000000000000000000000000000000..8fed955449b001a11d1911fb5ed534578438cc5c --- /dev/null +++ b/arm/virt/config/board/include/hisoc/timer.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. + * 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 __HISOC_TIMER_H__ +#define __HISOC_TIMER_H__ + +#include "asm/platform.h" +#include "los_bitmap.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +VOID LOS_Udelay(UINT32 usecs); +VOID LOS_Mdelay(UINT32 msecs); +VOID reset_timer_masked(VOID); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ +#endif + diff --git a/arm/virt/config/board/include/hisoc/uart.h b/arm/virt/config/board/include/hisoc/uart.h new file mode 100644 index 0000000000000000000000000000000000000000..53337e9741930937043d3a7398f4056c395a7182 --- /dev/null +++ b/arm/virt/config/board/include/hisoc/uart.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. + * 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 __HISOC_UART_H__ +#define __HISOC_UART_H__ + +#include "asm/platform.h" +#include "los_typedef.h" +#include "los_base.h" +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#define CONFIG_UART0_BAUDRATE 115200 +#define CONFIG_UART_CLK_INPUT (24000000) // 24M or 6M + +#define UART0 0 +#define UART0_ENABLE 1 +#define UART0_DMA_RX_PERI 4 + +#define TTYS0 "/dev/ttyS0" + +#define CONSOLE_UART UART0 + +#define CONSOLE_UART_BAUDRATE 115200 +#define UART_NUM 1 +#if (CONSOLE_UART == UART0) + #define TTY_DEVICE "/dev/uartdev-0" + #define UART_REG_BASE UART0_REG_BASE + #define NUM_HAL_INTERRUPT_UART NUM_HAL_INTERRUPT_UART0 +#endif + +extern VOID UartPuts(const CHAR *s, UINT32 len, BOOL isLock); + +#define UART_WITHOUT_LOCK 0 +#define UART_WITH_LOCK 1 + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif diff --git a/arm/virt/config/board/include/platform_config.h b/arm/virt/config/board/include/platform_config.h new file mode 100644 index 0000000000000000000000000000000000000000..2ab266111ee3c81f2589765474ea6ce0408af3f8 --- /dev/null +++ b/arm/virt/config/board/include/platform_config.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. + * 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 __PLATFORM_CONFIG_H__ +#define __PLATFORM_CONFIG_H__ + +#include "hisoc/clock.h" + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#define LOSCFG_PLATFORM_HWI_LIMIT 96 +#define OS_SYS_CLOCK 50000000 +#define LOSCFG_BASE_CORE_TICK_HW_TIME NO + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif diff --git a/arm/virt/config/device_info/device_info.hcs b/arm/virt/config/device_info/device_info.hcs new file mode 100644 index 0000000000000000000000000000000000000000..e4203d79f46f2e8fb0cbd3226079c747ac2ed07c --- /dev/null +++ b/arm/virt/config/device_info/device_info.hcs @@ -0,0 +1,40 @@ + root { + device_info { + match_attr = "hdf_manager"; + template host { + hostName = ""; + priority = 100; + template device{ + template deviceNode { + policy = 0; + priority = 100; + preload = 0; + permission = 0664; + moduleName = ""; + serviceName = ""; + deviceMatchAttr = ""; + } + } + } + platform :: host { + hostName = "platform_host"; + priority = 50; + device_uart :: device { + device0 :: deviceNode { + policy = 1; + priority = 40; + permission = 0644; + moduleName = "HDF_PLATFORM_UART"; + serviceName = "HDF_PLATFORM_UART_0"; + deviceMatchAttr = "qemu_virt_uart_0"; + } + } + } + network :: host { + } + storage :: host { + } + media :: host { + } + } +} diff --git a/arm/virt/config/hdf.hcs b/arm/virt/config/hdf.hcs new file mode 100644 index 0000000000000000000000000000000000000000..25285707023e51b2bbb743f50a21bae57b052b23 --- /dev/null +++ b/arm/virt/config/hdf.hcs @@ -0,0 +1,6 @@ +#include "device_info/device_info.hcs" +#include "uart/uart_config.hcs" + +root { + module = "qemu,arm_virt_chip"; +} diff --git a/arm/virt/config/uart/uart_config.hcs b/arm/virt/config/uart/uart_config.hcs new file mode 100644 index 0000000000000000000000000000000000000000..485cac96d1e4dae072a1077be1840993e9b8f82d --- /dev/null +++ b/arm/virt/config/uart/uart_config.hcs @@ -0,0 +1,18 @@ +root { + platfrom { + template uart_controller { + match_attr = ""; + num = 0; + baudrate = 115200; + fifoRxEn = 1; + fifoTxEn = 1; + flags = 4; + regPbase = 0x09000000; + interrupt = 33; + iomemCount = 0x48; + } + controller_0x09000000 :: uart_controller { + match_attr = "qemu_virt_uart_0"; + } + } +} diff --git a/arm/virt/module_init/src/system_init.c b/arm/virt/module_init/src/system_init.c new file mode 100644 index 0000000000000000000000000000000000000000..5a05f94d65a8e6e4dd47a3b3fd8dbefa2ab2f93e --- /dev/null +++ b/arm/virt/module_init/src/system_init.c @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. + * 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 "sys_config.h" +#include "board.h" +#include "los_typedef.h" + +#include "stdlib.h" +#include "stdio.h" +#include "los_process_pri.h" +#ifdef LOSCFG_FS_VFS +#include "disk.h" +#endif +#include "los_rootfs.h" +#ifdef LOSCFG_SHELL +#include "shell.h" +#include "shcmd.h" +#endif + +#ifdef LOSCFG_DRIVERS_HDF_PLATFORM_UART +#include "console.h" +#include "hisoc/uart.h" +#endif + +#ifdef LOSCFG_DRIVERS_HDF +#include "devmgr_service_start.h" +#endif + +#ifdef LOSCFG_DRIVERS_NETDEV +#include "lwip/tcpip.h" +#include "lwip/netif.h" +#include "lwip/netifapi.h" + +#define SLEEP_TIME_MS 60 +#define NETIF_SETUP_OVERTIME 100 + +void net_init(void) +{ +extern void tcpip_init(tcpip_init_done_fn initfunc, void *arg); + dprintf("\ntcpip_init start\n"); + tcpip_init(NULL, NULL); + dprintf("\ntcpip_init end\n"); + + PRINTK("Ethernet start."); + +#ifdef LOSCFG_DRIVERS_HIGMAC + extern int ethnet_higmac_init(void); + (void)ethnet_higmac_init(); +#endif + +#ifdef LOSCFG_DRIVERS_HIETH_SF + extern int ethnet_hieth_init(void); + (void)ethnet_hieth_init(); +#endif + + /* TODO: Re-enable this when Netif driver is implemented */ +#if 0 + struct netif *pnetif; + + extern void get_defaultNetif(struct netif **pnetif); + get_defaultNetif(&pnetif); + + (void)netifapi_netif_set_up(pnetif); + unsigned int overtime = 0; + do { + LOS_Msleep(SLEEP_TIME_MS); + overtime++; + if (overtime > NETIF_SETUP_OVERTIME) { + PRINTK("netif_is_link_up overtime!\n"); + break; + } + } while (netif_is_link_up(pnetif) == 0); +#endif +} +#endif + +void SystemInit(void) +{ + +#ifdef LOSCFG_FS_PROC + dprintf("proc fs init ...\n"); + extern void ProcFsInit(void); + ProcFsInit(); +#endif + +#ifdef LOSCFG_DRIVERS_MEM + dprintf("mem dev init ...\n"); + extern int mem_dev_register(void); + mem_dev_register(); +#endif + + dprintf("Date:%s.\n", __DATE__); + dprintf("Time:%s.\n", __TIME__); + +#ifdef LOSCFG_DRIVERS_NETDEV + dprintf("net init ...\n"); + net_init(); + dprintf("\n************************************************************\n"); +#endif + +#ifdef LOSCFG_PLATFORM_ROOTFS + dprintf("OsMountRootfs start ...\n"); + OsMountRootfs(); + dprintf("OsMountRootfs end ...\n"); +#endif + +#ifdef LOSCFG_DRIVERS_HDF + dprintf("DeviceManagerStart start ...\n"); + if (DeviceManagerStart()) { + PRINT_ERR("No drivers need load by hdf manager!"); + } + dprintf("DeviceManagerStart end ...\n"); +#endif + +#ifdef LOSCFG_DRIVERS_HDF_PLATFORM_UART + dprintf("virtual_serial_init start ...\n"); + if (virtual_serial_init(TTY_DEVICE) != 0) { + PRINT_ERR("virtual_serial_init failed"); + } + dprintf("virtual_serial_init end ...\n"); + dprintf("system_console_init start ...\n"); + if (system_console_init(SERIAL) != 0) { + PRINT_ERR("system_console_init failed\n"); + } + dprintf("system_console_init end ...\n"); +#endif + dprintf("OsUserInitProcess start ...\n"); + if (OsUserInitProcess()) { + PRINT_ERR("Create user init process faialed!\n"); + return; + } + dprintf("OsUserInitProcess end ...\n"); + return; +}