From 70199118e1bf5776029cfb261055f76e2f5737d3 Mon Sep 17 00:00:00 2001 From: Claus Michael Olsen Date: Thu, 16 Feb 2017 15:06:22 -0600 Subject: xip_tool: Now dumping raw decompressed DATA and CARE nibbles. Change-Id: If938045f9cf31529b8bdf7d5771b76a865a5a1dd Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/36585 Tested-by: Jenkins Server Reviewed-by: Sumit Kumar Reviewed-by: Martin Peschke Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/36615 Reviewed-by: Hostboot Team Reviewed-by: Sachin Gupta --- src/import/chips/p9/xip/p9_xip_tool.C | 112 +++++++++++++++++++++++++++++----- 1 file changed, 97 insertions(+), 15 deletions(-) (limited to 'src/import/chips/p9/xip/p9_xip_tool.C') diff --git a/src/import/chips/p9/xip/p9_xip_tool.C b/src/import/chips/p9/xip/p9_xip_tool.C index 21c06b90..081249f9 100644 --- a/src/import/chips/p9/xip/p9_xip_tool.C +++ b/src/import/chips/p9/xip/p9_xip_tool.C @@ -61,7 +61,8 @@ enum LISTING_MODE_ID LMID_TABLE, LMID_SHORT, LMID_NORMAL, // default - LMID_LONG + LMID_LONG, + LMID_RAW }; // Usage: p9_xip_tool [- ...] normalize @@ -74,7 +75,7 @@ enum LISTING_MODE_ID // p9_xip_tool [- ...] append
// p9_xip_tool [- ...] extract
// p9_xip_tool [- ...] delete
[ ... ] -// p9_xip_tool [- ...] dissect [table,short,normal(default),long] +// p9_xip_tool [- ...] dissect [table,short,normal(default),long,raw] // p9_xip_tool [- ...] disasm // // This simple application uses the P9-XIP image APIs to normalize, search @@ -141,8 +142,9 @@ enum LISTING_MODE_ID // is included in the listing: // table: Tabular overview. // short: The bare necessities. -// normal: Everything but a raw binary dump of the actual ring block. -// long: Everything inclusing a raw binary dump of the actual ring block. +// normal: Everything except a binary dump of the ring block. +// long: Everything including a binary dump of the ring block. +// raw: Everything including a dump of the raw decompressed ring. // Note that iff the second argument is omitted, a 'normal' listing of the ring // section will occur. // @@ -167,7 +169,7 @@ const char* g_usage = " p9_xip_tool [-i ...] extract
\n" " p9_xip_tool [-i ...] delete
[ ... ]\n" " p9_xip_tool [-i ...] dis
\n" - " p9_xip_tool [-i ...] dissect [table,short,normal(default),long]\n" + " p9_xip_tool [-i ...] dissect [table,short,normal(default),long,raw]\n" " p9_xip_tool [-i ...] disasm \n" " p9_xip_tool [-i ...] check-sbe-ring-section
\n" "\n" @@ -231,12 +233,13 @@ const char* g_usage = "\n" "The 'dissect' command dissects the ring section named by the section argument\n" "and summarizes the content of the ring section. The second argument to\n" - "'dissect', i.e. [table,short,normal(default),long], specifies how much information\n" + "'dissect', i.e. [table,short,normal(default),long,raw], specifies how much information\n" "is included in the listing:\n" " table: Tabular overview.\n" " short: The bare necessities.\n" - " normal: Everything but a raw binary dump of the actual ring block.\n" - " long: Everything inclusing a raw binary dump of the actual ring block.\n" + " normal: Everything except a binary dump of the ring block.\n" + " long: Everything including a binary dump of the ring block.\n" + " raw: Everything including a dump of the raw decompressed ring.\n" "Note that if the second argument is omitted, a 'normal' listing of the ring\n" "section will occur.\n" "\n" @@ -1721,6 +1724,60 @@ TEST(void* io_image, const int i_argc, const char** i_argv) #ifdef XIP_TOOL_ENABLE_DISSECT // Needed on the ppe side to avoid TOR API + +// This function prints out the raw decompressed ring content in the same +// format that it appears as in EKB's ifCompiler generated raw ring +// files, i.e. *.bin.srd (DATA) and *.bin.srd.bitsModified (CARE). +static +void printRawRing( uint8_t* data, + uint32_t bits) +{ + uint32_t i; + uint8_t bytePerWordCount = 0; // Nibble count in each word + uint32_t bytePerLineCount = 0; // Column count + uint8_t rem = bits % 8; // Rem raw bits beyond 1-byte boundary + uint8_t nibblesToPrint; // The last 1 or 2 nibbles to dump + + for (i = 0; i < bits / 8; i++) + { + fprintf( stdout, "%02x", *(data + i)); + + if (++bytePerWordCount == 4) + { + fprintf( stdout, " "); + bytePerWordCount = 0; + } + + if (++bytePerLineCount == 32) + { + fprintf( stdout, "\n"); + bytePerLineCount = 0; + } + } + + // Dump remaining bits (in whole nibbles and with any + // unused bits being zeroed) + if (rem) + { + // Ensure the rightmost (8-rem) unused bits are zeroed out + nibblesToPrint = (*(data + i) >> (8 - rem)) << (8 - rem); + + if (rem <= 4) + { + // Content only in first nibble. Dump only first nibble + fprintf( stdout, "%01x", nibblesToPrint >> 4); + } + else + { + // Content in both nibbles. Dump both nibbles + fprintf( stdout, "%02x", nibblesToPrint); + } + } + + fprintf( stdout, "\n"); +} + + //@FIXME: This should be improved. Probably defined somewhere else. #define CHIPLET_ID_MAX (uint8_t)0x37 @@ -1732,7 +1789,7 @@ TEST(void* io_image, const int i_argc, const char** i_argv) /// /// \param[in] i_imageMagicNo The image's MAGIC number. /// -/// \param[in] i_listingModeId The listing mode: {table, short, normal(default), long}. +/// \param[in] i_listingModeId The listing mode: {table, short, normal(default), long, raw}. /// /// Assumptions: /// - Dissection only works with .rings section. It does not work with .overrides @@ -1918,8 +1975,10 @@ int dissectRingSectionTor( void* i_ringSection, ringVariantName[ringVariant], instanceId ); } - // Summarize all characteristics of the ring block if "normal" or "long" (default). - if ( i_listingModeId == LMID_NORMAL || i_listingModeId == LMID_LONG ) + // Summarize all characteristics of the ring block if "normal", "long" or "raw" + if (i_listingModeId == LMID_NORMAL || + i_listingModeId == LMID_LONG || + i_listingModeId == LMID_RAW) { fprintf( stdout, "-----------------------------\n" @@ -1930,14 +1989,17 @@ int dissectRingSectionTor( void* i_ringSection, "ringName = %s\n" "ringVariant = %s\n" "instanceId = 0x%02x\n" - "ringBlockSize = 0x%08x\n", + "ringBlockSize = 0x%08x\n" + "raw bit length = %d\n" + "compression [%%] = %6.2f\n", ringSeqNo, ddLevel, ppeTypeName[ppeType], ringId, ringName, ringVariantName[ringVariant], instanceId, - ringBlockSize); + ringBlockSize, bits, comprRate); } - // Dump ring block if "long". - if (i_listingModeId == LMID_LONG) + // Dump ring block if "long" or "raw" + if (i_listingModeId == LMID_LONG || + i_listingModeId == LMID_RAW) { fprintf(stdout, "Binary ring block dump (LE format):\n"); @@ -1953,6 +2015,20 @@ int dissectRingSectionTor( void* i_ringSection, } } + // Below we dump the raw decompressed ring content in the exact same + // format that it appears as in EKB's ifCompiler generated raw ring + // files, i.e. *.bin.srd (DATA) and *.bin.srd.bitsModified (CARE). + if (i_listingModeId == LMID_RAW) + { + fprintf( stdout, "\nRaw decompressed DATA nibbles:\n"); + printRawRing( data, bits); + + fprintf( stdout, "\nRaw decompressed CARE nibbles:\n"); + printRawRing( care, bits); + + fprintf( stdout, "\n"); + } + free(data); free(care); } @@ -2114,13 +2190,19 @@ int dissectRingSection(void* i_image, { listingModeId = LMID_LONG; } + else if (strcmp(listingModeName, "raw") == 0) + { + listingModeId = LMID_RAW; + } else { fprintf(stderr, "ERROR : %s is an invalid listing mode name.\n", listingModeName); fprintf(stderr, "Valid listing mode names the 'dissect' function are:\n"); + fprintf(stderr, "\ttable\n"); fprintf(stderr, "\tshort\n"); fprintf(stderr, "\tnormal (default if omitted)\n"); fprintf(stderr, "\tlong\n"); + fprintf(stderr, "\traw\n"); exit(1); } -- cgit v1.2.1