enum bootstage_id id;
};
-static struct bootstage_record record[BOOTSTAGE_ID_COUNT] = { {1} };
-static int next_id = BOOTSTAGE_ID_USER;
+struct bootstage_data {
+ uint next_id;
+ struct bootstage_record record[BOOTSTAGE_ID_COUNT];
+};
enum {
BOOTSTAGE_VERSION = 0,
int bootstage_relocate(void)
{
+ struct bootstage_data *data = gd->bootstage;
int i;
/*
* program .text section that can eventually get trashed.
*/
for (i = 0; i < BOOTSTAGE_ID_COUNT; i++)
- if (record[i].name)
- record[i].name = strdup(record[i].name);
+ if (data->record[i].name)
+ data->record[i].name = strdup(data->record[i].name);
return 0;
}
ulong bootstage_add_record(enum bootstage_id id, const char *name,
int flags, ulong mark)
{
+ struct bootstage_data *data = gd->bootstage;
struct bootstage_record *rec;
if (flags & BOOTSTAGEF_ALLOC)
- id = next_id++;
+ id = data->next_id++;
if (id < BOOTSTAGE_ID_COUNT) {
- rec = &record[id];
+ rec = &data->record[id];
/* Only record the first event for each */
if (!rec->time_us) {
uint32_t bootstage_start(enum bootstage_id id, const char *name)
{
- struct bootstage_record *rec = &record[id];
+ struct bootstage_data *data = gd->bootstage;
+ struct bootstage_record *rec = &data->record[id];
rec->start_us = timer_get_boot_us();
rec->name = name;
uint32_t bootstage_accum(enum bootstage_id id)
{
- struct bootstage_record *rec = &record[id];
+ struct bootstage_data *data = gd->bootstage;
+ struct bootstage_record *rec = &data->record[id];
uint32_t duration;
duration = (uint32_t)timer_get_boot_us() - rec->start_us;
return buf;
}
-static uint32_t print_time_record(enum bootstage_id id,
- struct bootstage_record *rec, uint32_t prev)
+static uint32_t print_time_record(struct bootstage_record *rec, uint32_t prev)
{
char buf[20];
*/
static int add_bootstages_devicetree(struct fdt_header *blob)
{
+ struct bootstage_data *data = gd->bootstage;
int bootstage;
char buf[20];
int id;
* that they can be printed in the Linux kernel in the right order.
*/
for (id = BOOTSTAGE_ID_COUNT - 1, i = 0; id >= 0; id--, i++) {
- struct bootstage_record *rec = &record[id];
+ struct bootstage_record *rec = &data->record[id];
int node;
if (id != BOOTSTAGE_ID_AWAKE && rec->time_us == 0)
void bootstage_report(void)
{
- struct bootstage_record *rec = record;
+ struct bootstage_data *data = gd->bootstage;
+ struct bootstage_record *rec = data->record;
int id;
uint32_t prev;
puts("Timer summary in microseconds:\n");
printf("%11s%11s %s\n", "Mark", "Elapsed", "Stage");
- /* Fake the first record - we could get it from early boot */
- rec->name = "reset";
- rec->time_us = 0;
- prev = print_time_record(BOOTSTAGE_ID_AWAKE, rec, 0);
+ prev = print_time_record(rec, 0);
/* Sort records by increasing time */
- qsort(record, ARRAY_SIZE(record), sizeof(*rec), h_compare_record);
+ qsort(data->record, ARRAY_SIZE(data->record), sizeof(*rec),
+ h_compare_record);
for (id = 0; id < BOOTSTAGE_ID_COUNT; id++, rec++) {
if (rec->time_us != 0 && !rec->start_us)
- prev = print_time_record(rec->id, rec, prev);
+ prev = print_time_record(rec, prev);
}
- if (next_id > BOOTSTAGE_ID_COUNT)
+ if (data->next_id > BOOTSTAGE_ID_COUNT)
printf("(Overflowed internal boot id table by %d entries\n"
"- please increase CONFIG_BOOTSTAGE_USER_COUNT\n",
- next_id - BOOTSTAGE_ID_COUNT);
+ data->next_id - BOOTSTAGE_ID_COUNT);
puts("\nAccumulated time:\n");
- for (id = 0, rec = record; id < BOOTSTAGE_ID_COUNT; id++, rec++) {
+ for (id = 0, rec = data->record; id < BOOTSTAGE_ID_COUNT; id++, rec++) {
if (rec->start_us)
- prev = print_time_record(id, rec, -1);
+ prev = print_time_record(rec, -1);
}
}
int bootstage_stash(void *base, int size)
{
+ struct bootstage_data *data = gd->bootstage;
struct bootstage_hdr *hdr = (struct bootstage_hdr *)base;
struct bootstage_record *rec;
char buf[20];
hdr->version = BOOTSTAGE_VERSION;
/* Count the number of records, and write that value first */
- for (rec = record, id = count = 0; id < BOOTSTAGE_ID_COUNT;
+ for (rec = data->record, id = count = 0; id < BOOTSTAGE_ID_COUNT;
id++, rec++) {
if (rec->time_us != 0)
count++;
ptr += sizeof(*hdr);
/* Write the records, silently stopping when we run out of space */
- for (rec = record, id = 0; id < BOOTSTAGE_ID_COUNT; id++, rec++) {
+ for (rec = data->record, id = 0; id < BOOTSTAGE_ID_COUNT; id++, rec++) {
if (rec->time_us != 0)
append_data(&ptr, end, rec, sizeof(*rec));
}
/* Write the name strings */
- for (rec = record, id = 0; id < BOOTSTAGE_ID_COUNT; id++, rec++) {
+ for (rec = data->record, id = 0; id < BOOTSTAGE_ID_COUNT; id++, rec++) {
if (rec->time_us != 0) {
const char *name;
int bootstage_unstash(void *base, int size)
{
+ struct bootstage_data *data = gd->bootstage;
struct bootstage_hdr *hdr = (struct bootstage_hdr *)base;
struct bootstage_record *rec;
char *ptr = base, *end = ptr + size;
return -1;
}
- if (next_id + hdr->count > BOOTSTAGE_ID_COUNT) {
+ if (data->next_id + hdr->count > BOOTSTAGE_ID_COUNT) {
debug("%s: Bootstage has %d records, we have space for %d\n"
"- please increase CONFIG_BOOTSTAGE_USER_COUNT\n",
- __func__, hdr->count, BOOTSTAGE_ID_COUNT - next_id);
+ __func__, hdr->count, BOOTSTAGE_ID_COUNT - data->next_id);
return -1;
}
ptr += sizeof(*hdr);
/* Read the records */
- rec_size = hdr->count * sizeof(*record);
- memcpy(record + next_id, ptr, rec_size);
+ rec_size = hdr->count * sizeof(*data->record);
+ memcpy(data->record + data->next_id, ptr, rec_size);
/* Read the name strings */
ptr += rec_size;
- for (rec = record + next_id, id = 0; id < hdr->count; id++, rec++) {
+ for (rec = data->record + data->next_id, id = 0; id < hdr->count;
+ id++, rec++) {
rec->name = ptr;
/* Assume no data corruption here */
}
/* Mark the records as read */
- next_id += hdr->count;
+ data->next_id += hdr->count;
printf("Unstashed %d records\n", hdr->count);
return 0;
}
+
+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);
+ if (first)
+ bootstage_add_record(BOOTSTAGE_ID_AWAKE, "reset", 0, 0);
+
+ return 0;
+}