From 4564e7822b5174d904a0b61cb3b85f6bd66c908b Mon Sep 17 00:00:00 2001 From: Bernhard Nortmann Date: Tue, 25 Oct 2016 14:18:20 +0200 Subject: [PATCH 1/5] Fix some issues that showed up as compiler warnings with mingw64 Signed-off-by: Bernhard Nortmann --- bootinfo.c | 2 +- fel.c | 2 +- nand-image-builder.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bootinfo.c b/bootinfo.c index ea7d5e3..93b94d7 100644 --- a/bootinfo.c +++ b/bootinfo.c @@ -198,7 +198,7 @@ void print_boot_file_head(boot_file_head_t *hdr) void print_boot_dram_para(boot_dram_para_t *dram) { - pprintf(&dram->dram_baseaddr, "DRAM base : %p\n", (void *)(long)dram->dram_baseaddr); + pprintf(&dram->dram_baseaddr, "DRAM base : %p\n", (void *)(uintptr_t)dram->dram_baseaddr); pprintf(&dram->dram_clk, "DRAM clk : %d\n", dram->dram_clk); pprintf(&dram->dram_type, "DRAM type : %d\n", dram->dram_type); pprintf(&dram->dram_rank_num, "DRAM rank : %d\n", dram->dram_rank_num); diff --git a/fel.c b/fel.c index 5d8a382..6d9cfc6 100644 --- a/fel.c +++ b/fel.c @@ -325,7 +325,7 @@ void hexdump(void *data, uint32_t offset, size_t size) unsigned char *buf = data; for (j = 0; j < size; j+=16) { size_t i; - printf("%08lx: ",(long int)offset + j); + printf("%08zx: ", offset + j); for (i = 0; i < 16; i++) { if (j + i < size) printf("%02x ", buf[j+i]); diff --git a/nand-image-builder.c b/nand-image-builder.c index db42690..964a142 100644 --- a/nand-image-builder.c +++ b/nand-image-builder.c @@ -257,7 +257,7 @@ static void encode_bch(struct bch_control *bch, const uint8_t *data, } /* process first unaligned data bytes */ - m = ((unsigned long)data) & 3; + m = ((uintptr_t)data) & 3; if (m) { mlen = (len < (4-m)) ? len : 4-m; encode_bch_unaligned(bch, data, mlen, bch->ecc_buf); From b496582b3d3dcd6130e1f40024fbc9d6895cc513 Mon Sep 17 00:00:00 2001 From: Bernhard Nortmann Date: Wed, 26 Oct 2016 19:32:04 +0200 Subject: [PATCH 2/5] Have a workaround for missing mmap() in fexc.c and pio.c By defining NO_MMAP it's now possible to avoid the usage of mmap() and munmap(). This benefits platforms that don't support these functions, e.g. Windows. Signed-off-by: Bernhard Nortmann --- Makefile | 4 ++++ fexc.c | 8 +++++++- pio.c | 9 ++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 975bf67..4771bf9 100644 --- a/Makefile +++ b/Makefile @@ -100,6 +100,10 @@ sunxi-fexc: fexc.h script.h script.c \ LIBUSB = libusb-1.0 LIBUSB_CFLAGS = `pkg-config --cflags $(LIBUSB)` LIBUSB_LIBS = `pkg-config --libs $(LIBUSB)` +ifeq ($(OS),Windows_NT) + # Windows lacks mman.h / mmap() + DEFINES += -DNO_MMAP +endif sunxi-fel: fel.c fel-to-spl-thunk.h progress.c progress.h $(CC) $(CFLAGS) $(LIBUSB_CFLAGS) $(LDFLAGS) -o $@ $(filter %.c,$^) $(LIBS) $(LIBUSB_LIBS) diff --git a/fexc.c b/fexc.c index e90bd14..a1cc9cc 100644 --- a/fexc.c +++ b/fexc.c @@ -21,7 +21,9 @@ #include #include #include -#include +#ifndef NO_MMAP + #include +#endif #include #include #include @@ -117,6 +119,7 @@ static inline int script_parse(enum script_format format, pr_err("%s: %s: %s\n", filename, "fstat", strerror(errno)); goto bin_close; +#ifndef NO_MMAP } else if (S_ISREG(sb.st_mode)) { /* regular file, mmap it */ bin = mmap(0, sb.st_size, PROT_READ, MAP_SHARED, in, 0); @@ -127,6 +130,7 @@ static inline int script_parse(enum script_format format, } bin_size = sb.st_size; allocated = 0; +#endif } else { /* something else... just read it all! */ bin = read_all(in, filename, &bin_size); @@ -138,10 +142,12 @@ static inline int script_parse(enum script_format format, ret = script_decompile_bin(bin, bin_size, filename, script); if (allocated) free(bin); +#ifndef NO_MMAP else if (munmap(bin, bin_size) == -1) { pr_err("%s: %s: %s\n", filename, "munmap", strerror(errno)); } +#endif bin_close: close(in); }; break; diff --git a/pio.c b/pio.c index 3ecf912..4bcdc18 100644 --- a/pio.c +++ b/pio.c @@ -24,7 +24,9 @@ #include #include #include -#include +#ifndef NO_MMAP + #include +#endif #include #include #include @@ -365,6 +367,10 @@ int main(int argc, char **argv) if (!in_name && !do_mmap) usage(1); if (do_mmap) { +#ifdef NO_MMAP + errno = ENOSYS; /* Function not implemented */ + perror("mmap PIO"); +#else int pagesize = sysconf(_SC_PAGESIZE); int fd = open("/dev/mem",O_RDWR); int addr = 0x01c20800 & ~(pagesize-1); @@ -380,6 +386,7 @@ int main(int argc, char **argv) } close(fd); buf += offset; +#endif } if (in_name) { if (strcmp(in_name, "-") == 0) { From f3960f4a7704e16203f2f82507f4bbb2a7e31a4c Mon Sep 17 00:00:00 2001 From: Bernhard Nortmann Date: Wed, 26 Oct 2016 19:39:41 +0200 Subject: [PATCH 3/5] fel: Change order of includes For Windows portable_endian.h relies on and includes . Thus it needs to be requested first, otherwise other includes might pull in and cause a preprocessor warning / compilation failure (observed with MinGW). Signed-off-by: Bernhard Nortmann --- fel.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fel.c b/fel.c index 6d9cfc6..8e617bd 100644 --- a/fel.c +++ b/fel.c @@ -15,6 +15,10 @@ * along with this program. If not, see . */ +#include "common.h" +#include "portable_endian.h" +#include "progress.h" + #include #include #include @@ -28,10 +32,6 @@ #include #include -#include "common.h" -#include "portable_endian.h" -#include "progress.h" - static const uint16_t AW_USB_VENDOR_ID = 0x1F3A; static const uint16_t AW_USB_PRODUCT_ID = 0xEFE8; From eb44a075db6b454bb5074d2d0d38284ee9c44a60 Mon Sep 17 00:00:00 2001 From: Bernhard Nortmann Date: Wed, 26 Oct 2016 19:49:32 +0200 Subject: [PATCH 4/5] Makefile: allow overriding libusb Makefile variables externally Also: Add the winsock2 library to LIBS for Windows. When not linking against it, the usage of WS2 conversion functions from portable_endian.h would cause unresolved symbols. Signed-off-by: Bernhard Nortmann --- Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 4771bf9..6adf0b8 100644 --- a/Makefile +++ b/Makefile @@ -98,11 +98,13 @@ sunxi-fexc: fexc.h script.h script.c \ script_fex.h script_fex.c LIBUSB = libusb-1.0 -LIBUSB_CFLAGS = `pkg-config --cflags $(LIBUSB)` -LIBUSB_LIBS = `pkg-config --libs $(LIBUSB)` +LIBUSB_CFLAGS ?= `pkg-config --cflags $(LIBUSB)` +LIBUSB_LIBS ?= `pkg-config --libs $(LIBUSB)` ifeq ($(OS),Windows_NT) # Windows lacks mman.h / mmap() DEFINES += -DNO_MMAP + # portable_endian.h relies on winsock2 + LIBS += -lws2_32 endif sunxi-fel: fel.c fel-to-spl-thunk.h progress.c progress.h From beed002864066de6ccd579237290c271be7c7f6b Mon Sep 17 00:00:00 2001 From: Bernhard Nortmann Date: Thu, 27 Oct 2016 13:12:46 +0200 Subject: [PATCH 5/5] meminfo: Add missing version output, fix initializer syntax (Changing to a proper struct initializer avoids a possible compiler warning.) Signed-off-by: Bernhard Nortmann --- meminfo.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/meminfo.c b/meminfo.c index 86b5c1e..0b0ff23 100644 --- a/meminfo.c +++ b/meminfo.c @@ -25,6 +25,8 @@ #include #include +#include "common.h" + typedef uint32_t u32; /* from u-boot code: */ @@ -412,7 +414,7 @@ sun4i_dram_para_print_fex(struct sun4i_dram_para *dram_para) static int sun4i_dram_para_print(bool uboot) { - struct sun4i_dram_para dram_para = {0}; + struct sun4i_dram_para dram_para = { .baseaddr = 0 }; int ret; ret = sunxi_dram_clock_read(&dram_para.clock); @@ -710,6 +712,7 @@ sun8i_dram_regs_print(void) static void print_usage(const char *name) { + puts("sunxi-meminfo " VERSION "\n"); printf("Utility to retrieve DRAM information from registers on " "Allwinner SoCs.\n"); printf("\n");