Re: [U-Boot] [PATCH v2] cmd, fdt: add subcommand "get" to fdt header

2018-11-14 Thread Marek Vasut
On 11/14/2018 04:17 PM, Heiko Schocher wrote:
> store fdt header member with name  in U-Boot
> Environment variable with name .
> 
> for example to get the total length of the fdt and store
> it in filesize, call:
> 
> fdt header get filesize totalsize
> 
> For membernames look into fdt header definition at
> scripts/dtc/libfdt/libfdt.h
> 
> Signed-off-by: Heiko Schocher 
> ---
> 
> Changes in v2:
> - add obviously missing "static const char *"
> 
>  cmd/fdt.c | 40 +++-
>  1 file changed, 39 insertions(+), 1 deletion(-)
> 
> diff --git a/cmd/fdt.c b/cmd/fdt.c
> index 8a19a3fdbf..501aa7c887 100644
> --- a/cmd/fdt.c
> +++ b/cmd/fdt.c
> @@ -73,6 +73,40 @@ static int fdt_value_env_set(const void *nodep, int
> len, const char *var)
>  return 0;
>  }
> 
> +static const char * const fdt_member_table[] = {
> +    "magic",
> +    "totalsize",
> +    "off_dt_struct",
> +    "off_dt_strings",
> +    "off_mem_rsvmap",
> +    "version",
> +    "last_comp_version",
> +    "boot_cpuid_phys",
> +    "size_dt_strings",
> +    "size_dt_struct",
> +};
> +
> +static int fdt_get_header_value(int argc, char * const argv[])
> +{
> +    fdt32_t *fdtp = (fdt32_t *)working_fdt;
> +    ulong val;
> +    int i;
> +
> +    if (argv[2][0] != 'g')
> +    return CMD_RET_FAILURE;
> +
> +    for (i = 0; i < ARRAY_SIZE(fdt_member_table); i++) {
> +    if (strcmp(fdt_member_table[i], argv[4]) == 0) {

if (strcmp...)
 continue;

> +    val = fdt32_to_cpu(*fdtp);

You can use fdtp[i]

> +    env_set_hex(argv[3], val);
> +    return CMD_RET_SUCCESS;
> +    }
> +    fdtp++;

And drop this

> +    }

Looks great otherwise

> +    return CMD_RET_FAILURE;
> +}
> +
>  /*
>   * Flattened Device Tree command, see the help for parameter definitions.
>   */
> @@ -491,6 +525,9 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int
> argc, char * const argv[])
>   * Display header info
>   */
>  } else if (argv[1][0] == 'h') {
> +    if (argc == 5)
> +    return fdt_get_header_value(argc, argv);
> +
>  u32 version = fdt_version(working_fdt);
>  printf("magic:\t\t\t0x%x\n", fdt_magic(working_fdt));
>  printf("totalsize:\t\t0x%x (%d)\n", fdt_totalsize(working_fdt),
> @@ -1090,7 +1127,8 @@ static char fdt_help_text[] =
>  "fdt set      []    - Set  [to ]\n"
>  "fdt mknode      - Create a new node after
> \n"
>  "fdt rm  []  - Delete the node or
> \n"
> -    "fdt header  - Display header info\n"
> +    "fdt header [get  ] - Display header info\n"
> +    "  get - get header member
>  and store it in \n"
>  "fdt bootcpu     - Set boot cpuid\n"
>  "fdt memory      - Add/Update memory node\n"
>  "fdt rsvmem print    - Show current mem reserves\n"


-- 
Best regards,
Marek Vasut
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [PATCH v2] cmd, fdt: add subcommand "get" to fdt header

2018-11-14 Thread Heiko Schocher

store fdt header member with name  in U-Boot
Environment variable with name .

for example to get the total length of the fdt and store
it in filesize, call:

fdt header get filesize totalsize

For membernames look into fdt header definition at
scripts/dtc/libfdt/libfdt.h

Signed-off-by: Heiko Schocher 
---

Changes in v2:
- add obviously missing "static const char *"

 cmd/fdt.c | 40 +++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/cmd/fdt.c b/cmd/fdt.c
index 8a19a3fdbf..501aa7c887 100644
--- a/cmd/fdt.c
+++ b/cmd/fdt.c
@@ -73,6 +73,40 @@ static int fdt_value_env_set(const void *nodep, int len, 
const char *var)
return 0;
 }

+static const char * const fdt_member_table[] = {
+   "magic",
+   "totalsize",
+   "off_dt_struct",
+   "off_dt_strings",
+   "off_mem_rsvmap",
+   "version",
+   "last_comp_version",
+   "boot_cpuid_phys",
+   "size_dt_strings",
+   "size_dt_struct",
+};
+
+static int fdt_get_header_value(int argc, char * const argv[])
+{
+   fdt32_t *fdtp = (fdt32_t *)working_fdt;
+   ulong val;
+   int i;
+
+   if (argv[2][0] != 'g')
+   return CMD_RET_FAILURE;
+
+   for (i = 0; i < ARRAY_SIZE(fdt_member_table); i++) {
+   if (strcmp(fdt_member_table[i], argv[4]) == 0) {
+   val = fdt32_to_cpu(*fdtp);
+   env_set_hex(argv[3], val);
+   return CMD_RET_SUCCESS;
+   }
+   fdtp++;
+   }
+
+   return CMD_RET_FAILURE;
+}
+
 /*
  * Flattened Device Tree command, see the help for parameter definitions.
  */
@@ -491,6 +525,9 @@ static int do_fdt(cmd_tbl_t *cmdtp, int flag, int argc, 
char * const argv[])
 * Display header info
 */
} else if (argv[1][0] == 'h') {
+   if (argc == 5)
+   return fdt_get_header_value(argc, argv);
+
u32 version = fdt_version(working_fdt);
printf("magic:\t\t\t0x%x\n", fdt_magic(working_fdt));
printf("totalsize:\t\t0x%x (%d)\n", fdt_totalsize(working_fdt),
@@ -1090,7 +1127,8 @@ static char fdt_help_text[] =
"fdt set  []- Set  [to ]\n"
"fdt mknode  - Create a new node after \n"
"fdt rm  []  - Delete the node or \n"
-   "fdt header  - Display header info\n"
+   "fdt header [get  ] - Display header info\n"
+   "  get - get header member  and store 
it in \n"
"fdt bootcpu - Set boot cpuid\n"
"fdt memory  - Add/Update memory node\n"
"fdt rsvmem print- Show current mem reserves\n"
--
2.13.6


--
DENX Software Engineering GmbH,  Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: h...@denx.de
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot