diff --git a/src/CLR/Debugger/Debugger.cpp b/src/CLR/Debugger/Debugger.cpp index 0123a8f25d..5fc2d3d302 100644 --- a/src/CLR/Debugger/Debugger.cpp +++ b/src/CLR/Debugger/Debugger.cpp @@ -1026,7 +1026,7 @@ bool CLR_DBG_Debugger::Monitor_UpdateConfiguration(WP_Message* message) case DeviceConfigurationOption_Wireless80211Network: case DeviceConfigurationOption_X509CaRootBundle: case DeviceConfigurationOption_All: - if(ConfigurationManager_StoreConfigurationBlock(cmd->Data, (DeviceConfigurationOption)cmd->Configuration, cmd->BlockIndex, cmd->Length, cmd->Offset) == true) + if(ConfigurationManager_StoreConfigurationBlock(cmd->Data, (DeviceConfigurationOption)cmd->Configuration, cmd->BlockIndex, cmd->Length, cmd->Offset, cmd->Done) == true) { cmdReply.ErrorCode = 0; success = true; diff --git a/src/CLR/Include/WireProtocol_MonitorCommands.h b/src/CLR/Include/WireProtocol_MonitorCommands.h index f2cea51ca2..b593cbf636 100644 --- a/src/CLR/Include/WireProtocol_MonitorCommands.h +++ b/src/CLR/Include/WireProtocol_MonitorCommands.h @@ -9,6 +9,7 @@ #include "WireProtocol.h" #include "WireProtocol_Message.h" +#include ////////////////////////////////////////// // enums @@ -156,12 +157,13 @@ typedef struct Monitor_QueryConfiguration_Command }Monitor_QueryConfiguration_Command; -typedef struct Monitor_UpdateConfiguration_Command +typedef struct __nfpack Monitor_UpdateConfiguration_Command { uint32_t Configuration; uint32_t BlockIndex; uint32_t Length; uint32_t Offset; + uint32_t Done; uint8_t Data[1]; }Monitor_UpdateConfiguration_Command; diff --git a/src/DeviceInterfaces/System.Net/sys_net_native_System_Net_Security_CertificateManager.cpp b/src/DeviceInterfaces/System.Net/sys_net_native_System_Net_Security_CertificateManager.cpp index 4946f4df4f..a8c6b9b244 100644 --- a/src/DeviceInterfaces/System.Net/sys_net_native_System_Net_Security_CertificateManager.cpp +++ b/src/DeviceInterfaces/System.Net/sys_net_native_System_Net_Security_CertificateManager.cpp @@ -30,7 +30,7 @@ HRESULT Library_sys_net_native_System_Net_Security_CertificateManager::AddCaCert if(g_TargetConfiguration.CertificateStore->Count == 0) { // not found, add the certificate bundle - if(ConfigurationManager_StoreConfigurationBlock(certificateBinary, DeviceConfigurationOption_X509CaRootBundle, configIndex, certificateSize, 0) != TRUE) + if(ConfigurationManager_StoreConfigurationBlock(certificateBinary, DeviceConfigurationOption_X509CaRootBundle, configIndex, certificateSize, 0, false) != TRUE) { NANOCLR_SET_AND_LEAVE(CLR_E_FAIL); } diff --git a/src/HAL/Include/nanoHAL_ConfigurationManager.h b/src/HAL/Include/nanoHAL_ConfigurationManager.h index a1c7df090a..1ee4f8d399 100644 --- a/src/HAL/Include/nanoHAL_ConfigurationManager.h +++ b/src/HAL/Include/nanoHAL_ConfigurationManager.h @@ -111,7 +111,7 @@ bool ConfigurationManager_GetConfigurationBlock(void* configurationBlock, Device // StoreConfigurationBlock() is defined in targetHAL_ConfigurationManager.cpp at target level because the target // needs to be free to implement the storage of the configuration block as they see fit -bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, DeviceConfigurationOption configuration, uint32_t configurationIndex, uint32_t blockSize, uint32_t offset); +bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, DeviceConfigurationOption configuration, uint32_t configurationIndex, uint32_t blockSize, uint32_t offset, bool done); // UpdateConfigurationBlock() is defined in targetHAL_ConfigurationManager.cpp at target level because the target // needs to be free to implement the storage of the configuration block as they see fit diff --git a/targets/CMSIS-OS/ChibiOS/common/targetHAL_ConfigurationManager.cpp b/targets/CMSIS-OS/ChibiOS/common/targetHAL_ConfigurationManager.cpp index 6ee55243db..c525094d5e 100644 --- a/targets/CMSIS-OS/ChibiOS/common/targetHAL_ConfigurationManager.cpp +++ b/targets/CMSIS-OS/ChibiOS/common/targetHAL_ConfigurationManager.cpp @@ -38,7 +38,7 @@ __nfweak void ConfigurationManager_EnumerateConfigurationBlocks() if(InitialiseNetworkDefaultConfig(networkConfig, 0)) { // config block created, store it - ConfigurationManager_StoreConfigurationBlock(networkConfig, DeviceConfigurationOption_Network, 0, sizeof(HAL_Configuration_NetworkInterface), 0); + ConfigurationManager_StoreConfigurationBlock(networkConfig, DeviceConfigurationOption_Network, 0, sizeof(HAL_Configuration_NetworkInterface), 0, false); // have to enumerate again to pick it up networkConfigs = (HAL_CONFIGURATION_NETWORK*)ConfigurationManager_FindNetworkConfigurationBlocks((uint32_t)&__nanoConfig_start__, (uint32_t)&__nanoConfig_end__); @@ -146,7 +146,7 @@ __nfweak bool ConfigurationManager_GetConfigurationBlock(void* configurationBloc // NOTE: because inserting or removing a configuration block it's very 'RAM expensive' we choose not to support those operations // the host debugger will have to be used to manage these operations on the device configuration collection // it's implemented with 'weak' attribute so it can be replaced at target level if a different persistance mechanism is used -__nfweak bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, DeviceConfigurationOption configuration, uint32_t configurationIndex, uint32_t blockSize, uint32_t offset) +__nfweak bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, DeviceConfigurationOption configuration, uint32_t configurationIndex, uint32_t blockSize, uint32_t offset, bool done) { ByteAddress storageAddress = 0; bool requiresEnumeration = FALSE; @@ -233,9 +233,6 @@ __nfweak bool ConfigurationManager_StoreConfigurationBlock(void* configurationBl // set storage address as the start of the flash configuration sector, plus the requested offset storageAddress = (ByteAddress)&__nanoConfig_start__ + offset; - // always enumerate the blocks again after storing it - requiresEnumeration = TRUE; - // for save all the block size has to be provided, check that if(blockSize == 0) { @@ -246,7 +243,10 @@ __nfweak bool ConfigurationManager_StoreConfigurationBlock(void* configurationBl // copy the config block content to the config block storage success = STM32FlashDriver_Write(NULL, storageAddress, blockSize, (unsigned char*)configurationBlock, true); - if(success == TRUE && requiresEnumeration) + // enumeration is required after we are DONE with SUCCESSFULLY storing all the config chunks + requiresEnumeration = (success && done); + + if(requiresEnumeration) { // free the current allocation(s) platform_free(g_TargetConfiguration.NetworkInterfaceConfigs); diff --git a/targets/CMSIS-OS/ChibiOS/nanoBooter/WireProtocol_MonitorCommands.c b/targets/CMSIS-OS/ChibiOS/nanoBooter/WireProtocol_MonitorCommands.c index 0449a8125c..0c67fb515a 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoBooter/WireProtocol_MonitorCommands.c +++ b/targets/CMSIS-OS/ChibiOS/nanoBooter/WireProtocol_MonitorCommands.c @@ -262,7 +262,7 @@ int Monitor_UpdateConfiguration(WP_Message* message) case DeviceConfigurationOption_Wireless80211Network: case DeviceConfigurationOption_X509CaRootBundle: case DeviceConfigurationOption_All: - if(ConfigurationManager_StoreConfigurationBlock(cmd->Data, (DeviceConfigurationOption)cmd->Configuration, cmd->BlockIndex, cmd->Length, cmd->Offset) == true) + if(ConfigurationManager_StoreConfigurationBlock(cmd->Data, (DeviceConfigurationOption)cmd->Configuration, cmd->BlockIndex, cmd->Length, cmd->Offset, cmd->Done) == true) { cmdReply.ErrorCode = 0; success = true; diff --git a/targets/FreeRTOS/NXP/common/targetHAL_ConfigurationManager.cpp b/targets/FreeRTOS/NXP/common/targetHAL_ConfigurationManager.cpp index 47b53863b1..302b948528 100644 --- a/targets/FreeRTOS/NXP/common/targetHAL_ConfigurationManager.cpp +++ b/targets/FreeRTOS/NXP/common/targetHAL_ConfigurationManager.cpp @@ -129,7 +129,7 @@ bool ConfigurationManager_GetConfigurationBlock(void* configurationBlock, Device // Stores the configuration block to the configuration flash sector // NOTE: because inserting or removing a configuration block it's very 'RAM expensive' we choose not to support those operations // the host debugger will have to be used to manage these operations on the device configuration collection -bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, DeviceConfigurationOption configuration, uint32_t configurationIndex, uint32_t blockSize, uint32_t offset) +bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, DeviceConfigurationOption configuration, uint32_t configurationIndex, uint32_t blockSize, uint32_t offset, bool done) { ByteAddress storageAddress = 0; bool requiresEnumeration = FALSE; @@ -216,7 +216,10 @@ bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, Devi // copy the config block content to the config block storage success = iMXRTFlexSPIDriver_Write(NULL, storageAddress, blockSize, (unsigned char*)configurationBlock, false); - if(success == TRUE && requiresEnumeration) + // enumeration is required after we are DONE with SUCCESSFULLY storing all the config chunks + requiresEnumeration = (success && done); + + if(requiresEnumeration) { // free the current allocation(s) platform_free(g_TargetConfiguration.NetworkInterfaceConfigs); diff --git a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_ConfigurationManager.cpp b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_ConfigurationManager.cpp index a04458d1bc..e4152ac93f 100644 --- a/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_ConfigurationManager.cpp +++ b/targets/FreeRTOS_ESP32/ESP32_WROOM_32/nanoCLR/targetHAL_ConfigurationManager.cpp @@ -651,7 +651,7 @@ bool ConfigurationManager_StoreConfigurationBlockAll(void* configurationBlock, u // true - OK // false- Error/Not found // -bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, DeviceConfigurationOption configuration, uint32_t configurationIndex, uint32_t blockSize, uint32_t offset) +bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, DeviceConfigurationOption configuration, uint32_t configurationIndex, uint32_t blockSize, uint32_t offset, bool done) { bool result = false; bool requiresEnumeration = false; @@ -662,38 +662,45 @@ bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, Devi #endif if (configuration == DeviceConfigurationOption_All) - return ConfigurationManager_StoreConfigurationBlockAll(configurationBlock, blockSize, offset); - - if (configuration == DeviceConfigurationOption_Network) { - // set blob size - blobSize = sizeof(HAL_Configuration_NetworkInterface); - } - else if (configuration == DeviceConfigurationOption_Wireless80211Network) - { - // set blob size - blobSize = sizeof(HAL_Configuration_Wireless80211); - } - else if (configuration == DeviceConfigurationOption_WirelessNetworkAP) - { - // set blob size - blobSize = sizeof(HAL_Configuration_WirelessAP); - } - else if (configuration == DeviceConfigurationOption_X509CaRootBundle) - { - // set blob size ( Total size of X509 certificate ) - // because X509 certificate has a variable length need to compute the block size in two steps - blobSize = offsetof(HAL_Configuration_X509CaRootBundle, Certificate); - blobSize += ((HAL_Configuration_X509CaRootBundle*)configurationBlock)->CertificateSize; + result = ConfigurationManager_StoreConfigurationBlockAll(configurationBlock, blockSize, offset); -#ifdef DEBUG_CONFIG - ets_printf("StoreConfig x509 blobSize:%d, certsize:%d", blobSize, ((HAL_Configuration_X509CaRootBundle*)configurationBlock)->CertificateSize); -#endif + // enumeration is required after we are DONE with SUCCESSFULLY storing all the config chunks + requiresEnumeration = (result && done); } else { - // Invalid Config - return false; + if (configuration == DeviceConfigurationOption_Network) + { + // set blob size + blobSize = sizeof(HAL_Configuration_NetworkInterface); + } + else if (configuration == DeviceConfigurationOption_Wireless80211Network) + { + // set blob size + blobSize = sizeof(HAL_Configuration_Wireless80211); + } + else if (configuration == DeviceConfigurationOption_WirelessNetworkAP) + { + // set blob size + blobSize = sizeof(HAL_Configuration_WirelessAP); + } + else if (configuration == DeviceConfigurationOption_X509CaRootBundle) + { + // set blob size ( Total size of X509 certificate ) + // because X509 certificate has a variable length need to compute the block size in two steps + blobSize = offsetof(HAL_Configuration_X509CaRootBundle, Certificate); + blobSize += ((HAL_Configuration_X509CaRootBundle*)configurationBlock)->CertificateSize; + + #ifdef DEBUG_CONFIG + ets_printf("StoreConfig x509 blobSize:%d, certsize:%d", blobSize, ((HAL_Configuration_X509CaRootBundle*)configurationBlock)->CertificateSize); + #endif + } + else + { + // Invalid Config + return false; + } } // Anything to save @@ -745,5 +752,5 @@ bool ConfigurationManager_UpdateConfigurationBlock(void* configurationBlock, Dev return FALSE; } - return ConfigurationManager_StoreConfigurationBlock(configurationBlock, configuration, configurationIndex, blockSize, 0); + return ConfigurationManager_StoreConfigurationBlock(configurationBlock, configuration, configurationIndex, blockSize, 0, false); } diff --git a/targets/TI-SimpleLink/common/targetHAL_ConfigurationManager_CC13x2_26x2.cpp b/targets/TI-SimpleLink/common/targetHAL_ConfigurationManager_CC13x2_26x2.cpp index bc3a3461c6..1361b1b78f 100644 --- a/targets/TI-SimpleLink/common/targetHAL_ConfigurationManager_CC13x2_26x2.cpp +++ b/targets/TI-SimpleLink/common/targetHAL_ConfigurationManager_CC13x2_26x2.cpp @@ -130,7 +130,7 @@ void ConfigurationManager_EnumerateConfigurationBlocks() if(InitialiseNetworkDefaultConfig(networkConfig, 0)) { // config block created, store it - ConfigurationManager_StoreConfigurationBlock(networkConfig, DeviceConfigurationOption_Network, 0, sizeof(HAL_Configuration_NetworkInterface), 0); + ConfigurationManager_StoreConfigurationBlock(networkConfig, DeviceConfigurationOption_Network, 0, sizeof(HAL_Configuration_NetworkInterface), 0, false); // have to enumerate again to pick it up networkConfigs = (HAL_CONFIGURATION_NETWORK*)ConfigurationManagerCC13x2_26x2_FindNetworkConfigurationBlocks(); @@ -359,8 +359,11 @@ uint8_t GetSecurityType(AuthenticationType authentication) } // Stores the configuration block to the file system -bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, DeviceConfigurationOption configuration, uint32_t configurationIndex, uint32_t blockSize, uint32_t offset) +bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, DeviceConfigurationOption configuration, uint32_t configurationIndex, uint32_t blockSize, uint32_t offset, bool done) { + // this platform doesn't need to handle this + (void)done; + bool requiresEnumeration = false; bool success = false; @@ -470,7 +473,7 @@ bool ConfigurationManager_UpdateConfigurationBlock(void* configurationBlock, Dev { case DeviceConfigurationOption_Network: case DeviceConfigurationOption_Wireless80211Network: - return ConfigurationManager_StoreConfigurationBlock(configurationBlock, configuration, configurationIndex, 0, 0); + return ConfigurationManager_StoreConfigurationBlock(configurationBlock, configuration, configurationIndex, 0, 0, false); // this configuration option is not supported case DeviceConfigurationOption_X509CaRootBundle: diff --git a/targets/TI-SimpleLink/common/targetHAL_ConfigurationManager_CC32xx.cpp b/targets/TI-SimpleLink/common/targetHAL_ConfigurationManager_CC32xx.cpp index 15808c7e05..2dd3844d74 100644 --- a/targets/TI-SimpleLink/common/targetHAL_ConfigurationManager_CC32xx.cpp +++ b/targets/TI-SimpleLink/common/targetHAL_ConfigurationManager_CC32xx.cpp @@ -130,7 +130,7 @@ void ConfigurationManager_EnumerateConfigurationBlocks() if(InitialiseNetworkDefaultConfig(networkConfig, 0)) { // config block created, store it - ConfigurationManager_StoreConfigurationBlock(networkConfig, DeviceConfigurationOption_Network, 0, sizeof(HAL_Configuration_NetworkInterface), 0); + ConfigurationManager_StoreConfigurationBlock(networkConfig, DeviceConfigurationOption_Network, 0, sizeof(HAL_Configuration_NetworkInterface), 0, false); // have to enumerate again to pick it up networkConfigs = (HAL_CONFIGURATION_NETWORK*)ConfigurationManagerCC32xx_FindNetworkConfigurationBlocks(); @@ -359,8 +359,11 @@ uint8_t GetSecurityType(AuthenticationType authentication) } // Stores the configuration block to the file system -bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, DeviceConfigurationOption configuration, uint32_t configurationIndex, uint32_t blockSize, uint32_t offset) +bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, DeviceConfigurationOption configuration, uint32_t configurationIndex, uint32_t blockSize, uint32_t offset, bool done) { + // this platform doesn't need to handle this + (void)done; + bool requiresEnumeration = false; bool success = false; @@ -470,7 +473,7 @@ bool ConfigurationManager_UpdateConfigurationBlock(void* configurationBlock, Dev { case DeviceConfigurationOption_Network: case DeviceConfigurationOption_Wireless80211Network: - return ConfigurationManager_StoreConfigurationBlock(configurationBlock, configuration, configurationIndex, 0, 0); + return ConfigurationManager_StoreConfigurationBlock(configurationBlock, configuration, configurationIndex, 0, 0, false); // this configuration option is not supported case DeviceConfigurationOption_X509CaRootBundle: diff --git a/targets/os/win32/nanoCLR/Various.cpp b/targets/os/win32/nanoCLR/Various.cpp index 6158528645..331eff9050 100644 --- a/targets/os/win32/nanoCLR/Various.cpp +++ b/targets/os/win32/nanoCLR/Various.cpp @@ -71,7 +71,7 @@ bool ConfigurationManager_GetConfigurationBlock(void* configurationBlock, Device return true; } -bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, DeviceConfigurationOption configuration, uint32_t configurationIndex, uint32_t blockSize) +bool ConfigurationManager_StoreConfigurationBlock(void* configurationBlock, DeviceConfigurationOption configuration, uint32_t configurationIndex, uint32_t blockSize, bool done) { return true; }