[U-Boot] [PATCH 1/6] .gitignore: Add .su files

The '-fstack-usage' option to gcc will generate .su files, ignore them.
Signed-off-by: Tom Rini trini@ti.com --- .gitignore | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/.gitignore b/.gitignore index e4e95e2..0f32fd8 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ *.orig *.a *.o +*.su *~ *.swp *.patch

Testing for -fstack-usage requires the creation of an output file, which isnt possible with /dev/null.
Signed-off-by: Tom Rini trini@ti.com --- config.mk | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/config.mk b/config.mk index ddaa477..519bc1b 100644 --- a/config.mk +++ b/config.mk @@ -108,14 +108,14 @@ HOSTCFLAGS += -pedantic # only supported compiler options are used # CC_OPTIONS_CACHE_FILE := $(OBJTREE)/include/generated/cc_options.mk - -$(if $(wildcard $(CC_OPTIONS_CACHE_FILE)),,\ - $(shell mkdir -p $(dir $(CC_OPTIONS_CACHE_FILE)))) +CC_TEST_FILE := $(OBJTREE)/include/generated/cc_test_file.c
-include $(CC_OPTIONS_CACHE_FILE)
-cc-option-sys = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \ - > /dev/null 2>&1; then \ +cc-option-sys = $(shell mkdir -p $(dir $(CC_TEST_FILE)); \ + touch $(CC_TEST_FILE); \ + if $(CC) $(CFLAGS) $(1) -S -o $(CC_TEST_FILE) \ + -xc $(CC_TEST_FILE) > /dev/null 2>&1; then \ echo 'CC_OPTIONS += $(strip $1)' >> $(CC_OPTIONS_CACHE_FILE); \ echo "$(1)"; fi)

Signed-off-by: Tom Rini trini@ti.com --- arch/arm/config.mk | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/arch/arm/config.mk b/arch/arm/config.mk index 45f9dca..caf6adb 100644 --- a/arch/arm/config.mk +++ b/arch/arm/config.mk @@ -53,7 +53,11 @@ PF_CPPFLAGS_ABI := $(call cc-option,\ )\ ) $(call cc-option,-mno-thumb-interwork,)\ ) -PLATFORM_CPPFLAGS += $(PF_CPPFLAGS_ARM) $(PF_CPPFLAGS_ABI) + +# Report stack usage if supported +PF_CPPFLAGS_STACK := $(call cc-option,-fstack-usage,) + +PLATFORM_CPPFLAGS += $(PF_CPPFLAGS_ARM) $(PF_CPPFLAGS_ABI) $(PF_CPPFLAGS_STACK)
# For EABI, make sure to provide raise() ifneq (,$(findstring -mabi=aapcs-linux,$(PLATFORM_CPPFLAGS)))

Dear Tom Rini,
In message 1328741900-18174-3-git-send-email-trini@ti.com you wrote:
Signed-off-by: Tom Rini trini@ti.com
arch/arm/config.mk | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
This should not be ARM specific.
Best regards,
Wolfgang Denk

Signed-off-by: Tom Rini trini@ti.com --- arch/arm/cpu/armv7/omap-common/spl.c | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/arch/arm/cpu/armv7/omap-common/spl.c b/arch/arm/cpu/armv7/omap-common/spl.c index 9c1f7e3..3a2d957 100644 --- a/arch/arm/cpu/armv7/omap-common/spl.c +++ b/arch/arm/cpu/armv7/omap-common/spl.c @@ -92,9 +92,9 @@ void spl_parse_image_header(const struct image_header *header) } }
-static void jump_to_image_no_args(void) +static void __noreturn jump_to_image_no_args(void) { - typedef void (*image_entry_noargs_t)(u32 *)__attribute__ ((noreturn)); + typedef void __noreturn (*image_entry_noargs_t)(u32 *); image_entry_noargs_t image_entry = (image_entry_noargs_t) spl_image.entry_point;
@@ -107,7 +107,6 @@ static void jump_to_image_no_args(void) image_entry((u32 *)boot_params_ptr_addr); }
-void jump_to_image_no_args(void) __attribute__ ((noreturn)); void board_init_r(gd_t *id, ulong dummy) { u32 boot_device;

Signed-off-by: Tom Rini trini@ti.com --- README | 22 ++++++++++++++++++++-- 1 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/README b/README index 9d713e8..5ec663a 100644 --- a/README +++ b/README @@ -2430,11 +2430,29 @@ FIT uImage format: CONFIG_SPL Enable building of SPL globally.
+ CONFIG_SPL_LDSCRIPT + LDSCRIPT for linking the SPL binary. + + CONFIG_SPL_MAX_SIZE + Maximum binary size (text, data and rodata) of the SPL binary. + CONFIG_SPL_TEXT_BASE TEXT_BASE for linking the SPL binary.
- CONFIG_SPL_LDSCRIPT - LDSCRIPT for linking the SPL binary. + CONFIG_SPL_BSS_START_ADDR + Link address for the BSS within the SPL binary. + + CONFIG_SPL_BSS_MAX_SIZE + Maximum binary size of the BSS section of the SPL binary. + + CONFIG_SPL_STACK + Adress of the start of the stack SPL will use + + CONFIG_SYS_SPL_MALLOC_START + Starting address of the malloc pool used in SPL. + + CONFIG_SYS_SPL_MALLOC_SIZE + The size of the malloc pool used in SPL.
CONFIG_SPL_LIBCOMMON_SUPPORT Support for common/libcommon.o in SPL binary

This document describes the SPL process for OMAP3 (and related) boards as well as a partial memory map and how to verify certain aspects outside of running on the target.
Signed-off-by: Tom Rini trini@ti.com --- doc/SPL/README.omap3 | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 71 insertions(+), 0 deletions(-) create mode 100644 doc/SPL/README.omap3
diff --git a/doc/SPL/README.omap3 b/doc/SPL/README.omap3 new file mode 100644 index 0000000..729fef1 --- /dev/null +++ b/doc/SPL/README.omap3 @@ -0,0 +1,71 @@ +Overview of SPL on OMAP3 devices +================================ + +Introduction +------------ + +This document provides an overview of how SPL functions on OMAP3 (and related +such as am35x and am37x) processors. + +Methodology +----------- + +On these platforms the ROM supports trying a sequence of boot devices. Once +one has been used successfully to load SPL this information is stored in memory +and the location stored in a register. We will read this to determine where to +read U-Boot from in turn. + +Memory Map +---------- + +This is an example of a typical setup. See top-level README for documentation +of which CONFIG variables control these values. For a given board and the +amount of DRAM available to it different values may need to be used. +Note that the size of the SPL text rodata and data is enforced with a CONFIG +option and growing over that size results in a link error. The SPL stack +starts at the top of SRAM (which is configurable) and grows downward. The +space between the top of SRAM and the enforced upper bound on the size of the +SPL text, data and rodata is considered the safe stack area. Details on +confirming this behavior are shown below. + +A portion of the system memory map looks as follows: +SRAM: 0x40200000 - 0x4020FFFF +DDR1: 0x80000000 - 0xBFFFFFFF + +Option 1 (SPL only): +0x40200800 - 0x4020BBFF: Area for SPL text, data and rodata +0x4020BC00 - 0x4020FFFC: Area for the SPL stack. +0x80000000 - 0x8007FFFF: Area for the SPL BSS. +0x80100000: CONFIG_SYS_TEXT_BASE of U-Boot +0x80208000 - 0x80307FFF: malloc() pool available to SPL. + +Option 2 (SPL or X-Loader): +0x40200800 - 0x4020BBFF: Area for SPL text, data and rodata +0x4020BC00 - 0x4020FFFC: Area for the SPL stack. +0x80008000: CONFIG_SYS_TEXT_BASE of U-Boot +0x87000000 - 0x8707FFFF: Area for the SPL BSS. +0x87080000 - 0x870FFFFF: malloc() pool available to SPL. + +For the areas that reside within DDR1 they must not be used prior to s_init() +completing. Note that CONFIG_SYS_TEXT_BASE must be clear of the areas that SPL +uses while running. This is why we have two versions of the memory map that +only varry in where the BSS and malloc pool reside. + +Estimating stack usage +---------------------- + +With gcc 4.6 (and later) and the use of GNU cflow it is possible to estimate stack usage at various points in run sequence of SPL. The -fstack-usage option to gcc will produce '.su' files (such as arch/arm/cpu/armv7/syslib.su) that will give stack usage information and cflow can construct program flow. + +Must have gcc 4.6 or later, which supports -fstack-usage + +1) Build normally +2) Perform the following shell to generate a list of C files used in SPL +$ for F in `cd spl; find -name *.su`; do \ + echo $F | sed -e 's/.su$/.c/'; done > used-spl.list +3) Execute cflow: +$ cflow --main=board_init_r `cat used-spl.list` 2>&1 | $PAGER + +cflow will spit out a number of warnings as it does not parse +the config files and pick functions based on #ifdef. Parsing the '.i' +files instead introduces another set of headaches. These warnings are +not usually important to understanding the flow, however.

+only varry in where the BSS and malloc pool reside.
vary
+2) Perform the following shell to generate a list of C files used in SPL
shell command
+cflow will spit out a number of warnings as it does not parse +the config files and pick functions based on #ifdef. Parsing the '.i'
picks

On 02/08/2012 04:08 PM, Peter Meerwald wrote:
+only varry in where the BSS and malloc pool reside.
vary
+2) Perform the following shell to generate a list of C files used in SPL
shell command
+cflow will spit out a number of warnings as it does not parse +the config files and pick functions based on #ifdef. Parsing the '.i'
picks
Thanks

Hey all,
The following series (v2) is an attempt to make it easier for developers and users to use SPL. At the end of the series, we have filled in some missing CONFIG options for SPL, explained how the sequence works on OMAP3 and similar platforms and added an explanation on how to check stack usage with a combination of recent gcc (for -fstack-usage) and GNU cflow.
Changes for v2: - Move -fstack-usage to top-level config.mk (per Wolfgang) - Wording fixes in doc/SPL/README.omap3 (per Peter Meerwald)

Hey all,
The following series (v3) is an attempt to make it easier for developers and users to use SPL. At the end of the series, we have filled in some missing CONFIG options for SPL, explained how the sequence works on OMAP3 and similar platforms and added an explanation on how to check stack usage with a combination of recent gcc (for -fstack-usage) and GNU cflow.
Changes for v3: - Better summary on 5/6, add even more options (Mike F, self) - Drop trailing comma in adding -fstack-usgae check (Mike F) - Still use /dev/null for cc-option input, just generate output (Mike F) - "isnt" -> "isn't" in commit message for cc-option change (Mike F)
Changes for v2: - Move -fstack-usage to top-level config.mk (per Wolfgang) - Wording fixes in doc/SPL/README.omap3 (per Peter Meerwald)

The '-fstack-usage' option to gcc will generate .su files, ignore them.
Acked-by: Mike Frysinger vapier@gentoo.org Signed-off-by: Tom Rini trini@ti.com --- .gitignore | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/.gitignore b/.gitignore index e4e95e2..0f32fd8 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ *.orig *.a *.o +*.su *~ *.swp *.patch

Testing for -fstack-usage requires the creation of an output file, which isn't possible with /dev/null.
Signed-off-by: Tom Rini trini@ti.com
--- Changes for v3: - Change to use outputing a file but compiling /dev/null - "isnt" -> "isn't" (both per Mike Frysinger) --- config.mk | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/config.mk b/config.mk index ddaa477..596ba93 100644 --- a/config.mk +++ b/config.mk @@ -108,13 +108,12 @@ HOSTCFLAGS += -pedantic # only supported compiler options are used # CC_OPTIONS_CACHE_FILE := $(OBJTREE)/include/generated/cc_options.mk - -$(if $(wildcard $(CC_OPTIONS_CACHE_FILE)),,\ - $(shell mkdir -p $(dir $(CC_OPTIONS_CACHE_FILE)))) +CC_TEST_OFILE := $(OBJTREE)/include/generated/cc_test_file.o
-include $(CC_OPTIONS_CACHE_FILE)
-cc-option-sys = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \ +cc-option-sys = $(shell mkdir -p $(dir $(CC_TEST_OFILE)); \ + if $(CC) $(CFLAGS) $(1) -S -xc /dev/null -o $(CC_TEST_OFILE) \ > /dev/null 2>&1; then \ echo 'CC_OPTIONS += $(strip $1)' >> $(CC_OPTIONS_CACHE_FILE); \ echo "$(1)"; fi)

Acked-by: Mike Frysinger vapier@gentoo.org Signed-off-by: Tom Rini trini@ti.com
--- Changes for v2: - Move check from arch/arm/config.mk to config.mk, reword summary
Changes for v3: - Drop trailing comma in cc-option call (per Mike Frysinger) --- config.mk | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/config.mk b/config.mk index 596ba93..fa33e62 100644 --- a/config.mk +++ b/config.mk @@ -232,6 +232,10 @@ CFLAGS_WARN := $(call cc-option,-Wno-format-nonliteral) \ $(call cc-option,-Wno-format-security) CFLAGS += $(CFLAGS_WARN)
+# Report stack usage if supported +CFLAGS_STACK := $(call cc-option,-fstack-usage) +CFLAGS += $(CFLAGS_STACK) + # $(CPPFLAGS) sets -g, which causes gcc to pass a suitable -g<format> # option to the assembler. AFLAGS_DEBUG :=

Acked-by: Mike Frysinger vapier@gentoo.org Signed-off-by: Tom Rini trini@ti.com
--- Changes for v2: - Move check from arch/arm/config.mk to config.mk, reword summary
Changes for v3: - Drop trailing comma in cc-option call (per Mike Frysinger)
Changes for v4: - Add .su files to clean list
add .su to nuke list
Signed-off-by: Tom Rini trini@ti.com --- Makefile | 2 +- config.mk | 4 ++++ 2 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/Makefile b/Makefile index 11aac21..8e66739 100644 --- a/Makefile +++ b/Makefile @@ -749,7 +749,7 @@ clean: @rm -f $(obj)MLO @rm -f $(TIMESTAMP_FILE) $(VERSION_FILE) @find $(OBJTREE) -type f \ - ( -name 'core' -o -name '*.bak' -o -name '*~' \ + ( -name 'core' -o -name '*.bak' -o -name '*~' -o -name '*.su' \ -o -name '*.o' -o -name '*.a' -o -name '*.exe' ) -print \ | xargs rm -f
diff --git a/config.mk b/config.mk index 596ba93..fa33e62 100644 --- a/config.mk +++ b/config.mk @@ -232,6 +232,10 @@ CFLAGS_WARN := $(call cc-option,-Wno-format-nonliteral) \ $(call cc-option,-Wno-format-security) CFLAGS += $(CFLAGS_WARN)
+# Report stack usage if supported +CFLAGS_STACK := $(call cc-option,-fstack-usage) +CFLAGS += $(CFLAGS_STACK) + # $(CPPFLAGS) sets -g, which causes gcc to pass a suitable -g<format> # option to the assembler. AFLAGS_DEBUG :=

Acked-by: Mike Frysinger vapier@gentoo.org Signed-off-by: Tom Rini trini@ti.com --- arch/arm/cpu/armv7/omap-common/spl.c | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/arch/arm/cpu/armv7/omap-common/spl.c b/arch/arm/cpu/armv7/omap-common/spl.c index 9c1f7e3..3a2d957 100644 --- a/arch/arm/cpu/armv7/omap-common/spl.c +++ b/arch/arm/cpu/armv7/omap-common/spl.c @@ -92,9 +92,9 @@ void spl_parse_image_header(const struct image_header *header) } }
-static void jump_to_image_no_args(void) +static void __noreturn jump_to_image_no_args(void) { - typedef void (*image_entry_noargs_t)(u32 *)__attribute__ ((noreturn)); + typedef void __noreturn (*image_entry_noargs_t)(u32 *); image_entry_noargs_t image_entry = (image_entry_noargs_t) spl_image.entry_point;
@@ -107,7 +107,6 @@ static void jump_to_image_no_args(void) image_entry((u32 *)boot_params_ptr_addr); }
-void jump_to_image_no_args(void) __attribute__ ((noreturn)); void board_init_r(gd_t *id, ulong dummy) { u32 boot_device;

Signed-off-by: Tom Rini trini@ti.com
--- Changes for v3: - Better summaru (per Mike Frysinger) - Add more NAND/MMC related options, move CONFIG_SYS_NAND_HW_ECC_OOBFIRST to be with the rest of SPL --- README | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 59 insertions(+), 10 deletions(-)
diff --git a/README b/README index b6c9d0b..72a463f 100644 --- a/README +++ b/README @@ -2436,11 +2436,29 @@ FIT uImage format: CONFIG_SPL Enable building of SPL globally.
+ CONFIG_SPL_LDSCRIPT + LDSCRIPT for linking the SPL binary. + + CONFIG_SPL_MAX_SIZE + Maximum binary size (text, data and rodata) of the SPL binary. + CONFIG_SPL_TEXT_BASE TEXT_BASE for linking the SPL binary.
- CONFIG_SPL_LDSCRIPT - LDSCRIPT for linking the SPL binary. + CONFIG_SPL_BSS_START_ADDR + Link address for the BSS within the SPL binary. + + CONFIG_SPL_BSS_MAX_SIZE + Maximum binary size of the BSS section of the SPL binary. + + CONFIG_SPL_STACK + Adress of the start of the stack SPL will use + + CONFIG_SYS_SPL_MALLOC_START + Starting address of the malloc pool used in SPL. + + CONFIG_SYS_SPL_MALLOC_SIZE + The size of the malloc pool used in SPL.
CONFIG_SPL_LIBCOMMON_SUPPORT Support for common/libcommon.o in SPL binary @@ -2457,6 +2475,45 @@ FIT uImage format: CONFIG_SPL_MMC_SUPPORT Support for drivers/mmc/libmmc.o in SPL binary
+ CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR, + CONFIG_SYS_U_BOOT_MAX_SIZE_SECTORS, + CONFIG_SYS_MMC_SD_FAT_BOOT_PARTITION + Address, size and partition on the MMC to load U-Boot from + when the MMC is being used in raw mode. + + CONFIG_SPL_FAT_SUPPORT + Support for fs/fat/libfat.o in SPL binary + + CONFIG_SPL_FAT_LOAD_PAYLOAD_NAME + Filename to read to load U-Boot when reading from FAT + + CONFIG_SPL_NAND_SIMPLE + Support for drivers/mtd/nand/libnand.o in SPL binary + + CONFIG_SYS_NAND_5_ADDR_CYCLE, CONFIG_SYS_NAND_PAGE_COUNT, + CONFIG_SYS_NAND_PAGE_SIZE, CONFIG_SYS_NAND_OOBSIZE, + CONFIG_SYS_NAND_BLOCK_SIZE, CONFIG_SYS_NAND_BAD_BLOCK_POS, + CONFIG_SYS_NAND_ECCPOS, CONFIG_SYS_NAND_ECCSIZE, + CONFIG_SYS_NAND_ECCBYTES + Defines the size and behavior of the NAND that SPL uses + to read U-Boot with CONFIG_SPL_NAND_SIMPLE + + CONFIG_SYS_NAND_U_BOOT_OFFS + Location in NAND for CONFIG_SPL_NAND_SIMPLE to read U-Boot + from. + + CONFIG_SYS_NAND_U_BOOT_START + Location in memory for CONFIG_SPL_NAND_SIMPLE to load U-Boot + to. + + CONFIG_SYS_NAND_HW_ECC_OOBFIRST + Define this if you need to first read the OOB and then the + data. This is used for example on davinci plattforms. + + CONFIG_SPL_OMAP3_ID_NAND + Support for an OMAP3-specific set of functions to return the + ID and MFR of the first attached NAND chip, if present. + CONFIG_SPL_SERIAL_SUPPORT Support for drivers/serial/libserial.o in SPL binary
@@ -2466,9 +2523,6 @@ FIT uImage format: CONFIG_SPL_SPI_SUPPORT Support for drivers/spi/libspi.o in SPL binary
- CONFIG_SPL_FAT_SUPPORT - Support for fs/fat/libfat.o in SPL binary - CONFIG_SPL_LIBGENERIC_SUPPORT Support for lib/libgeneric.o in SPL binary
@@ -3316,11 +3370,6 @@ Low Level (hardware related) configuration options: that is executed before the actual U-Boot. E.g. when compiling a NAND SPL.
-- CONFIG_SYS_NAND_HW_ECC_OOBFIRST - define this, if you want to read first the oob data - and then the data. This is used for example on - davinci plattforms. - - CONFIG_USE_ARCH_MEMCPY CONFIG_USE_ARCH_MEMSET If these options are used a optimized version of memcpy/memset will

This document describes the SPL process for OMAP3 (and related) boards as well as a partial memory map and how to verify certain aspects outside of running on the target.
Signed-off-by: Tom Rini trini@ti.com
--- Changes for v2: - Wording changes from Peter Meerwald --- doc/SPL/README.omap3 | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 72 insertions(+), 0 deletions(-) create mode 100644 doc/SPL/README.omap3
diff --git a/doc/SPL/README.omap3 b/doc/SPL/README.omap3 new file mode 100644 index 0000000..1f30994 --- /dev/null +++ b/doc/SPL/README.omap3 @@ -0,0 +1,72 @@ +Overview of SPL on OMAP3 devices +================================ + +Introduction +------------ + +This document provides an overview of how SPL functions on OMAP3 (and related +such as am35x and am37x) processors. + +Methodology +----------- + +On these platforms the ROM supports trying a sequence of boot devices. Once +one has been used successfully to load SPL this information is stored in memory +and the location stored in a register. We will read this to determine where to +read U-Boot from in turn. + +Memory Map +---------- + +This is an example of a typical setup. See top-level README for documentation +of which CONFIG variables control these values. For a given board and the +amount of DRAM available to it different values may need to be used. +Note that the size of the SPL text rodata and data is enforced with a CONFIG +option and growing over that size results in a link error. The SPL stack +starts at the top of SRAM (which is configurable) and grows downward. The +space between the top of SRAM and the enforced upper bound on the size of the +SPL text, data and rodata is considered the safe stack area. Details on +confirming this behavior are shown below. + +A portion of the system memory map looks as follows: +SRAM: 0x40200000 - 0x4020FFFF +DDR1: 0x80000000 - 0xBFFFFFFF + +Option 1 (SPL only): +0x40200800 - 0x4020BBFF: Area for SPL text, data and rodata +0x4020BC00 - 0x4020FFFC: Area for the SPL stack. +0x80000000 - 0x8007FFFF: Area for the SPL BSS. +0x80100000: CONFIG_SYS_TEXT_BASE of U-Boot +0x80208000 - 0x80307FFF: malloc() pool available to SPL. + +Option 2 (SPL or X-Loader): +0x40200800 - 0x4020BBFF: Area for SPL text, data and rodata +0x4020BC00 - 0x4020FFFC: Area for the SPL stack. +0x80008000: CONFIG_SYS_TEXT_BASE of U-Boot +0x87000000 - 0x8707FFFF: Area for the SPL BSS. +0x87080000 - 0x870FFFFF: malloc() pool available to SPL. + +For the areas that reside within DDR1 they must not be used prior to s_init() +completing. Note that CONFIG_SYS_TEXT_BASE must be clear of the areas that SPL +uses while running. This is why we have two versions of the memory map that +only vary in where the BSS and malloc pool reside. + +Estimating stack usage +---------------------- + +With gcc 4.6 (and later) and the use of GNU cflow it is possible to estimate stack usage at various points in run sequence of SPL. The -fstack-usage option to gcc will produce '.su' files (such as arch/arm/cpu/armv7/syslib.su) that will give stack usage information and cflow can construct program flow. + +Must have gcc 4.6 or later, which supports -fstack-usage + +1) Build normally +2) Perform the following shell command to generate a list of C files used in +SPL: +$ for F in `cd spl; find -name *.su`; do \ + echo $F | sed -e 's/.su$/.c/'; done > used-spl.list +3) Execute cflow: +$ cflow --main=board_init_r `cat used-spl.list` 2>&1 | $PAGER + +cflow will spit out a number of warnings as it does not parse +the config files and picks functions based on #ifdef. Parsing the '.i' +files instead introduces another set of headaches. These warnings are +not usually important to understanding the flow, however.

On Tuesday 14 February 2012 12:29:41 Tom Rini wrote:
+Estimating stack usage +----------------------
isn't this usable for any target and not just omap3 ?
+With gcc 4.6 (and later) and the use of GNU cflow it is possible to estimate stack usage at various points in run sequence of SPL. The -fstack-usage option to gcc will produce '.su' files (such as arch/arm/cpu/armv7/syslib.su) that will give stack usage information and cflow can construct program flow. + +Must have gcc 4.6 or later, which supports -fstack-usage
tools/checkpatch.pl is also pretty useful and doesn't require any compile version
+$ for F in `cd spl; find -name *.su`; do \
- echo $F | sed -e 's/.su$/.c/'; done > used-spl.list
find spl -name '*.su' | sed -e 's:^spl/::' -e 's:[.]su$:.c:' > used-spl.list -mike

On 02/14/2012 11:43 AM, Mike Frysinger wrote:
On Tuesday 14 February 2012 12:29:41 Tom Rini wrote:
+Estimating stack usage +----------------------
isn't this usable for any target and not just omap3 ?
To a degree, yes. If you try this on full u-boot instead it highlights some of the funny build things we do (there's still a handful of always-compiled-often-empty files like tqm8xx_pcmcia.c) and the lack of dealing with #ifdef's makes life real hard.
+With gcc 4.6 (and later) and the use of GNU cflow it is possible to estimate stack usage at various points in run sequence of SPL. The -fstack-usage option to gcc will produce '.su' files (such as arch/arm/cpu/armv7/syslib.su) that will give stack usage information and cflow can construct program flow. + +Must have gcc 4.6 or later, which supports -fstack-usage
tools/checkpatch.pl is also pretty useful and doesn't require any compile version
checkstack.pl I assume you mean (which I posted the other week). I believe it only reports 'large' usages whereas -fstack-usage reports all.
I'm not opposed to that also being merged of course, but it's just not the same :)
+$ for F in `cd spl; find -name *.su`; do \
- echo $F | sed -e 's/.su$/.c/'; done> used-spl.list
find spl -name '*.su' | sed -e 's:^spl/::' -e 's:[.]su$:.c:'> used-spl.list -mike
Thanks.

This document describes the SPL process for OMAP3 (and related) boards as well as a partial memory map and how to verify certain aspects outside of running on the target.
Signed-off-by: Tom Rini trini@ti.com
--- Changes for v4: - Rework shell line, from Mike Frysinger
Changes for v2: - Wording changes from Peter Meerwald --- doc/SPL/README.omap3 | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 74 insertions(+), 0 deletions(-) create mode 100644 doc/SPL/README.omap3
diff --git a/doc/SPL/README.omap3 b/doc/SPL/README.omap3 new file mode 100644 index 0000000..cc5d5c0 --- /dev/null +++ b/doc/SPL/README.omap3 @@ -0,0 +1,74 @@ +Overview of SPL on OMAP3 devices +================================ + +Introduction +------------ + +This document provides an overview of how SPL functions on OMAP3 (and related +such as am35x and am37x) processors. + +Methodology +----------- + +On these platforms the ROM supports trying a sequence of boot devices. Once +one has been used successfully to load SPL this information is stored in memory +and the location stored in a register. We will read this to determine where to +read U-Boot from in turn. + +Memory Map +---------- + +This is an example of a typical setup. See top-level README for documentation +of which CONFIG variables control these values. For a given board and the +amount of DRAM available to it different values may need to be used. +Note that the size of the SPL text rodata and data is enforced with a CONFIG +option and growing over that size results in a link error. The SPL stack +starts at the top of SRAM (which is configurable) and grows downward. The +space between the top of SRAM and the enforced upper bound on the size of the +SPL text, data and rodata is considered the safe stack area. Details on +confirming this behavior are shown below. + +A portion of the system memory map looks as follows: +SRAM: 0x40200000 - 0x4020FFFF +DDR1: 0x80000000 - 0xBFFFFFFF + +Option 1 (SPL only): +0x40200800 - 0x4020BBFF: Area for SPL text, data and rodata +0x4020BC00 - 0x4020FFFC: Area for the SPL stack. +0x80000000 - 0x8007FFFF: Area for the SPL BSS. +0x80100000: CONFIG_SYS_TEXT_BASE of U-Boot +0x80208000 - 0x80307FFF: malloc() pool available to SPL. + +Option 2 (SPL or X-Loader): +0x40200800 - 0x4020BBFF: Area for SPL text, data and rodata +0x4020BC00 - 0x4020FFFC: Area for the SPL stack. +0x80008000: CONFIG_SYS_TEXT_BASE of U-Boot +0x87000000 - 0x8707FFFF: Area for the SPL BSS. +0x87080000 - 0x870FFFFF: malloc() pool available to SPL. + +For the areas that reside within DDR1 they must not be used prior to s_init() +completing. Note that CONFIG_SYS_TEXT_BASE must be clear of the areas that SPL +uses while running. This is why we have two versions of the memory map that +only vary in where the BSS and malloc pool reside. + +Estimating stack usage +---------------------- + +With gcc 4.6 (and later) and the use of GNU cflow it is possible to estimate +stack usage at various points in run sequence of SPL. The -fstack-usage option +to gcc will produce '.su' files (such as arch/arm/cpu/armv7/syslib.su) that +will give stack usage information and cflow can construct program flow. + +Must have gcc 4.6 or later, which supports -fstack-usage + +1) Build normally +2) Perform the following shell command to generate a list of C files used in +SPL: +$ find spl -name '*.su' | sed -e 's:^spl/::' -e 's:[.]su$:.c:' > used-spl.list +3) Execute cflow: +$ cflow --main=board_init_r `cat used-spl.list` 2>&1 | $PAGER + +cflow will spit out a number of warnings as it does not parse +the config files and picks functions based on #ifdef. Parsing the '.i' +files instead introduces another set of headaches. These warnings are +not usually important to understanding the flow, however.

The '-fstack-usage' option to gcc will generate .su files, ignore them.
Acked-by: Mike Frysinger vapier@gentoo.org Signed-off-by: Tom Rini trini@ti.com --- .gitignore | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/.gitignore b/.gitignore index e4e95e2..0f32fd8 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ *.orig *.a *.o +*.su *~ *.swp *.patch

Testing for -fstack-usage requires the creation of an output file, which isnt possible with /dev/null.
Signed-off-by: Tom Rini trini@ti.com --- config.mk | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/config.mk b/config.mk index ddaa477..519bc1b 100644 --- a/config.mk +++ b/config.mk @@ -108,14 +108,14 @@ HOSTCFLAGS += -pedantic # only supported compiler options are used # CC_OPTIONS_CACHE_FILE := $(OBJTREE)/include/generated/cc_options.mk - -$(if $(wildcard $(CC_OPTIONS_CACHE_FILE)),,\ - $(shell mkdir -p $(dir $(CC_OPTIONS_CACHE_FILE)))) +CC_TEST_FILE := $(OBJTREE)/include/generated/cc_test_file.c
-include $(CC_OPTIONS_CACHE_FILE)
-cc-option-sys = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \ - > /dev/null 2>&1; then \ +cc-option-sys = $(shell mkdir -p $(dir $(CC_TEST_FILE)); \ + touch $(CC_TEST_FILE); \ + if $(CC) $(CFLAGS) $(1) -S -o $(CC_TEST_FILE) \ + -xc $(CC_TEST_FILE) > /dev/null 2>&1; then \ echo 'CC_OPTIONS += $(strip $1)' >> $(CC_OPTIONS_CACHE_FILE); \ echo "$(1)"; fi)

On Monday 13 February 2012 18:02:02 Tom Rini wrote:
isnt possible with /dev/null.
isn't
--- a/config.mk +++ b/config.mk
-cc-option-sys = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
> /dev/null 2>&1; then \
+cc-option-sys = $(shell mkdir -p $(dir $(CC_TEST_FILE)); \
touch $(CC_TEST_FILE); \
if $(CC) $(CFLAGS) $(1) -S -o $(CC_TEST_FILE) \
-xc $(CC_TEST_FILE) > /dev/null 2>&1; then \
why do you need to touch the file first ? why do you source this test file instead of continuing to source /dev/null ? don't you run into problems if you use cc-option-sys more than once and a previous run wrote something to that file ? then cc-option-sys could fail on later runs ...
seems like you should drop the `touch` and keep the -xc /dev/null and only change the -o to $(CC_TEST_FILE) ... -mike

On Mon, Feb 13, 2012 at 10:43 PM, Mike Frysinger vapier@gentoo.org wrote:
On Monday 13 February 2012 18:02:02 Tom Rini wrote:
isnt possible with /dev/null.
isn't
--- a/config.mk +++ b/config.mk
-cc-option-sys = $(shell if $(CC) $(CFLAGS) $(1) -S -o /dev/null -xc /dev/null \
- > /dev/null 2>&1; then \
+cc-option-sys = $(shell mkdir -p $(dir $(CC_TEST_FILE)); \
- touch $(CC_TEST_FILE); \
- if $(CC) $(CFLAGS) $(1) -S -o $(CC_TEST_FILE) \
- -xc $(CC_TEST_FILE) > /dev/null 2>&1; then \
why do you need to touch the file first ? why do you source this test file instead of continuing to source /dev/null ? don't you run into problems if you use cc-option-sys more than once and a previous run wrote something to that file ? then cc-option-sys could fail on later runs ...
seems like you should drop the `touch` and keep the -xc /dev/null and only change the -o to $(CC_TEST_FILE) ...
I've also changed the variable to CC_TEST_OFILE and that works, thanks.

Signed-off-by: Tom Rini trini@ti.com
--- Changes for v2: - Move check from arch/arm/config.mk to config.mk, reword summary
Signed-off-by: Tom Rini trini@ti.com --- config.mk | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/config.mk b/config.mk index 519bc1b..91c9e42 100644 --- a/config.mk +++ b/config.mk @@ -233,6 +233,10 @@ CFLAGS_WARN := $(call cc-option,-Wno-format-nonliteral) \ $(call cc-option,-Wno-format-security) CFLAGS += $(CFLAGS_WARN)
+# Report stack usage if supported +CFLAGS_STACK := $(call cc-option,-fstack-usage,) +CFLAGS += $(CFLAGS_STACK) + # $(CPPFLAGS) sets -g, which causes gcc to pass a suitable -g<format> # option to the assembler. AFLAGS_DEBUG :=

On Monday 13 February 2012 18:02:03 Tom Rini wrote:
--- a/config.mk +++ b/config.mk
+# Report stack usage if supported +CFLAGS_STACK := $(call cc-option,-fstack-usage,)
not that it really matters, but you don't need the 2nd comma
Acked-by: Mike Frysinger vapier@gentoo.org -mike

Signed-off-by: Tom Rini trini@ti.com --- arch/arm/cpu/armv7/omap-common/spl.c | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/arch/arm/cpu/armv7/omap-common/spl.c b/arch/arm/cpu/armv7/omap-common/spl.c index 9c1f7e3..3a2d957 100644 --- a/arch/arm/cpu/armv7/omap-common/spl.c +++ b/arch/arm/cpu/armv7/omap-common/spl.c @@ -92,9 +92,9 @@ void spl_parse_image_header(const struct image_header *header) } }
-static void jump_to_image_no_args(void) +static void __noreturn jump_to_image_no_args(void) { - typedef void (*image_entry_noargs_t)(u32 *)__attribute__ ((noreturn)); + typedef void __noreturn (*image_entry_noargs_t)(u32 *); image_entry_noargs_t image_entry = (image_entry_noargs_t) spl_image.entry_point;
@@ -107,7 +107,6 @@ static void jump_to_image_no_args(void) image_entry((u32 *)boot_params_ptr_addr); }
-void jump_to_image_no_args(void) __attribute__ ((noreturn)); void board_init_r(gd_t *id, ulong dummy) { u32 boot_device;

Acked-by: Mike Frysinger vapier@gentoo.org -mike

Signed-off-by: Tom Rini trini@ti.com --- README | 22 ++++++++++++++++++++-- 1 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/README b/README index b6c9d0b..2737966 100644 --- a/README +++ b/README @@ -2436,11 +2436,29 @@ FIT uImage format: CONFIG_SPL Enable building of SPL globally.
+ CONFIG_SPL_LDSCRIPT + LDSCRIPT for linking the SPL binary. + + CONFIG_SPL_MAX_SIZE + Maximum binary size (text, data and rodata) of the SPL binary. + CONFIG_SPL_TEXT_BASE TEXT_BASE for linking the SPL binary.
- CONFIG_SPL_LDSCRIPT - LDSCRIPT for linking the SPL binary. + CONFIG_SPL_BSS_START_ADDR + Link address for the BSS within the SPL binary. + + CONFIG_SPL_BSS_MAX_SIZE + Maximum binary size of the BSS section of the SPL binary. + + CONFIG_SPL_STACK + Adress of the start of the stack SPL will use + + CONFIG_SYS_SPL_MALLOC_START + Starting address of the malloc pool used in SPL. + + CONFIG_SYS_SPL_MALLOC_SIZE + The size of the malloc pool used in SPL.
CONFIG_SPL_LIBCOMMON_SUPPORT Support for common/libcommon.o in SPL binary

pedantically, might be better summary: README: document more SPL config options -mike

This document describes the SPL process for OMAP3 (and related) boards as well as a partial memory map and how to verify certain aspects outside of running on the target.
Signed-off-by: Tom Rini trini@ti.com
--- Changes for v2: - Wording changes from Peter Meerwald --- doc/SPL/README.omap3 | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 72 insertions(+), 0 deletions(-) create mode 100644 doc/SPL/README.omap3
diff --git a/doc/SPL/README.omap3 b/doc/SPL/README.omap3 new file mode 100644 index 0000000..1f30994 --- /dev/null +++ b/doc/SPL/README.omap3 @@ -0,0 +1,72 @@ +Overview of SPL on OMAP3 devices +================================ + +Introduction +------------ + +This document provides an overview of how SPL functions on OMAP3 (and related +such as am35x and am37x) processors. + +Methodology +----------- + +On these platforms the ROM supports trying a sequence of boot devices. Once +one has been used successfully to load SPL this information is stored in memory +and the location stored in a register. We will read this to determine where to +read U-Boot from in turn. + +Memory Map +---------- + +This is an example of a typical setup. See top-level README for documentation +of which CONFIG variables control these values. For a given board and the +amount of DRAM available to it different values may need to be used. +Note that the size of the SPL text rodata and data is enforced with a CONFIG +option and growing over that size results in a link error. The SPL stack +starts at the top of SRAM (which is configurable) and grows downward. The +space between the top of SRAM and the enforced upper bound on the size of the +SPL text, data and rodata is considered the safe stack area. Details on +confirming this behavior are shown below. + +A portion of the system memory map looks as follows: +SRAM: 0x40200000 - 0x4020FFFF +DDR1: 0x80000000 - 0xBFFFFFFF + +Option 1 (SPL only): +0x40200800 - 0x4020BBFF: Area for SPL text, data and rodata +0x4020BC00 - 0x4020FFFC: Area for the SPL stack. +0x80000000 - 0x8007FFFF: Area for the SPL BSS. +0x80100000: CONFIG_SYS_TEXT_BASE of U-Boot +0x80208000 - 0x80307FFF: malloc() pool available to SPL. + +Option 2 (SPL or X-Loader): +0x40200800 - 0x4020BBFF: Area for SPL text, data and rodata +0x4020BC00 - 0x4020FFFC: Area for the SPL stack. +0x80008000: CONFIG_SYS_TEXT_BASE of U-Boot +0x87000000 - 0x8707FFFF: Area for the SPL BSS. +0x87080000 - 0x870FFFFF: malloc() pool available to SPL. + +For the areas that reside within DDR1 they must not be used prior to s_init() +completing. Note that CONFIG_SYS_TEXT_BASE must be clear of the areas that SPL +uses while running. This is why we have two versions of the memory map that +only vary in where the BSS and malloc pool reside. + +Estimating stack usage +---------------------- + +With gcc 4.6 (and later) and the use of GNU cflow it is possible to estimate stack usage at various points in run sequence of SPL. The -fstack-usage option to gcc will produce '.su' files (such as arch/arm/cpu/armv7/syslib.su) that will give stack usage information and cflow can construct program flow. + +Must have gcc 4.6 or later, which supports -fstack-usage + +1) Build normally +2) Perform the following shell command to generate a list of C files used in +SPL: +$ for F in `cd spl; find -name *.su`; do \ + echo $F | sed -e 's/.su$/.c/'; done > used-spl.list +3) Execute cflow: +$ cflow --main=board_init_r `cat used-spl.list` 2>&1 | $PAGER + +cflow will spit out a number of warnings as it does not parse +the config files and picks functions based on #ifdef. Parsing the '.i' +files instead introduces another set of headaches. These warnings are +not usually important to understanding the flow, however.
participants (4)
-
Mike Frysinger
-
Peter Meerwald
-
Tom Rini
-
Wolfgang Denk