Skip to content

Commit

Permalink
Remove <inttypes.h> includes and PRI* usages in printf() entirely
Browse files Browse the repository at this point in the history
In int-ll64.h, we always use the following typedefs:

  typedef unsigned int         u32;
  typedef unsigned long        uintptr_t;
  typedef unsigned long long   u64;

This does not need to match to the compiler's <inttypes.h>.
Do not include it.

The use of PRI* makes the code super-ugly.  You can simply use
"l" for printing uintptr_t, "ll" for u64, and no modifier for u32.

Signed-off-by: Masahiro Yamada <[email protected]>
  • Loading branch information
masahir0y authored and trini committed Sep 11, 2018
1 parent 3747bdb commit dee37fc
Show file tree
Hide file tree
Showing 22 changed files with 43 additions and 351 deletions.
12 changes: 4 additions & 8 deletions arch/x86/lib/relocate.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

#include <common.h>
#include <inttypes.h>
#include <relocate.h>
#include <asm/u-boot-x86.h>
#include <asm/sections.h>
Expand Down Expand Up @@ -70,8 +69,7 @@ static void do_elf_reloc_fixups64(unsigned int text_base, uintptr_t size,
*offset_ptr_ram = gd->reloc_off +
re_src->r_addend;
} else {
debug(" %p: %lx: rom reloc %lx, ram %p, value %lx, limit %"
PRIXPTR "\n",
debug(" %p: %lx: rom reloc %lx, ram %p, value %lx, limit %lX\n",
re_src, (ulong)re_src->r_info,
(ulong)re_src->r_offset, offset_ptr_ram,
(ulong)*offset_ptr_ram, text_base + size);
Expand Down Expand Up @@ -109,11 +107,9 @@ static void do_elf_reloc_fixups32(unsigned int text_base, uintptr_t size,
*offset_ptr_ram <= text_base + size) {
*offset_ptr_ram += gd->reloc_off;
} else {
debug(" %p: rom reloc %x, ram %p, value %x,"
" limit %" PRIXPTR "\n", re_src,
re_src->r_offset, offset_ptr_ram,
*offset_ptr_ram,
text_base + size);
debug(" %p: rom reloc %x, ram %p, value %x, limit %lX\n",
re_src, re_src->r_offset, offset_ptr_ram,
*offset_ptr_ram, text_base + size);
}
} else {
debug(" %p: rom reloc %x, last %p\n", re_src,
Expand Down
3 changes: 1 addition & 2 deletions board/raspberrypi/rpi/rpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/

#include <common.h>
#include <inttypes.h>
#include <config.h>
#include <dm.h>
#include <environment.h>
Expand Down Expand Up @@ -384,7 +383,7 @@ static void set_serial_number(void)
return;
}

snprintf(serial_string, sizeof(serial_string), "%016" PRIx64,
snprintf(serial_string, sizeof(serial_string), "%016llx",
msg->get_board_serial.body.resp.serial);
env_set("serial#", serial_string);
}
Expand Down
6 changes: 2 additions & 4 deletions cmd/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <command.h>
#include <console.h>
#include <hash.h>
#include <inttypes.h>
#include <mapmem.h>
#include <watchdog.h>
#include <asm/io.h>
Expand Down Expand Up @@ -275,8 +274,7 @@ static int do_mem_cmp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
if (word1 != word2) {
ulong offset = buf1 - base;
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
printf("%s at 0x%p (%#0*"PRIx64") != %s at 0x%p (%#0*"
PRIx64 ")\n",
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);
#else
Expand Down Expand Up @@ -1000,7 +998,7 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
printf(" %08x", *((u32 *)ptr));
#ifdef CONFIG_SYS_SUPPORT_64BIT_DATA
else if (size == 8)
printf(" %016" PRIx64, *((u64 *)ptr));
printf(" %016llx", *((u64 *)ptr));
#endif
else if (size == 2)
printf(" %04x", *((u16 *)ptr));
Expand Down
17 changes: 7 additions & 10 deletions common/fdt_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

#include <common.h>
#include <inttypes.h>
#include <stdio_dev.h>
#include <linux/ctype.h>
#include <linux/types.h>
Expand Down Expand Up @@ -1025,8 +1024,7 @@ static u64 of_bus_default_map(fdt32_t *addr, const fdt32_t *range,
s = fdt_read_number(range + na + pna, ns);
da = fdt_read_number(addr, na);

debug("OF: default map, cp=%" PRIu64 ", s=%" PRIu64
", da=%" PRIu64 "\n", cp, s, da);
debug("OF: default map, cp=%llu, s=%llu, da=%llu\n", cp, s, da);

if (da < cp || da >= (cp + s))
return OF_BAD_ADDR;
Expand Down Expand Up @@ -1081,8 +1079,7 @@ static u64 of_bus_isa_map(fdt32_t *addr, const fdt32_t *range,
s = fdt_read_number(range + na + pna, ns);
da = fdt_read_number(addr + 1, na - 1);

debug("OF: ISA map, cp=%" PRIu64 ", s=%" PRIu64
", da=%" PRIu64 "\n", cp, s, da);
debug("OF: ISA map, cp=%llu, s=%llu, da=%llu\n", cp, s, da);

if (da < cp || da >= (cp + s))
return OF_BAD_ADDR;
Expand Down Expand Up @@ -1188,7 +1185,7 @@ static int of_translate_one(const void *blob, int parent, struct of_bus *bus,

finish:
of_dump_addr("OF: parent translation for:", addr, pna);
debug("OF: with offset: %" PRIu64 "\n", offset);
debug("OF: with offset: %llu\n", offset);

/* Translate it into parent bus space */
return pbus->translate(addr, offset, pna);
Expand Down Expand Up @@ -1518,9 +1515,9 @@ int fdt_verify_alias_address(void *fdt, int anode, const char *alias, u64 addr)

dt_addr = fdt_translate_address(fdt, node, reg);
if (addr != dt_addr) {
printf("Warning: U-Boot configured device %s at address %"
PRIx64 ",\n but the device tree has it address %"
PRIx64 ".\n", alias, addr, dt_addr);
printf("Warning: U-Boot configured device %s at address %llu,\n"
"but the device tree has it address %llx.\n",
alias, addr, dt_addr);
return 0;
}

Expand Down Expand Up @@ -1668,7 +1665,7 @@ int fdt_setup_simplefb_node(void *fdt, int node, u64 base_address, u32 width,
if (ret < 0)
return ret;

snprintf(name, sizeof(name), "framebuffer@%" PRIx64, base_address);
snprintf(name, sizeof(name), "framebuffer@%llx", base_address);
ret = fdt_set_name(fdt, node, name);
if (ret < 0)
return ret;
Expand Down
16 changes: 7 additions & 9 deletions common/usb_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include <command.h>
#include <dm.h>
#include <errno.h>
#include <inttypes.h>
#include <mapmem.h>
#include <memalign.h>
#include <asm/byteorder.h>
Expand Down Expand Up @@ -1164,8 +1163,8 @@ static unsigned long usb_stor_read(struct blk_desc *block_dev, lbaint_t blknr,
start = blknr;
blks = blkcnt;

debug("\nusb_read: dev %d startblk " LBAF ", blccnt " LBAF " buffer %"
PRIxPTR "\n", block_dev->devnum, start, blks, buf_addr);
debug("\nusb_read: dev %d startblk " LBAF ", blccnt " LBAF " buffer %lx\n",
block_dev->devnum, start, blks, buf_addr);

do {
/* XXX need some comment here */
Expand Down Expand Up @@ -1194,8 +1193,7 @@ static unsigned long usb_stor_read(struct blk_desc *block_dev, lbaint_t blknr,
} while (blks != 0);
ss->flags &= ~USB_READY;

debug("usb_read: end startblk " LBAF
", blccnt %x buffer %" PRIxPTR "\n",
debug("usb_read: end startblk " LBAF ", blccnt %x buffer %lx\n",
start, smallblks, buf_addr);

usb_disable_asynch(0); /* asynch transfer allowed */
Expand Down Expand Up @@ -1248,8 +1246,8 @@ static unsigned long usb_stor_write(struct blk_desc *block_dev, lbaint_t blknr,
start = blknr;
blks = blkcnt;

debug("\nusb_write: dev %d startblk " LBAF ", blccnt " LBAF " buffer %"
PRIxPTR "\n", block_dev->devnum, start, blks, buf_addr);
debug("\nusb_write: dev %d startblk " LBAF ", blccnt " LBAF " buffer %lx\n",
block_dev->devnum, start, blks, buf_addr);

do {
/* If write fails retry for max retry count else
Expand Down Expand Up @@ -1280,8 +1278,8 @@ static unsigned long usb_stor_write(struct blk_desc *block_dev, lbaint_t blknr,
} while (blks != 0);
ss->flags &= ~USB_READY;

debug("usb_write: end startblk " LBAF ", blccnt %x buffer %"
PRIxPTR "\n", start, smallblks, buf_addr);
debug("usb_write: end startblk " LBAF ", blccnt %x buffer %lx\n",
start, smallblks, buf_addr);

usb_disable_asynch(0); /* asynch transfer allowed */
if (blkcnt >= ss->max_xfer_blk)
Expand Down
1 change: 0 additions & 1 deletion disk/part_efi.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <command.h>
#include <fdtdec.h>
#include <ide.h>
#include <inttypes.h>
#include <malloc.h>
#include <memalign.h>
#include <part_efi.h>
Expand Down
6 changes: 2 additions & 4 deletions drivers/pci/pci-uclass.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <common.h>
#include <dm.h>
#include <errno.h>
#include <inttypes.h>
#include <pci.h>
#include <asm/io.h>
#include <dm/device-internal.h>
Expand Down Expand Up @@ -854,9 +853,8 @@ static void decode_regions(struct pci_controller *hose, ofnode parent_node,
prop += addr_cells;
size = fdtdec_get_number(prop, size_cells);
prop += size_cells;
debug("%s: region %d, pci_addr=%" PRIx64 ", addr=%" PRIx64
", size=%" PRIx64 ", space_code=%d\n", __func__,
hose->region_count, pci_addr, addr, size, space_code);
debug("%s: region %d, pci_addr=%llx, addr=%llx, size=%llx, space_code=%d\n",
__func__, hose->region_count, pci_addr, addr, size, space_code);
if (space_code & 2) {
type = flags & (1U << 30) ? PCI_REGION_PREFETCH :
PCI_REGION_MEM;
Expand Down
1 change: 0 additions & 1 deletion drivers/pci/pci_sandbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <common.h>
#include <dm.h>
#include <fdtdec.h>
#include <inttypes.h>
#include <pci.h>

#define FDT_DEV_INFO_CELLS 4
Expand Down
9 changes: 4 additions & 5 deletions drivers/scsi/scsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <common.h>
#include <dm.h>
#include <inttypes.h>
#include <pci.h>
#include <scsi.h>
#include <dm/device-internal.h>
Expand Down Expand Up @@ -196,7 +195,7 @@ static ulong scsi_read(struct blk_desc *block_dev, lbaint_t blknr,
blks = 0;
}
debug("scsi_read_ext: startblk " LBAF
", blccnt %x buffer %" PRIXPTR "\n",
", blccnt %x buffer %lX\n",
start, smallblks, buf_addr);
if (scsi_exec(bdev, pccb)) {
scsi_print_error(pccb);
Expand All @@ -206,7 +205,7 @@ static ulong scsi_read(struct blk_desc *block_dev, lbaint_t blknr,
buf_addr += pccb->datalen;
} while (blks != 0);
debug("scsi_read_ext: end startblk " LBAF
", blccnt %x buffer %" PRIXPTR "\n", start, smallblks, buf_addr);
", blccnt %x buffer %lX\n", start, smallblks, buf_addr);
return blkcnt;
}

Expand Down Expand Up @@ -260,7 +259,7 @@ static ulong scsi_write(struct blk_desc *block_dev, lbaint_t blknr,
start += blks;
blks = 0;
}
debug("%s: startblk " LBAF ", blccnt %x buffer %" PRIXPTR "\n",
debug("%s: startblk " LBAF ", blccnt %x buffer %lx\n",
__func__, start, smallblks, buf_addr);
if (scsi_exec(bdev, pccb)) {
scsi_print_error(pccb);
Expand All @@ -269,7 +268,7 @@ static ulong scsi_write(struct blk_desc *block_dev, lbaint_t blknr,
}
buf_addr += pccb->datalen;
} while (blks != 0);
debug("%s: end startblk " LBAF ", blccnt %x buffer %" PRIXPTR "\n",
debug("%s: end startblk " LBAF ", blccnt %x buffer %lX\n",
__func__, start, smallblks, buf_addr);
return blkcnt;
}
Expand Down
3 changes: 1 addition & 2 deletions fs/ext4/ext4_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include <common.h>
#include <ext_common.h>
#include <ext4fs.h>
#include <inttypes.h>
#include <malloc.h>
#include <memalign.h>
#include <stddef.h>
Expand Down Expand Up @@ -210,7 +209,7 @@ void put_ext4(uint64_t off, void *buf, uint32_t size)
if ((startblock + (size >> log2blksz)) >
(part_offset + fs->total_sect)) {
printf("part_offset is " LBAFU "\n", part_offset);
printf("total_sector is %" PRIu64 "\n", fs->total_sect);
printf("total_sector is %llu\n", fs->total_sect);
printf("error: overflow occurs\n");
return;
}
Expand Down
3 changes: 0 additions & 3 deletions include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ typedef volatile unsigned char vu_char;
#include <flash.h>
#include <image.h>

/* Bring in printf format macros if inttypes.h is included */
#define __STDC_FORMAT_MACROS

#ifdef __LP64__
#define CONFIG_SYS_SUPPORT_64BIT_DATA
#endif
Expand Down
Loading

0 comments on commit dee37fc

Please sign in to comment.