diff --git a/.gitignore b/.gitignore index f31ded306980653a8571ecdfcc17d54fb325f363..3df7ed227ad9e2d51d60acb8005ca51c6d99a81f 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,8 @@ targets/cortex-m7_nucleo_f767zi_gcc/build *.o *.d *.su + +# Menuconfig temp files +/config.h +/.config +/.config.old diff --git a/BUILD.gn b/BUILD.gn index ef196cb493cc7be8e44119d9b416aa3ec3c71806..be0a0665ccd3482459515417a97d231eabc7b93c 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -27,67 +27,293 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import("config.gni") +import("//build/lite/config/component/lite_component.gni") -LITEOS_LOS_CONFIG_H = rebase_path("$LITEOSTOPDIR/kernel/include/los_config.h") +LITEOS_MENUCONFIG_H = rebase_path("$root_out_dir/config.h") -config("los_config") { - cflags = [ "-Werror" ] +declare_args() { + liteos_name = "OHOS_Image" + liteos_config_file = "${ohos_build_type}.config" + liteos_kernel_only = false +} - asmflags = [ - "-DCLZ=CLZ", - "-imacros", - "$LITEOS_LOS_CONFIG_H", - ] +liteos_config_file = + rebase_path(liteos_config_file, "", "$product_path/kernel_configs") +print("liteos_config_file:", liteos_config_file) - include_dirs = [ - "//kernel/liteos_m/kernel/include", - "//kernel/liteos_m/kernel/arch/include", - "//kernel/liteos_m/utils", - "//third_party/bounds_checking_function/include", - ] +exec_script("//build/lite/run_shell_cmd.py", + [ "env" + " CONFIG_=LOSCFG_" + " KCONFIG_CONFIG_HEADER='y=true'" + + " KCONFIG_CONFIG=$liteos_config_file" + + " DEVICE_PATH=$device_path" + " srctree=" + rebase_path(".") + + " genconfig" + " --header-path $LITEOS_MENUCONFIG_H" + + " --file-list kconfig_files.txt" + + " --env-list kconfig_env.txt" + " --config-out config.gni" ], + "", + [ liteos_config_file ]) + +import("liteos.gni") + +visibility = [ "$LITEOSTOPDIR/*" ] + +liteos_arch_cflags = [] +if (defined(LOSCFG_ARCH_ARM)) { + mcpu = LOSCFG_ARCH_CPU + if (defined(LOSCFG_ARCH_ARM_AARCH64) && defined(LOSCFG_ARCH_FPU_DISABLE)) { + mcpu += "+nofp" + } + liteos_arch_cflags += [ "-mcpu=$mcpu" ] + if (defined(LOSCFG_ARCH_ARM_AARCH32) && defined(LOSCFG_ARCH_FPU)) { + liteos_arch_cflags += [ "-mfpu=$LOSCFG_ARCH_FPU" ] + } } -group("kernel") { - deps = [ - "kernel:kernel", - "utils:utils", - "//third_party/bounds_checking_function:libsec_static", - ] - if (enable_ohos_kernel_liteos_m_cppsupport) { - deps += [ "components/cppsupport:cppsupport" ] +cc = "$ohos_current_cc_command " + string_join(" ", liteos_arch_cflags) +if (ohos_build_compiler == "clang") { + cc += " --target=$target_triple" +} + +config("arch_config") { + cflags = liteos_arch_cflags + asmflags = cflags + ldflags = cflags + if (defined(LOSCFG_ARCH_ARM_AARCH32)) { + if (!defined(LOSCFG_COMPILER_CLANG_LLVM)) { + cflags += [ "-mthumb-interwork" ] + } } - if (enable_ohos_kernel_liteos_m_cpup) { - deps += [ "components/cpup:cpup" ] + if (defined(LOSCFG_THUMB)) { + cflags += [ "-mthumb" ] + if (defined(LOSCFG_COMPILER_CLANG_LLVM)) { + cflags += [ "-mimplicit-it=thumb" ] + } else { + cflags += [ "-Wa,-mimplicit-it=thumb" ] + } } - if (enable_ohos_kernel_liteos_m_exchook) { - deps += [ "components/exchook:exchook" ] +} + +config("stdinc_config") { + std_include = exec_script("//build/lite/run_shell_cmd.py", + [ "$cc -print-file-name=include" ], + "trim string") + cflags = [ + "-isystem", + std_include, + ] + cflags += [ "-nostdinc" ] + asmflags = cflags +} + +config("ssp_config") { + cflags = [] + if (defined(LOSCFG_CC_STACKPROTECTOR_ALL)) { + cflags += [ "-fstack-protector-all" ] + } else if (defined(LOSCFG_CC_STACKPROTECTOR_STRONG)) { + cflags += [ "-fstack-protector-strong" ] + } else if (defined(LOSCFG_CC_STACKPROTECTOR)) { + cflags += [ + "-fstack-protector", + "--param", + "ssp-buffer-size=4", + ] + } else { + cflags += [ "-fno-stack-protector" ] } - if (enable_ohos_kernel_liteos_m_backtrace) { - deps += [ "components/backtrace:backtrace" ] + asmflags = cflags +} + +config("optimize_config") { + cflags = [] + if (defined(LOSCFG_COMPILE_DEBUG)) { + cflags += [ + "-g", + "-gdwarf-2", + ] + optimization_cflag = "-O0" } - if (enable_ohos_kernel_liteos_m_fs) { - deps += [ "components/fs:fs" ] + if (defined(LOSCFG_COMPILE_OPTIMIZE)) { + optimization_cflag = "-O2" } - if (enable_ohos_kernel_liteos_m_pm) { - deps += [ "components/power:pm" ] + if (defined(LOSCFG_COMPILE_OPTIMIZE_SIZE)) { + if (defined(LOSCFG_COMPILER_CLANG_LLVM)) { + optimization_cflag = "-Oz" + } else { + optimization_cflag = "-Os" + } } - if (enable_ohos_kernel_liteos_m_trace) { - deps += [ "components/trace:trace" ] + if (defined(LOSCFG_COMPILE_LTO)) { + if (defined(LOSCFG_COMPILER_CLANG_LLVM)) { + cflags += [ "-flto=thin" ] + } else { + #cflags += [ "-flto" ] + } } - if (enable_ohos_kernel_liteos_m_kal) { - deps += [ "kal:kal" ] + cflags += [ optimization_cflag ] + asmflags = cflags +} + +config("kconfig_config") { + cflags = [ + "-imacros", + "$LITEOS_MENUCONFIG_H", + ] + asmflags = cflags +} + +config("warn_config") { + cflags = [ + "-Wall", + "-Werror", + "-Wpointer-arith", + "-Wstrict-prototypes", + "-Winvalid-pch", + "-Wno-address-of-packed-member", + ] + asmflags = cflags +} + +config("dialect_config") { + cflags_c = [ "-std=c99" ] + cflags_cc = [ "-std=c++11" ] +} + +config("misc_config") { + defines = [ "__LITEOS__" ] + defines += [ "__LITEOS_M__" ] + if (!defined(LOSCFG_DEBUG_VERSION)) { + defines += [ "NDEBUG" ] } - if (enable_ohos_kernel_liteos_m_shell) { - deps += [ "components/shell:shell" ] + + cflags = [ + "-fno-pic", + "-fno-builtin", + "-fms-extensions", + "-fno-strict-aliasing", + "-fno-common", + "-fsigned-char", + "-ffunction-sections", + "-fdata-sections", + "-fno-exceptions", + "-fno-omit-frame-pointer", + "-fno-short-enums", + ] + + if (!defined(LOSCFG_COMPILER_CLANG_LLVM)) { + cflags += [ "-fno-aggressive-loop-optimizations" ] } - if (enable_ohos_kernel_liteos_m_test) { - deps += [ "testsuites:test" ] + + asmflags = cflags + asmflags += [ "-DCLZ=CLZ" ] +} + +config("los_config") { + configs = [ + ":arch_config", + ":kconfig_config", + + #":stdinc_config", + ":dialect_config", + ":optimize_config", + ":ssp_config", + + #":warn_config", + ":misc_config", + ] +} + +cmd = "if [ -f $device_path/BUILD.gn ]; then echo true; else echo false; fi" +HAVE_DEVICE_SDK = exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value") + +config("public") { + configs = [ + "kernel/arch:public", + "kernel:public", + "kal:public", + "components:public", + "utils:public", + ] + + if (HAVE_DEVICE_SDK) { + configs += [ "$device_path:public" ] } - if (enable_ohos_kernel_liteos_m_lwip) { - deps += [ ohos_kernel_liteos_m_lwip_path ] + + configs += + [ "$LITEOSTHIRDPARTY/bounds_checking_function:libsec_public_config" ] + configs += [ "$LITEOSTHIRDPARTY/musl/porting/liteos_m/kernel:include" ] +} + +group("modules") { + deps = [ + "components", + "kal", + "kernel", + "kernel/arch", + "testsuites", + "utils", + HDFTOPDIR, + ] + + if (HAVE_DEVICE_SDK) { + deps += [ device_path ] } - if (enable_ohos_kernel_liteos_m_dynlink) { - deps += [ "components/dynlink:dynlink" ] + + deps += [ "$LITEOSTHIRDPARTY/bounds_checking_function:libsec_static" ] + deps += [ "$LITEOSTHIRDPARTY/musl/porting/liteos_m/kernel" ] +} + +static_library("libkernel") { + deps = [ ":modules" ] + public_configs = [ + ":public", + ":los_config", + ] + complete_static_lib = true + visibility += [] +} + +group("kernel") { + public_deps = [ ":libkernel" ] + visibility += [ "//build/lite:ohos" ] +} + +group("liteos_m") { +} + +executable("liteos") { + configs += [ + ":public", + ":los_config", + ] + + ldflags = [ + "-static", + "-Wl,--gc-sections", + "-Wl,-Map=$liteos_name.map", + ] + + output_dir = target_out_dir + + if (liteos_kernel_only) { + deps = [ ":kernel" ] + } else { + deps = [ "//build/lite:ohos" ] } } + +copy("copy_liteos") { + deps = [ ":liteos" ] + sources = [ "$target_out_dir/unstripped/bin/liteos" ] + outputs = [ "$root_out_dir/$liteos_name" ] +} + +build_ext_component("build_kernel_image") { + deps = [ ":copy_liteos" ] + exec_path = rebase_path(root_out_dir) + + objcopy = "${compile_prefix}objcopy$toolchain_cmd_suffix" + objdump = "${compile_prefix}objdump$toolchain_cmd_suffix" + + command = "$objcopy -O binary $liteos_name $liteos_name.bin" + command += + " && sh -c '$objdump -t $liteos_name | sort >$liteos_name.sym.sorted'" + command += " && sh -c '$objdump -d $liteos_name >$liteos_name.asm'" +} diff --git a/Kconfig b/Kconfig new file mode 100644 index 0000000000000000000000000000000000000000..5f32f85463bbbb15790f411b8187b1da07b40fa8 --- /dev/null +++ b/Kconfig @@ -0,0 +1,647 @@ +# 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. + +mainmenu "Huawei LiteOS Configuration" + +menu "Compiler" +choice + prompt "Compiler type" + default COMPILER_GCC + help + Choose compiler type. + +config COMPILER_GCC + bool "GCC" + +config CROSS_COMPILE + string "GCC cross-compile toolchain prefix" + depends on COMPILER_GCC + default "arm-none-eabi-" if ARCH_ARM_AARCH32 + +config COMPILER_CLANG_LLVM + bool "Clang" + +config LLVM_TARGET + string "Clang LLVM target" + depends on COMPILER_CLANG_LLVM + default "arm-liteos" if ARCH_ARM_AARCH32 + +endchoice + +config COMPILE_DEBUG + bool "Enable debug options" + default n + help + Answer Y to add -g option in compile command. + +config COMPILE_OPTIMIZE + bool "Enable code optimization options" + default y + help + Answer Y to add optimization options for efficient code. + The final binary size will be smaller and execute faster. + But the debugging experience may be worst somehow. + +config COMPILE_OPTIMIZE_SIZE + bool "Enable code size optimization options" if COMPILE_OPTIMIZE + default y + help + Answer Y to add optimization options for small code size. + The final binary size will be smaller. + But the compile time may be a bit longer. + +config COMPILE_LTO + bool "Enable link time optimization (LTO)" if COMPILE_OPTIMIZE_SIZE + default y + help + Answer Y to add lto options for more smaller code size. + The final binary size will be smaller. + But the compile time may be much longer. + +endmenu + +menu "Platform" + +######################### config options of bsp ##################### +config PLATFORM + string + default "virt" if PLATFORM_QEMU_ARM_VIRT_CM7 || PLATFORM_QEMU_ARM_VIRT_CM4 || PRODUCT_QEMU_RISCV32_VIRT || PLATFORM_QEMU_CSKY_SMARTL || PLATFORM_QEMU_XTENSA_ESP32 + +config PRODUCT_NAME + string + default "arm_virt" if PRODUCT_QEMU_ARM + default "arm_mps2_an386" if PRODUCT_QEMU_ARM_MPS2_AN386 + default "riscv32_virt" if PRODUCT_QEMU_RISCV32_VIRT + default "csky_smartl_e802" if PRODUCT_QEMU_CSKY_SMARTL_E802 + default "xtensa_esp32" if PRODUCT_QEMU_XTENSA_ESP32 + +config DEVICE_COMPANY + string + default "qemu" if PLATFORM_QEMU_ARM_VIRT_CM7 || PLATFORM_QEMU_ARM_VIRT_CM4 || PRODUCT_QEMU_RISCV32_VIRT || PLATFORM_QEMU_CSKY_SMARTL || PLATFORM_QEMU_XTENSA_ESP32 + +choice + prompt "Chip" + default PLATFORM_QEMU_ARM_VIRT_CM7 + help + Qemu ARM Virt variants (based on different CPU types): + - qemu_arm_virt_cm7 + - qemu_arm_virt_cm4 + - qemu_riscv32_virt + - qemu_csky_smartl + - qemu_xtensa_esp32 + +config PLATFORM_QEMU_ARM_VIRT_CM7 + bool "qemu_arm_virt_cm7" + select ARCH_CORTEX_M7 + help + QEMU ARM Virtual Platform using Cortex-M7 CPU. + +config PLATFORM_QEMU_ARM_VIRT_CM4 + bool "qemu_arm_virt_cm4" + select ARCH_CORTEX_M4 + help + QEMU ARM Virtual Platform using Cortex-M4 CPU. + +config PLATFORM_QEMU_RISCV32_VIRT + bool "qemu_riscv32_virt" + select ARCH_RISCV32 + help + QEMU RISCV Virtual Platform using riscv32 CPU. + +config PLATFORM_QEMU_CSKY_SMARTL + bool "qemu_csky_smartl" + select ARCH_CSKY + help + QEMU SmartL Virtual Platform using csky CPU. + +config PLATFORM_QEMU_XTENSA_ESP32 + bool "qemu_xtensa_esp32" + select ARCH_XTENSA + help + QEMU ESP32 Virtual Platform using xtensa CPU. + +endchoice + +choice + prompt "Product" + help + Select your target board. + +config PRODUCT_QEMU_ARM + bool "arm_virt" if PLATFORM_QEMU_ARM_VIRT_CM7 + +config PRODUCT_QEMU_ARM_MPS2_AN386 + bool "arm_mps2_an386" if PLATFORM_QEMU_ARM_VIRT_CM4 + +config PRODUCT_QEMU_RISCV32_VIRT + bool "riscv32_virt" if PLATFORM_QEMU_RISCV32_VIRT + +config PRODUCT_QEMU_CSKY_SMARTL_E802 + bool "csky_smartl_e802" if PLATFORM_QEMU_CSKY_SMARTL + +config PRODUCT_QEMU_XTENSA_ESP32 + bool "xtensa_esp32" if PLATFORM_QEMU_XTENSA_ESP32 + +endchoice + + +######################### config options of cpu arch ################ +source "kernel/arch/Kconfig" + +# Device Kconfig import +osource "$(DEVICE_PATH)/Kconfig" + +config QUICK_START + bool "Enable QUICK_START" + default n + depends on DRIVERS && FS_VFS + help + Answer Y to enable LiteOS support quick start. +endmenu + +######################### config options of kernel ##################### +menu "Kernel" + +######################### config options of extended ##################### + +config KERNEL_EXTKERNEL + bool "Enable Extend Kernel" + default y + help + This option will enable extend Kernel of LiteOS. Extend kernel include + cppsupport, cpup, etc. You can select one or some + of them. + +config KERNEL_BACKTRACE + bool "Enable Backtrace" + default n + depends on KERNEL_EXTKERNEL + help + If you wish to build LiteOS with support for backtrace. + +choice + prompt "Select Backtrace Type" + depends on KERNEL_BACKTRACE + +config BACKTRACE_TYPE_1 + bool "1: Call stack analysis for cortex-m series by scanning the stack" + depends on ARCH_ARM && !ARCH_ARM9 + +config BACKTRACE_TYPE_2 + bool "2: Call stack analysis for risc-v by using frame pointer" + depends on ARCH_RISCV + +config BACKTRACE_TYPE_3 + bool "3: Call stack analysis for risc-v by scanning the stack" + depends on ARCH_RISCV + +config BACKTRACE_TYPE_4 + bool "4: Call stack analysis for xtensa by scanning the stack" + depends on ARCH_XTENSA + +config BACKTRACE_TYPE_5 + bool "5: Call stack analysis for c-sky by scanning the stack" + depends on ARCH_CSKY + +config BACKTRACE_TYPE_6 + bool "6: Call stack analysis for arm9 by scanning the stack" + depends on ARCH_ARM9 + +endchoice + +config BACKTRACE_TYPE + int + default 0 if ! KERNEL_BACKTRACE + default 1 if BACKTRACE_TYPE_1 + default 2 if BACKTRACE_TYPE_2 + default 3 if BACKTRACE_TYPE_3 + default 4 if BACKTRACE_TYPE_4 + default 5 if BACKTRACE_TYPE_5 + default 6 if BACKTRACE_TYPE_6 + +config BACKTRACE_DEPTH + int "Backtrace depth" + default 15 + depends on KERNEL_BACKTRACE + +config KERNEL_CPPSUPPORT + bool "Enable C++ Support" + default n + depends on KERNEL_EXTKERNEL + help + If you wish to build LiteOS with support for C++. + +config BASE_CORE_CPUP + bool + default n + +config KERNEL_CPUP + bool "Enable Cpup" + default n + depends on KERNEL_EXTKERNEL + select BASE_CORE_CPUP + help + If you wish to build LiteOS with support for cpup. + +config CPUP_INCLUDE_IRQ + bool "Enable Cpup include irq" + default y + depends on KERNEL_CPUP + help + If you wish to include irq usage for cpup. + +config DYNLINK + bool "Enable Dynamic Link Feature" + default n + depends on KERNEL_EXTKERNEL && ARCH_ARM + help + If you wish to build LiteOS with support for dynamic link. + +config KERNEL_PM + bool "Enable Power Management" + default n + depends on KERNEL_EXTKERNEL + help + Configuration item for low power frame tailoring. + If you wish to build LiteOS with support for power management. + +config KERNEL_PM_TASK_PTIORITY + int "Power Management Task Priority" + default 1 + range 1 31 + depends on KERNEL_PM + help + Configuration item for priority of low-power task. + +config KERNEL_PM_TASK_STACKSIZE + int "Power Management Task Stack Size" + default 1024 + depends on KERNEL_PM + help + Configuration item for stack size of low-power task. + +config KERNEL_PM_DEBUG + bool "Power Management Debug" + default n + depends on KERNEL_PM + help + Configuration item for low power frame debug tailoring. + +config DEBUG_HOOK + bool + default n + +config PLATFORM_EXC + bool "Enable Hook Feature" + default n + depends on KERNEL_EXTKERNEL + select DEBUG_HOOK + +######################### config options of trace ######################### +source "components/trace/Kconfig" + +endmenu + +######################### config options of lib ######################## +menu "Lib" +config LIB_LIBC + bool "Enable Libc" + default y + help + Answer Y to enable libc for full code. + +endmenu + + +######################### config options of compatibility ############## +menu "Compat" +config COMPAT_POSIX + bool "Enable Posix" + default y + + help + Answer Y to enable LiteOS support posix interface. + +config COMPAT_CMSIS + bool "Enable CMSIS v2" + default n + + help + Answer Y to enable LiteOS support CMSIS v2 interface. + +endmenu + +######################## config options of filesystem ################## +menu "FileSystem" +config FS_VFS + bool "Enable VFS" + default y + + help + Answer Y to enable LiteOS support virtual filesystem. + +source "components/fs/fatfs/Kconfig" + +config FS_LITTLEFS + bool "Enable littlefs" + default n + depends on FS_VFS + select SUPPORT_LITTLEFS + help + Answer Y to enable LiteOS support littlefs. + +config LFS_MAX_MOUNT_SIZE + int "Littlefs max mounts" + default 3 + depends on FS_LITTLEFS + +config SUPPORT_FATFS + bool + default n + +config SUPPORT_LITTLEFS + bool + default n + +endmenu + +######################## config options of net ############################ +menu "Net" +config NET_LWIP + bool "Enable Lwip" + default n + select NET_LWIP_SACK + select COMPAT_CMSIS + + help + Answer Y to enable LiteOS support lwip. + +config NET_LWIP_SACK + bool + default n + +endmenu + +######################## config options of debug ######################## +menu "Debug" +config GDB + bool "Enable gdb functions" + default n + help + Answer Y to enable gdb functions. + +config PLATFORM_ADAPT + bool "Enable Os_adapt" + default y + help + Answer Y to add os_adapt.c to LiteOS. + +config ENABLE_OOM_LOOP_TASK + bool "Enable Oom loop task" + default n + depends on KERNEL_VM + help + Answer Y to enable oom loop kthread to check system out of memory. + +config DO_ALIGN + bool "Enable do align for hi3518e" + default y + depends on PLATFORM_HI3518EV200 + help + Answer Y to enable do align for hi3518e. + + +config ENABLE_MAGICKEY + bool "Enable MAGIC KEY" + default y + help + Answer Y to enable LiteOS Magic key. + ctrl + r : Magic key check switch; + ctrl + z : Show all magic op key; + ctrl + t : Show task information; + ctrl + p : System panic; + ctrl + e : Check system memory pool. + +config THUMB + bool "Enable Thumb" + default n + depends on ARCH_ARM + help + Answer Y to build thumb version. This will make LiteOS smaller. + +config PLATFORM_DVFS + bool "Enable Dvfs" + default n + depends on COMPAT_LINUXKPI + help + Answer Y to enable LiteOS support dynamic voltage and frequency scaling feature for + low power consumption. + +config SAVE_EXCINFO + bool "Enable Saving Exception Information" + default n + help + Answer Y to enable LiteOS support saving exception information to storage medium. + +config DEBUG_VERSION + bool "Enable a Debug Version" + default y + help + If you do not select this option that means you enable a release version for LiteOS. + It also means you do not want to use debug modules, like shell,telnet,tftp,nfs and + memory check, etc. + If you select this option that means you enable a debug version for LiteOS. + That means you want a opposite behaviour compared to release version. + +config DEBUG_KERNEL + bool "Enable Debug LiteOS Kernel Resource" + default n + depends on DEBUG_VERSION + help + If you select this option that means you enable debugging kernel resource. + It also means you want to get queue, mutex, semaphore, memory debug information. + That means you want a opposite behaviour compared to release version. + +config DEBUG_QUEUE + bool "Enable Queue Debugging" + default n + depends on DEBUG_KERNEL + help + Answer Y to enable debug queue. + +config DEBUG_DEADLOCK + bool "Enable Mutex Deadlock Debugging" + default n + depends on DEBUG_KERNEL + help + Answer Y to enable debug mutex deadlock. + +config DEBUG_SEMAPHORE + bool "Enable Semaphore Debugging" + default n + depends on DEBUG_KERNEL + help + Answer Y to enable debug semaphore. + +source "components/shell/Kconfig" +config NET_LWIP_SACK_TFTP + bool "Enable Tftp" + default y + depends on SHELL && NET_LWIP_SACK && DEBUG_VERSION + help + Answer Y to enable LiteOS support tftp cmd and tftp tool. +osource "net/telnet/Kconfig" +config SCHED_DEBUG + bool "Enable sched debug Feature" + default n + depends on DEBUG_VERSION + help + If you wish to build LiteOS with support for sched debug. + +config USER_INIT_DEBUG + bool "Enable user init Debug" + default n + depends on DEBUG_VERSION + +config SHELL_CMD_DEBUG + bool "Enable shell cmd Debug" + default n + depends on DEBUG_VERSION && SHELL + +config USB_DEBUG + bool "Enable USB Debug" + default n + depends on SHELL && DRIVERS_USB && DEBUG_VERSION + help + Answer Y to enable LiteOS support usb debug. + use shell command to open the specified debug level print. +config MEM_DEBUG + bool "Enable MEM Debug" + default n + depends on DEBUG_VERSION + help + Answer Y to enable LiteOS support mem debug. + +config MEM_LEAKCHECK + bool "Enable Function call stack of Mem operation recorded" + default n + depends on DEBUG_VERSION && MEM_DEBUG + select KERNEL_BACKTRACE + help + Answer Y to enable record the LR of Function call stack of Mem operation, it can check the mem leak through the infomations of mem node. +config BASE_MEM_NODE_INTEGRITY_CHECK + bool "Enable integrity check or not" + default n + depends on DEBUG_VERSION && MEM_DEBUG +config MEM_WATERLINE + bool "Enable memory pool waterline or not" + default n + depends on DEBUG_VERSION && MEM_DEBUG + +config VM_OVERLAP_CHECK + bool "Enable VM overlap check or not" + default n + depends on DEBUG_VERSION && MEM_DEBUG + help + Answer Y to enable vm overlap check. + +endmenu + +######################## config options os drivers ######################## +menu "Driver" +source "drivers/Kconfig" +endmenu + +######################## config options os security ####################### +menu "Security" +osource "security/Kconfig" +config SECURE_TRUSTZONE + bool "Enable ARM TrustZone" + default n + depends on ARCH_ARM +config SECURE_HEAP_SIZE + int "TrustZone Heap Size (bytes)" + default 2048 + depends on SECURE_TRUSTZONE +config SECURE_STACK_DEFAULT_SIZE + int "TrustZone Stack Size (bytes)" + default 512 + depends on SECURE_TRUSTZONE + help + The secure stack must be allocated before the task calls non-secure functions. +endmenu + +menu "Test" +config TEST + bool + default n +config KERNEL_TEST + bool "Enable Kernel Test" + default n + select TEST +config KERNEL_TEST_FULL + bool "Full Kernel Test" + default n + depends on KERNEL_TEST +endmenu + +menu "Stack Smashing Protector (SSP) Compiler Feature" + +choice + prompt "Enable stack buffer overflow detection" + default CC_STACKPROTECTOR_STRONG + ---help--- + This option turns on the -fstack-protector GCC feature. This + feature puts, at the beginning of functions, a canary value on + the stack just before the return address, and validates + the value just before actually returning. Stack based buffer + overflows (that need to overwrite this return address) now also + overwrite the canary, which gets detected and the attack is then + neutralized via a kernel panic. + + This feature requires gcc version 4.2 or above, or a distribution + gcc with the feature backported. Older versions are automatically + detected and for those versions, this configuration option is + ignored. (and a warning is printed during bootup) + +config CC_NO_STACKPROTECTOR + bool "-fno-stack-protector" + +config CC_STACKPROTECTOR + bool "-fstack-protector" + +config CC_STACKPROTECTOR_STRONG + bool "-fstack-protector-strong" + +config CC_STACKPROTECTOR_ALL + bool "-fstack-protector-all" + +endchoice + +endmenu diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..244aeef80a833274a18a826b32345acf457c341b --- /dev/null +++ b/Makefile @@ -0,0 +1,115 @@ +# 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. + +LITEOSTOPDIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST)))) +export LITEOSTOPDIR + +LITEOS_TARGET = liteos +HIDE := @ +KCONFIG_CMDS := $(notdir $(wildcard $(dir $(shell which menuconfig))*config)) + +ohos_kernel ?= liteos_m +$(foreach line,$(shell hb env | sed 's/\[OHOS INFO\]/ohos/g;s/ /_/g;s/:_/=/g' || true),$(eval $(line))) +ifneq ($(ohos_kernel),liteos_m) +$(error The selected product ($(ohos_product)) is not a liteos_m kernel type product) +endif + +ifeq ($(PRODUCT_PATH),) +PRODUCT_PATH:=$(ohos_product_path) +endif + +ifeq ($(DEVICE_PATH),) +DEVICE_PATH:=$(ohos_device_path) +endif + +ifeq ($(TEE:1=y),y) +tee = _tee +endif +ifeq ($(RELEASE:1=y),y) +CONFIG ?= $(PRODUCT_PATH)/kernel_configs/release$(tee).config +else +CONFIG ?= $(PRODUCT_PATH)/kernel_configs/debug$(tee).config +endif + +KCONFIG_CONFIG ?= $(CONFIG) +LITEOS_MENUCONFIG_H ?= $(LITEOSTOPDIR)/config.h +LITEOS_CONFIG_FILE ?= $(LITEOSTOPDIR)/.config + +# export los_config.mk related environment variables +export LITEOS_MENUCONFIG_H +export LITEOS_CONFIG_FILE + +# export kconfig related environment variables +export CONFIG_=LOSCFG_ +export srctree=$(LITEOSTOPDIR) + +-include $(LITEOS_CONFIG_FILE) + +define HELP = +Usage: make [TARGET]... [PARAMETER=VALUE]... + +Targets: + help: display this help and exit + clean: clean compiled objects + cleanall: clean all build outputs + all: do build (Default target) + update_config: update product kernel config (use menuconfig) + xxconfig: invoke xxconfig command of kconfiglib (xxconfig is one of $(KCONFIG_CMDS)) + +Parameters: + TEE: boolean value(1 or y for true), enable tee + RELEASE: boolean value(1 or y for true), build release version + CONFIG: kernel config file to be use + args: arguments for xxconfig command +endef +export HELP + +all: + $(HIDE)hb build -f --gn-args "liteos_kernel_only=true liteos_name=$(LITEOS_TARGET)" + +help: + $(HIDE)echo "$$HELP" + +$(filter-out menuconfig,$(KCONFIG_CMDS)): + $(HIDE)$@ $(args) + +$(LITEOS_CONFIG_FILE): $(KCONFIG_CONFIG) + $(HIDE)env KCONFIG_CONFIG=$< genconfig --config-out $@ --header-path $(LITEOS_MENUCONFIG_H) + +update_config menuconfig: + $(HIDE)test -f "$(CONFIG)" && cp -v "$(CONFIG)" .config && menuconfig $(args) && savedefconfig --out "$(CONFIG)" + +clean: + $(HIDE)hb clean + $(HIDE)echo "clean $(LOSCFG_PLATFORM) finish" + +cleanall: clean + $(HIDE)echo "clean all done" + +.PHONY: all clean cleanall help update_config $(KCONFIG_CMDS) $(KCONFIG_CONFIG) diff --git a/components/BUILD.gn b/components/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e666373e51b2d7337ed6a9b5dc44c4d2d69ef172 --- /dev/null +++ b/components/BUILD.gn @@ -0,0 +1,60 @@ +# 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("//kernel/liteos_m/liteos.gni") + +group("components") { + deps = [ + "backtrace", + "cppsupport", + "cpup", + "dynlink", + "exchook", + "fs", + "net", + "power", + "shell", + "trace", + ] +} + +config("public") { + configs = [ + "backtrace:public", + "cppsupport:public", + "cpup:public", + "dynlink:public", + "exchook:public", + "fs:public", + "net:public", + "power:public", + "shell:public", + "trace:public", + ] +} diff --git a/components/backtrace/BUILD.gn b/components/backtrace/BUILD.gn index c543abe9a7532770ecaf639fda3ea58f0b01261e..c25c5913d95f6cdd31ada13e1ba6814114de1090 100644 --- a/components/backtrace/BUILD.gn +++ b/components/backtrace/BUILD.gn @@ -27,10 +27,14 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import("//kernel/liteos_m/config.gni") +import("//kernel/liteos_m/liteos.gni") -static_library("backtrace") { +module_switch = defined(LOSCFG_KERNEL_BACKTRACE) +module_name = get_path_info(rebase_path("."), "name") +kernel_module(module_name) { sources = [ "los_backtrace.c" ] +} - configs += [ "$LITEOSTOPDIR:los_config" ] +config("public") { + include_dirs = [ "." ] } diff --git a/components/cppsupport/BUILD.gn b/components/cppsupport/BUILD.gn index 7a8a5ddca9b450abd83eeec0bde960ba7d6ec5b3..87e68716f135c860c27839ab9dac9c3114efbb31 100644 --- a/components/cppsupport/BUILD.gn +++ b/components/cppsupport/BUILD.gn @@ -27,10 +27,14 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import("//kernel/liteos_m/config.gni") +import("//kernel/liteos_m/liteos.gni") -static_library("cppsupport") { +module_switch = defined(LOSCFG_KERNEL_CPPSUPPORT) +module_name = get_path_info(rebase_path("."), "name") +kernel_module(module_name) { sources = [ "los_cppsupport.c" ] +} - configs += [ "$LITEOSTOPDIR:los_config" ] +config("public") { + include_dirs = [ "." ] } diff --git a/components/cpup/BUILD.gn b/components/cpup/BUILD.gn index 6c51771cc7d42e636ec47e16291114297d58ff28..5464b6a0b8882ec6b51f391eece9ed6f84b0fb5c 100644 --- a/components/cpup/BUILD.gn +++ b/components/cpup/BUILD.gn @@ -27,10 +27,14 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import("//kernel/liteos_m/config.gni") +import("//kernel/liteos_m/liteos.gni") -static_library("cpup") { +module_switch = defined(LOSCFG_BASE_CORE_CPUP) +module_name = get_path_info(rebase_path("."), "name") +kernel_module(module_name) { sources = [ "los_cpup.c" ] +} - configs += [ "$LITEOSTOPDIR:los_config" ] +config("public") { + include_dirs = [ "." ] } diff --git a/components/dynlink/BUILD.gn b/components/dynlink/BUILD.gn index 35b12b5357c298705ede6bc81d4f8686fe52799a..5c5ee1a89278707a89415a7f7a91866f593c44d8 100644 --- a/components/dynlink/BUILD.gn +++ b/components/dynlink/BUILD.gn @@ -26,23 +26,14 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import("//kernel/liteos_m/config.gni") +import("//kernel/liteos_m/liteos.gni") -config("dynlink_config") { - include_dirs = [ "./" ] - if (arch == "arm") { - include_dirs += [ "../../kernel/arch/arm/include" ] - } else { - assert(false, - "Dynlink module does not support for other archs except for arm!") - } -} - -static_library("dynlink") { +module_switch = defined(LOSCFG_KERNEL_DYNLINK) +module_name = get_path_info(rebase_path("."), "name") +kernel_module(module_name) { sources = [ "los_dynlink.c" ] +} - public_configs = [ ":dynlink_config" ] - configs += [ "$LITEOSTOPDIR:los_config" ] - - deps = [ "//kernel/liteos_m/kal/posix" ] +config("public") { + include_dirs = [ "." ] } diff --git a/components/exchook/BUILD.gn b/components/exchook/BUILD.gn index ab968eeda0147ae0e5404ed05b4e3f6a91bfb65f..15ad3cbe97718fb886a847d2be71a38e250de89c 100644 --- a/components/exchook/BUILD.gn +++ b/components/exchook/BUILD.gn @@ -27,13 +27,17 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import("//kernel/liteos_m/config.gni") +import("//kernel/liteos_m/liteos.gni") -static_library("exchook") { +module_switch = defined(LOSCFG_PLATFORM_EXC) +module_name = get_path_info(rebase_path("."), "name") +kernel_module(module_name) { sources = [ "los_exc_info.c", "los_exchook.c", ] +} - configs += [ "$LITEOSTOPDIR:los_config" ] +config("public") { + include_dirs = [ "." ] } diff --git a/components/fs/BUILD.gn b/components/fs/BUILD.gn index 16675cdd976103bd1be54210ce8ea9004e6dfbe5..3078c1670c01749221504ced51de5b65eaacb8cf 100644 --- a/components/fs/BUILD.gn +++ b/components/fs/BUILD.gn @@ -27,32 +27,26 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -static_library("fs_operations") { - sources = [ "./fs.c" ] +import("//kernel/liteos_m/liteos.gni") - include_dirs = [ - "../../../kernel/arch/include", - "../../../kernel/include", - "../../../utils", - "../../../kal/posix/include", - "./", - ] - - deps = [ "//kernel/liteos_m/kal/posix" ] +module_switch = defined(LOSCFG_FS_VFS) +module_name = "fs_operations" +kernel_module(module_name) { + sources = [ "fs.c" ] } -declare_args() { - enable_ohos_kernel_liteos_m_fatfs = true - enable_ohos_kernel_liteos_m_littlefs = true +group("fs") { + deps = [ ":$module_name" ] + deps += [ + "fatfs", + "littlefs", + ] } -group("fs") { - deps = [] - deps += [ ".:fs_operations" ] - if (enable_ohos_kernel_liteos_m_fatfs) { - deps += [ "fatfs:fatfs" ] - } - if (enable_ohos_kernel_liteos_m_littlefs) { - deps += [ "littlefs:littlefs" ] - } +config("public") { + include_dirs = [ "." ] + configs = [ + "fatfs:public", + "littlefs:public", + ] } diff --git a/components/fs/fatfs/BUILD.gn b/components/fs/fatfs/BUILD.gn index 04c494a5eeb1b9c439b1a3977cac687554fa7290..ec3682f883025c25cf6d71b611c8877ee7e8a70b 100644 --- a/components/fs/fatfs/BUILD.gn +++ b/components/fs/fatfs/BUILD.gn @@ -27,25 +27,21 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -static_library("fatfs") { +import("//kernel/liteos_m/liteos.gni") + +module_switch = defined(LOSCFG_FS_FAT) +module_name = get_path_info(rebase_path("."), "name") +kernel_module(module_name) { sources = [ - "//third_party/FatFs/source/diskio.c", - "//third_party/FatFs/source/ff.c", - "//third_party/FatFs/source/ffsystem.c", - "//third_party/FatFs/source/ffunicode.c", + "$LITEOSTHIRDPARTY/FatFs/source/diskio.c", + "$LITEOSTHIRDPARTY/FatFs/source/ff.c", + "$LITEOSTHIRDPARTY/FatFs/source/ffsystem.c", + "$LITEOSTHIRDPARTY/FatFs/source/ffunicode.c", "fatfs.c", ] +} - include_dirs = [ - "../", - "../../../kernel/arch/include", - "../../../kernel/include", - "../../../utils", - "../../../kal/cmsis", - "../../../kal/posix/include", - "//third_party/bounds_checking_function/include", - "//third_party/FatFs/source/", - ] - - deps = [ "//kernel/liteos_m/kal/posix" ] +config("public") { + include_dirs = [ "." ] + include_dirs += [ "$LITEOSTHIRDPARTY/FatFs/source" ] } diff --git a/components/fs/fatfs/Kconfig b/components/fs/fatfs/Kconfig new file mode 100644 index 0000000000000000000000000000000000000000..1d401bbd0ad53ac8ec9a942e809fa658b7acd34c --- /dev/null +++ b/components/fs/fatfs/Kconfig @@ -0,0 +1,45 @@ +config FS_FAT + bool "Enable FAT" + default n + depends on FS_VFS + select SUPPORT_FATFS + select COMPAT_CMSIS + help + Answer Y to enable LiteOS support fat filesystem. + +config FS_FAT_CACHE + bool "Enable FAT Cache" + default y + depends on FS_FAT + help + Answer Y to enable LiteOS fat filesystem support cache. + +config FS_FAT_CACHE_SYNC_THREAD + bool "Enable FAT Cache Sync Thread" + default n + depends on FS_FAT_CACHE + help + Answer Y to enable LiteOS fat filesystem support cache sync thread. + +config FS_FAT_CHINESE + bool "Enable Chinese" + default y + depends on FS_FAT + help + Answer Y to enable LiteOS fat filesystem support Chinese. + +config FS_FAT_VIRTUAL_PARTITION + bool "Enabel Virtual Partition" + default n + depends on FS_FAT + +config FS_FAT_VOLUMES + int + depends on FS_FAT + default 32 if PLATFORM_HI3731 + default 16 + +config FS_FAT_DISK + bool "Enable partinfo for storage device" + depends on FS_FAT + default y diff --git a/components/fs/fs.c b/components/fs/fs.c index 636667f9b22d32a64cc0182d30a6db0402bf3944..b28f2eea5385bd1ae8fb1192738350d1c28e25e2 100644 --- a/components/fs/fs.c +++ b/components/fs/fs.c @@ -45,18 +45,12 @@ #include "sys/stat.h" #include "unistd.h" -struct FsMap g_fsmap[MAX_FILESYSTEM_LEN] = {0}; -struct FsMap *g_fs = NULL; - #ifdef LOSCFG_NET_LWIP_SACK -#include "lwip/lwipopts.h" +#define _BSD_SOURCE #include "lwip/sockets.h" -#define CONFIG_NSOCKET_DESCRIPTORS LWIP_CONFIG_NUM_SOCKETS -#else -#define CONFIG_NSOCKET_DESCRIPTORS 0 #endif -#define CONFIG_NFILE_DESCRIPTORS FAT_MAX_OPEN_FILES /* only for random currently */ +#include "vfs_config.h" #ifdef LOSCFG_RANDOM_DEV #include "hks_client.h" @@ -159,6 +153,9 @@ static size_t GetCanonicalPath(const char *cwd, const char *path, char *buf, siz } #endif +static struct FsMap g_fsmap[MAX_FILESYSTEM_LEN] = {0}; +static struct FsMap *g_fs = NULL; + static void InitMountInfo(void) { #if (LOSCFG_SUPPORT_FATFS == 1) diff --git a/components/fs/littlefs/BUILD.gn b/components/fs/littlefs/BUILD.gn index d1908704dd1e0b4a4b3ecc6f3f8fd7939f92aa35..21b4a91ab68e9cc5ec6b29225dff395faa7266da 100644 --- a/components/fs/littlefs/BUILD.gn +++ b/components/fs/littlefs/BUILD.gn @@ -27,23 +27,21 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -static_library("littlefs") { +import("//kernel/liteos_m/liteos.gni") + +module_switch = defined(LOSCFG_FS_LITTLEFS) +module_name = get_path_info(rebase_path("."), "name") +kernel_module(module_name) { sources = [ - "//third_party/littlefs/lfs.c", - "//third_party/littlefs/lfs_util.c", + "$LITEOSTHIRDPARTY/littlefs/bd/lfs_rambd.c", + "$LITEOSTHIRDPARTY/littlefs/lfs.c", + "$LITEOSTHIRDPARTY/littlefs/lfs_util.c", "lfs_api.c", ] +} - include_dirs = [ - "../../../kernel/arch/include", - "../../../kernel/include", - "../../../utils", - "../../../kal/cmsis", - "../../../kal/posix/include", - "./", - "../", - "//third_party/littlefs", - ] - - deps = [ "//kernel/liteos_m/kal/posix" ] +config("public") { + include_dirs = [ "." ] + include_dirs += [ "$LITEOSTHIRDPARTY/littlefs" ] + include_dirs += [ "$LITEOSTHIRDPARTY/littlefs/bd" ] } diff --git a/components/fs/littlefs/lfs_api.h b/components/fs/littlefs/lfs_api.h index 9d0ccbf38397d1fb0040466a4dacfe7d42be5b62..8aa86068caed577835e1845391ccbc5e6daaa0df 100644 --- a/components/fs/littlefs/lfs_api.h +++ b/components/fs/littlefs/lfs_api.h @@ -93,7 +93,6 @@ typedef struct { LittleFsHandleStruct *GetFreeFd(int *fd); -int InitMountInfo(const char *fileSystemType, const struct MountOps *fsMops); int LfsMount(const char *source, const char *target, const char *fileSystemType, unsigned long mountflags, const void *data); @@ -114,7 +113,5 @@ int LfsStat(const char *path, struct stat *buf); int LfsFsync(int fd); int SetDefaultMountPath(int pathNameIndex, const char* target); -const struct FsMap *MountFindfs(const char *filesystemtype); - #endif /* _LFS_API_H_ */ diff --git a/components/fs/vfs_config.h b/components/fs/vfs_config.h new file mode 100644 index 0000000000000000000000000000000000000000..95b382b8d8854804698d8c408ee103ff3bda5351 --- /dev/null +++ b/components/fs/vfs_config.h @@ -0,0 +1,142 @@ +/* + * 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. + */ + +#ifndef _VFS_CONFIG_H_ +#define _VFS_CONFIG_H_ + +#define PATH_MAX 256 +#define CONFIG_DISABLE_MQUEUE // disable posix mqueue inode configure + +/* file system configur */ + +#define CONFIG_FS_WRITABLE // enable file system can be written +#define CONFIG_FS_READABLE // enable file system can be read +#define CONFIG_DEBUG_FS // enable vfs debug function + + +/* fatfs cache configur */ +/* config block size for fat file system, only can be 0,32,64,128,256,512,1024 */ +#define CONFIG_FS_FAT_SECTOR_PER_BLOCK 64 + +/* config block num for fat file system */ +#define CONFIG_FS_FAT_READ_NUMS 7 +#define CONFIG_FS_FAT_BLOCK_NUMS 28 + +#ifdef LOSCFG_FS_FAT_CACHE_SYNC_THREAD + +/* config the priority of sync task */ + +#define CONFIG_FS_FAT_SYNC_THREAD_PRIO 10 + +/* config dirty ratio of bcache for fat file system */ + +#define CONFIG_FS_FAT_DIRTY_RATIO 60 + +/* config time interval of sync thread for fat file system, in milliseconds */ + +#define CONFIG_FS_FAT_SYNC_INTERVAL 5000 +#endif + +#define CONFIG_FS_FLASH_BLOCK_NUM 1 + +#define CONFIG_FS_MAX_LNK_CNT 40 + +/* nfs configure */ + +#define CONFIG_NFS_MACHINE_NAME "IPC" // nfs device name is IPC +#define CONFIG_NFS_MACHINE_NAME_SIZE 3 // size of nfs machine name + + +/* file descriptors configure */ + +#define CONFIG_NFILE_STREAMS 1 // enable file stream +#define CONFIG_STDIO_BUFFER_SIZE 0 +#define CONFIG_NUNGET_CHARS 0 +#define MIN_START_FD 3 // 0,1,2 are used for stdin,stdout,stderr respectively + +#define FD_SET_TOTAL_SIZE (FD_SETSIZE + CONFIG_NEXPANED_DESCRIPTORS) +#define FD_SETSIZE (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS) +#define CONFIG_NEXPANED_DESCRIPTORS (CONFIG_NTIME_DESCRIPTORS + CONFIG_NQUEUE_DESCRIPTORS) +#define TIMER_FD_OFFSET FD_SETSIZE +#define MQUEUE_FD_OFFSET (FD_SETSIZE + CONFIG_NTIME_DESCRIPTORS) + +/* net configure */ + +#ifdef LOSCFG_NET_LWIP_SACK // enable socket and net function +#include "lwip/lwipopts.h" +#define CONFIG_NSOCKET_DESCRIPTORS LWIP_CONFIG_NUM_SOCKETS // max numbers of socket descriptor +#define CONFIG_NET_SENDFILE 1 // enable sendfile function +#define CONFIG_NET_TCP 1 // enable sendfile and send function +#else +#define CONFIG_NSOCKET_DESCRIPTORS 0 +#define CONFIG_NET_SENDFILE 0 // disable sendfile function +#define CONFIG_NET_TCP 0 // disable sendfile and send function +#endif + +/* max numbers of other descriptors except socket descriptors */ + +#ifdef LOSCFG_FS_FAT +#include "fatfs.h" +#define __FAT_NFILE FAT_MAX_OPEN_FILES +#else +#define __FAT_NFILE 0 +#endif + +#ifdef LOSCFG_FS_LITTLEFS +#include "lfs_api.h" +#define __LFS_NFILE LITTLE_FS_MAX_OPEN_FILES +#else +#define __LFS_NFILE 0 +#endif + +#define CONFIG_NFILE_DESCRIPTORS (__FAT_NFILE + __LFS_NFILE) + +#define NR_OPEN_DEFAULT CONFIG_NFILE_DESCRIPTORS + +/* time configure */ + +#define CONFIG_NTIME_DESCRIPTORS 0 + +/* mqueue configure */ + +#define CONFIG_NQUEUE_DESCRIPTORS 256 + +/* directory configure */ + +#define VFS_USING_WORKDIR // enable current working directory + +/* permission configure */ +#define DEFAULT_DIR_MODE 0777 +#define DEFAULT_FILE_MODE 0666 + +#define MAX_DIRENT_NUM 14 // 14 means 4096 length buffer can store 14 dirent, see struct DIR + +#endif diff --git a/config.gni b/components/net/BUILD.gn old mode 100755 new mode 100644 similarity index 71% rename from config.gni rename to components/net/BUILD.gn index 91b8d7e3d95670153a304a0092c71271647d1d18..5e15cf3e4587c267ace39cd0122895ef583d6dcf --- a/config.gni +++ b/components/net/BUILD.gn @@ -27,21 +27,16 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +import("//kernel/liteos_m/liteos.gni") + declare_args() { - enable_ohos_kernel_liteos_m_cppsupport = true - enable_ohos_kernel_liteos_m_cpup = true - enable_ohos_kernel_liteos_m_exchook = true - enable_ohos_kernel_liteos_m_kal = true - enable_ohos_kernel_liteos_m_fs = true - enable_ohos_kernel_liteos_m_shell = true - enable_ohos_kernel_liteos_m_backtrace = true - enable_ohos_kernel_liteos_m_test = false - enable_ohos_kernel_liteos_m_pm = true - enable_ohos_kernel_liteos_m_trace = false - enable_ohos_kernel_liteos_m_lwip = false - enable_ohos_kernel_liteos_m_dynlink = false - enable_ohos_kernel_liteos_m_tz = false - ohos_kernel_liteos_m_lwip_path = "components/net/lwip-2.1:lwip" + ohos_kernel_liteos_m_lwip_path = "lwip-2.1" +} + +config("public") { + configs = [ "$ohos_kernel_liteos_m_lwip_path:public" ] } -LITEOSTOPDIR = "//kernel/liteos_m" +group("net") { + deps = [ "$ohos_kernel_liteos_m_lwip_path" ] +} diff --git a/components/net/lwip-2.1/BUILD.gn b/components/net/lwip-2.1/BUILD.gn index 5a240130d92975b5e05b9dbcb3c14fbbb29d495e..1d1ee29a95e5a22af063c32b2599ad51e4dbe4f5 100644 --- a/components/net/lwip-2.1/BUILD.gn +++ b/components/net/lwip-2.1/BUILD.gn @@ -24,29 +24,20 @@ # 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. +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import("//third_party/lwip/lwip.gni") +import("//kernel/liteos_m/liteos.gni") +import("$LITEOSTHIRDPARTY/lwip/lwip.gni") import("lwip_porting.gni") -config("lwip_depends") { - defines = [ "_BSD_SOURCE = 1" ] +module_switch = defined(LOSCFG_NET_LWIP_SACK) +module_name = "lwip" +kernel_module(module_name) { + sources = LWIP_PORTING_FILES + LWIPNOAPPSFILES - [ "$LWIPDIR/api/sockets.c" ] + defines = [ "_BSD_SOURCE=1" ] + include_dirs = [ "//utils/native/lite/include" ] } -static_library("lwip") { - include_dirs = [ - "//kernel/liteos_m/kal/posix/include", - "//kernel/liteos_m/kernel/arch/include", - ] - - include_dirs += LWIP_PORTING_INCLUDE_DIRS - include_dirs += LWIP_INCLUDE_DIRS - - sources = LWIP_PORTING_FILES + LWIPNOAPPSFILES - - sources -= [ "$LWIPDIR/api/sockets.c" ] - - configs += [ ":lwip_depends" ] - - deps = [ "//kernel/liteos_m/kal/posix" ] +config("public") { + include_dirs = LWIP_PORTING_INCLUDE_DIRS + LWIP_INCLUDE_DIRS } diff --git a/components/net/lwip-2.1/lwip_porting.gni b/components/net/lwip-2.1/lwip_porting.gni old mode 100755 new mode 100644 index 9a0b631b6304a2f9ef62488e69cae6ef5d7fcf66..b6bb9ab80719afabbf7ce298e0edc28c8b57faf0 --- a/components/net/lwip-2.1/lwip_porting.gni +++ b/components/net/lwip-2.1/lwip_porting.gni @@ -25,8 +25,10 @@ # 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("//kernel/liteos_m/config.gni") -LWIP_PORTING_DIR = "//kernel/liteos_m/components/net/lwip-2.1" + +import("//kernel/liteos_m/liteos.gni") + +LWIP_PORTING_DIR = get_path_info(".", "abspath") LWIP_PORTING_INCLUDE_DIRS = [ "$LWIP_PORTING_DIR/porting/include" ] @@ -40,6 +42,6 @@ LWIP_PORTING_FILES = [ "$LWIP_PORTING_DIR/enhancement/src/lwip_ifaddrs.c", ] -if (enable_ohos_kernel_liteos_m_shell) { +if (defined(LOSCFG_SHELL)) { LWIP_PORTING_FILES += [ "$LWIP_PORTING_DIR/porting/src/api_shell.c" ] } diff --git a/components/net/lwip-2.1/porting/include/lwip/lwipopts.h b/components/net/lwip-2.1/porting/include/lwip/lwipopts.h index 512ed92f0e327f79a1ad44ad618b2ca398fa8dba..529f04a8ce0cbf3e902022d0df935342e7255f81 100644 --- a/components/net/lwip-2.1/porting/include/lwip/lwipopts.h +++ b/components/net/lwip-2.1/porting/include/lwip/lwipopts.h @@ -134,7 +134,10 @@ #define LWIP_NETIF_LOOPBACK 1 #define LWIP_POSIX_SOCKETS_IO_NAMES 0 #define LWIP_RAW 1 -#define LWIP_SOCKET_OFFSET 0 +#ifdef LOSCFG_FS_VFS +#include "vfs_config.h" +#define LWIP_SOCKET_OFFSET CONFIG_NFILE_DESCRIPTORS +#endif #define LWIP_SO_RCVBUF 1 #define LWIP_SO_RCVTIMEO 1 #define LWIP_SO_SNDTIMEO 1 diff --git a/components/power/BUILD.gn b/components/power/BUILD.gn index e0a8119b16466f7e020fc365508cd636b7baf2b2..4e11f10c5bdf8e61c8e614d86042cc193e6d1f33 100644 --- a/components/power/BUILD.gn +++ b/components/power/BUILD.gn @@ -27,10 +27,14 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import("//kernel/liteos_m/config.gni") +import("//kernel/liteos_m/liteos.gni") -static_library("pm") { +module_switch = defined(LOSCFG_KERNEL_PM) +module_name = get_path_info(rebase_path("."), "name") +kernel_module(module_name) { sources = [ "los_pm.c" ] +} - configs += [ "$LITEOSTOPDIR:los_config" ] +config("public") { + include_dirs = [ "." ] } diff --git a/components/shell/BUILD.gn b/components/shell/BUILD.gn index 93e310e7beca411e193ee9dfa791fe9500d3c4e0..f6422d6032e55bb59d2ae9760937aa80c3e6d119 100644 --- a/components/shell/BUILD.gn +++ b/components/shell/BUILD.gn @@ -27,9 +27,11 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import("//kernel/liteos_m/config.gni") +import("//kernel/liteos_m/liteos.gni") -static_library("shell") { +module_switch = defined(LOSCFG_SHELL) +module_name = get_path_info(rebase_path("."), "name") +kernel_module(module_name) { sources = [ "src/base/shcmd.c", "src/base/shcmdparse.c", @@ -42,21 +44,11 @@ static_library("shell") { "src/cmds/task_shellcmd.c", "src/cmds/vfs_shellcmd.c", ] - - include_dirs = [ - "../../kernel/arch/include", - "../../kernel/include", - "../../utils", - "./include", - ] - - configs += [ "$LITEOSTOPDIR:los_config" ] - - if (enable_ohos_kernel_liteos_m_lwip) { + if (defined(LOSCFG_NET_LWIP_SACK)) { defines = [ "LWIP_SHELLCMD_ENABLE" ] } - deps = [ - "//kernel/liteos_m/kal/posix", - "//third_party/bounds_checking_function:libsec_static", - ] +} + +config("public") { + include_dirs = [ "include" ] } diff --git a/components/shell/Kconfig b/components/shell/Kconfig new file mode 100644 index 0000000000000000000000000000000000000000..0148daa8e306f2cf659626872acaf0914bb72b07 --- /dev/null +++ b/components/shell/Kconfig @@ -0,0 +1,36 @@ +config SHELL + bool "Enable Shell" + default n + depends on DEBUG_VERSION + select USE_SHELL + help + Answer Y to enable LiteOS support shell cmd. + +config USE_SHELL + bool + default n + +menu "Functionality of Shell" + depends on SHELL + +config SHELL_PRIO + int "Shell Task Priority" + default 3 + range 1 31 + depends on SHELL + +config SHELL_LK + bool "Enable Shell lk" + default y + depends on DEBUG_VERSION && SHELL + help + Answer Y to enable LiteOS support shell lk. + +config SHELL_DMESG + bool "Enable Shell dmesg" + default n + depends on DEBUG_VERSION && SHELL && SHELL_CMD_DEBUG + help + Answer Y to enable LiteOS support shell dmesg. + +endmenu diff --git a/components/trace/BUILD.gn b/components/trace/BUILD.gn index c3b3314663b884d377e3a07b0d28a2a48a0b63a1..664729be17a3fecc9c92fc55ac08956228253031 100644 --- a/components/trace/BUILD.gn +++ b/components/trace/BUILD.gn @@ -27,24 +27,39 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import("//kernel/liteos_m/config.gni") +import("//kernel/liteos_m/liteos.gni") -static_library("trace") { +module_switch = defined(LOSCFG_KERNEL_TRACE) +module_name = get_path_info(rebase_path("."), "name") +kernel_module(module_name) { sources = [ "cnv/trace_cnv.c", "los_trace.c", - "pipeline/serial/trace_pipeline_serial.c", - "pipeline/trace_pipeline.c", - "pipeline/trace_tlv.c", - "trace_offline.c", - "trace_online.c", ] include_dirs = [ - "./", + ".", "cnv", "pipeline", - "pipeline/serial", ] - configs += [ "$LITEOSTOPDIR:los_config" ] + + if (defined(LOSCFG_RECORDER_MODE_OFFLINE)) { + sources += [ "trace_offline.c" ] + } + + if (defined(LOSCFG_RECORDER_MODE_ONLINE)) { + sources += [ "trace_online.c" ] + } + + if (defined(LOSCFG_TRACE_CLIENT_INTERACT)) { + sources += [ + "pipeline/trace_pipeline.c", + "pipeline/trace_tlv.c", + ] + } + + if (defined(LOSCFG_TRACE_PIPELINE_SERIAL)) { + sources += [ "pipeline/serial/trace_pipeline_serial.c" ] + include_dirs += [ "pipeline/serial" ] + } } diff --git a/components/trace/Kconfig b/components/trace/Kconfig new file mode 100644 index 0000000000000000000000000000000000000000..ff901035043246fa029cfccf36dc150e24ff8f15 --- /dev/null +++ b/components/trace/Kconfig @@ -0,0 +1,78 @@ +config KERNEL_TRACE + bool "Enable Trace Feature" + default n + depends on DEBUG_HOOK + +config TRACE_MSG_EXTEND + bool "Enable Record more extended content" + default n + depends on KERNEL_TRACE + +config TRACE_FRAME_CORE_MSG + bool "Record cpuid, hardware interrupt status, task lock status" + default n + depends on TRACE_MSG_EXTEND + +config TRACE_FRAME_EVENT_COUNT + bool "Record event count, which indicate the sequence of happend events" + default n + depends on TRACE_MSG_EXTEND + +config TRACE_FRAME_MAX_PARAMS + int "Record max params" + default 3 + depends on KERNEL_TRACE + help + Make sure the max value is bigger than the number defined by each #MODULE#_#TYPE#_PARMAS in los_trace.h, e.g. TASK_SWITCH_PARAMS + +choice + prompt "Trace work mode" + default RECORDER_MODE_OFFLINE + depends on KERNEL_TRACE + +config RECORDER_MODE_ONLINE + bool "Online mode" + select TRACE_CLIENT_INTERACT + +config RECORDER_MODE_OFFLINE + bool "Offline mode" + +endchoice + +config TRACE_BUFFER_SIZE + int "Trace record buffer size" + default 2048 + depends on RECORDER_MODE_OFFLINE + +config TRACE_CLIENT_INTERACT + bool "Enable Trace Client Visualization and Control" + default n + depends on KERNEL_TRACE + +choice + prompt "Trace Pipeline for Data Transmission" + depends on TRACE_CLIENT_INTERACT + +config TRACE_PIPELINE_SERIAL + bool "Via Serial" + +endchoice + +choice + prompt "Trace Control" + default TRACE_CONTROL_VIA_SHELL + depends on TRACE_CLIENT_INTERACT + help + If you wish to control Trace's start/stop etc.,dynamically by Trace Client. + +config TRACE_CONTROL_VIA_SHELL + bool "Via Shell" + select LOSCFG_SHELL + +config TRACE_CONTROL_AGENT + bool "Via Trace Agent Task" + +config TRACE_NO_CONTROL + bool "No Control" + +endchoice \ No newline at end of file diff --git a/drivers/Kconfig b/drivers/Kconfig new file mode 100644 index 0000000000000000000000000000000000000000..6509991c5f0d952e53df80abbda29cfbb8d54040 --- /dev/null +++ b/drivers/Kconfig @@ -0,0 +1,10 @@ +config DRIVERS + bool "Enable Driver" + default y + help + Answer Y to enable LiteOS support driver. + +source "../../drivers/adapter/khdf/liteos_m/Kconfig" + +# Device driver Kconfig import +osource "$(DEVICE_PATH)/drivers/Kconfig" diff --git a/kal/BUILD.gn b/kal/BUILD.gn index 295668d72c5c0c32216e4923b1e383c345095f2f..0850528a7a123afd5c7a33dd98a9ae1d775e9b5e 100644 --- a/kal/BUILD.gn +++ b/kal/BUILD.gn @@ -27,21 +27,16 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import("//build/lite/config/component/lite_component.gni") +import("//kernel/liteos_m/liteos.gni") -declare_args() { - enable_ohos_kernel_liteos_m_cmsis = true - enable_ohos_kernel_liteos_m_posix = true +group("kal") { + deps = [ "cmsis" ] + deps += [ "posix" ] } -lite_component("kal") { - features = [] - - if (enable_ohos_kernel_liteos_m_cmsis) { - features += [ "cmsis" ] - } - - if (enable_ohos_kernel_liteos_m_posix) { - features += [ "posix" ] - } +config("public") { + configs = [ + "cmsis:public", + "posix:public", + ] } diff --git a/kal/cmsis/BUILD.gn b/kal/cmsis/BUILD.gn index 2782b12fa3f6da9c16112f898a015bfe38448cae..3c45fabae66a8923b47b0d009a33128dbc15ca8d 100644 --- a/kal/cmsis/BUILD.gn +++ b/kal/cmsis/BUILD.gn @@ -27,18 +27,18 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import("//kernel/liteos_m/config.gni") +import("//kernel/liteos_m/liteos.gni") -static_library("cmsis") { +module_switch = defined(LOSCFG_COMPAT_CMSIS) +module_name = get_path_info(rebase_path("."), "name") +kernel_module(module_name) { sources = [ "cmsis_liteos2.c" ] - - public_configs = [ ":include" ] - configs += [ "$LITEOSTOPDIR:los_config" ] } -config("include") { +config("public") { include_dirs = [ ".", - "//third_party/cmsis/CMSIS/RTOS2/Include", + "$LITEOSTHIRDPARTY/cmsis/CMSIS/RTOS2/Include", + "$LITEOSTHIRDPARTY/cmsis/CMSIS/Core/Include", ] } diff --git a/kal/posix/BUILD.gn b/kal/posix/BUILD.gn index d192a8aeea87a1d56936171cc74f0bb778f464d7..8da23522b034aca84f821ac73b3c91b6d054cc84 100644 --- a/kal/posix/BUILD.gn +++ b/kal/posix/BUILD.gn @@ -27,13 +27,11 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import("//kernel/liteos_m/config.gni") +import("//kernel/liteos_m/liteos.gni") -config("include") { - include_dirs = [ "include" ] -} - -static_library("posix") { +module_switch = defined(LOSCFG_COMPAT_POSIX) +module_name = get_path_info(rebase_path("."), "name") +kernel_module(module_name) { sources = [ "src/errno.c", "src/libc.c", @@ -46,9 +44,8 @@ static_library("posix") { "src/semaphore.c", "src/time.c", ] +} - public_configs = [ ":include" ] - configs += [ "$LITEOSTOPDIR:los_config" ] - - public_deps = [ "//third_party/musl/porting/liteos_m/kernel" ] +config("public") { + include_dirs = [ "include" ] } diff --git a/kernel/BUILD.gn b/kernel/BUILD.gn index 81d8ea66af746a7c4465ba6e021b4d03c00c196d..7851eb26ac8e9d195dac551b818d8bb8c79f463c 100644 --- a/kernel/BUILD.gn +++ b/kernel/BUILD.gn @@ -27,9 +27,10 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import("//kernel/liteos_m/config.gni") +import("//kernel/liteos_m/liteos.gni") -static_library("kernel") { +module_name = get_path_info(rebase_path("."), "name") +kernel_module(module_name) { sources = [ "src/los_event.c", "src/los_init.c", @@ -44,36 +45,8 @@ static_library("kernel") { "src/mm/los_membox.c", "src/mm/los_memory.c", ] +} - include_dirs = [ - "../components/cpup", - "../components/exchook", - "../components/backtrace", - "../components/power", - "../components/dynlink", - ] - - configs += [ "$LITEOSTOPDIR:los_config" ] - - if ("$board_cpu" == "cortex-m3") { - deps = [ "arch/arm/cortex-m3/gcc/:arch" ] - } else if ("$board_cpu" == "cortex-m4") { - deps = [ "arch/arm/cortex-m4/gcc/:arch" ] - } else if ("$board_cpu" == "cortex-m7") { - deps = [ "arch/arm/cortex-m7/gcc/:arch" ] - } else if ("$board_cpu" == "cortex-m33") { - if (enable_ohos_kernel_liteos_m_tz) { - deps = [ "arch/arm/cortex-m33/gcc/TZ:arch" ] - } else { - deps = [ "arch/arm/cortex-m33/gcc/NTZ:arch" ] - } - } else if ("$board_cpu" == "ck802" || "$board_cpu" == "e802") { - deps = [ "arch/csky/v2/gcc:arch" ] - } else if ("$board_cpu" == "") { - if ("$board_arch" == "rv32imac" || "$board_arch" == "rv32imafdc") { - deps = [ "arch/risc-v/riscv32/gcc:arch" ] - } else if ("$board" == "esp32") { - deps = [ "arch/xtensa/lx6/gcc:arch" ] - } - } +config("public") { + include_dirs = [ "include" ] } diff --git a/kernel/arch/BUILD.gn b/kernel/arch/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..6367bf1aecf6b36f4f1e8aba66fc371227acc462 --- /dev/null +++ b/kernel/arch/BUILD.gn @@ -0,0 +1,81 @@ +# 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("//kernel/liteos_m/liteos.gni") + +group("arch") { + if ("$board_cpu" == "cortex-m3") { + deps = [ "arm/cortex-m3/gcc/:arch" ] + } else if ("$board_cpu" == "cortex-m4") { + deps = [ "arm/cortex-m4/gcc/:arch" ] + } else if ("$board_cpu" == "cortex-m7") { + deps = [ "arm/cortex-m7/gcc/:arch" ] + } else if ("$board_cpu" == "cortex-m33") { + if (defined(LOSCFG_SECURE_TRUSTZONE)) { + deps = [ "arm/cortex-m33/gcc/TZ:arch" ] + } else { + deps = [ "arm/cortex-m33/gcc/NTZ:arch" ] + } + } else if ("$board_cpu" == "ck802" || "$board_cpu" == "e802") { + deps = [ "csky/v2/gcc:arch" ] + } else if ("$board_cpu" == "") { + if ("$board_arch" == "rv32imac" || "$board_arch" == "rv32imafdc") { + deps = [ "risc-v/riscv32/gcc:arch" ] + } else if ("$board" == "esp32") { + deps = [ "xtensa/lx6/gcc:arch" ] + } + } +} + +config("public") { + include_dirs = [ "include" ] + if (defined(LOSCFG_ARCH_ARM)) { + include_dirs += [ "arm/include" ] + if (defined(LOSCFG_ARCH_CORTEX_M3)) { + include_dirs += [ "arm/cortex-m3/gcc" ] + } else if (defined(LOSCFG_ARCH_CORTEX_M4)) { + include_dirs += [ "arm/cortex-m4/gcc" ] + } else if (defined(LOSCFG_ARCH_CORTEX_M7)) { + include_dirs += [ "arm/cortex-m7/gcc" ] + } else if (defined(LOSCFG_ARCH_CORTEX_M33)) { + if (defined(LOSCFG_TRUSTZONE)) { + include_dirs += [ "arm/cortex-m33/gcc/TZ/non_secure" ] + } else { + include_dirs += [ "arm/cortex-m33/gcc/NTZ" ] + } + } + } else if (defined(LOSCFG_ARCH_RISCV32)) { + include_dirs += [ "risc-v/riscv32/gcc" ] + include_dirs += [ "risc-v/riscv32/gcc/asm" ] + } else if (defined(LOSCFG_ARCH_CSKY)) { + include_dirs += [ "csky/v2/gcc" ] + } else if (defined(LOSCFG_ARCH_XTENSA)) { + include_dirs += [ "xtensa/lx6/gcc" ] + } +} diff --git a/kernel/arch/Kconfig b/kernel/arch/Kconfig new file mode 100644 index 0000000000000000000000000000000000000000..86dce9505e4f8fd7806f2e4b1d31810388a14f2c --- /dev/null +++ b/kernel/arch/Kconfig @@ -0,0 +1,46 @@ +config ARCH_ARM + bool + +rsource "arm/Kconfig" + +config ARCH_CSKY + bool + +config ARCH_RISCV + bool + +config ARCH_RISCV32 + bool + select ARCH_RISCV + +config ARCH_XTENSA + bool + +comment "Extra Configurations" + +config ARCH_FPU_DISABLE + bool "Disable Floating Pointer Unit" + default n + help + This option will bypass floating procedure in system. + +config ARCH_SECURE_MONITOR_MODE + bool "Run On Secure Monitor Mode" + default n + depends on ARCH_ARM_AARCH64 + help + This option will make the system run on EL3. + +config ARCH_INTERRUPT_PREEMPTION + bool "Enable Interrupt Preemption" + default n + depends on ARCH_ARM_AARCH64 + help + This option will support high priority interrupt preemption. + +config IRQ_USE_STANDALONE_STACK + bool "Use Interrupt Stack" + default y + depends on ARCH_ARM_AARCH64 || ARCH_ARM_AARCH32 + help + This option will support using standalone interrupt stack. diff --git a/kernel/arch/arm/Kconfig b/kernel/arch/arm/Kconfig new file mode 100644 index 0000000000000000000000000000000000000000..b8fb0225a7197d558fcdfd0278d77507a7187398 --- /dev/null +++ b/kernel/arch/arm/Kconfig @@ -0,0 +1,108 @@ +# ARM Architecture + +# +# ARM has 32-bit(Aarch32) and 64-bit(Aarch64) implementations +# +config ARCH_ARM_AARCH32 + bool + select ARCH_ARM + help + 32-bit ARM architecture implementations, Except the M-profile. + It is not limited to ARMv7-A but also ARMv7-R, ARMv8-A 32-bit and etc. + +# +# Architecture Versions +# +config ARCH_ARM_V7M + bool + +config ARCH_ARM_V5TE + bool + +config ARCH_ARM_VER + string + default "armv7-m" if ARCH_ARM_V7M + default "armv5te" if ARCH_ARM_V5TE + +# +# VFP Hardware +# +config ARCH_FPU_VFP_V3 + bool + help + An optional extension to the Arm, Thumb, and ThumbEE instruction sets in the ARMv7-A and ARMv7-R profiles. + VFPv3U is a variant of VFPv3 that supports the trapping of floating-point exceptions to support code. + +config ARCH_FPU_VFP_V4 + bool + help + An optional extension to the Arm, Thumb, and ThumbEE instruction sets in the ARMv7-A and ARMv7-R profiles. + VFPv4U is a variant of VFPv4 that supports the trapping of floating-point exceptions to support code. + VFPv4 and VFPv4U add both the Half-precision Extension and the fused multiply-add instructions to the features of VFPv3. + +config ARCH_FPU_VFP_D16 + bool + depends on ARCH_ARM_AARCH32 + help + VPU implemented with 16 doubleword registers (16 x 64-bit). + +config ARCH_FPU_VFP_D32 + bool + depends on ARCH_ARM_AARCH32 + help + VPU implemented with 32 doubleword registers (32 x 64-bit). + +config ARCH_FPU_VFP_NEON + bool + help + Advanced SIMD extension (NEON) support. + +config ARCH_FPU + string + default "vfpv3" if ARCH_FPU_VFP_V3 && ARCH_FPU_VFP_D32 + default "vfpv3-d16" if ARCH_FPU_VFP_V3 && ARCH_FPU_VFP_D16 + default "neon-vfpv4" if ARCH_FPU_VFP_V4 && ARCH_FPU_VFP_D32 && ARCH_FPU_VFP_NEON + default "vfpv4" if ARCH_FPU_VFP_V4 && ARCH_FPU_VFP_D32 + default "vfpv4-d16" if ARCH_FPU_VFP_V4 && ARCH_FPU_VFP_D16 + +# +# Supported Processor Cores +# +config ARCH_CORTEX_M3 + bool + select ARCH_ARM_V7M + select ARCH_ARM_AARCH32 + +config ARCH_CORTEX_M4 + bool + select ARCH_ARM_V7M + select ARCH_ARM_AARCH32 + +config ARCH_CORTEX_M7 + bool + select ARCH_ARM_V7M + select ARCH_ARM_AARCH32 + select ARCH_FPU_VFP_V4 + select ARCH_FPU_VFP_D32 + select ARCH_FPU_VFP_NEON + +config ARCH_CORTEX_M33 + bool + select ARCH_ARM_V7M + select ARCH_ARM_AARCH32 + select ARCH_FPU_VFP_V4 + select ARCH_FPU_VFP_D32 + select ARCH_FPU_VFP_NEON + +config ARCH_ARM9 + bool + select ARCH_ARM_V5TE + select ARCH_ARM_AARCH32 + +config ARCH_CPU + string + default "cortex-m3" if ARCH_CORTEX_M3 + default "cortex-m4" if ARCH_CORTEX_M4 + default "cortex-m7" if ARCH_CORTEX_M7 + default "cortex-m33" if ARCH_CORTEX_M33 + default "arm9" if ARCH_ARM9 diff --git a/kernel/arch/arm/arm9/gcc/BUILD.gn b/kernel/arch/arm/arm9/gcc/BUILD.gn index a6cdddb942d59598c9602a7d1b99e15ea7619679..105d00dc65859da686714f590e061b9f82f79c00 100644 --- a/kernel/arch/arm/arm9/gcc/BUILD.gn +++ b/kernel/arch/arm/arm9/gcc/BUILD.gn @@ -27,9 +27,10 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import("//kernel/liteos_m/config.gni") +import("//kernel/liteos_m/liteos.gni") -static_library("arch") { +module_name = "arch" +kernel_module(module_name) { sources = [ "los_context.c", "los_dispatch.S", @@ -38,6 +39,4 @@ static_library("arch") { "los_timer.c", "reset_vector.S", ] - - configs += [ "$LITEOSTOPDIR:los_config" ] } diff --git a/kernel/arch/arm/cortex-m33/gcc/BUILD.gn b/kernel/arch/arm/cortex-m33/gcc/BUILD.gn index 9adb6f493335f5cd6d30abb4f9a23cf38fee05ab..a0ecc6b335536d8d10c186b8dba9c8d6792d7b53 100644 --- a/kernel/arch/arm/cortex-m33/gcc/BUILD.gn +++ b/kernel/arch/arm/cortex-m33/gcc/BUILD.gn @@ -27,9 +27,10 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import("//kernel/liteos_m/config.gni") +import("//kernel/liteos_m/liteos.gni") -static_library("arch") { +module_name = "arch" +kernel_module(module_name) { sources = [ "los_context.c", "los_dispatch.S", @@ -37,6 +38,4 @@ static_library("arch") { "los_interrupt.c", "los_timer.c", ] - - configs += [ "$LITEOSTOPDIR:los_config" ] } diff --git a/kernel/arch/arm/cortex-m33/gcc/NTZ/BUILD.gn b/kernel/arch/arm/cortex-m33/gcc/NTZ/BUILD.gn index 9adb6f493335f5cd6d30abb4f9a23cf38fee05ab..a0ecc6b335536d8d10c186b8dba9c8d6792d7b53 100755 --- a/kernel/arch/arm/cortex-m33/gcc/NTZ/BUILD.gn +++ b/kernel/arch/arm/cortex-m33/gcc/NTZ/BUILD.gn @@ -27,9 +27,10 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import("//kernel/liteos_m/config.gni") +import("//kernel/liteos_m/liteos.gni") -static_library("arch") { +module_name = "arch" +kernel_module(module_name) { sources = [ "los_context.c", "los_dispatch.S", @@ -37,6 +38,4 @@ static_library("arch") { "los_interrupt.c", "los_timer.c", ] - - configs += [ "$LITEOSTOPDIR:los_config" ] } diff --git a/kernel/arch/arm/cortex-m33/gcc/TZ/BUILD.gn b/kernel/arch/arm/cortex-m33/gcc/TZ/BUILD.gn index 9e31917895b469034ca7cc6bbdc18adfa20b9698..7299844af822348d5c241a97b3cc1ada09351cab 100644 --- a/kernel/arch/arm/cortex-m33/gcc/TZ/BUILD.gn +++ b/kernel/arch/arm/cortex-m33/gcc/TZ/BUILD.gn @@ -27,9 +27,10 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import("//kernel/liteos_m/config.gni") +import("//kernel/liteos_m/liteos.gni") -static_library("arch") { +module_name = "arch" +kernel_module(module_name) { sources = [ "non_secure/los_context.c", "non_secure/los_dispatch.S", @@ -40,9 +41,7 @@ static_library("arch") { ] include_dirs = [ - "./non_secure", - "./secure", + "non_secure", + "secure", ] - - configs += [ "$LITEOSTOPDIR:los_config" ] } diff --git a/kernel/arch/arm/cortex-m4/gcc/BUILD.gn b/kernel/arch/arm/cortex-m4/gcc/BUILD.gn index 9fcb66e12ca65f429107ba82d017726917c7dea2..a22e60037b967b86c207b743c7ff1b55ae1dd336 100644 --- a/kernel/arch/arm/cortex-m4/gcc/BUILD.gn +++ b/kernel/arch/arm/cortex-m4/gcc/BUILD.gn @@ -27,9 +27,10 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import("//kernel/liteos_m/config.gni") +import("//kernel/liteos_m/liteos.gni") -static_library("arch") { +module_name = "arch" +kernel_module(module_name) { sources = [ "los_context.c", "los_dispatch.S", @@ -38,6 +39,4 @@ static_library("arch") { "los_mpu.c", "los_timer.c", ] - - configs += [ "$LITEOSTOPDIR:los_config" ] } diff --git a/kernel/arch/arm/cortex-m7/gcc/BUILD.gn b/kernel/arch/arm/cortex-m7/gcc/BUILD.gn index 9fcb66e12ca65f429107ba82d017726917c7dea2..a22e60037b967b86c207b743c7ff1b55ae1dd336 100644 --- a/kernel/arch/arm/cortex-m7/gcc/BUILD.gn +++ b/kernel/arch/arm/cortex-m7/gcc/BUILD.gn @@ -27,9 +27,10 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import("//kernel/liteos_m/config.gni") +import("//kernel/liteos_m/liteos.gni") -static_library("arch") { +module_name = "arch" +kernel_module(module_name) { sources = [ "los_context.c", "los_dispatch.S", @@ -38,6 +39,4 @@ static_library("arch") { "los_mpu.c", "los_timer.c", ] - - configs += [ "$LITEOSTOPDIR:los_config" ] } diff --git a/kernel/arch/csky/v2/gcc/BUILD.gn b/kernel/arch/csky/v2/gcc/BUILD.gn index 9adb6f493335f5cd6d30abb4f9a23cf38fee05ab..a0ecc6b335536d8d10c186b8dba9c8d6792d7b53 100644 --- a/kernel/arch/csky/v2/gcc/BUILD.gn +++ b/kernel/arch/csky/v2/gcc/BUILD.gn @@ -27,9 +27,10 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import("//kernel/liteos_m/config.gni") +import("//kernel/liteos_m/liteos.gni") -static_library("arch") { +module_name = "arch" +kernel_module(module_name) { sources = [ "los_context.c", "los_dispatch.S", @@ -37,6 +38,4 @@ static_library("arch") { "los_interrupt.c", "los_timer.c", ] - - configs += [ "$LITEOSTOPDIR:los_config" ] } diff --git a/kernel/arch/risc-v/riscv32/gcc/BUILD.gn b/kernel/arch/risc-v/riscv32/gcc/BUILD.gn index 55b0138d1faf64b3de3622338642feac7d4d4101..9fa6c4ce51a972d814de7ba75400ffb0d873216b 100644 --- a/kernel/arch/risc-v/riscv32/gcc/BUILD.gn +++ b/kernel/arch/risc-v/riscv32/gcc/BUILD.gn @@ -27,10 +27,10 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import("//kernel/liteos_m/config.gni") +import("//kernel/liteos_m/liteos.gni") -static_library("arch") { - asmflags = board_asmflags +module_name = "arch" +kernel_module(module_name) { sources = [ "los_context.c", "los_dispatch.S", @@ -40,6 +40,4 @@ static_library("arch") { ] include_dirs = [ "asm" ] - - configs += [ "$LITEOSTOPDIR:los_config" ] } diff --git a/kernel/arch/xtensa/lx6/gcc/BUILD.gn b/kernel/arch/xtensa/lx6/gcc/BUILD.gn index 04cc46404338927efdd942062a0682f2d345068f..9bd87108c76dbb68454e8ba5845a54879e32b179 100644 --- a/kernel/arch/xtensa/lx6/gcc/BUILD.gn +++ b/kernel/arch/xtensa/lx6/gcc/BUILD.gn @@ -27,9 +27,10 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import("//kernel/liteos_m/config.gni") +import("//kernel/liteos_m/liteos.gni") -static_library("arch") { +module_name = "arch" +kernel_module(module_name) { sources = [ "los_context.c", "los_dispatch.S", @@ -38,6 +39,4 @@ static_library("arch") { "los_timer.c", "los_window.S", ] - - configs += [ "$LITEOSTOPDIR:los_config" ] } diff --git a/kernel/include/los_config.h b/kernel/include/los_config.h index 52f8d31000e4be7382070493175bde7c0477f358..e70ffabf3f2537542fa60e8a16fcca9dcb79e356 100644 --- a/kernel/include/los_config.h +++ b/kernel/include/los_config.h @@ -478,21 +478,6 @@ extern UINT8 *m_aucSysMem0; #define LOSCFG_BASE_MEM_NODE_INTEGRITY_CHECK 0 #endif -/** - * @ingroup los_config - * Configuration memory leak detection - * @attention - * Need to enable backtrace module synchronously by configuration LOSCFG_BACKTRACE_TYPE, - * and call OsBackTraceInit to complete initialization before the memory pool is initialized. - */ -#ifndef LOSCFG_MEM_LEAKCHECK -#define LOSCFG_MEM_LEAKCHECK 0 -#endif - -#if (LOSCFG_MEM_LEAKCHECK == 1) && (LOSCFG_BACKTRACE_TYPE == 0) - #error "if LOSCFG_MEM_LEAKCHECK is set to 1, then LOSCFG_BACKTRACE_TYPE must be set to 1, 2 or 3." -#endif - /** * @ingroup los_config * The default is 4, which means that the function call stack is recorded from the kernel interface, @@ -565,14 +550,6 @@ extern UINT8 *m_aucSysMem0; /* ============================================================================= Exception module configuration ============================================================================= */ -/** - * @ingroup los_config - * Configuration item for exception tailoring - */ -#ifndef LOSCFG_PLATFORM_EXC -#define LOSCFG_PLATFORM_EXC 0 -#endif - /** * @ingroup los_config * Configuration of hardware stack protection @@ -582,27 +559,8 @@ extern UINT8 *m_aucSysMem0; #endif /* ============================================================================= - CPUP module configuration + KAL module configuration ============================================================================= */ -/** - * @ingroup los_config - * Configuration item for CPU usage tailoring - */ -#ifndef LOSCFG_BASE_CORE_CPUP -#define LOSCFG_BASE_CORE_CPUP 0 -#endif - -/* ============================================================================= - Test module configuration -============================================================================= */ -/** - * @ingroup los_config - * Configuration test case to open - */ -#ifndef LOSCFG_TEST -#define LOSCFG_TEST 0 -#endif - /** * @ingroup los_config * Configuration CMSIS_OS_VER @@ -611,21 +569,6 @@ extern UINT8 *m_aucSysMem0; #define CMSIS_OS_VER 2 #endif -/* ============================================================================= - Fs module configuration -============================================================================= */ -#ifndef LOSCFG_SUPPORT_FATFS -#define LOSCFG_SUPPORT_FATFS 0 -#endif - -#ifndef LOSCFG_SUPPORT_LITTLEFS -#define LOSCFG_SUPPORT_LITTLEFS 1 -#endif - -#ifndef LOSCFG_LFS_MAX_MOUNT_SIZE -#define LOSCFG_LFS_MAX_MOUNT_SIZE 3 -#endif - /* ============================================================================= Trace module configuration ============================================================================= */ @@ -633,46 +576,9 @@ extern UINT8 *m_aucSysMem0; * @ingroup los_config * Configuration trace tool */ -#ifndef LOSCFG_DEBUG_HOOK -#define LOSCFG_DEBUG_HOOK 0 -#endif - -#if (LOSCFG_DEBUG_HOOK == 1) -#ifndef LOSCFG_KERNEL_TRACE -#define LOSCFG_KERNEL_TRACE 0 -#endif -#endif #if (LOSCFG_KERNEL_TRACE == 1) -#ifndef LOSCFG_TRACE_FRAME_MAX_PARAMS -#define LOSCFG_TRACE_FRAME_MAX_PARAMS 3 -#endif - -#ifndef LOSCFG_TRACE_FRAME_EVENT_COUNT -#define LOSCFG_TRACE_FRAME_EVENT_COUNT 0 -#endif - -#ifndef LOSCFG_RECORDER_MODE_OFFLINE -#define LOSCFG_RECORDER_MODE_OFFLINE 1 -#endif - -#ifndef LOSCFG_RECORDER_MODE_ONLINE -#define LOSCFG_RECORDER_MODE_ONLINE 0 -#endif - -#if (!(LOSCFG_RECORDER_MODE_OFFLINE ^ LOSCFG_RECORDER_MODE_ONLINE)) -#error One of LOSCFG_RECORDER_MODE_OFFLINE and LOSCFG_RECORDER_MODE_ONLINE should be set to 1 and only. -#endif - -#ifndef LOSCFG_TRACE_CLIENT_INTERACT -#define LOSCFG_TRACE_CLIENT_INTERACT 1 -#endif - -#ifndef LOSCFG_TRACE_BUFFER_SIZE -#define LOSCFG_TRACE_BUFFER_SIZE 2048 -#endif - #ifndef NUM_HAL_INTERRUPT_UART #define NUM_HAL_INTERRUPT_UART 0xff #endif @@ -683,41 +589,6 @@ extern UINT8 *m_aucSysMem0; #endif -/* ============================================================================= - PM module configuration -============================================================================= */ -/** - * @ingroup los_config - * Configuration item for low power frame tailoring - */ -#ifndef LOSCFG_KERNEL_PM -#define LOSCFG_KERNEL_PM 1 -#endif - -/** - * @ingroup los_config - * Configuration item for priority of low-power task. - */ -#ifndef LOSCFG_KERNEL_PM_TASK_PTIORITY -#define LOSCFG_KERNEL_PM_TASK_PTIORITY 1 -#endif - -/** - * @ingroup los_config - * Configuration item for stack size of low-power task. - */ -#ifndef LOSCFG_KERNEL_PM_TASK_STACKSIZE -#define LOSCFG_KERNEL_PM_TASK_STACKSIZE 0x800 -#endif - -/** - * @ingroup los_config - * Configuration item for low power frame debug tailoring - */ -#ifndef LOSCFG_KERNEL_PM_DEBUG -#define LOSCFG_KERNEL_PM_DEBUG 0 -#endif - /* ============================================================================= printf configuration ============================================================================= */ @@ -730,52 +601,8 @@ extern UINT8 *m_aucSysMem0; #endif /* ============================================================================= - backtrace configuration -============================================================================= */ -/** - * @ingroup los_config - * Configuration backtrace type - * 0: Close stack analysis module. - * 1: Call stack analysis for cortex-m series by scanning the stack. - * 2: Call stack analysis for risc-v by using frame pointer. - * 3: Call stack analysis for risc-v by scanning the stack. - * 4: Call stack analysis for xtensa by scanning the stack. - * 5: Call stack analysis for c-sky by scanning the stack. - * 6: Call stack analysis for arm9 by scanning the stack. - * others: Not currently supported. - */ -#ifndef LOSCFG_BACKTRACE_TYPE -#define LOSCFG_BACKTRACE_TYPE 0 -#endif - -/** - * @ingroup los_config - * Configuration backtrace depth. - */ -#ifndef LOSCFG_BACKTRACE_DEPTH -#define LOSCFG_BACKTRACE_DEPTH 15 -#endif - -/* ============================================================================= - trustzone configuration + misc configuration ============================================================================= */ -/** - * @ingroup los_config - * Configuration trustzone secure heap size. - */ -#ifndef LOSCFG_SECURE_HEAP_SIZE -#define LOSCFG_SECURE_HEAP_SIZE 2048 -#endif - -/** - * @ingroup los_config - * Configuration trustzone secure stack default size. - * The secure stack must be allocated before the task calls non-secure callble functions. - */ -#ifndef LOSCFG_SECURE_STACK_DEFAULT_SIZE -#define LOSCFG_SECURE_STACK_DEFAULT_SIZE 512 -#endif - /** * @ingroup los_config * Configuration item for mpu. @@ -788,25 +615,6 @@ extern UINT8 *m_aucSysMem0; #error "if hardware stack protection is enabled, then MPU should be supported and enabled" #endif -/*============================================================================= - shell module configuration -=============================================================================*/ -/** - * @ingroup los_config - * Configuration item for shell. - */ -#ifndef LOSCFG_USE_SHELL -#define LOSCFG_USE_SHELL 0 -#endif - -/** - * @ingroup los_config - * Configuration shell task priority. - */ -#ifndef LOSCFG_SHELL_PRIO -#define LOSCFG_SHELL_PRIO 3 -#endif - /** * @ingroup los_config * Configuration item to get task used memory. diff --git a/kernel/src/los_init.c b/kernel/src/los_init.c index f4ae35fbe579d5a517d04a072b8798da1bb534c1..d2b13a3ee5a4429e573555e914af68886fe4ce8c 100644 --- a/kernel/src/los_init.c +++ b/kernel/src/los_init.c @@ -202,14 +202,6 @@ LITE_OS_SEC_TEXT_INIT UINT32 LOS_KernelInit(VOID) } #endif -#if (LOSCFG_TEST == 1) - ret = los_TestInit(); - if (ret != LOS_OK) { - PRINT_ERR("los_TestInit error\n"); - return ret; - } -#endif - #if (LOSCFG_PLATFORM_EXC == 1) OsExcMsgDumpInit(); #endif diff --git a/liteos.gni b/liteos.gni new file mode 100644 index 0000000000000000000000000000000000000000..8c43e5a0d289838cae0a1651aafb32127d489e8b --- /dev/null +++ b/liteos.gni @@ -0,0 +1,126 @@ +# 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("$root_out_dir/config.gni") + +LITEOSTOPDIR = "//kernel/liteos_m" +LITEOSTHIRDPARTY = "//third_party" +HDFTOPDIR = "//drivers/adapter/khdf/liteos_m" + +ARCH = "" +if (defined(LOSCFG_ARCH_ARM_AARCH32)) { + ARCH = "arm" +} else if (defined(LOSCFG_ARCH_ARM_AARCH64)) { + ARCH = "aarch64" +} else if (defined(LOSCFG_ARCH_RISCV32)) { + ARCH = "rv32imac" +} else if (defined(LOSCFG_ARCH_CSKY)) { + ARCH = "csky" +} else if (defined(LOSCFG_ARCH_XTENSA)) { + ARCH = "xtensa" +} + +template("kernel_module") { + build_gn = rebase_path("BUILD.gn") + cmd = "grep -c '^\s*\(kernel_module\|hdf_driver\)\s*(\s*\S*\s*)\s*{\s*\$' $build_gn" + modules_count = exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value") + if (modules_count == 1) { + auto_config = true + } + + cmd = "if grep -q '^\s*config\s*(\s*\"public\"\s*)\s*{\s*\$' $build_gn; then echo true; else echo false; fi" + has_public_config = + exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value") + if (!has_public_config && defined(auto_config)) { + config("public") { + configs = [] + } + } + + current_dir_name = get_path_info(rebase_path("."), "file") + if (target_name != current_dir_name) { + cmd = "if grep -q '^\s*group\s*(\s*\"$current_dir_name\"\s*)\s*{\s*\$' $build_gn; then echo true; else echo false; fi" + has_current_dir_group = + exec_script("//build/lite/run_shell_cmd.py", [ cmd ], "value") + if (!has_current_dir_group && defined(auto_config)) { + module_name = target_name + group(current_dir_name) { + public_deps = [ ":$module_name" ] + } + } + } + + if (defined(invoker.module_switch) && !invoker.module_switch) { + group(target_name) { + not_needed(invoker, "*") + } + } else { + source_set(target_name) { + public_configs = [] + forward_variables_from(invoker, "*", [ "configs" ]) + configs += invoker.configs + if (has_public_config) { + included_public_config = false + foreach(cfg, public_configs) { + what = "label_no_toolchain" + if (get_label_info(cfg, what) == get_label_info(":public", what)) { + included_public_config = true + } + } + if (!included_public_config) { + public_configs += [ ":public" ] + } + } + } + } + not_needed([ "auto_config" ]) +} + +template("config") { + config(target_name) { + if (defined(invoker.module_switch) && !invoker.module_switch && + target_name == "public") { + not_needed(invoker, "*") + forward_variables_from(invoker, [ "configs" ]) + } else { + forward_variables_from(invoker, "*") + } + } +} + +set_defaults("kernel_module") { + configs = [ + "$LITEOSTOPDIR:public", + "$LITEOSTOPDIR:los_config", + ] + visibility = [ + "$LITEOSTOPDIR/*", + "../*", + ] +} diff --git a/testsuites/BUILD.gn b/testsuites/BUILD.gn index d44a8b1e22ad6399cf7f7798b8e426a15bda8212..40722a3a2e37caa8e16c91b5ab227b9b08e8c3ff 100644 --- a/testsuites/BUILD.gn +++ b/testsuites/BUILD.gn @@ -27,12 +27,7 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import("//build/lite/config/component/lite_component.gni") -import("//kernel/liteos_m/config.gni") - -declare_args() { - enable_ohos_kernel_liteos_m_test_full = false -} +import("//kernel/liteos_m/liteos.gni") config("include") { defines = [] @@ -43,12 +38,13 @@ config("include") { "//kernel/liteos_m/components/cpup", ] - if (enable_ohos_kernel_liteos_m_test_full) { + if (defined(LOSCFG_KERNEL_TEST_FULL)) { defines += [ "LOS_KERNEL_TEST_FULL=1" ] } } -static_library("test_init") { +module_switch = defined(LOSCFG_TEST) +kernel_module("test_init") { sources = [ "src/iCunit.c", "src/osTest.c", @@ -57,22 +53,23 @@ static_library("test_init") { configs += [ ":include" ] } -lite_component("test") { - features = [ +group("testsuites") { + deps = [ ":test_init", "sample/kernel/event:test_event", "sample/kernel/hwi:test_hwi", "sample/kernel/mem:test_mem", "sample/kernel/mux:test_mux", + "sample/kernel/power:test_pm", "sample/kernel/queue:test_queue", "sample/kernel/sem:test_sem", "sample/kernel/swtmr:test_swtmr", "sample/kernel/task:test_task", - "sample/kernel/power:test_pm", - - #"sample/kernel/tickless:test_tickless", ] - if (enable_ohos_kernel_liteos_m_dynlink) { - features += [ "sample/kernel/dynlink:test_dynlink" ] + if (defined(LOSCFG_DYNLINK)) { + deps += [ "sample/kernel/dynlink:test_dynlink" ] + } + if (!module_switch) { + deps = [] } } diff --git a/utils/BUILD.gn b/utils/BUILD.gn index a18d6e5eeeb1682c4bcb59e8f28586bb8976883a..972a4def8ca08ce3ed47a14cf165f6483caeb5be 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -27,14 +27,17 @@ # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -import("//kernel/liteos_m/config.gni") +import("//kernel/liteos_m/liteos.gni") -static_library("utils") { +module_name = get_path_info(rebase_path("."), "name") +kernel_module(module_name) { sources = [ "los_debug.c", "los_error.c", "los_hook.c", ] +} - configs += [ "$LITEOSTOPDIR:los_config" ] +config("public") { + include_dirs = [ "." ] }