Fix warnings in coreboot utilities.
authorStefan Reinauer <reinauer@chromium.org>
Mon, 14 Nov 2011 20:40:34 +0000 (12:40 -0800)
committerStefan Reinauer <stefan.reinauer@coreboot.org>
Fri, 30 Mar 2012 18:26:50 +0000 (20:26 +0200)
- Fix some poor programming practice (breaks of strict aliasing as well
  as not checking the return value of read)
- Use PRIx64 instead of %llx to prevent compilation warnings with both
  32bit and 64bit compilers
- Use same compiler command options when linking inteltool and when
  detecting libpci for inteltool

Change-Id: I08b2e8d1bbc908f6b1f26d25cb3a4b03d818e124
Signed-off-by: Stefan Reinauer <reinauer@google.com>
Reviewed-on: http://review.coreboot.org/752
Tested-by: build bot (Jenkins)
Reviewed-by: Mathias Krause <minipli@googlemail.com>
util/inteltool/Makefile
util/inteltool/cpu.c
util/inteltool/inteltool.c
util/inteltool/memory.c
util/inteltool/pcie.c
util/nvramtool/cli/nvramtool.c

index 6a011732d9b1394b958fc7f9feb3e25792ff0ce3..d7540059beb6973e3a81edaef5e7a87b81826cb3 100644 (file)
@@ -42,7 +42,7 @@ endif
 all: pciutils dep $(PROGRAM)
 
 $(PROGRAM): $(OBJS)
-       $(CC) -o $(PROGRAM) $(OBJS) $(LDFLAGS)
+       $(CC) $(CFLAGS) -o $(PROGRAM) $(OBJS) $(LDFLAGS)
 
 clean:
        rm -f $(PROGRAM) *.o *~
@@ -59,7 +59,7 @@ pciutils:
                   printf "struct pci_access *pacc;\n";         \
                   printf "int main(int argc, char **argv)\n";  \
                   printf "{ pacc = pci_alloc(); return 0; }\n"; ) > .test.c )
-       @$(CC) $(CFLAGS) $(LDFLAGS) .test.c -o .test &>/dev/null &&       \
+       @$(CC) $(CFLAGS) .test.c -o .test $(LDFLAGS) &>/dev/null &&       \
                printf "found.\n" || ( printf "not found.\n\n";           \
                printf "Please install pciutils-devel and zlib-devel.\n"; \
                printf "See README for more information.\n\n";            \
index 20748bda44b0d3b39bfaf118e5f50783aa5b4aca..f0183816f7a347a88289650d30c36dad55d806fc 100644 (file)
@@ -57,7 +57,7 @@ int msr_readerror = 0;
 
 msr_t rdmsr(int addr)
 {
-       uint8_t buf[8];
+       uint32_t buf[2];
        msr_t msr = { 0xffffffff, 0xffffffff };
 
        if (lseek(fd_msr, (off_t) addr, SEEK_SET) == -1) {
@@ -67,9 +67,8 @@ msr_t rdmsr(int addr)
        }
 
        if (read(fd_msr, buf, 8) == 8) {
-               msr.lo = *(uint32_t *)buf;
-               msr.hi = *(uint32_t *)(buf + 4);
-
+               msr.lo = buf[0];
+               msr.hi = buf[1];
                return msr;
        }
 
index 6b9960552081051af9639ff618cc0f93ea9ce4a8..e5c2b867c39ec8dcc8c7127a0786b5811559d5f9 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <inttypes.h>
 #include <getopt.h>
 #include <fcntl.h>
 #include <sys/mman.h>
@@ -99,7 +100,8 @@ void *map_physical(uint64_t phys_addr, size_t len)
                    fd_mem, (off_t) phys_addr);
 
        if (virt_addr == MAP_FAILED) {
-               printf("Error mapping physical memory 0x%08lx[0x%zx]\n", phys_addr, len);
+               printf("Error mapping physical memory 0x%08" PRIx64 "[0x%zx]\n",
+                       phys_addr, len);
                return NULL;
        }
 
index 9230419d53438f4ef0c6edbda17bb14da07c83d9..18300ac4450a93efaf89642ed2833c15acb6cea4 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <inttypes.h>
 #include "inteltool.h"
 
 /*
@@ -130,9 +131,9 @@ int print_mchbar(struct pci_dev *nb, struct pci_access *pacc)
        }
 
        if (nb->device_id == PCI_DEVICE_ID_INTEL_82865)
-               printf("BAR6 = 0x%08llx (MEM)\n\n", mchbar_phys);
+               printf("BAR6 = 0x%08" PRIx64 " (MEM)\n\n", mchbar_phys);
        else
-               printf("MCHBAR = 0x%08llx (MEM)\n\n", mchbar_phys);
+               printf("MCHBAR = 0x%08" PRIx64 " (MEM)\n\n", mchbar_phys);
 
        for (i = 0; i < size; i += 4) {
                if (*(uint32_t *)(mchbar + i))
index 4913150943548f487a2701974d23a6101cd59bc2..ea238354254042611b588bee446c9ab662e41088 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <inttypes.h>
 #include "inteltool.h"
 
 /*
@@ -72,7 +73,7 @@ int print_epbar(struct pci_dev *nb)
                exit(1);
        }
 
-       printf("EPBAR = 0x%08llx (MEM)\n\n", epbar_phys);
+       printf("EPBAR = 0x%08" PRIx64 " (MEM)\n\n", epbar_phys);
        for (i = 0; i < size; i += 4) {
                if (*(uint32_t *)(epbar + i))
                        printf("0x%04x: 0x%08x\n", i, *(uint32_t *)(epbar+i));
@@ -135,7 +136,7 @@ int print_dmibar(struct pci_dev *nb)
                exit(1);
        }
 
-       printf("DMIBAR = 0x%08llx (MEM)\n\n", dmibar_phys);
+       printf("DMIBAR = 0x%08" PRIx64 " (MEM)\n\n", dmibar_phys);
        for (i = 0; i < size; i += 4) {
                if (*(uint32_t *)(dmibar + i))
                        printf("0x%04x: 0x%08x\n", i, *(uint32_t *)(dmibar+i));
@@ -213,7 +214,7 @@ int print_pciexbar(struct pci_dev *nb)
                return 1;
        }
 
-       printf("PCIEXBAR: 0x%08llx\n", pciexbar_phys);
+       printf("PCIEXBAR: 0x%08" PRIx64 "\n", pciexbar_phys);
 
        pciexbar = map_physical(pciexbar_phys, (max_busses * 1024 * 1024));
 
index 11a1a702afcf1a754330c9153efcd5e9986ee3bc..bcb10bbf34bce9ab47c124c0b7be14cffd076c17 100644 (file)
@@ -143,7 +143,11 @@ int main(int argc, char *argv[])
 
                if (fd_stat.st_size < 128) {
                        lseek(fd, 127, SEEK_SET);
-                       write(fd, "\0", 1);
+                       if (write(fd, "\0", 1) != 1) {
+                               fprintf(stderr, "Unable to extended '%s' to its full size.\n",
+                                               nvramtool_op_modifiers[NVRAMTOOL_MOD_USE_CMOS_FILE].param);
+                               exit(1);
+                       }
                        fsync(fd);
                }