From e0b1ada6ac82de14223b468ff8f2ed58a351f1e2 Mon Sep 17 00:00:00 2001 From: josesimoes Date: Wed, 28 Feb 2024 11:19:13 +0000 Subject: [PATCH 01/18] Add implementation for Storage Operation WP command - Add supporting enum (mirroring C# declaration). - Add declaration for handler function. --- src/CLR/Include/WireProtocol.h | 1 + .../Include/WireProtocol_MonitorCommands.h | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/CLR/Include/WireProtocol.h b/src/CLR/Include/WireProtocol.h index 4510e8d4f0..3f4563a330 100644 --- a/src/CLR/Include/WireProtocol.h +++ b/src/CLR/Include/WireProtocol.h @@ -87,6 +87,7 @@ typedef enum CLR_DBG_Commands_Monitor CLR_DBG_Commands_c_Monitor_OemInfo = 0x0000000E, CLR_DBG_Commands_c_Monitor_QueryConfiguration = 0x0000000F, CLR_DBG_Commands_c_Monitor_UpdateConfiguration = 0x00000010, + CLR_DBG_Commands_c_Monitor_StorageOperation = 0x00000011, CLR_DBG_Commands_c_Monitor_TargetInfo = 0x00000020, }CLR_DBG_Commands_Monitor; diff --git a/src/CLR/Include/WireProtocol_MonitorCommands.h b/src/CLR/Include/WireProtocol_MonitorCommands.h index aa2f99bd41..17f41871d7 100644 --- a/src/CLR/Include/WireProtocol_MonitorCommands.h +++ b/src/CLR/Include/WireProtocol_MonitorCommands.h @@ -56,6 +56,17 @@ typedef enum MemoryMap_Options } MemoryMap_Options; +// structure for storage operations +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// !!! KEEP IN SYNC WITH nanoFramework.Tools.Debugger.WireProtocol.Monitor_StorageOperation.StorageOperation (in managed code) !!! // +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +typedef enum Monitor_StorageOperation +{ + StorageOperation_None = 0, + StorageOperation_Write = 1, + StorageOperation_Delete = 2 +} Monitor_StorageOperation; + ////////////////////////////////////////// // typedefs @@ -163,6 +174,22 @@ typedef struct __nfpack Monitor_UpdateConfiguration_Command } Monitor_UpdateConfiguration_Command; + +typedef struct Monitor_StorageOperation_Command +{ + uint8_t Operation; + uint32_t Length; + uint8_t StorageName[128]; + uint8_t Data[1]; + +} Monitor_StorageOperation_Command; + +typedef struct Monitor_StorageOperation_Reply +{ + uint32_t ErrorCode; + +} Monitor_StorageOperation_Reply; + typedef struct Monitor_UpdateConfiguration_Reply { uint32_t ErrorCode; @@ -196,6 +223,7 @@ extern "C" int Monitor_Reboot(WP_Message *message); int Monitor_EraseMemory(WP_Message *message); int Monitor_QueryConfiguration(WP_Message *message); + int Monitor_StorageOperation(WP_Message *message); int Monitor_UpdateConfiguration(WP_Message *message); int Monitor_CheckMemory(WP_Message *message); int Monitor_MemoryMap(WP_Message *message); From 5ae779f7ebd98645b3555cc52196a8601e1f4235 Mon Sep 17 00:00:00 2001 From: Laurent Ellerbach Date: Sat, 9 Mar 2024 19:37:56 +0000 Subject: [PATCH 02/18] adding logic --- CMake/AzureRTOS_target_os.h.in | 1 + CMake/ChibiOS_target_os.h.in | 1 + CMake/ESP32_target_os.h.in | 1 + CMake/FreeRTOS_target_os.h.in | 1 + CMake/TI_SimpleLink_target_os.h.in | 1 + CMake/xtensa-esp32.json | 1 + CMake/xtensa-esp32c3.json | 1 + CMake/xtensa-esp32s2.json | 1 + CMake/xtensa-esp32s3.json | 1 + CMakeLists.txt | 13 ++++ src/CLR/Debugger/Debugger.cpp | 23 ++++++ src/CLR/Debugger/Debugger.h | 11 +++ .../Include/WireProtocol_MonitorCommands.h | 4 +- src/CLR/Include/nanoCLR_Debugging.h | 2 +- .../WireProtocol_MonitorCommands.c | 22 ++++++ src/HAL/Include/nanoHAL_StorageOperation.h | 27 +++++++ .../Maxim/MAX78000_FTHR/nanoBooter/main.c | 1 + .../Maxim/MAX78000_FTHR/nanoCLR/main.c | 1 + .../AzureRTOS/Maxim/_common/CMakeLists.txt | 5 ++ .../AzureRTOS/Maxim/_nanoCLR/targetHAL.cpp | 1 + .../ST/ORGPAL_PALTHREE/nanoBooter/main.c | 1 + .../ST/ST_B_L475E_IOT01A/nanoBooter/main.c | 1 + .../ST/ST_B_L475E_IOT01A/nanoCLR/main.c | 1 + targets/AzureRTOS/ST/_common/CMakeLists.txt | 5 ++ .../drivers/wifi/inventek/ISM43362_sockets.h | 1 + targets/AzureRTOS/ST/_nanoCLR/targetHAL.cpp | 1 + .../SiliconLabs/_common/CMakeLists.txt | 5 ++ .../SiliconLabs/_nanoCLR/targetHAL.cpp | 1 + .../ChibiOS/ORGPAL_PALTHREE/nanoBooter/main.c | 1 + .../ST_STM32F769I_DISCOVERY/nanoBooter/main.c | 1 + targets/ChibiOS/_common/CMakeLists.txt | 5 ++ targets/ChibiOS/_nanoCLR/targetHAL.cpp | 1 + targets/ESP32/_common/CMakeLists.txt | 2 + .../_common/targetHAL_ConfigStorageSPIFFS.c | 3 - .../ESP32/_common/targetHAL_FileOperation.cpp | 70 +++++++++++++++++++ .../_common/targetHAL_StorageOperation.cpp | 64 +++++++++++++++++ .../ESP32/_include/targetHAL_ConfigStorage.h | 3 + .../ESP32/_include/targetHAL_FileOperation.h | 19 +++++ .../_include/targetHAL_StorageOperation.h | 14 ++++ ..._sys_io_filesystem_System_IO_Directory.cpp | 3 +- .../nf_sys_io_filesystem_System_IO_File.cpp | 4 +- ...sys_io_filesystem_System_IO_FileStream.cpp | 62 +--------------- targets/ESP32/_nanoCLR/targetHAL.cpp | 1 + .../NXP/NXP_MIMXRT1060_EVK/nanoBooter/main.c | 1 + targets/FreeRTOS/NXP/_common/CMakeLists.txt | 5 ++ targets/FreeRTOS/NXP/_nanoCLR/targetHAL.cpp | 1 + targets/TI_SimpleLink/_nanoCLR/targetHAL.cpp | 1 + 47 files changed, 324 insertions(+), 72 deletions(-) create mode 100644 src/HAL/Include/nanoHAL_StorageOperation.h create mode 100644 targets/ESP32/_common/targetHAL_FileOperation.cpp create mode 100644 targets/ESP32/_common/targetHAL_StorageOperation.cpp create mode 100644 targets/ESP32/_include/targetHAL_FileOperation.h create mode 100644 targets/ESP32/_include/targetHAL_StorageOperation.h diff --git a/CMake/AzureRTOS_target_os.h.in b/CMake/AzureRTOS_target_os.h.in index 0c70efc014..d16582bade 100644 --- a/CMake/AzureRTOS_target_os.h.in +++ b/CMake/AzureRTOS_target_os.h.in @@ -27,6 +27,7 @@ #define DP_FLOATINGPOINT @TARGET_DP_FLOATINGPOINT@ #define SUPPORT_ANY_BASE_CONVERSION @TARGET_SUPPORT_ANY_BASE_CONVERSION@ #define HAS_CONFIG_BLOCK @TARGET_HAS_CONFIG_BLOCK@ +#define HAS_INTERNAL_STORAGE @TARGET_HAS_INTERNAL_STORAGE@ #define NANOCLR_REFLECTION @TARGET_NANOCLR_REFLECTION@ #define NANOCLR_SYSTEM_COLLECTIONS @TARGET_SYSTEM_COLLECTIONS@ #define TARGET_HAS_NANOBOOTER @TARGET_HAS_NANOBOOTER@ diff --git a/CMake/ChibiOS_target_os.h.in b/CMake/ChibiOS_target_os.h.in index c368b5c909..faa8426b7b 100644 --- a/CMake/ChibiOS_target_os.h.in +++ b/CMake/ChibiOS_target_os.h.in @@ -27,6 +27,7 @@ #define DP_FLOATINGPOINT @TARGET_DP_FLOATINGPOINT@ #define SUPPORT_ANY_BASE_CONVERSION @TARGET_SUPPORT_ANY_BASE_CONVERSION@ #define HAS_CONFIG_BLOCK @TARGET_HAS_CONFIG_BLOCK@ +#define HAS_INTERNAL_STORAGE @TARGET_HAS_INTERNAL_STORAGE@ #define NANOCLR_REFLECTION @TARGET_NANOCLR_REFLECTION@ #define NANOCLR_SYSTEM_COLLECTIONS @TARGET_SYSTEM_COLLECTIONS@ #define TARGET_HAS_NANOBOOTER @TARGET_HAS_NANOBOOTER@ diff --git a/CMake/ESP32_target_os.h.in b/CMake/ESP32_target_os.h.in index b71783e3ec..38b98a54d7 100644 --- a/CMake/ESP32_target_os.h.in +++ b/CMake/ESP32_target_os.h.in @@ -24,6 +24,7 @@ #define DP_FLOATINGPOINT @TARGET_DP_FLOATINGPOINT@ #define SUPPORT_ANY_BASE_CONVERSION @TARGET_SUPPORT_ANY_BASE_CONVERSION@ #define HAS_CONFIG_BLOCK @TARGET_HAS_CONFIG_BLOCK@ +#define HAS_INTERNAL_STORAGE @TARGET_HAS_INTERNAL_STORAGE@ #define NANOCLR_REFLECTION @TARGET_NANOCLR_REFLECTION@ #define NANOCLR_SYSTEM_COLLECTIONS @TARGET_SYSTEM_COLLECTIONS@ #define TARGET_HAS_NANOBOOTER FALSE diff --git a/CMake/FreeRTOS_target_os.h.in b/CMake/FreeRTOS_target_os.h.in index 30c0693f91..4d7e8b448f 100644 --- a/CMake/FreeRTOS_target_os.h.in +++ b/CMake/FreeRTOS_target_os.h.in @@ -25,6 +25,7 @@ #define DP_FLOATINGPOINT @TARGET_DP_FLOATINGPOINT@ #define SUPPORT_ANY_BASE_CONVERSION @TARGET_SUPPORT_ANY_BASE_CONVERSION@ #define HAS_CONFIG_BLOCK @TARGET_HAS_CONFIG_BLOCK@ +#define HAS_INTERNAL_STORAGE @TARGET_HAS_INTERNAL_STORAGE@ #define NANOCLR_REFLECTION @TARGET_NANOCLR_REFLECTION@ #define NANOCLR_SYSTEM_COLLECTIONS @TARGET_SYSTEM_COLLECTIONS@ #define TARGET_HAS_NANOBOOTER @TARGET_HAS_NANOBOOTER@ diff --git a/CMake/TI_SimpleLink_target_os.h.in b/CMake/TI_SimpleLink_target_os.h.in index 26063d19e1..d48488c8cc 100644 --- a/CMake/TI_SimpleLink_target_os.h.in +++ b/CMake/TI_SimpleLink_target_os.h.in @@ -20,6 +20,7 @@ #define DP_FLOATINGPOINT @TARGET_DP_FLOATINGPOINT@ #define SUPPORT_ANY_BASE_CONVERSION @TARGET_SUPPORT_ANY_BASE_CONVERSION@ #define HAS_CONFIG_BLOCK @TARGET_HAS_CONFIG_BLOCK@ +#define HAS_INTERNAL_STORAGE @TARGET_HAS_INTERNAL_STORAGE@ #define NANOCLR_REFLECTION @TARGET_NANOCLR_REFLECTION@ #define NANOCLR_SYSTEM_COLLECTIONS @TARGET_SYSTEM_COLLECTIONS@ #define TARGET_HAS_NANOBOOTER FALSE diff --git a/CMake/xtensa-esp32.json b/CMake/xtensa-esp32.json index 257b67f53a..ef6e47583b 100644 --- a/CMake/xtensa-esp32.json +++ b/CMake/xtensa-esp32.json @@ -20,6 +20,7 @@ "TARGET_SERIES": "ESP32", "TARGET_BOARD": "ESP32", "NF_FEATURE_HAS_CONFIG_BLOCK": "ON", + "NF_FEATURE_HAS_INTERNAL_STORAGE": "ON", "SUPPORT_ANY_BASE_CONVERSION": "ON", "API_System.Net": "ON", "API_System.Math": "ON", diff --git a/CMake/xtensa-esp32c3.json b/CMake/xtensa-esp32c3.json index baf2455cfa..ed97ff5949 100644 --- a/CMake/xtensa-esp32c3.json +++ b/CMake/xtensa-esp32c3.json @@ -20,6 +20,7 @@ "TARGET_SERIES": "ESP32_C3", "TARGET_BOARD": "ESP32_C3", "NF_FEATURE_HAS_CONFIG_BLOCK": "ON", + "NF_FEATURE_HAS_INTERNAL_STORAGE": "ON", "SUPPORT_ANY_BASE_CONVERSION": "ON", "API_System.Net": "ON", "API_System.Math": "ON", diff --git a/CMake/xtensa-esp32s2.json b/CMake/xtensa-esp32s2.json index e99a301520..888ddc7795 100644 --- a/CMake/xtensa-esp32s2.json +++ b/CMake/xtensa-esp32s2.json @@ -20,6 +20,7 @@ "TARGET_SERIES": "ESP32_S2", "TARGET_BOARD": "ESP32_S2", "NF_FEATURE_HAS_CONFIG_BLOCK": "ON", + "NF_FEATURE_HAS_INTERNAL_STORAGE": "ON", "SUPPORT_ANY_BASE_CONVERSION": "ON", "API_System.Net": "ON", "API_System.Math": "ON", diff --git a/CMake/xtensa-esp32s3.json b/CMake/xtensa-esp32s3.json index 7e502075a2..78470ab94c 100644 --- a/CMake/xtensa-esp32s3.json +++ b/CMake/xtensa-esp32s3.json @@ -20,6 +20,7 @@ "TARGET_SERIES": "ESP32_S3", "TARGET_BOARD": "ESP32_S3", "NF_FEATURE_HAS_CONFIG_BLOCK": "ON", + "NF_FEATURE_HAS_INTERNAL_STORAGE": "ON", "SUPPORT_ANY_BASE_CONVERSION": "ON", "API_System.Net": "ON", "API_System.Math": "ON", diff --git a/CMakeLists.txt b/CMakeLists.txt index f3965581d9..d6e5a5a663 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -287,6 +287,19 @@ else() message(STATUS "Configuration block storage **IS NOT** included") endif() +################################################################# +# enables internal storage support +# (default is OFF so Configuration block storage is NOT supported) +option(NF_FEATURE_HAS_INTERNAL_STORAGE "option to enable internal storage") + +if(NF_FEATURE_HAS_INTERNAL_STORAGE) + set(TARGET_HAS_INTERNAL_STORAGE TRUE CACHE INTERNAL "Option for internal storage") + message(STATUS "Configuration internal storage is included") +else() + set(TARGET_HAS_INTERNAL_STORAGE FALSE CACHE INTERNAL "Option for internal storage") + message(STATUS "Configuration internal storage **IS NOT** included") +endif() + ################################################################# # enables support for SD Card # (default is OFF so SD Card is NOT supported) diff --git a/src/CLR/Debugger/Debugger.cpp b/src/CLR/Debugger/Debugger.cpp index 5775b62316..a3a6756aa5 100644 --- a/src/CLR/Debugger/Debugger.cpp +++ b/src/CLR/Debugger/Debugger.cpp @@ -1335,6 +1335,29 @@ bool CLR_DBG_Debugger::Monitor_UpdateConfiguration(WP_Message *message) #endif } +bool CLR_DBG_Debugger::Monitor_StorageOperation(WP_Message *message) +{ + NATIVE_PROFILE_CLR_DEBUGGER(); + debug_printf("Monitor_StorageOperation"); +#if (HAS_INTERNAL_STORAGE == TRUE) + + Monitor_StorageOperation_Command *cmd = (Monitor_StorageOperation_Command *)message->m_payload; + Monitor_StorageOperation_Reply cmdReply; + uint8_t err = 0; + + //HAL_StorageOperation(cmd->Operation, cmd->Length, cmd->StorageName, cmd->Data, &err); + cmdReply.ErrorCode = err; + + WP_ReplyToCommand(message, true, false, &cmdReply, sizeof(cmdReply)); + + return true; + +#endif + + (void)message; + return false; +} + //--// bool CLR_DBG_Debugger::Debugging_Execution_BasePtr(WP_Message *msg) diff --git a/src/CLR/Debugger/Debugger.h b/src/CLR/Debugger/Debugger.h index c6ad35cabb..44ba64649c 100644 --- a/src/CLR/Debugger/Debugger.h +++ b/src/CLR/Debugger/Debugger.h @@ -98,4 +98,15 @@ typedef enum AccessMemoryErrorCodes }AccessMemoryErrorCodes; +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// !!! KEEP IN SYNC WITH nanoFramework.Tools.Debugger.WireProtocol.StorageOperationErrorCodes (in managed code) !!! // +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +typedef enum StorageOperationErrorCodes +{ + NoError = 0x0001, // no error + WriteError = 0x0010, // write error + DeleteError = 0x0020, // delete error + +}StorageOperationErrorCodes; + #endif //DEBUGGER_H diff --git a/src/CLR/Include/WireProtocol_MonitorCommands.h b/src/CLR/Include/WireProtocol_MonitorCommands.h index 17f41871d7..b396163990 100644 --- a/src/CLR/Include/WireProtocol_MonitorCommands.h +++ b/src/CLR/Include/WireProtocol_MonitorCommands.h @@ -60,12 +60,12 @@ typedef enum MemoryMap_Options ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // !!! KEEP IN SYNC WITH nanoFramework.Tools.Debugger.WireProtocol.Monitor_StorageOperation.StorageOperation (in managed code) !!! // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -typedef enum Monitor_StorageOperation +typedef enum StorageOperation_Monitor { StorageOperation_None = 0, StorageOperation_Write = 1, StorageOperation_Delete = 2 -} Monitor_StorageOperation; +} StorageOperation_Monitor; ////////////////////////////////////////// // typedefs diff --git a/src/CLR/Include/nanoCLR_Debugging.h b/src/CLR/Include/nanoCLR_Debugging.h index 501cca1f76..99e7677180 100644 --- a/src/CLR/Include/nanoCLR_Debugging.h +++ b/src/CLR/Include/nanoCLR_Debugging.h @@ -933,7 +933,7 @@ struct CLR_DBG_Debugger static bool Monitor_DeploymentMap ( WP_Message *msg ); static bool Monitor_QueryConfiguration ( WP_Message *msg ); static bool Monitor_UpdateConfiguration ( WP_Message *msg ); - + static bool Monitor_StorageOperation ( WP_Message *msg ); static bool Debugging_Execution_BasePtr ( WP_Message *msg ); static bool Debugging_Execution_ChangeConditions ( WP_Message *msg ); diff --git a/src/CLR/WireProtocol/WireProtocol_MonitorCommands.c b/src/CLR/WireProtocol/WireProtocol_MonitorCommands.c index b1bd1daaa4..6e502dbbe6 100644 --- a/src/CLR/WireProtocol/WireProtocol_MonitorCommands.c +++ b/src/CLR/WireProtocol/WireProtocol_MonitorCommands.c @@ -253,6 +253,28 @@ int Monitor_UpdateConfiguration(WP_Message *message) return success; } +int Monitor_StorageOperation(WP_Message *message) +{ + debug_printf("Monitor_StorageOperation"); +#if (HAS_INTERNAL_STORAGE == TRUE) + + Monitor_StorageOperation_Command *cmd = (Monitor_StorageOperation_Command *)message->m_payload; + Monitor_StorageOperation_Reply cmdReply; + uint8_t err = 0; + + HAL_StorageOperation(cmd->Operation, cmd->Length, cmd->StorageName, cmd->Data, &err); + cmdReply.ErrorCode = err; + + WP_ReplyToCommand(message, true, false, &cmdReply, sizeof(cmdReply)); + + return true; + +#endif + + (void)message; + return false; +} + int Monitor_CheckMemory(WP_Message *message) { bool ret = false; diff --git a/src/HAL/Include/nanoHAL_StorageOperation.h b/src/HAL/Include/nanoHAL_StorageOperation.h new file mode 100644 index 0000000000..02573b1d89 --- /dev/null +++ b/src/HAL/Include/nanoHAL_StorageOperation.h @@ -0,0 +1,27 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +#ifndef NANOHAL_STORAGE_OPERATION_H +#define NANOHAL_STORAGE_OPERATION_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + void HAL_StorageOperation( + uint8_t operation, + uint32_t *length, + uint8_t *storageName, + uint8_t *data, + uint32_t *errorCode); + +#ifdef __cplusplus +} +#endif + +#endif // NANOHAL_STORAGE_OPERATIN_H \ No newline at end of file diff --git a/targets/AzureRTOS/Maxim/MAX78000_FTHR/nanoBooter/main.c b/targets/AzureRTOS/Maxim/MAX78000_FTHR/nanoBooter/main.c index 835a7d0ccc..6b006e4c81 100644 --- a/targets/AzureRTOS/Maxim/MAX78000_FTHR/nanoBooter/main.c +++ b/targets/AzureRTOS/Maxim/MAX78000_FTHR/nanoBooter/main.c @@ -11,6 +11,7 @@ #include #include #include +#include #include diff --git a/targets/AzureRTOS/Maxim/MAX78000_FTHR/nanoCLR/main.c b/targets/AzureRTOS/Maxim/MAX78000_FTHR/nanoCLR/main.c index 2312420cf8..b053c82c44 100644 --- a/targets/AzureRTOS/Maxim/MAX78000_FTHR/nanoCLR/main.c +++ b/targets/AzureRTOS/Maxim/MAX78000_FTHR/nanoCLR/main.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include "led.h" diff --git a/targets/AzureRTOS/Maxim/_common/CMakeLists.txt b/targets/AzureRTOS/Maxim/_common/CMakeLists.txt index 459a5f4bc4..6a6895a823 100644 --- a/targets/AzureRTOS/Maxim/_common/CMakeLists.txt +++ b/targets/AzureRTOS/Maxim/_common/CMakeLists.txt @@ -12,6 +12,11 @@ if(NF_FEATURE_HAS_CONFIG_BLOCK) list(APPEND TARGET_AZURERTOS_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/targetHAL_ConfigurationManager.cpp) endif() +# include internal storage, if feature is enabled +if(NF_FEATURE_HAS_INTERNAL_STORAGE) + list(APPEND TARGET_AZURERTOS_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/targetHAL_StorageOperation.cpp) +endif() + # append hard fault handler if the build type is to include debug info if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") list(APPEND TARGET_AZURERTOS_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/hard_fault_handler.c) diff --git a/targets/AzureRTOS/Maxim/_nanoCLR/targetHAL.cpp b/targets/AzureRTOS/Maxim/_nanoCLR/targetHAL.cpp index 3cd2dcfc2e..e0f857fd3a 100644 --- a/targets/AzureRTOS/Maxim/_nanoCLR/targetHAL.cpp +++ b/targets/AzureRTOS/Maxim/_nanoCLR/targetHAL.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include diff --git a/targets/AzureRTOS/ST/ORGPAL_PALTHREE/nanoBooter/main.c b/targets/AzureRTOS/ST/ORGPAL_PALTHREE/nanoBooter/main.c index ec82c2eaba..0e34e0bad1 100644 --- a/targets/AzureRTOS/ST/ORGPAL_PALTHREE/nanoBooter/main.c +++ b/targets/AzureRTOS/ST/ORGPAL_PALTHREE/nanoBooter/main.c @@ -10,6 +10,7 @@ #include #include #include +#include #include // byte pool configuration and definitions diff --git a/targets/AzureRTOS/ST/ST_B_L475E_IOT01A/nanoBooter/main.c b/targets/AzureRTOS/ST/ST_B_L475E_IOT01A/nanoBooter/main.c index b72ba0c138..c1e330532d 100644 --- a/targets/AzureRTOS/ST/ST_B_L475E_IOT01A/nanoBooter/main.c +++ b/targets/AzureRTOS/ST/ST_B_L475E_IOT01A/nanoBooter/main.c @@ -13,6 +13,7 @@ #include #include #include +#include // byte pool configuration and definitions #define DEFAULT_BYTE_POOL_SIZE 4096 diff --git a/targets/AzureRTOS/ST/ST_B_L475E_IOT01A/nanoCLR/main.c b/targets/AzureRTOS/ST/ST_B_L475E_IOT01A/nanoCLR/main.c index 7993e763f3..2d92fbc5d4 100644 --- a/targets/AzureRTOS/ST/ST_B_L475E_IOT01A/nanoCLR/main.c +++ b/targets/AzureRTOS/ST/ST_B_L475E_IOT01A/nanoCLR/main.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include diff --git a/targets/AzureRTOS/ST/_common/CMakeLists.txt b/targets/AzureRTOS/ST/_common/CMakeLists.txt index fa012d625a..f0953d7286 100644 --- a/targets/AzureRTOS/ST/_common/CMakeLists.txt +++ b/targets/AzureRTOS/ST/_common/CMakeLists.txt @@ -22,6 +22,11 @@ if(NF_FEATURE_HAS_CONFIG_BLOCK) list(APPEND TARGET_AZURERTOS_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/targetHAL_ConfigurationManager.cpp) endif() +# include internal storage, if feature is enabled +if(NF_FEATURE_HAS_INTERNAL_STORAGE) + list(APPEND TARGET_AZURERTOS_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/targetHAL_StorageOperation.cpp) +endif() + if(NF_TRACE_TO_STDIO) list(APPEND TARGET_AZURERTOS_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Target_GenericPort_stdio.c) list(APPEND TARGET_AZURERTOS_COMMON_SOURCES ${TARGET_BASE_LOCATION}/target_stdio_config.c) diff --git a/targets/AzureRTOS/ST/_common/drivers/wifi/inventek/ISM43362_sockets.h b/targets/AzureRTOS/ST/_common/drivers/wifi/inventek/ISM43362_sockets.h index 5d49c640b6..7dff802b7e 100644 --- a/targets/AzureRTOS/ST/_common/drivers/wifi/inventek/ISM43362_sockets.h +++ b/targets/AzureRTOS/ST/_common/drivers/wifi/inventek/ISM43362_sockets.h @@ -8,6 +8,7 @@ #include #include +#include #include "wifi.h" #define NATIVE_PROFILE_PAL_NETWORK() diff --git a/targets/AzureRTOS/ST/_nanoCLR/targetHAL.cpp b/targets/AzureRTOS/ST/_nanoCLR/targetHAL.cpp index 9bb022b8bc..f50cbf05cb 100644 --- a/targets/AzureRTOS/ST/_nanoCLR/targetHAL.cpp +++ b/targets/AzureRTOS/ST/_nanoCLR/targetHAL.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include // #if (HAL_USE_CAN == TRUE) diff --git a/targets/AzureRTOS/SiliconLabs/_common/CMakeLists.txt b/targets/AzureRTOS/SiliconLabs/_common/CMakeLists.txt index 86fbb3bc2c..b4f85784e6 100644 --- a/targets/AzureRTOS/SiliconLabs/_common/CMakeLists.txt +++ b/targets/AzureRTOS/SiliconLabs/_common/CMakeLists.txt @@ -18,6 +18,11 @@ if(NF_FEATURE_HAS_CONFIG_BLOCK) list(APPEND TARGET_AZURERTOS_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/targetHAL_ConfigurationManager.cpp) endif() +# include internal storage, if feature is enabled +if(NF_FEATURE_HAS_INTERNAL_STORAGE) + list(APPEND TARGET_AZURERTOS_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/targetHAL_StorageOperation.cpp) +endif() + if(HAL_WP_USE_USB_CDC) list(APPEND TARGET_AZURERTOS_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/usb_cdc_acm_app.c) list(APPEND TARGET_AZURERTOS_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/WireProtocol_ReceiverThread_Platform.c) diff --git a/targets/AzureRTOS/SiliconLabs/_nanoCLR/targetHAL.cpp b/targets/AzureRTOS/SiliconLabs/_nanoCLR/targetHAL.cpp index 701868f4b9..d1a4aafefd 100644 --- a/targets/AzureRTOS/SiliconLabs/_nanoCLR/targetHAL.cpp +++ b/targets/AzureRTOS/SiliconLabs/_nanoCLR/targetHAL.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include diff --git a/targets/ChibiOS/ORGPAL_PALTHREE/nanoBooter/main.c b/targets/ChibiOS/ORGPAL_PALTHREE/nanoBooter/main.c index 9d9e3c9c98..9fc107bcd6 100644 --- a/targets/ChibiOS/ORGPAL_PALTHREE/nanoBooter/main.c +++ b/targets/ChibiOS/ORGPAL_PALTHREE/nanoBooter/main.c @@ -14,6 +14,7 @@ #include #include #include +#include #include // need to declare the Receiver thread here diff --git a/targets/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/main.c b/targets/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/main.c index ed31c6ef93..241824b8a1 100644 --- a/targets/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/main.c +++ b/targets/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/main.c @@ -14,6 +14,7 @@ #include #include #include +#include #include // need to declare the Receiver thread here diff --git a/targets/ChibiOS/_common/CMakeLists.txt b/targets/ChibiOS/_common/CMakeLists.txt index fdb1d6231f..073d79a4df 100644 --- a/targets/ChibiOS/_common/CMakeLists.txt +++ b/targets/ChibiOS/_common/CMakeLists.txt @@ -19,6 +19,11 @@ if(NF_FEATURE_HAS_CONFIG_BLOCK) list(APPEND TARGET_CHIBIOS_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/targetHAL_ConfigurationManager.cpp) endif() +# include internal storage, if feature is enabled +if(NF_FEATURE_HAS_INTERNAL_STORAGE) + list(APPEND TARGET_CHIBIOS_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/targetHAL_StorageOperation.cpp) +endif() + # append nanoHAL list(APPEND TARGET_CHIBIOS_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/targetHAL.c) list(APPEND TARGET_CHIBIOS_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/targetHAL_Time.cpp) diff --git a/targets/ChibiOS/_nanoCLR/targetHAL.cpp b/targets/ChibiOS/_nanoCLR/targetHAL.cpp index 8fb59b3253..b6db4df079 100644 --- a/targets/ChibiOS/_nanoCLR/targetHAL.cpp +++ b/targets/ChibiOS/_nanoCLR/targetHAL.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #if (HAL_USE_CAN == TRUE) diff --git a/targets/ESP32/_common/CMakeLists.txt b/targets/ESP32/_common/CMakeLists.txt index d1acee08a8..219fe2a694 100644 --- a/targets/ESP32/_common/CMakeLists.txt +++ b/targets/ESP32/_common/CMakeLists.txt @@ -17,6 +17,8 @@ list(APPEND TARGET_ESP32_IDF_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/WireProt list(APPEND TARGET_ESP32_IDF_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/targetHAL_ConfigStorageSPIFFS.c) list(APPEND TARGET_ESP32_IDF_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/targetHAL_ConfigurationManager.cpp) +list(APPEND TARGET_ESP32_IDF_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/targetHAL_StorageOperation.cpp) +list(APPEND TARGET_ESP32_IDF_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/targetHAL_FileOperation.cpp) list(APPEND TARGET_ESP32_IDF_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nanoSupport_CRC32.c) list(APPEND TARGET_ESP32_IDF_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/DeviceMapping_common.cpp) diff --git a/targets/ESP32/_common/targetHAL_ConfigStorageSPIFFS.c b/targets/ESP32/_common/targetHAL_ConfigStorageSPIFFS.c index fb4e750f72..eefe05a945 100644 --- a/targets/ESP32/_common/targetHAL_ConfigStorageSPIFFS.c +++ b/targets/ESP32/_common/targetHAL_ConfigStorageSPIFFS.c @@ -12,9 +12,6 @@ #define NANO_SPIFFS_BASE_PATH "/I" #define NANO_SPIFFS_CONFIG_NAME "con_" -// label for the config partition (same as partition CSV file) -#define SPIFFS_PARTITION_LABEL "config" - static const char *TAG = "Config"; typedef enum ConfigIoType diff --git a/targets/ESP32/_common/targetHAL_FileOperation.cpp b/targets/ESP32/_common/targetHAL_FileOperation.cpp new file mode 100644 index 0000000000..9cfb3bddad --- /dev/null +++ b/targets/ESP32/_common/targetHAL_FileOperation.cpp @@ -0,0 +1,70 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +#include +#include +#include +#include + +void CombinePathAndName(char *outpath, const char *path1, const char *path2) +{ + strcat(outpath, path1); + + // Add "\" to path if required + if (outpath[hal_strlen_s(outpath) - 1] != '\\') + { + strcat(outpath, "\\"); + } + strcat(outpath, path2); +} + +// +// Converts from windows type path "c:\folder\folder\file.ext" +// to linux type path used in ESP32 VFS "/c/folder/folder/file.exe +// where /c is the mount point +//////////////////////////////////////////// +// MAKE SURE TO FREE THE RETURNED POINTER // +//////////////////////////////////////////// +// +char *ConvertToVfsPath(const char *filepath) +{ + char *startPath = NULL; + char *path = NULL; + + int pathlen = hal_strlen_s(filepath); + + ///////////////////////////////// + // MAKE SURE TO FREE THIS POINTER + startPath = (char *)platform_malloc(pathlen + 1); + + // sanity check for successfull malloc + if (startPath == NULL) + { + // failed to allocate memory + return NULL; + } + + path = startPath; + hal_strcpy_s(path, pathlen + 1, filepath); + + if (hal_strlen_s(path) >= 2) + { + // Map Drive: -> /C + char drive = *path; + *path++ = '/'; + *path++ = drive; + + // Convert '\' to '/' + while (*path) + { + if (*path == '\\') + *path++ = '/'; + else + path++; + } + } + + return startPath; +} \ No newline at end of file diff --git a/targets/ESP32/_common/targetHAL_StorageOperation.cpp b/targets/ESP32/_common/targetHAL_StorageOperation.cpp new file mode 100644 index 0000000000..48439cf907 --- /dev/null +++ b/targets/ESP32/_common/targetHAL_StorageOperation.cpp @@ -0,0 +1,64 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +#include +#include +#include +#include +#include "esp32_idf.h" +#include +#include +#include + +// Ensure Storage is initialized +void EnsureStorageInitialized() +{ + if (!esp_spiffs_mounted(SPIFFS_PARTITION_LABEL)) + { + ConfigStorage_Initialise(); + } +} + +void HAL_StorageOperation(uint8_t operation, uint32_t *length, uint8_t *storageName, uint8_t *data, uint32_t *errorCode) +{ + EnsureStorageInitialized(); + + // reset error code + *errorCode = (uint32_t)(StorageOperationErrorCodes::NoError); + size_t result; + + // convert storageName to char* + char *storageNameChar = ConvertToVfsPath(reinterpret_cast(storageName)); + + CLR_Debug::Printf("StorageOperation: %s", storageNameChar); + + if (operation == (uint8_t)(StorageOperation_Monitor::StorageOperation_Write)) + { + // Open the file in read mode + FILE *file = fopen(storageNameChar, "w"); + + // append more data + result = fwrite((const void *)data, 1, (size_t)length, file); + fclose(file); + + if (result != (size_t)length) + { + *errorCode = (uint32_t)(StorageOperationErrorCodes::WriteError); + } + } + else if (operation == (uint8_t)(StorageOperation_Monitor::StorageOperation_Delete)) + { + result = remove(storageNameChar); + if (result != 0) + { + *errorCode = (uint32_t)(StorageOperationErrorCodes::DeleteError); + } + } + + if (storageNameChar != NULL) + { + platform_free(storageNameChar); + } +} \ No newline at end of file diff --git a/targets/ESP32/_include/targetHAL_ConfigStorage.h b/targets/ESP32/_include/targetHAL_ConfigStorage.h index 194148588d..85d4feb1c4 100644 --- a/targets/ESP32/_include/targetHAL_ConfigStorage.h +++ b/targets/ESP32/_include/targetHAL_ConfigStorage.h @@ -6,6 +6,9 @@ #include #include +// label for the config partition (same as partition CSV file) +#define SPIFFS_PARTITION_LABEL "config" + #ifdef __cplusplus extern "C" { diff --git a/targets/ESP32/_include/targetHAL_FileOperation.h b/targets/ESP32/_include/targetHAL_FileOperation.h new file mode 100644 index 0000000000..41f68dc752 --- /dev/null +++ b/targets/ESP32/_include/targetHAL_FileOperation.h @@ -0,0 +1,19 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +#ifndef TARGET_PAL_FILE_OPERATION_H +#define TARGET_PAL_FILE_OPERATION_H + +#ifdef __cplusplus +extern "C" +{ +#endif + void CombinePathAndName(char *outpath, const char *path1, const char *path2); + char *ConvertToVfsPath(const char *filepath); +#ifdef __cplusplus +} +#endif + +#endif // TARGET_PAL_FILE_OPERATION_H \ No newline at end of file diff --git a/targets/ESP32/_include/targetHAL_StorageOperation.h b/targets/ESP32/_include/targetHAL_StorageOperation.h new file mode 100644 index 0000000000..92a800d6d1 --- /dev/null +++ b/targets/ESP32/_include/targetHAL_StorageOperation.h @@ -0,0 +1,14 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +#ifndef TARGET_PAL_STORAGE_OPERATION_H +#define TARGET_PAL_STORAGE_OPERATION_H + +#include +#include +#include +#include + +#endif // TARGET_PAL_STORAGE_OPERATION_H \ No newline at end of file diff --git a/targets/ESP32/_nanoCLR/System.IO.FileSystem/nf_sys_io_filesystem_System_IO_Directory.cpp b/targets/ESP32/_nanoCLR/System.IO.FileSystem/nf_sys_io_filesystem_System_IO_Directory.cpp index 6243ac120f..177491bb0e 100644 --- a/targets/ESP32/_nanoCLR/System.IO.FileSystem/nf_sys_io_filesystem_System_IO_Directory.cpp +++ b/targets/ESP32/_nanoCLR/System.IO.FileSystem/nf_sys_io_filesystem_System_IO_Directory.cpp @@ -6,9 +6,8 @@ #include "nf_sys_io_filesystem.h" #include #include +#include -extern void CombinePathAndName(char *outpath, const char *path1, const char *path2); -extern char *ConvertToVfsPath(const char *filepath); extern SYSTEMTIME GetDateTimeFromStat(time_t *time); // We will use this to extract the file extension diff --git a/targets/ESP32/_nanoCLR/System.IO.FileSystem/nf_sys_io_filesystem_System_IO_File.cpp b/targets/ESP32/_nanoCLR/System.IO.FileSystem/nf_sys_io_filesystem_System_IO_File.cpp index 4894329ab4..a9b2ecbcd9 100644 --- a/targets/ESP32/_nanoCLR/System.IO.FileSystem/nf_sys_io_filesystem_System_IO_File.cpp +++ b/targets/ESP32/_nanoCLR/System.IO.FileSystem/nf_sys_io_filesystem_System_IO_File.cpp @@ -7,9 +7,7 @@ #include #include - -extern void CombinePathAndName(char *outpath, const char *path1, const char *path2); -extern char *ConvertToVfsPath(const char *filepath); +#include bool IsInternalFilePath(const char *filePath) { diff --git a/targets/ESP32/_nanoCLR/System.IO.FileSystem/nf_sys_io_filesystem_System_IO_FileStream.cpp b/targets/ESP32/_nanoCLR/System.IO.FileSystem/nf_sys_io_filesystem_System_IO_FileStream.cpp index 894d2cff12..e76c480625 100644 --- a/targets/ESP32/_nanoCLR/System.IO.FileSystem/nf_sys_io_filesystem_System_IO_FileStream.cpp +++ b/targets/ESP32/_nanoCLR/System.IO.FileSystem/nf_sys_io_filesystem_System_IO_FileStream.cpp @@ -7,67 +7,7 @@ #include #include - -void CombinePathAndName(char *outpath, const char *path1, const char *path2) -{ - strcat(outpath, path1); - - // Add "\" to path if required - if (outpath[hal_strlen_s(outpath) - 1] != '\\') - { - strcat(outpath, "\\"); - } - strcat(outpath, path2); -} - -// -// Converts from windows type path "c:\folder\folder\file.ext" -// to linux type path used in ESP32 VFS "/c/folder/folder/file.exe -// where /c is the mount point -//////////////////////////////////////////// -// MAKE SURE TO FREE THE RETURNED POINTER // -//////////////////////////////////////////// -// -char *ConvertToVfsPath(const char *filepath) -{ - char *startPath = NULL; - char *path = NULL; - - int pathlen = hal_strlen_s(filepath); - - ///////////////////////////////// - // MAKE SURE TO FREE THIS POINTER - startPath = (char *)platform_malloc(pathlen + 1); - - // sanity check for successful malloc - if (startPath == NULL) - { - // failed to allocate memory - return NULL; - } - - path = startPath; - hal_strcpy_s(path, pathlen + 1, filepath); - - if (hal_strlen_s(path) >= 2) - { - // Map Drive: -> /C - char drive = *path; - *path++ = '/'; - *path++ = drive; - - // Convert '\' to '/' - while (*path) - { - if (*path == '\\') - *path++ = '/'; - else - path++; - } - } - - return startPath; -} +#include HRESULT Library_nf_sys_io_filesystem_System_IO_FileStream::OpenFileNative___VOID__STRING__STRING__I4( CLR_RT_StackFrame &stack) diff --git a/targets/ESP32/_nanoCLR/targetHAL.cpp b/targets/ESP32/_nanoCLR/targetHAL.cpp index 317df98cd3..f3ef08340c 100644 --- a/targets/ESP32/_nanoCLR/targetHAL.cpp +++ b/targets/ESP32/_nanoCLR/targetHAL.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include void Storage_Initialize(); diff --git a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoBooter/main.c b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoBooter/main.c index 131558f52f..c7a4e703c4 100644 --- a/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoBooter/main.c +++ b/targets/FreeRTOS/NXP/NXP_MIMXRT1060_EVK/nanoBooter/main.c @@ -17,6 +17,7 @@ #include #include #include "nanoHAL_ConfigurationManager.h" +#include "nanoHAL_StorageOperation.h" #include "Target_BlockStorage_iMXRTFlashDriver.h" #include diff --git a/targets/FreeRTOS/NXP/_common/CMakeLists.txt b/targets/FreeRTOS/NXP/_common/CMakeLists.txt index 1bbb9b54f8..5454b31a4d 100644 --- a/targets/FreeRTOS/NXP/_common/CMakeLists.txt +++ b/targets/FreeRTOS/NXP/_common/CMakeLists.txt @@ -75,6 +75,11 @@ if(NF_FEATURE_HAS_CONFIG_BLOCK) list(APPEND TARGET_NXP_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/targetHAL_ConfigurationManager.cpp) endif() +# include internal storage, if feature is enabled +if(NF_FEATURE_HAS_INTERNAL_STORAGE) + list(APPEND TARGET_NXP_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/targetHAL_StorageOperation.cpp) +endif() + # make var global set(TARGET_NXP_COMMON_SOURCES ${TARGET_NXP_COMMON_SOURCES} CACHE INTERNAL "make global") set(TARGET_NXP_COMMON_INCLUDE_DIRS ${TARGET_NXP_COMMON_INCLUDE_DIRS} CACHE INTERNAL "make global") diff --git a/targets/FreeRTOS/NXP/_nanoCLR/targetHAL.cpp b/targets/FreeRTOS/NXP/_nanoCLR/targetHAL.cpp index 6fc1eb748e..02d9ca47b5 100644 --- a/targets/FreeRTOS/NXP/_nanoCLR/targetHAL.cpp +++ b/targets/FreeRTOS/NXP/_nanoCLR/targetHAL.cpp @@ -9,6 +9,7 @@ #include #include #include +#include // // Reboot handlers clean up on reboot diff --git a/targets/TI_SimpleLink/_nanoCLR/targetHAL.cpp b/targets/TI_SimpleLink/_nanoCLR/targetHAL.cpp index 5133a4baa1..1e93be609a 100644 --- a/targets/TI_SimpleLink/_nanoCLR/targetHAL.cpp +++ b/targets/TI_SimpleLink/_nanoCLR/targetHAL.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include From ad508243f171c905fc89e171d1e3ffdb4947ce81 Mon Sep 17 00:00:00 2001 From: Laurent Ellerbach Date: Mon, 11 Mar 2024 21:17:11 +0000 Subject: [PATCH 03/18] working version --- src/CLR/Debugger/Debugger.cpp | 7 ++-- src/CLR/Debugger/Debugger_full.cpp | 1 + src/CLR/Debugger/Debugger_minimal.cpp | 1 + .../Include/WireProtocol_MonitorCommands.h | 9 +++-- .../WireProtocol_MonitorCommands.c | 4 +- src/HAL/Include/nanoHAL_StorageOperation.h | 4 +- .../_common/targetHAL_StorageOperation.cpp | 39 ++++++++++++++++--- 7 files changed, 48 insertions(+), 17 deletions(-) diff --git a/src/CLR/Debugger/Debugger.cpp b/src/CLR/Debugger/Debugger.cpp index a3a6756aa5..e51b859d21 100644 --- a/src/CLR/Debugger/Debugger.cpp +++ b/src/CLR/Debugger/Debugger.cpp @@ -12,6 +12,7 @@ #include "Debugger.h" #include #include +#include #define __min(a, b) (((a) < (b)) ? (a) : (b)) @@ -1338,14 +1339,14 @@ bool CLR_DBG_Debugger::Monitor_UpdateConfiguration(WP_Message *message) bool CLR_DBG_Debugger::Monitor_StorageOperation(WP_Message *message) { NATIVE_PROFILE_CLR_DEBUGGER(); - debug_printf("Monitor_StorageOperation"); + #if (HAS_INTERNAL_STORAGE == TRUE) Monitor_StorageOperation_Command *cmd = (Monitor_StorageOperation_Command *)message->m_payload; Monitor_StorageOperation_Reply cmdReply; - uint8_t err = 0; + uint32_t err = 0; - //HAL_StorageOperation(cmd->Operation, cmd->Length, cmd->StorageName, cmd->Data, &err); + HAL_StorageOperation(cmd->Operation, cmd->NameLength, cmd->DataLength, cmd->Data, &err); cmdReply.ErrorCode = err; WP_ReplyToCommand(message, true, false, &cmdReply, sizeof(cmdReply)); diff --git a/src/CLR/Debugger/Debugger_full.cpp b/src/CLR/Debugger/Debugger_full.cpp index 1c7236d34a..6b43fa8892 100644 --- a/src/CLR/Debugger/Debugger_full.cpp +++ b/src/CLR/Debugger/Debugger_full.cpp @@ -28,6 +28,7 @@ const CLR_Messaging_CommandHandlerLookup c_Debugger_Lookup_Request[] = { DEFINE_CMD2(EraseMemory), DEFINE_CMD2(QueryConfiguration), DEFINE_CMD2(UpdateConfiguration), + DEFINE_CMD2(StorageOperation), // DEFINE_CMD2(Execute), DEFINE_CMD2(Reboot), diff --git a/src/CLR/Debugger/Debugger_minimal.cpp b/src/CLR/Debugger/Debugger_minimal.cpp index 8de4a0d9f4..fdba18653f 100644 --- a/src/CLR/Debugger/Debugger_minimal.cpp +++ b/src/CLR/Debugger/Debugger_minimal.cpp @@ -27,6 +27,7 @@ const CLR_Messaging_CommandHandlerLookup c_Debugger_Lookup_Request[] = { DEFINE_CMD2(EraseMemory), DEFINE_CMD2(QueryConfiguration), DEFINE_CMD2(UpdateConfiguration), + DEFINE_CMD2(StorageOperation), // DEFINE_CMD2(Execute), DEFINE_CMD2(Reboot), diff --git a/src/CLR/Include/WireProtocol_MonitorCommands.h b/src/CLR/Include/WireProtocol_MonitorCommands.h index b396163990..25dcf36015 100644 --- a/src/CLR/Include/WireProtocol_MonitorCommands.h +++ b/src/CLR/Include/WireProtocol_MonitorCommands.h @@ -64,7 +64,8 @@ typedef enum StorageOperation_Monitor { StorageOperation_None = 0, StorageOperation_Write = 1, - StorageOperation_Delete = 2 + StorageOperation_Delete = 2, + StorageOperation_Append = 3 } StorageOperation_Monitor; ////////////////////////////////////////// @@ -177,9 +178,9 @@ typedef struct __nfpack Monitor_UpdateConfiguration_Command typedef struct Monitor_StorageOperation_Command { - uint8_t Operation; - uint32_t Length; - uint8_t StorageName[128]; + uint32_t Operation; + uint32_t NameLength; + uint32_t DataLength; uint8_t Data[1]; } Monitor_StorageOperation_Command; diff --git a/src/CLR/WireProtocol/WireProtocol_MonitorCommands.c b/src/CLR/WireProtocol/WireProtocol_MonitorCommands.c index 6e502dbbe6..eb6dcbb64b 100644 --- a/src/CLR/WireProtocol/WireProtocol_MonitorCommands.c +++ b/src/CLR/WireProtocol/WireProtocol_MonitorCommands.c @@ -262,9 +262,9 @@ int Monitor_StorageOperation(WP_Message *message) Monitor_StorageOperation_Reply cmdReply; uint8_t err = 0; - HAL_StorageOperation(cmd->Operation, cmd->Length, cmd->StorageName, cmd->Data, &err); + HAL_StorageOperation(cmd->Operation, cmd->NameLength, cmd->DataLength, cmd->Data, &err); cmdReply.ErrorCode = err; - + WP_ReplyToCommand(message, true, false, &cmdReply, sizeof(cmdReply)); return true; diff --git a/src/HAL/Include/nanoHAL_StorageOperation.h b/src/HAL/Include/nanoHAL_StorageOperation.h index 02573b1d89..8e3a53da9a 100644 --- a/src/HAL/Include/nanoHAL_StorageOperation.h +++ b/src/HAL/Include/nanoHAL_StorageOperation.h @@ -15,8 +15,8 @@ extern "C" void HAL_StorageOperation( uint8_t operation, - uint32_t *length, - uint8_t *storageName, + uint32_t nameLength, + uint32_t dataLength, uint8_t *data, uint32_t *errorCode); diff --git a/targets/ESP32/_common/targetHAL_StorageOperation.cpp b/targets/ESP32/_common/targetHAL_StorageOperation.cpp index 48439cf907..86ef3b43a2 100644 --- a/targets/ESP32/_common/targetHAL_StorageOperation.cpp +++ b/targets/ESP32/_common/targetHAL_StorageOperation.cpp @@ -21,8 +21,8 @@ void EnsureStorageInitialized() } } -void HAL_StorageOperation(uint8_t operation, uint32_t *length, uint8_t *storageName, uint8_t *data, uint32_t *errorCode) -{ +void HAL_StorageOperation(uint8_t operation, uint32_t nameLength, uint32_t dataLength, uint8_t *data, uint32_t *errorCode) +{ EnsureStorageInitialized(); // reset error code @@ -30,20 +30,47 @@ void HAL_StorageOperation(uint8_t operation, uint32_t *length, uint8_t *storageN size_t result; // convert storageName to char* - char *storageNameChar = ConvertToVfsPath(reinterpret_cast(storageName)); + char* strName = (char *)platform_malloc(nameLength + 1); + for(uint32_t i = 0; i < nameLength; i++) + { + strName[i] = static_cast(data[i]); + } + + // Just making sure it's properly 0 terminated + strName[nameLength] = '\0'; - CLR_Debug::Printf("StorageOperation: %s", storageNameChar); + char *storageNameChar = ConvertToVfsPath(strName); + + // Cleaning the temporary name buffer + platform_free(strName); if (operation == (uint8_t)(StorageOperation_Monitor::StorageOperation_Write)) { + // Remove the file if already exists + remove(storageNameChar); + // Open the file in read mode FILE *file = fopen(storageNameChar, "w"); // append more data - result = fwrite((const void *)data, 1, (size_t)length, file); + result = fwrite((const void *)(data + nameLength), 1, (size_t)dataLength, file); + fclose(file); + + if (result != (size_t)dataLength) + { + *errorCode = (uint32_t)(StorageOperationErrorCodes::WriteError); + } + } + else if(operation == (uint8_t)(StorageOperation_Monitor::StorageOperation_Append)) + { + // Open the file in read mode + FILE *file = fopen(storageNameChar, "a"); + fseek(file, 0, SEEK_END); + // append more data + result = fwrite((const void *)(data + nameLength), 1, (size_t)dataLength, file); fclose(file); - if (result != (size_t)length) + if (result != (size_t)dataLength) { *errorCode = (uint32_t)(StorageOperationErrorCodes::WriteError); } From f88754c57c0cceb1bc9ae64fb58059a998635b34 Mon Sep 17 00:00:00 2001 From: nfbot Date: Tue, 12 Mar 2024 14:12:15 +0000 Subject: [PATCH 04/18] Code style fixes for nanoframework/nf-interpreter PR#2901 (#2902) --- src/CLR/Debugger/Debugger.cpp | 2 +- src/CLR/Debugger/Debugger.h | 166 +++++++++++++++++----------------- 2 files changed, 86 insertions(+), 82 deletions(-) diff --git a/src/CLR/Debugger/Debugger.cpp b/src/CLR/Debugger/Debugger.cpp index e51b859d21..428fa0bf9c 100644 --- a/src/CLR/Debugger/Debugger.cpp +++ b/src/CLR/Debugger/Debugger.cpp @@ -1348,7 +1348,7 @@ bool CLR_DBG_Debugger::Monitor_StorageOperation(WP_Message *message) HAL_StorageOperation(cmd->Operation, cmd->NameLength, cmd->DataLength, cmd->Data, &err); cmdReply.ErrorCode = err; - + WP_ReplyToCommand(message, true, false, &cmdReply, sizeof(cmdReply)); return true; diff --git a/src/CLR/Debugger/Debugger.h b/src/CLR/Debugger/Debugger.h index 44ba64649c..66b326465b 100644 --- a/src/CLR/Debugger/Debugger.h +++ b/src/CLR/Debugger/Debugger.h @@ -11,79 +11,82 @@ // backwards compatible with .NETMF typedef enum CLR_DBG_Commands_Debugging { - CLR_DBG_Commands_c_Debugging_Execution_BasePtr = 0x00020000, // Returns the pointer for the ExecutionEngine object. - CLR_DBG_Commands_c_Debugging_Execution_ChangeConditions = 0x00020001, // Sets/resets the state of the debugger. - CLR_DBG_Commands_c_Debugging_Execution_SecurityKey = 0x00020002, // Sets security key. - CLR_DBG_Commands_c_Debugging_Execution_Unlock = 0x00020003, // Unlock the low-level command, for mfg. test programs. - CLR_DBG_Commands_c_Debugging_Execution_Allocate = 0x00020004, // Permanently allocate some memory. - CLR_DBG_Commands_c_Debugging_Execution_Breakpoints = 0x00020005, // Sets breakpoints. - CLR_DBG_Commands_c_Debugging_Execution_BreakpointHit = 0x00020006, // Notification that a breakpoint was hit. - CLR_DBG_Commands_c_Debugging_Execution_BreakpointStatus = 0x00020007, // Queries last breakpoint hit. + CLR_DBG_Commands_c_Debugging_Execution_BasePtr = 0x00020000, // Returns the pointer for the ExecutionEngine object. + CLR_DBG_Commands_c_Debugging_Execution_ChangeConditions = 0x00020001, // Sets/resets the state of the debugger. + CLR_DBG_Commands_c_Debugging_Execution_SecurityKey = 0x00020002, // Sets security key. + CLR_DBG_Commands_c_Debugging_Execution_Unlock = 0x00020003, // Unlock the low-level command, for mfg. test programs. + CLR_DBG_Commands_c_Debugging_Execution_Allocate = 0x00020004, // Permanently allocate some memory. + CLR_DBG_Commands_c_Debugging_Execution_Breakpoints = 0x00020005, // Sets breakpoints. + CLR_DBG_Commands_c_Debugging_Execution_BreakpointHit = 0x00020006, // Notification that a breakpoint was hit. + CLR_DBG_Commands_c_Debugging_Execution_BreakpointStatus = 0x00020007, // Queries last breakpoint hit. CLR_DBG_Commands_c_Debugging_Execution_QueryCLRCapabilities = 0x00020008, // Queries capabilities of the CLR. - CLR_DBG_Commands_c_Debugging_Execution_SetCurrentAppDomain = 0x00020009, // Sets the current AppDomain. This is required before - // performing certain debugging operations, such as - // accessing a static field, or doing function evaluation, - - CLR_DBG_Commands_c_Debugging_Thread_Create = 0x00020010, // OBSOLETE - Use c_Debugging_Thread_CreateEx instead. - CLR_DBG_Commands_c_Debugging_Thread_List = 0x00020011, // Lists the active/waiting threads. - CLR_DBG_Commands_c_Debugging_Thread_Stack = 0x00020012, // Lists the call stack for a thread. - CLR_DBG_Commands_c_Debugging_Thread_Kill = 0x00020013, // Kills a thread. - CLR_DBG_Commands_c_Debugging_Thread_Suspend = 0x00020014, // Suspends the execution of a thread. - CLR_DBG_Commands_c_Debugging_Thread_Resume = 0x00020015, // Resumes the execution of a thread. - CLR_DBG_Commands_c_Debugging_Thread_GetException = 0x00020016, // Gets the current exception. - CLR_DBG_Commands_c_Debugging_Thread_Unwind = 0x00020017, // Unwinds to given stack frame. - CLR_DBG_Commands_c_Debugging_Thread_CreateEx = 0x00020018, // Creates a new thread but Thread.CurrentThread will return the identity of the passed thread. - CLR_DBG_Commands_c_Debugging_Thread_Get = 0x00021000, // Gets the current thread. - - CLR_DBG_Commands_c_Debugging_Stack_Info = 0x00020020, // Gets more info on a stack frame. - CLR_DBG_Commands_c_Debugging_Stack_SetIP = 0x00020021, // Sets the IP on a given thread. - - CLR_DBG_Commands_c_Debugging_Value_ResizeScratchPad = 0x00020030, // Resizes the scratchpad area. - CLR_DBG_Commands_c_Debugging_Value_GetStack = 0x00020031, // Reads a value from the stack frame. - CLR_DBG_Commands_c_Debugging_Value_GetField = 0x00020032, // Reads a value from an object's field. - CLR_DBG_Commands_c_Debugging_Value_GetArray = 0x00020033, // Reads a value from an array's element. - CLR_DBG_Commands_c_Debugging_Value_GetBlock = 0x00020034, // Reads a value from a heap block. - CLR_DBG_Commands_c_Debugging_Value_GetScratchPad = 0x00020035, // Reads a value from the scratchpad area. - CLR_DBG_Commands_c_Debugging_Value_SetBlock = 0x00020036, // Writes a value to a heap block. - CLR_DBG_Commands_c_Debugging_Value_SetArray = 0x00020037, // Writes a value to an array's element. - CLR_DBG_Commands_c_Debugging_Value_AllocateObject = 0x00020038, // Creates a new instance of an object. - CLR_DBG_Commands_c_Debugging_Value_AllocateString = 0x00020039, // Creates a new instance of a string. - CLR_DBG_Commands_c_Debugging_Value_AllocateArray = 0x0002003A, // Creates a new instance of an array. - CLR_DBG_Commands_c_Debugging_Value_Assign = 0x0002003B, // Assigns a value to another value. - - CLR_DBG_Commands_c_Debugging_TypeSys_Assemblies = 0x00020040, // Lists all the assemblies in the system. - CLR_DBG_Commands_c_Debugging_TypeSys_AppDomains = 0x00020044, // Lists all the AppDomans loaded. - - CLR_DBG_Commands_c_Debugging_Resolve_Assembly = 0x00020050, // Resolves an assembly. - CLR_DBG_Commands_c_Debugging_Resolve_Type = 0x00020051, // Resolves a type to a string. - CLR_DBG_Commands_c_Debugging_Resolve_Field = 0x00020052, // Resolves a field to a string. - CLR_DBG_Commands_c_Debugging_Resolve_Method = 0x00020053, // Resolves a method to a string. - CLR_DBG_Commands_c_Debugging_Resolve_VirtualMethod = 0x00020054, // Resolves a virtual method to the actual implementation. - CLR_DBG_Commands_c_Debugging_Resolve_AppDomain = 0x00020055, // Resolves an AppDomain to it's name, and list its loaded assemblies. - - - CLR_DBG_Commands_c_Debugging_MFUpdate_Start = 0x00020056, // - CLR_DBG_Commands_c_Debugging_MFUpdate_AddPacket = 0x00020057, // - CLR_DBG_Commands_c_Debugging_MFUpdate_Install = 0x00020058, // - CLR_DBG_Commands_c_Debugging_MFUpdate_AuthCommand = 0x00020059, // - CLR_DBG_Commands_c_Debugging_MFUpdate_Authenticate = 0x00020060, // - CLR_DBG_Commands_c_Debugging_MFUpdate_GetMissingPkts = 0x00020061, // - - CLR_DBG_Commands_c_Debugging_UpgradeToSsl = 0x00020069, // - - //--// - - CLR_DBG_Commands_c_Debugging_Button_Report = 0x00020080, // Reports a button press/release. - CLR_DBG_Commands_c_Debugging_Button_Inject = 0x00020081, // Injects a button press/release. - - CLR_DBG_Commands_c_Debugging_Deployment_Status = 0x000200B0, // Returns entryPoint and boundary of deployment area. - - CLR_DBG_Commands_c_Debugging_Info_SetJMC = 0x000200C0, // Sets code to be flagged as JMC (Just my code). - - CLR_DBG_Commands_c_Profiling_Command = 0x00030000, // Various incoming commands regarding profiling - CLR_DBG_Commands_c_Profiling_Stream = 0x00030001, // Stream for MFProfiler information. - -}CLR_DBG_Commands_Debugging; + CLR_DBG_Commands_c_Debugging_Execution_SetCurrentAppDomain = + 0x00020009, // Sets the current AppDomain. This is required before + // performing certain debugging operations, such as + // accessing a static field, or doing function evaluation, + + CLR_DBG_Commands_c_Debugging_Thread_Create = 0x00020010, // OBSOLETE - Use c_Debugging_Thread_CreateEx instead. + CLR_DBG_Commands_c_Debugging_Thread_List = 0x00020011, // Lists the active/waiting threads. + CLR_DBG_Commands_c_Debugging_Thread_Stack = 0x00020012, // Lists the call stack for a thread. + CLR_DBG_Commands_c_Debugging_Thread_Kill = 0x00020013, // Kills a thread. + CLR_DBG_Commands_c_Debugging_Thread_Suspend = 0x00020014, // Suspends the execution of a thread. + CLR_DBG_Commands_c_Debugging_Thread_Resume = 0x00020015, // Resumes the execution of a thread. + CLR_DBG_Commands_c_Debugging_Thread_GetException = 0x00020016, // Gets the current exception. + CLR_DBG_Commands_c_Debugging_Thread_Unwind = 0x00020017, // Unwinds to given stack frame. + CLR_DBG_Commands_c_Debugging_Thread_CreateEx = + 0x00020018, // Creates a new thread but Thread.CurrentThread will return the identity of the passed thread. + CLR_DBG_Commands_c_Debugging_Thread_Get = 0x00021000, // Gets the current thread. + + CLR_DBG_Commands_c_Debugging_Stack_Info = 0x00020020, // Gets more info on a stack frame. + CLR_DBG_Commands_c_Debugging_Stack_SetIP = 0x00020021, // Sets the IP on a given thread. + + CLR_DBG_Commands_c_Debugging_Value_ResizeScratchPad = 0x00020030, // Resizes the scratchpad area. + CLR_DBG_Commands_c_Debugging_Value_GetStack = 0x00020031, // Reads a value from the stack frame. + CLR_DBG_Commands_c_Debugging_Value_GetField = 0x00020032, // Reads a value from an object's field. + CLR_DBG_Commands_c_Debugging_Value_GetArray = 0x00020033, // Reads a value from an array's element. + CLR_DBG_Commands_c_Debugging_Value_GetBlock = 0x00020034, // Reads a value from a heap block. + CLR_DBG_Commands_c_Debugging_Value_GetScratchPad = 0x00020035, // Reads a value from the scratchpad area. + CLR_DBG_Commands_c_Debugging_Value_SetBlock = 0x00020036, // Writes a value to a heap block. + CLR_DBG_Commands_c_Debugging_Value_SetArray = 0x00020037, // Writes a value to an array's element. + CLR_DBG_Commands_c_Debugging_Value_AllocateObject = 0x00020038, // Creates a new instance of an object. + CLR_DBG_Commands_c_Debugging_Value_AllocateString = 0x00020039, // Creates a new instance of a string. + CLR_DBG_Commands_c_Debugging_Value_AllocateArray = 0x0002003A, // Creates a new instance of an array. + CLR_DBG_Commands_c_Debugging_Value_Assign = 0x0002003B, // Assigns a value to another value. + + CLR_DBG_Commands_c_Debugging_TypeSys_Assemblies = 0x00020040, // Lists all the assemblies in the system. + CLR_DBG_Commands_c_Debugging_TypeSys_AppDomains = 0x00020044, // Lists all the AppDomans loaded. + + CLR_DBG_Commands_c_Debugging_Resolve_Assembly = 0x00020050, // Resolves an assembly. + CLR_DBG_Commands_c_Debugging_Resolve_Type = 0x00020051, // Resolves a type to a string. + CLR_DBG_Commands_c_Debugging_Resolve_Field = 0x00020052, // Resolves a field to a string. + CLR_DBG_Commands_c_Debugging_Resolve_Method = 0x00020053, // Resolves a method to a string. + CLR_DBG_Commands_c_Debugging_Resolve_VirtualMethod = + 0x00020054, // Resolves a virtual method to the actual implementation. + CLR_DBG_Commands_c_Debugging_Resolve_AppDomain = + 0x00020055, // Resolves an AppDomain to it's name, and list its loaded assemblies. + + CLR_DBG_Commands_c_Debugging_MFUpdate_Start = 0x00020056, // + CLR_DBG_Commands_c_Debugging_MFUpdate_AddPacket = 0x00020057, // + CLR_DBG_Commands_c_Debugging_MFUpdate_Install = 0x00020058, // + CLR_DBG_Commands_c_Debugging_MFUpdate_AuthCommand = 0x00020059, // + CLR_DBG_Commands_c_Debugging_MFUpdate_Authenticate = 0x00020060, // + CLR_DBG_Commands_c_Debugging_MFUpdate_GetMissingPkts = 0x00020061, // + + CLR_DBG_Commands_c_Debugging_UpgradeToSsl = 0x00020069, // + + //--// + + CLR_DBG_Commands_c_Debugging_Button_Report = 0x00020080, // Reports a button press/release. + CLR_DBG_Commands_c_Debugging_Button_Inject = 0x00020081, // Injects a button press/release. + + CLR_DBG_Commands_c_Debugging_Deployment_Status = 0x000200B0, // Returns entryPoint and boundary of deployment area. + + CLR_DBG_Commands_c_Debugging_Info_SetJMC = 0x000200C0, // Sets code to be flagged as JMC (Just my code). + + CLR_DBG_Commands_c_Profiling_Command = 0x00030000, // Various incoming commands regarding profiling + CLR_DBG_Commands_c_Profiling_Stream = 0x00030001, // Stream for MFProfiler information. + +} CLR_DBG_Commands_Debugging; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // !!! KEEP IN SYNC WITH nanoFramework.Tools.Debugger.WireProtocol.AccessMemoryErrorCodes (in managed code) !!! // @@ -91,22 +94,23 @@ typedef enum CLR_DBG_Commands_Debugging // enum with AccessMemoryErrorCodes typedef enum AccessMemoryErrorCodes { - AccessMemoryErrorCode_NoError = 0x0001, // no error - AccessMemoryErrorCode_PermissionDenied = 0x0010, // permission denied to execute operation - AccessMemoryErrorCode_FailedToAllocateReadBuffer = 0x0020, // failed to allocate buffer for read operation. better check heap - AccessMemoryErrorCode_RequestedOperationFailed = 0x0030, // the requested operation failed + AccessMemoryErrorCode_NoError = 0x0001, // no error + AccessMemoryErrorCode_PermissionDenied = 0x0010, // permission denied to execute operation + AccessMemoryErrorCode_FailedToAllocateReadBuffer = + 0x0020, // failed to allocate buffer for read operation. better check heap + AccessMemoryErrorCode_RequestedOperationFailed = 0x0030, // the requested operation failed -}AccessMemoryErrorCodes; +} AccessMemoryErrorCodes; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // !!! KEEP IN SYNC WITH nanoFramework.Tools.Debugger.WireProtocol.StorageOperationErrorCodes (in managed code) !!! // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// typedef enum StorageOperationErrorCodes { - NoError = 0x0001, // no error - WriteError = 0x0010, // write error + NoError = 0x0001, // no error + WriteError = 0x0010, // write error DeleteError = 0x0020, // delete error -}StorageOperationErrorCodes; +} StorageOperationErrorCodes; -#endif //DEBUGGER_H +#endif // DEBUGGER_H From bcfd804d89263dd44190a46856e00bb542121958 Mon Sep 17 00:00:00 2001 From: josesimoes Date: Wed, 20 Mar 2024 15:35:56 +0000 Subject: [PATCH 05/18] Rename StorageOperationErrorCode to follow managed one --- src/CLR/Debugger/Debugger.h | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/CLR/Debugger/Debugger.h b/src/CLR/Debugger/Debugger.h index 66b326465b..624b84a19d 100644 --- a/src/CLR/Debugger/Debugger.h +++ b/src/CLR/Debugger/Debugger.h @@ -102,15 +102,18 @@ typedef enum AccessMemoryErrorCodes } AccessMemoryErrorCodes; -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -// !!! KEEP IN SYNC WITH nanoFramework.Tools.Debugger.WireProtocol.StorageOperationErrorCodes (in managed code) !!! // -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -typedef enum StorageOperationErrorCodes +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// !!! KEEP IN SYNC WITH nanoFramework.Tools.Debugger.WireProtocol.StorageOperationErrorCode (in managed code) !!! // +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +typedef enum StorageOperationErrorCode { - NoError = 0x0001, // no error - WriteError = 0x0010, // write error - DeleteError = 0x0020, // delete error - -} StorageOperationErrorCodes; + // no error + NoError = 0x0001, + // write error + WriteError = 0x0010, + // delete error + DeleteError = 0x0020, + +} StorageOperationErrorCode; #endif // DEBUGGER_H From 9c429950295d8c0cb438596c992c21177550cbed Mon Sep 17 00:00:00 2001 From: josesimoes Date: Wed, 20 Mar 2024 15:36:10 +0000 Subject: [PATCH 06/18] Code style formatting --- .../_common/targetHAL_StorageOperation.cpp | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/targets/ESP32/_common/targetHAL_StorageOperation.cpp b/targets/ESP32/_common/targetHAL_StorageOperation.cpp index 86ef3b43a2..ace4c2df80 100644 --- a/targets/ESP32/_common/targetHAL_StorageOperation.cpp +++ b/targets/ESP32/_common/targetHAL_StorageOperation.cpp @@ -21,17 +21,22 @@ void EnsureStorageInitialized() } } -void HAL_StorageOperation(uint8_t operation, uint32_t nameLength, uint32_t dataLength, uint8_t *data, uint32_t *errorCode) -{ +void HAL_StorageOperation( + uint8_t operation, + uint32_t nameLength, + uint32_t dataLength, + uint8_t *data, + uint32_t *errorCode) +{ EnsureStorageInitialized(); // reset error code - *errorCode = (uint32_t)(StorageOperationErrorCodes::NoError); + *errorCode = (uint32_t)(StorageOperationErrorCode::NoError); size_t result; // convert storageName to char* - char* strName = (char *)platform_malloc(nameLength + 1); - for(uint32_t i = 0; i < nameLength; i++) + char *strName = (char *)platform_malloc(nameLength + 1); + for (uint32_t i = 0; i < nameLength; i++) { strName[i] = static_cast(data[i]); } @@ -58,10 +63,10 @@ void HAL_StorageOperation(uint8_t operation, uint32_t nameLength, uint32_t dataL if (result != (size_t)dataLength) { - *errorCode = (uint32_t)(StorageOperationErrorCodes::WriteError); + *errorCode = (uint32_t)(StorageOperationErrorCode::WriteError); } } - else if(operation == (uint8_t)(StorageOperation_Monitor::StorageOperation_Append)) + else if (operation == (uint8_t)(StorageOperation_Monitor::StorageOperation_Append)) { // Open the file in read mode FILE *file = fopen(storageNameChar, "a"); @@ -72,7 +77,7 @@ void HAL_StorageOperation(uint8_t operation, uint32_t nameLength, uint32_t dataL if (result != (size_t)dataLength) { - *errorCode = (uint32_t)(StorageOperationErrorCodes::WriteError); + *errorCode = (uint32_t)(StorageOperationErrorCode::WriteError); } } else if (operation == (uint8_t)(StorageOperation_Monitor::StorageOperation_Delete)) @@ -80,7 +85,7 @@ void HAL_StorageOperation(uint8_t operation, uint32_t nameLength, uint32_t dataL result = remove(storageNameChar); if (result != 0) { - *errorCode = (uint32_t)(StorageOperationErrorCodes::DeleteError); + *errorCode = (uint32_t)(StorageOperationErrorCode::DeleteError); } } From 4e4c80f3e15fe63bb3b493986abaf7cb2841f2de Mon Sep 17 00:00:00 2001 From: josesimoes Date: Wed, 20 Mar 2024 15:55:45 +0000 Subject: [PATCH 07/18] Update declaration to match managed class --- src/CLR/Include/WireProtocol_MonitorCommands.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CLR/Include/WireProtocol_MonitorCommands.h b/src/CLR/Include/WireProtocol_MonitorCommands.h index 25dcf36015..92ebb64f7c 100644 --- a/src/CLR/Include/WireProtocol_MonitorCommands.h +++ b/src/CLR/Include/WireProtocol_MonitorCommands.h @@ -181,6 +181,7 @@ typedef struct Monitor_StorageOperation_Command uint32_t Operation; uint32_t NameLength; uint32_t DataLength; + uint32_t Offset; uint8_t Data[1]; } Monitor_StorageOperation_Command; From 0163672cb8cf3d250794831301af2764ad7517c6 Mon Sep 17 00:00:00 2001 From: josesimoes Date: Wed, 20 Mar 2024 15:56:52 +0000 Subject: [PATCH 08/18] HAL_StorageOperation now returns execution result on return type - Update code accordingly. --- src/CLR/Debugger/Debugger.cpp | 4 +--- .../WireProtocol_MonitorCommands.c | 4 +--- src/HAL/Include/nanoHAL_StorageOperation.h | 7 +++--- .../_common/targetHAL_StorageOperation.cpp | 23 +++++++++++-------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/CLR/Debugger/Debugger.cpp b/src/CLR/Debugger/Debugger.cpp index 428fa0bf9c..761b3814a4 100644 --- a/src/CLR/Debugger/Debugger.cpp +++ b/src/CLR/Debugger/Debugger.cpp @@ -1344,10 +1344,8 @@ bool CLR_DBG_Debugger::Monitor_StorageOperation(WP_Message *message) Monitor_StorageOperation_Command *cmd = (Monitor_StorageOperation_Command *)message->m_payload; Monitor_StorageOperation_Reply cmdReply; - uint32_t err = 0; - HAL_StorageOperation(cmd->Operation, cmd->NameLength, cmd->DataLength, cmd->Data, &err); - cmdReply.ErrorCode = err; + cmdReply.ErrorCode = HAL_StorageOperation(cmd->Operation, cmd->NameLength, cmd->DataLength, cmd->Offset, cmd->Data); WP_ReplyToCommand(message, true, false, &cmdReply, sizeof(cmdReply)); diff --git a/src/CLR/WireProtocol/WireProtocol_MonitorCommands.c b/src/CLR/WireProtocol/WireProtocol_MonitorCommands.c index eb6dcbb64b..e511e12236 100644 --- a/src/CLR/WireProtocol/WireProtocol_MonitorCommands.c +++ b/src/CLR/WireProtocol/WireProtocol_MonitorCommands.c @@ -260,10 +260,8 @@ int Monitor_StorageOperation(WP_Message *message) Monitor_StorageOperation_Command *cmd = (Monitor_StorageOperation_Command *)message->m_payload; Monitor_StorageOperation_Reply cmdReply; - uint8_t err = 0; - HAL_StorageOperation(cmd->Operation, cmd->NameLength, cmd->DataLength, cmd->Data, &err); - cmdReply.ErrorCode = err; + cmdReply.ErrorCode = HAL_StorageOperation(cmd->Operation, cmd->NameLength, cmd->DataLength, cmd->Offset, cmd->Data); WP_ReplyToCommand(message, true, false, &cmdReply, sizeof(cmdReply)); diff --git a/src/HAL/Include/nanoHAL_StorageOperation.h b/src/HAL/Include/nanoHAL_StorageOperation.h index 8e3a53da9a..9be109f780 100644 --- a/src/HAL/Include/nanoHAL_StorageOperation.h +++ b/src/HAL/Include/nanoHAL_StorageOperation.h @@ -6,6 +6,7 @@ #ifndef NANOHAL_STORAGE_OPERATION_H #define NANOHAL_STORAGE_OPERATION_H +#include #include #ifdef __cplusplus @@ -13,12 +14,12 @@ extern "C" { #endif - void HAL_StorageOperation( + uint32_t HAL_StorageOperation( uint8_t operation, uint32_t nameLength, uint32_t dataLength, - uint8_t *data, - uint32_t *errorCode); + uint32_t offset, + uint8_t *data); #ifdef __cplusplus } diff --git a/targets/ESP32/_common/targetHAL_StorageOperation.cpp b/targets/ESP32/_common/targetHAL_StorageOperation.cpp index ace4c2df80..4f3bdf2887 100644 --- a/targets/ESP32/_common/targetHAL_StorageOperation.cpp +++ b/targets/ESP32/_common/targetHAL_StorageOperation.cpp @@ -21,18 +21,19 @@ void EnsureStorageInitialized() } } -void HAL_StorageOperation( +uint32_t HAL_StorageOperation( uint8_t operation, uint32_t nameLength, uint32_t dataLength, - uint8_t *data, - uint32_t *errorCode) + uint32_t offset, + uint8_t *data) { - EnsureStorageInitialized(); + (void)offset; - // reset error code - *errorCode = (uint32_t)(StorageOperationErrorCode::NoError); size_t result; + StorageOperationErrorCode errorCode = StorageOperationErrorCode::NoError; + + EnsureStorageInitialized(); // convert storageName to char* char *strName = (char *)platform_malloc(nameLength + 1); @@ -63,7 +64,7 @@ void HAL_StorageOperation( if (result != (size_t)dataLength) { - *errorCode = (uint32_t)(StorageOperationErrorCode::WriteError); + errorCode = StorageOperationErrorCode::WriteError; } } else if (operation == (uint8_t)(StorageOperation_Monitor::StorageOperation_Append)) @@ -77,7 +78,7 @@ void HAL_StorageOperation( if (result != (size_t)dataLength) { - *errorCode = (uint32_t)(StorageOperationErrorCode::WriteError); + errorCode = StorageOperationErrorCode::WriteError; } } else if (operation == (uint8_t)(StorageOperation_Monitor::StorageOperation_Delete)) @@ -85,7 +86,7 @@ void HAL_StorageOperation( result = remove(storageNameChar); if (result != 0) { - *errorCode = (uint32_t)(StorageOperationErrorCode::DeleteError); + errorCode = StorageOperationErrorCode::DeleteError; } } @@ -93,4 +94,6 @@ void HAL_StorageOperation( { platform_free(storageNameChar); } -} \ No newline at end of file + + return errorCode; +} From aa39e72e0d3ae959fffe05a39957bfe410d2452e Mon Sep 17 00:00:00 2001 From: josesimoes Date: Wed, 20 Mar 2024 15:59:55 +0000 Subject: [PATCH 09/18] Add sanity check for malloc --- targets/ESP32/_common/targetHAL_StorageOperation.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/targets/ESP32/_common/targetHAL_StorageOperation.cpp b/targets/ESP32/_common/targetHAL_StorageOperation.cpp index 4f3bdf2887..6de75ba283 100644 --- a/targets/ESP32/_common/targetHAL_StorageOperation.cpp +++ b/targets/ESP32/_common/targetHAL_StorageOperation.cpp @@ -37,6 +37,13 @@ uint32_t HAL_StorageOperation( // convert storageName to char* char *strName = (char *)platform_malloc(nameLength + 1); + + // sanity check for successfull malloc + if (strName == NULL) + { + return StorageOperationErrorCode::PlatformError; + } + for (uint32_t i = 0; i < nameLength; i++) { strName[i] = static_cast(data[i]); From a5275b97ea82dbc69b2e13b597dfa9c07bded260 Mon Sep 17 00:00:00 2001 From: josesimoes Date: Wed, 20 Mar 2024 16:00:30 +0000 Subject: [PATCH 10/18] Add platform error to enum - To pass generic information about platform related errors. --- src/CLR/Debugger/Debugger.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/CLR/Debugger/Debugger.h b/src/CLR/Debugger/Debugger.h index 624b84a19d..96e9faf9ee 100644 --- a/src/CLR/Debugger/Debugger.h +++ b/src/CLR/Debugger/Debugger.h @@ -113,6 +113,8 @@ typedef enum StorageOperationErrorCode WriteError = 0x0010, // delete error DeleteError = 0x0020, + // platform error + PlatformError = 0x0030, } StorageOperationErrorCode; From 394f7880ebee3856c2524b1248d66d71d3ce5dca Mon Sep 17 00:00:00 2001 From: josesimoes Date: Wed, 20 Mar 2024 22:46:42 +0000 Subject: [PATCH 11/18] Minor changes and tweaks in code - Add enums where used. - Replace for loop with memcpy call. - Add verbose comments to make it super easy to port to other platforms. --- .../_common/targetHAL_StorageOperation.cpp | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/targets/ESP32/_common/targetHAL_StorageOperation.cpp b/targets/ESP32/_common/targetHAL_StorageOperation.cpp index 6de75ba283..c7739198d6 100644 --- a/targets/ESP32/_common/targetHAL_StorageOperation.cpp +++ b/targets/ESP32/_common/targetHAL_StorageOperation.cpp @@ -32,32 +32,37 @@ uint32_t HAL_StorageOperation( size_t result; StorageOperationErrorCode errorCode = StorageOperationErrorCode::NoError; - + EnsureStorageInitialized(); + // check if the name is not empty + if (nameLength == 0) + { + return StorageOperationErrorCode::WriteError; + } + // convert storageName to char* char *strName = (char *)platform_malloc(nameLength + 1); - + // sanity check for successfull malloc if (strName == NULL) { return StorageOperationErrorCode::PlatformError; } - for (uint32_t i = 0; i < nameLength; i++) - { - strName[i] = static_cast(data[i]); - } + // go and copy the name + memcpy(strName, data, nameLength); // Just making sure it's properly 0 terminated strName[nameLength] = '\0'; + // !! the returned char* needs to be freed !! char *storageNameChar = ConvertToVfsPath(strName); // Cleaning the temporary name buffer platform_free(strName); - if (operation == (uint8_t)(StorageOperation_Monitor::StorageOperation_Write)) + if (operation == StorageOperation_Monitor::StorageOperation_Write) { // Remove the file if already exists remove(storageNameChar); @@ -69,34 +74,40 @@ uint32_t HAL_StorageOperation( result = fwrite((const void *)(data + nameLength), 1, (size_t)dataLength, file); fclose(file); + // check if the data was written if (result != (size_t)dataLength) { errorCode = StorageOperationErrorCode::WriteError; } } - else if (operation == (uint8_t)(StorageOperation_Monitor::StorageOperation_Append)) + else if (operation == StorageOperation_Monitor::StorageOperation_Append) { // Open the file in read mode FILE *file = fopen(storageNameChar, "a"); fseek(file, 0, SEEK_END); + // append more data result = fwrite((const void *)(data + nameLength), 1, (size_t)dataLength, file); fclose(file); + // check if the data was written if (result != (size_t)dataLength) { errorCode = StorageOperationErrorCode::WriteError; } } - else if (operation == (uint8_t)(StorageOperation_Monitor::StorageOperation_Delete)) + else if (operation == StorageOperation_Monitor::StorageOperation_Delete) { result = remove(storageNameChar); + + // check if the file was deleted if (result != 0) { errorCode = StorageOperationErrorCode::DeleteError; } } + // free buffer memory if (storageNameChar != NULL) { platform_free(storageNameChar); From ebc5159d99ffdb49b793647f097bccc059c0ef3f Mon Sep 17 00:00:00 2001 From: josesimoes Date: Wed, 20 Mar 2024 22:49:22 +0000 Subject: [PATCH 12/18] Fix comment --- src/HAL/Include/nanoHAL_StorageOperation.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HAL/Include/nanoHAL_StorageOperation.h b/src/HAL/Include/nanoHAL_StorageOperation.h index 9be109f780..de000b8f94 100644 --- a/src/HAL/Include/nanoHAL_StorageOperation.h +++ b/src/HAL/Include/nanoHAL_StorageOperation.h @@ -25,4 +25,4 @@ extern "C" } #endif -#endif // NANOHAL_STORAGE_OPERATIN_H \ No newline at end of file +#endif // NANOHAL_STORAGE_OPERATION_H From 115d0cceccb93128192ecf007155a739ba94197a Mon Sep 17 00:00:00 2001 From: josesimoes Date: Thu, 21 Mar 2024 10:53:16 +0000 Subject: [PATCH 13/18] Rename feature to HAS_ACCESSIBLE_STORAGE - Update code and CMake files accordingly. --- CMake/AzureRTOS_target_os.h.in | 2 +- CMake/ChibiOS_target_os.h.in | 2 +- CMake/ESP32_target_os.h.in | 2 +- CMake/FreeRTOS_target_os.h.in | 2 +- CMake/TI_SimpleLink_target_os.h.in | 2 +- CMake/xtensa-esp32.json | 2 +- CMake/xtensa-esp32c3.json | 2 +- CMake/xtensa-esp32s2.json | 2 +- CMake/xtensa-esp32s3.json | 2 +- CMakeLists.txt | 14 +++++++------- src/CLR/Debugger/Debugger.cpp | 2 +- .../WireProtocol/WireProtocol_MonitorCommands.c | 2 +- targets/AzureRTOS/Maxim/_common/CMakeLists.txt | 2 +- targets/AzureRTOS/ST/_common/CMakeLists.txt | 2 +- .../AzureRTOS/SiliconLabs/_common/CMakeLists.txt | 2 +- targets/ChibiOS/_common/CMakeLists.txt | 2 +- targets/FreeRTOS/NXP/_common/CMakeLists.txt | 2 +- 17 files changed, 23 insertions(+), 23 deletions(-) diff --git a/CMake/AzureRTOS_target_os.h.in b/CMake/AzureRTOS_target_os.h.in index d16582bade..a13a1a6487 100644 --- a/CMake/AzureRTOS_target_os.h.in +++ b/CMake/AzureRTOS_target_os.h.in @@ -27,7 +27,7 @@ #define DP_FLOATINGPOINT @TARGET_DP_FLOATINGPOINT@ #define SUPPORT_ANY_BASE_CONVERSION @TARGET_SUPPORT_ANY_BASE_CONVERSION@ #define HAS_CONFIG_BLOCK @TARGET_HAS_CONFIG_BLOCK@ -#define HAS_INTERNAL_STORAGE @TARGET_HAS_INTERNAL_STORAGE@ +#define HAS_ACCESSIBLE_STORAGE @TARGET_HAS_ACCESSIBLE_STORAGE@ #define NANOCLR_REFLECTION @TARGET_NANOCLR_REFLECTION@ #define NANOCLR_SYSTEM_COLLECTIONS @TARGET_SYSTEM_COLLECTIONS@ #define TARGET_HAS_NANOBOOTER @TARGET_HAS_NANOBOOTER@ diff --git a/CMake/ChibiOS_target_os.h.in b/CMake/ChibiOS_target_os.h.in index faa8426b7b..0a71cf8ac0 100644 --- a/CMake/ChibiOS_target_os.h.in +++ b/CMake/ChibiOS_target_os.h.in @@ -27,7 +27,7 @@ #define DP_FLOATINGPOINT @TARGET_DP_FLOATINGPOINT@ #define SUPPORT_ANY_BASE_CONVERSION @TARGET_SUPPORT_ANY_BASE_CONVERSION@ #define HAS_CONFIG_BLOCK @TARGET_HAS_CONFIG_BLOCK@ -#define HAS_INTERNAL_STORAGE @TARGET_HAS_INTERNAL_STORAGE@ +#define HAS_ACCESSIBLE_STORAGE @TARGET_HAS_ACCESSIBLE_STORAGE@ #define NANOCLR_REFLECTION @TARGET_NANOCLR_REFLECTION@ #define NANOCLR_SYSTEM_COLLECTIONS @TARGET_SYSTEM_COLLECTIONS@ #define TARGET_HAS_NANOBOOTER @TARGET_HAS_NANOBOOTER@ diff --git a/CMake/ESP32_target_os.h.in b/CMake/ESP32_target_os.h.in index 38b98a54d7..052dc4287f 100644 --- a/CMake/ESP32_target_os.h.in +++ b/CMake/ESP32_target_os.h.in @@ -24,7 +24,7 @@ #define DP_FLOATINGPOINT @TARGET_DP_FLOATINGPOINT@ #define SUPPORT_ANY_BASE_CONVERSION @TARGET_SUPPORT_ANY_BASE_CONVERSION@ #define HAS_CONFIG_BLOCK @TARGET_HAS_CONFIG_BLOCK@ -#define HAS_INTERNAL_STORAGE @TARGET_HAS_INTERNAL_STORAGE@ +#define HAS_ACCESSIBLE_STORAGE @TARGET_HAS_ACCESSIBLE_STORAGE@ #define NANOCLR_REFLECTION @TARGET_NANOCLR_REFLECTION@ #define NANOCLR_SYSTEM_COLLECTIONS @TARGET_SYSTEM_COLLECTIONS@ #define TARGET_HAS_NANOBOOTER FALSE diff --git a/CMake/FreeRTOS_target_os.h.in b/CMake/FreeRTOS_target_os.h.in index 4d7e8b448f..7c25b52ed5 100644 --- a/CMake/FreeRTOS_target_os.h.in +++ b/CMake/FreeRTOS_target_os.h.in @@ -25,7 +25,7 @@ #define DP_FLOATINGPOINT @TARGET_DP_FLOATINGPOINT@ #define SUPPORT_ANY_BASE_CONVERSION @TARGET_SUPPORT_ANY_BASE_CONVERSION@ #define HAS_CONFIG_BLOCK @TARGET_HAS_CONFIG_BLOCK@ -#define HAS_INTERNAL_STORAGE @TARGET_HAS_INTERNAL_STORAGE@ +#define HAS_ACCESSIBLE_STORAGE @TARGET_HAS_ACCESSIBLE_STORAGE@ #define NANOCLR_REFLECTION @TARGET_NANOCLR_REFLECTION@ #define NANOCLR_SYSTEM_COLLECTIONS @TARGET_SYSTEM_COLLECTIONS@ #define TARGET_HAS_NANOBOOTER @TARGET_HAS_NANOBOOTER@ diff --git a/CMake/TI_SimpleLink_target_os.h.in b/CMake/TI_SimpleLink_target_os.h.in index d48488c8cc..578ae67cab 100644 --- a/CMake/TI_SimpleLink_target_os.h.in +++ b/CMake/TI_SimpleLink_target_os.h.in @@ -20,7 +20,7 @@ #define DP_FLOATINGPOINT @TARGET_DP_FLOATINGPOINT@ #define SUPPORT_ANY_BASE_CONVERSION @TARGET_SUPPORT_ANY_BASE_CONVERSION@ #define HAS_CONFIG_BLOCK @TARGET_HAS_CONFIG_BLOCK@ -#define HAS_INTERNAL_STORAGE @TARGET_HAS_INTERNAL_STORAGE@ +#define HAS_ACCESSIBLE_STORAGE @TARGET_HAS_ACCESSIBLE_STORAGE@ #define NANOCLR_REFLECTION @TARGET_NANOCLR_REFLECTION@ #define NANOCLR_SYSTEM_COLLECTIONS @TARGET_SYSTEM_COLLECTIONS@ #define TARGET_HAS_NANOBOOTER FALSE diff --git a/CMake/xtensa-esp32.json b/CMake/xtensa-esp32.json index ef6e47583b..233be87bdd 100644 --- a/CMake/xtensa-esp32.json +++ b/CMake/xtensa-esp32.json @@ -20,7 +20,7 @@ "TARGET_SERIES": "ESP32", "TARGET_BOARD": "ESP32", "NF_FEATURE_HAS_CONFIG_BLOCK": "ON", - "NF_FEATURE_HAS_INTERNAL_STORAGE": "ON", + "NF_FEATURE_HAS_ACCESSIBLE_STORAGE": "ON", "SUPPORT_ANY_BASE_CONVERSION": "ON", "API_System.Net": "ON", "API_System.Math": "ON", diff --git a/CMake/xtensa-esp32c3.json b/CMake/xtensa-esp32c3.json index ed97ff5949..702a4484af 100644 --- a/CMake/xtensa-esp32c3.json +++ b/CMake/xtensa-esp32c3.json @@ -20,7 +20,7 @@ "TARGET_SERIES": "ESP32_C3", "TARGET_BOARD": "ESP32_C3", "NF_FEATURE_HAS_CONFIG_BLOCK": "ON", - "NF_FEATURE_HAS_INTERNAL_STORAGE": "ON", + "NF_FEATURE_HAS_ACCESSIBLE_STORAGE": "ON", "SUPPORT_ANY_BASE_CONVERSION": "ON", "API_System.Net": "ON", "API_System.Math": "ON", diff --git a/CMake/xtensa-esp32s2.json b/CMake/xtensa-esp32s2.json index 888ddc7795..e629ab8615 100644 --- a/CMake/xtensa-esp32s2.json +++ b/CMake/xtensa-esp32s2.json @@ -20,7 +20,7 @@ "TARGET_SERIES": "ESP32_S2", "TARGET_BOARD": "ESP32_S2", "NF_FEATURE_HAS_CONFIG_BLOCK": "ON", - "NF_FEATURE_HAS_INTERNAL_STORAGE": "ON", + "NF_FEATURE_HAS_ACCESSIBLE_STORAGE": "ON", "SUPPORT_ANY_BASE_CONVERSION": "ON", "API_System.Net": "ON", "API_System.Math": "ON", diff --git a/CMake/xtensa-esp32s3.json b/CMake/xtensa-esp32s3.json index 78470ab94c..d46db7d5a2 100644 --- a/CMake/xtensa-esp32s3.json +++ b/CMake/xtensa-esp32s3.json @@ -20,7 +20,7 @@ "TARGET_SERIES": "ESP32_S3", "TARGET_BOARD": "ESP32_S3", "NF_FEATURE_HAS_CONFIG_BLOCK": "ON", - "NF_FEATURE_HAS_INTERNAL_STORAGE": "ON", + "NF_FEATURE_HAS_ACCESSIBLE_STORAGE": "ON", "SUPPORT_ANY_BASE_CONVERSION": "ON", "API_System.Net": "ON", "API_System.Math": "ON", diff --git a/CMakeLists.txt b/CMakeLists.txt index d6e5a5a663..8be45617ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -289,15 +289,15 @@ endif() ################################################################# # enables internal storage support -# (default is OFF so Configuration block storage is NOT supported) -option(NF_FEATURE_HAS_INTERNAL_STORAGE "option to enable internal storage") +# (default is OFF so Accessible Storage Feature is NOT supported) +option(NF_FEATURE_HAS_ACCESSIBLE_STORAGE "option to enable accessible storage") -if(NF_FEATURE_HAS_INTERNAL_STORAGE) - set(TARGET_HAS_INTERNAL_STORAGE TRUE CACHE INTERNAL "Option for internal storage") - message(STATUS "Configuration internal storage is included") +if(NF_FEATURE_HAS_ACCESSIBLE_STORAGE) + set(TARGET_HAS_ACCESSIBLE_STORAGE TRUE CACHE INTERNAL "Option for accessible storage") + message(STATUS "Accessible Storage feature is included") else() - set(TARGET_HAS_INTERNAL_STORAGE FALSE CACHE INTERNAL "Option for internal storage") - message(STATUS "Configuration internal storage **IS NOT** included") + set(TARGET_HAS_ACCESSIBLE_STORAGE FALSE CACHE INTERNAL "Option for accessible storage") + message(STATUS "Accessible Storage feature **IS NOT** included") endif() ################################################################# diff --git a/src/CLR/Debugger/Debugger.cpp b/src/CLR/Debugger/Debugger.cpp index 761b3814a4..62fb37f333 100644 --- a/src/CLR/Debugger/Debugger.cpp +++ b/src/CLR/Debugger/Debugger.cpp @@ -1340,7 +1340,7 @@ bool CLR_DBG_Debugger::Monitor_StorageOperation(WP_Message *message) { NATIVE_PROFILE_CLR_DEBUGGER(); -#if (HAS_INTERNAL_STORAGE == TRUE) +#if (HAS_ACCESSIBLE_STORAGE == TRUE) Monitor_StorageOperation_Command *cmd = (Monitor_StorageOperation_Command *)message->m_payload; Monitor_StorageOperation_Reply cmdReply; diff --git a/src/CLR/WireProtocol/WireProtocol_MonitorCommands.c b/src/CLR/WireProtocol/WireProtocol_MonitorCommands.c index e511e12236..d35adaa4ca 100644 --- a/src/CLR/WireProtocol/WireProtocol_MonitorCommands.c +++ b/src/CLR/WireProtocol/WireProtocol_MonitorCommands.c @@ -256,7 +256,7 @@ int Monitor_UpdateConfiguration(WP_Message *message) int Monitor_StorageOperation(WP_Message *message) { debug_printf("Monitor_StorageOperation"); -#if (HAS_INTERNAL_STORAGE == TRUE) +#if (HAS_ACCESSIBLE_STORAGE == TRUE) Monitor_StorageOperation_Command *cmd = (Monitor_StorageOperation_Command *)message->m_payload; Monitor_StorageOperation_Reply cmdReply; diff --git a/targets/AzureRTOS/Maxim/_common/CMakeLists.txt b/targets/AzureRTOS/Maxim/_common/CMakeLists.txt index 6a6895a823..c1ec4ca7d1 100644 --- a/targets/AzureRTOS/Maxim/_common/CMakeLists.txt +++ b/targets/AzureRTOS/Maxim/_common/CMakeLists.txt @@ -13,7 +13,7 @@ if(NF_FEATURE_HAS_CONFIG_BLOCK) endif() # include internal storage, if feature is enabled -if(NF_FEATURE_HAS_INTERNAL_STORAGE) +if(NF_FEATURE_HAS_ACCESSIBLE_STORAGE) list(APPEND TARGET_AZURERTOS_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/targetHAL_StorageOperation.cpp) endif() diff --git a/targets/AzureRTOS/ST/_common/CMakeLists.txt b/targets/AzureRTOS/ST/_common/CMakeLists.txt index f0953d7286..3dc738774c 100644 --- a/targets/AzureRTOS/ST/_common/CMakeLists.txt +++ b/targets/AzureRTOS/ST/_common/CMakeLists.txt @@ -23,7 +23,7 @@ if(NF_FEATURE_HAS_CONFIG_BLOCK) endif() # include internal storage, if feature is enabled -if(NF_FEATURE_HAS_INTERNAL_STORAGE) +if(NF_FEATURE_HAS_ACCESSIBLE_STORAGE) list(APPEND TARGET_AZURERTOS_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/targetHAL_StorageOperation.cpp) endif() diff --git a/targets/AzureRTOS/SiliconLabs/_common/CMakeLists.txt b/targets/AzureRTOS/SiliconLabs/_common/CMakeLists.txt index b4f85784e6..493b2fed6c 100644 --- a/targets/AzureRTOS/SiliconLabs/_common/CMakeLists.txt +++ b/targets/AzureRTOS/SiliconLabs/_common/CMakeLists.txt @@ -19,7 +19,7 @@ if(NF_FEATURE_HAS_CONFIG_BLOCK) endif() # include internal storage, if feature is enabled -if(NF_FEATURE_HAS_INTERNAL_STORAGE) +if(NF_FEATURE_HAS_ACCESSIBLE_STORAGE) list(APPEND TARGET_AZURERTOS_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/targetHAL_StorageOperation.cpp) endif() diff --git a/targets/ChibiOS/_common/CMakeLists.txt b/targets/ChibiOS/_common/CMakeLists.txt index 073d79a4df..846419b76f 100644 --- a/targets/ChibiOS/_common/CMakeLists.txt +++ b/targets/ChibiOS/_common/CMakeLists.txt @@ -20,7 +20,7 @@ if(NF_FEATURE_HAS_CONFIG_BLOCK) endif() # include internal storage, if feature is enabled -if(NF_FEATURE_HAS_INTERNAL_STORAGE) +if(NF_FEATURE_HAS_ACCESSIBLE_STORAGE) list(APPEND TARGET_CHIBIOS_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/targetHAL_StorageOperation.cpp) endif() diff --git a/targets/FreeRTOS/NXP/_common/CMakeLists.txt b/targets/FreeRTOS/NXP/_common/CMakeLists.txt index 5454b31a4d..4dafa69b34 100644 --- a/targets/FreeRTOS/NXP/_common/CMakeLists.txt +++ b/targets/FreeRTOS/NXP/_common/CMakeLists.txt @@ -76,7 +76,7 @@ if(NF_FEATURE_HAS_CONFIG_BLOCK) endif() # include internal storage, if feature is enabled -if(NF_FEATURE_HAS_INTERNAL_STORAGE) +if(NF_FEATURE_HAS_ACCESSIBLE_STORAGE) list(APPEND TARGET_NXP_COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/targetHAL_StorageOperation.cpp) endif() From 0f8a4760ed5aa12d55e57bc2629adbc2ad60d859 Mon Sep 17 00:00:00 2001 From: josesimoes Date: Thu, 21 Mar 2024 15:51:45 +0000 Subject: [PATCH 14/18] Remove command from Monitor command set - Adding it completely bloats nanoBooter image size. --- .../WireProtocol_MonitorCommands.c | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/src/CLR/WireProtocol/WireProtocol_MonitorCommands.c b/src/CLR/WireProtocol/WireProtocol_MonitorCommands.c index d35adaa4ca..b1bd1daaa4 100644 --- a/src/CLR/WireProtocol/WireProtocol_MonitorCommands.c +++ b/src/CLR/WireProtocol/WireProtocol_MonitorCommands.c @@ -253,26 +253,6 @@ int Monitor_UpdateConfiguration(WP_Message *message) return success; } -int Monitor_StorageOperation(WP_Message *message) -{ - debug_printf("Monitor_StorageOperation"); -#if (HAS_ACCESSIBLE_STORAGE == TRUE) - - Monitor_StorageOperation_Command *cmd = (Monitor_StorageOperation_Command *)message->m_payload; - Monitor_StorageOperation_Reply cmdReply; - - cmdReply.ErrorCode = HAL_StorageOperation(cmd->Operation, cmd->NameLength, cmd->DataLength, cmd->Offset, cmd->Data); - - WP_ReplyToCommand(message, true, false, &cmdReply, sizeof(cmdReply)); - - return true; - -#endif - - (void)message; - return false; -} - int Monitor_CheckMemory(WP_Message *message) { bool ret = false; From 36321dc5b4cbdc97e4470e4291b6b40cfafa47b4 Mon Sep 17 00:00:00 2001 From: josesimoes Date: Thu, 21 Mar 2024 15:51:56 +0000 Subject: [PATCH 15/18] Remove duplicated include --- src/HAL/Include/nanoHAL_StorageOperation.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/HAL/Include/nanoHAL_StorageOperation.h b/src/HAL/Include/nanoHAL_StorageOperation.h index de000b8f94..8083ee0f9b 100644 --- a/src/HAL/Include/nanoHAL_StorageOperation.h +++ b/src/HAL/Include/nanoHAL_StorageOperation.h @@ -6,7 +6,6 @@ #ifndef NANOHAL_STORAGE_OPERATION_H #define NANOHAL_STORAGE_OPERATION_H -#include #include #ifdef __cplusplus From 63075e2310feabe56bdaee264260a3e7d1cbf4ff Mon Sep 17 00:00:00 2001 From: josesimoes Date: Thu, 21 Mar 2024 15:53:23 +0000 Subject: [PATCH 16/18] Remove include from booter on all targets --- targets/AzureRTOS/Maxim/MAX78000_FTHR/nanoBooter/main.c | 1 - targets/AzureRTOS/ST/ORGPAL_PALTHREE/nanoBooter/main.c | 1 - targets/AzureRTOS/ST/ST_B_L475E_IOT01A/nanoBooter/main.c | 1 - targets/ChibiOS/ORGPAL_PALTHREE/nanoBooter/main.c | 1 - targets/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/main.c | 1 - 5 files changed, 5 deletions(-) diff --git a/targets/AzureRTOS/Maxim/MAX78000_FTHR/nanoBooter/main.c b/targets/AzureRTOS/Maxim/MAX78000_FTHR/nanoBooter/main.c index 6b006e4c81..835a7d0ccc 100644 --- a/targets/AzureRTOS/Maxim/MAX78000_FTHR/nanoBooter/main.c +++ b/targets/AzureRTOS/Maxim/MAX78000_FTHR/nanoBooter/main.c @@ -11,7 +11,6 @@ #include #include #include -#include #include diff --git a/targets/AzureRTOS/ST/ORGPAL_PALTHREE/nanoBooter/main.c b/targets/AzureRTOS/ST/ORGPAL_PALTHREE/nanoBooter/main.c index 0e34e0bad1..ec82c2eaba 100644 --- a/targets/AzureRTOS/ST/ORGPAL_PALTHREE/nanoBooter/main.c +++ b/targets/AzureRTOS/ST/ORGPAL_PALTHREE/nanoBooter/main.c @@ -10,7 +10,6 @@ #include #include #include -#include #include // byte pool configuration and definitions diff --git a/targets/AzureRTOS/ST/ST_B_L475E_IOT01A/nanoBooter/main.c b/targets/AzureRTOS/ST/ST_B_L475E_IOT01A/nanoBooter/main.c index c1e330532d..b72ba0c138 100644 --- a/targets/AzureRTOS/ST/ST_B_L475E_IOT01A/nanoBooter/main.c +++ b/targets/AzureRTOS/ST/ST_B_L475E_IOT01A/nanoBooter/main.c @@ -13,7 +13,6 @@ #include #include #include -#include // byte pool configuration and definitions #define DEFAULT_BYTE_POOL_SIZE 4096 diff --git a/targets/ChibiOS/ORGPAL_PALTHREE/nanoBooter/main.c b/targets/ChibiOS/ORGPAL_PALTHREE/nanoBooter/main.c index 9fc107bcd6..9d9e3c9c98 100644 --- a/targets/ChibiOS/ORGPAL_PALTHREE/nanoBooter/main.c +++ b/targets/ChibiOS/ORGPAL_PALTHREE/nanoBooter/main.c @@ -14,7 +14,6 @@ #include #include #include -#include #include // need to declare the Receiver thread here diff --git a/targets/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/main.c b/targets/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/main.c index 241824b8a1..ed31c6ef93 100644 --- a/targets/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/main.c +++ b/targets/ChibiOS/ST_STM32F769I_DISCOVERY/nanoBooter/main.c @@ -14,7 +14,6 @@ #include #include #include -#include #include // need to declare the Receiver thread here From 828521e33a8dd09b8b7a045732092b7b6f1451d1 Mon Sep 17 00:00:00 2001 From: josesimoes Date: Thu, 21 Mar 2024 15:54:50 +0000 Subject: [PATCH 17/18] Add implementation to ChibiOS using SPIFFs - Enabled it for ORGPAL3, which is the only target that supports this. --- CMake/binutils.ChibiOS.cmake | 3 +- .../ChibiOS/ORGPAL_PALTHREE/CMakePresets.json | 1 + .../_common/targetHAL_StorageOperation.cpp | 132 ++++++++++++++++++ .../_include/targetHAL_StorageOperation.h | 13 ++ 4 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 targets/ChibiOS/_common/targetHAL_StorageOperation.cpp create mode 100644 targets/ChibiOS/_include/targetHAL_StorageOperation.h diff --git a/CMake/binutils.ChibiOS.cmake b/CMake/binutils.ChibiOS.cmake index a5d74426ed..7d919f900d 100644 --- a/CMake/binutils.ChibiOS.cmake +++ b/CMake/binutils.ChibiOS.cmake @@ -235,6 +235,8 @@ macro(nf_add_platform_include_directories target) ${TARGET_CMSIS_COMMON_INCLUDE_DIRS} ${TARGET_CHIBIOS_COMMON_INCLUDE_DIRS} ${lWIP_INCLUDE_DIRS} + ${SPIFFS_INCLUDE_DIRS} + ) # includes specific to nanoBooter @@ -243,7 +245,6 @@ macro(nf_add_platform_include_directories target) target_include_directories(${target}.elf PUBLIC ${TARGET_CHIBIOS_NANOBOOTER_INCLUDE_DIRS} - ) endif() diff --git a/targets/ChibiOS/ORGPAL_PALTHREE/CMakePresets.json b/targets/ChibiOS/ORGPAL_PALTHREE/CMakePresets.json index bce72fa557..48fda2ff32 100644 --- a/targets/ChibiOS/ORGPAL_PALTHREE/CMakePresets.json +++ b/targets/ChibiOS/ORGPAL_PALTHREE/CMakePresets.json @@ -27,6 +27,7 @@ "NF_FEATURE_HAS_CONFIG_BLOCK": "ON", "NF_FEATURE_HAS_USB_MSD": "ON", "NF_FEATURE_USE_SPIFFS": "ON", + "NF_FEATURE_HAS_ACCESSIBLE_STORAGE": "ON", "NF_BUILD_RTM": "OFF", "API_System.Math": "ON", "API_Hardware.Stm32": "ON", diff --git a/targets/ChibiOS/_common/targetHAL_StorageOperation.cpp b/targets/ChibiOS/_common/targetHAL_StorageOperation.cpp new file mode 100644 index 0000000000..684bf9e384 --- /dev/null +++ b/targets/ChibiOS/_common/targetHAL_StorageOperation.cpp @@ -0,0 +1,132 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +// make sure to include this only for nanoCLR +#ifdef I_AM_NANOCLR + +#include +#include +#include +#include +#include +#include +#include +#include + +#if HAS_ACCESSIBLE_STORAGE + +#if defined(NF_FEATURE_USE_SPIFFS) && (NF_FEATURE_USE_SPIFFS == TRUE) + +uint32_t HAL_StorageOperation( + uint8_t operation, + uint32_t nameLength, + uint32_t dataLength, + uint32_t offset, + uint8_t *data) +{ + (void)offset; + + spiffs_file *spiffsFile = NULL; + spiffs *driveFs = NULL; + // default to drive 0 + int32_t driveIndex = 0; + StorageOperationErrorCode errorCode = StorageOperationErrorCode::NoError; + + // check if the name is not empty + if (nameLength == 0) + { + return StorageOperationErrorCode::WriteError; + } + + // convert storageName to char* + char *storageName = (char *)platform_malloc(nameLength + 1); + + // sanity check for successfull malloc + if (storageName == NULL) + { + return StorageOperationErrorCode::PlatformError; + } + + // go and copy the name + memcpy(storageName, data, nameLength); + + // Just making sure it's properly 0 terminated + storageName[nameLength] = '\0'; + + //... and pointer to the SPIFFS instance + driveFs = hal_spiffs_get_fs_from_index(driveIndex); + + if (operation == StorageOperation_Monitor::StorageOperation_Write) + { + // Open the file in read mode + *spiffsFile = SPIFFS_open(driveFs, storageName, SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_RDWR, 0); + if (*spiffsFile < 0) + { + errorCode = StorageOperationErrorCode::WriteError; + + goto done; + } + + if (SPIFFS_write( + driveFs, + *spiffsFile, + (data + nameLength), + dataLength) < 0) + { + // failed to write expected number of bytes + errorCode = StorageOperationErrorCode::WriteError; + } + + // close file + SPIFFS_close(driveFs, *spiffsFile); + } + else if (operation == StorageOperation_Monitor::StorageOperation_Append) + { + // Open the file in apped mode + *spiffsFile = SPIFFS_open(driveFs, storageName, SPIFFS_APPEND | SPIFFS_RDWR, 0); + if (*spiffsFile < 0) + { + errorCode = StorageOperationErrorCode::WriteError; + + goto done; + } + + // append more data + if (SPIFFS_write( + driveFs, + *spiffsFile, + (data + nameLength), + dataLength) < 0) + { + // failed to write expected number of bytes + errorCode = StorageOperationErrorCode::WriteError; + } + + // close file + SPIFFS_close(driveFs, *spiffsFile); + } + else if (operation == StorageOperation_Monitor::StorageOperation_Delete) + { + // remove the file + if (SPIFFS_remove(driveFs, storageName) < 0) + { + errorCode = StorageOperationErrorCode::DeleteError; + } + } + +done: + + // free buffer memory + if (storageName != NULL) + { + platform_free(storageName); + } + + return errorCode; +} + +#endif // HAL_USE_SPIFFS +#endif // HAS_ACCESSIBLE_STORAGE +#endif // I_AM_NANOCLR diff --git a/targets/ChibiOS/_include/targetHAL_StorageOperation.h b/targets/ChibiOS/_include/targetHAL_StorageOperation.h new file mode 100644 index 0000000000..8aff59202c --- /dev/null +++ b/targets/ChibiOS/_include/targetHAL_StorageOperation.h @@ -0,0 +1,13 @@ +// +// Copyright (c) .NET Foundation and Contributors +// See LICENSE file in the project root for full license information. +// + +#ifndef TARGET_PAL_STORAGE_OPERATION_H +#define TARGET_PAL_STORAGE_OPERATION_H + +#include +#include +#include + +#endif // TARGET_PAL_STORAGE_OPERATION_H \ No newline at end of file From ef4ef9747d356daf35e58c55d3dacc0c2431429a Mon Sep 17 00:00:00 2001 From: josesimoes Date: Thu, 21 Mar 2024 16:05:40 +0000 Subject: [PATCH 18/18] Rename define for consistency thanks @networkfusion --- targets/ChibiOS/_include/targetHAL_StorageOperation.h | 7 ++++--- targets/ESP32/_include/targetHAL_StorageOperation.h | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/targets/ChibiOS/_include/targetHAL_StorageOperation.h b/targets/ChibiOS/_include/targetHAL_StorageOperation.h index 8aff59202c..0576747c34 100644 --- a/targets/ChibiOS/_include/targetHAL_StorageOperation.h +++ b/targets/ChibiOS/_include/targetHAL_StorageOperation.h @@ -3,11 +3,12 @@ // See LICENSE file in the project root for full license information. // -#ifndef TARGET_PAL_STORAGE_OPERATION_H -#define TARGET_PAL_STORAGE_OPERATION_H +#ifndef TARGET_HAL_STORAGE_OPERATION_H +#define TARGET_HAL_STORAGE_OPERATION_H #include #include #include -#endif // TARGET_PAL_STORAGE_OPERATION_H \ No newline at end of file + +#endif // TARGET_HAL_STORAGE_OPERATION_H diff --git a/targets/ESP32/_include/targetHAL_StorageOperation.h b/targets/ESP32/_include/targetHAL_StorageOperation.h index 92a800d6d1..c8c523d188 100644 --- a/targets/ESP32/_include/targetHAL_StorageOperation.h +++ b/targets/ESP32/_include/targetHAL_StorageOperation.h @@ -3,12 +3,12 @@ // See LICENSE file in the project root for full license information. // -#ifndef TARGET_PAL_STORAGE_OPERATION_H -#define TARGET_PAL_STORAGE_OPERATION_H +#ifndef TARGET_HAL_STORAGE_OPERATION_H +#define TARGET_HAL_STORAGE_OPERATION_H #include #include #include #include -#endif // TARGET_PAL_STORAGE_OPERATION_H \ No newline at end of file +#endif // TARGET_HAL_STORAGE_OPERATION_H