tools/intel_bios_reader: abstract header information dumping
PATCH 1/3 tools/intel_bios_reader: abstract header information dumping
Signed-off-by Jani Nikula <[email protected]>
--- tools/intel_bios_reader.c | 52 +++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 22 deletions(-)
tools/intel_bios_reader.c +30 -22
@@ -62,6 +62,7 @@ struct bdb_block { };struct context { +const struct vbt_header *vbt;const struct bdb_header *bdb;int size;
@@ -1405,6 +1406,32 @@ static bool dump_section(struct context *context, int section_id)return true; } +static void dump_headers (struct context *context) +{ +char signature[17 ]; +int i; + +printf ("VBT vers: %d.%d\n" , + context->vbt->version /100 , context->vbt->version %100 ); + +strncpy (signature, (char *)context->bdb->signature,16 ); + signature[16 ] =0 ; +printf ("BDB sig: %s\n" , signature); +printf ("BDB vers: %d\n" , context->bdb->version); + +printf ("Available sections: " ); +for (i =0 ; i <256 ; i++) { +struct bdb_block *block; + + block =find_section (context, i); +if (!block) +continue ; +printf ("%d " , i); +free (block); + } +printf ("\n" ); +} +enum opt {OPT_UNKNOWN ='?' ,OPT_END =-1 ,
@@ -1441,11 +1468,9 @@ int main(int argc, char **argv)const char *toolname = argv[0 ];struct stat finfo;int size; -struct bdb_header *bdb;struct context context = { .panel_type =-1 , }; -char signature[17 ];char *endp;int block_number =-1 ;
@@ -1570,34 +1595,17 @@ int main(int argc, char **argv)return 1 ; } -printf ("VBT vers: %d.%d\n" , vbt->version /100 , vbt->version %100 ); - bdb_off = vbt_off + vbt->bdb_offset;if (bdb_off >= size -sizeof (struct bdb_header )) {printf ("Invalid VBT found, BDB points beyond end of data block\n" );return 1 ; } - bdb = (struct bdb_header *)(VBIOS + bdb_off); -strncpy (signature, (char *)bdb->signature,16 ); - signature[16 ] =0 ; -printf ("BDB sig: %s\n" , signature); -printf ("BDB vers: %d\n" , bdb->version); - - context.bdb = bdb; + context.vbt = vbt; + context.bdb = (const struct bdb_header *)(VBIOS + bdb_off); context.size = size; -printf ("Available sections: " ); -for (i =0 ; i <256 ; i++) { -struct bdb_block *block; - - block =find_section (&context, i); -if (!block) -continue ; -printf ("%d " , i); -free (block); - } -printf ("\n" ); +dump_headers (&context);if (!context.devid) {const char *devid_string =getenv ("DEVICE" );
Signature · 6 lines
2.1.4 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 2/3 tools/intel_bios_reader: clean up VBT/BDB header dumping
Make the output nicer. Do not print the header if a specific block is requested.
Signed-off-by Jani Nikula <[email protected]>
--- tools/intel_bios_reader.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-)
tools/intel_bios_reader.c +19 -13
@@ -1408,28 +1408,34 @@ static bool dump_section(struct context *context, int section_id)static void dump_headers (struct context *context) { -char signature[17 ]; -int i; +const struct vbt_header *vbt = context->vbt; +const struct bdb_header *bdb = context->bdb; +int i, j =0 ; -printf ("VBT vers: %d.%d\n" , - context->vbt->version /100 , context->vbt->version %100 ); +printf ("VBT signature:\t\"%.*s\"\n" , + (int )sizeof (vbt->signature), vbt->signature); +printf ("VBT version:\t%d.%d\n" , vbt->version /100 , vbt->version %100 ); -strncpy (signature, (char *)context->bdb->signature,16 ); - signature[16 ] =0 ; -printf ("BDB sig: %s\n" , signature); -printf ("BDB vers: %d\n" , context->bdb->version); +printf ("BDB signature:\t\"%.*s\"\n" , + (int )sizeof (bdb->signature), bdb->signature); +printf ("BDB version:\t%d\n" , bdb->version); -printf ("Available sections: " ); +printf ("BDB blocks present:" );for (i =0 ; i <256 ; i++) {struct bdb_block *block; block =find_section (context, i);if (!block)continue ; -printf ("%d " , i); + +if (j++ %16 ) +printf (" %3d" , i); +else +printf ("\n\t%3d" , i); +free (block); } -printf ("\n" ); +printf ("\n\n" ); }enum opt {
@@ -1605,8 +1611,6 @@ int main(int argc, char **argv) context.bdb = (const struct bdb_header *)(VBIOS + bdb_off); context.size = size; -dump_headers (&context); -if (!context.devid) {const char *devid_string =getenv ("DEVICE" );if (devid_string)
@@ -1631,6 +1635,8 @@ int main(int argc, char **argv)return EXIT_FAILURE ; } }else { +dump_headers (&context); +/* dump all sections */ for (i =0 ; i <256 ; i++)dump_section (&context, i);
Signature · 6 lines
2.1.4 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH 3/3 tools/intel_bios_reader: print errors to stderr, return EXIT_FAILURE
In reply to Jani NikulaBe consistent with exit status and printing errors to stderr.
Signed-off-by Jani Nikula <[email protected]>
--- tools/intel_bios_reader.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-)
tools/intel_bios_reader.c +17 -15
@@ -101,7 +101,7 @@ static struct bdb_block *find_section(struct context *context, int section_id) block =malloc (sizeof (*block));if (!block) {fprintf (stderr,"out of memory\n" ); -exit (-1 ); +exit (EXIT_FAILURE ); }/* walk the sections looking for section_id */
@@ -1551,14 +1551,15 @@ int main(int argc, char **argv) fd =open (filename,O_RDONLY );if (fd ==-1 ) { -printf ("Couldn't open \"%s\": %s\n" , filename,strerror (errno)); -return 1 ; +fprintf (stderr,"Couldn't open \"%s\": %s\n" , + filename,strerror (errno)); +return EXIT_FAILURE ; }if (stat (filename, &finfo)) { -printf ("failed to stat \"%s\": %s\n" , filename, -strerror (errno)); -return 1 ; +fprintf (stderr,"Failed to stat \"%s\": %s\n" , + filename,strerror (errno)); +return EXIT_FAILURE ; } size = finfo.st_size;
@@ -1568,9 +1569,9 @@ int main(int argc, char **argv)VBIOS =malloc (size);while ((ret =read (fd,VBIOS + len, size - len))) {if (ret <0 ) { -printf ("failed to read \"%s\": %s\n" , filename, -strerror (errno)); -return 1 ; +fprintf (stderr,"Failed to read \"%s\": %s\n" , + filename,strerror (errno)); +return EXIT_FAILURE ; } len += ret;
@@ -1582,8 +1583,9 @@ int main(int argc, char **argv) }else {VBIOS =mmap (NULL , size,PROT_READ ,MAP_SHARED , fd,0 );if (VBIOS ==MAP_FAILED ) { -printf ("failed to map \"%s\": %s\n" , filename,strerror (errno)); -return 1 ; +fprintf (stderr,"Failed to map \"%s\": %s\n" , + filename,strerror (errno)); +return EXIT_FAILURE ; } }
@@ -1597,14 +1599,14 @@ int main(int argc, char **argv) }if (!vbt) { -printf ("VBT signature missing\n" ); -return 1 ; +fprintf (stderr,"VBT signature missing\n" ); +return EXIT_FAILURE ; } bdb_off = vbt_off + vbt->bdb_offset;if (bdb_off >= size -sizeof (struct bdb_header )) { -printf ("Invalid VBT found, BDB points beyond end of data block\n" ); -return 1 ; +fprintf (stderr,"Invalid VBT found, BDB points beyond end of data block\n" ); +return EXIT_FAILURE ; } context.vbt = vbt;
Signature · 6 lines
2.1.4 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Fairly simple stuff, pushed the series to igt.
BR,
Jani.
Quoted 100 lines · Jani Nikula
Signed-off-by Jani Nikula <[email protected]>--- tools/intel_bios_reader.c | 52 +++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 22 deletions(-)tools/intel_bios_reader.c +30
-22@@ -62,6 +62,7 @@ struct bdb_block { };struct context { +const struct vbt_header *vbt;const struct bdb_header *bdb;int size;@@ -1405,6 +1406,32 @@ static bool dump_section(struct context *context, int section_id)return true; } +static void dump_headers (struct context *context) +{ +char signature[17 ]; +int i; + +printf ("VBT vers: %d.%d\n" , + context->vbt->version /100 , context->vbt->version %100 ); + +strncpy (signature, (char *)context->bdb->signature,16 ); + signature[16 ] =0 ; +printf ("BDB sig: %s\n" , signature); +printf ("BDB vers: %d\n" , context->bdb->version); + +printf ("Available sections: " ); +for (i =0 ; i <256 ; i++) { +struct bdb_block *block; + + block =find_section (context, i); +if (!block) +continue ; +printf ("%d " , i); +free (block); + } +printf ("\n" ); +} +enum opt {OPT_UNKNOWN ='?' ,OPT_END =-1 ,@@ -1441,11 +1468,9 @@ int main(int argc, char **argv)const char *toolname = argv[0 ];struct stat finfo;int size; -struct bdb_header *bdb;struct context context = { .panel_type =-1 , }; -char signature[17 ];char *endp;int block_number =-1 ;@@ -1570,34 +1595,17 @@ int main(int argc, char **argv)return 1 ; } -printf ("VBT vers: %d.%d\n" , vbt->version /100 , vbt->version %100 ); - bdb_off = vbt_off + vbt->bdb_offset;if (bdb_off >= size -sizeof (struct bdb_header )) {printf ("Invalid VBT found, BDB points beyond end of data block\n" );return 1 ; } - bdb = (struct bdb_header *)(VBIOS + bdb_off); -strncpy (signature, (char *)bdb->signature,16 ); - signature[16 ] =0 ; -printf ("BDB sig: %s\n" , signature); -printf ("BDB vers: %d\n" , bdb->version); - - context.bdb = bdb; + context.vbt = vbt; + context.bdb = (const struct bdb_header *)(VBIOS + bdb_off); context.size = size; -printf ("Available sections: " ); -for (i =0 ; i <256 ; i++) { -struct bdb_block *block; - - block =find_section (&context, i); -if (!block) -continue ; -printf ("%d " , i); -free (block); - } -printf ("\n" ); +dump_headers (&context);if (!context.devid) {const char *devid_string =getenv ("DEVICE" );
Signature · 5 lines
Jani Nikula, Intel Open Source Technology Center _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx