From: openocd-gerrit <ope...@us...> - 2023-01-11 17:03:04
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "Main OpenOCD repository". The branch, master has been updated via d92ebb5ab43f6c6a900c6beb0bc426573058c359 (commit) via 7dd5b6a4645cf0ce9c635a7fc8b140575385c827 (commit) from dfe57baa16cdbc0dc2ae7182b5b3831028637223 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit d92ebb5ab43f6c6a900c6beb0bc426573058c359 Author: Antonio Borneo <bor...@gm...> Date: Fri Jan 6 12:40:01 2023 +0100 jtag: esp_usb_jtag: remove macro __packed In FreeBSB 13.0 the build fails due to redefined macro __packed. src/jtag/drivers/esp_usb_jtag.c:19:9: error: '__packed' macro redefined [-Werror,-Wmacro-redefined] #define __packed __attribute__((packed)) ^ /usr/include/sys/cdefs.h:223:9: note: previous definition is here #define __packed __attribute__((__packed__)) ^ 1 error generated. Drop the macro and align the code with the other files in OpenOCD project, where the attribute is directly applied without using a macro. Change-Id: I89ae943e77036206d40d4d54172cd4a73e76e5c5 Signed-off-by: Antonio Borneo <bor...@gm...> Reported-by: Wojciech Puchar <wo...@pu...> Reviewed-on: https://review.openocd.org/c/openocd/+/7435 Tested-by: jenkins Reviewed-by: Erhan Kurubas <erh...@es...> diff --git a/src/jtag/drivers/esp_usb_jtag.c b/src/jtag/drivers/esp_usb_jtag.c index 65293ee37..dd96f4b39 100644 --- a/src/jtag/drivers/esp_usb_jtag.c +++ b/src/jtag/drivers/esp_usb_jtag.c @@ -16,8 +16,6 @@ #include "bitq.h" #include "libusb_helper.h" -#define __packed __attribute__((packed)) - /* Holy Crap, it's protocol documentation, and it's even vendor-provided! @@ -110,7 +108,7 @@ descriptor. struct jtag_proto_caps_hdr { uint8_t proto_ver; /* Protocol version. Expects JTAG_PROTO_CAPS_VER for now. */ uint8_t length; /* of this plus any following descriptors */ -} __packed; +} __attribute__((packed)); /* start of the descriptor headers */ #define JTAG_BUILTIN_DESCR_START_OFF 0 /* Devices with builtin usb jtag */ @@ -133,7 +131,7 @@ of caps header to assume this. If no such caps exist, assume a minimum (in) buff struct jtag_gen_hdr { uint8_t type; uint8_t length; -} __packed; +} __attribute__((packed)); struct jtag_proto_caps_speed_apb { uint8_t type; /* Type, always JTAG_PROTO_CAPS_SPEED_APB_TYPE */ @@ -141,7 +139,7 @@ struct jtag_proto_caps_speed_apb { uint8_t apb_speed_10khz[2]; /* ABP bus speed, in 10KHz increments. Base speed is half this. */ uint8_t div_min[2]; /* minimum divisor (to base speed), inclusive */ uint8_t div_max[2]; /* maximum divisor (to base speed), inclusive */ -} __packed; +} __attribute__((packed)); #define JTAG_PROTO_CAPS_DATA_LEN 255 #define JTAG_PROTO_CAPS_SPEED_APB_TYPE 1 commit 7dd5b6a4645cf0ce9c635a7fc8b140575385c827 Author: Marcin Niestroj <m.n...@em...v> Date: Mon Jan 2 08:04:06 2023 +0100 rtt: fix corner-cases of finding control block This patch fixes two corner-cases of finding RTT control block. The first one is when there was a partial match (even single byte) at the end of loaded buffer (uint8_t buf[1024]), but this was not part of full match. In that case `cb_offset` was not updated correctly and the returned `*address` was lower by the legth of the partial match. In case of searched 'SEGGER RTT' (the default control block ID) string, it was enough to match `buf[1023] == 'S'`, which is quite likely to happen, and the `*address` was offset by 1 (e.g. it was 0x20000fff instead of 0x20010000). Updating (or even maintaining) `cb_offset` is not needed, as start address of control block can be calculated based on memory address that was loaded into `uint8_t buf[1024]`, the offset within this buffer and the length of expected string. The second issue is when control block is prepended with a byte that matches first ID character, e.g. there is `SEGGER RTT` control block ID is prepended by another `S`, making memory contents be `SSEGGER RTT`. In that case there was no match found. Fix that issue by making sure that tested byte is always compared with first byte of expected control block ID. While at it, change names of local variables to better describe their meaning. Signed-off-by: Marcin Niestroj <m.n...@em...v> Change-Id: I12aa6e202bf12bedcbb888ab595751a2a2518a24 Reviewed-on: https://review.openocd.org/c/openocd/+/7429 Tested-by: jenkins Reviewed-by: Antonio Borneo <bor...@gm...> diff --git a/src/target/rtt.c b/src/target/rtt.c index ef2c45d69..b14c42f91 100644 --- a/src/target/rtt.c +++ b/src/target/rtt.c @@ -241,43 +241,37 @@ int target_rtt_find_control_block(struct target *target, target_addr_t *address, size_t size, const char *id, bool *found, void *user_data) { + target_addr_t address_end = *address + size; uint8_t buf[1024]; *found = false; - size_t j = 0; - size_t cb_offset = 0; + size_t id_matched_length = 0; const size_t id_length = strlen(id); LOG_INFO("rtt: Searching for control block '%s'", id); - for (target_addr_t addr = 0; addr < size; addr = addr + sizeof(buf)) { + for (target_addr_t addr = *address; addr < address_end; addr += sizeof(buf)) { int ret; - const size_t buf_size = MIN(sizeof(buf), size - addr); - ret = target_read_buffer(target, *address + addr, buf_size, buf); + const size_t buf_size = MIN(sizeof(buf), address_end - addr); + ret = target_read_buffer(target, addr, buf_size, buf); if (ret != ERROR_OK) return ret; - size_t start = 0; - size_t i = 0; - - while (i < buf_size) { - if (buf[i] != id[j]) { - start++; - cb_offset++; - i = start; - j = 0; - - continue; + for (size_t buf_off = 0; buf_off < buf_size; buf_off++) { + if (id_matched_length > 0 && + buf[buf_off] != id[id_matched_length]) { + /* Start from beginning */ + id_matched_length = 0; } - i++; - j++; + if (buf[buf_off] == id[id_matched_length]) + id_matched_length++; - if (j == id_length) { - *address = *address + cb_offset; + if (id_matched_length == id_length) { + *address = addr + buf_off + 1 - id_length; *found = true; return ERROR_OK; } ----------------------------------------------------------------------- Summary of changes: src/jtag/drivers/esp_usb_jtag.c | 8 +++----- src/target/rtt.c | 34 ++++++++++++++-------------------- 2 files changed, 17 insertions(+), 25 deletions(-) hooks/post-receive -- Main OpenOCD repository |