summaryrefslogtreecommitdiff
path: root/common/bloblist.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2020-09-19 18:49:26 -0600
committerSimon Glass <sjg@chromium.org>2020-10-06 09:07:54 -0600
commit4aed22762303755f8f26d14f0ad2608d63550e72 (patch)
tree8dd4859918fb4b6a1311cbf9ddb722505dfdb23b /common/bloblist.c
parent9c22adb8f979ce1386b600a13f5abc37ec92d696 (diff)
bloblist: Add a command
It is helpful to be able to see basic statistics about the bloblist and also to list its contents. Add a 'bloblist' command to handle this. Put the display functions in the bloblist modules rather than in the command code itself. That allows showing a list from SPL, where commands are not available. Also make bloblist_first/next_blob() static as they are not used outside this file. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common/bloblist.c')
-rw-r--r--common/bloblist.c62
1 files changed, 59 insertions, 3 deletions
diff --git a/common/bloblist.c b/common/bloblist.c
index 99501951e0..c86ea029c8 100644
--- a/common/bloblist.c
+++ b/common/bloblist.c
@@ -13,15 +13,31 @@
DECLARE_GLOBAL_DATA_PTR;
-struct bloblist_rec *bloblist_first_blob(struct bloblist_hdr *hdr)
+static const char *const tag_name[] = {
+ [BLOBLISTT_NONE] = "(none)",
+ [BLOBLISTT_EC_HOSTEVENT] = "EC host event",
+ [BLOBLISTT_SPL_HANDOFF] = "SPL hand-off",
+ [BLOBLISTT_VBOOT_CTX] = "Chrome OS vboot context",
+ [BLOBLISTT_VBOOT_HANDOFF] = "Chrome OS vboot hand-off",
+};
+
+const char *bloblist_tag_name(enum bloblist_tag_t tag)
+{
+ if (tag < 0 || tag >= BLOBLISTT_COUNT)
+ return "invalid";
+
+ return tag_name[tag];
+}
+
+static struct bloblist_rec *bloblist_first_blob(struct bloblist_hdr *hdr)
{
if (hdr->alloced <= hdr->hdr_size)
return NULL;
return (struct bloblist_rec *)((void *)hdr + hdr->hdr_size);
}
-struct bloblist_rec *bloblist_next_blob(struct bloblist_hdr *hdr,
- struct bloblist_rec *rec)
+static struct bloblist_rec *bloblist_next_blob(struct bloblist_hdr *hdr,
+ struct bloblist_rec *rec)
{
ulong offset;
@@ -233,6 +249,46 @@ int bloblist_finish(void)
return 0;
}
+void bloblist_get_stats(ulong *basep, ulong *sizep, ulong *allocedp)
+{
+ struct bloblist_hdr *hdr = gd->bloblist;
+
+ *basep = map_to_sysmem(gd->bloblist);
+ *sizep = hdr->size;
+ *allocedp = hdr->alloced;
+}
+
+static void show_value(const char *prompt, ulong value)
+{
+ printf("%s:%*s %-5lx ", prompt, 8 - (int)strlen(prompt), "", value);
+ print_size(value, "\n");
+}
+
+void bloblist_show_stats(void)
+{
+ ulong base, size, alloced;
+
+ bloblist_get_stats(&base, &size, &alloced);
+ printf("base: %lx\n", base);
+ show_value("size", size);
+ show_value("alloced", alloced);
+ show_value("free", size - alloced);
+}
+
+void bloblist_show_list(void)
+{
+ struct bloblist_hdr *hdr = gd->bloblist;
+ struct bloblist_rec *rec;
+
+ printf("%-8s %8s Tag Name\n", "Address", "Size");
+ for (rec = bloblist_first_blob(hdr); rec;
+ rec = bloblist_next_blob(hdr, rec)) {
+ printf("%08lx %8x %3d %s\n",
+ (ulong)map_to_sysmem((void *)rec + rec->hdr_size),
+ rec->size, rec->tag, bloblist_tag_name(rec->tag));
+ }
+}
+
int bloblist_init(void)
{
bool expected;