Commit b496582b authored by Bernhard Nortmann's avatar Bernhard Nortmann
Browse files

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: default avatarBernhard Nortmann <bernhard.nortmann@web.de>
parent 4564e782
...@@ -100,6 +100,10 @@ sunxi-fexc: fexc.h script.h script.c \ ...@@ -100,6 +100,10 @@ sunxi-fexc: fexc.h script.h script.c \
LIBUSB = libusb-1.0 LIBUSB = libusb-1.0
LIBUSB_CFLAGS = `pkg-config --cflags $(LIBUSB)` LIBUSB_CFLAGS = `pkg-config --cflags $(LIBUSB)`
LIBUSB_LIBS = `pkg-config --libs $(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 sunxi-fel: fel.c fel-to-spl-thunk.h progress.c progress.h
$(CC) $(CFLAGS) $(LIBUSB_CFLAGS) $(LDFLAGS) -o $@ $(filter %.c,$^) $(LIBS) $(LIBUSB_LIBS) $(CC) $(CFLAGS) $(LIBUSB_CFLAGS) $(LDFLAGS) -o $@ $(filter %.c,$^) $(LIBS) $(LIBUSB_LIBS)
......
...@@ -21,7 +21,9 @@ ...@@ -21,7 +21,9 @@
#include <libgen.h> #include <libgen.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/mman.h> #ifndef NO_MMAP
#include <sys/mman.h>
#endif
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
...@@ -117,6 +119,7 @@ static inline int script_parse(enum script_format format, ...@@ -117,6 +119,7 @@ static inline int script_parse(enum script_format format,
pr_err("%s: %s: %s\n", filename, pr_err("%s: %s: %s\n", filename,
"fstat", strerror(errno)); "fstat", strerror(errno));
goto bin_close; goto bin_close;
#ifndef NO_MMAP
} else if (S_ISREG(sb.st_mode)) { } else if (S_ISREG(sb.st_mode)) {
/* regular file, mmap it */ /* regular file, mmap it */
bin = mmap(0, sb.st_size, PROT_READ, MAP_SHARED, in, 0); 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, ...@@ -127,6 +130,7 @@ static inline int script_parse(enum script_format format,
} }
bin_size = sb.st_size; bin_size = sb.st_size;
allocated = 0; allocated = 0;
#endif
} else { } else {
/* something else... just read it all! */ /* something else... just read it all! */
bin = read_all(in, filename, &bin_size); bin = read_all(in, filename, &bin_size);
...@@ -138,10 +142,12 @@ static inline int script_parse(enum script_format format, ...@@ -138,10 +142,12 @@ static inline int script_parse(enum script_format format,
ret = script_decompile_bin(bin, bin_size, filename, script); ret = script_decompile_bin(bin, bin_size, filename, script);
if (allocated) if (allocated)
free(bin); free(bin);
#ifndef NO_MMAP
else if (munmap(bin, bin_size) == -1) { else if (munmap(bin, bin_size) == -1) {
pr_err("%s: %s: %s\n", filename, pr_err("%s: %s: %s\n", filename,
"munmap", strerror(errno)); "munmap", strerror(errno));
} }
#endif
bin_close: bin_close:
close(in); close(in);
}; break; }; break;
......
...@@ -24,7 +24,9 @@ ...@@ -24,7 +24,9 @@
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#include <sys/mman.h> #ifndef NO_MMAP
#include <sys/mman.h>
#endif
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
...@@ -365,6 +367,10 @@ int main(int argc, char **argv) ...@@ -365,6 +367,10 @@ int main(int argc, char **argv)
if (!in_name && !do_mmap) if (!in_name && !do_mmap)
usage(1); usage(1);
if (do_mmap) { if (do_mmap) {
#ifdef NO_MMAP
errno = ENOSYS; /* Function not implemented */
perror("mmap PIO");
#else
int pagesize = sysconf(_SC_PAGESIZE); int pagesize = sysconf(_SC_PAGESIZE);
int fd = open("/dev/mem",O_RDWR); int fd = open("/dev/mem",O_RDWR);
int addr = 0x01c20800 & ~(pagesize-1); int addr = 0x01c20800 & ~(pagesize-1);
...@@ -380,6 +386,7 @@ int main(int argc, char **argv) ...@@ -380,6 +386,7 @@ int main(int argc, char **argv)
} }
close(fd); close(fd);
buf += offset; buf += offset;
#endif
} }
if (in_name) { if (in_name) {
if (strcmp(in_name, "-") == 0) { if (strcmp(in_name, "-") == 0) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment