cmd/mem.c: fix wrong use of ifdef, drop pointless SUPPORT_64BIT_DATA macro

The macro MEM_SUPPORT_64BIT_DATA is always defined, as either 1 or 0,
so using "#ifdef MEM_SUPPORT_64BIT_DATA" doesn't do what one
expects.

This means that currently all 32 bit targets get compiled with the .q
suffix mentioned in the help text, while it doesn't actually work.

Use the proper "#if" instead.

There's really no point defining another similarly-named macro with
exactly the same value, so just use MEM_SUPPORT_64BIT_DATA throughout.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
This commit is contained in:
Rasmus Villemoes 2024-01-03 11:47:08 +01:00 committed by Tom Rini
parent 13f4c85828
commit 4762c51562

View file

@ -35,11 +35,9 @@
DECLARE_GLOBAL_DATA_PTR; DECLARE_GLOBAL_DATA_PTR;
/* Create a compile-time value */ /* Create a compile-time value */
#ifdef MEM_SUPPORT_64BIT_DATA #if MEM_SUPPORT_64BIT_DATA
#define SUPPORT_64BIT_DATA 1
#define HELP_Q ", .q" #define HELP_Q ", .q"
#else #else
#define SUPPORT_64BIT_DATA 0
#define HELP_Q "" #define HELP_Q ""
#endif #endif
@ -131,7 +129,7 @@ static int do_mem_nm(struct cmd_tbl *cmdtp, int flag, int argc,
static int do_mem_mw(struct cmd_tbl *cmdtp, int flag, int argc, static int do_mem_mw(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[]) char *const argv[])
{ {
ulong writeval; /* 64-bit if SUPPORT_64BIT_DATA */ ulong writeval; /* 64-bit if MEM_SUPPORT_64BIT_DATA */
ulong addr, count; ulong addr, count;
int size; int size;
void *buf, *start; void *buf, *start;
@ -152,7 +150,7 @@ static int do_mem_mw(struct cmd_tbl *cmdtp, int flag, int argc,
/* Get the value to write. /* Get the value to write.
*/ */
if (SUPPORT_64BIT_DATA) if (MEM_SUPPORT_64BIT_DATA)
writeval = simple_strtoull(argv[2], NULL, 16); writeval = simple_strtoull(argv[2], NULL, 16);
else else
writeval = hextoul(argv[2], NULL); writeval = hextoul(argv[2], NULL);
@ -170,7 +168,7 @@ static int do_mem_mw(struct cmd_tbl *cmdtp, int flag, int argc,
while (count-- > 0) { while (count-- > 0) {
if (size == 4) if (size == 4)
*((u32 *)buf) = (u32)writeval; *((u32 *)buf) = (u32)writeval;
else if (SUPPORT_64BIT_DATA && size == 8) else if (MEM_SUPPORT_64BIT_DATA && size == 8)
*((ulong *)buf) = writeval; *((ulong *)buf) = writeval;
else if (size == 2) else if (size == 2)
*((u16 *)buf) = (u16)writeval; *((u16 *)buf) = (u16)writeval;
@ -248,7 +246,7 @@ static int do_mem_cmp(struct cmd_tbl *cmdtp, int flag, int argc,
int rcode = 0; int rcode = 0;
const char *type; const char *type;
const void *buf1, *buf2, *base; const void *buf1, *buf2, *base;
ulong word1, word2; /* 64-bit if SUPPORT_64BIT_DATA */ ulong word1, word2; /* 64-bit if MEM_SUPPORT_64BIT_DATA */
if (argc != 4) if (argc != 4)
return CMD_RET_USAGE; return CMD_RET_USAGE;
@ -276,7 +274,7 @@ static int do_mem_cmp(struct cmd_tbl *cmdtp, int flag, int argc,
if (size == 4) { if (size == 4) {
word1 = *(u32 *)buf1; word1 = *(u32 *)buf1;
word2 = *(u32 *)buf2; word2 = *(u32 *)buf2;
} else if (SUPPORT_64BIT_DATA && size == 8) { } else if (MEM_SUPPORT_64BIT_DATA && size == 8) {
word1 = *(ulong *)buf1; word1 = *(ulong *)buf1;
word2 = *(ulong *)buf2; word2 = *(ulong *)buf2;
} else if (size == 2) { } else if (size == 2) {
@ -528,7 +526,7 @@ static int do_mem_loop(struct cmd_tbl *cmdtp, int flag, int argc,
{ {
ulong addr, length, i, bytes; ulong addr, length, i, bytes;
int size; int size;
volatile ulong *llp; /* 64-bit if SUPPORT_64BIT_DATA */ volatile ulong *llp; /* 64-bit if MEM_SUPPORT_64BIT_DATA */
volatile u32 *longp; volatile u32 *longp;
volatile u16 *shortp; volatile u16 *shortp;
volatile u8 *cp; volatile u8 *cp;
@ -559,7 +557,7 @@ static int do_mem_loop(struct cmd_tbl *cmdtp, int flag, int argc,
* If we have only one object, just run infinite loops. * If we have only one object, just run infinite loops.
*/ */
if (length == 1) { if (length == 1) {
if (SUPPORT_64BIT_DATA && size == 8) { if (MEM_SUPPORT_64BIT_DATA && size == 8) {
llp = (ulong *)buf; llp = (ulong *)buf;
for (;;) for (;;)
i = *llp; i = *llp;
@ -579,7 +577,7 @@ static int do_mem_loop(struct cmd_tbl *cmdtp, int flag, int argc,
i = *cp; i = *cp;
} }
if (SUPPORT_64BIT_DATA && size == 8) { if (MEM_SUPPORT_64BIT_DATA && size == 8) {
for (;;) { for (;;) {
llp = (ulong *)buf; llp = (ulong *)buf;
i = length; i = length;
@ -620,8 +618,8 @@ static int do_mem_loopw(struct cmd_tbl *cmdtp, int flag, int argc,
{ {
ulong addr, length, i, bytes; ulong addr, length, i, bytes;
int size; int size;
volatile ulong *llp; /* 64-bit if SUPPORT_64BIT_DATA */ volatile ulong *llp; /* 64-bit if MEM_SUPPORT_64BIT_DATA */
ulong data; /* 64-bit if SUPPORT_64BIT_DATA */ ulong data; /* 64-bit if MEM_SUPPORT_64BIT_DATA */
volatile u32 *longp; volatile u32 *longp;
volatile u16 *shortp; volatile u16 *shortp;
volatile u8 *cp; volatile u8 *cp;
@ -646,7 +644,7 @@ static int do_mem_loopw(struct cmd_tbl *cmdtp, int flag, int argc,
length = hextoul(argv[2], NULL); length = hextoul(argv[2], NULL);
/* data to write */ /* data to write */
if (SUPPORT_64BIT_DATA) if (MEM_SUPPORT_64BIT_DATA)
data = simple_strtoull(argv[3], NULL, 16); data = simple_strtoull(argv[3], NULL, 16);
else else
data = hextoul(argv[3], NULL); data = hextoul(argv[3], NULL);
@ -658,7 +656,7 @@ static int do_mem_loopw(struct cmd_tbl *cmdtp, int flag, int argc,
* If we have only one object, just run infinite loops. * If we have only one object, just run infinite loops.
*/ */
if (length == 1) { if (length == 1) {
if (SUPPORT_64BIT_DATA && size == 8) { if (MEM_SUPPORT_64BIT_DATA && size == 8) {
llp = (ulong *)buf; llp = (ulong *)buf;
for (;;) for (;;)
*llp = data; *llp = data;
@ -678,7 +676,7 @@ static int do_mem_loopw(struct cmd_tbl *cmdtp, int flag, int argc,
*cp = data; *cp = data;
} }
if (SUPPORT_64BIT_DATA && size == 8) { if (MEM_SUPPORT_64BIT_DATA && size == 8) {
for (;;) { for (;;) {
llp = (ulong *)buf; llp = (ulong *)buf;
i = length; i = length;
@ -1151,7 +1149,7 @@ mod_mem(struct cmd_tbl *cmdtp, int incrflag, int flag, int argc,
char *const argv[]) char *const argv[])
{ {
ulong addr; ulong addr;
ulong i; /* 64-bit if SUPPORT_64BIT_DATA */ ulong i; /* 64-bit if MEM_SUPPORT_64BIT_DATA */
int nbytes, size; int nbytes, size;
void *ptr = NULL; void *ptr = NULL;
@ -1186,7 +1184,7 @@ mod_mem(struct cmd_tbl *cmdtp, int incrflag, int flag, int argc,
printf("%08lx:", addr); printf("%08lx:", addr);
if (size == 4) if (size == 4)
printf(" %08x", *((u32 *)ptr)); printf(" %08x", *((u32 *)ptr));
else if (SUPPORT_64BIT_DATA && size == 8) else if (MEM_SUPPORT_64BIT_DATA && size == 8)
printf(" %0lx", *((ulong *)ptr)); printf(" %0lx", *((ulong *)ptr));
else if (size == 2) else if (size == 2)
printf(" %04x", *((u16 *)ptr)); printf(" %04x", *((u16 *)ptr));
@ -1211,7 +1209,7 @@ mod_mem(struct cmd_tbl *cmdtp, int incrflag, int flag, int argc,
#endif #endif
else { else {
char *endp; char *endp;
if (SUPPORT_64BIT_DATA) if (MEM_SUPPORT_64BIT_DATA)
i = simple_strtoull(console_buffer, &endp, 16); i = simple_strtoull(console_buffer, &endp, 16);
else else
i = hextoul(console_buffer, &endp); i = hextoul(console_buffer, &endp);
@ -1222,7 +1220,7 @@ mod_mem(struct cmd_tbl *cmdtp, int incrflag, int flag, int argc,
bootretry_reset_cmd_timeout(); bootretry_reset_cmd_timeout();
if (size == 4) if (size == 4)
*((u32 *)ptr) = i; *((u32 *)ptr) = i;
else if (SUPPORT_64BIT_DATA && size == 8) else if (MEM_SUPPORT_64BIT_DATA && size == 8)
*((ulong *)ptr) = i; *((ulong *)ptr) = i;
else if (size == 2) else if (size == 2)
*((u16 *)ptr) = i; *((u16 *)ptr) = i;