cmd: bdinfo: introduce bdinfo_print_size() helper
authorOvidiu Panait <ovpanait@gmail.com>
Mon, 29 Aug 2022 17:02:04 +0000 (20:02 +0300)
committerMichal Simek <michal.simek@amd.com>
Tue, 13 Sep 2022 09:32:48 +0000 (11:32 +0200)
Add bdinfo_print_size() helper to display size variables (such as cache
sizes) in bdinfo format. The size is printed as "xxx Bytes", "xxx KiB",
"xxx MiB", "xxx GiB", etc as needed;

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Ovidiu Panait <ovpanait@gmail.com>
Reviewed-by: Jason Liu <jason.hui.liu@nxp.com>
Link: https://lore.kernel.org/r/20220829170205.1274484-3-ovpanait@gmail.com
Signed-off-by: Michal Simek <michal.simek@amd.com>
cmd/bdinfo.c
include/init.h

index 8a1bea4..af2e975 100644 (file)
 #include <vsprintf.h>
 #include <asm/cache.h>
 #include <asm/global_data.h>
+#include <display_options.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
+void bdinfo_print_size(const char *name, uint64_t size)
+{
+       printf("%-12s= ", name);
+       print_size(size, "\n");
+}
+
 void bdinfo_print_num_l(const char *name, ulong value)
 {
        printf("%-12s= 0x%0*lx\n", name, 2 * (int)sizeof(value), value);
index 7b8f62c..02bb4ce 100644 (file)
@@ -343,6 +343,19 @@ void bdinfo_print_num_ll(const char *name, unsigned long long value);
 /* Print a clock speed in MHz */
 void bdinfo_print_mhz(const char *name, unsigned long hz);
 
+/**
+ * bdinfo_print_size - print size variables in bdinfo format
+ * @name:      string to print before the size
+ * @size:      size to print
+ *
+ * Helper function for displaying size variables as properly formatted bdinfo
+ * entries. The size is printed as "xxx Bytes", "xxx KiB", "xxx MiB",
+ * "xxx GiB", etc. as needed;
+ *
+ * For use in arch_print_bdinfo().
+ */
+void bdinfo_print_size(const char *name, uint64_t size);
+
 /* Show arch-specific information for the 'bd' command */
 void arch_print_bdinfo(void);