rtos: chibios: fix version display

The field 'struct chibios_chdebug::ch_version' is 16 bits wide, so
using le_to_h_u32() and be_to_h_u32() overflows in the following
fields of the struct.

Restrict the endianness conversion to 16 bits and use the target
endianness dependent target_buffer_get_u16().
Convert the 'struct chibios_chdebug::ch_version' to an array of
uint8_t.

Change-Id: Iaa80e9cb1a65c27512919398b8ffbf14e5c240cd
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8473
Tested-by: jenkins
This commit is contained in:
Antonio Borneo 2024-09-01 14:45:36 +02:00
parent 1173473f66
commit 8edfdb02ed
1 changed files with 2 additions and 8 deletions

View File

@ -31,7 +31,7 @@ struct chibios_chdebug {
char ch_identifier[4]; /**< @brief Always set to "main". */
uint8_t ch_zero; /**< @brief Must be zero. */
uint8_t ch_size; /**< @brief Size of this structure. */
uint16_t ch_version; /**< @brief Encoded ChibiOS/RT version. */
uint8_t ch_version[2]; /**< @brief Encoded ChibiOS/RT version. */
uint8_t ch_ptrsize; /**< @brief Size of a pointer. */
uint8_t ch_timesize; /**< @brief Size of a @p systime_t. */
uint8_t ch_threadsize; /**< @brief Size of a @p Thread struct. */
@ -171,13 +171,7 @@ static int chibios_update_memory_signature(struct rtos *rtos)
" expected. Assuming compatibility...");
}
/* Convert endianness of version field */
const uint8_t *versiontarget = (const uint8_t *)
&signature->ch_version;
signature->ch_version = rtos->target->endianness == TARGET_LITTLE_ENDIAN ?
le_to_h_u32(versiontarget) : be_to_h_u32(versiontarget);
const uint16_t ch_version = signature->ch_version;
const uint16_t ch_version = target_buffer_get_u16(rtos->target, signature->ch_version);
LOG_INFO("Successfully loaded memory map of ChibiOS/RT target "
"running version %i.%i.%i", GET_CH_KERNEL_MAJOR(ch_version),
GET_CH_KERNEL_MINOR(ch_version), GET_CH_KERNEL_PATCH(ch_version));