From e79c5faad0b44d55fa823a8ab9e802192d1b672a Mon Sep 17 00:00:00 2001 From: Laurent Ellerbach Date: Thu, 21 Mar 2024 12:26:19 -0400 Subject: [PATCH] Add Support for Storage Operations (#2901) --- 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/binutils.ChibiOS.cmake | 3 +- 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 | 22 +++ src/CLR/Debugger/Debugger.h | 176 ++++++++++-------- src/CLR/Debugger/Debugger_full.cpp | 1 + src/CLR/Debugger/Debugger_minimal.cpp | 1 + src/CLR/Include/WireProtocol.h | 1 + .../Include/WireProtocol_MonitorCommands.h | 30 +++ src/CLR/Include/nanoCLR_Debugging.h | 2 +- src/HAL/Include/nanoHAL_StorageOperation.h | 27 +++ .../Maxim/MAX78000_FTHR/nanoCLR/main.c | 1 + .../AzureRTOS/Maxim/_common/CMakeLists.txt | 5 + .../AzureRTOS/Maxim/_nanoCLR/targetHAL.cpp | 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/CMakePresets.json | 1 + targets/ChibiOS/_common/CMakeLists.txt | 5 + .../_common/targetHAL_StorageOperation.cpp | 132 +++++++++++++ .../_include/targetHAL_StorageOperation.h | 14 ++ 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 | 117 ++++++++++++ .../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 + 48 files changed, 616 insertions(+), 149 deletions(-) create mode 100644 src/HAL/Include/nanoHAL_StorageOperation.h create mode 100644 targets/ChibiOS/_common/targetHAL_StorageOperation.cpp create mode 100644 targets/ChibiOS/_include/targetHAL_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..a13a1a6487 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_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 c368b5c909..0a71cf8ac0 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_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 b71783e3ec..052dc4287f 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_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 30c0693f91..7c25b52ed5 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_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 26063d19e1..578ae67cab 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_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/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/CMake/xtensa-esp32.json b/CMake/xtensa-esp32.json index 257b67f53a..233be87bdd 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_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 baf2455cfa..702a4484af 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_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 e99a301520..e629ab8615 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_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 7e502075a2..d46db7d5a2 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_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 f3965581d9..8be45617ce 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 Accessible Storage Feature is NOT supported) +option(NF_FEATURE_HAS_ACCESSIBLE_STORAGE "option to enable accessible storage") + +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_ACCESSIBLE_STORAGE FALSE CACHE INTERNAL "Option for accessible storage") + message(STATUS "Accessible Storage feature **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..62fb37f333 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)) @@ -1335,6 +1336,27 @@ bool CLR_DBG_Debugger::Monitor_UpdateConfiguration(WP_Message *message) #endif } +bool CLR_DBG_Debugger::Monitor_StorageOperation(WP_Message *message) +{ + NATIVE_PROFILE_CLR_DEBUGGER(); + +#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; +} + //--// 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..96e9faf9ee 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,11 +94,28 @@ 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; + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// !!! KEEP IN SYNC WITH nanoFramework.Tools.Debugger.WireProtocol.StorageOperationErrorCode (in managed code) !!! // +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +typedef enum StorageOperationErrorCode +{ + // no error + NoError = 0x0001, + // write error + WriteError = 0x0010, + // delete error + DeleteError = 0x0020, + // platform error + PlatformError = 0x0030, -}AccessMemoryErrorCodes; +} StorageOperationErrorCode; -#endif //DEBUGGER_H +#endif // DEBUGGER_H 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.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..92ebb64f7c 100644 --- a/src/CLR/Include/WireProtocol_MonitorCommands.h +++ b/src/CLR/Include/WireProtocol_MonitorCommands.h @@ -56,6 +56,18 @@ 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 StorageOperation_Monitor +{ + StorageOperation_None = 0, + StorageOperation_Write = 1, + StorageOperation_Delete = 2, + StorageOperation_Append = 3 +} StorageOperation_Monitor; + ////////////////////////////////////////// // typedefs @@ -163,6 +175,23 @@ typedef struct __nfpack Monitor_UpdateConfiguration_Command } Monitor_UpdateConfiguration_Command; + +typedef struct Monitor_StorageOperation_Command +{ + uint32_t Operation; + uint32_t NameLength; + uint32_t DataLength; + uint32_t Offset; + 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 +225,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); 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/HAL/Include/nanoHAL_StorageOperation.h b/src/HAL/Include/nanoHAL_StorageOperation.h new file mode 100644 index 0000000000..8083ee0f9b --- /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 + + uint32_t HAL_StorageOperation( + uint8_t operation, + uint32_t nameLength, + uint32_t dataLength, + uint32_t offset, + uint8_t *data); + +#ifdef __cplusplus +} +#endif + +#endif // NANOHAL_STORAGE_OPERATION_H 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..c1ec4ca7d1 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_ACCESSIBLE_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/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..3dc738774c 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_ACCESSIBLE_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..493b2fed6c 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_ACCESSIBLE_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/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/CMakeLists.txt b/targets/ChibiOS/_common/CMakeLists.txt index fdb1d6231f..846419b76f 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_ACCESSIBLE_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/_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..0576747c34 --- /dev/null +++ b/targets/ChibiOS/_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_HAL_STORAGE_OPERATION_H +#define TARGET_HAL_STORAGE_OPERATION_H + +#include +#include +#include + + +#endif // TARGET_HAL_STORAGE_OPERATION_H 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..c7739198d6 --- /dev/null +++ b/targets/ESP32/_common/targetHAL_StorageOperation.cpp @@ -0,0 +1,117 @@ +// +// 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(); + } +} + +uint32_t HAL_StorageOperation( + uint8_t operation, + uint32_t nameLength, + uint32_t dataLength, + uint32_t offset, + uint8_t *data) +{ + (void)offset; + + 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; + } + + // 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 == 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 + 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 == 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 == 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); + } + + return errorCode; +} 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..c8c523d188 --- /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_HAL_STORAGE_OPERATION_H +#define TARGET_HAL_STORAGE_OPERATION_H + +#include +#include +#include +#include + +#endif // TARGET_HAL_STORAGE_OPERATION_H 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..4dafa69b34 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_ACCESSIBLE_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