Skip to content

Commit e8a4b9e

Browse files
ycsinjhedberg
authored andcommitted
shell: modules: devmem: support 64-bit read & write
Add support for 64-bit devmem operations for 64-bit devices. Signed-off-by: Sergii Vystoropskyi <[email protected]> Signed-off-by: Yong Cong Sin <[email protected]> Signed-off-by: Yong Cong Sin <[email protected]>
1 parent df1cb88 commit e8a4b9e

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

subsys/shell/modules/devmem_service.c

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static bool littleendian;
4242

4343
static int memory_dump(const struct shell *sh, mem_addr_t phys_addr, size_t size, uint8_t width)
4444
{
45-
uint32_t value;
45+
uint64_t value;
4646
size_t data_offset;
4747
mm_reg_t addr;
4848
const size_t vsize = width / BITS_PER_BYTE;
@@ -82,6 +82,26 @@ static int memory_dump(const struct shell *sh, mem_addr_t phys_addr, size_t size
8282
value >>= 8;
8383
hex_data[data_offset + 3] = (uint8_t)value;
8484
break;
85+
#ifdef CONFIG_64BIT
86+
case 64:
87+
value = sys_le64_to_cpu(sys_read64(addr + data_offset));
88+
hex_data[data_offset] = (uint8_t)value;
89+
value >>= 8;
90+
hex_data[data_offset + 1] = (uint8_t)value;
91+
value >>= 8;
92+
hex_data[data_offset + 2] = (uint8_t)value;
93+
value >>= 8;
94+
hex_data[data_offset + 3] = (uint8_t)value;
95+
value >>= 8;
96+
hex_data[data_offset + 4] = (uint8_t)value;
97+
value >>= 8;
98+
hex_data[data_offset + 5] = (uint8_t)value;
99+
value >>= 8;
100+
hex_data[data_offset + 6] = (uint8_t)value;
101+
value >>= 8;
102+
hex_data[data_offset + 7] = (uint8_t)value;
103+
break;
104+
#endif /* CONFIG_64BIT */
85105
default:
86106
shell_fprintf(sh, SHELL_NORMAL, "Incorrect data width\n");
87107
return -EINVAL;
@@ -253,7 +273,7 @@ static int cmd_load(const struct shell *sh, size_t argc, char **argv)
253273

254274
static int memory_read(const struct shell *sh, mem_addr_t addr, uint8_t width)
255275
{
256-
uint32_t value;
276+
uint64_t value;
257277
int err = 0;
258278

259279
switch (width) {
@@ -266,14 +286,19 @@ static int memory_read(const struct shell *sh, mem_addr_t addr, uint8_t width)
266286
case 32:
267287
value = sys_read32(addr);
268288
break;
289+
#ifdef CONFIG_64BIT
290+
case 64:
291+
value = sys_read64(addr);
292+
break;
293+
#endif /* CONFIG_64BIT */
269294
default:
270295
shell_fprintf(sh, SHELL_NORMAL, "Incorrect data width\n");
271296
err = -EINVAL;
272297
break;
273298
}
274299

275300
if (err == 0) {
276-
shell_fprintf(sh, SHELL_NORMAL, "Read value 0x%x\n", value);
301+
shell_fprintf(sh, SHELL_NORMAL, "Read value 0x%llx\n", value);
277302
}
278303

279304
return err;
@@ -293,6 +318,11 @@ static int memory_write(const struct shell *sh, mem_addr_t addr, uint8_t width,
293318
case 32:
294319
sys_write32(value, addr);
295320
break;
321+
#ifdef CONFIG_64BIT
322+
case 64:
323+
sys_write64(value, addr);
324+
break;
325+
#endif /* CONFIG_64BIT */
296326
default:
297327
shell_fprintf(sh, SHELL_NORMAL, "Incorrect data width\n");
298328
err = -EINVAL;
@@ -306,7 +336,7 @@ static int memory_write(const struct shell *sh, mem_addr_t addr, uint8_t width,
306336
static int cmd_devmem(const struct shell *sh, size_t argc, char **argv)
307337
{
308338
mem_addr_t phys_addr, addr;
309-
uint32_t value = 0;
339+
uint64_t value = 0;
310340
uint8_t width;
311341

312342
phys_addr = strtoul(argv[1], NULL, 16);
@@ -335,9 +365,9 @@ static int cmd_devmem(const struct shell *sh, size_t argc, char **argv)
335365
* this value at the address provided
336366
*/
337367

338-
value = strtoul(argv[3], NULL, 16);
368+
value = (uint64_t)strtoull(argv[3], NULL, 16);
339369

340-
shell_fprintf(sh, SHELL_NORMAL, "Writing value 0x%x\n", value);
370+
shell_fprintf(sh, SHELL_NORMAL, "Writing value 0x%llx\n", value);
341371

342372
return memory_write(sh, addr, width, value);
343373
}

0 commit comments

Comments
 (0)