bootstage: Update to support early malloc() and SPL
Subsystems (2)
cover bootstage: Update to support early malloc() and SPL
The bootstage feature is useful for timing booting of a board, both for debugging and for production. On ARM devices, detailed timing information can be passed to Linux (where for example it could be logged or reported to a connected server).
Bootstage was written before early malloc(). At present bootstage uses the data section and a large block of memory, which is not ideal. Also it does not support SPL.
This series revamps bootstage. It allows a full timing trace to be collected from SPL through to booting Linux, for example:
Mark Elapsed Stage
0 0 reset
2,809,110 2,809,110 spl
2,824,791 15,681 end_spl
2,879,616 54,825 board_init_f
3,180,834 301,218 board_init_r
3,496,057 315,223 id=64
3,497,957 1,900 id=64
3,497,959 2 main_loopAccumulated time:
723 dm_r
3,763 of_live
8,027 dm_spl
120,731 dm_f
168,207 lcdSimon Glass (15):
bootstage: Provide a default timer function
bootstage: Require timer_get_boot_us() to be defined
bootstage: Change CONFIG_BOOTSTAGE_USER_COUNT to an int
bootstage: Convert to use malloc()
bootstage: Fix up code style and comments
bootstage: Use rec_count as the array index
bootstage: Show records with a zero time
bootstage: Use debug() for stashing messages
bootstage: Support relocating boostage data
bootstage: Init as early as possible
bootstage: Record the time taken to set up driver model
bootstage: Tidy up error return values
bootstage: Adjust to use const * where possible
bootstage: Support SPL
bootstage: Record time taken to set up the live device tree
arch/sandbox/cpu/cpu.c | 11 ++ common/Kconfig | 18 ++- common/Makefile | 3 +- common/board_f.c | 61 ++++++++- common/board_r.c | 16 ++- common/bootstage.c | 257 ++++++++++++++++++++++--------------- common/spl/spl.c | 18 +++ configs/sandbox_defconfig | 2 +- configs/sandbox_flattree_defconfig | 2 +- configs/sandbox_noblk_defconfig | 2 +- configs/sandbox_spl_defconfig | 2 +- include/asm-generic/global_data.h | 4 + include/bootstage.h | 62 +++++++-- lib/time.c | 17 +++ 14 files changed, 349 insertions(+), 126 deletions(-)
Signature · 1 line
2.13.0.303.g4ebf302169-goog
PATCH 1/15 bootstage: Provide a default timer function
If CONFIG_SYS_TIMER_COUNTER is used we can provide a default microsecond timer implementation.
---
lib/time.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
lib/time.c +17 -0
@@ -36,6 +36,23 @@ unsigned long notrace timer_read_counter(void)return readl (CONFIG_SYS_TIMER_COUNTER ); #endif } + +ulong timer_get_boot_us (void ) +{ +ulong count =timer_read_counter (); + +#if CONFIG_SYS_TIMER_RATE ==1000000 +return count; +#elif CONFIG_SYS_TIMER_RATE >1000000 +return lldiv (count,CONFIG_SYS_TIMER_RATE /1000000 ); +#elif defined(CONFIG_SYS_TIMER_RATE ) +return (unsigned long long )count *1000000 /CONFIG_SYS_TIMER_RATE ; +#else +/* Assume the counter is in microseconds */ +return count; +#endif +} +#else extern unsigned long __weak timer_read_counter (void );#endif
Signature · 1 line
2.13.0.303.g4ebf302169-goog
PATCH 1/15 bootstage: Provide a default timer function
Quoted 4 lines · Simon Glass
If
CONFIG_SYS_TIMER_COUNTERis used we can provide a default microsecond timer implementation.Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170605/ba6b1f2c/attachment.sig>
PATCH 2/15 bootstage: Require timer_get_boot_us() to be defined
In reply to Simon GlassAt present we provide a default version of this function for use by bootstage. However it uses the system timer and therefore likely requires driver model. This makes it impossible to time driver-model init.
Drop the function and require boards to provide their own. Add a sandbox version also. There is a default implememtation in lib/time.c for boards which use CONFIG_SYS_TIMER_COUNTER.
---
arch/sandbox/cpu/cpu.c | 11 +++++++++++ common/bootstage.c | 19 +------------------ include/bootstage.h | 3 ++- 3 files changed, 14 insertions(+), 19 deletions(-)
arch/sandbox/cpu/cpu.c +11 -0
@@ -139,3 +139,14 @@ done:return 0 ; } + +ulong timer_get_boot_us (void ) +{ +static uint64_t base_count; +uint64_t count =os_get_nsec (); + +if (!base_count) + base_count = count; + +return (count - base_count) /1000 ; +}
common/bootstage.c +1 -18
@@ -8,7 +8,7 @@/* * This module records the progress of boot and arbitrary commands, and * permits accurate timestamping of each. -* +* * TBD: Pass timings to kernel in the FDT */
@@ -292,23 +292,6 @@ void bootstage_report(void) } } -ulong __timer_get_boot_us (void ) -{ -static ulong base_time; - -/* -* We can't implement this properly. Return 0 on the first call and -* larger values after that. -*/ -if (base_time) -return get_timer (base_time) *1000 ; - base_time =get_timer (0 ); -return 0 ; -} - -ulong timer_get_boot_us (void ) - __attribute__((weak,alias ("__timer_get_boot_us" ))); -/** * Append data to a memory buffer *
include/bootstage.h +2 -1
@@ -2,6 +2,7 @@* This file implements recording of each stage of the boot process. It is * intended to implement timing of each stage, reporting this information * to the user and passing it to the OS for logging / further analysis. +* Note that it requires timer_get_boot_us() to be defined by the board * * Copyright (c) 2011 The Chromium OS Authors. *
@@ -209,7 +210,7 @@ enum bootstage_id {/* * Return the time since boot in microseconds, This is needed for bootstage * and should be defined in CPU- or board-specific code. If undefined then -* millisecond resolution will be used (the standard get_timer()). +* you will get a link error. */ ulong timer_get_boot_us (void );
Signature · 1 line
2.13.0.303.g4ebf302169-goog
PATCH 2/15 bootstage: Require timer_get_boot_us() to be defined
Quoted 9 lines · Simon Glass
At present we provide a default version of this function for use by bootstage. However it uses the system timer and therefore likely requires driver model. This makes it impossible to time driver-model init.
Drop the function and require boards to provide their own. Add a sandbox version also. There is a default implememtation in
lib/time.cfor boards which useCONFIG_SYS_TIMER_COUNTER.Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170605/7e58fea5/attachment.sig>
PATCH 3/15 bootstage: Change CONFIG_BOOTSTAGE_USER_COUNT to an int
In reply to Simon GlassThere is no good read to make this hex, and integer is more natural for this type of setting. Update it.
---
common/Kconfig | 2 +- configs/sandbox_defconfig | 2 +- configs/sandbox_flattree_defconfig | 2 +- configs/sandbox_noblk_defconfig | 2 +- configs/sandbox_spl_defconfig | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-)
common/Kconfig +1 -1
@@ -38,7 +38,7 @@ config BOOTSTAGE_REPORT 30,361,327 445,160 start_kernel config BOOTSTAGE_USER_COUNT - hex "Number of boot ID numbers available for user use" + int "Number of boot ID numbers available for user use" default 20 help This is the number of available user bootstage records.
configs/sandbox_defconfig +1 -1
@@ -7,7 +7,7 @@ CONFIG_FIT_VERBOSE=y CONFIG_SPL_LOAD_FIT=y CONFIG_BOOTSTAGE=y CONFIG_BOOTSTAGE_REPORT=y -CONFIG_BOOTSTAGE_USER_COUNT=0x20 +CONFIG_BOOTSTAGE_USER_COUNT=32 CONFIG_BOOTSTAGE_FDT=y CONFIG_BOOTSTAGE_STASH=y CONFIG_BOOTSTAGE_STASH_ADDR=0x0
configs/sandbox_flattree_defconfig +1 -1
@@ -7,7 +7,7 @@ CONFIG_FIT_VERBOSE=y CONFIG_SPL_LOAD_FIT=y CONFIG_BOOTSTAGE=y CONFIG_BOOTSTAGE_REPORT=y -CONFIG_BOOTSTAGE_USER_COUNT=0x20 +CONFIG_BOOTSTAGE_USER_COUNT=32 CONFIG_BOOTSTAGE_FDT=y CONFIG_BOOTSTAGE_STASH=y CONFIG_BOOTSTAGE_STASH_ADDR=0x0
configs/sandbox_noblk_defconfig +1 -1
@@ -6,7 +6,7 @@ CONFIG_FIT_VERBOSE=y CONFIG_SPL_LOAD_FIT=y CONFIG_BOOTSTAGE=y CONFIG_BOOTSTAGE_REPORT=y -CONFIG_BOOTSTAGE_USER_COUNT=0x20 +CONFIG_BOOTSTAGE_USER_COUNT=32 CONFIG_BOOTSTAGE_FDT=y CONFIG_BOOTSTAGE_STASH=y CONFIG_BOOTSTAGE_STASH_ADDR=0x0
configs/sandbox_spl_defconfig +1 -1
@@ -12,7 +12,7 @@ CONFIG_FIT_VERBOSE=y CONFIG_SPL_LOAD_FIT=y CONFIG_BOOTSTAGE=y CONFIG_BOOTSTAGE_REPORT=y -CONFIG_BOOTSTAGE_USER_COUNT=0x20 +CONFIG_BOOTSTAGE_USER_COUNT=32 CONFIG_BOOTSTAGE_FDT=y CONFIG_BOOTSTAGE_STASH=y CONFIG_BOOTSTAGE_STASH_ADDR=0x0
Signature · 1 line
2.13.0.303.g4ebf302169-goog
PATCH 3/15 bootstage: Change CONFIG_BOOTSTAGE_USER_COUNT to an int
Quoted 4 lines · Simon Glass
There is no good read to make this hex, and integer is more natural for this type of setting. Update it.
Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170605/8ac04281/attachment.sig>
PATCH 4/15 bootstage: Convert to use malloc()
In reply to Simon GlassAt present bootstage uses the data section of the image to store its information. There are a few problems with this:
- It does not work on all boards (e.g. those which run from flash before relocation)
- Allocated strings still point back to the pre-relocation data after relocation
Now that U-Boot has a pre-relocation malloc() we can use this instead, with a pointer to the data in global_data. Update bootstage to do this and set up an init routine to allocate the memory.
Now that we have a real init function, we can drop the fake 'reset' record and add a normal one instead.
Note that part of the problem with allocated strings remains. They are reallocated but this will only work where pre-relocation memory is accessible after relocation.
---
common/board_f.c | 10 ++++- common/bootstage.c | 86 +++++++++++++++++++++++++-------------- include/asm-generic/global_data.h | 3 ++ include/bootstage.h | 13 ++++++ 4 files changed, 79 insertions(+), 33 deletions(-)
common/board_f.c +8 -2
@@ -670,8 +670,14 @@ static int jump_to_copy(void)#endif /* Record the board_init_f() bootstage (after arch_cpu_init()) */ -static int mark_bootstage (void ) +static int initf_bootstage (void ) { +int ret; + + ret =bootstage_init (true); +if (ret) +return ret; +bootstage_mark_name (BOOTSTAGE_ID_START_UBOOT_F ,"board_init_f" );return 0 ;
@@ -732,7 +738,7 @@ static const init_fnc_t init_sequence_f[] = { mach_cpu_init,/* SoC/machine dependent CPU setup */ initf_dm, arch_cpu_init_dm, - mark_bootstage,/* need timer, go after init dm */ + initf_bootstage,/* need timer, go after init dm */ #if defined(CONFIG_BOARD_EARLY_INIT_F) board_early_init_f, #endif
common/bootstage.c +55 -31
221 lines not on this page · raw message
include/asm-generic/global_data.h +3 -0
@@ -110,6 +110,9 @@ typedef struct global_data {ulong video_top;/* Top of video frame buffer area */ ulong video_bottom;/* Bottom of video frame buffer area */ #endif +#ifdef CONFIG_BOOTSTAGE +struct bootstage_data *bootstage;/* Bootstage information */ +#endif } gd_t;#endif
include/bootstage.h +13 -0
@@ -331,6 +331,14 @@ int bootstage_stash(void *base, int size);*/ int bootstage_unstash (void *base,int size); +/** +* bootstage_init() - Prepare bootstage for use +* +* @first: true if this is the first time bootstage is set up. This causes it +* to add a 'reset' record with a time of 0. +*/ +int bootstage_init (bool first); +#else static inline ulong bootstage_add_record (enum bootstage_id id,const char *name,int flags,ulong mark)
@@ -391,6 +399,11 @@ static inline int bootstage_unstash(void *base, int size) {return 0 ;/* Pretend to succeed */ } + +static inline int bootstage_init (bool first) +{ +return 0 ; +}#endif /* CONFIG_BOOTSTAGE */ /* Helper macro for adding a bootstage to a line of code */
Signature · 1 line
2.13.0.303.g4ebf302169-goog
PATCH 4/15 bootstage: Convert to use malloc()
Quoted 12 lines · Simon Glass
At present bootstage uses the data section of the image to store its information. There are a few problems with this:
- It does not work on all boards (e.g. those which run from flash before relocation)
- Allocated strings still point back to the pre-relocation data after relocationNow that U-Boot has a pre-relocation
malloc()we can use this instead, with a pointer to the data inglobal_data. Update bootstage to do this and set up an init routine to allocate the memory.
Quoted 8 lines
Now that we have a real init function, we can drop the fake 'reset' record and add a normal one instead.
Note that part of the problem with allocated strings remains. They are reallocated but this will only work where pre-relocation memory is accessible after relocation.
Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170605/05747c1d/attachment.sig>
PATCH 5/15 bootstage: Fix up code style and comments
In reply to Simon GlassThere are several code style and comment nits. Fix them and also remove the comment about passing bootstage to the kernel being TBD. This is already supported.
---
common/bootstage.c | 6 ++++-- include/bootstage.h | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-)
common/bootstage.c +4 -2
@@ -8,8 +8,6 @@/* * This module records the progress of boot and arbitrary commands, and * permits accurate timestamping of each. -* -* TBD: Pass timings to kernel in the FDT */ #include <common.h>
@@ -84,6 +82,7 @@ ulong bootstage_add_record(enum bootstage_id id, const char *name,/* Tell the board about this progress */ show_boot_progress (flags &BOOTSTAGEF_ERROR ? -id : id); +return mark; }
@@ -105,6 +104,7 @@ ulong bootstage_mark_name(enum bootstage_id id, const char *name)if (id ==BOOTSTAGE_ID_ALLOC ) flags =BOOTSTAGEF_ALLOC ; +return bootstage_add_record (id, name, flags,timer_get_boot_us ()); }
@@ -142,6 +142,7 @@ uint32_t bootstage_start(enum bootstage_id id, const char *name) rec->start_us =timer_get_boot_us (); rec->name = name; +return rec->start_us; }
@@ -153,6 +154,7 @@ uint32_t bootstage_accum(enum bootstage_id id) duration = (uint32_t )timer_get_boot_us () - rec->start_us; rec->time_us += duration; +return duration; }
include/bootstage.h +4 -4
@@ -217,7 +217,7 @@ ulong timer_get_boot_us(void);#if defined(USE_HOSTCC )#define show_boot_progress (val) do {} while (0)#else -/* +/** * Board code can implement show_boot_progress() if needed. * * @param val Progress state (enum bootstage_id), or -id if an error
@@ -235,7 +235,7 @@ void show_boot_progress(int val);* * Call this after relocation has happened and after malloc has been initted. * We need to copy any pointers in bootstage records that were added pre- -* relocation, since memory can be overritten later. +* relocation, since memory can be overwritten later. * @return Always returns 0, to indicate success */ int bootstage_relocate (void );
@@ -251,7 +251,7 @@ int bootstage_relocate(void);ulong bootstage_add_record (enum bootstage_id id,const char *name,int flags,ulong mark); -/* +/** * Mark a time stamp for the current boot stage. */ ulong bootstage_mark (enum bootstage_id id);
@@ -310,7 +310,7 @@ void bootstage_report(void);*/ int bootstage_fdt_add_report (void ); -/* +/** * Stash bootstage data into memory * * @param base Base address of memory buffer
Signature · 1 line
2.13.0.303.g4ebf302169-goog
PATCH 5/15 bootstage: Fix up code style and comments
Quoted 5 lines · Simon Glass
There are several code style and comment nits. Fix them and also remove the comment about passing bootstage to the kernel being TBD. This is already supported.
Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170605/dd29b1ae/attachment.sig>
PATCH 6/15 bootstage: Use rec_count as the array index
In reply to Simon GlassAt present bootstage has a large array with all possible bootstage IDs recorded. It adds times to the array element indexed by the ID. This is inefficient because many IDs are not used during boot. We can save space by only recording those IDs which actually have timestamps.
Update the array to use a record count, which increments with each addition of a new timestamp. This takes longer to record a time, since it may involve an array search. Such a search may be particularly expensive before relocation when the CPU is running slowly or the cache is off. But at that stage there should be very few records.
---
common/Kconfig | 7 +++ common/bootstage.c | 138 ++++++++++++++++++++++++++++++++++------------------- 2 files changed, 96 insertions(+), 49 deletions(-)
common/Kconfig +7 -0
@@ -46,6 +46,13 @@ config BOOTSTAGE_USER_COUNT a new ID will be allocated from this stash. If you exceed the limit, recording will stop. +config BOOTSTAGE_RECORD_COUNT + int "Number of boot stage records to store" + default 30 + help + This is the size of the bootstage record list and is the maximum + number of bootstage records that can be recorded. + config BOOTSTAGE_FDT bool "Store boot timing information in the OS device tree" depends on BOOTSTAGE
common/bootstage.c +89 -49
279 lines not on this page · raw message
Signature · 1 line
2.13.0.303.g4ebf302169-goog
PATCH 6/15 bootstage: Use rec_count as the array index
Quoted 5 lines · Simon Glass
At present bootstage has a large array with all possible bootstage IDs recorded. It adds times to the array element indexed by the ID. This is inefficient because many IDs are not used during boot. We can save space by only recording those IDs which actually have timestamps.
Quoted 7 lines
Update the array to use a record count, which increments with each addition of a new timestamp. This takes longer to record a time, since it may involve an array search. Such a search may be particularly expensive before relocation when the CPU is running slowly or the cache is off. But at that stage there should be very few records.
Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170605/5a516dee/attachment.sig>
PATCH 7/15 bootstage: Show records with a zero time
In reply to Simon GlassWe can now use the record count to determine whether a record is valid or not. Drop the test for a zero time.
---
common/bootstage.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
common/bootstage.c +4 -7
@@ -390,18 +390,15 @@ int bootstage_stash(void *base, int size)/* Write the records, silently stopping when we run out of space */ for (rec = data->record, i =0 ; i < data->rec_count; i++, rec++) { -if (rec->time_us !=0 ) -append_data (&ptr, end, rec,sizeof (*rec)); +append_data (&ptr, end, rec,sizeof (*rec)); }/* Write the name strings */ for (rec = data->record, i =0 ; i < data->rec_count; i++, rec++) { -if (rec->time_us !=0 ) { -const char *name; +const char *name; - name =get_record_name (buf,sizeof (buf), rec); -append_data (&ptr, end, name,strlen (name) +1 ); - } + name =get_record_name (buf,sizeof (buf), rec); +append_data (&ptr, end, name,strlen (name) +1 ); }/* Check for buffer overflow */
Signature · 1 line
2.13.0.303.g4ebf302169-goog
PATCH 7/15 bootstage: Show records with a zero time
Quoted 4 lines · Simon Glass
We can now use the record count to determine whether a record is valid or not. Drop the test for a zero time.
Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170605/22f705fb/attachment.sig>
PATCH 8/15 bootstage: Use debug() for stashing messages
In reply to Simon GlassWe don't normally want to see these messages. Change them to debug-only.
---
common/bootstage.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
common/bootstage.c +2 -2
@@ -409,7 +409,7 @@ int bootstage_stash(void *base, int size)/* Update total data size */ hdr->size = ptr - (char *)base; -printf ("Stashed %d records\n" , hdr->count); +debug ("Stashed %d records\n" , hdr->count);return 0 ; }
@@ -479,7 +479,7 @@ int bootstage_unstash(void *base, int size)/* Mark the records as read */ data->rec_count += hdr->count; -printf ("Unstashed %d records\n" , hdr->count); +debug ("Unstashed %d records\n" , hdr->count);return 0 ; }
Signature · 1 line
2.13.0.303.g4ebf302169-goog
PATCH 8/15 bootstage: Use debug() for stashing messages
Quoted 3 lines · Simon Glass
We don't normally want to see these messages. Change them to debug-only.
Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170605/d266d262/attachment.sig>
PATCH 9/15 bootstage: Support relocating boostage data
In reply to Simon GlassSome boards cannot access pre-relocation data after relocation. Reserve space for this and copy it during preparation for relocation.
---
common/board_f.c | 34 ++++++++++++++++++++++++++++++++++ common/bootstage.c | 5 +++++ include/asm-generic/global_data.h | 1 + include/bootstage.h | 12 ++++++++++++ 4 files changed, 52 insertions(+)
common/board_f.c +34 -0
@@ -488,6 +488,20 @@ static int reserve_fdt(void)return 0 ; } +static int reserve_bootstage (void ) +{ +#ifdef CONFIG_BOOTSTAGE +int size =bootstage_get_size (); + + gd->start_addr_sp -= size; + gd->new_bootstage =map_sysmem (gd->start_addr_sp, size); +debug ("Reserving %#x Bytes for bootstage at: %08lx\n" , size, + gd->start_addr_sp); +#endif + +return 0 ; +} +int arch_reserve_stacks (void ) {return 0 ;
@@ -602,6 +616,24 @@ static int reloc_fdt(void)return 0 ; } +static int reloc_bootstage (void ) +{ +#ifdef CONFIG_BOOTSTAGE +if (gd->flags &GD_FLG_SKIP_RELOC ) +return 0 ; +if (gd->new_bootstage) { +int size =bootstage_get_size (); + +debug ("Copying bootstage from %p to %p, size %x\n" , + gd->bootstage, gd->new_bootstage, size); +memcpy (gd->new_bootstage, gd->bootstage, size); + gd->bootstage = gd->new_bootstage; + } +#endif + +return 0 ; +} +static int setup_reloc (void ) {if (gd->flags &GD_FLG_SKIP_RELOC ) {
@@ -825,6 +857,7 @@ static const init_fnc_t init_sequence_f[] = { setup_machine, reserve_global_data, reserve_fdt, + reserve_bootstage, reserve_arch, reserve_stacks, dram_init_banksize,
@@ -846,6 +879,7 @@ static const init_fnc_t init_sequence_f[] = {#endif INIT_FUNC_WATCHDOG_RESET reloc_fdt, + reloc_bootstage, setup_reloc, #if defined(CONFIG_X86) || defined(CONFIG_ARC) copy_uboot_to_ram,
common/bootstage.c +5 -0
@@ -484,6 +484,11 @@ int bootstage_unstash(void *base, int size)return 0 ; } +int bootstage_get_size (void ) +{ +return sizeof (struct bootstage_data ); +} +int bootstage_init (bool first) {struct bootstage_data *data;
include/asm-generic/global_data.h +1 -0
@@ -112,6 +112,7 @@ typedef struct global_data {#endif #ifdef CONFIG_BOOTSTAGE struct bootstage_data *bootstage;/* Bootstage information */ +struct bootstage_data *new_bootstage;/* Relocated bootstage info */ #endif } gd_t;#endif
include/bootstage.h +12 -0
@@ -332,6 +332,13 @@ int bootstage_stash(void *base, int size);int bootstage_unstash (void *base,int size);/** +* bootstage_get_size() - Get the size of the bootstage data +* +* @return size of boostage data in bytes +*/ +int bootstage_get_size (void ); + +/** * bootstage_init() - Prepare bootstage for use * * @first: true if this is the first time bootstage is set up. This causes it
@@ -400,6 +407,11 @@ static inline int bootstage_unstash(void *base, int size)return 0 ;/* Pretend to succeed */ } +static inline int bootstage_get_size (void ) +{ +return 0 ; +} +static inline int bootstage_init (bool first) {return 0 ;
Signature · 1 line
2.13.0.303.g4ebf302169-goog
PATCH 9/15 bootstage: Support relocating boostage data
Quoted 4 lines · Simon Glass
Some boards cannot access pre-relocation data after relocation. Reserve space for this and copy it during preparation for relocation.
Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170605/86ce019e/attachment.sig>
PATCH 10/15 bootstage: Init as early as possible
In reply to Simon GlassAt present we don't allow use of bootstage before driver model is running. This means we cannot time the init of driver model itself.
Now that bootstage requires its own board-specific timer, we can move its init to earlier in the sequence, both before and after relocation.
---
common/board_f.c | 2 +- common/board_r.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-)
common/board_f.c +1 -1
@@ -762,6 +762,7 @@ static const init_fnc_t init_sequence_f[] = { trace_early_init, #endif initf_malloc, + initf_bootstage,/* uses its own timer, so does not need DM */ initf_console_record, #if defined(CONFIG_HAVE_FSP) arch_fsp_init,
@@ -770,7 +771,6 @@ static const init_fnc_t init_sequence_f[] = { mach_cpu_init,/* SoC/machine dependent CPU setup */ initf_dm, arch_cpu_init_dm, - initf_bootstage,/* need timer, go after init dm */ #if defined(CONFIG_BOARD_EARLY_INIT_F) board_early_init_f, #endif
common/board_r.c +1 -2
@@ -329,7 +329,6 @@ static int initr_dm(void)static int initr_bootstage (void ) { -/* We cannot do this before initr_dm() */ bootstage_mark_name (BOOTSTAGE_ID_START_UBOOT_R ,"board_init_r" );return 0 ;
@@ -728,6 +727,7 @@ static init_fnc_t init_sequence_r[] = {#endif initr_barrier, initr_malloc, + initr_bootstage,/* Needs malloc() but has its own timer */ initr_console_record, #ifdef CONFIG_SYS_NONCACHED_MEMORY initr_noncached,
@@ -739,7 +739,6 @@ static init_fnc_t init_sequence_r[] = {#ifdef CONFIG_DM initr_dm,#endif - initr_bootstage,#if defined(CONFIG_ARM ) || defined(CONFIG_NDS32 ) board_init, /* Setup chipselects */#endif
Signature · 1 line
2.13.0.303.g4ebf302169-goog
PATCH 10/15 bootstage: Init as early as possible
Quoted 7 lines · Simon Glass
At present we don't allow use of bootstage before driver model is running. This means we cannot time the init of driver model itself.
Now that bootstage requires its own board-specific timer, we can move its init to earlier in the sequence, both before and after relocation.
Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170605/221b07af/attachment.sig>
PATCH 11/15 bootstage: Record the time taken to set up driver model
In reply to Simon GlassDriver model is set up ones before relocation and once after. Record the time taken in each case.
---
common/board_f.c | 2 ++ common/board_r.c | 2 ++ include/bootstage.h | 2 ++ 3 files changed, 6 insertions(+)
common/board_f.c +2 -0
@@ -729,7 +729,9 @@ static int initf_dm(void)#if defined(CONFIG_DM ) && defined(CONFIG_SYS_MALLOC_F_LEN )int ret; +bootstage_start (BOOTSTATE_ID_ACCUM_DM_F ,"dm_f" ); ret =dm_init_and_scan (true); +bootstage_accum (BOOTSTATE_ID_ACCUM_DM_F );if (ret)return ret;#endif
common/board_r.c +2 -0
@@ -314,7 +314,9 @@ static int initr_dm(void)#ifdef CONFIG_TIMER gd->timer =NULL ;#endif +bootstage_start (BOOTSTATE_ID_ACCUM_DM_R ,"dm_r" ); ret =dm_init_and_scan (false); +bootstage_accum (BOOTSTATE_ID_ACCUM_DM_R );if (ret)return ret;#ifdef CONFIG_TIMER_EARLY
include/bootstage.h +2 -0
@@ -200,6 +200,8 @@ enum bootstage_id {BOOTSTAGE_ID_ACCUM_SPI ,BOOTSTAGE_ID_ACCUM_DECOMP ,BOOTSTAGE_ID_FPGA_INIT , +BOOTSTATE_ID_ACCUM_DM_F , +BOOTSTATE_ID_ACCUM_DM_R ,/* a few spare for the user, from here */ BOOTSTAGE_ID_USER,
Signature · 1 line
2.13.0.303.g4ebf302169-goog
PATCH 11/15 bootstage: Record the time taken to set up driver model
Quoted 4 lines · Simon Glass
Driver model is set up ones before relocation and once after. Record the time taken in each case.
Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170605/a02e8948/attachment.sig>
PATCH 12/15 bootstage: Tidy up error return values
In reply to Simon GlassWe should return a proper error number instead of just -1. This helps the caller to determine what when wrong. Update a few functions to fix this.
---
common/bootstage.c | 22 +++++++++++----------- include/bootstage.h | 4 +++- 2 files changed, 14 insertions(+), 12 deletions(-)
common/bootstage.c +11 -11
@@ -264,7 +264,7 @@ static int add_bootstages_devicetree(struct fdt_header *blob)*/ bootstage =fdt_add_subnode (blob,0 ,"bootstage" );if (bootstage <0 ) -return -1 ; +return -EINVAL ;/* * Insert the timings to the device tree in the reverse order so
@@ -284,13 +284,13 @@ static int add_bootstages_devicetree(struct fdt_header *blob)/* add properties to the node. */ if (fdt_setprop_string (blob, node,"name" ,get_record_name (buf,sizeof (buf), rec))) -return -1 ; +return -EINVAL ;/* Check if this is a 'mark' or 'accum' record */ if (fdt_setprop_cell (blob, node, rec->start_us ?"accum" :"mark" , rec->time_us)) -return -1 ; +return -EINVAL ; }return 0 ;
@@ -371,7 +371,7 @@ int bootstage_stash(void *base, int size)if (hdr +1 > (struct bootstage_hdr *)end) {debug ("%s: Not enough space for bootstage hdr\n" , __func__); -return -1 ; +return -ENOSPC ; }/* Write an arbitrary version number */
@@ -404,7 +404,7 @@ int bootstage_stash(void *base, int size)/* Check for buffer overflow */ if (ptr > end) {debug ("%s: Not enough space for bootstage stash\n" , __func__); -return -1 ; +return -ENOSPC ; }/* Update total data size */
@@ -428,37 +428,37 @@ int bootstage_unstash(void *base, int size)if (hdr +1 > (struct bootstage_hdr *)end) {debug ("%s: Not enough space for bootstage hdr\n" , __func__); -return -1 ; +return -EPERM ; }if (hdr->magic !=BOOTSTAGE_MAGIC ) {debug ("%s: Invalid bootstage magic\n" , __func__); -return -1 ; +return -ENOENT ; }if (ptr + hdr->size > end) {debug ("%s: Bootstage data runs past buffer end\n" , __func__); -return -1 ; +return -ENOSPC ; }if (hdr->count *sizeof (*rec) > hdr->size) {debug ("%s: Bootstage has %d records needing %lu bytes, but " "only %d bytes is available\n" , __func__, hdr->count, (ulong )hdr->count *sizeof (*rec), hdr->size); -return -1 ; +return -ENOSPC ; }if (hdr->version !=BOOTSTAGE_VERSION ) {debug ("%s: Bootstage data version %#0x unrecognised\n" , __func__, hdr->version); -return -1 ; +return -EINVAL ; }if (data->rec_count + hdr->count >RECORD_COUNT ) {debug ("%s: Bootstage has %d records, we have space for %d\n" "- please increase CONFIG_BOOTSTAGE_USER_COUNT\n" , __func__, hdr->count,RECORD_COUNT - data->rec_count); -return -1 ; +return -ENOSPC ; } ptr +=sizeof (*hdr);
include/bootstage.h +3 -1
@@ -329,7 +329,9 @@ int bootstage_stash(void *base, int size);* * @param base Base address of memory buffer * @param size Size of memory buffer (-1 if unknown) -* @return 0 if unstashed ok, -1 if bootstage info not found, or out of space +* @return 0 if unstashed ok, -ENOENT if bootstage info not found, -ENOSPC if +* there is not space for read the stacked data, or other error if +* something else went wrong */ int bootstage_unstash (void *base,int size);
Signature · 1 line
2.13.0.303.g4ebf302169-goog
PATCH 12/15 bootstage: Tidy up error return values
Quoted 4 lines · Simon Glass
We should return a proper error number instead of just -1. This helps the caller to determine what when wrong. Update a few functions to fix this.
Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170605/d80c0a74/attachment.sig>
PATCH 13/15 bootstage: Adjust to use const * where possible
In reply to Simon GlassThere are a few places that should use const *, such as bootstage_unstash(). Update these to make it clearer when parameters are changed.
---
common/bootstage.c | 12 ++++++------ include/bootstage.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-)
common/bootstage.c +6 -6
@@ -205,7 +205,7 @@ uint32_t bootstage_accum(enum bootstage_id id)* @return pointer to name, either from the record or pointing to buf. */ static const char *get_record_name (char *buf,int len, -struct bootstage_record *rec) +const struct bootstage_record *rec) {if (rec->name)return rec->name;
@@ -361,9 +361,9 @@ static void append_data(char **ptrp, char *end, const void *data, int size)int bootstage_stash (void *base,int size) { -struct bootstage_data *data = gd->bootstage; +const struct bootstage_data *data = gd->bootstage;struct bootstage_hdr *hdr = (struct bootstage_hdr *)base; -struct bootstage_record *rec; +const struct bootstage_record *rec;char buf[20 ];char *ptr = base, *end = ptr + size;uint32_t count;
@@ -414,12 +414,12 @@ int bootstage_stash(void *base, int size)return 0 ; } -int bootstage_unstash (void *base,int size) +int bootstage_unstash (const void *base,int size) { +const struct bootstage_hdr *hdr = (struct bootstage_hdr *)base;struct bootstage_data *data = gd->bootstage; -struct bootstage_hdr *hdr = (struct bootstage_hdr *)base; +const char *ptr = base, *end = ptr + size;struct bootstage_record *rec; -char *ptr = base, *end = ptr + size;uint rec_size;int i;
include/bootstage.h +2 -2
@@ -333,7 +333,7 @@ int bootstage_stash(void *base, int size);* there is not space for read the stacked data, or other error if * something else went wrong */ -int bootstage_unstash (void *base,int size); +int bootstage_unstash (const void *base,int size);/** * bootstage_get_size() - Get the size of the bootstage data
@@ -406,7 +406,7 @@ static inline int bootstage_stash(void *base, int size)return 0 ;/* Pretend to succeed */ } -static inline int bootstage_unstash (void *base,int size) +static inline int bootstage_unstash (const void *base,int size) {return 0 ;/* Pretend to succeed */ }
Signature · 1 line
2.13.0.303.g4ebf302169-goog
PATCH 13/15 bootstage: Adjust to use const * where possible
Quoted 5 lines · Simon Glass
There are a few places that should use const *, such as
bootstage_unstash(). Update these to make it clearer when parameters are changed.Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170605/040cc5ee/attachment.sig>
PATCH 14/15 bootstage: Support SPL
In reply to Simon GlassAt present bootstage only supports U-Boot proper. But SPL can also consume boot time so it is useful to have the record start there.
Add bootstage support to SPL. Also support stashing the timing information when SPL finishes so that it can be picked up and reported by U-Boot proper. This provides a full boot time record, excluding only the time taken by the boot ROM.
---
common/Kconfig | 9 +++++++++ common/Makefile | 3 ++- common/board_f.c | 17 ++++++++++++++++- common/spl/spl.c | 18 ++++++++++++++++++ include/bootstage.h | 15 ++++++++++++--- 5 files changed, 57 insertions(+), 5 deletions(-)
common/Kconfig +9 -0
@@ -18,6 +18,15 @@ config BOOTSTAGE Calls to show_boot_progress() will also result in log entries but these will not have names. +config SPL_BOOTSTAGE + bool "Boot timing and reported in SPL" + depends on BOOTSTAGE + help + Enable recording of boot time in SPL. To make this visible to U-Boot + proper, enable BOOTSTAGE_STASH as well. This will stash the timing + information when SPL finishes and load it when U-Boot proper starts + up. + config BOOTSTAGE_REPORT bool "Display a detailed boot timing report before booting the OS" depends on BOOTSTAGE
common/Makefile +2 -1
@@ -65,7 +65,6 @@ obj-$(CONFIG_USB_STORAGE) += usb_storage.o endif # others -obj-$(CONFIG_BOOTSTAGE) += bootstage.o obj-$(CONFIG_CONSOLE_MUX) += iomux.o obj-$(CONFIG_MTD_NOR_FLASH) += flash.o obj-$(CONFIG_CMD_KGDB) += kgdb.o kgdb_stubs.o
@@ -89,6 +88,8 @@ obj-$(CONFIG_CMDLINE) += cli_readline.o cli_simple.o endif # !CONFIG_SPL_BUILD +obj-$(CONFIG_$(SPL_)BOOTSTAGE) += bootstage.o + ifdef CONFIG_SPL_BUILD obj-$(CONFIG_SPL_DFU_SUPPORT) += dfu.o obj-$(CONFIG_SPL_DFU_SUPPORT) += cli_hush.o
common/board_f.c +16 -1
@@ -704,11 +704,26 @@ static int jump_to_copy(void)/* Record the board_init_f() bootstage (after arch_cpu_init()) */ static int initf_bootstage (void ) { +#if defined(CONFIG_SPL_BOOTSTAGE ) && defined(CONFIG_BOOTSTAGE_STASH ) +bool from_spl = true; +#else +bool from_spl = false; +#endif int ret; - ret =bootstage_init (true); + ret =bootstage_init (!from_spl);if (ret)return ret; +if (from_spl) { +const void *stash =map_sysmem (CONFIG_BOOTSTAGE_STASH_ADDR , +CONFIG_BOOTSTAGE_STASH_SIZE ); + + ret =bootstage_unstash (stash,CONFIG_BOOTSTAGE_STASH_SIZE ); +if (ret && ret != -ENOENT ) { +debug ("Failed to unstash bootstage: err=%d\n" , ret); +return ret; + } + }bootstage_mark_name (BOOTSTAGE_ID_START_UBOOT_F ,"board_init_f" );
common/spl/spl.c +18 -0
@@ -232,6 +232,13 @@ static int spl_common_init(bool setup_malloc) gd->malloc_ptr = 0; }#endif + ret =bootstage_init (true); +if (ret) { +debug ("%s: Failed to set up bootstage: ret=%d\n" , __func__, + ret); +return ret; + } +bootstage_mark_name (BOOTSTAGE_ID_START_SPL ,"spl" );if (CONFIG_IS_ENABLED (OF_CONTROL ) && !CONFIG_IS_ENABLED (OF_PLATDATA )) { ret =fdtdec_setup ();if (ret) {
@@ -240,8 +247,10 @@ static int spl_common_init(bool setup_malloc) } }if (IS_ENABLED (CONFIG_SPL_DM )) { +bootstage_start (BOOTSTATE_ID_ACCUM_DM_SPL ,"dm_spl" );/* With CONFIG_SPL_OF_PLATDATA, bring in all devices */ ret =dm_init_and_scan (!CONFIG_IS_ENABLED (OF_PLATDATA )); +bootstage_accum (BOOTSTATE_ID_ACCUM_DM_SPL );if (ret) {debug ("dm_init_and_scan() returned error %d\n" , ret);return ret;
@@ -421,6 +430,15 @@ void board_init_r(gd_t *dummy1, ulong dummy2) }debug ("loaded - jumping to U-Boot...\n" ); +#ifdef CONFIG_BOOTSTAGE_STASH +int ret; + +bootstage_mark_name (BOOTSTAGE_ID_END_SPL ,"end_spl" ); + ret =bootstage_stash ((void *)CONFIG_BOOTSTAGE_STASH_ADDR , +CONFIG_BOOTSTAGE_STASH_SIZE ); +if (ret) +debug ("Failed to stash bootstage: err=%d\n" , ret); +#endif spl_board_prepare_for_boot ();jump_to_image_no_args (&spl_image); }
include/bootstage.h +12 -3
@@ -177,6 +177,7 @@ enum bootstage_id {*/ BOOTSTAGE_ID_AWAKE ,BOOTSTAGE_ID_START_SPL , +BOOTSTAGE_ID_END_SPL ,BOOTSTAGE_ID_START_UBOOT_F ,BOOTSTAGE_ID_START_UBOOT_R , BOOTSTAGE_ID_USB_START,
@@ -200,6 +201,7 @@ enum bootstage_id {BOOTSTAGE_ID_ACCUM_SPI ,BOOTSTAGE_ID_ACCUM_DECOMP ,BOOTSTAGE_ID_FPGA_INIT , +BOOTSTATE_ID_ACCUM_DM_SPL ,BOOTSTATE_ID_ACCUM_DM_F , BOOTSTATE_ID_ACCUM_DM_R,
@@ -228,8 +230,14 @@ ulong timer_get_boot_us(void);void show_boot_progress (int val);#endif -#if defined(CONFIG_BOOTSTAGE ) && !defined(CONFIG_SPL_BUILD ) && \ - !defined(USE_HOSTCC ) +#if !defined(USE_HOSTCC ) +#if CONFIG_IS_ENABLED (BOOTSTAGE ) +#define ENABLE_BOOTSTAGE +#endif +#endif + +#ifdef ENABLE_BOOTSTAGE +/* This is the full bootstage implementation */ /**
@@ -420,7 +428,8 @@ static inline int bootstage_init(bool first) {return 0 ; } -#endif /* CONFIG_BOOTSTAGE */ + +#endif /* ENABLE_BOOTSTAGE */ /* Helper macro for adding a bootstage to a line of code */ #define BOOTSTAGE_MARKER () \
Signature · 1 line
2.13.0.303.g4ebf302169-goog
PATCH 14/15 bootstage: Support SPL
Quoted 9 lines · Simon Glass
At present bootstage only supports U-Boot proper. But SPL can also consume boot time so it is useful to have the record start there.
Add bootstage support to SPL. Also support stashing the timing information when SPL finishes so that it can be picked up and reported by U-Boot proper. This provides a full boot time record, excluding only the time taken by the boot ROM.
Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170605/b891cf8e/attachment.sig>
PATCH 15/15 bootstage: Record time taken to set up the live device tree
In reply to Simon GlassThis time is interesting as a comparision with the flat device tree time. Add it to the record.
---
common/board_r.c | 11 +++++++++-- include/bootstage.h | 1 + 2 files changed, 10 insertions(+), 2 deletions(-)
common/board_r.c +9 -2
@@ -298,8 +298,15 @@ static int initr_noncached(void)#ifdef CONFIG_OF_LIVE static int initr_of_live (void ) { -return of_live_build (gd->fdt_blob, - (struct device_node **)&gd->of_root); +int ret; + +bootstage_start (BOOTSTAGE_ID_ACCUM_OF_LIVE ,"of_live" ); + ret =of_live_build (gd->fdt_blob, (struct device_node **)&gd->of_root); +bootstage_accum (BOOTSTAGE_ID_ACCUM_OF_LIVE ); +if (ret) +return ret; + +return 0 ; }#endif
include/bootstage.h +1 -0
@@ -200,6 +200,7 @@ enum bootstage_id {BOOTSTAGE_ID_ACCUM_SCSI ,BOOTSTAGE_ID_ACCUM_SPI ,BOOTSTAGE_ID_ACCUM_DECOMP , +BOOTSTAGE_ID_ACCUM_OF_LIVE ,BOOTSTAGE_ID_FPGA_INIT ,BOOTSTATE_ID_ACCUM_DM_SPL , BOOTSTATE_ID_ACCUM_DM_F,
Signature · 1 line
2.13.0.303.g4ebf302169-goog
PATCH 15/15 bootstage: Record time taken to set up the live device tree
Quoted 4 lines · Simon Glass
This time is interesting as a comparision with the flat device tree time. Add it to the record.
Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170605/24c39a6c/attachment.sig>