Commit 23ac79ff8011c290cc1755b8ab510df80e614db6

Authored by Christophe Leroy
Committed by Tom Rini
1 parent b3ede33170

common: env_embedded: allow fine placement of environment object

Commit 7653942b10e9e ("common/env_embedded.c: drop support for
CONFIG_SYS_USE_PPCENV") dropped the .ppcenv section which was
used in linking scripts to allow fine placement of embedded
environment sections.

This implies that GCC randomly places objects from env/embedded.o
and environment is not guaranteed to be located at the correct address:

04003df8 g     F .text  00000038 mii_init
04004000 g     O .text  00000004 env_size
04004004 g     O .text  00002000 environment
04006004 g     F .text  00000040 .hidden __lshrdi3

This patch restores this capability by allocating each object marked
with __UBOOT_ENV_SECTION__ into a different section. Hence
'environment' will be alone in .text.environment, allowing a
fine placement in u-boot.lds with:

		. = DEFINED(env_offset) ? env_offset : .;
		env/embedded.o			(.text.environment)

Fixes: 7653942b10e9e ("common/env_embedded.c: drop support for CONFIG_SYS_USE_PPCENV")
Cc: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>

Showing 2 changed files with 5 additions and 5 deletions Side-by-side Diff

... ... @@ -35,11 +35,11 @@
35 35 * a seperate section.
36 36 */
37 37 #if defined(USE_HOSTCC) /* Native for 'tools/envcrc' */
38   -# define __UBOOT_ENV_SECTION__ /*XXX DO_NOT_DEL_THIS_COMMENT*/
  38 +# define __UBOOT_ENV_SECTION__(name) /*XXX DO_NOT_DEL_THIS_COMMENT*/
39 39  
40 40 #else /* Environment is embedded in U-Boot's .text section */
41 41 /* XXX - This only works with GNU C */
42   -# define __UBOOT_ENV_SECTION__ __attribute__ ((section(".text")))
  42 +# define __UBOOT_ENV_SECTION__(name) __attribute__ ((section(".text."#name)))
43 43 #endif
44 44  
45 45 /*
... ... @@ -70,7 +70,7 @@
70 70 #include <env_default.h>
71 71  
72 72 #ifdef CONFIG_ENV_ADDR_REDUND
73   -env_t redundand_environment __UBOOT_ENV_SECTION__ = {
  73 +env_t redundand_environment __UBOOT_ENV_SECTION__(redundand_environment) = {
74 74 0, /* CRC Sum: invalid */
75 75 0, /* Flags: invalid */
76 76 {
... ... @@ -87,7 +87,7 @@
87 87 * .data/.sdata section.
88 88 *
89 89 */
90   -unsigned long env_size __UBOOT_ENV_SECTION__ = sizeof(env_t);
  90 +unsigned long env_size __UBOOT_ENV_SECTION__(env_size) = sizeof(env_t);
91 91  
92 92 /*
93 93 * Add in absolutes.
include/env_default.h
... ... @@ -11,7 +11,7 @@
11 11 #include <env_callback.h>
12 12  
13 13 #ifdef DEFAULT_ENV_INSTANCE_EMBEDDED
14   -env_t environment __UBOOT_ENV_SECTION__ = {
  14 +env_t environment __UBOOT_ENV_SECTION__(environment) = {
15 15 ENV_CRC, /* CRC Sum */
16 16 #ifdef CONFIG_SYS_REDUNDAND_ENVIRONMENT
17 17 1, /* Flags: valid */