[Skiboot] [PATCH v4 5/6] hdata/hdata_to_dt: Add -s option

Michael Neuling mikey at neuling.org
Wed Mar 23 11:08:25 AEDT 2016


On Tue, 2016-03-22 at 11:18 +0530, Vasant Hegde wrote:

> hdata_to_dt handles legacy SPIRA data only. This patch adds
> new option (-s) to handle new SPIRAH/S data.

Why not just auto detect it for the user based on the header, rather
than making them add this option?

eg:
  if (spiras->hdr == SPIRAS_HDIF_SIG)
	new_spira = true;

Mikey


> 
> Signed-off-by: Vasant Hegde <hegdevasant at linux.vnet.ibm.com>
> ---
>  hdata/test/hdata_to_dt.c | 80 +++++++++++++++++++++++++++++++-----------------
>  1 file changed, 52 insertions(+), 28 deletions(-)
> 
> diff --git a/hdata/test/hdata_to_dt.c b/hdata/test/hdata_to_dt.c
> index 38bf825..c68e5bb 100644
> --- a/hdata/test/hdata_to_dt.c
> +++ b/hdata/test/hdata_to_dt.c
> @@ -125,43 +125,64 @@ static void undefined_bytes(void *p, size_t len)
>  
>  int main(int argc, char *argv[])
>  {
> -	int fd, r;
> -	bool verbose = false, quiet = false, tree_only = false;
> +	int fd, r, i = 0, opt_count = 0;
> +	bool verbose = false, quiet = false, tree_only = false, new_spira = false;
>  
> -	while (argv[1]) {
> -		if (strcmp(argv[1], "-v") == 0) {
> +	while (argv[++i]) {
> +		if (strcmp(argv[i], "-v") == 0) {
>  			verbose = true;
> -			argv++;
> -			argc--;
> -		} else if (strcmp(argv[1], "-q") == 0) {
> +			opt_count++;
> +		} else if (strcmp(argv[i], "-q") == 0) {
>  			quiet = true;
> -			argv++;
> -			argc--;
> -		} else if (strcmp(argv[1], "-t") == 0) {
> +			opt_count++;
> +		} else if (strcmp(argv[i], "-t") == 0) {
>  			tree_only = true;
> -			argv++;
> -			argc--;
> -		} else
> -			break;
> +			opt_count++;
> +		} else if (strcmp(argv[i], "-s") == 0) {
> +			new_spira = true;
> +			opt_count++;
> +		}
>  	}
>  
> -	if (argc != 3)
> -		errx(1, "Usage: hdata [-v|-q|-t] <spira-dump> <heap-dump>");
> +	argc -= opt_count;
> +	argv += opt_count;
> +	if (argc != 3) {
> +		errx(1, "Usage:\n"
> +		        "       hdata [-v|-q|-t] <spira-dump> <heap-dump>\n"
> +		        "       hdata -s [-v|-q|-t] <spirah-dump> <spiras-dump>\n");
> +	}
>  
>  	/* Copy in spira dump (assumes little has changed!). */
> -	fd = open(argv[1], O_RDONLY);
> -	if (fd < 0)
> -		err(1, "opening %s", argv[1]);
> -	r = read(fd, &spira, sizeof(spira));
> -	if (r < sizeof(spira.hdr))
> -		err(1, "reading %s gave %i", argv[1], r);
> -	if (verbose)
> -		printf("verbose: read spira %u bytes\n", r);
> -	close(fd);
> -
> -	undefined_bytes((void *)&spira + r, sizeof(spira) - r);
> +	if (new_spira) {
> +		fd = open(argv[1], O_RDONLY);
> +		if (fd < 0)
> +			err(1, "opening %s", argv[1]);
> +		r = read(fd, &spirah, sizeof(spirah));
> +		if (r < sizeof(spirah.hdr))
> +			err(1, "reading %s gave %i", argv[1], r);
> +		if (verbose)
> +			printf("verbose: read spirah %u bytes\n", r);
> +		close(fd);
> +
> +		undefined_bytes((void *)&spirah + r, sizeof(spirah) - r);
> +
> +		base_addr = be64_to_cpu(spirah.ntuples.hs_data_area.addr);
> +	} else {
> +		fd = open(argv[1], O_RDONLY);
> +		if (fd < 0)
> +			err(1, "opening %s", argv[1]);
> +		r = read(fd, &spira, sizeof(spira));
> +		if (r < sizeof(spira.hdr))
> +			err(1, "reading %s gave %i", argv[1], r);
> +		if (verbose)
> +			printf("verbose: read spira %u bytes\n", r);
> +		close(fd);
> +
> +		undefined_bytes((void *)&spira + r, sizeof(spira) - r);
> +
> +		base_addr = be64_to_cpu(spira.ntuples.heap.addr);
> +	}
>  
> -	base_addr = be64_to_cpu(spira.ntuples.heap.addr);
>  	if (!base_addr)
>  		errx(1, "Invalid base addr");
>  	if (verbose)
> @@ -181,6 +202,9 @@ int main(int argc, char *argv[])
>  		       spira_heap_size, spira_heap);
>  	close(fd);
>  
> +	if (new_spira)
> +		spiras = (struct spiras *)spira_heap;
> +
>  	if (quiet) {
>  		fclose(stdout);
>  		fclose(stderr);


More information about the Skiboot mailing list