From 97aa2cdf9579b3abf8b4e3e2b085687ed768ae2e Mon Sep 17 00:00:00 2001 From: Mike Date: Wed, 29 Sep 2021 09:58:09 +0100 Subject: [PATCH] Add Kconfig support (#2374) Type `make manuconfig` in your Sming based application to see the available options. You might need to run `make python-requirements` before that if you are missing the required python libraries. Sample `Basic_IFS` provides an example how to add application specific configuration settings. --- .../Esp32/Components/esp32/sdk/config/debug | 12 ++ .../Esp32/Components/esp32/sdk/config/release | 12 ++ Sming/Arch/Esp8266/Components/driver/Kconfig | 22 ++++ Sming/Arch/Esp8266/Components/heap/Kconfig | 20 ++++ Sming/Components/Hosted/Kconfig | 37 ++++++ .../Hosted/samples/serial/README.rst | 2 +- Sming/Components/Network/Kconfig | 53 ++++++++ Sming/Components/Network/component.mk | 7 ++ Sming/Components/esptool/Kconfig | 9 ++ Sming/Components/rboot/Kconfig | 22 ++++ Sming/Components/ssl/Kconfig | 28 +++++ Sming/Components/terminal/Kconfig | 33 +++++ Sming/Kconfig | 113 ++++++++++++++++++ Sming/Libraries/OtaUpgrade/Kconfig | 41 +++++++ Sming/Libraries/OtaUpgradeMqtt/Kconfig | 20 ++++ Sming/Libraries/Spiffs/Kconfig | 30 +++++ Sming/Libraries/Spiffs/README.rst | 2 - Sming/Libraries/Spiffs/component.mk | 2 +- Sming/Libraries/Spiffs/src/FileSystem.cpp | 2 +- .../src/include/IFS/SPIFFS/FileSystem.h | 9 +- Sming/Platform/System.cpp | 19 +-- Sming/build.mk | 2 + Sming/component.mk | 7 -- Sming/project.mk | 27 ++++- Tools/cfgtool.py | 110 +++++++++++++++++ Tools/requirements.txt | 1 + samples/Basic_IFS/Kconfig | 9 ++ 27 files changed, 624 insertions(+), 27 deletions(-) create mode 100644 Sming/Arch/Esp8266/Components/driver/Kconfig create mode 100644 Sming/Arch/Esp8266/Components/heap/Kconfig create mode 100644 Sming/Components/Hosted/Kconfig create mode 100644 Sming/Components/Network/Kconfig create mode 100644 Sming/Components/esptool/Kconfig create mode 100644 Sming/Components/rboot/Kconfig create mode 100644 Sming/Components/ssl/Kconfig create mode 100644 Sming/Components/terminal/Kconfig create mode 100644 Sming/Kconfig create mode 100644 Sming/Libraries/OtaUpgrade/Kconfig create mode 100644 Sming/Libraries/OtaUpgradeMqtt/Kconfig create mode 100644 Sming/Libraries/Spiffs/Kconfig create mode 100644 Tools/cfgtool.py create mode 100644 samples/Basic_IFS/Kconfig diff --git a/Sming/Arch/Esp32/Components/esp32/sdk/config/debug b/Sming/Arch/Esp32/Components/esp32/sdk/config/debug index 55e48a89ac..c74a1e37de 100644 --- a/Sming/Arch/Esp32/Components/esp32/sdk/config/debug +++ b/Sming/Arch/Esp32/Components/esp32/sdk/config/debug @@ -3,9 +3,21 @@ # # The bootloader logs all type of messages +CONFIG_BOOTLOADER_LOG_LEVEL_NONE= +CONFIG_BOOTLOADER_LOG_LEVEL_ERROR= +CONFIG_BOOTLOADER_LOG_LEVEL_WARN= +CONFIG_BOOTLOADER_LOG_LEVEL_INFO=y +CONFIG_BOOTLOADER_LOG_LEVEL_DEBUG= +CONFIG_BOOTLOADER_LOG_LEVEL_VERBOSE= CONFIG_BOOTLOADER_LOG_LEVEL=3 # ESP-IDF logs all type of messages +CONFIG_LOG_DEFAULT_LEVEL_NONE= +CONFIG_LOG_DEFAULT_LEVEL_ERROR= +CONFIG_LOG_DEFAULT_LEVEL_WARN= +CONFIG_LOG_DEFAULT_LEVEL_INFO=y +CONFIG_LOG_DEFAULT_LEVEL_DEBUG= +CONFIG_LOG_DEFAULT_LEVEL_VERBOSE= CONFIG_LOG_DEFAULT_LEVEL=3 # Sets watchpoint index 1 (the second of two) at the end of any task stack. This is the most accurate way to debug task stack overflows. diff --git a/Sming/Arch/Esp32/Components/esp32/sdk/config/release b/Sming/Arch/Esp32/Components/esp32/sdk/config/release index 2e3743a7c1..f130372a9e 100644 --- a/Sming/Arch/Esp32/Components/esp32/sdk/config/release +++ b/Sming/Arch/Esp32/Components/esp32/sdk/config/release @@ -3,8 +3,20 @@ # # The bootloader logs only errors +CONFIG_BOOTLOADER_LOG_LEVEL_NONE= +CONFIG_BOOTLOADER_LOG_LEVEL_ERROR=y +CONFIG_BOOTLOADER_LOG_LEVEL_WARN= +CONFIG_BOOTLOADER_LOG_LEVEL_INFO= +CONFIG_BOOTLOADER_LOG_LEVEL_DEBUG= +CONFIG_BOOTLOADER_LOG_LEVEL_VERBOSE= CONFIG_BOOTLOADER_LOG_LEVEL=1 # ESP-IDF logs only errors +CONFIG_LOG_DEFAULT_LEVEL_NONE= +CONFIG_LOG_DEFAULT_LEVEL_ERROR=y +CONFIG_LOG_DEFAULT_LEVEL_WARN= +CONFIG_LOG_DEFAULT_LEVEL_INFO= +CONFIG_LOG_DEFAULT_LEVEL_DEBUG= +CONFIG_LOG_DEFAULT_LEVEL_VERBOSE= CONFIG_LOG_DEFAULT_LEVEL=1 diff --git a/Sming/Arch/Esp8266/Components/driver/Kconfig b/Sming/Arch/Esp8266/Components/driver/Kconfig new file mode 100644 index 0000000000..566932a5af --- /dev/null +++ b/Sming/Arch/Esp8266/Components/driver/Kconfig @@ -0,0 +1,22 @@ +menu "Drivers" + config USE_US_TIMER + bool "Enable microsecond precision for software timers (Timer2)" + help + The following functions depend on Timer2: + - NOW() return value, the Timer2 tick count + - Software timers + - System time + + Software timers are driven by Timer2, which by default uses a /256 prescale + providing a resolution of 3.2us and a range of 1' 54". + + Enabling this setting increases the resolution to 200ns but reduces the maximum + software timer to 7" 9.5s. + + config ENABLE_CUSTOM_PWM + bool "Use the *New PWM* driver" + default y + help + New PWM is a drop-in replacement for the version provided in the Espressif SDK. + +endmenu diff --git a/Sming/Arch/Esp8266/Components/heap/Kconfig b/Sming/Arch/Esp8266/Components/heap/Kconfig new file mode 100644 index 0000000000..b78223f531 --- /dev/null +++ b/Sming/Arch/Esp8266/Components/heap/Kconfig @@ -0,0 +1,20 @@ +menu "Heap" + config ENABLE_CUSTOM_HEAP + bool "Enable custom heap using UMM Malloc" + + if ENABLE_CUSTOM_HEAP + + config UMM_POISON_CHECK + bool "UMM Poison Check" + help + Add heap integrity checks + + config UMM_FUNC_IRAM + bool "Store custom heap functions in IRAM" + default y + help + Custom heap functions are stored in IRAM by default for performance reasons. + If you need the IRAM (about 1.5K bytes) then disable this option. + + endif +endmenu diff --git a/Sming/Components/Hosted/Kconfig b/Sming/Components/Hosted/Kconfig new file mode 100644 index 0000000000..2c06ba5ced --- /dev/null +++ b/Sming/Components/Hosted/Kconfig @@ -0,0 +1,37 @@ +menu "Hosted" + choice + depends on SMING_ARCH="Host" + default ENABLE_HOSTED_NONE + prompt "Hosted transport mechanism" + config ENABLE_HOSTED_NONE + bool "None" + config ENABLE_HOSTED_TCP + bool "TCP" + config ENABLE_HOSTED_SERIAL + bool "Serial" + endchoice + + config ENABLE_HOSTED + string + default "" if ENABLE_HOSTED_NONE + default "tcp" if ENABLE_HOSTED_TCP + default "serial" if ENABLE_HOSTED_SERIAL + + if ENABLE_HOSTED="tcp" + config HOSTED_SERVER_IP + depends on ENABLE_HOSTED="tcp" + string "Remote RPC server IP address" + default "192.168.13.1" + endif + + if ENABLE_HOSTED="serial" + config HOSTED_COM_PORT + string "COM port connected to remote RPC server" + default "$(COM_PORT)" + + config HOSTED_COM_SPEED + int "Baud rate for hosted COM port" + default 115200 + endif + +endmenu diff --git a/Sming/Components/Hosted/samples/serial/README.rst b/Sming/Components/Hosted/samples/serial/README.rst index d1635d59fb..0bf048eb84 100644 --- a/Sming/Components/Hosted/samples/serial/README.rst +++ b/Sming/Components/Hosted/samples/serial/README.rst @@ -1,4 +1,4 @@ -Hosted RCP Server over Serial +Hosted RPC Server over Serial ============================= Overview diff --git a/Sming/Components/Network/Kconfig b/Sming/Components/Network/Kconfig new file mode 100644 index 0000000000..2d9d0e353a --- /dev/null +++ b/Sming/Components/Network/Kconfig @@ -0,0 +1,53 @@ +menu "Network" + depends on !DISABLE_NETWORK + + config DISABLE_WIFI + bool "Build without WiFi support" + default n + help + Keeps the core Network library but excludes WiFi code. + Applications using ethernet can use this to reduce code size. + + if !DISABLE_WIFI + config WIFI_SSID + string "Default WiFi SSID" + depends on !DISABLE_WIFI + + config WIFI_PWD + string "Default WiFi Passphrase" + depends on !DISABLE_WIFI + + if SMING_ARCH=Esp8266 + config ENABLE_WPS + bool "Enable WiFi Protected Setup (WPS)" + help + WPS is not enabled by default to preserve resources, and because + there may be security implications which you should consider carefully. + + config ENABLE_SMART_CONFIG + bool "Enable WiFi Smart Configuration API" + help + See :sample:`Basic_SmartConfig` sample application. + endif + endif + + config HTTP_SERVER_EXPOSE_NAME + bool "Add \"HttpServer/Sming\" to the SERVER field in response headers" + default y + help + If disabled, the SERVER field is omitted from all responses. + + config HTTP_SERVER_EXPOSE_VERSION + bool "Include Sming version in HTTP server headers" + depends on HTTP_SERVER_EXPOSE_NAME + help + Adds the current Sming build version to the SERVER field in response headers. + For example, "Sming/4.0.0-rc2". + + config ENABLE_CUSTOM_LWIP + int "LWIP version (0 for SDK, 1 or 2)" + range 0 2 + default 1 + depends on SMING_ARCH=Esp8266 + +endmenu diff --git a/Sming/Components/Network/component.mk b/Sming/Components/Network/component.mk index 69d0d4bb02..e0b6847fb9 100644 --- a/Sming/Components/Network/component.mk +++ b/Sming/Components/Network/component.mk @@ -19,6 +19,13 @@ COMPONENT_DEPENDS := \ mqtt-codec \ libyuarel +# WiFi settings may be provide via Environment variables +CONFIG_VARS += WIFI_SSID WIFI_PWD +ifdef WIFI_SSID + APP_CFLAGS += -DWIFI_SSID=\"$(WIFI_SSID)\" + APP_CFLAGS += -DWIFI_PWD=\"$(WIFI_PWD)\" +endif + # => WPS COMPONENT_VARS += ENABLE_WPS ifeq ($(ENABLE_WPS), 1) diff --git a/Sming/Components/esptool/Kconfig b/Sming/Components/esptool/Kconfig new file mode 100644 index 0000000000..882992e93a --- /dev/null +++ b/Sming/Components/esptool/Kconfig @@ -0,0 +1,9 @@ +menu "esptool" + config COM_PORT_ESPTOOL + string "Port to use for flashing device" + default COM_PORT + + config COM_SPEED_ESPTOOL + string "Baud rate to use for flashing device" + default COM_SPEED +endmenu diff --git a/Sming/Components/rboot/Kconfig b/Sming/Components/rboot/Kconfig new file mode 100644 index 0000000000..730b474ff0 --- /dev/null +++ b/Sming/Components/rboot/Kconfig @@ -0,0 +1,22 @@ +menu "rBoot" + depends on SMING_ARCH = "Esp8266" + + config RBOOT_RTC_ENABLED + bool "Enable extended boot information via RTC memory" + + choice + prompt "GPIO boot behaviour" + default RBOOT_GPIO_DISABLED + config RBOOT_GPIO_DISABLED + bool "Disable GPIO features" + config RBOOT_GPIO_ENABLED + bool "Enable GPIO boot slot 2" + help + rBoot supports booting into a third slot upon explicit user request, + e.g. by pressing a button during reset/power up. + This is especially useful for implementing some sort of recovery mechanism. + config RBOOT_GPIO_SKIP_ENABLED + bool "Use GPIO to skip between boot roms" + endchoice + +endmenu diff --git a/Sming/Components/ssl/Kconfig b/Sming/Components/ssl/Kconfig new file mode 100644 index 0000000000..ea73643ca5 --- /dev/null +++ b/Sming/Components/ssl/Kconfig @@ -0,0 +1,28 @@ +menu "SSL" + depends on !DISABLE_NETWORK + + choice + default SELECT_SSL_NONE + prompt "SSL adapter" + config SELECT_SSL_NONE + bool "None" + config SELECT_SSL_DEFAULT + bool "Default (Axtls)" + config SELECT_SSL_AXTLS + bool "AXTLS" + config SELECT_SSL_BEARSSL + bool "Bear SSL" + endchoice + + config ENABLE_SSL + string + default "0" if SELECT_SSL_NONE + default "1" if SELECT_SSL_DEFAULT + default "Axtls" if SELECT_SSL_AXTLS + default "Bearssl" if SELECT_SSL_BEARSSL + + config SSL_DEBUG + depends on ENABLE_SSL != "0" + bool "Enable SSL debug" + +endmenu diff --git a/Sming/Components/terminal/Kconfig b/Sming/Components/terminal/Kconfig new file mode 100644 index 0000000000..59906f3609 --- /dev/null +++ b/Sming/Components/terminal/Kconfig @@ -0,0 +1,33 @@ +menu "Terminal" + + config COM_PORT + string "Default port for device communications" + help + Default value depends on the development platform being used. + default "/dev/cuaU0" if ("$UNAME" = "FreeBSD") + default "/dev/tty.usbserial" if "$UNAME" = "MacOS" + default "/dev/ttyUSB0" if "$UNAME" = "Linux" + default "COM3" if "$UNAME" = "Windows" + + config COM_SPEED_SERIAL + int "Default baud rate to use for serial communication within application" + default COM_SPEED + + config COM_OPTS + string "Additional options to pass to the terminal" + default "--raw --encoding ascii --rts 0 --dtr 0" + + config TERMINAL + string "Command line to use when running `make terminal`" + help + Redefine if you want to use a different terminal application + default "powershell.exe -Command \"python -m serial.tools.miniterm $(COM_OPTS) $(COM_PORT) $(COM_SPEED_SERIAL)\"" if $WSL_ROOT + default "$(PYTHON) -m serial.tools.miniterm $(COM_OPTS) $(COM_PORT) $(COM_SPEED_SERIAL)" if !$WSL_ROOT + + config KILL_TERM + string "Command line to use to kill the running terminal process" + help + If the terminal never runs in the background and the warnings annoy you, just clear it + default "pkill -9 -f \"$(COM_PORT) $(COM_SPEED_SERIAL)\" || exit 0" + +endmenu diff --git a/Sming/Kconfig b/Sming/Kconfig new file mode 100644 index 0000000000..febd794328 --- /dev/null +++ b/Sming/Kconfig @@ -0,0 +1,113 @@ +# +# For a description of the syntax of this configuration file, +# see kconfig/kconfig-language.txt. +# +mainmenu "Sming Framework Configuration: $(SMING_ARCH) $(ESP_VARIANT)" + + config SMING_ARCH + string + option env="SMING_ARCH" + + menu "Sming" + choice + default SELECT_LOCALE_EN_GB + prompt "Date/Time country code" + help + Sming can format dates/time values based on a country code identified by this value. + This is provided as a #define symbol for your application to use. + See :source:`Sming/Core/SmingLocale.h` for further details. + config SELECT_LOCALE_EN_US + bool "English (US)" + config SELECT_LOCALE_EN_GB + bool "English (UK)" + config SELECT_LOCALE_EN_AU + bool "English (Australia)" + config SELECT_LOCALE_FR_FR + bool "Français" + config SELECT_LOCALE_DE_DE + bool "Deutsch" + endchoice + + config LOCALE + int + default 1 if SELECT_LOCALE_EN_US + default 33 if SELECT_LOCALE_FR_FR + default 44 if SELECT_LOCALE_EN_GB + default 49 if SELECT_LOCALE_DE_DE + default 61 if SELECT_LOCALE_EN_AU + + config COM_SPEED + int "Default baud rate for serial port" + default 115200 + help + This will recompile your application to use the revised baud rate. + Note that this will change the default speed used for both flashing and serial comms. + + config ENABLE_CMD_EXECUTOR + bool "Enable command executor functionality" + default y + help + This facilty requires documenting! + + config TASK_QUEUE_LENGTH + int "Length of task queue" + default 10 + depends on SMING_ARCH="Esp8266" || SMING_ARCH="Host" + + config STRING_OBJECT_SIZE + int "Size of a Wiring String object" + default 12 + help + Change this to increase space for Small String Optimisation (SSO) + + config DISABLE_NETWORK + bool "Build without networking support" + default n + select DISABLE_WIFI if DISABLE_NETWORK + help + Applications which do not require networking can set this flag to avoid building + or linking the core Network library. + + This will reduce build times, application size and RAM usage. + Builds will not succeeded if network code has been inadvertently included. + endmenu + + menu "Debug" + choice + default SELECT_DEBUG_INFO + prompt "Detail level for debug messages" + config SELECT_DEBUG_ERROR + bool "0 Errors only" + config SELECT_DEBUG_WARN + bool "1 Errors and warnings" + config SELECT_DEBUG_INFO + bool "2 Errors, warnings and Information" + config SELECT_DEBUG_DEBUG + bool "3 All debug messages" + endchoice + + config DEBUG_VERBOSE_LEVEL + int + default 0 if SELECT_DEBUG_ERROR + default 1 if SELECT_DEBUG_WARN + default 2 if SELECT_DEBUG_INFO + default 3 if SELECT_DEBUG_DEBUG + + config DEBUG_PRINT_FILENAME_AND_LINE + bool "Include the filename and line number in every line of debug output." + default n + help + This will require extra space on flash + + config ENABLE_GDB + bool "Compile with support for serial debugging using GDB" + + config ENABLE_SPI_DEBUG + bool "Enable SPI debug output" + + config ENABLE_TASK_COUNT + bool "Enable use of System task counting to check for queue overflows" + depends on SMING_ARCH="Esp8266" + endmenu + + source "$KCONFIG_COMPONENTS" diff --git a/Sming/Libraries/OtaUpgrade/Kconfig b/Sming/Libraries/OtaUpgrade/Kconfig new file mode 100644 index 0000000000..3dd5c1893c --- /dev/null +++ b/Sming/Libraries/OtaUpgrade/Kconfig @@ -0,0 +1,41 @@ +menu "OTA Upgrade" + + config ENABLE_OTA_SIGNING + bool "Protect upgrade files using digital signature" + default y + help + If enabled (highly recommended), OTA upgrade files are protected against unauthorized modification by a digital signature. + + You may disable signing in order to save some program memory if your communication channel already establishes a + comparable level of trust, e.g. TLS with a pinned certificate. + + config OTA_ENABLE_ENCRYPTION + bool "Encrypt upgrade files" + help + This option helps to protect any confidential data embedded in your firmware, such as WiFi credentials, server certificates, etc. + + config OTA_KEY + string "Path to secret encryption/signing key" + default "ota.key" + + config ENABLE_OTA_DOWNGRADE + bool "Enable downgrade" + help + By default, BasicStream refuses to downgrade to an older firmware version to prevent an attacker from restoring already patched security vulnerabilities. + + Downgrade protection must be combined with encryption or signing to be effective. + + config OTA_UPLOAD_URL + string "URL used by the `make ota-upload` command" + + + config OTA_UPLOAD_NAME + string "Field name for upgrade file in HTTP POST request" + default "firmware" + help + This relates to the `name` attribute of the HTML input element + used with the `make ota-upload` command: + + + +endmenu diff --git a/Sming/Libraries/OtaUpgradeMqtt/Kconfig b/Sming/Libraries/OtaUpgradeMqtt/Kconfig new file mode 100644 index 0000000000..e9eaf979c4 --- /dev/null +++ b/Sming/Libraries/OtaUpgradeMqtt/Kconfig @@ -0,0 +1,20 @@ +menu "OTA Upgrade MQTT" + + config ENABLE_OTA_VARINT_VERSION + bool "Enable 'varint' encoding for patch version" + default y + help + If enabled, the OTA upgrade mechanism and application will use a `varint `_ + encoding for the patch version. Thus allowing unlimited number of patch versions. Useful for enumerating unstable/nightly releases. + A bit more difficult to read and write but allows for unlimited versions. + + If set to 0 the OTA upgrade mechanism and application will use one byte for the patch version which will limit it to 256 possible patch versions. + Useful for enumarating stable releases. Easier to write and read but limited to 256 versions only. + + config ENABLE_OTA_ADVANCED + bool "Support firmware signing/encryption" + help + Enabling this option allows the library to work with OtaUpgradeStream which supports signature and encryption of the firmware data itself. + In the application the AdvancedPayloadParser can be used to do the MQTT message handling. + +endmenu diff --git a/Sming/Libraries/Spiffs/Kconfig b/Sming/Libraries/Spiffs/Kconfig new file mode 100644 index 0000000000..7aa6d949fe --- /dev/null +++ b/Sming/Libraries/Spiffs/Kconfig @@ -0,0 +1,30 @@ +menu "SPIFFS" + config SPIFF_FILEDESC_COUNT + int "Number of file descriptors allocated" + default 7 + help + This sets the maximum number of files which may be opened at once. + + config SPIFFS_OBJ_META_LEN + int "Maximum size of file metadata" + default 16 + help + Maximum size of metadata which SPIFFS stores in each file index header (after the filename). + If this value is changed, existing SPIFFS images will not be readable. + + The default value is the minimum necessary to support IFS extended file attribute information. + + The first 16 bytes are used for system attributes (e.g. modified time), so setting this to, say, 64 + leaves 48 bytes for user metadata. Each attribute has a 2-byte header (tag + size) so a single user + attribute can be stored of up to 46 bytes, or multiple tags up to this limit. + + Note: LittleFS provides better support for user metadata. + + config SPIFF_FILES + string "Path to source files for default spiffs volume" + default "files" + help + The SPIFFS image is built using files from this directory, which must exist or the build will fail. + If you set this to an empty value, then an empty filesystem will be created. + +endmenu diff --git a/Sming/Libraries/Spiffs/README.rst b/Sming/Libraries/Spiffs/README.rst index 4e50a7c99d..ef7ed673a1 100644 --- a/Sming/Libraries/Spiffs/README.rst +++ b/Sming/Libraries/Spiffs/README.rst @@ -18,8 +18,6 @@ A single SPIFFS partition is defined using :envvar:`HWCONFIG` ``=spiffs``, which Size (in bytes) of the SPIFFS area in Flash memory. To change this, edit the :ref:`hardware_config`. - .. envvar:: SPIFF_FILES - .. envvar:: SPIFF_FILES default: ``files`` diff --git a/Sming/Libraries/Spiffs/component.mk b/Sming/Libraries/Spiffs/component.mk index 946794670c..a482d6ff1f 100644 --- a/Sming/Libraries/Spiffs/component.mk +++ b/Sming/Libraries/Spiffs/component.mk @@ -19,7 +19,7 @@ SPIFF_BIN_OUT := $(FW_BASE)/$(SPIFF_BIN).bin COMPONENT_RELINK_VARS += SPIFF_FILEDESC_COUNT SPIFF_FILEDESC_COUNT ?= 7 -COMPONENT_CFLAGS += -DSPIFF_FILEDESC_COUNT=$(SPIFF_FILEDESC_COUNT) +COMPONENT_CXXFLAGS += -DSPIFF_FILEDESC_COUNT=$(SPIFF_FILEDESC_COUNT) COMPONENT_CFLAGS += -Wno-tautological-compare diff --git a/Sming/Libraries/Spiffs/src/FileSystem.cpp b/Sming/Libraries/Spiffs/src/FileSystem.cpp index 710a3adab6..c17b14cfb2 100644 --- a/Sming/Libraries/Spiffs/src/FileSystem.cpp +++ b/Sming/Libraries/Spiffs/src/FileSystem.cpp @@ -409,7 +409,7 @@ SpiffsMetaBuffer* FileSystem::initMetaBuffer(FileHandle file) SpiffsMetaBuffer* FileSystem::getMetaBuffer(FileHandle file) { unsigned off = SPIFFS_FH_UNOFFS(handle(), file) - 1; - if(off >= FFS_MAX_FILEDESC) { + if(off >= SPIFF_FILEDESC_COUNT) { debug_e("getMetaBuffer(%d) - bad file", file); return nullptr; } diff --git a/Sming/Libraries/Spiffs/src/include/IFS/SPIFFS/FileSystem.h b/Sming/Libraries/Spiffs/src/include/IFS/SPIFFS/FileSystem.h index be59da5e25..ed9279218e 100644 --- a/Sming/Libraries/Spiffs/src/include/IFS/SPIFFS/FileSystem.h +++ b/Sming/Libraries/Spiffs/src/include/IFS/SPIFFS/FileSystem.h @@ -48,11 +48,6 @@ extern "C" { #include "../../../../spiffs/src/spiffs_nucleus.h" } -/* - * Maxmimum number of open files - */ -#define FFS_MAX_FILEDESC 8 - namespace IFS { namespace SPIFFS @@ -139,10 +134,10 @@ class FileSystem : public IFileSystem Storage::Partition partition; IProfiler* profiler{nullptr}; - SpiffsMetaBuffer metaCache[FFS_MAX_FILEDESC]; + SpiffsMetaBuffer metaCache[SPIFF_FILEDESC_COUNT]; spiffs fs; uint16_t workBuffer[LOG_PAGE_SIZE]; - spiffs_fd fileDescriptors[FFS_MAX_FILEDESC]; + spiffs_fd fileDescriptors[SPIFF_FILEDESC_COUNT]; uint8_t cache[CACHE_SIZE]; }; diff --git a/Sming/Platform/System.cpp b/Sming/Platform/System.cpp index 52472fa658..f661d942fd 100644 --- a/Sming/Platform/System.cpp +++ b/Sming/Platform/System.cpp @@ -11,20 +11,25 @@ #include "Platform/System.h" #include "Timer.h" -#ifndef TASK_QUEUE_LENGTH +SystemClass System; +SystemState SystemClass::state = eSS_None; + +#ifdef ARCH_ESP32 +#undef TASK_QUEUE_LENGTH +#define TASK_QUEUE_LENGTH 0 +#define taskQueue nullptr +#else +#ifdef TASK_QUEUE_LENGTH +static_assert(TASK_QUEUE_LENGTH >= 8, "Task queue too small"); +#else /** @brief default number of tasks in global queue * @note tasks are usually short-lived and executed very promptly, so a large queue is * normally un-necessry. If queue overrun is suspected, check `SystemClass::getMaxTaskCount()`. */ #define TASK_QUEUE_LENGTH 10 #endif - -SystemClass System; - -SystemState SystemClass::state = eSS_None; os_event_t SystemClass::taskQueue[TASK_QUEUE_LENGTH]; - -static_assert(TASK_QUEUE_LENGTH >= 8, "Task queue too small"); +#endif #ifdef ENABLE_TASK_COUNT volatile uint8_t SystemClass::taskCount; diff --git a/Sming/build.mk b/Sming/build.mk index c3b8958cca..4c06fdabd9 100644 --- a/Sming/build.mk +++ b/Sming/build.mk @@ -31,6 +31,8 @@ else endif export SMING_RELEASE +SMING_TOOLS := $(realpath $(SMING_HOME)/../Tools) + # Detect OS and build environment TOOL_EXT := DEBUG_VARS += UNAME diff --git a/Sming/component.mk b/Sming/component.mk index b24c7014e1..1ea550f99a 100644 --- a/Sming/component.mk +++ b/Sming/component.mk @@ -62,13 +62,6 @@ ifeq ($(DISABLE_WIFI),1) GLOBAL_CFLAGS += -DDISABLE_WIFI=1 endif -# WiFi settings may be provide via Environment variables -CONFIG_VARS += WIFI_SSID WIFI_PWD -ifdef WIFI_SSID - APP_CFLAGS += -DWIFI_SSID=\"$(WIFI_SSID)\" - APP_CFLAGS += -DWIFI_PWD=\"$(WIFI_PWD)\" -endif - # => LOCALE COMPONENT_VARS += LOCALE ifdef LOCALE diff --git a/Sming/project.mk b/Sming/project.mk index 828ef31c58..37a393d241 100644 --- a/Sming/project.mk +++ b/Sming/project.mk @@ -536,7 +536,7 @@ export HOST_PARAMETERS .PHONY: ide-vscode-update ide-vscode-update: $(Q) SMING_HOME=$(SMING_HOME) OUT_BASE=$(OUT_BASE) \ - $(PYTHON) $(SMING_HOME)/../Tools/vscode/setup.py + $(PYTHON) $(SMING_TOOLS)/vscode/setup.py ##@Testing @@ -671,3 +671,28 @@ CACHED_VAR_NAMES := $(sort $(CACHED_VAR_NAMES) $(CONFIG_VARS) $(RELINK_VARS) $(C $(eval $(call WriteConfigCache,$(CONFIG_CACHE_FILE),CACHED_VAR_NAMES)) $(eval $(call WriteCacheValues,$(CONFIG_DEBUG_FILE),$(sort $(DEBUG_VARS)))) endif + + +##@Configuration + +export UNAME +# List of all Kconfig files +export KCONFIG_FILES = $(wildcard $(foreach c,$(filter-out Sming,$(COMPONENTS)),$(CMP_$c_PATH)/Kconfig)) +# File containing list of component Kconfig file paths (created by cfgtool) +export KCONFIG_COMPONENTS = $(OUT_BASE)/kconfig.in + +KCONFIG := $(SMING_HOME)/Kconfig +KCONFIG_CONFIG := $(OUT_BASE)/kconfig.config + +KCONFIG_ENV := \ + CONFIG_= \ + KCONFIG=$(KCONFIG) \ + KCONFIG_CONFIG=$(KCONFIG_CONFIG) + +CFGTOOL_CMDLINE = $(KCONFIG_ENV) $(PYTHON) $(SMING_TOOLS)/cfgtool.py $(CONFIG_CACHE_FILE) + +.PHONY: menuconfig +menuconfig: ##Run option editor + $(Q) $(CFGTOOL_CMDLINE) --to-kconfig + $(Q) $(KCONFIG_ENV) $(PYTHON) -m menuconfig $(SMING_HOME)/Kconfig + $(Q) $(CFGTOOL_CMDLINE) --from-kconfig diff --git a/Tools/cfgtool.py b/Tools/cfgtool.py new file mode 100644 index 0000000000..a40a0bc7e6 --- /dev/null +++ b/Tools/cfgtool.py @@ -0,0 +1,110 @@ +#!/usr/bin/env python3 +# +# Sming configuration management tool +# +# Used by build system to enable compatibility with Kconfig +# +# + +import argparse, configparser, os, sys, platform, kconfiglib + + +def load_config_vars(filename): + parser = configparser.ConfigParser() + parser.optionxform = str # preserve case + with open(filename) as f: + data = "[config]\n" + f.read() + data = data.replace(' := ', ' = ') + parser.read_string(data) + return parser['config'] + + +def set_kconfig_value(symbol, v): + """Convert values from Sming format to Kconfig format. + + Hidden variables are used to store choice selections and cannot be set directly. + Instead, locate the corresponding choice variable and set that. + """ + if symbol.visibility == 2: + if symbol.type is kconfiglib.BOOL: + v = 'y' if v == '1' else 'n' + elif symbol.type == kconfiglib._T_INT: + v = 0 if v == '' else v + symbol.set_value(v) + else: + for sym, cond in symbol.defaults: + if isinstance(cond, tuple): + cond = cond[1] + if not isinstance(cond, kconfiglib.Symbol): + continue + if v == sym.name and cond.type is kconfiglib.BOOL: + cond.set_value('y') + break + + +def fixpath(path): + """Paths in Windows can get a little weird""" + if len(path) > 2 and path[1] != ':' and platform.system() == 'Windows' and path[2] == '/': + return path[1] + ':' + path[2:] + return path + + +def createComponentsFile(): + fileList = os.environ['KCONFIG_FILES'].split() + compFile = os.environ['KCONFIG_COMPONENTS'] + with open(compFile, "w") as f: + for s in fileList: + f.write('source "%s"\n' % fixpath(s)) + + +def main(): + parser = argparse.ArgumentParser(description='Sming configuration management tool') + parser.add_argument('--to-kconfig', help="Convert Sming configuration to Kconfig format", action='store_true') + parser.add_argument('--from-kconfig', help="Convert Kconfig configration to Sming format", action='store_true') + parser.add_argument('config_file', help='Source configuration file') + + args = parser.parse_args() + + if args.to_kconfig: + createComponentsFile() + + conf = kconfiglib.Kconfig(os.environ['KCONFIG']) + src = load_config_vars(args.config_file) + for k, v in src.items(): + c = conf.syms.get(k) + if c: + set_kconfig_value(c, v) + conf.write_config(os.environ['KCONFIG_CONFIG']) + elif args.from_kconfig: + conf = kconfiglib.Kconfig(os.environ['KCONFIG']) + conf.load_config(os.environ['KCONFIG_CONFIG']) + dst = load_config_vars(args.config_file) + varnames = set(dst.pop('CACHED_VAR_NAMES').split()) + + for k, sym in conf.syms.items(): + if sym.type is kconfiglib.UNKNOWN: + continue + if sym.env_var is not None: + continue + v = str(sym.user_value) if sym.user_value else "" + if sym.type is kconfiglib.BOOL: + v = "1" if v in ['y', '2'] else "0" + dst[sym.name] = v + varnames.add(sym.name) + with open(args.config_file, "w") as f: + for k, v in dst.items(): + f.write("%s=%s\n" % (k, v)) + f.write("\n") + varnames = list(varnames) + varnames.sort() + f.write("CACHED_VAR_NAMES := " + " ".join(varnames)) + else: + raise RuntimeError("No command specified") + + +if __name__ == '__main__': + try: + main() + except Exception as e: + print("** ERROR! %s" % e, file=sys.stderr) + sys.exit(2) diff --git a/Tools/requirements.txt b/Tools/requirements.txt index ee96c8f8e1..bc47cf1a0c 100644 --- a/Tools/requirements.txt +++ b/Tools/requirements.txt @@ -1,2 +1,3 @@ pyserial jsonschema +kconfiglib diff --git a/samples/Basic_IFS/Kconfig b/samples/Basic_IFS/Kconfig new file mode 100644 index 0000000000..9cf1c781ba --- /dev/null +++ b/samples/Basic_IFS/Kconfig @@ -0,0 +1,9 @@ +menu "Basic IFS sample" + config ENABLE_FLASHSTRING_IMAGE + bool "Store filesystem image in a FlashString object instead of partition" + + config HWCONFIG + string "Project hardware configuration" + default "basic_ifs_$(SMING_ARCH)" if ENABLE_FLASHSTRING_IMAGE + default "spiffs" if !ENABLE_FLASHSTRING_IMAGE +endmenu