From c66af9fe057e953a9ed2458e0878cca74a74a521 Mon Sep 17 00:00:00 2001 From: Juergen Beisert Date: Fri, 14 Oct 2011 14:11:28 +0200 Subject: [PATCH 1/7] 'bootz' command fails to load the zImage's header Running the 'bootz' command always fails with could not read due to it loads only a size of a pointer, instead of the size of the expected header structure. Signed-off-by: Juergen Beisert Signed-off-by: Sascha Hauer --- arch/arm/lib/bootz.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/lib/bootz.c b/arch/arm/lib/bootz.c index fc14487bf..9be615be2 100644 --- a/arch/arm/lib/bootz.c +++ b/arch/arm/lib/bootz.c @@ -53,7 +53,7 @@ static int do_bootz(struct command *cmdtp, int argc, char *argv[]) if (!usemap) { header = &__header; - ret = read(fd, header, sizeof(header)); + ret = read(fd, header, sizeof(*header)); if (ret < sizeof(*header)) { printf("could not read %s\n", argv[1]); goto err_out; From 2b5d8792ac7c95f41f3d5fced553450eea9b40f8 Mon Sep 17 00:00:00 2001 From: Juergen Beisert Date: Fri, 14 Oct 2011 14:37:56 +0200 Subject: [PATCH 2/7] Really fix the 'bootz' command Running the 'bootz' command always fails with could not read due to wrong usage of pointers and structures. This is the second try to fix the 'bootz' command. At least on my target it is now be able again to load a kernel without any error. Signed-off-by: Juergen Beisert Signed-off-by: Sascha Hauer --- arch/arm/lib/bootz.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm/lib/bootz.c b/arch/arm/lib/bootz.c index 9be615be2..956ea8286 100644 --- a/arch/arm/lib/bootz.c +++ b/arch/arm/lib/bootz.c @@ -89,10 +89,10 @@ static int do_bootz(struct command *cmdtp, int argc, char *argv[]) } } - memcpy(zimage, &header, sizeof(header)); + memcpy(zimage, header, sizeof(*header)); - ret = read(fd, zimage + sizeof(header), end - sizeof(header)); - if (ret < end - sizeof(header)) { + ret = read(fd, zimage + sizeof(*header), end - sizeof(*header)); + if (ret < end - sizeof(*header)) { printf("could not read %s\n", argv[1]); goto err_out1; } From 4e26fba6803b0b4820875df50ed733eeb4980d60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Minier?= Date: Fri, 14 Oct 2011 00:06:37 +0200 Subject: [PATCH 3/7] Only pass -P to cpp when generating ld scripts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When building sandbox with ccache, one would hit warnings such as: warning: 'struct mmsghdr' declared inside parameter list on random files; a way to reproduce this issue is to build a simple file doing just: #include int main(void) { return 0; } gcc -Wall -P -c -o foo foo.c But actually the -P flag is only useful when generating non-C files, such as linker scripts in the case of barebox. Removing the -P flag from all the gcc invocations, except when generating .lds files makes the warning go away. It turns out that this is what linux/scripts/Makefile.build also does nowadays. Signed-off-by: Loïc Minier Signed-off-by: Sascha Hauer --- Makefile | 2 +- arch/arm/Makefile | 2 +- arch/blackfin/Makefile | 2 +- arch/ppc/Makefile | 2 +- arch/sandbox/Makefile | 1 - arch/sandbox/os/Makefile | 1 - arch/x86/Makefile | 2 +- scripts/Makefile.build | 2 +- 8 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 5414e6313..10d5780ba 100644 --- a/Makefile +++ b/Makefile @@ -825,7 +825,7 @@ prepare prepare-all: prepare0 # Leave this as default for preprocessing barebox.lds.S, which is now # done in arch/$(ARCH)/kernel/Makefile -export CPPFLAGS_barebox.lds += -P -C -U$(ARCH) +export CPPFLAGS_barebox.lds += -C -U$(ARCH) # FIXME: The asm symlink changes when $(ARCH) changes. That's # hard to detect, but I suppose "make mrproper" is a good idea diff --git a/arch/arm/Makefile b/arch/arm/Makefile index d25412d11..0c42f3d1e 100644 --- a/arch/arm/Makefile +++ b/arch/arm/Makefile @@ -121,7 +121,7 @@ endif TEXT_BASE = $(CONFIG_TEXT_BASE) -CPPFLAGS += -DTEXT_BASE=$(TEXT_BASE) -P +CPPFLAGS += -DTEXT_BASE=$(TEXT_BASE) ifndef CONFIG_MODULES # Add cleanup flags diff --git a/arch/blackfin/Makefile b/arch/blackfin/Makefile index 902268da7..a0b87f77d 100644 --- a/arch/blackfin/Makefile +++ b/arch/blackfin/Makefile @@ -7,7 +7,7 @@ cpu-$(CONFIG_BF561) := bf561 TEXT_BASE = $(CONFIG_TEXT_BASE) -CPPFLAGS += -DTEXT_BASE=$(TEXT_BASE) -P +CPPFLAGS += -DTEXT_BASE=$(TEXT_BASE) CFLAGS += -D__blackfin__ # -Ttext $(TEXT_BASE) KALLSYMS += --symbol-prefix=_ diff --git a/arch/ppc/Makefile b/arch/ppc/Makefile index 46d64e5bc..c7bf86374 100644 --- a/arch/ppc/Makefile +++ b/arch/ppc/Makefile @@ -14,7 +14,7 @@ cpu-$(CONFIG_ARCH_MPC5200) := mpc5xxx TEXT_BASE = $(CONFIG_TEXT_BASE) -CPPFLAGS += -DTEXT_BASE=$(TEXT_BASE) -P +CPPFLAGS += -DTEXT_BASE=$(TEXT_BASE) # Add cleanup flags ifndef CONFIG_MODULES diff --git a/arch/sandbox/Makefile b/arch/sandbox/Makefile index 4ca17ed83..73c06db09 100644 --- a/arch/sandbox/Makefile +++ b/arch/sandbox/Makefile @@ -10,7 +10,6 @@ lds-y := $(BOARD)/barebox.lds TEXT_BASE = $(CONFIG_TEXT_BASE) -CPPFLAGS += -P CFLAGS += -Dmalloc=barebox_malloc \ -Dfree=barebox_free -Drealloc=barebox_realloc \ -Dread=barebox_read -Dwrite=barebox_write \ diff --git a/arch/sandbox/os/Makefile b/arch/sandbox/os/Makefile index 2980301e1..dc211d94c 100644 --- a/arch/sandbox/os/Makefile +++ b/arch/sandbox/os/Makefile @@ -8,7 +8,6 @@ else CPPFLAGS = $(patsubst %,-I$(srctree)/%include,$(machdirs)) endif -CPPFLAGS += -P CFLAGS := -Wall NOSTDINC_FLAGS := diff --git a/arch/x86/Makefile b/arch/x86/Makefile index 3b034c051..db4180b32 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -5,7 +5,7 @@ machine-y := i386 TEXT_BASE = $(CONFIG_TEXT_BASE) -CPPFLAGS += -march=i386 -m32 -DTEXT_BASE=$(TEXT_BASE) -P +CPPFLAGS += -march=i386 -m32 -DTEXT_BASE=$(TEXT_BASE) LDFLAGS += -m elf_i386 ifndef CONFIG_MODULES diff --git a/scripts/Makefile.build b/scripts/Makefile.build index c2bab5cb1..f70e2b946 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -244,7 +244,7 @@ targets += $(extra-y) $(MAKECMDGOALS) $(always) # Linker scripts preprocessor (.lds.S -> .lds) # --------------------------------------------------------------------------- quiet_cmd_cpp_lds_S = LDS $@ - cmd_cpp_lds_S = $(CPP) $(cpp_flags) -D__ASSEMBLY__ -o $@ $< + cmd_cpp_lds_S = $(CPP) $(cpp_flags) -P -D__ASSEMBLY__ -o $@ $< %.lds: %.lds.S FORCE $(call if_changed_dep,cpp_lds_S) From 3808cb7a451a032c9181e6b3ed3f88b62eb46ee7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Minier?= Date: Fri, 14 Oct 2011 00:06:38 +0200 Subject: [PATCH 4/7] Avoid warnings by using format(__printf__) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When building sandbox, barebox is built with -Dprintf=barebox_printf as to not collide with the printf provided by libc. This would also match the format(printf) function __attribute__. Since gcc documents that __printf__ can be used instead of printf as a format attribute, use this instead and avoid a lot of noisy warnings. NB: this relates to 6b082cfe9f9b5b2bea294918ad916c739490cea7 which was an earlier attempt at solving this, which got reverted due to other regressions. Signed-off-by: Loïc Minier Signed-off-by: Sascha Hauer --- include/stdio.h | 12 ++++++------ scripts/mod/modpost.c | 2 +- scripts/mod/modpost.h | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/stdio.h b/include/stdio.h index c82476468..a0d81d3b7 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -9,7 +9,7 @@ */ /* serial stuff */ -void serial_printf(const char *fmt, ...) __attribute__ ((format(printf, 1, 2))); +void serial_printf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2))); /* stdin */ int tstc(void); @@ -30,12 +30,12 @@ static inline void putchar(char c) console_putc(CONSOLE_STDOUT, c); } -int printf(const char *fmt, ...) __attribute__ ((format(printf, 1, 2))); +int printf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2))); int vprintf(const char *fmt, va_list args); -int sprintf(char *buf, const char *fmt, ...) __attribute__ ((format(printf, 2, 3))); -int snprintf(char *buf, size_t size, const char *fmt, ...) __attribute__ ((format(printf, 3, 4))); +int sprintf(char *buf, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3))); +int snprintf(char *buf, size_t size, const char *fmt, ...) __attribute__ ((format(__printf__, 3, 4))); int vsprintf(char *buf, const char *fmt, va_list args); -char *asprintf(const char *fmt, ...) __attribute__ ((format(printf, 1, 2))); +char *asprintf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2))); char *vasprintf(const char *fmt, va_list ap); int vsnprintf(char *buf, size_t size, const char *fmt, va_list args); int vscnprintf(char *buf, size_t size, const char *fmt, va_list args); @@ -54,7 +54,7 @@ int vscnprintf(char *buf, size_t size, const char *fmt, va_list args); #define stderr 2 #define MAX_FILES 128 -void fprintf(int file, const char *fmt, ...) __attribute__ ((format(printf, 2, 3))); +void fprintf(int file, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3))); int fputs(int file, const char *s); int fputc(int file, const char c); int ftstc(int file); diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 08b75b67f..e99448602 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -1300,7 +1300,7 @@ static void read_symbols(char *modname) * following helper, then compare to the file on disk and * only update the later if anything changed */ -void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf, +void __attribute__((format(__printf__, 2, 3))) buf_printf(struct buffer *buf, const char *fmt, ...) { char tmp[SZ]; diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h index 4156dd34c..0c2325983 100644 --- a/scripts/mod/modpost.h +++ b/scripts/mod/modpost.h @@ -94,7 +94,7 @@ struct buffer { int size; }; -void __attribute__((format(printf, 2, 3))) +void __attribute__((format(__printf__, 2, 3))) buf_printf(struct buffer *buf, const char *fmt, ...); void From 74c36329c3531acf59d76a09cd0c4cf11ce6b6a0 Mon Sep 17 00:00:00 2001 From: Antony Pavlov Date: Tue, 18 Oct 2011 13:48:44 +0400 Subject: [PATCH 5/7] fs: fix path_check_prereq() This patch makes impossible the situations than path_check_prereq() can make 'return 0' without changing errno. Signed-off-by: Antony Pavlov Signed-off-by: Sascha Hauer --- fs/fs.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/fs.c b/fs/fs.c index 7d65ec819..714fc9bcd 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -293,9 +293,11 @@ static int path_check_prereq(const char *path, unsigned int flags) struct stat s; unsigned int m; + errno = 0; + if (stat(path, &s)) { if (flags & S_UB_DOES_NOT_EXIST) - return 0; + goto out; errno = -ENOENT; goto out; } @@ -306,7 +308,7 @@ static int path_check_prereq(const char *path, unsigned int flags) } if (flags == S_UB_EXISTS) - return 0; + goto out; m = s.st_mode; @@ -325,7 +327,6 @@ static int path_check_prereq(const char *path, unsigned int flags) goto out; } - errno = 0; out: return errno; } From a76e310abf6a82154dd6a1161a1883c031ec9652 Mon Sep 17 00:00:00 2001 From: Antony Pavlov Date: Tue, 18 Oct 2011 13:48:45 +0400 Subject: [PATCH 6/7] fs: fix chdir() chdir() allocates memory using mormalise_path(). But if path_check_prereq() returns error than memory isn't freed. Signed-off-by: Antony Pavlov Signed-off-by: Sascha Hauer --- fs/fs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/fs.c b/fs/fs.c index 714fc9bcd..f42ca3607 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -347,8 +347,9 @@ int chdir(const char *pathname) strcpy(cwd, p); - free(p); out: + free(p); + return errno; } EXPORT_SYMBOL(chdir); From dac6e90115de9b47295fc5289a26f686bcae4d35 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Wed, 19 Oct 2011 11:52:46 +0200 Subject: [PATCH 7/7] fix bug introduced with fixing path_check_prereq() This fixes a bug introduced with: commit 74c36329c3531acf59d76a09cd0c4cf11ce6b6a0 Author: Antony Pavlov Date: Tue Oct 18 13:48:44 2011 +0400 fs: fix path_check_prereq() This patch makes impossible the situations than path_check_prereq() can make 'return 0' without changing errno. Signed-off-by: Antony Pavlov Signed-off-by: Sascha Hauer path_check_prereq is supposed to return 0 when a file does not exist and S_UB_DOES_NOT_EXIST is given. stat() changes errno, so we have to set errno back to 0 before returning. Signed-off-by: Sascha Hauer --- fs/fs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/fs.c b/fs/fs.c index f42ca3607..51a7411b6 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -296,8 +296,10 @@ static int path_check_prereq(const char *path, unsigned int flags) errno = 0; if (stat(path, &s)) { - if (flags & S_UB_DOES_NOT_EXIST) + if (flags & S_UB_DOES_NOT_EXIST) { + errno = 0; goto out; + } errno = -ENOENT; goto out; } @@ -307,8 +309,10 @@ static int path_check_prereq(const char *path, unsigned int flags) goto out; } - if (flags == S_UB_EXISTS) + if (flags == S_UB_EXISTS) { + errno = 0; goto out; + } m = s.st_mode;