aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPali Rohár2023-01-08 13:53:48 +0100
committerStefan Roese2023-03-01 06:39:17 +0100
commit908801dcfe8a1e45b5e6e37c4b7e43f79dfc36ec (patch)
tree3410e4d72a91130d2da17ea485a1592417815342
parent4941652df5a9a8a9404e64655e3630318247d329 (diff)
tools: kwbimage: Fix dumping register set / DATA commands
Upper-bound for iterating for-loop over register set entries is incorrect. Fix it byt calculating correct number of entries. And fix also dumping the last entry DATA_DELAY, which is the last and not first (zero). Fixes: 1a8e6b63e24f ("tools: kwbimage: Dump kwbimage config file on '-p -1' option") Signed-off-by: Pali Rohár <pali@kernel.org>
-rw-r--r--tools/kwbimage.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/tools/kwbimage.c b/tools/kwbimage.c
index 67b45503e46..1719b0415da 100644
--- a/tools/kwbimage.c
+++ b/tools/kwbimage.c
@@ -2148,6 +2148,7 @@ static int kwbimage_generate_config(void *ptr, struct image_tool_params *params)
struct ext_hdr_v0 *ehdr0;
struct bin_hdr_v0 *bhdr0;
struct opt_hdr_v1 *ohdr;
+ int regset_count;
int params_count;
unsigned offset;
int is_v0_ext;
@@ -2232,18 +2233,20 @@ static int kwbimage_generate_config(void *ptr, struct image_tool_params *params)
cur_idx++;
} else if (ohdr->headertype == OPT_HDR_V1_REGISTER_TYPE) {
regset_hdr = (struct register_set_hdr_v1 *)ohdr;
- for (i = 0;
- i < opt_hdr_v1_size(ohdr) - sizeof(struct opt_hdr_v1) -
- sizeof(regset_hdr->data[0].last_entry);
- i++)
+ if (opt_hdr_v1_size(ohdr) > sizeof(*ohdr))
+ regset_count = (opt_hdr_v1_size(ohdr) - sizeof(*ohdr)) /
+ sizeof(regset_hdr->data[0].entry);
+ else
+ regset_count = 0;
+ for (i = 0; i < regset_count; i++)
fprintf(f, "DATA 0x%08x 0x%08x\n",
le32_to_cpu(regset_hdr->data[i].entry.address),
le32_to_cpu(regset_hdr->data[i].entry.value));
- if (opt_hdr_v1_size(ohdr) - sizeof(struct opt_hdr_v1) >=
- sizeof(regset_hdr->data[0].last_entry)) {
- if (regset_hdr->data[0].last_entry.delay)
+ if (regset_count > 0) {
+ if (regset_hdr->data[regset_count-1].last_entry.delay !=
+ REGISTER_SET_HDR_OPT_DELAY_SDRAM_SETUP)
fprintf(f, "DATA_DELAY %u\n",
- (unsigned)regset_hdr->data[0].last_entry.delay);
+ (unsigned)regset_hdr->data[regset_count-1].last_entry.delay);
else
fprintf(f, "DATA_DELAY SDRAM_SETUP\n");
}