2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
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>
2012-02-13 13:51:19 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2011, Google Inc. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This module records the progress of boot and arbitrary commands, and
|
|
|
|
* permits accurate timestamping of each.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2018-03-04 16:20:11 +00:00
|
|
|
#include <linux/libfdt.h>
|
2013-04-17 16:13:44 +00:00
|
|
|
#include <malloc.h>
|
|
|
|
#include <linux/compiler.h>
|
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>
2012-02-13 13:51:19 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2017-05-22 11:05:27 +00:00
|
|
|
enum {
|
2017-09-06 01:49:49 +00:00
|
|
|
RECORD_COUNT = CONFIG_VAL(BOOTSTAGE_RECORD_COUNT),
|
2017-05-22 11:05:27 +00:00
|
|
|
};
|
|
|
|
|
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>
2012-02-13 13:51:19 +00:00
|
|
|
struct bootstage_record {
|
|
|
|
ulong time_us;
|
2012-09-28 08:56:35 +00:00
|
|
|
uint32_t start_us;
|
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>
2012-02-13 13:51:19 +00:00
|
|
|
const char *name;
|
|
|
|
int flags; /* see enum bootstage_flags */
|
|
|
|
enum bootstage_id id;
|
|
|
|
};
|
|
|
|
|
2017-05-22 11:05:25 +00:00
|
|
|
struct bootstage_data {
|
2017-05-22 11:05:27 +00:00
|
|
|
uint rec_count;
|
2017-05-22 11:05:25 +00:00
|
|
|
uint next_id;
|
2017-05-22 11:05:27 +00:00
|
|
|
struct bootstage_record record[RECORD_COUNT];
|
2017-05-22 11:05:25 +00:00
|
|
|
};
|
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>
2012-02-13 13:51:19 +00:00
|
|
|
|
2012-09-28 08:56:38 +00:00
|
|
|
enum {
|
|
|
|
BOOTSTAGE_VERSION = 0,
|
|
|
|
BOOTSTAGE_MAGIC = 0xb00757a3,
|
2013-06-11 18:14:38 +00:00
|
|
|
BOOTSTAGE_DIGITS = 9,
|
2012-09-28 08:56:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct bootstage_hdr {
|
|
|
|
uint32_t version; /* BOOTSTAGE_VERSION */
|
|
|
|
uint32_t count; /* Number of records */
|
|
|
|
uint32_t size; /* Total data size (non-zero if valid) */
|
|
|
|
uint32_t magic; /* Unused */
|
|
|
|
};
|
|
|
|
|
2013-04-17 16:13:41 +00:00
|
|
|
int bootstage_relocate(void)
|
|
|
|
{
|
2017-05-22 11:05:25 +00:00
|
|
|
struct bootstage_data *data = gd->bootstage;
|
2013-04-17 16:13:41 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Duplicate all strings. They may point to an old location in the
|
|
|
|
* program .text section that can eventually get trashed.
|
|
|
|
*/
|
2017-05-22 11:05:27 +00:00
|
|
|
debug("Relocating %d records\n", data->rec_count);
|
|
|
|
for (i = 0; i < data->rec_count; i++)
|
|
|
|
data->record[i].name = strdup(data->record[i].name);
|
2013-04-17 16:13:41 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-05-22 11:05:27 +00:00
|
|
|
struct bootstage_record *find_id(struct bootstage_data *data,
|
|
|
|
enum bootstage_id id)
|
|
|
|
{
|
|
|
|
struct bootstage_record *rec;
|
|
|
|
struct bootstage_record *end;
|
|
|
|
|
|
|
|
for (rec = data->record, end = rec + data->rec_count; rec < end;
|
|
|
|
rec++) {
|
|
|
|
if (rec->id == id)
|
|
|
|
return rec;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct bootstage_record *ensure_id(struct bootstage_data *data,
|
|
|
|
enum bootstage_id id)
|
|
|
|
{
|
|
|
|
struct bootstage_record *rec;
|
|
|
|
|
|
|
|
rec = find_id(data, id);
|
|
|
|
if (!rec && data->rec_count < RECORD_COUNT) {
|
|
|
|
rec = &data->record[data->rec_count++];
|
|
|
|
rec->id = id;
|
|
|
|
return rec;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rec;
|
|
|
|
}
|
|
|
|
|
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>
2012-02-13 13:51:19 +00:00
|
|
|
ulong bootstage_add_record(enum bootstage_id id, const char *name,
|
2012-09-28 08:56:35 +00:00
|
|
|
int flags, ulong mark)
|
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>
2012-02-13 13:51:19 +00:00
|
|
|
{
|
2017-05-22 11:05:25 +00:00
|
|
|
struct bootstage_data *data = gd->bootstage;
|
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>
2012-02-13 13:51:19 +00:00
|
|
|
struct bootstage_record *rec;
|
|
|
|
|
2019-04-08 19:20:45 +00:00
|
|
|
/*
|
|
|
|
* initf_bootstage() is called very early during boot but since hang()
|
|
|
|
* calls bootstage_error() we can be called before bootstage is set up.
|
|
|
|
* Add a check to avoid this.
|
|
|
|
*/
|
|
|
|
if (!data)
|
|
|
|
return mark;
|
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>
2012-02-13 13:51:19 +00:00
|
|
|
if (flags & BOOTSTAGEF_ALLOC)
|
2017-05-22 11:05:25 +00:00
|
|
|
id = data->next_id++;
|
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>
2012-02-13 13:51:19 +00:00
|
|
|
|
2017-05-22 11:05:27 +00:00
|
|
|
/* Only record the first event for each */
|
|
|
|
rec = find_id(data, id);
|
|
|
|
if (!rec && data->rec_count < RECORD_COUNT) {
|
|
|
|
rec = &data->record[data->rec_count++];
|
|
|
|
rec->time_us = mark;
|
|
|
|
rec->name = name;
|
|
|
|
rec->flags = flags;
|
|
|
|
rec->id = id;
|
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>
2012-02-13 13:51:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Tell the board about this progress */
|
|
|
|
show_boot_progress(flags & BOOTSTAGEF_ERROR ? -id : id);
|
2017-05-22 11:05:26 +00:00
|
|
|
|
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>
2012-02-13 13:51:19 +00:00
|
|
|
return mark;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ulong bootstage_mark(enum bootstage_id id)
|
|
|
|
{
|
2012-09-28 08:56:35 +00:00
|
|
|
return bootstage_add_record(id, NULL, 0, timer_get_boot_us());
|
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>
2012-02-13 13:51:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ulong bootstage_error(enum bootstage_id id)
|
|
|
|
{
|
2012-09-28 08:56:35 +00:00
|
|
|
return bootstage_add_record(id, NULL, BOOTSTAGEF_ERROR,
|
|
|
|
timer_get_boot_us());
|
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>
2012-02-13 13:51:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ulong bootstage_mark_name(enum bootstage_id id, const char *name)
|
|
|
|
{
|
|
|
|
int flags = 0;
|
|
|
|
|
|
|
|
if (id == BOOTSTAGE_ID_ALLOC)
|
|
|
|
flags = BOOTSTAGEF_ALLOC;
|
2017-05-22 11:05:26 +00:00
|
|
|
|
2012-09-28 08:56:35 +00:00
|
|
|
return bootstage_add_record(id, name, flags, timer_get_boot_us());
|
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>
2012-02-13 13:51:19 +00:00
|
|
|
}
|
|
|
|
|
2013-04-17 16:13:44 +00:00
|
|
|
ulong bootstage_mark_code(const char *file, const char *func, int linenum)
|
|
|
|
{
|
|
|
|
char *str, *p;
|
|
|
|
__maybe_unused char *end;
|
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
/* First work out the length we need to allocate */
|
|
|
|
if (linenum != -1)
|
|
|
|
len = 11;
|
|
|
|
if (func)
|
|
|
|
len += strlen(func);
|
|
|
|
if (file)
|
|
|
|
len += strlen(file);
|
|
|
|
|
|
|
|
str = malloc(len + 1);
|
|
|
|
p = str;
|
|
|
|
end = p + len;
|
|
|
|
if (file)
|
|
|
|
p += snprintf(p, end - p, "%s,", file);
|
|
|
|
if (linenum != -1)
|
|
|
|
p += snprintf(p, end - p, "%d", linenum);
|
|
|
|
if (func)
|
|
|
|
p += snprintf(p, end - p, ": %s", func);
|
|
|
|
|
|
|
|
return bootstage_mark_name(BOOTSTAGE_ID_ALLOC, str);
|
|
|
|
}
|
|
|
|
|
2012-09-28 08:56:36 +00:00
|
|
|
uint32_t bootstage_start(enum bootstage_id id, const char *name)
|
|
|
|
{
|
2017-05-22 11:05:25 +00:00
|
|
|
struct bootstage_data *data = gd->bootstage;
|
2017-05-22 11:05:27 +00:00
|
|
|
struct bootstage_record *rec = ensure_id(data, id);
|
|
|
|
ulong start_us = timer_get_boot_us();
|
2012-09-28 08:56:36 +00:00
|
|
|
|
2017-05-22 11:05:27 +00:00
|
|
|
if (rec) {
|
|
|
|
rec->start_us = start_us;
|
|
|
|
rec->name = name;
|
|
|
|
}
|
2017-05-22 11:05:26 +00:00
|
|
|
|
2017-05-22 11:05:27 +00:00
|
|
|
return start_us;
|
2012-09-28 08:56:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t bootstage_accum(enum bootstage_id id)
|
|
|
|
{
|
2017-05-22 11:05:25 +00:00
|
|
|
struct bootstage_data *data = gd->bootstage;
|
2017-05-22 11:05:27 +00:00
|
|
|
struct bootstage_record *rec = ensure_id(data, id);
|
2012-09-28 08:56:36 +00:00
|
|
|
uint32_t duration;
|
|
|
|
|
2017-05-22 11:05:27 +00:00
|
|
|
if (!rec)
|
|
|
|
return 0;
|
2012-09-28 08:56:36 +00:00
|
|
|
duration = (uint32_t)timer_get_boot_us() - rec->start_us;
|
|
|
|
rec->time_us += duration;
|
2017-05-22 11:05:26 +00:00
|
|
|
|
2012-09-28 08:56:36 +00:00
|
|
|
return duration;
|
|
|
|
}
|
|
|
|
|
2012-09-28 08:56:37 +00:00
|
|
|
/**
|
|
|
|
* Get a record name as a printable string
|
|
|
|
*
|
|
|
|
* @param buf Buffer to put name if needed
|
|
|
|
* @param len Length of buffer
|
|
|
|
* @param rec Boot stage record to get the name from
|
|
|
|
* @return pointer to name, either from the record or pointing to buf.
|
|
|
|
*/
|
|
|
|
static const char *get_record_name(char *buf, int len,
|
2017-05-22 11:05:34 +00:00
|
|
|
const struct bootstage_record *rec)
|
2012-09-28 08:56:37 +00:00
|
|
|
{
|
|
|
|
if (rec->name)
|
|
|
|
return rec->name;
|
|
|
|
else if (rec->id >= BOOTSTAGE_ID_USER)
|
|
|
|
snprintf(buf, len, "user_%d", rec->id - BOOTSTAGE_ID_USER);
|
|
|
|
else
|
|
|
|
snprintf(buf, len, "id=%d", rec->id);
|
|
|
|
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2017-05-22 11:05:25 +00:00
|
|
|
static uint32_t print_time_record(struct bootstage_record *rec, uint32_t prev)
|
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>
2012-02-13 13:51:19 +00:00
|
|
|
{
|
2012-09-28 08:56:37 +00:00
|
|
|
char buf[20];
|
|
|
|
|
2012-09-28 08:56:36 +00:00
|
|
|
if (prev == -1U) {
|
|
|
|
printf("%11s", "");
|
2013-06-11 18:14:38 +00:00
|
|
|
print_grouped_ull(rec->time_us, BOOTSTAGE_DIGITS);
|
2012-09-28 08:56:36 +00:00
|
|
|
} else {
|
2013-06-11 18:14:38 +00:00
|
|
|
print_grouped_ull(rec->time_us, BOOTSTAGE_DIGITS);
|
|
|
|
print_grouped_ull(rec->time_us - prev, BOOTSTAGE_DIGITS);
|
2012-09-28 08:56:36 +00:00
|
|
|
}
|
2012-09-28 08:56:37 +00:00
|
|
|
printf(" %s\n", get_record_name(buf, sizeof(buf), rec));
|
|
|
|
|
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>
2012-02-13 13:51:19 +00:00
|
|
|
return rec->time_us;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int h_compare_record(const void *r1, const void *r2)
|
|
|
|
{
|
|
|
|
const struct bootstage_record *rec1 = r1, *rec2 = r2;
|
|
|
|
|
|
|
|
return rec1->time_us > rec2->time_us ? 1 : -1;
|
|
|
|
}
|
|
|
|
|
2012-09-28 08:56:37 +00:00
|
|
|
#ifdef CONFIG_OF_LIBFDT
|
|
|
|
/**
|
|
|
|
* Add all bootstage timings to a device tree.
|
|
|
|
*
|
|
|
|
* @param blob Device tree blob
|
|
|
|
* @return 0 on success, != 0 on failure.
|
|
|
|
*/
|
|
|
|
static int add_bootstages_devicetree(struct fdt_header *blob)
|
|
|
|
{
|
2017-05-22 11:05:25 +00:00
|
|
|
struct bootstage_data *data = gd->bootstage;
|
2012-09-28 08:56:37 +00:00
|
|
|
int bootstage;
|
|
|
|
char buf[20];
|
2017-05-22 11:05:27 +00:00
|
|
|
int recnum;
|
2012-09-28 08:56:37 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!blob)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the node for bootstage.
|
|
|
|
* The address of flat device tree is set up by the command bootm.
|
|
|
|
*/
|
|
|
|
bootstage = fdt_add_subnode(blob, 0, "bootstage");
|
|
|
|
if (bootstage < 0)
|
2017-05-22 11:05:33 +00:00
|
|
|
return -EINVAL;
|
2012-09-28 08:56:37 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Insert the timings to the device tree in the reverse order so
|
|
|
|
* that they can be printed in the Linux kernel in the right order.
|
|
|
|
*/
|
2017-05-22 11:05:27 +00:00
|
|
|
for (recnum = data->rec_count - 1, i = 0; recnum >= 0; recnum--, i++) {
|
|
|
|
struct bootstage_record *rec = &data->record[recnum];
|
2012-09-28 08:56:37 +00:00
|
|
|
int node;
|
|
|
|
|
2017-05-22 11:05:27 +00:00
|
|
|
if (rec->id != BOOTSTAGE_ID_AWAKE && rec->time_us == 0)
|
2012-09-28 08:56:37 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
node = fdt_add_subnode(blob, bootstage, simple_itoa(i));
|
|
|
|
if (node < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* add properties to the node. */
|
|
|
|
if (fdt_setprop_string(blob, node, "name",
|
2017-05-22 11:05:27 +00:00
|
|
|
get_record_name(buf, sizeof(buf), rec)))
|
2017-05-22 11:05:33 +00:00
|
|
|
return -EINVAL;
|
2012-09-28 08:56:37 +00:00
|
|
|
|
|
|
|
/* Check if this is a 'mark' or 'accum' record */
|
|
|
|
if (fdt_setprop_cell(blob, node,
|
|
|
|
rec->start_us ? "accum" : "mark",
|
|
|
|
rec->time_us))
|
2017-05-22 11:05:33 +00:00
|
|
|
return -EINVAL;
|
2012-09-28 08:56:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int bootstage_fdt_add_report(void)
|
|
|
|
{
|
|
|
|
if (add_bootstages_devicetree(working_fdt))
|
|
|
|
puts("bootstage: Failed to add to device tree\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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>
2012-02-13 13:51:19 +00:00
|
|
|
void bootstage_report(void)
|
|
|
|
{
|
2017-05-22 11:05:25 +00:00
|
|
|
struct bootstage_data *data = gd->bootstage;
|
|
|
|
struct bootstage_record *rec = data->record;
|
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>
2012-02-13 13:51:19 +00:00
|
|
|
uint32_t prev;
|
2017-05-22 11:05:27 +00:00
|
|
|
int i;
|
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>
2012-02-13 13:51:19 +00:00
|
|
|
|
2017-05-22 11:05:27 +00:00
|
|
|
printf("Timer summary in microseconds (%d records):\n",
|
|
|
|
data->rec_count);
|
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>
2012-02-13 13:51:19 +00:00
|
|
|
printf("%11s%11s %s\n", "Mark", "Elapsed", "Stage");
|
|
|
|
|
2017-05-22 11:05:25 +00:00
|
|
|
prev = print_time_record(rec, 0);
|
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>
2012-02-13 13:51:19 +00:00
|
|
|
|
|
|
|
/* Sort records by increasing time */
|
2017-05-22 11:05:27 +00:00
|
|
|
qsort(data->record, data->rec_count, sizeof(*rec), h_compare_record);
|
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>
2012-02-13 13:51:19 +00:00
|
|
|
|
2017-05-22 11:05:27 +00:00
|
|
|
for (i = 1, rec++; i < data->rec_count; i++, rec++) {
|
|
|
|
if (rec->id && !rec->start_us)
|
2017-05-22 11:05:25 +00:00
|
|
|
prev = print_time_record(rec, prev);
|
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>
2012-02-13 13:51:19 +00:00
|
|
|
}
|
2017-05-22 11:05:27 +00:00
|
|
|
if (data->rec_count > RECORD_COUNT)
|
|
|
|
printf("Overflowed internal boot id table by %d entries\n"
|
2017-09-06 01:49:49 +00:00
|
|
|
"Please increase CONFIG_(SPL_)BOOTSTAGE_RECORD_COUNT\n",
|
2017-05-22 11:05:27 +00:00
|
|
|
data->rec_count - RECORD_COUNT);
|
2012-09-28 08:56:36 +00:00
|
|
|
|
|
|
|
puts("\nAccumulated time:\n");
|
2017-05-22 11:05:27 +00:00
|
|
|
for (i = 0, rec = data->record; i < data->rec_count; i++, rec++) {
|
2012-09-28 08:56:36 +00:00
|
|
|
if (rec->start_us)
|
2017-05-22 11:05:25 +00:00
|
|
|
prev = print_time_record(rec, -1);
|
2012-09-28 08:56:36 +00:00
|
|
|
}
|
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>
2012-02-13 13:51:19 +00:00
|
|
|
}
|
2012-04-05 12:05:17 +00:00
|
|
|
|
2012-09-28 08:56:38 +00:00
|
|
|
/**
|
|
|
|
* Append data to a memory buffer
|
|
|
|
*
|
|
|
|
* Write data to the buffer if there is space. Whether there is space or not,
|
|
|
|
* the buffer pointer is incremented.
|
|
|
|
*
|
|
|
|
* @param ptrp Pointer to buffer, updated by this function
|
|
|
|
* @param end Pointer to end of buffer
|
|
|
|
* @param data Data to write to buffer
|
|
|
|
* @param size Size of data
|
|
|
|
*/
|
|
|
|
static void append_data(char **ptrp, char *end, const void *data, int size)
|
|
|
|
{
|
|
|
|
char *ptr = *ptrp;
|
|
|
|
|
|
|
|
*ptrp += size;
|
|
|
|
if (*ptrp > end)
|
|
|
|
return;
|
|
|
|
|
|
|
|
memcpy(ptr, data, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
int bootstage_stash(void *base, int size)
|
|
|
|
{
|
2017-05-22 11:05:34 +00:00
|
|
|
const struct bootstage_data *data = gd->bootstage;
|
2012-09-28 08:56:38 +00:00
|
|
|
struct bootstage_hdr *hdr = (struct bootstage_hdr *)base;
|
2017-05-22 11:05:34 +00:00
|
|
|
const struct bootstage_record *rec;
|
2012-09-28 08:56:38 +00:00
|
|
|
char buf[20];
|
|
|
|
char *ptr = base, *end = ptr + size;
|
|
|
|
uint32_t count;
|
2017-05-22 11:05:27 +00:00
|
|
|
int i;
|
2012-09-28 08:56:38 +00:00
|
|
|
|
|
|
|
if (hdr + 1 > (struct bootstage_hdr *)end) {
|
|
|
|
debug("%s: Not enough space for bootstage hdr\n", __func__);
|
2017-05-22 11:05:33 +00:00
|
|
|
return -ENOSPC;
|
2012-09-28 08:56:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Write an arbitrary version number */
|
|
|
|
hdr->version = BOOTSTAGE_VERSION;
|
|
|
|
|
|
|
|
/* Count the number of records, and write that value first */
|
2017-05-22 11:05:27 +00:00
|
|
|
for (rec = data->record, i = count = 0; i < data->rec_count;
|
|
|
|
i++, rec++) {
|
|
|
|
if (rec->id != 0)
|
2012-09-28 08:56:38 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
hdr->count = count;
|
|
|
|
hdr->size = 0;
|
|
|
|
hdr->magic = BOOTSTAGE_MAGIC;
|
|
|
|
ptr += sizeof(*hdr);
|
|
|
|
|
|
|
|
/* Write the records, silently stopping when we run out of space */
|
2017-05-22 11:05:27 +00:00
|
|
|
for (rec = data->record, i = 0; i < data->rec_count; i++, rec++) {
|
2017-05-22 11:05:28 +00:00
|
|
|
append_data(&ptr, end, rec, sizeof(*rec));
|
2012-09-28 08:56:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Write the name strings */
|
2017-05-22 11:05:27 +00:00
|
|
|
for (rec = data->record, i = 0; i < data->rec_count; i++, rec++) {
|
2017-05-22 11:05:28 +00:00
|
|
|
const char *name;
|
2012-09-28 08:56:38 +00:00
|
|
|
|
2017-05-22 11:05:28 +00:00
|
|
|
name = get_record_name(buf, sizeof(buf), rec);
|
|
|
|
append_data(&ptr, end, name, strlen(name) + 1);
|
2012-09-28 08:56:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for buffer overflow */
|
|
|
|
if (ptr > end) {
|
|
|
|
debug("%s: Not enough space for bootstage stash\n", __func__);
|
2017-05-22 11:05:33 +00:00
|
|
|
return -ENOSPC;
|
2012-09-28 08:56:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Update total data size */
|
|
|
|
hdr->size = ptr - (char *)base;
|
2017-05-22 11:05:29 +00:00
|
|
|
debug("Stashed %d records\n", hdr->count);
|
2012-09-28 08:56:38 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-05-22 11:05:34 +00:00
|
|
|
int bootstage_unstash(const void *base, int size)
|
2012-09-28 08:56:38 +00:00
|
|
|
{
|
2017-05-22 11:05:34 +00:00
|
|
|
const struct bootstage_hdr *hdr = (struct bootstage_hdr *)base;
|
2017-05-22 11:05:25 +00:00
|
|
|
struct bootstage_data *data = gd->bootstage;
|
2017-05-22 11:05:34 +00:00
|
|
|
const char *ptr = base, *end = ptr + size;
|
2012-09-28 08:56:38 +00:00
|
|
|
struct bootstage_record *rec;
|
|
|
|
uint rec_size;
|
2017-05-22 11:05:27 +00:00
|
|
|
int i;
|
2012-09-28 08:56:38 +00:00
|
|
|
|
|
|
|
if (size == -1)
|
|
|
|
end = (char *)(~(uintptr_t)0);
|
|
|
|
|
|
|
|
if (hdr + 1 > (struct bootstage_hdr *)end) {
|
|
|
|
debug("%s: Not enough space for bootstage hdr\n", __func__);
|
2017-05-22 11:05:33 +00:00
|
|
|
return -EPERM;
|
2012-09-28 08:56:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hdr->magic != BOOTSTAGE_MAGIC) {
|
|
|
|
debug("%s: Invalid bootstage magic\n", __func__);
|
2017-05-22 11:05:33 +00:00
|
|
|
return -ENOENT;
|
2012-09-28 08:56:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ptr + hdr->size > end) {
|
|
|
|
debug("%s: Bootstage data runs past buffer end\n", __func__);
|
2017-05-22 11:05:33 +00:00
|
|
|
return -ENOSPC;
|
2012-09-28 08:56:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hdr->count * sizeof(*rec) > hdr->size) {
|
2013-06-11 18:14:37 +00:00
|
|
|
debug("%s: Bootstage has %d records needing %lu bytes, but "
|
2012-09-28 08:56:38 +00:00
|
|
|
"only %d bytes is available\n", __func__, hdr->count,
|
2013-06-11 18:14:37 +00:00
|
|
|
(ulong)hdr->count * sizeof(*rec), hdr->size);
|
2017-05-22 11:05:33 +00:00
|
|
|
return -ENOSPC;
|
2012-09-28 08:56:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hdr->version != BOOTSTAGE_VERSION) {
|
|
|
|
debug("%s: Bootstage data version %#0x unrecognised\n",
|
|
|
|
__func__, hdr->version);
|
2017-05-22 11:05:33 +00:00
|
|
|
return -EINVAL;
|
2012-09-28 08:56:38 +00:00
|
|
|
}
|
|
|
|
|
2017-05-22 11:05:27 +00:00
|
|
|
if (data->rec_count + hdr->count > RECORD_COUNT) {
|
2012-09-28 08:56:38 +00:00
|
|
|
debug("%s: Bootstage has %d records, we have space for %d\n"
|
2017-09-06 01:49:49 +00:00
|
|
|
"Please increase CONFIG_(SPL_)BOOTSTAGE_RECORD_COUNT\n",
|
2017-05-22 11:05:27 +00:00
|
|
|
__func__, hdr->count, RECORD_COUNT - data->rec_count);
|
2017-05-22 11:05:33 +00:00
|
|
|
return -ENOSPC;
|
2012-09-28 08:56:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ptr += sizeof(*hdr);
|
|
|
|
|
|
|
|
/* Read the records */
|
2017-05-22 11:05:25 +00:00
|
|
|
rec_size = hdr->count * sizeof(*data->record);
|
2017-05-22 11:05:27 +00:00
|
|
|
memcpy(data->record + data->rec_count, ptr, rec_size);
|
2012-09-28 08:56:38 +00:00
|
|
|
|
|
|
|
/* Read the name strings */
|
|
|
|
ptr += rec_size;
|
2017-05-22 11:05:27 +00:00
|
|
|
for (rec = data->record + data->next_id, i = 0; i < hdr->count;
|
|
|
|
i++, rec++) {
|
2012-09-28 08:56:38 +00:00
|
|
|
rec->name = ptr;
|
|
|
|
|
|
|
|
/* Assume no data corruption here */
|
|
|
|
ptr += strlen(ptr) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Mark the records as read */
|
2017-05-22 11:05:27 +00:00
|
|
|
data->rec_count += hdr->count;
|
2017-05-22 11:05:29 +00:00
|
|
|
debug("Unstashed %d records\n", hdr->count);
|
2012-09-28 08:56:38 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2017-05-22 11:05:25 +00:00
|
|
|
|
2017-05-22 11:05:30 +00:00
|
|
|
int bootstage_get_size(void)
|
|
|
|
{
|
|
|
|
return sizeof(struct bootstage_data);
|
|
|
|
}
|
|
|
|
|
2017-05-22 11:05:25 +00:00
|
|
|
int bootstage_init(bool first)
|
|
|
|
{
|
|
|
|
struct bootstage_data *data;
|
|
|
|
int size = sizeof(struct bootstage_data);
|
|
|
|
|
|
|
|
gd->bootstage = (struct bootstage_data *)malloc(size);
|
|
|
|
if (!gd->bootstage)
|
|
|
|
return -ENOMEM;
|
|
|
|
data = gd->bootstage;
|
|
|
|
memset(data, '\0', size);
|
2017-05-22 11:05:27 +00:00
|
|
|
if (first) {
|
|
|
|
data->next_id = BOOTSTAGE_ID_USER;
|
2017-05-22 11:05:25 +00:00
|
|
|
bootstage_add_record(BOOTSTAGE_ID_AWAKE, "reset", 0, 0);
|
2017-05-22 11:05:27 +00:00
|
|
|
}
|
2017-05-22 11:05:25 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|