From 6fc7a1b006773ee1c06dc191a60e0bff4fb1a626 Mon Sep 17 00:00:00 2001 From: Jeroen Hofstee Date: Sat, 10 Aug 2013 17:16:50 +0200 Subject: [PATCH 01/16] compiler_gcc: do not redefine __gnu_attributes gcc allows extensions to be non compiler specific by defining __* macros for the attributes supported by gcc. Having a different definition causes many warnings during the build (cdefs.h on FreeBSD uses __attribute((__pure__)) where u-boot uses __attribute__((pure)) for example). Do not redefine these macros to suppress these warnings. This patch ignores the checkpatch warning: WARNING: __packed is preferred over __attribute__((packed)) Signed-off-by: Jeroen Hofstee [backport from u-boot mainline for gcc6] Signed-off-by: Seung-Woo Kim Change-Id: I3ee9aa3b3732cc97b4b3305908fcf62ee86e2964 --- include/linux/compiler-gcc.h | 12 +++++++++--- include/linux/compiler-gcc4.h | 4 +++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h index 73dcf80..9896e54 100644 --- a/include/linux/compiler-gcc.h +++ b/include/linux/compiler-gcc.h @@ -50,7 +50,9 @@ #endif #define __deprecated __attribute__((deprecated)) -#define __packed __attribute__((packed)) +#ifndef __packed +# define __packed __attribute__((packed)) +#endif #define __weak __attribute__((weak)) /* @@ -73,8 +75,12 @@ * would be. * [...] */ -#define __pure __attribute__((pure)) -#define __aligned(x) __attribute__((aligned(x))) +#ifndef __pure +# define __pure __attribute__((pure)) +#endif +#ifndef __aligned +# define __aligned(x) __attribute__((aligned(x))) +#endif #define __printf(a,b) __attribute__((format(printf,a,b))) #define noinline __attribute__((noinline)) #define __attribute_const__ __attribute__((__const__)) diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h index 94dea3f..27d11ca 100644 --- a/include/linux/compiler-gcc4.h +++ b/include/linux/compiler-gcc4.h @@ -12,7 +12,9 @@ #define __used __attribute__((__used__)) #define __must_check __attribute__((warn_unused_result)) #define __compiler_offsetof(a,b) __builtin_offsetof(a,b) -#define __always_inline inline __attribute__((always_inline)) +#ifndef __always_inline +# define __always_inline inline __attribute__((always_inline)) +#endif /* * A trick to suppress uninitialized variable warning without generating any -- 2.7.4 From 4d833cb626a993ad4e050682cf46d8cf39a9a749 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Thu, 4 Sep 2014 02:40:58 +0900 Subject: [PATCH 02/16] compiler*.h: sync include/linux/compiler*.h with Linux 3.16 Copy them from Linux v3.16 tag. My main motivation of this commit is to add compiler-clang.h. Signed-off-by: Masahiro Yamada Cc: Jeroen Hofstee [backport from u-boot mainline for gcc6] Signed-off-by: Seung-Woo Kim Change-Id: I1874abe85a7ed2c228fee5f7ceae0fa3eccaf5da --- include/linux/compiler-clang.h | 12 ++++++ include/linux/compiler-gcc.h | 57 ++++++++++++++++++-------- include/linux/compiler-gcc3.h | 20 ++++----- include/linux/compiler-gcc4.h | 59 +++++++++++++++++++-------- include/linux/compiler-intel.h | 40 ++++++++++++++++++ include/linux/compiler.h | 92 +++++++++++++++++++++++++++++++++++++++++- 6 files changed, 236 insertions(+), 44 deletions(-) create mode 100644 include/linux/compiler-clang.h create mode 100644 include/linux/compiler-intel.h diff --git a/include/linux/compiler-clang.h b/include/linux/compiler-clang.h new file mode 100644 index 0000000..d1e49d5 --- /dev/null +++ b/include/linux/compiler-clang.h @@ -0,0 +1,12 @@ +#ifndef __LINUX_COMPILER_H +#error "Please don't include directly, include instead." +#endif + +/* Some compiler specific definitions are overwritten here + * for Clang compiler + */ + +#ifdef uninitialized_var +#undef uninitialized_var +#define uninitialized_var(x) x = *(&(x)) +#endif diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h index 9896e54..02ae99e 100644 --- a/include/linux/compiler-gcc.h +++ b/include/linux/compiler-gcc.h @@ -5,6 +5,9 @@ /* * Common definitions for all gcc versions go here. */ +#define GCC_VERSION (__GNUC__ * 10000 \ + + __GNUC_MINOR__ * 100 \ + + __GNUC_PATCHLEVEL__) /* Optimization barrier */ @@ -34,9 +37,15 @@ __asm__ ("" : "=r"(__ptr) : "0"(ptr)); \ (typeof(ptr)) (__ptr + (off)); }) +/* Make the optimizer believe the variable can be manipulated arbitrarily. */ +#define OPTIMIZER_HIDE_VAR(var) __asm__ ("" : "=r" (var) : "0" (var)) + +#ifdef __CHECKER__ +#define __must_be_array(arr) 0 +#else /* &a[0] degrades to a pointer: a different type from an array */ -#define __must_be_array(a) \ - BUILD_BUG_ON_ZERO(__builtin_types_compatible_p(typeof(a), typeof(&a[0]))) +#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) +#endif /* * Force always-inline if the user requests it so via the .config, @@ -44,15 +53,18 @@ */ #if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \ !defined(CONFIG_OPTIMIZE_INLINING) || (__GNUC__ < 4) -# define inline inline __attribute__((always_inline)) -# define __inline__ __inline__ __attribute__((always_inline)) -# define __inline __inline __attribute__((always_inline)) +# define inline inline __attribute__((always_inline)) notrace +# define __inline__ __inline__ __attribute__((always_inline)) notrace +# define __inline __inline __attribute__((always_inline)) notrace +#else +/* A lot of inline functions can cause havoc with function tracing */ +# define inline inline notrace +# define __inline__ __inline__ notrace +# define __inline __inline notrace #endif #define __deprecated __attribute__((deprecated)) -#ifndef __packed -# define __packed __attribute__((packed)) -#endif +#define __packed __attribute__((packed)) #define __weak __attribute__((weak)) /* @@ -60,8 +72,12 @@ * naked functions because then mcount is called without stack and frame pointer * being set up and there is no chance to restore the lr register to the value * before mcount was called. + * + * The asm() bodies of naked functions often depend on standard calling conventions, + * therefore they must be noinline and noclone. GCC 4.[56] currently fail to enforce + * this, so we must do so ourselves. See GCC PR44290. */ -#define __naked __attribute__((naked)) notrace +#define __naked __attribute__((naked)) noinline __noclone notrace #define __noreturn __attribute__((noreturn)) @@ -75,13 +91,10 @@ * would be. * [...] */ -#ifndef __pure -# define __pure __attribute__((pure)) -#endif -#ifndef __aligned -# define __aligned(x) __attribute__((aligned(x))) -#endif -#define __printf(a,b) __attribute__((format(printf,a,b))) +#define __pure __attribute__((pure)) +#define __aligned(x) __attribute__((aligned(x))) +#define __printf(a, b) __attribute__((format(printf, a, b))) +#define __scanf(a, b) __attribute__((format(scanf, a, b))) #define noinline __attribute__((noinline)) #define __attribute_const__ __attribute__((__const__)) #define __maybe_unused __attribute__((unused)) @@ -91,3 +104,15 @@ #define _gcc_header(x) __gcc_header(linux/compiler-gcc##x.h) #define gcc_header(x) _gcc_header(x) #include gcc_header(__GNUC__) + +#if !defined(__noclone) +#define __noclone /* not needed */ +#endif + +/* + * A trick to suppress uninitialized variable warning without generating any + * code + */ +#define uninitialized_var(x) x = x + +#define __always_inline inline __attribute__((always_inline)) diff --git a/include/linux/compiler-gcc3.h b/include/linux/compiler-gcc3.h index 2befe65..7d89feb 100644 --- a/include/linux/compiler-gcc3.h +++ b/include/linux/compiler-gcc3.h @@ -2,20 +2,22 @@ #error "Please don't include directly, include instead." #endif -#if __GNUC_MINOR__ >= 3 +#if GCC_VERSION < 30200 +# error Sorry, your compiler is too old - please upgrade it. +#endif + +#if GCC_VERSION >= 30300 # define __used __attribute__((__used__)) #else # define __used __attribute__((__unused__)) #endif -#if __GNUC_MINOR__ >= 4 +#if GCC_VERSION >= 30400 #define __must_check __attribute__((warn_unused_result)) #endif -/* - * A trick to suppress uninitialized variable warning without generating any - * code - */ -#define uninitialized_var(x) x = x - -#define __always_inline inline __attribute__((always_inline)) +#ifdef CONFIG_GCOV_KERNEL +# if GCC_VERSION < 30400 +# error "GCOV profiling support for gcc versions below 3.4 not included" +# endif /* __GNUC_MINOR__ */ +#endif /* CONFIG_GCOV_KERNEL */ diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h index 27d11ca..2507fd2 100644 --- a/include/linux/compiler-gcc4.h +++ b/include/linux/compiler-gcc4.h @@ -4,7 +4,7 @@ /* GCC 4.1.[01] miscompiles __weak */ #ifdef __KERNEL__ -# if __GNUC_MINOR__ == 1 && __GNUC_PATCHLEVEL__ <= 1 +# if GCC_VERSION >= 40100 && GCC_VERSION <= 40101 # error Your version of gcc miscompiles the __weak directive # endif #endif @@ -12,17 +12,12 @@ #define __used __attribute__((__used__)) #define __must_check __attribute__((warn_unused_result)) #define __compiler_offsetof(a,b) __builtin_offsetof(a,b) -#ifndef __always_inline -# define __always_inline inline __attribute__((always_inline)) -#endif -/* - * A trick to suppress uninitialized variable warning without generating any - * code - */ -#define uninitialized_var(x) x = x +#if GCC_VERSION >= 40100 && GCC_VERSION < 40600 +# define __compiletime_object_size(obj) __builtin_object_size(obj, 0) +#endif -#if __GNUC_MINOR__ >= 3 +#if GCC_VERSION >= 40300 /* Mark functions as cold. gcc will assume any path leading to a call to them will be unlikely. This means a lot of manual unlikely()s are unnecessary now for any paths leading to the usual suspects @@ -38,8 +33,15 @@ the kernel context */ #define __cold __attribute__((__cold__)) +#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__) -#if __GNUC_MINOR__ >= 5 +#ifndef __CHECKER__ +# define __compiletime_warning(message) __attribute__((warning(message))) +# define __compiletime_error(message) __attribute__((error(message))) +#endif /* __CHECKER__ */ +#endif /* GCC_VERSION >= 40300 */ + +#if GCC_VERSION >= 40500 /* * Mark a position in code as unreachable. This can be used to * suppress control flow warnings after asm blocks that transfer @@ -50,14 +52,37 @@ * unreleased. Really, we need to have autoconf for the kernel. */ #define unreachable() __builtin_unreachable() -#endif +/* Mark a function definition as prohibited from being cloned. */ +#define __noclone __attribute__((__noclone__)) + +#endif /* GCC_VERSION >= 40500 */ + +#if GCC_VERSION >= 40600 +/* + * Tell the optimizer that something else uses this function or variable. + */ +#define __visible __attribute__((externally_visible)) #endif -#if __GNUC_MINOR__ > 0 -#define __compiletime_object_size(obj) __builtin_object_size(obj, 0) +/* + * GCC 'asm goto' miscompiles certain code sequences: + * + * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670 + * + * Work it around via a compiler barrier quirk suggested by Jakub Jelinek. + * Fixed in GCC 4.8.2 and later versions. + * + * (asm goto is automatically volatile - the naming reflects this.) + */ +#define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0) + +#ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP +#if GCC_VERSION >= 40400 +#define __HAVE_BUILTIN_BSWAP32__ +#define __HAVE_BUILTIN_BSWAP64__ #endif -#if __GNUC_MINOR__ >= 4 -#define __compiletime_warning(message) __attribute__((warning(message))) -#define __compiletime_error(message) __attribute__((error(message))) +#if GCC_VERSION >= 40800 || (defined(__powerpc__) && GCC_VERSION >= 40600) +#define __HAVE_BUILTIN_BSWAP16__ #endif +#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */ diff --git a/include/linux/compiler-intel.h b/include/linux/compiler-intel.h new file mode 100644 index 0000000..ba147a1 --- /dev/null +++ b/include/linux/compiler-intel.h @@ -0,0 +1,40 @@ +#ifndef __LINUX_COMPILER_H +#error "Please don't include directly, include instead." +#endif + +#ifdef __ECC + +/* Some compiler specific definitions are overwritten here + * for Intel ECC compiler + */ + +#include + +/* Intel ECC compiler doesn't support gcc specific asm stmts. + * It uses intrinsics to do the equivalent things. + */ +#undef RELOC_HIDE +#undef OPTIMIZER_HIDE_VAR + +#define RELOC_HIDE(ptr, off) \ + ({ unsigned long __ptr; \ + __ptr = (unsigned long) (ptr); \ + (typeof(ptr)) (__ptr + (off)); }) + +/* This should act as an optimization barrier on var. + * Given that this compiler does not have inline assembly, a compiler barrier + * is the best we can do. + */ +#define OPTIMIZER_HIDE_VAR(var) barrier() + +/* Intel ECC compiler doesn't support __builtin_types_compatible_p() */ +#define __must_be_array(a) 0 + +#endif + +#ifndef __HAVE_BUILTIN_BSWAP16__ +/* icc has this, but it's called _bswap16 */ +#define __HAVE_BUILTIN_BSWAP16__ +#define __builtin_bswap16 _bswap16 +#endif + diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 5be3dab..d5ad7b1 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -5,16 +5,23 @@ #ifdef __CHECKER__ # define __user __attribute__((noderef, address_space(1))) -# define __kernel /* default address space */ +# define __kernel __attribute__((address_space(0))) # define __safe __attribute__((safe)) # define __force __attribute__((force)) # define __nocast __attribute__((nocast)) # define __iomem __attribute__((noderef, address_space(2))) +# define __must_hold(x) __attribute__((context(x,1,1))) # define __acquires(x) __attribute__((context(x,0,1))) # define __releases(x) __attribute__((context(x,1,0))) # define __acquire(x) __context__(x,1) # define __release(x) __context__(x,-1) # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0) +# define __percpu __attribute__((noderef, address_space(3))) +#ifdef CONFIG_SPARSE_RCU_POINTER +# define __rcu __attribute__((noderef, address_space(4))) +#else +# define __rcu +#endif extern void __chk_user_ptr(const volatile void __user *); extern void __chk_io_ptr(const volatile void __iomem *); #else @@ -27,13 +34,20 @@ extern void __chk_io_ptr(const volatile void __iomem *); # define __chk_user_ptr(x) (void)0 # define __chk_io_ptr(x) (void)0 # define __builtin_warning(x, y...) (1) +# define __must_hold(x) # define __acquires(x) # define __releases(x) # define __acquire(x) (void)0 # define __release(x) (void)0 # define __cond_lock(x,c) (c) +# define __percpu +# define __rcu #endif +/* Indirect macros required for expanded argument pasting, eg. __LINE__. */ +#define ___PASTE(a,b) a##b +#define __PASTE(a,b) ___PASTE(a,b) + #ifdef __KERNEL__ #ifdef __GNUC__ @@ -49,6 +63,13 @@ extern void __chk_io_ptr(const volatile void __iomem *); # include #endif +/* Clang compiler defines __GNUC__. So we will overwrite implementations + * coming from above header files here + */ +#ifdef __clang__ +#include +#endif + /* * Generic compiler-dependent macros required for kernel * build go below this comment. Actual compiler/compiler version @@ -156,6 +177,15 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect); (typeof(ptr)) (__ptr + (off)); }) #endif +#ifndef OPTIMIZER_HIDE_VAR +#define OPTIMIZER_HIDE_VAR(var) barrier() +#endif + +/* Not-quite-unique ID. */ +#ifndef __UNIQUE_ID +# define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __LINE__) +#endif + #endif /* __KERNEL__ */ #endif /* __ASSEMBLY__ */ @@ -228,7 +258,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect); /* * Rather then using noinline to prevent stack consumption, use - * noinline_for_stack instead. For documentaiton reasons. + * noinline_for_stack instead. For documentation reasons. */ #define noinline_for_stack noinline @@ -270,11 +300,20 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect); # define __section(S) __attribute__ ((__section__(#S))) #endif +#ifndef __visible +#define __visible +#endif + /* Are two types/vars the same type (ignoring qualifiers)? */ #ifndef __same_type # define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) #endif +/* Is this type a native word size -- useful for atomic operations */ +#ifndef __native_word +# define __native_word(t) (sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long)) +#endif + /* Compile time object size, -1 for unknown */ #ifndef __compiletime_object_size # define __compiletime_object_size(obj) -1 @@ -284,8 +323,49 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect); #endif #ifndef __compiletime_error # define __compiletime_error(message) +/* + * Sparse complains of variable sized arrays due to the temporary variable in + * __compiletime_assert. Unfortunately we can't just expand it out to make + * sparse see a constant array size without breaking compiletime_assert on old + * versions of GCC (e.g. 4.2.4), so hide the array from sparse altogether. + */ +# ifndef __CHECKER__ +# define __compiletime_error_fallback(condition) \ + do { ((void)sizeof(char[1 - 2 * condition])); } while (0) +# endif +#endif +#ifndef __compiletime_error_fallback +# define __compiletime_error_fallback(condition) do { } while (0) #endif +#define __compiletime_assert(condition, msg, prefix, suffix) \ + do { \ + bool __cond = !(condition); \ + extern void prefix ## suffix(void) __compiletime_error(msg); \ + if (__cond) \ + prefix ## suffix(); \ + __compiletime_error_fallback(__cond); \ + } while (0) + +#define _compiletime_assert(condition, msg, prefix, suffix) \ + __compiletime_assert(condition, msg, prefix, suffix) + +/** + * compiletime_assert - break build and emit msg if condition is false + * @condition: a compile-time constant condition to check + * @msg: a message to emit if condition is false + * + * In tradition of POSIX assert, this macro will break the build if the + * supplied condition is *false*, emitting the supplied error message if the + * compiler has support to do so. + */ +#define compiletime_assert(condition, msg) \ + _compiletime_assert(condition, msg, __compiletime_assert_, __LINE__) + +#define compiletime_assert_atomic_type(t) \ + compiletime_assert(__native_word(t), \ + "Need native word sized stores/loads for atomicity.") + /* * Prevent the compiler from merging or refetching accesses. The compiler * is also forbidden from reordering successive instances of ACCESS_ONCE(), @@ -300,4 +380,12 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect); */ #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x)) +/* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */ +#ifdef CONFIG_KPROBES +# define __kprobes __attribute__((__section__(".kprobes.text"))) +# define nokprobe_inline __always_inline +#else +# define __kprobes +# define nokprobe_inline inline +#endif #endif /* __LINUX_COMPILER_H */ -- 2.7.4 From 26314cd880fc20de034c9e78667e984da6cae524 Mon Sep 17 00:00:00 2001 From: Jeroen Hofstee Date: Thu, 18 Sep 2014 20:10:27 +0200 Subject: [PATCH 03/16] compiler_gcc: prevent redefining attributes The libc headers on FreeBSD and likely related projects as well contain an header file, cdefs.h which provides similiar functionality as linux/compiler.h. It provides compiler independent defines like __weak __packed, to allow compiling with multiple compilers which might have a different syntax for such extension. Since that header file is included in multiple standard headers, like stddef.h and stdarg.h, multiple definitions of those defines will be present if both are included. When compiling u-boot the compiler will warn about it hundreds of times since e.g. common.h will include both files indirectly. commit 7ea50d52849fe8ffa5b5b74c979b60b1045d6fc9 "compiler_gcc: do not redefine __gnu_attributes" prevented such redefinitions, but this was undone by commit fb8ffd7cfc68b3dc44e182356a207d784cb30b34 "compiler*.h: sync include/linux/compiler*.h with Linux 3.16". Add the checks back where necessary to prevent such warnings. As the original patch this checkpatch warning is ignored: "WARNING: Adding new packed members is to be done with care" Cc: Masahiro Yamada Cc: Tom Rini Signed-off-by: Jeroen Hofstee Acked-by: Masahiro Yamada [backport from u-boot mainline for gcc6] Signed-off-by: Seung-Woo Kim Change-Id: I510e45c099dc0111a94c10035366675d94abdf3e --- include/linux/compiler-gcc.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h index 02ae99e..e057bd2 100644 --- a/include/linux/compiler-gcc.h +++ b/include/linux/compiler-gcc.h @@ -64,8 +64,12 @@ #endif #define __deprecated __attribute__((deprecated)) +#ifndef __packed #define __packed __attribute__((packed)) +#endif +#ifndef __weak #define __weak __attribute__((weak)) +#endif /* * it doesn't make sense on ARM (currently the only user of __naked) to trace @@ -91,8 +95,12 @@ * would be. * [...] */ +#ifndef __pure #define __pure __attribute__((pure)) +#endif +#ifndef __aligned #define __aligned(x) __attribute__((aligned(x))) +#endif #define __printf(a, b) __attribute__((format(printf, a, b))) #define __scanf(a, b) __attribute__((format(scanf, a, b))) #define noinline __attribute__((noinline)) @@ -115,4 +123,6 @@ */ #define uninitialized_var(x) x = x +#ifndef __always_inline #define __always_inline inline __attribute__((always_inline)) +#endif -- 2.7.4 From 1e7c26a57e34611fe059466bf0809874f503689c Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Sat, 7 Feb 2015 22:52:40 +0100 Subject: [PATCH 04/16] Add linux/compiler-gcc5.h to fix builds with gcc5 Add linux/compiler-gcc5/h from the kernel sources at: commit 5631b8fba640a4ab2f8a954f63a603fa34eda96b Author: Steven Noonan Date: Sat Oct 25 15:09:42 2014 -0700 compiler/gcc4+: Remove inaccurate comment about 'asm goto' miscompiles Signed-off-by: Hans de Goede [backport from u-boot mainline for gcc6] Signed-off-by: Seung-Woo Kim Change-Id: I04addcb7ccb452bc51e6b073e72cc570684e5bcc --- include/linux/compiler-gcc5.h | 65 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 include/linux/compiler-gcc5.h diff --git a/include/linux/compiler-gcc5.h b/include/linux/compiler-gcc5.h new file mode 100644 index 0000000..c8c5659 --- /dev/null +++ b/include/linux/compiler-gcc5.h @@ -0,0 +1,65 @@ +#ifndef __LINUX_COMPILER_H +#error "Please don't include directly, include instead." +#endif + +#define __used __attribute__((__used__)) +#define __must_check __attribute__((warn_unused_result)) +#define __compiler_offsetof(a, b) __builtin_offsetof(a, b) + +/* Mark functions as cold. gcc will assume any path leading to a call + to them will be unlikely. This means a lot of manual unlikely()s + are unnecessary now for any paths leading to the usual suspects + like BUG(), printk(), panic() etc. [but let's keep them for now for + older compilers] + + Early snapshots of gcc 4.3 don't support this and we can't detect this + in the preprocessor, but we can live with this because they're unreleased. + Maketime probing would be overkill here. + + gcc also has a __attribute__((__hot__)) to move hot functions into + a special section, but I don't see any sense in this right now in + the kernel context */ +#define __cold __attribute__((__cold__)) + +#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__) + +#ifndef __CHECKER__ +# define __compiletime_warning(message) __attribute__((warning(message))) +# define __compiletime_error(message) __attribute__((error(message))) +#endif /* __CHECKER__ */ + +/* + * Mark a position in code as unreachable. This can be used to + * suppress control flow warnings after asm blocks that transfer + * control elsewhere. + * + * Early snapshots of gcc 4.5 don't support this and we can't detect + * this in the preprocessor, but we can live with this because they're + * unreleased. Really, we need to have autoconf for the kernel. + */ +#define unreachable() __builtin_unreachable() + +/* Mark a function definition as prohibited from being cloned. */ +#define __noclone __attribute__((__noclone__)) + +/* + * Tell the optimizer that something else uses this function or variable. + */ +#define __visible __attribute__((externally_visible)) + +/* + * GCC 'asm goto' miscompiles certain code sequences: + * + * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670 + * + * Work it around via a compiler barrier quirk suggested by Jakub Jelinek. + * + * (asm goto is automatically volatile - the naming reflects this.) + */ +#define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0) + +#ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP +#define __HAVE_BUILTIN_BSWAP32__ +#define __HAVE_BUILTIN_BSWAP64__ +#define __HAVE_BUILTIN_BSWAP16__ +#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */ -- 2.7.4 From 76e3878e5c157d97f490df0298e2184969d839b4 Mon Sep 17 00:00:00 2001 From: Tom Rini Date: Mon, 29 Feb 2016 11:34:15 -0500 Subject: [PATCH 05/16] compiler*.h: sync include/linux/compiler*.h with Linux 4.5-rc6 Copy these from Linux v4.5-rc6 tag. This is needed so that we can keep up with newer gcc versions. Note that we don't have the uapi/ hierarchy from the kernel so continue to use Signed-off-by: Tom Rini [backport from u-boot mainline for gcc6] Signed-off-by: Seung-Woo Kim Change-Id: I21e3573bec8c826d4dfd4dc16d762f81e87be0c4 --- include/linux/compiler-gcc.h | 259 ++++++++++++++++++++++++++++++++--------- include/linux/compiler-gcc3.h | 23 ---- include/linux/compiler-gcc4.h | 88 -------------- include/linux/compiler-gcc5.h | 65 ----------- include/linux/compiler-intel.h | 5 + include/linux/compiler.h | 178 ++++++++++++++++++++++++++-- 6 files changed, 383 insertions(+), 235 deletions(-) delete mode 100644 include/linux/compiler-gcc3.h delete mode 100644 include/linux/compiler-gcc4.h delete mode 100644 include/linux/compiler-gcc5.h diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h index e057bd2..22ab246 100644 --- a/include/linux/compiler-gcc.h +++ b/include/linux/compiler-gcc.h @@ -5,14 +5,28 @@ /* * Common definitions for all gcc versions go here. */ -#define GCC_VERSION (__GNUC__ * 10000 \ - + __GNUC_MINOR__ * 100 \ - + __GNUC_PATCHLEVEL__) - +#define GCC_VERSION (__GNUC__ * 10000 \ + + __GNUC_MINOR__ * 100 \ + + __GNUC_PATCHLEVEL__) /* Optimization barrier */ + /* The "volatile" is due to gcc bugs */ #define barrier() __asm__ __volatile__("": : :"memory") +/* + * This version is i.e. to prevent dead stores elimination on @ptr + * where gcc and llvm may behave differently when otherwise using + * normal barrier(): while gcc behavior gets along with a normal + * barrier(), llvm needs an explicit input variable to be assumed + * clobbered. The issue is as follows: while the inline asm might + * access any memory it wants, the compiler could have fit all of + * @ptr into memory registers instead, and since @ptr never escaped + * from that, it proofed that the inline asm wasn't touching any of + * it. This version works well with both compilers, i.e. we're telling + * the compiler that the inline asm absolutely may see the contents + * of @ptr. See also: https://llvm.org/bugs/show_bug.cgi?id=15495 + */ +#define barrier_data(ptr) __asm__ __volatile__("": :"r"(ptr) :"memory") /* * This macro obfuscates arithmetic on a variable address so that gcc @@ -32,58 +46,63 @@ * the inline assembly constraint from =g to =r, in this particular * case either is valid. */ -#define RELOC_HIDE(ptr, off) \ - ({ unsigned long __ptr; \ - __asm__ ("" : "=r"(__ptr) : "0"(ptr)); \ - (typeof(ptr)) (__ptr + (off)); }) +#define RELOC_HIDE(ptr, off) \ +({ \ + unsigned long __ptr; \ + __asm__ ("" : "=r"(__ptr) : "0"(ptr)); \ + (typeof(ptr)) (__ptr + (off)); \ +}) /* Make the optimizer believe the variable can be manipulated arbitrarily. */ -#define OPTIMIZER_HIDE_VAR(var) __asm__ ("" : "=r" (var) : "0" (var)) +#define OPTIMIZER_HIDE_VAR(var) \ + __asm__ ("" : "=r" (var) : "0" (var)) #ifdef __CHECKER__ -#define __must_be_array(arr) 0 +#define __must_be_array(a) 0 #else /* &a[0] degrades to a pointer: a different type from an array */ -#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) +#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) #endif /* * Force always-inline if the user requests it so via the .config, * or if gcc is too old: */ -#if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \ +#if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \ !defined(CONFIG_OPTIMIZE_INLINING) || (__GNUC__ < 4) -# define inline inline __attribute__((always_inline)) notrace -# define __inline__ __inline__ __attribute__((always_inline)) notrace -# define __inline __inline __attribute__((always_inline)) notrace +#define inline inline __attribute__((always_inline)) notrace +#define __inline__ __inline__ __attribute__((always_inline)) notrace +#define __inline __inline __attribute__((always_inline)) notrace #else /* A lot of inline functions can cause havoc with function tracing */ -# define inline inline notrace -# define __inline__ __inline__ notrace -# define __inline __inline notrace +#define inline inline notrace +#define __inline__ __inline__ notrace +#define __inline __inline notrace #endif -#define __deprecated __attribute__((deprecated)) -#ifndef __packed -#define __packed __attribute__((packed)) -#endif -#ifndef __weak -#define __weak __attribute__((weak)) -#endif +#define __always_inline inline __attribute__((always_inline)) +#define noinline __attribute__((noinline)) + +#define __deprecated __attribute__((deprecated)) +#define __packed __attribute__((packed)) +#define __weak __attribute__((weak)) +#define __alias(symbol) __attribute__((alias(#symbol))) /* - * it doesn't make sense on ARM (currently the only user of __naked) to trace - * naked functions because then mcount is called without stack and frame pointer - * being set up and there is no chance to restore the lr register to the value - * before mcount was called. + * it doesn't make sense on ARM (currently the only user of __naked) + * to trace naked functions because then mcount is called without + * stack and frame pointer being set up and there is no chance to + * restore the lr register to the value before mcount was called. + * + * The asm() bodies of naked functions often depend on standard calling + * conventions, therefore they must be noinline and noclone. * - * The asm() bodies of naked functions often depend on standard calling conventions, - * therefore they must be noinline and noclone. GCC 4.[56] currently fail to enforce - * this, so we must do so ourselves. See GCC PR44290. + * GCC 4.[56] currently fail to enforce this, so we must do so ourselves. + * See GCC PR44290. */ -#define __naked __attribute__((naked)) noinline __noclone notrace +#define __naked __attribute__((naked)) noinline __noclone notrace -#define __noreturn __attribute__((noreturn)) +#define __noreturn __attribute__((noreturn)) /* * From the GCC manual: @@ -95,34 +114,170 @@ * would be. * [...] */ -#ifndef __pure -#define __pure __attribute__((pure)) +#define __pure __attribute__((pure)) +#define __aligned(x) __attribute__((aligned(x))) +#define __printf(a, b) __attribute__((format(printf, a, b))) +#define __scanf(a, b) __attribute__((format(scanf, a, b))) +#define __attribute_const__ __attribute__((__const__)) +#define __maybe_unused __attribute__((unused)) +#define __always_unused __attribute__((unused)) + +/* gcc version specific checks */ + +#if GCC_VERSION < 30200 +# error Sorry, your compiler is too old - please upgrade it. +#endif + +#if GCC_VERSION < 30300 +# define __used __attribute__((__unused__)) +#else +# define __used __attribute__((__used__)) +#endif + +#ifdef CONFIG_GCOV_KERNEL +# if GCC_VERSION < 30400 +# error "GCOV profiling support for gcc versions below 3.4 not included" +# endif /* __GNUC_MINOR__ */ +#endif /* CONFIG_GCOV_KERNEL */ + +#if GCC_VERSION >= 30400 +#define __must_check __attribute__((warn_unused_result)) +#endif + +#if GCC_VERSION >= 40000 + +/* GCC 4.1.[01] miscompiles __weak */ +#ifdef __KERNEL__ +# if GCC_VERSION >= 40100 && GCC_VERSION <= 40101 +# error Your version of gcc miscompiles the __weak directive +# endif +#endif + +#define __used __attribute__((__used__)) +#define __compiler_offsetof(a, b) \ + __builtin_offsetof(a, b) + +#if GCC_VERSION >= 40100 && GCC_VERSION < 40600 +# define __compiletime_object_size(obj) __builtin_object_size(obj, 0) +#endif + +#if GCC_VERSION >= 40300 +/* Mark functions as cold. gcc will assume any path leading to a call + * to them will be unlikely. This means a lot of manual unlikely()s + * are unnecessary now for any paths leading to the usual suspects + * like BUG(), printk(), panic() etc. [but let's keep them for now for + * older compilers] + * + * Early snapshots of gcc 4.3 don't support this and we can't detect this + * in the preprocessor, but we can live with this because they're unreleased. + * Maketime probing would be overkill here. + * + * gcc also has a __attribute__((__hot__)) to move hot functions into + * a special section, but I don't see any sense in this right now in + * the kernel context + */ +#define __cold __attribute__((__cold__)) + +#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__) + +#ifndef __CHECKER__ +# define __compiletime_warning(message) __attribute__((warning(message))) +# define __compiletime_error(message) __attribute__((error(message))) +#endif /* __CHECKER__ */ +#endif /* GCC_VERSION >= 40300 */ + +#if GCC_VERSION >= 40500 +/* + * Mark a position in code as unreachable. This can be used to + * suppress control flow warnings after asm blocks that transfer + * control elsewhere. + * + * Early snapshots of gcc 4.5 don't support this and we can't detect + * this in the preprocessor, but we can live with this because they're + * unreleased. Really, we need to have autoconf for the kernel. + */ +#define unreachable() __builtin_unreachable() + +/* Mark a function definition as prohibited from being cloned. */ +#define __noclone __attribute__((__noclone__)) + +#endif /* GCC_VERSION >= 40500 */ + +#if GCC_VERSION >= 40600 +/* + * When used with Link Time Optimization, gcc can optimize away C functions or + * variables which are referenced only from assembly code. __visible tells the + * optimizer that something else uses this function or variable, thus preventing + * this. + */ +#define __visible __attribute__((externally_visible)) #endif -#ifndef __aligned -#define __aligned(x) __attribute__((aligned(x))) + + +#if GCC_VERSION >= 40900 && !defined(__CHECKER__) +/* + * __assume_aligned(n, k): Tell the optimizer that the returned + * pointer can be assumed to be k modulo n. The second argument is + * optional (default 0), so we use a variadic macro to make the + * shorthand. + * + * Beware: Do not apply this to functions which may return + * ERR_PTRs. Also, it is probably unwise to apply it to functions + * returning extra information in the low bits (but in that case the + * compiler should see some alignment anyway, when the return value is + * massaged by 'flags = ptr & 3; ptr &= ~3;'). + */ +#define __assume_aligned(a, ...) __attribute__((__assume_aligned__(a, ## __VA_ARGS__))) #endif -#define __printf(a, b) __attribute__((format(printf, a, b))) -#define __scanf(a, b) __attribute__((format(scanf, a, b))) -#define noinline __attribute__((noinline)) -#define __attribute_const__ __attribute__((__const__)) -#define __maybe_unused __attribute__((unused)) -#define __always_unused __attribute__((unused)) -#define __gcc_header(x) #x -#define _gcc_header(x) __gcc_header(linux/compiler-gcc##x.h) -#define gcc_header(x) _gcc_header(x) -#include gcc_header(__GNUC__) +/* + * GCC 'asm goto' miscompiles certain code sequences: + * + * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670 + * + * Work it around via a compiler barrier quirk suggested by Jakub Jelinek. + * + * (asm goto is automatically volatile - the naming reflects this.) + */ +#define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0) + +#ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP +#if GCC_VERSION >= 40400 +#define __HAVE_BUILTIN_BSWAP32__ +#define __HAVE_BUILTIN_BSWAP64__ +#endif +#if GCC_VERSION >= 40800 || (defined(__powerpc__) && GCC_VERSION >= 40600) +#define __HAVE_BUILTIN_BSWAP16__ +#endif +#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */ + +#if GCC_VERSION >= 50000 +#define KASAN_ABI_VERSION 4 +#elif GCC_VERSION >= 40902 +#define KASAN_ABI_VERSION 3 +#endif + +#if GCC_VERSION >= 40902 +/* + * Tell the compiler that address safety instrumentation (KASAN) + * should not be applied to that function. + * Conflicts with inlining: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67368 + */ +#define __no_sanitize_address __attribute__((no_sanitize_address)) +#endif + +#endif /* gcc version >= 40000 specific checks */ #if !defined(__noclone) #define __noclone /* not needed */ #endif +#if !defined(__no_sanitize_address) +#define __no_sanitize_address +#endif + /* * A trick to suppress uninitialized variable warning without generating any * code */ #define uninitialized_var(x) x = x - -#ifndef __always_inline -#define __always_inline inline __attribute__((always_inline)) -#endif diff --git a/include/linux/compiler-gcc3.h b/include/linux/compiler-gcc3.h deleted file mode 100644 index 7d89feb..0000000 --- a/include/linux/compiler-gcc3.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef __LINUX_COMPILER_H -#error "Please don't include directly, include instead." -#endif - -#if GCC_VERSION < 30200 -# error Sorry, your compiler is too old - please upgrade it. -#endif - -#if GCC_VERSION >= 30300 -# define __used __attribute__((__used__)) -#else -# define __used __attribute__((__unused__)) -#endif - -#if GCC_VERSION >= 30400 -#define __must_check __attribute__((warn_unused_result)) -#endif - -#ifdef CONFIG_GCOV_KERNEL -# if GCC_VERSION < 30400 -# error "GCOV profiling support for gcc versions below 3.4 not included" -# endif /* __GNUC_MINOR__ */ -#endif /* CONFIG_GCOV_KERNEL */ diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h deleted file mode 100644 index 2507fd2..0000000 --- a/include/linux/compiler-gcc4.h +++ /dev/null @@ -1,88 +0,0 @@ -#ifndef __LINUX_COMPILER_H -#error "Please don't include directly, include instead." -#endif - -/* GCC 4.1.[01] miscompiles __weak */ -#ifdef __KERNEL__ -# if GCC_VERSION >= 40100 && GCC_VERSION <= 40101 -# error Your version of gcc miscompiles the __weak directive -# endif -#endif - -#define __used __attribute__((__used__)) -#define __must_check __attribute__((warn_unused_result)) -#define __compiler_offsetof(a,b) __builtin_offsetof(a,b) - -#if GCC_VERSION >= 40100 && GCC_VERSION < 40600 -# define __compiletime_object_size(obj) __builtin_object_size(obj, 0) -#endif - -#if GCC_VERSION >= 40300 -/* Mark functions as cold. gcc will assume any path leading to a call - to them will be unlikely. This means a lot of manual unlikely()s - are unnecessary now for any paths leading to the usual suspects - like BUG(), printk(), panic() etc. [but let's keep them for now for - older compilers] - - Early snapshots of gcc 4.3 don't support this and we can't detect this - in the preprocessor, but we can live with this because they're unreleased. - Maketime probing would be overkill here. - - gcc also has a __attribute__((__hot__)) to move hot functions into - a special section, but I don't see any sense in this right now in - the kernel context */ -#define __cold __attribute__((__cold__)) - -#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__) - -#ifndef __CHECKER__ -# define __compiletime_warning(message) __attribute__((warning(message))) -# define __compiletime_error(message) __attribute__((error(message))) -#endif /* __CHECKER__ */ -#endif /* GCC_VERSION >= 40300 */ - -#if GCC_VERSION >= 40500 -/* - * Mark a position in code as unreachable. This can be used to - * suppress control flow warnings after asm blocks that transfer - * control elsewhere. - * - * Early snapshots of gcc 4.5 don't support this and we can't detect - * this in the preprocessor, but we can live with this because they're - * unreleased. Really, we need to have autoconf for the kernel. - */ -#define unreachable() __builtin_unreachable() - -/* Mark a function definition as prohibited from being cloned. */ -#define __noclone __attribute__((__noclone__)) - -#endif /* GCC_VERSION >= 40500 */ - -#if GCC_VERSION >= 40600 -/* - * Tell the optimizer that something else uses this function or variable. - */ -#define __visible __attribute__((externally_visible)) -#endif - -/* - * GCC 'asm goto' miscompiles certain code sequences: - * - * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670 - * - * Work it around via a compiler barrier quirk suggested by Jakub Jelinek. - * Fixed in GCC 4.8.2 and later versions. - * - * (asm goto is automatically volatile - the naming reflects this.) - */ -#define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0) - -#ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP -#if GCC_VERSION >= 40400 -#define __HAVE_BUILTIN_BSWAP32__ -#define __HAVE_BUILTIN_BSWAP64__ -#endif -#if GCC_VERSION >= 40800 || (defined(__powerpc__) && GCC_VERSION >= 40600) -#define __HAVE_BUILTIN_BSWAP16__ -#endif -#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */ diff --git a/include/linux/compiler-gcc5.h b/include/linux/compiler-gcc5.h deleted file mode 100644 index c8c5659..0000000 --- a/include/linux/compiler-gcc5.h +++ /dev/null @@ -1,65 +0,0 @@ -#ifndef __LINUX_COMPILER_H -#error "Please don't include directly, include instead." -#endif - -#define __used __attribute__((__used__)) -#define __must_check __attribute__((warn_unused_result)) -#define __compiler_offsetof(a, b) __builtin_offsetof(a, b) - -/* Mark functions as cold. gcc will assume any path leading to a call - to them will be unlikely. This means a lot of manual unlikely()s - are unnecessary now for any paths leading to the usual suspects - like BUG(), printk(), panic() etc. [but let's keep them for now for - older compilers] - - Early snapshots of gcc 4.3 don't support this and we can't detect this - in the preprocessor, but we can live with this because they're unreleased. - Maketime probing would be overkill here. - - gcc also has a __attribute__((__hot__)) to move hot functions into - a special section, but I don't see any sense in this right now in - the kernel context */ -#define __cold __attribute__((__cold__)) - -#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__) - -#ifndef __CHECKER__ -# define __compiletime_warning(message) __attribute__((warning(message))) -# define __compiletime_error(message) __attribute__((error(message))) -#endif /* __CHECKER__ */ - -/* - * Mark a position in code as unreachable. This can be used to - * suppress control flow warnings after asm blocks that transfer - * control elsewhere. - * - * Early snapshots of gcc 4.5 don't support this and we can't detect - * this in the preprocessor, but we can live with this because they're - * unreleased. Really, we need to have autoconf for the kernel. - */ -#define unreachable() __builtin_unreachable() - -/* Mark a function definition as prohibited from being cloned. */ -#define __noclone __attribute__((__noclone__)) - -/* - * Tell the optimizer that something else uses this function or variable. - */ -#define __visible __attribute__((externally_visible)) - -/* - * GCC 'asm goto' miscompiles certain code sequences: - * - * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670 - * - * Work it around via a compiler barrier quirk suggested by Jakub Jelinek. - * - * (asm goto is automatically volatile - the naming reflects this.) - */ -#define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0) - -#ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP -#define __HAVE_BUILTIN_BSWAP32__ -#define __HAVE_BUILTIN_BSWAP64__ -#define __HAVE_BUILTIN_BSWAP16__ -#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */ diff --git a/include/linux/compiler-intel.h b/include/linux/compiler-intel.h index ba147a1..d4c7113 100644 --- a/include/linux/compiler-intel.h +++ b/include/linux/compiler-intel.h @@ -13,9 +13,14 @@ /* Intel ECC compiler doesn't support gcc specific asm stmts. * It uses intrinsics to do the equivalent things. */ +#undef barrier +#undef barrier_data #undef RELOC_HIDE #undef OPTIMIZER_HIDE_VAR +#define barrier() __memory_barrier() +#define barrier_data(ptr) barrier() + #define RELOC_HIDE(ptr, off) \ ({ unsigned long __ptr; \ __ptr = (unsigned long) (ptr); \ diff --git a/include/linux/compiler.h b/include/linux/compiler.h index d5ad7b1..020ad16 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -17,6 +17,7 @@ # define __release(x) __context__(x,-1) # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0) # define __percpu __attribute__((noderef, address_space(3))) +# define __pmem __attribute__((noderef, address_space(5))) #ifdef CONFIG_SPARSE_RCU_POINTER # define __rcu __attribute__((noderef, address_space(4))) #else @@ -42,6 +43,7 @@ extern void __chk_io_ptr(const volatile void __iomem *); # define __cond_lock(x,c) (c) # define __percpu # define __rcu +# define __pmem #endif /* Indirect macros required for expanded argument pasting, eg. __LINE__. */ @@ -54,7 +56,11 @@ extern void __chk_io_ptr(const volatile void __iomem *); #include #endif +#if defined(CC_USING_HOTPATCH) && !defined(__CHECKER__) +#define notrace __attribute__((hotpatch(0,0))) +#else #define notrace __attribute__((no_instrument_function)) +#endif /* Intel compiler defines __GNUC__. So we will overwrite implementations * coming from above header files here @@ -138,7 +144,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect); */ #define if(cond, ...) __trace_if( (cond , ## __VA_ARGS__) ) #define __trace_if(cond) \ - if (__builtin_constant_p((cond)) ? !!(cond) : \ + if (__builtin_constant_p(!!(cond)) ? !!(cond) : \ ({ \ int ______r; \ static struct ftrace_branch_data \ @@ -165,6 +171,10 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect); # define barrier() __memory_barrier() #endif +#ifndef barrier_data +# define barrier_data(ptr) barrier() +#endif + /* Unreachable code */ #ifndef unreachable # define unreachable() do { } while (1) @@ -186,6 +196,126 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect); # define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __LINE__) #endif +#include + +#define __READ_ONCE_SIZE \ +({ \ + switch (size) { \ + case 1: *(__u8 *)res = *(volatile __u8 *)p; break; \ + case 2: *(__u16 *)res = *(volatile __u16 *)p; break; \ + case 4: *(__u32 *)res = *(volatile __u32 *)p; break; \ + case 8: *(__u64 *)res = *(volatile __u64 *)p; break; \ + default: \ + barrier(); \ + __builtin_memcpy((void *)res, (const void *)p, size); \ + barrier(); \ + } \ +}) + +static __always_inline +void __read_once_size(const volatile void *p, void *res, int size) +{ + __READ_ONCE_SIZE; +} + +#ifdef CONFIG_KASAN +/* + * This function is not 'inline' because __no_sanitize_address confilcts + * with inlining. Attempt to inline it may cause a build failure. + * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67368 + * '__maybe_unused' allows us to avoid defined-but-not-used warnings. + */ +static __no_sanitize_address __maybe_unused +void __read_once_size_nocheck(const volatile void *p, void *res, int size) +{ + __READ_ONCE_SIZE; +} +#else +static __always_inline +void __read_once_size_nocheck(const volatile void *p, void *res, int size) +{ + __READ_ONCE_SIZE; +} +#endif + +static __always_inline void __write_once_size(volatile void *p, void *res, int size) +{ + switch (size) { + case 1: *(volatile __u8 *)p = *(__u8 *)res; break; + case 2: *(volatile __u16 *)p = *(__u16 *)res; break; + case 4: *(volatile __u32 *)p = *(__u32 *)res; break; + case 8: *(volatile __u64 *)p = *(__u64 *)res; break; + default: + barrier(); + __builtin_memcpy((void *)p, (const void *)res, size); + barrier(); + } +} + +/* + * Prevent the compiler from merging or refetching reads or writes. The + * compiler is also forbidden from reordering successive instances of + * READ_ONCE, WRITE_ONCE and ACCESS_ONCE (see below), but only when the + * compiler is aware of some particular ordering. One way to make the + * compiler aware of ordering is to put the two invocations of READ_ONCE, + * WRITE_ONCE or ACCESS_ONCE() in different C statements. + * + * In contrast to ACCESS_ONCE these two macros will also work on aggregate + * data types like structs or unions. If the size of the accessed data + * type exceeds the word size of the machine (e.g., 32 bits or 64 bits) + * READ_ONCE() and WRITE_ONCE() will fall back to memcpy and print a + * compile-time warning. + * + * Their two major use cases are: (1) Mediating communication between + * process-level code and irq/NMI handlers, all running on the same CPU, + * and (2) Ensuring that the compiler does not fold, spindle, or otherwise + * mutilate accesses that either do not require ordering or that interact + * with an explicit memory barrier or atomic instruction that provides the + * required ordering. + */ + +#define __READ_ONCE(x, check) \ +({ \ + union { typeof(x) __val; char __c[1]; } __u; \ + if (check) \ + __read_once_size(&(x), __u.__c, sizeof(x)); \ + else \ + __read_once_size_nocheck(&(x), __u.__c, sizeof(x)); \ + __u.__val; \ +}) +#define READ_ONCE(x) __READ_ONCE(x, 1) + +/* + * Use READ_ONCE_NOCHECK() instead of READ_ONCE() if you need + * to hide memory access from KASAN. + */ +#define READ_ONCE_NOCHECK(x) __READ_ONCE(x, 0) + +#define WRITE_ONCE(x, val) \ +({ \ + union { typeof(x) __val; char __c[1]; } __u = \ + { .__val = (__force typeof(x)) (val) }; \ + __write_once_size(&(x), __u.__c, sizeof(x)); \ + __u.__val; \ +}) + +/** + * smp_cond_acquire() - Spin wait for cond with ACQUIRE ordering + * @cond: boolean expression to wait for + * + * Equivalent to using smp_load_acquire() on the condition variable but employs + * the control dependency of the wait to reduce the barrier on many platforms. + * + * The control dependency provides a LOAD->STORE order, the additional RMB + * provides LOAD->LOAD order, together they provide LOAD->{LOAD,STORE} order, + * aka. ACQUIRE. + */ +#define smp_cond_acquire(cond) do { \ + while (!(cond)) \ + cpu_relax(); \ + smp_rmb(); /* ctrl + rmb := acquire */ \ +} while (0) + #endif /* __KERNEL__ */ #endif /* __ASSEMBLY__ */ @@ -304,6 +434,14 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect); #define __visible #endif +/* + * Assume alignment of return value. + */ +#ifndef __assume_aligned +#define __assume_aligned(a, ...) +#endif + + /* Are two types/vars the same type (ignoring qualifiers)? */ #ifndef __same_type # define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) @@ -311,7 +449,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect); /* Is this type a native word size -- useful for atomic operations */ #ifndef __native_word -# define __native_word(t) (sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long)) +# define __native_word(t) (sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long)) #endif /* Compile time object size, -1 for unknown */ @@ -373,12 +511,38 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect); * to make the compiler aware of ordering is to put the two invocations of * ACCESS_ONCE() in different C statements. * - * This macro does absolutely -nothing- to prevent the CPU from reordering, - * merging, or refetching absolutely anything at any time. Its main intended - * use is to mediate communication between process-level code and irq/NMI - * handlers, all running on the same CPU. + * ACCESS_ONCE will only work on scalar types. For union types, ACCESS_ONCE + * on a union member will work as long as the size of the member matches the + * size of the union and the size is smaller than word size. + * + * The major use cases of ACCESS_ONCE used to be (1) Mediating communication + * between process-level code and irq/NMI handlers, all running on the same CPU, + * and (2) Ensuring that the compiler does not fold, spindle, or otherwise + * mutilate accesses that either do not require ordering or that interact + * with an explicit memory barrier or atomic instruction that provides the + * required ordering. + * + * If possible use READ_ONCE()/WRITE_ONCE() instead. + */ +#define __ACCESS_ONCE(x) ({ \ + __maybe_unused typeof(x) __var = (__force typeof(x)) 0; \ + (volatile typeof(x) *)&(x); }) +#define ACCESS_ONCE(x) (*__ACCESS_ONCE(x)) + +/** + * lockless_dereference() - safely load a pointer for later dereference + * @p: The pointer to load + * + * Similar to rcu_dereference(), but for situations where the pointed-to + * object's lifetime is managed by something other than RCU. That + * "something other" might be reference counting or simple immortality. */ -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x)) +#define lockless_dereference(p) \ +({ \ + typeof(p) _________p1 = READ_ONCE(p); \ + smp_read_barrier_depends(); /* Dependency order vs. p above. */ \ + (_________p1); \ +}) /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */ #ifdef CONFIG_KPROBES -- 2.7.4 From 830e375db59ea2cfb502f9adca5b69e3c85356a1 Mon Sep 17 00:00:00 2001 From: "Dongkyun, Son" Date: Mon, 7 Nov 2016 17:42:50 +0900 Subject: [PATCH 06/16] build: fix gcc6 build error error: aliased to external symbol. Change-Id: I722d0051211d1835d6d4d764a05d959f2c88d315 Signed-off-by: Dongkyun, Son Signed-off-by: Seung-Woo Kim --- arch/arm/cpu/armv7/sc8830/check_reboot.c | 2 +- arch/arm/cpu/armv7/sc8830/misc.c | 2 +- arch/arm/include/asm/io.h | 12 ++++++------ arch/arm/lib/board.c | 18 +++++++++--------- common/main.c | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/arch/arm/cpu/armv7/sc8830/check_reboot.c b/arch/arm/cpu/armv7/sc8830/check_reboot.c index 66c0842..f751d8f 100644 --- a/arch/arm/cpu/armv7/sc8830/check_reboot.c +++ b/arch/arm/cpu/armv7/sc8830/check_reboot.c @@ -41,7 +41,7 @@ extern int hw_watchdog_rst_pending(void); extern inline int is_7s_reset(void); extern int is_7s_reset_for_systemdump(void); extern inline int is_hw_smpl_enable(void); -extern inline int is_smpl_bootup(void); +__attribute__ ((gnu_inline))inline int is_smpl_bootup(void); unsigned check_reboot_mode(void) { unsigned val, rst_mode= 0; diff --git a/arch/arm/cpu/armv7/sc8830/misc.c b/arch/arm/cpu/armv7/sc8830/misc.c index 07fbd8c..33cf5fc 100644 --- a/arch/arm/cpu/armv7/sc8830/misc.c +++ b/arch/arm/cpu/armv7/sc8830/misc.c @@ -381,7 +381,7 @@ static int smpl_config(void) #endif } #else -inline int is_smpl_bootup(void) +__attribute__ ((gnu_inline))inline int is_smpl_bootup(void) { return 0; } diff --git a/arch/arm/include/asm/io.h b/arch/arm/include/asm/io.h index ff1518e..8913a1c 100644 --- a/arch/arm/include/asm/io.h +++ b/arch/arm/include/asm/io.h @@ -75,42 +75,42 @@ static inline phys_addr_t virt_to_phys(void * vaddr) #define __arch_putw(v,a) (*(volatile unsigned short *)(a) = (v)) #define __arch_putl(v,a) (*(volatile unsigned int *)(a) = (v)) -extern inline void __raw_writesb(unsigned int addr, const void *data, int bytelen) +static inline void __raw_writesb(unsigned int addr, const void *data, int bytelen) { uint8_t *buf = (uint8_t *)data; while(bytelen--) __arch_putb(*buf++, addr); } -extern inline void __raw_writesw(unsigned int addr, const void *data, int wordlen) +static inline void __raw_writesw(unsigned int addr, const void *data, int wordlen) { uint16_t *buf = (uint16_t *)data; while(wordlen--) __arch_putw(*buf++, addr); } -extern inline void __raw_writesl(unsigned int addr, const void *data, int longlen) +static inline void __raw_writesl(unsigned int addr, const void *data, int longlen) { uint32_t *buf = (uint32_t *)data; while(longlen--) __arch_putl(*buf++, addr); } -extern inline void __raw_readsb(unsigned int addr, void *data, int bytelen) +static inline void __raw_readsb(unsigned int addr, void *data, int bytelen) { uint8_t *buf = (uint8_t *)data; while(bytelen--) *buf++ = __arch_getb(addr); } -extern inline void __raw_readsw(unsigned int addr, void *data, int wordlen) +static inline void __raw_readsw(unsigned int addr, void *data, int wordlen) { uint16_t *buf = (uint16_t *)data; while(wordlen--) *buf++ = __arch_getw(addr); } -extern inline void __raw_readsl(unsigned int addr, void *data, int longlen) +static inline void __raw_readsl(unsigned int addr, void *data, int longlen) { uint32_t *buf = (uint32_t *)data; while(longlen--) diff --git a/arch/arm/lib/board.c b/arch/arm/lib/board.c index 2e6bc6f..e91a131 100644 --- a/arch/arm/lib/board.c +++ b/arch/arm/lib/board.c @@ -92,23 +92,23 @@ extern void rtl8019_get_enetaddr (uchar * addr); ************************************************************************ * May be supplied by boards if desired */ -void inline __coloured_LED_init (void) {} +void __attribute__ ((gnu_inline))inline __coloured_LED_init (void) {} void coloured_LED_init (void) __attribute__((weak, alias("__coloured_LED_init"))); -void inline __red_LED_on (void) {} +void __attribute__ ((gnu_inline))inline __red_LED_on (void) {} void red_LED_on (void) __attribute__((weak, alias("__red_LED_on"))); -void inline __red_LED_off(void) {} +void __attribute__ ((gnu_inline))inline __red_LED_off(void) {} void red_LED_off(void) __attribute__((weak, alias("__red_LED_off"))); -void inline __green_LED_on(void) {} +void __attribute__ ((gnu_inline))inline __green_LED_on(void) {} void green_LED_on(void) __attribute__((weak, alias("__green_LED_on"))); -void inline __green_LED_off(void) {} +void __attribute__ ((gnu_inline))inline __green_LED_off(void) {} void green_LED_off(void) __attribute__((weak, alias("__green_LED_off"))); -void inline __yellow_LED_on(void) {} +void __attribute__ ((gnu_inline))inline __yellow_LED_on(void) {} void yellow_LED_on(void) __attribute__((weak, alias("__yellow_LED_on"))); -void inline __yellow_LED_off(void) {} +void __attribute__ ((gnu_inline))inline __yellow_LED_off(void) {} void yellow_LED_off(void) __attribute__((weak, alias("__yellow_LED_off"))); -void inline __blue_LED_on(void) {} +void __attribute__ ((gnu_inline))inline __blue_LED_on(void) {} void blue_LED_on(void) __attribute__((weak, alias("__blue_LED_on"))); -void inline __blue_LED_off(void) {} +void __attribute__ ((gnu_inline))inline __blue_LED_off(void) {} void blue_LED_off(void) __attribute__((weak, alias("__blue_LED_off"))); extern int boot_pwr_check(void); diff --git a/common/main.c b/common/main.c index 3b45583..f100fc7 100644 --- a/common/main.c +++ b/common/main.c @@ -47,7 +47,7 @@ DECLARE_GLOBAL_DATA_PTR; /* * Board-specific Platform code can reimplement show_boot_progress () if needed */ -void inline __show_boot_progress (int val) {} +void __attribute__ ((gnu_inline))inline __show_boot_progress (int val) {} void show_boot_progress (int val) __attribute__((weak, alias("__show_boot_progress"))); #if defined(CONFIG_BOOT_RETRY_TIME) && defined(CONFIG_RESET_TO_RETRY) -- 2.7.4 From 6925411d5b3b7a182f409af6f745a9c9cfc8a632 Mon Sep 17 00:00:00 2001 From: Seung-Woo Kim Date: Fri, 13 Jan 2017 14:17:23 +0900 Subject: [PATCH 07/16] packaging: remove To-Be-Unsupported macro The tizen_target_name macro will be removed, so this patch removes it. Change-Id: I2b83e3dc6d7754ae875f31fc3a8345b472cf56e0 Signed-off-by: Seung-Woo Kim --- packaging/u-boot-tm1.spec | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packaging/u-boot-tm1.spec b/packaging/u-boot-tm1.spec index 9d38386..4fa0d9b 100644 --- a/packaging/u-boot-tm1.spec +++ b/packaging/u-boot-tm1.spec @@ -9,10 +9,6 @@ URL: http://www.denx.de/wiki/U-Boot Source0: %{name}-%{version}.tar.bz2 Source1001: packaging/u-boot-tm1.manifest -%if "%{?tizen_target_name}" != "TM1" -ExcludeArch: %{arm} -%endif - %description bootloader for Embedded boards based on ARM processor -- 2.7.4 From 1816491ef9cf99e6f8b7d29f9b099d585c75d964 Mon Sep 17 00:00:00 2001 From: Seung-Woo Kim Date: Wed, 25 Jan 2017 09:31:52 +0900 Subject: [PATCH 08/16] tizen: add ramdisk1 partition to default partition table This patch adds ramdisk1 partition to default partition table to flash ramdisk.img to the partition. Change-Id: I5aa9ec8b61f51af0806a6ebd97b3bc8bda1c77e7 Signed-off-by: Seung-Woo Kim --- include/configs/tizen_tm1.h | 1 + property/tizen_part.h | 1 + 2 files changed, 2 insertions(+) diff --git a/include/configs/tizen_tm1.h b/include/configs/tizen_tm1.h index f4924ef..916c108 100644 --- a/include/configs/tizen_tm1.h +++ b/include/configs/tizen_tm1.h @@ -409,6 +409,7 @@ #define PARTS_ROOTFS "rootfs" #define PARTS_RUNTIMENV1 "runtimenv1" #define PARTS_RUNTIMENV2 "runtimenv2" +#define PARTS_RAMDISK "ramdisk1" #define CONFIG_SIG diff --git a/property/tizen_part.h b/property/tizen_part.h index 386d0eb..487577b 100644 --- a/property/tizen_part.h +++ b/property/tizen_part.h @@ -27,6 +27,7 @@ struct part_mapping_table thor_part_map[] = { { 26, PARTS_ROOTFS, "rootfs", 0xc9d000, 0x1c0000, 0x200 }, { -1, PARTS_RUNTIMENV1, "", 0x5800, 0x800, 0x200 }, { -1, PARTS_RUNTIMENV2, "", 0x6000, 0x800, 0x200 }, + { -1, PARTS_RAMDISK, "ramdisk", 0x1e000, 0x4000, 0x200 }, }; #endif /* _TIZEN_PART_H_ */ -- 2.7.4 From 25b0d59d9acd91f1ee87dfcb9acc3d7654db4a95 Mon Sep 17 00:00:00 2001 From: Seung-Woo Kim Date: Wed, 25 Jan 2017 13:20:39 +0900 Subject: [PATCH 09/16] tizen: add ramdisk bootmode with ramdisk config option This patch adds ramdisk bootmode with ramdisk boot config option. Change-Id: Ic9b571b4eb7c09805b7f567fa9ffa5ec08fe51de Signed-off-by: Seung-Woo Kim --- include/normal_mode.h | 1 + property/normal_emc_mode.c | 10 ++++++++++ property/normal_mode.c | 13 ++++++++++--- property/tizen_misc.c | 5 +++++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/include/normal_mode.h b/include/normal_mode.h index 2b2ab25..bd4beba 100644 --- a/include/normal_mode.h +++ b/include/normal_mode.h @@ -53,6 +53,7 @@ extern unsigned char raw_header[8192]; #define VLX_TAG_ADDR 0x82000100 #define DT_ADR 0x85400000 #define RAMDISK_ADR 0x85500000 +#define RAMDISK_SIZE_MB 8 #if defined (CONFIG_SPX30G) #define COOPERATE_PROCESSOR_RESET_ADDR 0x402b00b0 diff --git a/property/normal_emc_mode.c b/property/normal_emc_mode.c index d4fdecb..e364956 100644 --- a/property/normal_emc_mode.c +++ b/property/normal_emc_mode.c @@ -560,6 +560,15 @@ LOCAL int _boot_load_kernel_ramdisk_image(block_dev_desc_t * dev, char *bootmode debugf("%s:dt load error!\n", __FUNCTION__); return 0; } + + +#ifdef CONFIG_TIZEN +#ifdef CONFIG_RAMDISK_BOOT + { + load_ramdisk(PARTS_RAMDISK, RAMDISK_ADR, RAMDISK_SIZE_MB * 1024 * 1024); + } +#endif /* CONFIG_RAMDISK_BOOT */ +#else /* CONFIG_TIZEN */ #ifdef CONFIG_SDRAMDISK { int sd_ramdisk_size = 0; @@ -574,6 +583,7 @@ LOCAL int _boot_load_kernel_ramdisk_image(block_dev_desc_t * dev, char *bootmode hdr->ramdisk_size = sd_ramdisk_size; } #endif +#endif /* CONFIG_TIZEN */ return 1; } diff --git a/property/normal_mode.c b/property/normal_mode.c index 2bd31af..3ef7204 100644 --- a/property/normal_mode.c +++ b/property/normal_mode.c @@ -172,15 +172,18 @@ int fdt_fixup_for_tizen(void *fdt) /* Tizen default cmdline: mem */ ptr += sprintf(ptr, CMDLINE_DEFAULT_TIZEN); +#ifdef CONFIG_RAMDISK_BOOT + ptr += sprintf(ptr, " root=/dev/ram0 rw initrd=0x%x,%dM", + RAMDISK_ADR, RAMDISK_SIZE_MB); +#else val = tizen_get_part_num(PARTS_ROOTFS); ptr += sprintf(ptr, " root=/dev/mmcblk0p%d ro rootfstype=ext4 rootwait", val); + ptr += sprintf(ptr, " initrd=0x%x,0x%x", RAMDISK_ADR, 0); +#endif ptr += sprintf(ptr, " lcd_id=ID%06x", load_lcd_id_to_kernel()); ptr += sprintf(ptr, " lcd_base=%x", CONFIG_FB_RAM_BASE); - /* check ramdisk_size */ - ptr += sprintf(ptr, " initrd=0x%x,0x%x", RAMDISK_ADR, 0); - ptr += sprintf(ptr, " mtp_offset=%s", load_mtp_offset_to_kernel()); ptr += sprintf(ptr, " elvss_offset=0x%x", load_elvss_offset_to_kernel()); ptr += sprintf(ptr, " hbm_offset=%s", load_hbm_offset_to_kernel()); @@ -197,7 +200,11 @@ int fdt_fixup_for_tizen(void *fdt) break; case PM_STATE_NORMAL: default: +#ifdef CONFIG_RAMDISK_BOOT + ptr += sprintf(ptr, " bootmode=ramdisk"); +#else ptr += sprintf(ptr, " bootmode=normal"); +#endif } thor_save_env("normal"); diff --git a/property/tizen_misc.c b/property/tizen_misc.c index a881d17..263c476 100644 --- a/property/tizen_misc.c +++ b/property/tizen_misc.c @@ -775,6 +775,11 @@ static int load_binary_to_addr(char *name, unsigned int addr, unsigned int size) return 0; } +int load_ramdisk(char *name, unsigned int base_addr, unsigned int size) +{ + return load_binary_to_addr(name, base_addr, size); +} + int check_board_signature(char *fname, unsigned int dn_addr, unsigned int size) { struct sig_header bh_target; -- 2.7.4 From cda554e2afee98343e51296d9ff98b8d04cae4fd Mon Sep 17 00:00:00 2001 From: Seung-Woo Kim Date: Wed, 25 Jan 2017 13:22:15 +0900 Subject: [PATCH 10/16] tizen: tm1: enable ramdisk bootmode config option This patch enables ramdisk bootmode config option for tm1 board. Change-Id: I591324581500f9e10f2888f4c8bea46c3924bf10 Signed-off-by: Seung-Woo Kim --- include/configs/tizen_tm1.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/configs/tizen_tm1.h b/include/configs/tizen_tm1.h index 916c108..1c0b878 100644 --- a/include/configs/tizen_tm1.h +++ b/include/configs/tizen_tm1.h @@ -411,6 +411,8 @@ #define PARTS_RUNTIMENV2 "runtimenv2" #define PARTS_RAMDISK "ramdisk1" +#define CONFIG_RAMDISK_BOOT 1 + #define CONFIG_SIG #ifdef CONFIG_CMD_NET -- 2.7.4 From 0eb9c61b163897ce42932843ef1442d50075f4fc Mon Sep 17 00:00:00 2001 From: Seung-Woo Kim Date: Fri, 10 Feb 2017 13:15:09 +0900 Subject: [PATCH 11/16] tizen: add ramdisk2 partition to default parition table This patch adds ramdisk2 partition to default partition table to flash ramdisk-recovery.img to the partition for recovery mode. Change-Id: Ia6d1f78f14f40c83235af104c400af94552cb2f7 Signed-off-by: Seung-Woo Kim --- include/configs/tizen_tm1.h | 1 + property/tizen_part.h | 1 + 2 files changed, 2 insertions(+) diff --git a/include/configs/tizen_tm1.h b/include/configs/tizen_tm1.h index 1c0b878..4830323 100644 --- a/include/configs/tizen_tm1.h +++ b/include/configs/tizen_tm1.h @@ -410,6 +410,7 @@ #define PARTS_RUNTIMENV1 "runtimenv1" #define PARTS_RUNTIMENV2 "runtimenv2" #define PARTS_RAMDISK "ramdisk1" +#define PARTS_RAMDISK2 "ramdisk2" #define CONFIG_RAMDISK_BOOT 1 diff --git a/property/tizen_part.h b/property/tizen_part.h index 487577b..b12f176 100644 --- a/property/tizen_part.h +++ b/property/tizen_part.h @@ -28,6 +28,7 @@ struct part_mapping_table thor_part_map[] = { { -1, PARTS_RUNTIMENV1, "", 0x5800, 0x800, 0x200 }, { -1, PARTS_RUNTIMENV2, "", 0x6000, 0x800, 0x200 }, { -1, PARTS_RAMDISK, "ramdisk", 0x1e000, 0x4000, 0x200 }, + { -1, PARTS_RAMDISK2, "ramdisk-recovery", 0x22000, 0x4000, 0x200 }, }; #endif /* _TIZEN_PART_H_ */ -- 2.7.4 From 4bc519de93882e50a13916c9bc218d3f1ac38e9f Mon Sep 17 00:00:00 2001 From: Seung-Woo Kim Date: Fri, 10 Feb 2017 13:59:26 +0900 Subject: [PATCH 12/16] tizen: fix to load kernel image with partition information This patch fixes to load kernel image with partition information instead of hard coded block offset of emmc. Change-Id: I4026c517a272e358acbd018473549c15689300ec Signed-off-by: Seung-Woo Kim --- include/configs/tizen_tm1.h | 2 +- property/normal_emc_mode.c | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/configs/tizen_tm1.h b/include/configs/tizen_tm1.h index 4830323..c815126 100644 --- a/include/configs/tizen_tm1.h +++ b/include/configs/tizen_tm1.h @@ -60,7 +60,7 @@ //#define CONFIG_YAFFS2 1 //#define BOOT_PART "boot" -#define BOOT_PART "KERNEL" +#define BOOT_PART "kernel" #define RECOVERY_PART "recovery" #define UBIPAC_PART "ubipac" diff --git a/property/normal_emc_mode.c b/property/normal_emc_mode.c index e364956..cba588b 100644 --- a/property/normal_emc_mode.c +++ b/property/normal_emc_mode.c @@ -519,16 +519,24 @@ LOCAL int _boot_load_kernel_ramdisk_image(block_dev_desc_t * dev, char *bootmode uint32 size, offset; uint32 dt_img_adr; uint32 secure_boot_offset = 0; + disk_partition_t info; if (0 == memcmp(bootmode, RECOVERY_PART, strlen(RECOVERY_PART))) { partition = L"recovery"; debugf("enter recovery mode!\n"); } else { - partition = BOOT_PART; - debugf("Enter boot mode (partition name: %s)\n", partition); + partition = L""BOOT_PART; + debugf("Enter boot mode (partition name: %s)\n", w2c(partition)); } - if (!blk_data_read(0x2C00000, sizeof(*hdr), hdr)) { + if (get_partition_info_by_name(dev, partition, &info)) { + debugf("get partition %s info failed!\n", w2c(partition)); + return 0; + } + + offset = info.start * info.blksz; + + if (!blk_data_read(offset, sizeof(*hdr), hdr)) { debugf("%s:%s read error!\n", __FUNCTION__, w2c(partition)); return 0; } @@ -547,7 +555,7 @@ LOCAL int _boot_load_kernel_ramdisk_image(block_dev_desc_t * dev, char *bootmode debugf("bzImage size: %x\n", size); - if (!blk_data_read(0x2C00000, size, KERNEL_ADR - roundup(sizeof(*hdr), ALIGN_SIZE))) { + if (!blk_data_read(offset, size, KERNEL_ADR - roundup(sizeof(*hdr), ALIGN_SIZE))) { debugf("%s:%s kernel read error!\n", __FUNCTION__, w2c(partition)); return 0; } -- 2.7.4 From a7359e2fdf25ebe757fdbf54b0571cb85fdb3e10 Mon Sep 17 00:00:00 2001 From: Seung-Woo Kim Date: Fri, 10 Feb 2017 14:04:42 +0900 Subject: [PATCH 13/16] tizen: add recovery boot mode This patch adds recovery boot mode, in which mode, kernel image is loaded from recovery partition and ramdisk image is loaded from ramdisk2 partition. Also, it sets "bootmode=recovery" to bootargs of kernel. Change-Id: I5f6a024962a0d4744266763f7cddec8b6e4e2ea4 Signed-off-by: Seung-Woo Kim --- arch/arm/cpu/armv7/sc8830/misc.c | 15 +++++++++++++++ include/normal_mode.h | 1 + property/boot_mode_regist.c | 2 +- property/cmd_cboot.c | 8 ++++++++ property/normal_emc_mode.c | 8 +++++++- property/normal_mode.c | 15 +++++++++++++-- 6 files changed, 45 insertions(+), 4 deletions(-) diff --git a/arch/arm/cpu/armv7/sc8830/misc.c b/arch/arm/cpu/armv7/sc8830/misc.c index 33cf5fc..fbe348f 100644 --- a/arch/arm/cpu/armv7/sc8830/misc.c +++ b/arch/arm/cpu/armv7/sc8830/misc.c @@ -427,6 +427,7 @@ void pmic_init(void) #define REBOOT_MODE_MASK (0xFFFFFFF0) #define REBOOT_MODE_PREFIX (0x12345670) #define REBOOT_THOR_DOWNLOAD (0x1) +#define REBOOT_RECOVERY (0x4) int tizen_reboot_check(void) { int inform3 = readl(INFORM3); @@ -440,6 +441,20 @@ int tizen_reboot_check(void) return 0; } + +int tizen_reboot_recovery_check(void) +{ + int inform3 = readl(INFORM3); + + if ((inform3 & REBOOT_MODE_MASK) == REBOOT_MODE_PREFIX) { + if ((inform3 & 0xf) == REBOOT_RECOVERY) { + writel(0, INFORM3); + return 1; + } + } + + return 0; +} #endif #define REG32(x) (*((volatile uint32 *)(x))) diff --git a/include/normal_mode.h b/include/normal_mode.h index bd4beba..21d955e 100644 --- a/include/normal_mode.h +++ b/include/normal_mode.h @@ -216,6 +216,7 @@ int creat_cmdline(char * cmdline,boot_img_hdr *hdr); void vlx_entry(); extern char* get_product_sn(void); extern char *calibration_cmd_buf; +void set_recovery_mode(unsigned int recovery_mode); diff --git a/property/boot_mode_regist.c b/property/boot_mode_regist.c index 44dda2d..4d06c1f 100644 --- a/property/boot_mode_regist.c +++ b/property/boot_mode_regist.c @@ -35,8 +35,8 @@ void cmd_mode_regist(CBOOT_MODE_ENTRY *array) MODE_REGIST(CMD_NORMAL_MODE, normal_mode); MODE_REGIST(CMD_CHARGE_MODE, charge_mode); MODE_REGIST(CMD_THOR_MODE, thor_mode); -#ifndef CONFIG_TIZEN MODE_REGIST(CMD_RECOVERY_MODE, recovery_mode); +#ifndef CONFIG_TIZEN MODE_REGIST(CMD_FACTORYTEST_MODE,factorytest_mode); MODE_REGIST(CMD_FASTBOOT_MODE, fastboot_mode); MODE_REGIST(CMD_WATCHDOG_REBOOT, watchdog_mode); diff --git a/property/cmd_cboot.c b/property/cmd_cboot.c index d184fd8..663ad2d 100644 --- a/property/cmd_cboot.c +++ b/property/cmd_cboot.c @@ -230,6 +230,7 @@ boot_mode_enum_type get_mode_from_gpio_extend(void){ #ifdef CONFIG_TIZEN extern int tizen_reboot_check(void); +extern int tizen_reboot_recovery_check(void); #endif int do_cboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) @@ -290,6 +291,13 @@ int do_cboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) if (tizen_reboot_check()) { bootmode = CMD_THOR_MODE; DBG("do_cboot:boot mode is %d\n",bootmode); + } else if (tizen_reboot_recovery_check()) { +#ifdef CONFIG_RAMDISK_BOOT + bootmode = CMD_RECOVERY_MODE; +#else + bootmode = CMD_NORMAL_MODE; +#endif + DBG("do_cboot:boot mode is %d\n",bootmode); } } diff --git a/property/normal_emc_mode.c b/property/normal_emc_mode.c index cba588b..55b1fa1 100644 --- a/property/normal_emc_mode.c +++ b/property/normal_emc_mode.c @@ -524,6 +524,7 @@ LOCAL int _boot_load_kernel_ramdisk_image(block_dev_desc_t * dev, char *bootmode if (0 == memcmp(bootmode, RECOVERY_PART, strlen(RECOVERY_PART))) { partition = L"recovery"; debugf("enter recovery mode!\n"); + set_recovery_mode(1); } else { partition = L""BOOT_PART; debugf("Enter boot mode (partition name: %s)\n", w2c(partition)); @@ -573,7 +574,12 @@ LOCAL int _boot_load_kernel_ramdisk_image(block_dev_desc_t * dev, char *bootmode #ifdef CONFIG_TIZEN #ifdef CONFIG_RAMDISK_BOOT { - load_ramdisk(PARTS_RAMDISK, RAMDISK_ADR, RAMDISK_SIZE_MB * 1024 * 1024); + char *ramdisk_part; + if (0 == memcmp(bootmode, RECOVERY_PART, strlen(RECOVERY_PART))) + ramdisk_part = PARTS_RAMDISK2; + else + ramdisk_part = PARTS_RAMDISK; + load_ramdisk(ramdisk_part, RAMDISK_ADR, RAMDISK_SIZE_MB * 1024 * 1024); } #endif /* CONFIG_RAMDISK_BOOT */ #else /* CONFIG_TIZEN */ diff --git a/property/normal_mode.c b/property/normal_mode.c index 3ef7204..0e4cd49 100644 --- a/property/normal_mode.c +++ b/property/normal_mode.c @@ -33,6 +33,7 @@ void *harsh_data = harsh_data_buf; unsigned char raw_header[8192]; const int SP09_MAX_PHASE_BUFF_SIZE = sizeof(SP09_PHASE_CHECK_T); unsigned int g_charger_mode = 0; +unsigned int g_recovery_mode = 0; char serial_number_to_transfer[SP09_MAX_SN_LEN]; extern int charger_connected(void); @@ -173,6 +174,9 @@ int fdt_fixup_for_tizen(void *fdt) ptr += sprintf(ptr, CMDLINE_DEFAULT_TIZEN); #ifdef CONFIG_RAMDISK_BOOT + if (g_recovery_mode) + ptr += sprintf(ptr, " bootmode=recovery"); + ptr += sprintf(ptr, " root=/dev/ram0 rw initrd=0x%x,%dM", RAMDISK_ADR, RAMDISK_SIZE_MB); #else @@ -200,11 +204,13 @@ int fdt_fixup_for_tizen(void *fdt) break; case PM_STATE_NORMAL: default: + if (!g_recovery_mode) { #ifdef CONFIG_RAMDISK_BOOT - ptr += sprintf(ptr, " bootmode=ramdisk"); + ptr += sprintf(ptr, " bootmode=ramdisk"); #else - ptr += sprintf(ptr, " bootmode=normal"); + ptr += sprintf(ptr, " bootmode=normal"); #endif + } } thor_save_env("normal"); @@ -389,6 +395,11 @@ static int start_linux() return 0; } +void set_recovery_mode(unsigned int recovery_mode) +{ + g_recovery_mode = recovery_mode; +} + void lcd_display_logo(int backlight_set, ulong bmp_img, size_t size) { #define mdelay(t) ({unsigned long msec=(t); while (msec--) { udelay(1000);}}) //LiWei add -- 2.7.4 From 1bf2efc4fffd9e6a0cf557a3021766f3a8a7d4d0 Mon Sep 17 00:00:00 2001 From: Seung-Woo Kim Date: Fri, 10 Feb 2017 14:06:40 +0900 Subject: [PATCH 14/16] tizen: add recovery u-boot prompt command This patch adds recovery command to u-boot prompt. Change-Id: Ifeaef04ea27beef5d7e31ac0d85717fe4c89eeb1 Signed-off-by: Seung-Woo Kim --- property/recv_mode.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/property/recv_mode.c b/property/recv_mode.c index ba43b80..47457ae 100644 --- a/property/recv_mode.c +++ b/property/recv_mode.c @@ -135,3 +135,18 @@ void recovery_mode(void) #endif } +#ifdef CONFIG_TIZEN +#ifdef CONFIG_RAMDISK_BOOT +int do_recovery(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + puts("Tizen Recovery mode\n"); + + recovery_mode(); +} + +U_BOOT_CMD(recovery, 1, 1, do_recovery, + "TIZEN Recovery mode", + "" +); +#endif +#endif -- 2.7.4 From cecbd73e488f709ca1d6889147890a59a8291ab2 Mon Sep 17 00:00:00 2001 From: Seung-Woo Kim Date: Thu, 6 Apr 2017 10:06:13 +0900 Subject: [PATCH 15/16] tizen: thordown: fix to check larger file size than partition size If the file is larger than its mapped partition size, then it should be failed to thor command. So, this patch fixes to check requested file size. Change-Id: I87a3c825138b93ebba961227e47a8cf600de602d Signed-off-by: Seung-Woo Kim --- property/thor_mode.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/property/thor_mode.c b/property/thor_mode.c index 4845b16..e277eba 100644 --- a/property/thor_mode.c +++ b/property/thor_mode.c @@ -178,6 +178,12 @@ static long long int process_rqt_download(const struct rqt_box *rqt) ret = rsp->ack; } + if (thor_file_size > part_info.size * part_info.blksz) { + thor_debug("Too large binary\n"); + rsp->ack = -EFBIG; + ret = rsp->ack; + } + break; case RQT_DL_FILE_START: send_rsp(rsp); -- 2.7.4 From fb35badbf11d74b8eee60d85447cab13ad07cb9c Mon Sep 17 00:00:00 2001 From: Gonzha Dmitriy Evgenevich Date: Wed, 31 May 2017 21:33:59 +0300 Subject: [PATCH 16/16] packaging: Turn off ASan build Turn off ASan in case of ASan build for u-boot-tm1 package Change-Id: I1a3714f47eb14da53fac8a14e179d90ffa416b7f Signed-off-by: Gonzha Dmitriy Evgenevich Signed-off-by: Seung-Woo Kim --- packaging/u-boot-tm1.spec | 1 + 1 file changed, 1 insertion(+) diff --git a/packaging/u-boot-tm1.spec b/packaging/u-boot-tm1.spec index 4fa0d9b..a94fb53 100644 --- a/packaging/u-boot-tm1.spec +++ b/packaging/u-boot-tm1.spec @@ -32,6 +32,7 @@ and Microblaze. %setup -q %build +%{?asan:/usr/bin/gcc-unforce-options} cp %{SOURCE1001} . make distclean make tizen_tm1_config -- 2.7.4