History log of /u-boot/common/bootstage.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 0d4d9f94 07-Nov-2023 Simon Glass <sjg@chromium.org>

bootstage: Correct exhasuted typo

Correct this typo in the warning message shown when no more bootstage
records can be added.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 17ba5010 26-Sep-2023 Simon Glass <sjg@chromium.org>

spl: Remove #ifdefs with BOOTSTAGE

This feature has some helpers in its header file so that its functions
resolve to nothing when the feature is disabled. Add a few more and use
these to simplify the code.

With this there are no more #ifdefs in board_init_r()

Signed-off-by: Simon Glass <sjg@chromium.org>

# 55bc2276 12-Aug-2022 Michal Simek <michal.simek@amd.com>

bootstage: Show func name for bootstage_mark/error

bootstage_mark() and bootstate_error() are not recording any name and in
report it is showing as id=<value>. That's not useful and it is better to
show function name which calls it.
That's why use macros with passing __func__ as recorded name for bootstage.

Origin report looks like this:
ZynqMP> bootstage report
Timer summary in microseconds (10 records):
Mark Elapsed Stage
0 0 reset
2,482,383 2,482,383 board_init_f
4,278,821 1,796,438 board_init_r
4,825,331 546,510 id=64
4,858,409 33,078 id=65
4,862,382 3,973 main_loop
4,921,713 59,331 usb_start
9,345,345 4,423,632 id=175

When this patch is applied.
ZynqMP> bootstage report
Timer summary in microseconds (31 records):
Mark Elapsed Stage
0 0 reset
2,465,624 2,465,624 board_init_f
4,278,628 1,813,004 board_init_r
4,825,139 546,511 eth_common_init
4,858,228 33,089 eth_initialize
4,862,201 3,973 main_loop
4,921,530 59,329 usb_start
8,885,334 3,963,804 cli_loop

Signed-off-by: Michal Simek <michal.simek@amd.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# eb26d88d 14-Mar-2021 Simon Glass <sjg@chromium.org>

bootstage: Warning if space is exhausted

At present bootstage silently ignores new records if it runs out of
space. It is sometimes obvious by looking at the report, but the IDs are
not contiguous, so it is easy to miss.

Aad a message so that action can be taken.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 939b04e9 03-Feb-2021 Simon Glass <sjg@chromium.org>

bootstage: Fix dependency for BOOTSTAGE_RECORD_COUNT

At present these three Kconfigs exist even when bootstage is not enabled.
This is not necessary since bootstage.c is only built if BOOTSTAGE is
enabled.

Make them conditional. Also fix up the overflow message to mention TPL.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 401d1c4f 30-Oct-2020 Simon Glass <sjg@chromium.org>

common: Drop asm/global_data.h from common header

Move this out of the common header and include it only where needed. In
a number of cases this requires adding "struct udevice;" to avoid adding
another large header or in other cases replacing / adding missing header
files that had been pulled in, very indirectly. Finally, we have a few
cases where we did not need to include <asm/global_data.h> at all, so
remove that include.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Tom Rini <trini@konsulko.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 52f24238 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop bootstage.h from common header

Move this fairly uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# db41d65a 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move hang() to the same header as panic()

At present panic() is in the vsprintf.h header file. That does not seem
like an obvious choice for hang(), even though it relates to panic(). So
let's put hang() in its own header.

Signed-off-by: Simon Glass <sjg@chromium.org>
[trini: Migrate a few more files]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 8bef79bf 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move sorting functions to their own header file

These don't need to be in common.h so move them out into a new header.
Also add some missing comments.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# ac9cd480 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Correct relocation algorithm

At present bootstage relocation assumes that it is possible to point back
to memory available before relocation, so it does not relocate the
strings. However this is not the case on some platforms, such as x86 which
uses the cache as RAM and loses access to this when the cache is enabled.

Move the relocation step to before U-Boot relocates, expand the allocated
region to include space for the strings and relocate the strings at the
same time as the bootstage records.

This ensures that bootstage data can remain accessible from TPL through
SPL to U-Boot before/after relocation.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 65b2d96f 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Avoid conflicts between stash/unstash

At present there is a single shared address for bootstage data in both
TPL and SPL. If SPL unstashs TPL bootstage info and then stashes it again
to pass it to U-Boot, the new stash overwrites the strings of the old
stash.

Fix this by duplicating the strings into the malloc() region. This should
be a small code. Fix the header-file order at the same time.

This problem doesn't happen at the next stage (SPL->U-Boot) since U-Boot
relocates the boostage data.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ed54bdaf 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Fix counting of entries in stash

The current code searches for empty records but these not existing with
bootstage now. This used to be needed when bootstage records were stored
in a spare array.

Drop the unnecessary code and fix a code-style nit at the same time.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 53a4f253 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Store the next ID in the stash

When stashing bootstage info, store the next ID so that it can be used
when the stash is restored. This avoids the ID starting at zero and
potentially overwriting existing entries.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 17357725 08-Apr-2019 Simon Glass <sjg@chromium.org>

bootstage: Allow calling bootstage_mark() before bootstage_init()

It is possible for this to happen if something goes wrong very early in
the init sequence. Add a check for this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# b08c8c48 04-Mar-2018 Masahiro Yamada <masahiroy@kernel.org>

libfdt: move headers to <linux/libfdt.h> and <linux/libfdt_env.h>

Thomas reported U-Boot failed to build host tools if libfdt-devel
package is installed because tools include libfdt headers from
/usr/include/ instead of using internal ones.

This commit moves the header code:
include/libfdt.h -> include/linux/libfdt.h
include/libfdt_env.h -> include/linux/libfdt_env.h

and replaces include directives:
#include <libfdt.h> -> #include <linux/libfdt.h>
#include <libfdt_env.h> -> #include <linux/libfdt_env.h>

Reported-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# d69bb0ec 05-Sep-2017 Simon Glass <sjg@chromium.org>

bootstage: Provide a separate record count setting for SPL

With SPL we often have limited memory and do not need very many bootstage
records. Add a separate Kconfig option for SPL.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 066b25b6 05-Sep-2017 Simon Glass <sjg@chromium.org>

bootstage: Drop unused options

The CONFIG_BOOTSTAGE_USER_COUNT option is no-longer needed since we can now
support any number of user IDs. Also BOOTSTAGE_ID_COUNT is not needed now.

Drop these unused options.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 9d2542d0 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Adjust to use const * where possible

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 <sjg@chromium.org>

# e003310a 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Tidy up error return values

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 <sjg@chromium.org>

# 25e7dc6a 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Support relocating boostage data

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 <sjg@chromium.org>

# ff00226e 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Use debug() for stashing messages

We don't normally want to see these messages. Change them to debug-only.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c91001f6 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Show records with a zero time

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 <sjg@chromium.org>

# 03ecac31 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Use rec_count as the array index

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.

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 <sjg@chromium.org>

# cbcd6970 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Fix up code style and comments

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 <sjg@chromium.org>

# b383d6c0 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Convert to use malloc()

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
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.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c87dc38d 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Require timer_get_boot_us() to be defined

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.c for boards
which use CONFIG_SYS_TIMER_COUNTER.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# b8bcaa3a 11-Jun-2013 Simon Glass <sjg@chromium.org>

Add function to print a number with grouped digits

Move bootstage's numbering printing code into a generic place so that it can
be used by tracing also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5d3bd345 11-Jun-2013 Simon Glass <sjg@chromium.org>

bootstage: Correct printf types

The unstash code is a bit loose with its printf() types, which gives
warnings on sandbox. Correct this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fb7db41c 17-Apr-2013 Simon Glass <sjg@chromium.org>

bootstage: Allow marking a particular line of code

Add a function which allows a (file, function, line number) to be marked
in bootstage.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Che-Liang Chiou <clchiou@chromium.org>

# 150678a5 17-Apr-2013 Doug Anderson <dianders@chromium.org>

bootstage: Copy bootstage strings post-relocation

Any pointers to name strings that were passed to bootstage_mark_name()
pre-relocation should be copied post-relocation so that they don't get
trashed as the original location of U-Boot is re-used for other
purposes.

This change introduces a new API call that should be called from
board_init_r() after malloc has been initted on any board that uses
bootstage.

Signed-off-by: Doug Anderson <dianders@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# fcf509b8 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Add feature to stash/unstash bootstage info

It is useful to be able to write the bootstage information to memory for
use by a later utility, or the Linux kernel. Provide a function to do
this as well as a function to read bootstage information back and incorporate
it into the current table.

This also makes it possible for U-Boot to chain to another U-Boot and pass
on its bootstage information.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 94fd1316 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Store boot timings in device tree

Add an option, CONFIG_BOOTSTAGE_FDT to pass boot timings to the kernel
in the device tree, if available. To use this, you must have
CONFIG_OF_LIBFDT defined.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0e996773 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Add time accumulation feature

Sometimes we want to add up the amount of time spent in a particular
activity when it is happening in a number of discrete chunks.

Add bootstage_start() to mark the start of an acitivity and
bootstage_accum() to accumulate the time since the last start. Calling
these function in pairs results in the accumulated time being collected.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 094e06a5 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Export bootstage_add_record() function

This function is not static, but not exported either. Add a prototype
in the header file and move the required enum to the header also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3786980d 04-Apr-2012 Simon Glass <sjg@chromium.org>

Move bootstage timer out of lib/time.c

The standalone example does not have get_timer() defined, so we cannot
rely on it being available.

Move the timer function into boootstage.c to avoid this problem.

This corrects a build breakage for the standalone example on some boards.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Matthias Fuchs <matthias.fuchs@esd.eu>

# 3a608ca0 13-Feb-2012 Simon Glass <sjg@chromium.org>

bootstage: Implement core microsecond boot time measurement

This defines the basics of a new boot time measurement feature. This allows
logging of very accurate time measurements as the boot proceeds, by using
an available microsecond counter.

To enable the feature, define CONFIG_BOOTSTAGE in your board config file.
Also available is CONFIG_BOOTSTAGE_REPORT which will cause a report to be
printed just before handing off to the OS.

Most IDs are not named at this stage. For that I would first like to
renumber them all.

Timer summary in microseconds:
Mark Elapsed Stage
0 0 reset
205,000 205,000 board_init_f
6,053,000 5,848,000 bootm_start
6,053,000 0 id=1
6,058,000 5,000 id=101
6,058,000 0 id=100
6,061,000 3,000 id=103
6,064,000 3,000 id=104
6,093,000 29,000 id=107
6,093,000 0 id=106
6,093,000 0 id=105
6,093,000 0 id=108
7,089,000 996,000 id=7
7,089,000 0 id=15
7,089,000 0 id=8
7,097,000 8,000 start_kernel

Signed-off-by: Simon Glass <sjg@chromium.org>

# 17ba5010 26-Sep-2023 Simon Glass <sjg@chromium.org>

spl: Remove #ifdefs with BOOTSTAGE

This feature has some helpers in its header file so that its functions
resolve to nothing when the feature is disabled. Add a few more and use
these to simplify the code.

With this there are no more #ifdefs in board_init_r()

Signed-off-by: Simon Glass <sjg@chromium.org>

# 55bc2276 12-Aug-2022 Michal Simek <michal.simek@amd.com>

bootstage: Show func name for bootstage_mark/error

bootstage_mark() and bootstate_error() are not recording any name and in
report it is showing as id=<value>. That's not useful and it is better to
show function name which calls it.
That's why use macros with passing __func__ as recorded name for bootstage.

Origin report looks like this:
ZynqMP> bootstage report
Timer summary in microseconds (10 records):
Mark Elapsed Stage
0 0 reset
2,482,383 2,482,383 board_init_f
4,278,821 1,796,438 board_init_r
4,825,331 546,510 id=64
4,858,409 33,078 id=65
4,862,382 3,973 main_loop
4,921,713 59,331 usb_start
9,345,345 4,423,632 id=175

When this patch is applied.
ZynqMP> bootstage report
Timer summary in microseconds (31 records):
Mark Elapsed Stage
0 0 reset
2,465,624 2,465,624 board_init_f
4,278,628 1,813,004 board_init_r
4,825,139 546,511 eth_common_init
4,858,228 33,089 eth_initialize
4,862,201 3,973 main_loop
4,921,530 59,329 usb_start
8,885,334 3,963,804 cli_loop

Signed-off-by: Michal Simek <michal.simek@amd.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# eb26d88d 14-Mar-2021 Simon Glass <sjg@chromium.org>

bootstage: Warning if space is exhausted

At present bootstage silently ignores new records if it runs out of
space. It is sometimes obvious by looking at the report, but the IDs are
not contiguous, so it is easy to miss.

Aad a message so that action can be taken.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 939b04e9 03-Feb-2021 Simon Glass <sjg@chromium.org>

bootstage: Fix dependency for BOOTSTAGE_RECORD_COUNT

At present these three Kconfigs exist even when bootstage is not enabled.
This is not necessary since bootstage.c is only built if BOOTSTAGE is
enabled.

Make them conditional. Also fix up the overflow message to mention TPL.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 401d1c4f 30-Oct-2020 Simon Glass <sjg@chromium.org>

common: Drop asm/global_data.h from common header

Move this out of the common header and include it only where needed. In
a number of cases this requires adding "struct udevice;" to avoid adding
another large header or in other cases replacing / adding missing header
files that had been pulled in, very indirectly. Finally, we have a few
cases where we did not need to include <asm/global_data.h> at all, so
remove that include.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Tom Rini <trini@konsulko.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 52f24238 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop bootstage.h from common header

Move this fairly uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# db41d65a 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move hang() to the same header as panic()

At present panic() is in the vsprintf.h header file. That does not seem
like an obvious choice for hang(), even though it relates to panic(). So
let's put hang() in its own header.

Signed-off-by: Simon Glass <sjg@chromium.org>
[trini: Migrate a few more files]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 8bef79bf 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move sorting functions to their own header file

These don't need to be in common.h so move them out into a new header.
Also add some missing comments.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# ac9cd480 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Correct relocation algorithm

At present bootstage relocation assumes that it is possible to point back
to memory available before relocation, so it does not relocate the
strings. However this is not the case on some platforms, such as x86 which
uses the cache as RAM and loses access to this when the cache is enabled.

Move the relocation step to before U-Boot relocates, expand the allocated
region to include space for the strings and relocate the strings at the
same time as the bootstage records.

This ensures that bootstage data can remain accessible from TPL through
SPL to U-Boot before/after relocation.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 65b2d96f 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Avoid conflicts between stash/unstash

At present there is a single shared address for bootstage data in both
TPL and SPL. If SPL unstashs TPL bootstage info and then stashes it again
to pass it to U-Boot, the new stash overwrites the strings of the old
stash.

Fix this by duplicating the strings into the malloc() region. This should
be a small code. Fix the header-file order at the same time.

This problem doesn't happen at the next stage (SPL->U-Boot) since U-Boot
relocates the boostage data.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ed54bdaf 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Fix counting of entries in stash

The current code searches for empty records but these not existing with
bootstage now. This used to be needed when bootstage records were stored
in a spare array.

Drop the unnecessary code and fix a code-style nit at the same time.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 53a4f253 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Store the next ID in the stash

When stashing bootstage info, store the next ID so that it can be used
when the stash is restored. This avoids the ID starting at zero and
potentially overwriting existing entries.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 17357725 08-Apr-2019 Simon Glass <sjg@chromium.org>

bootstage: Allow calling bootstage_mark() before bootstage_init()

It is possible for this to happen if something goes wrong very early in
the init sequence. Add a check for this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# b08c8c48 04-Mar-2018 Masahiro Yamada <masahiroy@kernel.org>

libfdt: move headers to <linux/libfdt.h> and <linux/libfdt_env.h>

Thomas reported U-Boot failed to build host tools if libfdt-devel
package is installed because tools include libfdt headers from
/usr/include/ instead of using internal ones.

This commit moves the header code:
include/libfdt.h -> include/linux/libfdt.h
include/libfdt_env.h -> include/linux/libfdt_env.h

and replaces include directives:
#include <libfdt.h> -> #include <linux/libfdt.h>
#include <libfdt_env.h> -> #include <linux/libfdt_env.h>

Reported-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# d69bb0ec 05-Sep-2017 Simon Glass <sjg@chromium.org>

bootstage: Provide a separate record count setting for SPL

With SPL we often have limited memory and do not need very many bootstage
records. Add a separate Kconfig option for SPL.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 066b25b6 05-Sep-2017 Simon Glass <sjg@chromium.org>

bootstage: Drop unused options

The CONFIG_BOOTSTAGE_USER_COUNT option is no-longer needed since we can now
support any number of user IDs. Also BOOTSTAGE_ID_COUNT is not needed now.

Drop these unused options.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 9d2542d0 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Adjust to use const * where possible

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 <sjg@chromium.org>

# e003310a 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Tidy up error return values

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 <sjg@chromium.org>

# 25e7dc6a 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Support relocating boostage data

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 <sjg@chromium.org>

# ff00226e 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Use debug() for stashing messages

We don't normally want to see these messages. Change them to debug-only.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c91001f6 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Show records with a zero time

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 <sjg@chromium.org>

# 03ecac31 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Use rec_count as the array index

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.

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 <sjg@chromium.org>

# cbcd6970 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Fix up code style and comments

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 <sjg@chromium.org>

# b383d6c0 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Convert to use malloc()

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
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.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c87dc38d 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Require timer_get_boot_us() to be defined

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.c for boards
which use CONFIG_SYS_TIMER_COUNTER.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# b8bcaa3a 11-Jun-2013 Simon Glass <sjg@chromium.org>

Add function to print a number with grouped digits

Move bootstage's numbering printing code into a generic place so that it can
be used by tracing also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5d3bd345 11-Jun-2013 Simon Glass <sjg@chromium.org>

bootstage: Correct printf types

The unstash code is a bit loose with its printf() types, which gives
warnings on sandbox. Correct this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fb7db41c 17-Apr-2013 Simon Glass <sjg@chromium.org>

bootstage: Allow marking a particular line of code

Add a function which allows a (file, function, line number) to be marked
in bootstage.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Che-Liang Chiou <clchiou@chromium.org>

# 150678a5 17-Apr-2013 Doug Anderson <dianders@chromium.org>

bootstage: Copy bootstage strings post-relocation

Any pointers to name strings that were passed to bootstage_mark_name()
pre-relocation should be copied post-relocation so that they don't get
trashed as the original location of U-Boot is re-used for other
purposes.

This change introduces a new API call that should be called from
board_init_r() after malloc has been initted on any board that uses
bootstage.

Signed-off-by: Doug Anderson <dianders@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# fcf509b8 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Add feature to stash/unstash bootstage info

It is useful to be able to write the bootstage information to memory for
use by a later utility, or the Linux kernel. Provide a function to do
this as well as a function to read bootstage information back and incorporate
it into the current table.

This also makes it possible for U-Boot to chain to another U-Boot and pass
on its bootstage information.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 94fd1316 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Store boot timings in device tree

Add an option, CONFIG_BOOTSTAGE_FDT to pass boot timings to the kernel
in the device tree, if available. To use this, you must have
CONFIG_OF_LIBFDT defined.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0e996773 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Add time accumulation feature

Sometimes we want to add up the amount of time spent in a particular
activity when it is happening in a number of discrete chunks.

Add bootstage_start() to mark the start of an acitivity and
bootstage_accum() to accumulate the time since the last start. Calling
these function in pairs results in the accumulated time being collected.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 094e06a5 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Export bootstage_add_record() function

This function is not static, but not exported either. Add a prototype
in the header file and move the required enum to the header also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3786980d 04-Apr-2012 Simon Glass <sjg@chromium.org>

Move bootstage timer out of lib/time.c

The standalone example does not have get_timer() defined, so we cannot
rely on it being available.

Move the timer function into boootstage.c to avoid this problem.

This corrects a build breakage for the standalone example on some boards.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Matthias Fuchs <matthias.fuchs@esd.eu>

# 3a608ca0 13-Feb-2012 Simon Glass <sjg@chromium.org>

bootstage: Implement core microsecond boot time measurement

This defines the basics of a new boot time measurement feature. This allows
logging of very accurate time measurements as the boot proceeds, by using
an available microsecond counter.

To enable the feature, define CONFIG_BOOTSTAGE in your board config file.
Also available is CONFIG_BOOTSTAGE_REPORT which will cause a report to be
printed just before handing off to the OS.

Most IDs are not named at this stage. For that I would first like to
renumber them all.

Timer summary in microseconds:
Mark Elapsed Stage
0 0 reset
205,000 205,000 board_init_f
6,053,000 5,848,000 bootm_start
6,053,000 0 id=1
6,058,000 5,000 id=101
6,058,000 0 id=100
6,061,000 3,000 id=103
6,064,000 3,000 id=104
6,093,000 29,000 id=107
6,093,000 0 id=106
6,093,000 0 id=105
6,093,000 0 id=108
7,089,000 996,000 id=7
7,089,000 0 id=15
7,089,000 0 id=8
7,097,000 8,000 start_kernel

Signed-off-by: Simon Glass <sjg@chromium.org>

# 55bc2276 12-Aug-2022 Michal Simek <michal.simek@amd.com>

bootstage: Show func name for bootstage_mark/error

bootstage_mark() and bootstate_error() are not recording any name and in
report it is showing as id=<value>. That's not useful and it is better to
show function name which calls it.
That's why use macros with passing __func__ as recorded name for bootstage.

Origin report looks like this:
ZynqMP> bootstage report
Timer summary in microseconds (10 records):
Mark Elapsed Stage
0 0 reset
2,482,383 2,482,383 board_init_f
4,278,821 1,796,438 board_init_r
4,825,331 546,510 id=64
4,858,409 33,078 id=65
4,862,382 3,973 main_loop
4,921,713 59,331 usb_start
9,345,345 4,423,632 id=175

When this patch is applied.
ZynqMP> bootstage report
Timer summary in microseconds (31 records):
Mark Elapsed Stage
0 0 reset
2,465,624 2,465,624 board_init_f
4,278,628 1,813,004 board_init_r
4,825,139 546,511 eth_common_init
4,858,228 33,089 eth_initialize
4,862,201 3,973 main_loop
4,921,530 59,329 usb_start
8,885,334 3,963,804 cli_loop

Signed-off-by: Michal Simek <michal.simek@amd.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# eb26d88d 14-Mar-2021 Simon Glass <sjg@chromium.org>

bootstage: Warning if space is exhausted

At present bootstage silently ignores new records if it runs out of
space. It is sometimes obvious by looking at the report, but the IDs are
not contiguous, so it is easy to miss.

Aad a message so that action can be taken.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 939b04e9 03-Feb-2021 Simon Glass <sjg@chromium.org>

bootstage: Fix dependency for BOOTSTAGE_RECORD_COUNT

At present these three Kconfigs exist even when bootstage is not enabled.
This is not necessary since bootstage.c is only built if BOOTSTAGE is
enabled.

Make them conditional. Also fix up the overflow message to mention TPL.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 401d1c4f 30-Oct-2020 Simon Glass <sjg@chromium.org>

common: Drop asm/global_data.h from common header

Move this out of the common header and include it only where needed. In
a number of cases this requires adding "struct udevice;" to avoid adding
another large header or in other cases replacing / adding missing header
files that had been pulled in, very indirectly. Finally, we have a few
cases where we did not need to include <asm/global_data.h> at all, so
remove that include.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Tom Rini <trini@konsulko.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 52f24238 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop bootstage.h from common header

Move this fairly uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# db41d65a 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move hang() to the same header as panic()

At present panic() is in the vsprintf.h header file. That does not seem
like an obvious choice for hang(), even though it relates to panic(). So
let's put hang() in its own header.

Signed-off-by: Simon Glass <sjg@chromium.org>
[trini: Migrate a few more files]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 8bef79bf 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move sorting functions to their own header file

These don't need to be in common.h so move them out into a new header.
Also add some missing comments.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# ac9cd480 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Correct relocation algorithm

At present bootstage relocation assumes that it is possible to point back
to memory available before relocation, so it does not relocate the
strings. However this is not the case on some platforms, such as x86 which
uses the cache as RAM and loses access to this when the cache is enabled.

Move the relocation step to before U-Boot relocates, expand the allocated
region to include space for the strings and relocate the strings at the
same time as the bootstage records.

This ensures that bootstage data can remain accessible from TPL through
SPL to U-Boot before/after relocation.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 65b2d96f 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Avoid conflicts between stash/unstash

At present there is a single shared address for bootstage data in both
TPL and SPL. If SPL unstashs TPL bootstage info and then stashes it again
to pass it to U-Boot, the new stash overwrites the strings of the old
stash.

Fix this by duplicating the strings into the malloc() region. This should
be a small code. Fix the header-file order at the same time.

This problem doesn't happen at the next stage (SPL->U-Boot) since U-Boot
relocates the boostage data.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ed54bdaf 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Fix counting of entries in stash

The current code searches for empty records but these not existing with
bootstage now. This used to be needed when bootstage records were stored
in a spare array.

Drop the unnecessary code and fix a code-style nit at the same time.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 53a4f253 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Store the next ID in the stash

When stashing bootstage info, store the next ID so that it can be used
when the stash is restored. This avoids the ID starting at zero and
potentially overwriting existing entries.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 17357725 08-Apr-2019 Simon Glass <sjg@chromium.org>

bootstage: Allow calling bootstage_mark() before bootstage_init()

It is possible for this to happen if something goes wrong very early in
the init sequence. Add a check for this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# b08c8c48 04-Mar-2018 Masahiro Yamada <yamada.masahiro@socionext.com>

libfdt: move headers to <linux/libfdt.h> and <linux/libfdt_env.h>

Thomas reported U-Boot failed to build host tools if libfdt-devel
package is installed because tools include libfdt headers from
/usr/include/ instead of using internal ones.

This commit moves the header code:
include/libfdt.h -> include/linux/libfdt.h
include/libfdt_env.h -> include/linux/libfdt_env.h

and replaces include directives:
#include <libfdt.h> -> #include <linux/libfdt.h>
#include <libfdt_env.h> -> #include <linux/libfdt_env.h>

Reported-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# d69bb0ec 05-Sep-2017 Simon Glass <sjg@chromium.org>

bootstage: Provide a separate record count setting for SPL

With SPL we often have limited memory and do not need very many bootstage
records. Add a separate Kconfig option for SPL.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 066b25b6 05-Sep-2017 Simon Glass <sjg@chromium.org>

bootstage: Drop unused options

The CONFIG_BOOTSTAGE_USER_COUNT option is no-longer needed since we can now
support any number of user IDs. Also BOOTSTAGE_ID_COUNT is not needed now.

Drop these unused options.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 9d2542d0 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Adjust to use const * where possible

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 <sjg@chromium.org>

# e003310a 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Tidy up error return values

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 <sjg@chromium.org>

# 25e7dc6a 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Support relocating boostage data

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 <sjg@chromium.org>

# ff00226e 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Use debug() for stashing messages

We don't normally want to see these messages. Change them to debug-only.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c91001f6 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Show records with a zero time

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 <sjg@chromium.org>

# 03ecac31 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Use rec_count as the array index

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.

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 <sjg@chromium.org>

# cbcd6970 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Fix up code style and comments

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 <sjg@chromium.org>

# b383d6c0 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Convert to use malloc()

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
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.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c87dc38d 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Require timer_get_boot_us() to be defined

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.c for boards
which use CONFIG_SYS_TIMER_COUNTER.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# b8bcaa3a 11-Jun-2013 Simon Glass <sjg@chromium.org>

Add function to print a number with grouped digits

Move bootstage's numbering printing code into a generic place so that it can
be used by tracing also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5d3bd345 11-Jun-2013 Simon Glass <sjg@chromium.org>

bootstage: Correct printf types

The unstash code is a bit loose with its printf() types, which gives
warnings on sandbox. Correct this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fb7db41c 17-Apr-2013 Simon Glass <sjg@chromium.org>

bootstage: Allow marking a particular line of code

Add a function which allows a (file, function, line number) to be marked
in bootstage.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Che-Liang Chiou <clchiou@chromium.org>

# 150678a5 17-Apr-2013 Doug Anderson <dianders@chromium.org>

bootstage: Copy bootstage strings post-relocation

Any pointers to name strings that were passed to bootstage_mark_name()
pre-relocation should be copied post-relocation so that they don't get
trashed as the original location of U-Boot is re-used for other
purposes.

This change introduces a new API call that should be called from
board_init_r() after malloc has been initted on any board that uses
bootstage.

Signed-off-by: Doug Anderson <dianders@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# fcf509b8 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Add feature to stash/unstash bootstage info

It is useful to be able to write the bootstage information to memory for
use by a later utility, or the Linux kernel. Provide a function to do
this as well as a function to read bootstage information back and incorporate
it into the current table.

This also makes it possible for U-Boot to chain to another U-Boot and pass
on its bootstage information.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 94fd1316 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Store boot timings in device tree

Add an option, CONFIG_BOOTSTAGE_FDT to pass boot timings to the kernel
in the device tree, if available. To use this, you must have
CONFIG_OF_LIBFDT defined.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0e996773 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Add time accumulation feature

Sometimes we want to add up the amount of time spent in a particular
activity when it is happening in a number of discrete chunks.

Add bootstage_start() to mark the start of an acitivity and
bootstage_accum() to accumulate the time since the last start. Calling
these function in pairs results in the accumulated time being collected.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 094e06a5 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Export bootstage_add_record() function

This function is not static, but not exported either. Add a prototype
in the header file and move the required enum to the header also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3786980d 04-Apr-2012 Simon Glass <sjg@chromium.org>

Move bootstage timer out of lib/time.c

The standalone example does not have get_timer() defined, so we cannot
rely on it being available.

Move the timer function into boootstage.c to avoid this problem.

This corrects a build breakage for the standalone example on some boards.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Matthias Fuchs <matthias.fuchs@esd.eu>

# 3a608ca0 13-Feb-2012 Simon Glass <sjg@chromium.org>

bootstage: Implement core microsecond boot time measurement

This defines the basics of a new boot time measurement feature. This allows
logging of very accurate time measurements as the boot proceeds, by using
an available microsecond counter.

To enable the feature, define CONFIG_BOOTSTAGE in your board config file.
Also available is CONFIG_BOOTSTAGE_REPORT which will cause a report to be
printed just before handing off to the OS.

Most IDs are not named at this stage. For that I would first like to
renumber them all.

Timer summary in microseconds:
Mark Elapsed Stage
0 0 reset
205,000 205,000 board_init_f
6,053,000 5,848,000 bootm_start
6,053,000 0 id=1
6,058,000 5,000 id=101
6,058,000 0 id=100
6,061,000 3,000 id=103
6,064,000 3,000 id=104
6,093,000 29,000 id=107
6,093,000 0 id=106
6,093,000 0 id=105
6,093,000 0 id=108
7,089,000 996,000 id=7
7,089,000 0 id=15
7,089,000 0 id=8
7,097,000 8,000 start_kernel

Signed-off-by: Simon Glass <sjg@chromium.org>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# eb26d88d 14-Mar-2021 Simon Glass <sjg@chromium.org>

bootstage: Warning if space is exhausted

At present bootstage silently ignores new records if it runs out of
space. It is sometimes obvious by looking at the report, but the IDs are
not contiguous, so it is easy to miss.

Aad a message so that action can be taken.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 939b04e9 03-Feb-2021 Simon Glass <sjg@chromium.org>

bootstage: Fix dependency for BOOTSTAGE_RECORD_COUNT

At present these three Kconfigs exist even when bootstage is not enabled.
This is not necessary since bootstage.c is only built if BOOTSTAGE is
enabled.

Make them conditional. Also fix up the overflow message to mention TPL.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 401d1c4f 30-Oct-2020 Simon Glass <sjg@chromium.org>

common: Drop asm/global_data.h from common header

Move this out of the common header and include it only where needed. In
a number of cases this requires adding "struct udevice;" to avoid adding
another large header or in other cases replacing / adding missing header
files that had been pulled in, very indirectly. Finally, we have a few
cases where we did not need to include <asm/global_data.h> at all, so
remove that include.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Tom Rini <trini@konsulko.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 52f24238 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop bootstage.h from common header

Move this fairly uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# db41d65a 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move hang() to the same header as panic()

At present panic() is in the vsprintf.h header file. That does not seem
like an obvious choice for hang(), even though it relates to panic(). So
let's put hang() in its own header.

Signed-off-by: Simon Glass <sjg@chromium.org>
[trini: Migrate a few more files]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 8bef79bf 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move sorting functions to their own header file

These don't need to be in common.h so move them out into a new header.
Also add some missing comments.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# ac9cd480 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Correct relocation algorithm

At present bootstage relocation assumes that it is possible to point back
to memory available before relocation, so it does not relocate the
strings. However this is not the case on some platforms, such as x86 which
uses the cache as RAM and loses access to this when the cache is enabled.

Move the relocation step to before U-Boot relocates, expand the allocated
region to include space for the strings and relocate the strings at the
same time as the bootstage records.

This ensures that bootstage data can remain accessible from TPL through
SPL to U-Boot before/after relocation.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 65b2d96f 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Avoid conflicts between stash/unstash

At present there is a single shared address for bootstage data in both
TPL and SPL. If SPL unstashs TPL bootstage info and then stashes it again
to pass it to U-Boot, the new stash overwrites the strings of the old
stash.

Fix this by duplicating the strings into the malloc() region. This should
be a small code. Fix the header-file order at the same time.

This problem doesn't happen at the next stage (SPL->U-Boot) since U-Boot
relocates the boostage data.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ed54bdaf 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Fix counting of entries in stash

The current code searches for empty records but these not existing with
bootstage now. This used to be needed when bootstage records were stored
in a spare array.

Drop the unnecessary code and fix a code-style nit at the same time.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 53a4f253 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Store the next ID in the stash

When stashing bootstage info, store the next ID so that it can be used
when the stash is restored. This avoids the ID starting at zero and
potentially overwriting existing entries.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 17357725 08-Apr-2019 Simon Glass <sjg@chromium.org>

bootstage: Allow calling bootstage_mark() before bootstage_init()

It is possible for this to happen if something goes wrong very early in
the init sequence. Add a check for this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# b08c8c48 04-Mar-2018 Masahiro Yamada <yamada.masahiro@socionext.com>

libfdt: move headers to <linux/libfdt.h> and <linux/libfdt_env.h>

Thomas reported U-Boot failed to build host tools if libfdt-devel
package is installed because tools include libfdt headers from
/usr/include/ instead of using internal ones.

This commit moves the header code:
include/libfdt.h -> include/linux/libfdt.h
include/libfdt_env.h -> include/linux/libfdt_env.h

and replaces include directives:
#include <libfdt.h> -> #include <linux/libfdt.h>
#include <libfdt_env.h> -> #include <linux/libfdt_env.h>

Reported-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# d69bb0ec 05-Sep-2017 Simon Glass <sjg@chromium.org>

bootstage: Provide a separate record count setting for SPL

With SPL we often have limited memory and do not need very many bootstage
records. Add a separate Kconfig option for SPL.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 066b25b6 05-Sep-2017 Simon Glass <sjg@chromium.org>

bootstage: Drop unused options

The CONFIG_BOOTSTAGE_USER_COUNT option is no-longer needed since we can now
support any number of user IDs. Also BOOTSTAGE_ID_COUNT is not needed now.

Drop these unused options.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 9d2542d0 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Adjust to use const * where possible

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 <sjg@chromium.org>

# e003310a 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Tidy up error return values

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 <sjg@chromium.org>

# 25e7dc6a 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Support relocating boostage data

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 <sjg@chromium.org>

# ff00226e 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Use debug() for stashing messages

We don't normally want to see these messages. Change them to debug-only.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c91001f6 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Show records with a zero time

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 <sjg@chromium.org>

# 03ecac31 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Use rec_count as the array index

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.

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 <sjg@chromium.org>

# cbcd6970 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Fix up code style and comments

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 <sjg@chromium.org>

# b383d6c0 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Convert to use malloc()

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
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.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c87dc38d 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Require timer_get_boot_us() to be defined

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.c for boards
which use CONFIG_SYS_TIMER_COUNTER.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# b8bcaa3a 11-Jun-2013 Simon Glass <sjg@chromium.org>

Add function to print a number with grouped digits

Move bootstage's numbering printing code into a generic place so that it can
be used by tracing also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5d3bd345 11-Jun-2013 Simon Glass <sjg@chromium.org>

bootstage: Correct printf types

The unstash code is a bit loose with its printf() types, which gives
warnings on sandbox. Correct this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fb7db41c 17-Apr-2013 Simon Glass <sjg@chromium.org>

bootstage: Allow marking a particular line of code

Add a function which allows a (file, function, line number) to be marked
in bootstage.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Che-Liang Chiou <clchiou@chromium.org>

# 150678a5 17-Apr-2013 Doug Anderson <dianders@chromium.org>

bootstage: Copy bootstage strings post-relocation

Any pointers to name strings that were passed to bootstage_mark_name()
pre-relocation should be copied post-relocation so that they don't get
trashed as the original location of U-Boot is re-used for other
purposes.

This change introduces a new API call that should be called from
board_init_r() after malloc has been initted on any board that uses
bootstage.

Signed-off-by: Doug Anderson <dianders@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# fcf509b8 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Add feature to stash/unstash bootstage info

It is useful to be able to write the bootstage information to memory for
use by a later utility, or the Linux kernel. Provide a function to do
this as well as a function to read bootstage information back and incorporate
it into the current table.

This also makes it possible for U-Boot to chain to another U-Boot and pass
on its bootstage information.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 94fd1316 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Store boot timings in device tree

Add an option, CONFIG_BOOTSTAGE_FDT to pass boot timings to the kernel
in the device tree, if available. To use this, you must have
CONFIG_OF_LIBFDT defined.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0e996773 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Add time accumulation feature

Sometimes we want to add up the amount of time spent in a particular
activity when it is happening in a number of discrete chunks.

Add bootstage_start() to mark the start of an acitivity and
bootstage_accum() to accumulate the time since the last start. Calling
these function in pairs results in the accumulated time being collected.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 094e06a5 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Export bootstage_add_record() function

This function is not static, but not exported either. Add a prototype
in the header file and move the required enum to the header also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3786980d 04-Apr-2012 Simon Glass <sjg@chromium.org>

Move bootstage timer out of lib/time.c

The standalone example does not have get_timer() defined, so we cannot
rely on it being available.

Move the timer function into boootstage.c to avoid this problem.

This corrects a build breakage for the standalone example on some boards.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Matthias Fuchs <matthias.fuchs@esd.eu>

# 3a608ca0 13-Feb-2012 Simon Glass <sjg@chromium.org>

bootstage: Implement core microsecond boot time measurement

This defines the basics of a new boot time measurement feature. This allows
logging of very accurate time measurements as the boot proceeds, by using
an available microsecond counter.

To enable the feature, define CONFIG_BOOTSTAGE in your board config file.
Also available is CONFIG_BOOTSTAGE_REPORT which will cause a report to be
printed just before handing off to the OS.

Most IDs are not named at this stage. For that I would first like to
renumber them all.

Timer summary in microseconds:
Mark Elapsed Stage
0 0 reset
205,000 205,000 board_init_f
6,053,000 5,848,000 bootm_start
6,053,000 0 id=1
6,058,000 5,000 id=101
6,058,000 0 id=100
6,061,000 3,000 id=103
6,064,000 3,000 id=104
6,093,000 29,000 id=107
6,093,000 0 id=106
6,093,000 0 id=105
6,093,000 0 id=108
7,089,000 996,000 id=7
7,089,000 0 id=15
7,089,000 0 id=8
7,097,000 8,000 start_kernel

Signed-off-by: Simon Glass <sjg@chromium.org>

# eb26d88d 14-Mar-2021 Simon Glass <sjg@chromium.org>

bootstage: Warning if space is exhausted

At present bootstage silently ignores new records if it runs out of
space. It is sometimes obvious by looking at the report, but the IDs are
not contiguous, so it is easy to miss.

Aad a message so that action can be taken.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 939b04e9 03-Feb-2021 Simon Glass <sjg@chromium.org>

bootstage: Fix dependency for BOOTSTAGE_RECORD_COUNT

At present these three Kconfigs exist even when bootstage is not enabled.
This is not necessary since bootstage.c is only built if BOOTSTAGE is
enabled.

Make them conditional. Also fix up the overflow message to mention TPL.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 401d1c4f 30-Oct-2020 Simon Glass <sjg@chromium.org>

common: Drop asm/global_data.h from common header

Move this out of the common header and include it only where needed. In
a number of cases this requires adding "struct udevice;" to avoid adding
another large header or in other cases replacing / adding missing header
files that had been pulled in, very indirectly. Finally, we have a few
cases where we did not need to include <asm/global_data.h> at all, so
remove that include.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Tom Rini <trini@konsulko.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 52f24238 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop bootstage.h from common header

Move this fairly uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# db41d65a 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move hang() to the same header as panic()

At present panic() is in the vsprintf.h header file. That does not seem
like an obvious choice for hang(), even though it relates to panic(). So
let's put hang() in its own header.

Signed-off-by: Simon Glass <sjg@chromium.org>
[trini: Migrate a few more files]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 8bef79bf 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move sorting functions to their own header file

These don't need to be in common.h so move them out into a new header.
Also add some missing comments.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# ac9cd480 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Correct relocation algorithm

At present bootstage relocation assumes that it is possible to point back
to memory available before relocation, so it does not relocate the
strings. However this is not the case on some platforms, such as x86 which
uses the cache as RAM and loses access to this when the cache is enabled.

Move the relocation step to before U-Boot relocates, expand the allocated
region to include space for the strings and relocate the strings at the
same time as the bootstage records.

This ensures that bootstage data can remain accessible from TPL through
SPL to U-Boot before/after relocation.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 65b2d96f 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Avoid conflicts between stash/unstash

At present there is a single shared address for bootstage data in both
TPL and SPL. If SPL unstashs TPL bootstage info and then stashes it again
to pass it to U-Boot, the new stash overwrites the strings of the old
stash.

Fix this by duplicating the strings into the malloc() region. This should
be a small code. Fix the header-file order at the same time.

This problem doesn't happen at the next stage (SPL->U-Boot) since U-Boot
relocates the boostage data.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ed54bdaf 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Fix counting of entries in stash

The current code searches for empty records but these not existing with
bootstage now. This used to be needed when bootstage records were stored
in a spare array.

Drop the unnecessary code and fix a code-style nit at the same time.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 53a4f253 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Store the next ID in the stash

When stashing bootstage info, store the next ID so that it can be used
when the stash is restored. This avoids the ID starting at zero and
potentially overwriting existing entries.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 17357725 08-Apr-2019 Simon Glass <sjg@chromium.org>

bootstage: Allow calling bootstage_mark() before bootstage_init()

It is possible for this to happen if something goes wrong very early in
the init sequence. Add a check for this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# b08c8c48 04-Mar-2018 Masahiro Yamada <yamada.masahiro@socionext.com>

libfdt: move headers to <linux/libfdt.h> and <linux/libfdt_env.h>

Thomas reported U-Boot failed to build host tools if libfdt-devel
package is installed because tools include libfdt headers from
/usr/include/ instead of using internal ones.

This commit moves the header code:
include/libfdt.h -> include/linux/libfdt.h
include/libfdt_env.h -> include/linux/libfdt_env.h

and replaces include directives:
#include <libfdt.h> -> #include <linux/libfdt.h>
#include <libfdt_env.h> -> #include <linux/libfdt_env.h>

Reported-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# d69bb0ec 05-Sep-2017 Simon Glass <sjg@chromium.org>

bootstage: Provide a separate record count setting for SPL

With SPL we often have limited memory and do not need very many bootstage
records. Add a separate Kconfig option for SPL.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 066b25b6 05-Sep-2017 Simon Glass <sjg@chromium.org>

bootstage: Drop unused options

The CONFIG_BOOTSTAGE_USER_COUNT option is no-longer needed since we can now
support any number of user IDs. Also BOOTSTAGE_ID_COUNT is not needed now.

Drop these unused options.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 9d2542d0 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Adjust to use const * where possible

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 <sjg@chromium.org>

# e003310a 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Tidy up error return values

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 <sjg@chromium.org>

# 25e7dc6a 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Support relocating boostage data

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 <sjg@chromium.org>

# ff00226e 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Use debug() for stashing messages

We don't normally want to see these messages. Change them to debug-only.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c91001f6 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Show records with a zero time

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 <sjg@chromium.org>

# 03ecac31 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Use rec_count as the array index

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.

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 <sjg@chromium.org>

# cbcd6970 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Fix up code style and comments

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 <sjg@chromium.org>

# b383d6c0 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Convert to use malloc()

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
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.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c87dc38d 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Require timer_get_boot_us() to be defined

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.c for boards
which use CONFIG_SYS_TIMER_COUNTER.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# b8bcaa3a 11-Jun-2013 Simon Glass <sjg@chromium.org>

Add function to print a number with grouped digits

Move bootstage's numbering printing code into a generic place so that it can
be used by tracing also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5d3bd345 11-Jun-2013 Simon Glass <sjg@chromium.org>

bootstage: Correct printf types

The unstash code is a bit loose with its printf() types, which gives
warnings on sandbox. Correct this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fb7db41c 17-Apr-2013 Simon Glass <sjg@chromium.org>

bootstage: Allow marking a particular line of code

Add a function which allows a (file, function, line number) to be marked
in bootstage.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Che-Liang Chiou <clchiou@chromium.org>

# 150678a5 17-Apr-2013 Doug Anderson <dianders@chromium.org>

bootstage: Copy bootstage strings post-relocation

Any pointers to name strings that were passed to bootstage_mark_name()
pre-relocation should be copied post-relocation so that they don't get
trashed as the original location of U-Boot is re-used for other
purposes.

This change introduces a new API call that should be called from
board_init_r() after malloc has been initted on any board that uses
bootstage.

Signed-off-by: Doug Anderson <dianders@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# fcf509b8 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Add feature to stash/unstash bootstage info

It is useful to be able to write the bootstage information to memory for
use by a later utility, or the Linux kernel. Provide a function to do
this as well as a function to read bootstage information back and incorporate
it into the current table.

This also makes it possible for U-Boot to chain to another U-Boot and pass
on its bootstage information.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 94fd1316 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Store boot timings in device tree

Add an option, CONFIG_BOOTSTAGE_FDT to pass boot timings to the kernel
in the device tree, if available. To use this, you must have
CONFIG_OF_LIBFDT defined.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0e996773 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Add time accumulation feature

Sometimes we want to add up the amount of time spent in a particular
activity when it is happening in a number of discrete chunks.

Add bootstage_start() to mark the start of an acitivity and
bootstage_accum() to accumulate the time since the last start. Calling
these function in pairs results in the accumulated time being collected.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 094e06a5 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Export bootstage_add_record() function

This function is not static, but not exported either. Add a prototype
in the header file and move the required enum to the header also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3786980d 04-Apr-2012 Simon Glass <sjg@chromium.org>

Move bootstage timer out of lib/time.c

The standalone example does not have get_timer() defined, so we cannot
rely on it being available.

Move the timer function into boootstage.c to avoid this problem.

This corrects a build breakage for the standalone example on some boards.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Matthias Fuchs <matthias.fuchs@esd.eu>

# 3a608ca0 13-Feb-2012 Simon Glass <sjg@chromium.org>

bootstage: Implement core microsecond boot time measurement

This defines the basics of a new boot time measurement feature. This allows
logging of very accurate time measurements as the boot proceeds, by using
an available microsecond counter.

To enable the feature, define CONFIG_BOOTSTAGE in your board config file.
Also available is CONFIG_BOOTSTAGE_REPORT which will cause a report to be
printed just before handing off to the OS.

Most IDs are not named at this stage. For that I would first like to
renumber them all.

Timer summary in microseconds:
Mark Elapsed Stage
0 0 reset
205,000 205,000 board_init_f
6,053,000 5,848,000 bootm_start
6,053,000 0 id=1
6,058,000 5,000 id=101
6,058,000 0 id=100
6,061,000 3,000 id=103
6,064,000 3,000 id=104
6,093,000 29,000 id=107
6,093,000 0 id=106
6,093,000 0 id=105
6,093,000 0 id=108
7,089,000 996,000 id=7
7,089,000 0 id=15
7,089,000 0 id=8
7,097,000 8,000 start_kernel

Signed-off-by: Simon Glass <sjg@chromium.org>

# 939b04e9 03-Feb-2021 Simon Glass <sjg@chromium.org>

bootstage: Fix dependency for BOOTSTAGE_RECORD_COUNT

At present these three Kconfigs exist even when bootstage is not enabled.
This is not necessary since bootstage.c is only built if BOOTSTAGE is
enabled.

Make them conditional. Also fix up the overflow message to mention TPL.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 401d1c4f 30-Oct-2020 Simon Glass <sjg@chromium.org>

common: Drop asm/global_data.h from common header

Move this out of the common header and include it only where needed. In
a number of cases this requires adding "struct udevice;" to avoid adding
another large header or in other cases replacing / adding missing header
files that had been pulled in, very indirectly. Finally, we have a few
cases where we did not need to include <asm/global_data.h> at all, so
remove that include.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Tom Rini <trini@konsulko.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 52f24238 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop bootstage.h from common header

Move this fairly uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# db41d65a 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move hang() to the same header as panic()

At present panic() is in the vsprintf.h header file. That does not seem
like an obvious choice for hang(), even though it relates to panic(). So
let's put hang() in its own header.

Signed-off-by: Simon Glass <sjg@chromium.org>
[trini: Migrate a few more files]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 8bef79bf 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move sorting functions to their own header file

These don't need to be in common.h so move them out into a new header.
Also add some missing comments.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# ac9cd480 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Correct relocation algorithm

At present bootstage relocation assumes that it is possible to point back
to memory available before relocation, so it does not relocate the
strings. However this is not the case on some platforms, such as x86 which
uses the cache as RAM and loses access to this when the cache is enabled.

Move the relocation step to before U-Boot relocates, expand the allocated
region to include space for the strings and relocate the strings at the
same time as the bootstage records.

This ensures that bootstage data can remain accessible from TPL through
SPL to U-Boot before/after relocation.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 65b2d96f 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Avoid conflicts between stash/unstash

At present there is a single shared address for bootstage data in both
TPL and SPL. If SPL unstashs TPL bootstage info and then stashes it again
to pass it to U-Boot, the new stash overwrites the strings of the old
stash.

Fix this by duplicating the strings into the malloc() region. This should
be a small code. Fix the header-file order at the same time.

This problem doesn't happen at the next stage (SPL->U-Boot) since U-Boot
relocates the boostage data.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ed54bdaf 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Fix counting of entries in stash

The current code searches for empty records but these not existing with
bootstage now. This used to be needed when bootstage records were stored
in a spare array.

Drop the unnecessary code and fix a code-style nit at the same time.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 53a4f253 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Store the next ID in the stash

When stashing bootstage info, store the next ID so that it can be used
when the stash is restored. This avoids the ID starting at zero and
potentially overwriting existing entries.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 17357725 08-Apr-2019 Simon Glass <sjg@chromium.org>

bootstage: Allow calling bootstage_mark() before bootstage_init()

It is possible for this to happen if something goes wrong very early in
the init sequence. Add a check for this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# b08c8c48 04-Mar-2018 Masahiro Yamada <yamada.masahiro@socionext.com>

libfdt: move headers to <linux/libfdt.h> and <linux/libfdt_env.h>

Thomas reported U-Boot failed to build host tools if libfdt-devel
package is installed because tools include libfdt headers from
/usr/include/ instead of using internal ones.

This commit moves the header code:
include/libfdt.h -> include/linux/libfdt.h
include/libfdt_env.h -> include/linux/libfdt_env.h

and replaces include directives:
#include <libfdt.h> -> #include <linux/libfdt.h>
#include <libfdt_env.h> -> #include <linux/libfdt_env.h>

Reported-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# d69bb0ec 05-Sep-2017 Simon Glass <sjg@chromium.org>

bootstage: Provide a separate record count setting for SPL

With SPL we often have limited memory and do not need very many bootstage
records. Add a separate Kconfig option for SPL.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 066b25b6 05-Sep-2017 Simon Glass <sjg@chromium.org>

bootstage: Drop unused options

The CONFIG_BOOTSTAGE_USER_COUNT option is no-longer needed since we can now
support any number of user IDs. Also BOOTSTAGE_ID_COUNT is not needed now.

Drop these unused options.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 9d2542d0 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Adjust to use const * where possible

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 <sjg@chromium.org>

# e003310a 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Tidy up error return values

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 <sjg@chromium.org>

# 25e7dc6a 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Support relocating boostage data

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 <sjg@chromium.org>

# ff00226e 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Use debug() for stashing messages

We don't normally want to see these messages. Change them to debug-only.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c91001f6 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Show records with a zero time

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 <sjg@chromium.org>

# 03ecac31 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Use rec_count as the array index

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.

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 <sjg@chromium.org>

# cbcd6970 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Fix up code style and comments

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 <sjg@chromium.org>

# b383d6c0 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Convert to use malloc()

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
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.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c87dc38d 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Require timer_get_boot_us() to be defined

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.c for boards
which use CONFIG_SYS_TIMER_COUNTER.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# b8bcaa3a 11-Jun-2013 Simon Glass <sjg@chromium.org>

Add function to print a number with grouped digits

Move bootstage's numbering printing code into a generic place so that it can
be used by tracing also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5d3bd345 11-Jun-2013 Simon Glass <sjg@chromium.org>

bootstage: Correct printf types

The unstash code is a bit loose with its printf() types, which gives
warnings on sandbox. Correct this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fb7db41c 17-Apr-2013 Simon Glass <sjg@chromium.org>

bootstage: Allow marking a particular line of code

Add a function which allows a (file, function, line number) to be marked
in bootstage.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Che-Liang Chiou <clchiou@chromium.org>

# 150678a5 17-Apr-2013 Doug Anderson <dianders@chromium.org>

bootstage: Copy bootstage strings post-relocation

Any pointers to name strings that were passed to bootstage_mark_name()
pre-relocation should be copied post-relocation so that they don't get
trashed as the original location of U-Boot is re-used for other
purposes.

This change introduces a new API call that should be called from
board_init_r() after malloc has been initted on any board that uses
bootstage.

Signed-off-by: Doug Anderson <dianders@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# fcf509b8 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Add feature to stash/unstash bootstage info

It is useful to be able to write the bootstage information to memory for
use by a later utility, or the Linux kernel. Provide a function to do
this as well as a function to read bootstage information back and incorporate
it into the current table.

This also makes it possible for U-Boot to chain to another U-Boot and pass
on its bootstage information.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 94fd1316 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Store boot timings in device tree

Add an option, CONFIG_BOOTSTAGE_FDT to pass boot timings to the kernel
in the device tree, if available. To use this, you must have
CONFIG_OF_LIBFDT defined.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0e996773 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Add time accumulation feature

Sometimes we want to add up the amount of time spent in a particular
activity when it is happening in a number of discrete chunks.

Add bootstage_start() to mark the start of an acitivity and
bootstage_accum() to accumulate the time since the last start. Calling
these function in pairs results in the accumulated time being collected.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 094e06a5 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Export bootstage_add_record() function

This function is not static, but not exported either. Add a prototype
in the header file and move the required enum to the header also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3786980d 04-Apr-2012 Simon Glass <sjg@chromium.org>

Move bootstage timer out of lib/time.c

The standalone example does not have get_timer() defined, so we cannot
rely on it being available.

Move the timer function into boootstage.c to avoid this problem.

This corrects a build breakage for the standalone example on some boards.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Matthias Fuchs <matthias.fuchs@esd.eu>

# 3a608ca0 13-Feb-2012 Simon Glass <sjg@chromium.org>

bootstage: Implement core microsecond boot time measurement

This defines the basics of a new boot time measurement feature. This allows
logging of very accurate time measurements as the boot proceeds, by using
an available microsecond counter.

To enable the feature, define CONFIG_BOOTSTAGE in your board config file.
Also available is CONFIG_BOOTSTAGE_REPORT which will cause a report to be
printed just before handing off to the OS.

Most IDs are not named at this stage. For that I would first like to
renumber them all.

Timer summary in microseconds:
Mark Elapsed Stage
0 0 reset
205,000 205,000 board_init_f
6,053,000 5,848,000 bootm_start
6,053,000 0 id=1
6,058,000 5,000 id=101
6,058,000 0 id=100
6,061,000 3,000 id=103
6,064,000 3,000 id=104
6,093,000 29,000 id=107
6,093,000 0 id=106
6,093,000 0 id=105
6,093,000 0 id=108
7,089,000 996,000 id=7
7,089,000 0 id=15
7,089,000 0 id=8
7,097,000 8,000 start_kernel

Signed-off-by: Simon Glass <sjg@chromium.org>

# 401d1c4f 30-Oct-2020 Simon Glass <sjg@chromium.org>

common: Drop asm/global_data.h from common header

Move this out of the common header and include it only where needed. In
a number of cases this requires adding "struct udevice;" to avoid adding
another large header or in other cases replacing / adding missing header
files that had been pulled in, very indirectly. Finally, we have a few
cases where we did not need to include <asm/global_data.h> at all, so
remove that include.

Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Tom Rini <trini@konsulko.com>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 52f24238 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop bootstage.h from common header

Move this fairly uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# db41d65a 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move hang() to the same header as panic()

At present panic() is in the vsprintf.h header file. That does not seem
like an obvious choice for hang(), even though it relates to panic(). So
let's put hang() in its own header.

Signed-off-by: Simon Glass <sjg@chromium.org>
[trini: Migrate a few more files]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 8bef79bf 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move sorting functions to their own header file

These don't need to be in common.h so move them out into a new header.
Also add some missing comments.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# ac9cd480 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Correct relocation algorithm

At present bootstage relocation assumes that it is possible to point back
to memory available before relocation, so it does not relocate the
strings. However this is not the case on some platforms, such as x86 which
uses the cache as RAM and loses access to this when the cache is enabled.

Move the relocation step to before U-Boot relocates, expand the allocated
region to include space for the strings and relocate the strings at the
same time as the bootstage records.

This ensures that bootstage data can remain accessible from TPL through
SPL to U-Boot before/after relocation.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 65b2d96f 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Avoid conflicts between stash/unstash

At present there is a single shared address for bootstage data in both
TPL and SPL. If SPL unstashs TPL bootstage info and then stashes it again
to pass it to U-Boot, the new stash overwrites the strings of the old
stash.

Fix this by duplicating the strings into the malloc() region. This should
be a small code. Fix the header-file order at the same time.

This problem doesn't happen at the next stage (SPL->U-Boot) since U-Boot
relocates the boostage data.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ed54bdaf 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Fix counting of entries in stash

The current code searches for empty records but these not existing with
bootstage now. This used to be needed when bootstage records were stored
in a spare array.

Drop the unnecessary code and fix a code-style nit at the same time.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 53a4f253 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Store the next ID in the stash

When stashing bootstage info, store the next ID so that it can be used
when the stash is restored. This avoids the ID starting at zero and
potentially overwriting existing entries.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 17357725 08-Apr-2019 Simon Glass <sjg@chromium.org>

bootstage: Allow calling bootstage_mark() before bootstage_init()

It is possible for this to happen if something goes wrong very early in
the init sequence. Add a check for this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# b08c8c48 04-Mar-2018 Masahiro Yamada <yamada.masahiro@socionext.com>

libfdt: move headers to <linux/libfdt.h> and <linux/libfdt_env.h>

Thomas reported U-Boot failed to build host tools if libfdt-devel
package is installed because tools include libfdt headers from
/usr/include/ instead of using internal ones.

This commit moves the header code:
include/libfdt.h -> include/linux/libfdt.h
include/libfdt_env.h -> include/linux/libfdt_env.h

and replaces include directives:
#include <libfdt.h> -> #include <linux/libfdt.h>
#include <libfdt_env.h> -> #include <linux/libfdt_env.h>

Reported-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# d69bb0ec 05-Sep-2017 Simon Glass <sjg@chromium.org>

bootstage: Provide a separate record count setting for SPL

With SPL we often have limited memory and do not need very many bootstage
records. Add a separate Kconfig option for SPL.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 066b25b6 05-Sep-2017 Simon Glass <sjg@chromium.org>

bootstage: Drop unused options

The CONFIG_BOOTSTAGE_USER_COUNT option is no-longer needed since we can now
support any number of user IDs. Also BOOTSTAGE_ID_COUNT is not needed now.

Drop these unused options.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 9d2542d0 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Adjust to use const * where possible

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 <sjg@chromium.org>

# e003310a 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Tidy up error return values

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 <sjg@chromium.org>

# 25e7dc6a 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Support relocating boostage data

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 <sjg@chromium.org>

# ff00226e 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Use debug() for stashing messages

We don't normally want to see these messages. Change them to debug-only.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c91001f6 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Show records with a zero time

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 <sjg@chromium.org>

# 03ecac31 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Use rec_count as the array index

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.

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 <sjg@chromium.org>

# cbcd6970 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Fix up code style and comments

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 <sjg@chromium.org>

# b383d6c0 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Convert to use malloc()

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
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.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c87dc38d 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Require timer_get_boot_us() to be defined

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.c for boards
which use CONFIG_SYS_TIMER_COUNTER.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# b8bcaa3a 11-Jun-2013 Simon Glass <sjg@chromium.org>

Add function to print a number with grouped digits

Move bootstage's numbering printing code into a generic place so that it can
be used by tracing also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5d3bd345 11-Jun-2013 Simon Glass <sjg@chromium.org>

bootstage: Correct printf types

The unstash code is a bit loose with its printf() types, which gives
warnings on sandbox. Correct this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fb7db41c 17-Apr-2013 Simon Glass <sjg@chromium.org>

bootstage: Allow marking a particular line of code

Add a function which allows a (file, function, line number) to be marked
in bootstage.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Che-Liang Chiou <clchiou@chromium.org>

# 150678a5 17-Apr-2013 Doug Anderson <dianders@chromium.org>

bootstage: Copy bootstage strings post-relocation

Any pointers to name strings that were passed to bootstage_mark_name()
pre-relocation should be copied post-relocation so that they don't get
trashed as the original location of U-Boot is re-used for other
purposes.

This change introduces a new API call that should be called from
board_init_r() after malloc has been initted on any board that uses
bootstage.

Signed-off-by: Doug Anderson <dianders@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# fcf509b8 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Add feature to stash/unstash bootstage info

It is useful to be able to write the bootstage information to memory for
use by a later utility, or the Linux kernel. Provide a function to do
this as well as a function to read bootstage information back and incorporate
it into the current table.

This also makes it possible for U-Boot to chain to another U-Boot and pass
on its bootstage information.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 94fd1316 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Store boot timings in device tree

Add an option, CONFIG_BOOTSTAGE_FDT to pass boot timings to the kernel
in the device tree, if available. To use this, you must have
CONFIG_OF_LIBFDT defined.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0e996773 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Add time accumulation feature

Sometimes we want to add up the amount of time spent in a particular
activity when it is happening in a number of discrete chunks.

Add bootstage_start() to mark the start of an acitivity and
bootstage_accum() to accumulate the time since the last start. Calling
these function in pairs results in the accumulated time being collected.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 094e06a5 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Export bootstage_add_record() function

This function is not static, but not exported either. Add a prototype
in the header file and move the required enum to the header also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3786980d 04-Apr-2012 Simon Glass <sjg@chromium.org>

Move bootstage timer out of lib/time.c

The standalone example does not have get_timer() defined, so we cannot
rely on it being available.

Move the timer function into boootstage.c to avoid this problem.

This corrects a build breakage for the standalone example on some boards.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Matthias Fuchs <matthias.fuchs@esd.eu>

# 3a608ca0 13-Feb-2012 Simon Glass <sjg@chromium.org>

bootstage: Implement core microsecond boot time measurement

This defines the basics of a new boot time measurement feature. This allows
logging of very accurate time measurements as the boot proceeds, by using
an available microsecond counter.

To enable the feature, define CONFIG_BOOTSTAGE in your board config file.
Also available is CONFIG_BOOTSTAGE_REPORT which will cause a report to be
printed just before handing off to the OS.

Most IDs are not named at this stage. For that I would first like to
renumber them all.

Timer summary in microseconds:
Mark Elapsed Stage
0 0 reset
205,000 205,000 board_init_f
6,053,000 5,848,000 bootm_start
6,053,000 0 id=1
6,058,000 5,000 id=101
6,058,000 0 id=100
6,061,000 3,000 id=103
6,064,000 3,000 id=104
6,093,000 29,000 id=107
6,093,000 0 id=106
6,093,000 0 id=105
6,093,000 0 id=108
7,089,000 996,000 id=7
7,089,000 0 id=15
7,089,000 0 id=8
7,097,000 8,000 start_kernel

Signed-off-by: Simon Glass <sjg@chromium.org>

# f7ae49fc 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop log.h from common header

Move this header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 52f24238 10-May-2020 Simon Glass <sjg@chromium.org>

common: Drop bootstage.h from common header

Move this fairly uncommon header out of the common header.

Signed-off-by: Simon Glass <sjg@chromium.org>

# db41d65a 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move hang() to the same header as panic()

At present panic() is in the vsprintf.h header file. That does not seem
like an obvious choice for hang(), even though it relates to panic(). So
let's put hang() in its own header.

Signed-off-by: Simon Glass <sjg@chromium.org>
[trini: Migrate a few more files]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 8bef79bf 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move sorting functions to their own header file

These don't need to be in common.h so move them out into a new header.
Also add some missing comments.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# ac9cd480 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Correct relocation algorithm

At present bootstage relocation assumes that it is possible to point back
to memory available before relocation, so it does not relocate the
strings. However this is not the case on some platforms, such as x86 which
uses the cache as RAM and loses access to this when the cache is enabled.

Move the relocation step to before U-Boot relocates, expand the allocated
region to include space for the strings and relocate the strings at the
same time as the bootstage records.

This ensures that bootstage data can remain accessible from TPL through
SPL to U-Boot before/after relocation.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 65b2d96f 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Avoid conflicts between stash/unstash

At present there is a single shared address for bootstage data in both
TPL and SPL. If SPL unstashs TPL bootstage info and then stashes it again
to pass it to U-Boot, the new stash overwrites the strings of the old
stash.

Fix this by duplicating the strings into the malloc() region. This should
be a small code. Fix the header-file order at the same time.

This problem doesn't happen at the next stage (SPL->U-Boot) since U-Boot
relocates the boostage data.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ed54bdaf 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Fix counting of entries in stash

The current code searches for empty records but these not existing with
bootstage now. This used to be needed when bootstage records were stored
in a spare array.

Drop the unnecessary code and fix a code-style nit at the same time.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 53a4f253 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Store the next ID in the stash

When stashing bootstage info, store the next ID so that it can be used
when the stash is restored. This avoids the ID starting at zero and
potentially overwriting existing entries.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 17357725 08-Apr-2019 Simon Glass <sjg@chromium.org>

bootstage: Allow calling bootstage_mark() before bootstage_init()

It is possible for this to happen if something goes wrong very early in
the init sequence. Add a check for this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# b08c8c48 04-Mar-2018 Masahiro Yamada <yamada.masahiro@socionext.com>

libfdt: move headers to <linux/libfdt.h> and <linux/libfdt_env.h>

Thomas reported U-Boot failed to build host tools if libfdt-devel
package is installed because tools include libfdt headers from
/usr/include/ instead of using internal ones.

This commit moves the header code:
include/libfdt.h -> include/linux/libfdt.h
include/libfdt_env.h -> include/linux/libfdt_env.h

and replaces include directives:
#include <libfdt.h> -> #include <linux/libfdt.h>
#include <libfdt_env.h> -> #include <linux/libfdt_env.h>

Reported-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# d69bb0ec 05-Sep-2017 Simon Glass <sjg@chromium.org>

bootstage: Provide a separate record count setting for SPL

With SPL we often have limited memory and do not need very many bootstage
records. Add a separate Kconfig option for SPL.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 066b25b6 05-Sep-2017 Simon Glass <sjg@chromium.org>

bootstage: Drop unused options

The CONFIG_BOOTSTAGE_USER_COUNT option is no-longer needed since we can now
support any number of user IDs. Also BOOTSTAGE_ID_COUNT is not needed now.

Drop these unused options.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 9d2542d0 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Adjust to use const * where possible

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 <sjg@chromium.org>

# e003310a 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Tidy up error return values

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 <sjg@chromium.org>

# 25e7dc6a 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Support relocating boostage data

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 <sjg@chromium.org>

# ff00226e 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Use debug() for stashing messages

We don't normally want to see these messages. Change them to debug-only.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c91001f6 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Show records with a zero time

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 <sjg@chromium.org>

# 03ecac31 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Use rec_count as the array index

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.

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 <sjg@chromium.org>

# cbcd6970 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Fix up code style and comments

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 <sjg@chromium.org>

# b383d6c0 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Convert to use malloc()

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
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.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c87dc38d 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Require timer_get_boot_us() to be defined

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.c for boards
which use CONFIG_SYS_TIMER_COUNTER.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# b8bcaa3a 11-Jun-2013 Simon Glass <sjg@chromium.org>

Add function to print a number with grouped digits

Move bootstage's numbering printing code into a generic place so that it can
be used by tracing also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5d3bd345 11-Jun-2013 Simon Glass <sjg@chromium.org>

bootstage: Correct printf types

The unstash code is a bit loose with its printf() types, which gives
warnings on sandbox. Correct this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fb7db41c 17-Apr-2013 Simon Glass <sjg@chromium.org>

bootstage: Allow marking a particular line of code

Add a function which allows a (file, function, line number) to be marked
in bootstage.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Che-Liang Chiou <clchiou@chromium.org>

# 150678a5 17-Apr-2013 Doug Anderson <dianders@chromium.org>

bootstage: Copy bootstage strings post-relocation

Any pointers to name strings that were passed to bootstage_mark_name()
pre-relocation should be copied post-relocation so that they don't get
trashed as the original location of U-Boot is re-used for other
purposes.

This change introduces a new API call that should be called from
board_init_r() after malloc has been initted on any board that uses
bootstage.

Signed-off-by: Doug Anderson <dianders@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# fcf509b8 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Add feature to stash/unstash bootstage info

It is useful to be able to write the bootstage information to memory for
use by a later utility, or the Linux kernel. Provide a function to do
this as well as a function to read bootstage information back and incorporate
it into the current table.

This also makes it possible for U-Boot to chain to another U-Boot and pass
on its bootstage information.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 94fd1316 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Store boot timings in device tree

Add an option, CONFIG_BOOTSTAGE_FDT to pass boot timings to the kernel
in the device tree, if available. To use this, you must have
CONFIG_OF_LIBFDT defined.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0e996773 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Add time accumulation feature

Sometimes we want to add up the amount of time spent in a particular
activity when it is happening in a number of discrete chunks.

Add bootstage_start() to mark the start of an acitivity and
bootstage_accum() to accumulate the time since the last start. Calling
these function in pairs results in the accumulated time being collected.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 094e06a5 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Export bootstage_add_record() function

This function is not static, but not exported either. Add a prototype
in the header file and move the required enum to the header also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3786980d 04-Apr-2012 Simon Glass <sjg@chromium.org>

Move bootstage timer out of lib/time.c

The standalone example does not have get_timer() defined, so we cannot
rely on it being available.

Move the timer function into boootstage.c to avoid this problem.

This corrects a build breakage for the standalone example on some boards.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Matthias Fuchs <matthias.fuchs@esd.eu>

# 3a608ca0 13-Feb-2012 Simon Glass <sjg@chromium.org>

bootstage: Implement core microsecond boot time measurement

This defines the basics of a new boot time measurement feature. This allows
logging of very accurate time measurements as the boot proceeds, by using
an available microsecond counter.

To enable the feature, define CONFIG_BOOTSTAGE in your board config file.
Also available is CONFIG_BOOTSTAGE_REPORT which will cause a report to be
printed just before handing off to the OS.

Most IDs are not named at this stage. For that I would first like to
renumber them all.

Timer summary in microseconds:
Mark Elapsed Stage
0 0 reset
205,000 205,000 board_init_f
6,053,000 5,848,000 bootm_start
6,053,000 0 id=1
6,058,000 5,000 id=101
6,058,000 0 id=100
6,061,000 3,000 id=103
6,064,000 3,000 id=104
6,093,000 29,000 id=107
6,093,000 0 id=106
6,093,000 0 id=105
6,093,000 0 id=108
7,089,000 996,000 id=7
7,089,000 0 id=15
7,089,000 0 id=8
7,097,000 8,000 start_kernel

Signed-off-by: Simon Glass <sjg@chromium.org>

# db41d65a 28-Dec-2019 Simon Glass <sjg@chromium.org>

common: Move hang() to the same header as panic()

At present panic() is in the vsprintf.h header file. That does not seem
like an obvious choice for hang(), even though it relates to panic(). So
let's put hang() in its own header.

Signed-off-by: Simon Glass <sjg@chromium.org>
[trini: Migrate a few more files]
Signed-off-by: Tom Rini <trini@konsulko.com>

# 8bef79bf 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move sorting functions to their own header file

These don't need to be in common.h so move them out into a new header.
Also add some missing comments.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# ac9cd480 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Correct relocation algorithm

At present bootstage relocation assumes that it is possible to point back
to memory available before relocation, so it does not relocate the
strings. However this is not the case on some platforms, such as x86 which
uses the cache as RAM and loses access to this when the cache is enabled.

Move the relocation step to before U-Boot relocates, expand the allocated
region to include space for the strings and relocate the strings at the
same time as the bootstage records.

This ensures that bootstage data can remain accessible from TPL through
SPL to U-Boot before/after relocation.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 65b2d96f 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Avoid conflicts between stash/unstash

At present there is a single shared address for bootstage data in both
TPL and SPL. If SPL unstashs TPL bootstage info and then stashes it again
to pass it to U-Boot, the new stash overwrites the strings of the old
stash.

Fix this by duplicating the strings into the malloc() region. This should
be a small code. Fix the header-file order at the same time.

This problem doesn't happen at the next stage (SPL->U-Boot) since U-Boot
relocates the boostage data.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ed54bdaf 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Fix counting of entries in stash

The current code searches for empty records but these not existing with
bootstage now. This used to be needed when bootstage records were stored
in a spare array.

Drop the unnecessary code and fix a code-style nit at the same time.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 53a4f253 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Store the next ID in the stash

When stashing bootstage info, store the next ID so that it can be used
when the stash is restored. This avoids the ID starting at zero and
potentially overwriting existing entries.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 17357725 08-Apr-2019 Simon Glass <sjg@chromium.org>

bootstage: Allow calling bootstage_mark() before bootstage_init()

It is possible for this to happen if something goes wrong very early in
the init sequence. Add a check for this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# b08c8c48 04-Mar-2018 Masahiro Yamada <yamada.masahiro@socionext.com>

libfdt: move headers to <linux/libfdt.h> and <linux/libfdt_env.h>

Thomas reported U-Boot failed to build host tools if libfdt-devel
package is installed because tools include libfdt headers from
/usr/include/ instead of using internal ones.

This commit moves the header code:
include/libfdt.h -> include/linux/libfdt.h
include/libfdt_env.h -> include/linux/libfdt_env.h

and replaces include directives:
#include <libfdt.h> -> #include <linux/libfdt.h>
#include <libfdt_env.h> -> #include <linux/libfdt_env.h>

Reported-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# d69bb0ec 05-Sep-2017 Simon Glass <sjg@chromium.org>

bootstage: Provide a separate record count setting for SPL

With SPL we often have limited memory and do not need very many bootstage
records. Add a separate Kconfig option for SPL.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 066b25b6 05-Sep-2017 Simon Glass <sjg@chromium.org>

bootstage: Drop unused options

The CONFIG_BOOTSTAGE_USER_COUNT option is no-longer needed since we can now
support any number of user IDs. Also BOOTSTAGE_ID_COUNT is not needed now.

Drop these unused options.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 9d2542d0 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Adjust to use const * where possible

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 <sjg@chromium.org>

# e003310a 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Tidy up error return values

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 <sjg@chromium.org>

# 25e7dc6a 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Support relocating boostage data

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 <sjg@chromium.org>

# ff00226e 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Use debug() for stashing messages

We don't normally want to see these messages. Change them to debug-only.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c91001f6 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Show records with a zero time

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 <sjg@chromium.org>

# 03ecac31 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Use rec_count as the array index

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.

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 <sjg@chromium.org>

# cbcd6970 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Fix up code style and comments

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 <sjg@chromium.org>

# b383d6c0 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Convert to use malloc()

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
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.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c87dc38d 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Require timer_get_boot_us() to be defined

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.c for boards
which use CONFIG_SYS_TIMER_COUNTER.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# b8bcaa3a 11-Jun-2013 Simon Glass <sjg@chromium.org>

Add function to print a number with grouped digits

Move bootstage's numbering printing code into a generic place so that it can
be used by tracing also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5d3bd345 11-Jun-2013 Simon Glass <sjg@chromium.org>

bootstage: Correct printf types

The unstash code is a bit loose with its printf() types, which gives
warnings on sandbox. Correct this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fb7db41c 17-Apr-2013 Simon Glass <sjg@chromium.org>

bootstage: Allow marking a particular line of code

Add a function which allows a (file, function, line number) to be marked
in bootstage.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Che-Liang Chiou <clchiou@chromium.org>

# 150678a5 17-Apr-2013 Doug Anderson <dianders@chromium.org>

bootstage: Copy bootstage strings post-relocation

Any pointers to name strings that were passed to bootstage_mark_name()
pre-relocation should be copied post-relocation so that they don't get
trashed as the original location of U-Boot is re-used for other
purposes.

This change introduces a new API call that should be called from
board_init_r() after malloc has been initted on any board that uses
bootstage.

Signed-off-by: Doug Anderson <dianders@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# fcf509b8 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Add feature to stash/unstash bootstage info

It is useful to be able to write the bootstage information to memory for
use by a later utility, or the Linux kernel. Provide a function to do
this as well as a function to read bootstage information back and incorporate
it into the current table.

This also makes it possible for U-Boot to chain to another U-Boot and pass
on its bootstage information.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 94fd1316 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Store boot timings in device tree

Add an option, CONFIG_BOOTSTAGE_FDT to pass boot timings to the kernel
in the device tree, if available. To use this, you must have
CONFIG_OF_LIBFDT defined.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0e996773 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Add time accumulation feature

Sometimes we want to add up the amount of time spent in a particular
activity when it is happening in a number of discrete chunks.

Add bootstage_start() to mark the start of an acitivity and
bootstage_accum() to accumulate the time since the last start. Calling
these function in pairs results in the accumulated time being collected.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 094e06a5 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Export bootstage_add_record() function

This function is not static, but not exported either. Add a prototype
in the header file and move the required enum to the header also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3786980d 04-Apr-2012 Simon Glass <sjg@chromium.org>

Move bootstage timer out of lib/time.c

The standalone example does not have get_timer() defined, so we cannot
rely on it being available.

Move the timer function into boootstage.c to avoid this problem.

This corrects a build breakage for the standalone example on some boards.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Matthias Fuchs <matthias.fuchs@esd.eu>

# 3a608ca0 13-Feb-2012 Simon Glass <sjg@chromium.org>

bootstage: Implement core microsecond boot time measurement

This defines the basics of a new boot time measurement feature. This allows
logging of very accurate time measurements as the boot proceeds, by using
an available microsecond counter.

To enable the feature, define CONFIG_BOOTSTAGE in your board config file.
Also available is CONFIG_BOOTSTAGE_REPORT which will cause a report to be
printed just before handing off to the OS.

Most IDs are not named at this stage. For that I would first like to
renumber them all.

Timer summary in microseconds:
Mark Elapsed Stage
0 0 reset
205,000 205,000 board_init_f
6,053,000 5,848,000 bootm_start
6,053,000 0 id=1
6,058,000 5,000 id=101
6,058,000 0 id=100
6,061,000 3,000 id=103
6,064,000 3,000 id=104
6,093,000 29,000 id=107
6,093,000 0 id=106
6,093,000 0 id=105
6,093,000 0 id=108
7,089,000 996,000 id=7
7,089,000 0 id=15
7,089,000 0 id=8
7,097,000 8,000 start_kernel

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8bef79bf 14-Nov-2019 Simon Glass <sjg@chromium.org>

common: Move sorting functions to their own header file

These don't need to be in common.h so move them out into a new header.
Also add some missing comments.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

# ac9cd480 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Correct relocation algorithm

At present bootstage relocation assumes that it is possible to point back
to memory available before relocation, so it does not relocate the
strings. However this is not the case on some platforms, such as x86 which
uses the cache as RAM and loses access to this when the cache is enabled.

Move the relocation step to before U-Boot relocates, expand the allocated
region to include space for the strings and relocate the strings at the
same time as the bootstage records.

This ensures that bootstage data can remain accessible from TPL through
SPL to U-Boot before/after relocation.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 65b2d96f 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Avoid conflicts between stash/unstash

At present there is a single shared address for bootstage data in both
TPL and SPL. If SPL unstashs TPL bootstage info and then stashes it again
to pass it to U-Boot, the new stash overwrites the strings of the old
stash.

Fix this by duplicating the strings into the malloc() region. This should
be a small code. Fix the header-file order at the same time.

This problem doesn't happen at the next stage (SPL->U-Boot) since U-Boot
relocates the boostage data.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ed54bdaf 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Fix counting of entries in stash

The current code searches for empty records but these not existing with
bootstage now. This used to be needed when bootstage records were stored
in a spare array.

Drop the unnecessary code and fix a code-style nit at the same time.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 53a4f253 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Store the next ID in the stash

When stashing bootstage info, store the next ID so that it can be used
when the stash is restored. This avoids the ID starting at zero and
potentially overwriting existing entries.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 17357725 08-Apr-2019 Simon Glass <sjg@chromium.org>

bootstage: Allow calling bootstage_mark() before bootstage_init()

It is possible for this to happen if something goes wrong very early in
the init sequence. Add a check for this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# b08c8c48 04-Mar-2018 Masahiro Yamada <yamada.masahiro@socionext.com>

libfdt: move headers to <linux/libfdt.h> and <linux/libfdt_env.h>

Thomas reported U-Boot failed to build host tools if libfdt-devel
package is installed because tools include libfdt headers from
/usr/include/ instead of using internal ones.

This commit moves the header code:
include/libfdt.h -> include/linux/libfdt.h
include/libfdt_env.h -> include/linux/libfdt_env.h

and replaces include directives:
#include <libfdt.h> -> #include <linux/libfdt.h>
#include <libfdt_env.h> -> #include <linux/libfdt_env.h>

Reported-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# d69bb0ec 05-Sep-2017 Simon Glass <sjg@chromium.org>

bootstage: Provide a separate record count setting for SPL

With SPL we often have limited memory and do not need very many bootstage
records. Add a separate Kconfig option for SPL.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 066b25b6 05-Sep-2017 Simon Glass <sjg@chromium.org>

bootstage: Drop unused options

The CONFIG_BOOTSTAGE_USER_COUNT option is no-longer needed since we can now
support any number of user IDs. Also BOOTSTAGE_ID_COUNT is not needed now.

Drop these unused options.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 9d2542d0 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Adjust to use const * where possible

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 <sjg@chromium.org>

# e003310a 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Tidy up error return values

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 <sjg@chromium.org>

# 25e7dc6a 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Support relocating boostage data

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 <sjg@chromium.org>

# ff00226e 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Use debug() for stashing messages

We don't normally want to see these messages. Change them to debug-only.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c91001f6 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Show records with a zero time

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 <sjg@chromium.org>

# 03ecac31 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Use rec_count as the array index

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.

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 <sjg@chromium.org>

# cbcd6970 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Fix up code style and comments

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 <sjg@chromium.org>

# b383d6c0 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Convert to use malloc()

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
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.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c87dc38d 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Require timer_get_boot_us() to be defined

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.c for boards
which use CONFIG_SYS_TIMER_COUNTER.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# b8bcaa3a 11-Jun-2013 Simon Glass <sjg@chromium.org>

Add function to print a number with grouped digits

Move bootstage's numbering printing code into a generic place so that it can
be used by tracing also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5d3bd345 11-Jun-2013 Simon Glass <sjg@chromium.org>

bootstage: Correct printf types

The unstash code is a bit loose with its printf() types, which gives
warnings on sandbox. Correct this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fb7db41c 17-Apr-2013 Simon Glass <sjg@chromium.org>

bootstage: Allow marking a particular line of code

Add a function which allows a (file, function, line number) to be marked
in bootstage.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Che-Liang Chiou <clchiou@chromium.org>

# 150678a5 17-Apr-2013 Doug Anderson <dianders@chromium.org>

bootstage: Copy bootstage strings post-relocation

Any pointers to name strings that were passed to bootstage_mark_name()
pre-relocation should be copied post-relocation so that they don't get
trashed as the original location of U-Boot is re-used for other
purposes.

This change introduces a new API call that should be called from
board_init_r() after malloc has been initted on any board that uses
bootstage.

Signed-off-by: Doug Anderson <dianders@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# fcf509b8 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Add feature to stash/unstash bootstage info

It is useful to be able to write the bootstage information to memory for
use by a later utility, or the Linux kernel. Provide a function to do
this as well as a function to read bootstage information back and incorporate
it into the current table.

This also makes it possible for U-Boot to chain to another U-Boot and pass
on its bootstage information.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 94fd1316 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Store boot timings in device tree

Add an option, CONFIG_BOOTSTAGE_FDT to pass boot timings to the kernel
in the device tree, if available. To use this, you must have
CONFIG_OF_LIBFDT defined.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0e996773 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Add time accumulation feature

Sometimes we want to add up the amount of time spent in a particular
activity when it is happening in a number of discrete chunks.

Add bootstage_start() to mark the start of an acitivity and
bootstage_accum() to accumulate the time since the last start. Calling
these function in pairs results in the accumulated time being collected.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 094e06a5 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Export bootstage_add_record() function

This function is not static, but not exported either. Add a prototype
in the header file and move the required enum to the header also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3786980d 04-Apr-2012 Simon Glass <sjg@chromium.org>

Move bootstage timer out of lib/time.c

The standalone example does not have get_timer() defined, so we cannot
rely on it being available.

Move the timer function into boootstage.c to avoid this problem.

This corrects a build breakage for the standalone example on some boards.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Matthias Fuchs <matthias.fuchs@esd.eu>

# 3a608ca0 13-Feb-2012 Simon Glass <sjg@chromium.org>

bootstage: Implement core microsecond boot time measurement

This defines the basics of a new boot time measurement feature. This allows
logging of very accurate time measurements as the boot proceeds, by using
an available microsecond counter.

To enable the feature, define CONFIG_BOOTSTAGE in your board config file.
Also available is CONFIG_BOOTSTAGE_REPORT which will cause a report to be
printed just before handing off to the OS.

Most IDs are not named at this stage. For that I would first like to
renumber them all.

Timer summary in microseconds:
Mark Elapsed Stage
0 0 reset
205,000 205,000 board_init_f
6,053,000 5,848,000 bootm_start
6,053,000 0 id=1
6,058,000 5,000 id=101
6,058,000 0 id=100
6,061,000 3,000 id=103
6,064,000 3,000 id=104
6,093,000 29,000 id=107
6,093,000 0 id=106
6,093,000 0 id=105
6,093,000 0 id=108
7,089,000 996,000 id=7
7,089,000 0 id=15
7,089,000 0 id=8
7,097,000 8,000 start_kernel

Signed-off-by: Simon Glass <sjg@chromium.org>

# ac9cd480 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Correct relocation algorithm

At present bootstage relocation assumes that it is possible to point back
to memory available before relocation, so it does not relocate the
strings. However this is not the case on some platforms, such as x86 which
uses the cache as RAM and loses access to this when the cache is enabled.

Move the relocation step to before U-Boot relocates, expand the allocated
region to include space for the strings and relocate the strings at the
same time as the bootstage records.

This ensures that bootstage data can remain accessible from TPL through
SPL to U-Boot before/after relocation.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 65b2d96f 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Avoid conflicts between stash/unstash

At present there is a single shared address for bootstage data in both
TPL and SPL. If SPL unstashs TPL bootstage info and then stashes it again
to pass it to U-Boot, the new stash overwrites the strings of the old
stash.

Fix this by duplicating the strings into the malloc() region. This should
be a small code. Fix the header-file order at the same time.

This problem doesn't happen at the next stage (SPL->U-Boot) since U-Boot
relocates the boostage data.

Signed-off-by: Simon Glass <sjg@chromium.org>

# ed54bdaf 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Fix counting of entries in stash

The current code searches for empty records but these not existing with
bootstage now. This used to be needed when bootstage records were stored
in a spare array.

Drop the unnecessary code and fix a code-style nit at the same time.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 53a4f253 21-Oct-2019 Simon Glass <sjg@chromium.org>

bootstage: Store the next ID in the stash

When stashing bootstage info, store the next ID so that it can be used
when the stash is restored. This avoids the ID starting at zero and
potentially overwriting existing entries.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 17357725 08-Apr-2019 Simon Glass <sjg@chromium.org>

bootstage: Allow calling bootstage_mark() before bootstage_init()

It is possible for this to happen if something goes wrong very early in
the init sequence. Add a check for this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# b08c8c48 04-Mar-2018 Masahiro Yamada <yamada.masahiro@socionext.com>

libfdt: move headers to <linux/libfdt.h> and <linux/libfdt_env.h>

Thomas reported U-Boot failed to build host tools if libfdt-devel
package is installed because tools include libfdt headers from
/usr/include/ instead of using internal ones.

This commit moves the header code:
include/libfdt.h -> include/linux/libfdt.h
include/libfdt_env.h -> include/linux/libfdt_env.h

and replaces include directives:
#include <libfdt.h> -> #include <linux/libfdt.h>
#include <libfdt_env.h> -> #include <linux/libfdt_env.h>

Reported-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# d69bb0ec 05-Sep-2017 Simon Glass <sjg@chromium.org>

bootstage: Provide a separate record count setting for SPL

With SPL we often have limited memory and do not need very many bootstage
records. Add a separate Kconfig option for SPL.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 066b25b6 05-Sep-2017 Simon Glass <sjg@chromium.org>

bootstage: Drop unused options

The CONFIG_BOOTSTAGE_USER_COUNT option is no-longer needed since we can now
support any number of user IDs. Also BOOTSTAGE_ID_COUNT is not needed now.

Drop these unused options.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 9d2542d0 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Adjust to use const * where possible

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 <sjg@chromium.org>

# e003310a 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Tidy up error return values

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 <sjg@chromium.org>

# 25e7dc6a 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Support relocating boostage data

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 <sjg@chromium.org>

# ff00226e 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Use debug() for stashing messages

We don't normally want to see these messages. Change them to debug-only.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c91001f6 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Show records with a zero time

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 <sjg@chromium.org>

# 03ecac31 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Use rec_count as the array index

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.

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 <sjg@chromium.org>

# cbcd6970 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Fix up code style and comments

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 <sjg@chromium.org>

# b383d6c0 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Convert to use malloc()

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
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.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c87dc38d 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Require timer_get_boot_us() to be defined

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.c for boards
which use CONFIG_SYS_TIMER_COUNTER.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# b8bcaa3a 11-Jun-2013 Simon Glass <sjg@chromium.org>

Add function to print a number with grouped digits

Move bootstage's numbering printing code into a generic place so that it can
be used by tracing also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5d3bd345 11-Jun-2013 Simon Glass <sjg@chromium.org>

bootstage: Correct printf types

The unstash code is a bit loose with its printf() types, which gives
warnings on sandbox. Correct this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fb7db41c 17-Apr-2013 Simon Glass <sjg@chromium.org>

bootstage: Allow marking a particular line of code

Add a function which allows a (file, function, line number) to be marked
in bootstage.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Che-Liang Chiou <clchiou@chromium.org>

# 150678a5 17-Apr-2013 Doug Anderson <dianders@chromium.org>

bootstage: Copy bootstage strings post-relocation

Any pointers to name strings that were passed to bootstage_mark_name()
pre-relocation should be copied post-relocation so that they don't get
trashed as the original location of U-Boot is re-used for other
purposes.

This change introduces a new API call that should be called from
board_init_r() after malloc has been initted on any board that uses
bootstage.

Signed-off-by: Doug Anderson <dianders@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# fcf509b8 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Add feature to stash/unstash bootstage info

It is useful to be able to write the bootstage information to memory for
use by a later utility, or the Linux kernel. Provide a function to do
this as well as a function to read bootstage information back and incorporate
it into the current table.

This also makes it possible for U-Boot to chain to another U-Boot and pass
on its bootstage information.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 94fd1316 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Store boot timings in device tree

Add an option, CONFIG_BOOTSTAGE_FDT to pass boot timings to the kernel
in the device tree, if available. To use this, you must have
CONFIG_OF_LIBFDT defined.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0e996773 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Add time accumulation feature

Sometimes we want to add up the amount of time spent in a particular
activity when it is happening in a number of discrete chunks.

Add bootstage_start() to mark the start of an acitivity and
bootstage_accum() to accumulate the time since the last start. Calling
these function in pairs results in the accumulated time being collected.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 094e06a5 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Export bootstage_add_record() function

This function is not static, but not exported either. Add a prototype
in the header file and move the required enum to the header also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3786980d 04-Apr-2012 Simon Glass <sjg@chromium.org>

Move bootstage timer out of lib/time.c

The standalone example does not have get_timer() defined, so we cannot
rely on it being available.

Move the timer function into boootstage.c to avoid this problem.

This corrects a build breakage for the standalone example on some boards.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Matthias Fuchs <matthias.fuchs@esd.eu>

# 3a608ca0 13-Feb-2012 Simon Glass <sjg@chromium.org>

bootstage: Implement core microsecond boot time measurement

This defines the basics of a new boot time measurement feature. This allows
logging of very accurate time measurements as the boot proceeds, by using
an available microsecond counter.

To enable the feature, define CONFIG_BOOTSTAGE in your board config file.
Also available is CONFIG_BOOTSTAGE_REPORT which will cause a report to be
printed just before handing off to the OS.

Most IDs are not named at this stage. For that I would first like to
renumber them all.

Timer summary in microseconds:
Mark Elapsed Stage
0 0 reset
205,000 205,000 board_init_f
6,053,000 5,848,000 bootm_start
6,053,000 0 id=1
6,058,000 5,000 id=101
6,058,000 0 id=100
6,061,000 3,000 id=103
6,064,000 3,000 id=104
6,093,000 29,000 id=107
6,093,000 0 id=106
6,093,000 0 id=105
6,093,000 0 id=108
7,089,000 996,000 id=7
7,089,000 0 id=15
7,089,000 0 id=8
7,097,000 8,000 start_kernel

Signed-off-by: Simon Glass <sjg@chromium.org>

# 17357725 08-Apr-2019 Simon Glass <sjg@chromium.org>

bootstage: Allow calling bootstage_mark() before bootstage_init()

It is possible for this to happen if something goes wrong very early in
the init sequence. Add a check for this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>

# b08c8c48 04-Mar-2018 Masahiro Yamada <yamada.masahiro@socionext.com>

libfdt: move headers to <linux/libfdt.h> and <linux/libfdt_env.h>

Thomas reported U-Boot failed to build host tools if libfdt-devel
package is installed because tools include libfdt headers from
/usr/include/ instead of using internal ones.

This commit moves the header code:
include/libfdt.h -> include/linux/libfdt.h
include/libfdt_env.h -> include/linux/libfdt_env.h

and replaces include directives:
#include <libfdt.h> -> #include <linux/libfdt.h>
#include <libfdt_env.h> -> #include <linux/libfdt_env.h>

Reported-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>

# d69bb0ec 05-Sep-2017 Simon Glass <sjg@chromium.org>

bootstage: Provide a separate record count setting for SPL

With SPL we often have limited memory and do not need very many bootstage
records. Add a separate Kconfig option for SPL.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 066b25b6 05-Sep-2017 Simon Glass <sjg@chromium.org>

bootstage: Drop unused options

The CONFIG_BOOTSTAGE_USER_COUNT option is no-longer needed since we can now
support any number of user IDs. Also BOOTSTAGE_ID_COUNT is not needed now.

Drop these unused options.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# 9d2542d0 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Adjust to use const * where possible

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 <sjg@chromium.org>

# e003310a 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Tidy up error return values

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 <sjg@chromium.org>

# 25e7dc6a 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Support relocating boostage data

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 <sjg@chromium.org>

# ff00226e 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Use debug() for stashing messages

We don't normally want to see these messages. Change them to debug-only.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c91001f6 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Show records with a zero time

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 <sjg@chromium.org>

# 03ecac31 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Use rec_count as the array index

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.

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 <sjg@chromium.org>

# cbcd6970 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Fix up code style and comments

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 <sjg@chromium.org>

# b383d6c0 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Convert to use malloc()

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
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.

Signed-off-by: Simon Glass <sjg@chromium.org>

# c87dc38d 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Require timer_get_boot_us() to be defined

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.c for boards
which use CONFIG_SYS_TIMER_COUNTER.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>

# b8bcaa3a 11-Jun-2013 Simon Glass <sjg@chromium.org>

Add function to print a number with grouped digits

Move bootstage's numbering printing code into a generic place so that it can
be used by tracing also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5d3bd345 11-Jun-2013 Simon Glass <sjg@chromium.org>

bootstage: Correct printf types

The unstash code is a bit loose with its printf() types, which gives
warnings on sandbox. Correct this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# fb7db41c 17-Apr-2013 Simon Glass <sjg@chromium.org>

bootstage: Allow marking a particular line of code

Add a function which allows a (file, function, line number) to be marked
in bootstage.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Che-Liang Chiou <clchiou@chromium.org>

# 150678a5 17-Apr-2013 Doug Anderson <dianders@chromium.org>

bootstage: Copy bootstage strings post-relocation

Any pointers to name strings that were passed to bootstage_mark_name()
pre-relocation should be copied post-relocation so that they don't get
trashed as the original location of U-Boot is re-used for other
purposes.

This change introduces a new API call that should be called from
board_init_r() after malloc has been initted on any board that uses
bootstage.

Signed-off-by: Doug Anderson <dianders@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>

# fcf509b8 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Add feature to stash/unstash bootstage info

It is useful to be able to write the bootstage information to memory for
use by a later utility, or the Linux kernel. Provide a function to do
this as well as a function to read bootstage information back and incorporate
it into the current table.

This also makes it possible for U-Boot to chain to another U-Boot and pass
on its bootstage information.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 94fd1316 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Store boot timings in device tree

Add an option, CONFIG_BOOTSTAGE_FDT to pass boot timings to the kernel
in the device tree, if available. To use this, you must have
CONFIG_OF_LIBFDT defined.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0e996773 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Add time accumulation feature

Sometimes we want to add up the amount of time spent in a particular
activity when it is happening in a number of discrete chunks.

Add bootstage_start() to mark the start of an acitivity and
bootstage_accum() to accumulate the time since the last start. Calling
these function in pairs results in the accumulated time being collected.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 094e06a5 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Export bootstage_add_record() function

This function is not static, but not exported either. Add a prototype
in the header file and move the required enum to the header also.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 3786980d 04-Apr-2012 Simon Glass <sjg@chromium.org>

Move bootstage timer out of lib/time.c

The standalone example does not have get_timer() defined, so we cannot
rely on it being available.

Move the timer function into boootstage.c to avoid this problem.

This corrects a build breakage for the standalone example on some boards.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Matthias Fuchs <matthias.fuchs@esd.eu>

# 3a608ca0 13-Feb-2012 Simon Glass <sjg@chromium.org>

bootstage: Implement core microsecond boot time measurement

This defines the basics of a new boot time measurement feature. This allows
logging of very accurate time measurements as the boot proceeds, by using
an available microsecond counter.

To enable the feature, define CONFIG_BOOTSTAGE in your board config file.
Also available is CONFIG_BOOTSTAGE_REPORT which will cause a report to be
printed just before handing off to the OS.

Most IDs are not named at this stage. For that I would first like to
renumber them all.

Timer summary in microseconds:
Mark Elapsed Stage
0 0 reset
205,000 205,000 board_init_f
6,053,000 5,848,000 bootm_start
6,053,000 0 id=1
6,058,000 5,000 id=101
6,058,000 0 id=100
6,061,000 3,000 id=103
6,064,000 3,000 id=104
6,093,000 29,000 id=107
6,093,000 0 id=106
6,093,000 0 id=105
6,093,000 0 id=108
7,089,000 996,000 id=7
7,089,000 0 id=15
7,089,000 0 id=8
7,097,000 8,000 start_kernel

Signed-off-by: Simon Glass <sjg@chromium.org>

# 83d290c5 06-May-2018 Tom Rini <trini@konsulko.com>

SPDX: Convert all of our single license tags to Linux Kernel style

When U-Boot started using SPDX tags we were among the early adopters and
there weren't a lot of other examples to borrow from. So we picked the
area of the file that usually had a full license text and replaced it
with an appropriate SPDX-License-Identifier: entry. Since then, the
Linux Kernel has adopted SPDX tags and they place it as the very first
line in a file (except where shebangs are used, then it's second line)
and with slightly different comment styles than us.

In part due to community overlap, in part due to better tag visibility
and in part for other minor reasons, switch over to that style.

This commit changes all instances where we have a single declared
license in the tag as both the before and after are identical in tag
contents. There's also a few places where I found we did not have a tag
and have introduced one.

Signed-off-by: Tom Rini <trini@konsulko.com>


# b08c8c48 04-Mar-2018 Masahiro Yamada <yamada.masahiro@socionext.com>

libfdt: move headers to <linux/libfdt.h> and <linux/libfdt_env.h>

Thomas reported U-Boot failed to build host tools if libfdt-devel
package is installed because tools include libfdt headers from
/usr/include/ instead of using internal ones.

This commit moves the header code:
include/libfdt.h -> include/linux/libfdt.h
include/libfdt_env.h -> include/linux/libfdt_env.h

and replaces include directives:
#include <libfdt.h> -> #include <linux/libfdt.h>
#include <libfdt_env.h> -> #include <linux/libfdt_env.h>

Reported-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>


# d69bb0ec 05-Sep-2017 Simon Glass <sjg@chromium.org>

bootstage: Provide a separate record count setting for SPL

With SPL we often have limited memory and do not need very many bootstage
records. Add a separate Kconfig option for SPL.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>


# 066b25b6 05-Sep-2017 Simon Glass <sjg@chromium.org>

bootstage: Drop unused options

The CONFIG_BOOTSTAGE_USER_COUNT option is no-longer needed since we can now
support any number of user IDs. Also BOOTSTAGE_ID_COUNT is not needed now.

Drop these unused options.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>


# 9d2542d0 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Adjust to use const * where possible

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 <sjg@chromium.org>


# e003310a 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Tidy up error return values

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 <sjg@chromium.org>


# 25e7dc6a 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Support relocating boostage data

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 <sjg@chromium.org>


# ff00226e 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Use debug() for stashing messages

We don't normally want to see these messages. Change them to debug-only.

Signed-off-by: Simon Glass <sjg@chromium.org>


# c91001f6 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Show records with a zero time

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 <sjg@chromium.org>


# 03ecac31 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Use rec_count as the array index

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.

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 <sjg@chromium.org>


# cbcd6970 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Fix up code style and comments

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 <sjg@chromium.org>


# b383d6c0 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Convert to use malloc()

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
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.

Signed-off-by: Simon Glass <sjg@chromium.org>


# c87dc38d 22-May-2017 Simon Glass <sjg@chromium.org>

bootstage: Require timer_get_boot_us() to be defined

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.c for boards
which use CONFIG_SYS_TIMER_COUNTER.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 1a459660 08-Jul-2013 Wolfgang Denk <wd@denx.de>

Add GPL-2.0+ SPDX-License-Identifier to source files

Signed-off-by: Wolfgang Denk <wd@denx.de>
[trini: Fixup common/cmd_io.c]
Signed-off-by: Tom Rini <trini@ti.com>


# b8bcaa3a 11-Jun-2013 Simon Glass <sjg@chromium.org>

Add function to print a number with grouped digits

Move bootstage's numbering printing code into a generic place so that it can
be used by tracing also.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 5d3bd345 11-Jun-2013 Simon Glass <sjg@chromium.org>

bootstage: Correct printf types

The unstash code is a bit loose with its printf() types, which gives
warnings on sandbox. Correct this.

Signed-off-by: Simon Glass <sjg@chromium.org>


# fb7db41c 17-Apr-2013 Simon Glass <sjg@chromium.org>

bootstage: Allow marking a particular line of code

Add a function which allows a (file, function, line number) to be marked
in bootstage.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Che-Liang Chiou <clchiou@chromium.org>


# 150678a5 17-Apr-2013 Doug Anderson <dianders@chromium.org>

bootstage: Copy bootstage strings post-relocation

Any pointers to name strings that were passed to bootstage_mark_name()
pre-relocation should be copied post-relocation so that they don't get
trashed as the original location of U-Boot is re-used for other
purposes.

This change introduces a new API call that should be called from
board_init_r() after malloc has been initted on any board that uses
bootstage.

Signed-off-by: Doug Anderson <dianders@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fcf509b8 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Add feature to stash/unstash bootstage info

It is useful to be able to write the bootstage information to memory for
use by a later utility, or the Linux kernel. Provide a function to do
this as well as a function to read bootstage information back and incorporate
it into the current table.

This also makes it possible for U-Boot to chain to another U-Boot and pass
on its bootstage information.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 94fd1316 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Store boot timings in device tree

Add an option, CONFIG_BOOTSTAGE_FDT to pass boot timings to the kernel
in the device tree, if available. To use this, you must have
CONFIG_OF_LIBFDT defined.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 0e996773 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Add time accumulation feature

Sometimes we want to add up the amount of time spent in a particular
activity when it is happening in a number of discrete chunks.

Add bootstage_start() to mark the start of an acitivity and
bootstage_accum() to accumulate the time since the last start. Calling
these function in pairs results in the accumulated time being collected.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 094e06a5 28-Sep-2012 Simon Glass <sjg@chromium.org>

bootstage: Export bootstage_add_record() function

This function is not static, but not exported either. Add a prototype
in the header file and move the required enum to the header also.

Signed-off-by: Simon Glass <sjg@chromium.org>


# 3786980d 04-Apr-2012 Simon Glass <sjg@chromium.org>

Move bootstage timer out of lib/time.c

The standalone example does not have get_timer() defined, so we cannot
rely on it being available.

Move the timer function into boootstage.c to avoid this problem.

This corrects a build breakage for the standalone example on some boards.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Matthias Fuchs <matthias.fuchs@esd.eu>


# 3a608ca0 13-Feb-2012 Simon Glass <sjg@chromium.org>

bootstage: Implement core microsecond boot time measurement

This defines the basics of a new boot time measurement feature. This allows
logging of very accurate time measurements as the boot proceeds, by using
an available microsecond counter.

To enable the feature, define CONFIG_BOOTSTAGE in your board config file.
Also available is CONFIG_BOOTSTAGE_REPORT which will cause a report to be
printed just before handing off to the OS.

Most IDs are not named at this stage. For that I would first like to
renumber them all.

Timer summary in microseconds:
Mark Elapsed Stage
0 0 reset
205,000 205,000 board_init_f
6,053,000 5,848,000 bootm_start
6,053,000 0 id=1
6,058,000 5,000 id=101
6,058,000 0 id=100
6,061,000 3,000 id=103
6,064,000 3,000 id=104
6,093,000 29,000 id=107
6,093,000 0 id=106
6,093,000 0 id=105
6,093,000 0 id=108
7,089,000 996,000 id=7
7,089,000 0 id=15
7,089,000 0 id=8
7,097,000 8,000 start_kernel

Signed-off-by: Simon Glass <sjg@chromium.org>