diff options
author | Simon Glass <sjg@chromium.org> | 2017-08-20 06:28:54 -0600 |
---|---|---|
committer | David Gibson <david@gibson.dropbear.id.au> | 2017-08-21 10:29:48 +1000 |
commit | fe50bd1ecc1da273a7627a76dcd38da9d77e496f (patch) | |
tree | a83ac023f4b055c4b87d856a03f548c9b45c3540 | |
parent | 62d812308d11f68a22f50e1852c425dac36edf52 (diff) | |
download | dtc-fe50bd1ecc1da273a7627a76dcd38da9d77e496f.zip dtc-fe50bd1ecc1da273a7627a76dcd38da9d77e496f.tar.gz dtc-fe50bd1ecc1da273a7627a76dcd38da9d77e496f.tar.bz2 |
fdtget: Split out cell list display into a new function
The show_data() function is quite long. Split out the part that loops
through the values. This makes it easier to add new features.
Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
-rw-r--r-- | fdtget.c | 49 |
1 files changed, 34 insertions, 15 deletions
@@ -54,6 +54,37 @@ static void report_error(const char *where, int err) } /** + * Shows a list of cells in the requested format + * + * @param disp Display information / options + * @param data Data to display + * @param len Maximum length of buffer + * @param size Data size to use for display (e.g. 4 for 32-bit) + * @return 0 if ok, -1 on error + */ +static int show_cell_list(struct display_info *disp, const char *data, int len, + int size) +{ + const uint8_t *p = (const uint8_t *)data; + char fmt[3]; + int value; + int i; + + fmt[0] = '%'; + fmt[1] = disp->type ? disp->type : 'd'; + fmt[2] = '\0'; + for (i = 0; i < len; i += size, p += size) { + if (i) + printf(" "); + value = size == 4 ? fdt32_to_cpu(*(const fdt32_t *)p) : + size == 2 ? (*p << 8) | p[1] : *p; + printf(fmt, value); + } + + return 0; +} + +/** * Displays data of a given length according to selected options * * If a specific data type is provided in disp, then this is used. Otherwise @@ -66,12 +97,9 @@ static void report_error(const char *where, int err) */ static int show_data(struct display_info *disp, const char *data, int len) { - int i, size; - const uint8_t *p = (const uint8_t *)data; + int size; const char *s; - int value; int is_string; - char fmt[3]; /* no data, don't print */ if (len == 0) @@ -99,17 +127,8 @@ static int show_data(struct display_info *disp, const char *data, int len) "selected data size\n"); return -1; } - fmt[0] = '%'; - fmt[1] = disp->type ? disp->type : 'd'; - fmt[2] = '\0'; - for (i = 0; i < len; i += size, p += size) { - if (i) - printf(" "); - value = size == 4 ? fdt32_to_cpu(*(const fdt32_t *)p) : - size == 2 ? (*p << 8) | p[1] : *p; - printf(fmt, value); - } - return 0; + + return show_cell_list(disp, data, len, size); } /** |