# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2022 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 COMPILER_CLANG_LLVM
    bool "Clang"

config COMPILER_ICCARM
    bool "ICCARM"

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 || PLATFORM_QEMU_ARM_VIRT_CM55 || PRODUCT_QEMU_RISCV32_VIRT || PLATFORM_QEMU_CSKY_SMARTL || PLATFORM_QEMU_XTENSA_ESP32

config DEVICE_COMPANY
    string
    default "qemu" if PLATFORM_QEMU_ARM_VIRT_CM7 || PLATFORM_QEMU_ARM_VIRT_CM4 || PLATFORM_QEMU_ARM_VIRT_CM55 || 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_ARM_VIRT_CM55
    bool "qemu_arm_virt_cm55"
    select ARCH_CORTEX_M55
    help
        QEMU ARM Virtual Platform using Cortex-M55 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_RISCV32_VIRT
    bool "riscv32_virt" if PLATFORM_QEMU_RISCV32_VIRT

endchoice


######################### config options of cpu arch ################
source "arch/Kconfig"

# Device Kconfig import
osource "$(DEVICE_PATH)/Kconfig"

config SOC_COMPANY
    string "SoC company name to locate soc build path"
    help
      This option specifies the SoC company name, used to locate the build path for soc. This option is set by the
      SoC's Kconfig file, and should be exactly the same with SoC company path, and the user should generally avoid
       modifying it via the menu configuration.

orsource "../../device/board/*/Kconfig.liteos_m.shields"

orsource "../../device/board/$(BOARD_COMPANY)/Kconfig.liteos_m.defconfig.boards"

choice
    prompt "Board Selection"

orsource "../../device/board/$(BOARD_COMPANY)/Kconfig.liteos_m.boards"

endchoice

orsource "../../device/soc/*/Kconfig.liteos_m.defconfig"

choice
    prompt "SoC Series Selection"

orsource "../../device/soc/*/Kconfig.liteos_m.series"

endchoice

orsource "../../device/soc/*/Kconfig.liteos_m.soc"

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++.

rsource "components/signal/Kconfig"

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 KERNEL_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_IDLE
    bool "Enable Power Management Idle"
    default n
    depends on KERNEL_PM
    help
      Configuration item for low power frame tailoring.
      If you wish to build LiteOS with support for power management idle.

config KERNEL_PM_DEBUG
    bool "Power Management Debug"
    default n
    depends on KERNEL_PM
    help
      Configuration item for low power frame debug tailoring.

config PLATFORM_EXC
    bool "Enable Platform Exc Hook"
    default n
    depends on KERNEL_EXTKERNEL

config KERNEL_LMK
    bool "Enable Low Memory Killer"
    default n
    depends on KERNEL_EXTKERNEL
    help
      Configuration item for low memory killer tailoring.
      If you wish to build LiteOS with support for low memory killer.

config KERNEL_LMK_DEBUG
    bool "Low Memory Killer Debug"
    default n
    depends on KERNEL_LMK
    help
      Configuration item forlow memory killer debug tailoring.

######################### config options of trace #########################
source "components/trace/Kconfig"

######################### config options of lms #########################
source "components/lms/Kconfig"

endmenu

######################### config options of compatibility ##############
menu "Compat"

rsource "kal/Kconfig"

endmenu

######################## config options of filesystem ##################
menu "FileSystem"

rsource "components/fs/Kconfig"

endmenu

######################## config options of net ############################
menu "Net"
config NET_LWIP
    bool "Enable Lwip"
    default n
    select NET_LWIP_SACK

    help
      Answer Y to enable LiteOS support lwip.

config NET_LWIP_SACK
    bool
    default n

endmenu

######################## config options of debug ########################
menu "Debug"

config THUMB
    bool "Enable Thumb"
    default n
    depends on ARCH_ARM
    help
      Answer Y to build thumb version.  This will make LiteOS smaller.

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 MUTEX_CREATE_TRACE
    bool "Enable Mutex Trace Debugging"
    default n
    depends on ARCH_ARM
    depends on DEBUG_KERNEL
    help
      Answer Y to enable debug mutex trace.

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.

config DEBUG_HOOK
    bool "Enable Hook Framework"
    default n
    depends on DEBUG_VERSION
    help
      Enable the kernel hook framework to support customized trace information capture.

config SHELL_CMD_DEBUG
    bool "Enable shell cmd Debug"
    default n
    depends on DEBUG_VERSION && SHELL

config DEBUG_TOOLS
    bool "Enable DEBUG TOOLS"
    default n
    depends on DEBUG_VERSION
    help
      Answer Y to enable LiteOS debug tools, include stackdump, hwidump, tasktrack.

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 information 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 TASK_MEM_USED
    bool "Enable show task mem used or not"
    default n
    depends on DEBUG_VERSION && MEM_DEBUG

source "components/shell/Kconfig"

endmenu

######################## config options os drivers ########################
menu "Driver"
source "drivers/Kconfig"
endmenu

######################## config options os security #######################
menu "Security"
config SECURE_TRUSTZONE
    bool "Enable ARM TrustZone"
    default n
    depends on ARCH_ARM
    depends on ARCH_ARM_V8M
config SECURE_HEAP_SIZE
    int "TrustZone Heap Size (bytes)"
    default 2048
    depends on SECURE_TRUSTZONE
config SECURE
    bool "Enable Security"
    default n
    select MPU_ENABLE
config MPU_ENABLE
    bool "Enable MPU"
    default n
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
