From 44014bf909d3fc0b5056901cd6726f484ec8b108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Wed, 24 Jul 2019 17:03:19 +0100 Subject: [PATCH] Fix OemInfo command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Current implementation was missing the new fields with target and platform names. - Improve code of NFReleaseInfo::Init(). - Improve code on GetClrReleaseInfo() to use static values for string lengths. Signed-off-by: José Simões --- src/CLR/Debugger/Debugger.cpp | 6 ++-- src/CLR/Debugger/Debugger_stub.cpp | 32 +++++++++++++------ src/CLR/Include/WireProtocol.h | 5 +-- .../nanoBooter/WireProtocol_MonitorCommands.c | 6 ++-- 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/CLR/Debugger/Debugger.cpp b/src/CLR/Debugger/Debugger.cpp index 339ed1e496..f8620c2e6a 100644 --- a/src/CLR/Debugger/Debugger.cpp +++ b/src/CLR/Debugger/Debugger.cpp @@ -1077,11 +1077,11 @@ static void GetClrReleaseInfo(CLR_DBG_Commands::Debugging_Execution_QueryCLRCapa VERSION_BUILD, VERSION_REVISION, OEMSYSTEMINFOSTRING, - hal_strlen_s(OEMSYSTEMINFOSTRING), + ARRAYSIZE(OEMSYSTEMINFOSTRING), TARGETNAMESTRING, - hal_strlen_s(TARGETNAMESTRING), + ARRAYSIZE(TARGETNAMESTRING), PLATFORMNAMESTRING, - hal_strlen_s(PLATFORMNAMESTRING) + ARRAYSIZE(PLATFORMNAMESTRING) ); if ( g_CLR_RT_TypeSystem.m_assemblyMscorlib && diff --git a/src/CLR/Debugger/Debugger_stub.cpp b/src/CLR/Debugger/Debugger_stub.cpp index 25a73302cd..bd3e130e99 100644 --- a/src/CLR/Debugger/Debugger_stub.cpp +++ b/src/CLR/Debugger/Debugger_stub.cpp @@ -56,18 +56,32 @@ __nfweak void NFReleaseInfo::Init( const char *platform, size_t platformLen) { + size_t len; + NFVersion::Init( NFReleaseInfo.Version, major, minor, build, revision ); + + // better set these to empty strings, in case there is nothing to fill in NFReleaseInfo.InfoString[ 0 ] = 0; - if ( NULL != info && infoLen > 0 ) + NFReleaseInfo.TargetName[ 0 ] = 0; + NFReleaseInfo.PlatformName[ 0 ] = 0; + + // fill each one, if it was provided + if ( NULL != info ) + { + len = MIN(infoLen, sizeof(NFReleaseInfo.InfoString)); + memcpy(NFReleaseInfo.InfoString, info, len); + } + + if ( NULL != target ) + { + len = MIN(targetLen, sizeof(NFReleaseInfo.TargetName)); + memcpy(NFReleaseInfo.TargetName, target, len); + } + + if ( NULL != platform ) { - size_t len = MIN(infoLen, sizeof(NFReleaseInfo.InfoString)-1); - hal_strncpy_s( (char*)&NFReleaseInfo.InfoString[0], sizeof(NFReleaseInfo.InfoString), info, len ); - - len = MIN(targetLen, sizeof(NFReleaseInfo.TargetName)-1); - hal_strncpy_s( (char*)&NFReleaseInfo.TargetName[0], sizeof(NFReleaseInfo.TargetName), target, len ); - - len = MIN(platformLen, sizeof(NFReleaseInfo.PlatformName)-1); - hal_strncpy_s( (char*)&NFReleaseInfo.PlatformName[0], sizeof(NFReleaseInfo.PlatformName), platform, len ); + len = MIN(platformLen, sizeof(NFReleaseInfo.PlatformName)); + memcpy(NFReleaseInfo.PlatformName, platform, len); } } diff --git a/src/CLR/Include/WireProtocol.h b/src/CLR/Include/WireProtocol.h index 32e727cb84..6a69c75395 100644 --- a/src/CLR/Include/WireProtocol.h +++ b/src/CLR/Include/WireProtocol.h @@ -185,8 +185,9 @@ typedef struct ReleaseInfo { VersionInfo version; - - uint8_t infoString[64-sizeof(VersionInfo)]; + uint8_t InfoString[128]; + uint8_t TargetName[32]; + uint8_t PlatformName[32]; }ReleaseInfo; diff --git a/targets/CMSIS-OS/ChibiOS/nanoBooter/WireProtocol_MonitorCommands.c b/targets/CMSIS-OS/ChibiOS/nanoBooter/WireProtocol_MonitorCommands.c index 10fa7bd287..8c9864b304 100644 --- a/targets/CMSIS-OS/ChibiOS/nanoBooter/WireProtocol_MonitorCommands.c +++ b/targets/CMSIS-OS/ChibiOS/nanoBooter/WireProtocol_MonitorCommands.c @@ -22,9 +22,11 @@ int NanoBooter_GetReleaseInfo(ReleaseInfo* releaseInfo) releaseInfo->version.usMajor = VERSION_MAJOR; releaseInfo->version.usMinor = VERSION_MINOR; releaseInfo->version.usBuild = VERSION_BUILD; - releaseInfo->version.usRevision = 0; + releaseInfo->version.usRevision = VERSION_REVISION; - memcpy(&releaseInfo->infoString, OEMSYSTEMINFOSTRING, sizeof(releaseInfo->infoString)); + memcpy(&releaseInfo->InfoString, OEMSYSTEMINFOSTRING, ARRAYSIZE(OEMSYSTEMINFOSTRING)); + memcpy(&releaseInfo->TargetName, TARGETNAMESTRING, ARRAYSIZE(TARGETNAMESTRING)); + memcpy(&releaseInfo->PlatformName, PLATFORMNAMESTRING, ARRAYSIZE(PLATFORMNAMESTRING)); return true; }