From: Stefan Roese Date: Wed, 3 Jun 2020 07:56:16 +0200 Subject: [PATCH 1/6] Update MEM_SUPPORT_64BIT_DATA to be always defined In-Reply-To: <20200602192642.1.Ibc067a3d1c5425aa60dfb9314a23d6dc5c2e480d@changeid> References: <20200602192642.1.Ibc067a3d1c5425aa60dfb9314a23d6dc5c2e480d@changeid> Message-ID: List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On 03.06.20 03:26, Simon Glass wrote: > Define this macro always so we don't need the preprocessor to check it. > Convert the users to #if instead of #ifdef. > > Note that '#if MEM_SUPPORT_64BIT_DATA' does not give an error if the > macro is not define. It just assumes zero. > > Signed-off-by: Simon Glass Reviewed-by: Stefan Roese Thanks, Stefan > --- > > cmd/mem.c | 54 +++++++++++++++++++++---------------------- > common/command.c | 2 +- > include/compiler.h | 4 +++- > lib/display_options.c | 6 ++--- > 4 files changed, 34 insertions(+), 32 deletions(-) > > diff --git a/cmd/mem.c b/cmd/mem.c > index 9b97f7bf69..fe43427d3c 100644 > --- a/cmd/mem.c > +++ b/cmd/mem.c > @@ -116,7 +116,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, > char *const argv[]) > { > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > u64 writeval; > #else > ulong writeval; > @@ -141,7 +141,7 @@ static int do_mem_mw(struct cmd_tbl *cmdtp, int flag, int argc, > > /* Get the value to write. > */ > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > writeval = simple_strtoull(argv[2], NULL, 16); > #else > writeval = simple_strtoul(argv[2], NULL, 16); > @@ -160,7 +160,7 @@ static int do_mem_mw(struct cmd_tbl *cmdtp, int flag, int argc, > while (count-- > 0) { > if (size == 4) > *((u32 *)buf) = (u32)writeval; > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > else if (size == 8) > *((u64 *)buf) = (u64)writeval; > #endif > @@ -240,7 +240,7 @@ static int do_mem_cmp(struct cmd_tbl *cmdtp, int flag, int argc, > int rcode = 0; > const char *type; > const void *buf1, *buf2, *base; > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > u64 word1, word2; > #else > ulong word1, word2; > @@ -272,7 +272,7 @@ static int do_mem_cmp(struct cmd_tbl *cmdtp, int flag, int argc, > if (size == 4) { > word1 = *(u32 *)buf1; > word2 = *(u32 *)buf2; > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > } else if (size == 8) { > word1 = *(u64 *)buf1; > word2 = *(u64 *)buf2; > @@ -286,7 +286,7 @@ static int do_mem_cmp(struct cmd_tbl *cmdtp, int flag, int argc, > } > if (word1 != word2) { > ulong offset = buf1 - base; > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > printf("%s at 0x%p (%#0*llx) != %s at 0x%p (%#0*llx)\n", > type, (void *)(addr1 + offset), size, word1, > type, (void *)(addr2 + offset), size, word2); > @@ -391,7 +391,7 @@ static int do_mem_loop(struct cmd_tbl *cmdtp, int flag, int argc, > { > ulong addr, length, i, bytes; > int size; > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > volatile u64 *llp; > #endif > volatile u32 *longp; > @@ -424,7 +424,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 (length == 1) { > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > if (size == 8) { > llp = (u64 *)buf; > for (;;) > @@ -446,7 +446,7 @@ static int do_mem_loop(struct cmd_tbl *cmdtp, int flag, int argc, > i = *cp; > } > > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > if (size == 8) { > for (;;) { > llp = (u64 *)buf; > @@ -489,7 +489,7 @@ static int do_mem_loopw(struct cmd_tbl *cmdtp, int flag, int argc, > { > ulong addr, length, i, bytes; > int size; > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > volatile u64 *llp; > u64 data; > #else > @@ -519,7 +519,7 @@ static int do_mem_loopw(struct cmd_tbl *cmdtp, int flag, int argc, > length = simple_strtoul(argv[2], NULL, 16); > > /* data to write */ > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > data = simple_strtoull(argv[3], NULL, 16); > #else > data = simple_strtoul(argv[3], NULL, 16); > @@ -532,7 +532,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 (length == 1) { > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > if (size == 8) { > llp = (u64 *)buf; > for (;;) > @@ -554,7 +554,7 @@ static int do_mem_loopw(struct cmd_tbl *cmdtp, int flag, int argc, > *cp = data; > } > > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > if (size == 8) { > for (;;) { > llp = (u64 *)buf; > @@ -1023,7 +1023,7 @@ mod_mem(struct cmd_tbl *cmdtp, int incrflag, int flag, int argc, > char *const argv[]) > { > ulong addr; > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > u64 i; > #else > ulong i; > @@ -1062,7 +1062,7 @@ mod_mem(struct cmd_tbl *cmdtp, int incrflag, int flag, int argc, > printf("%08lx:", addr); > if (size == 4) > printf(" %08x", *((u32 *)ptr)); > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > else if (size == 8) > printf(" %016llx", *((u64 *)ptr)); > #endif > @@ -1089,7 +1089,7 @@ mod_mem(struct cmd_tbl *cmdtp, int incrflag, int flag, int argc, > #endif > else { > char *endp; > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > i = simple_strtoull(console_buffer, &endp, 16); > #else > i = simple_strtoul(console_buffer, &endp, 16); > @@ -1101,7 +1101,7 @@ mod_mem(struct cmd_tbl *cmdtp, int incrflag, int flag, int argc, > bootretry_reset_cmd_timeout(); > if (size == 4) > *((u32 *)ptr) = i; > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > else if (size == 8) > *((u64 *)ptr) = i; > #endif > @@ -1196,7 +1196,7 @@ static int do_random(struct cmd_tbl *cmdtp, int flag, int argc, > U_BOOT_CMD( > md, 3, 1, do_mem_md, > "memory display", > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > "[.b, .w, .l, .q] address [# of objects]" > #else > "[.b, .w, .l] address [# of objects]" > @@ -1207,7 +1207,7 @@ U_BOOT_CMD( > U_BOOT_CMD( > mm, 2, 1, do_mem_mm, > "memory modify (auto-incrementing address)", > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > "[.b, .w, .l, .q] address" > #else > "[.b, .w, .l] address" > @@ -1218,7 +1218,7 @@ U_BOOT_CMD( > U_BOOT_CMD( > nm, 2, 1, do_mem_nm, > "memory modify (constant address)", > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > "[.b, .w, .l, .q] address" > #else > "[.b, .w, .l] address" > @@ -1228,7 +1228,7 @@ U_BOOT_CMD( > U_BOOT_CMD( > mw, 4, 1, do_mem_mw, > "memory write (fill)", > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > "[.b, .w, .l, .q] address value [count]" > #else > "[.b, .w, .l] address value [count]" > @@ -1238,7 +1238,7 @@ U_BOOT_CMD( > U_BOOT_CMD( > cp, 4, 1, do_mem_cp, > "memory copy", > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > "[.b, .w, .l, .q] source target count" > #else > "[.b, .w, .l] source target count" > @@ -1248,7 +1248,7 @@ U_BOOT_CMD( > U_BOOT_CMD( > cmp, 4, 1, do_mem_cmp, > "memory compare", > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > "[.b, .w, .l, .q] addr1 addr2 count" > #else > "[.b, .w, .l] addr1 addr2 count" > @@ -1299,7 +1299,7 @@ U_BOOT_CMD( > U_BOOT_CMD( > loop, 3, 1, do_mem_loop, > "infinite loop on address range", > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > "[.b, .w, .l, .q] address number_of_objects" > #else > "[.b, .w, .l] address number_of_objects" > @@ -1310,7 +1310,7 @@ U_BOOT_CMD( > U_BOOT_CMD( > loopw, 4, 1, do_mem_loopw, > "infinite write loop on address range", > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > "[.b, .w, .l, .q] address number_of_objects data_to_write" > #else > "[.b, .w, .l] address number_of_objects data_to_write" > @@ -1330,7 +1330,7 @@ U_BOOT_CMD( > U_BOOT_CMD( > mdc, 4, 1, do_mem_mdc, > "memory display cyclic", > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > "[.b, .w, .l, .q] address count delay(ms)" > #else > "[.b, .w, .l] address count delay(ms)" > @@ -1340,7 +1340,7 @@ U_BOOT_CMD( > U_BOOT_CMD( > mwc, 4, 1, do_mem_mwc, > "memory write cyclic", > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > "[.b, .w, .l, .q] address value delay(ms)" > #else > "[.b, .w, .l] address value delay(ms)" > diff --git a/common/command.c b/common/command.c > index 4f49f15bfd..fc37ed4d7c 100644 > --- a/common/command.c > +++ b/common/command.c > @@ -473,7 +473,7 @@ int cmd_get_data_size(char* arg, int default_size) > return 2; > case 'l': > return 4; > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > case 'q': > return 8; > #endif > diff --git a/include/compiler.h b/include/compiler.h > index ed74c272b8..90b7afae53 100644 > --- a/include/compiler.h > +++ b/include/compiler.h > @@ -145,7 +145,9 @@ typedef unsigned long int uintptr_t; > #define unlikely(x) __builtin_expect(!!(x), 0) > > #ifdef __LP64__ > -#define MEM_SUPPORT_64BIT_DATA > +#define MEM_SUPPORT_64BIT_DATA 1 > +#else > +#define MEM_SUPPORT_64BIT_DATA 0 > #endif > > #endif > diff --git a/lib/display_options.c b/lib/display_options.c > index 74f769d9ff..dadfc60560 100644 > --- a/lib/display_options.c > +++ b/lib/display_options.c > @@ -137,7 +137,7 @@ int print_buffer(ulong addr, const void *data, uint width, uint count, > { > /* linebuf as a union causes proper alignment */ > union linebuf { > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > uint64_t uq[MAX_LINE_LENGTH_BYTES/sizeof(uint64_t) + 1]; > #endif > uint32_t ui[MAX_LINE_LENGTH_BYTES/sizeof(uint32_t) + 1]; > @@ -145,7 +145,7 @@ int print_buffer(ulong addr, const void *data, uint width, uint count, > uint8_t uc[MAX_LINE_LENGTH_BYTES/sizeof(uint8_t) + 1]; > } lb; > int i; > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > uint64_t __maybe_unused x; > #else > uint32_t __maybe_unused x; > @@ -168,7 +168,7 @@ int print_buffer(ulong addr, const void *data, uint width, uint count, > for (i = 0; i < thislinelen; i++) { > if (width == 4) > x = lb.ui[i] = *(volatile uint32_t *)data; > -#ifdef MEM_SUPPORT_64BIT_DATA > +#if MEM_SUPPORT_64BIT_DATA > else if (width == 8) > x = lb.uq[i] = *(volatile uint64_t *)data; > #endif > Viele Gr??e, Stefan -- DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: sr at denx.de