diff options
author | Richard J. Knight <rjknight@us.ibm.com> | 2016-12-11 08:50:55 -0600 |
---|---|---|
committer | Joshua Hunsberger <jahunsbe@us.ibm.com> | 2017-10-23 17:04:21 -0500 |
commit | b2390a76461552ba4f244457fdb4278a8009011a (patch) | |
tree | 5b405ef9bf2e4cf098725c084c41d8c7ff3812c9 /import/chips | |
parent | 1f939826fcf21ac0dab1ae4bd8a5558603cac911 (diff) | |
download | talos-hcode-b2390a76461552ba4f244457fdb4278a8009011a.tar.gz talos-hcode-b2390a76461552ba4f244457fdb4278a8009011a.zip |
Add check to verify SBE .ring section size
-Add option to p9_xip_tool to verify the size of the
DD specific .rings section intended for the SBE image
-Update makefiles to correctly run p9_ring_apply to insert
and extract the DD level specific rings.
-Update tor_access_ring to correctly advance the pointer
to the next DD level in the HW image so the size can
be extracted correctlty.
Change-Id: I21a53b5d11341a14a4e9cc88388c9c2050394095
RTC:165558
Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/33873
Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com>
Tested-by: PPE CI <ppe-ci+hostboot@us.ibm.com>
Tested-by: Hostboot CI <hostboot-ci+hostboot@us.ibm.com>
Reviewed-by: Joseph J. McGill <jmcgill@us.ibm.com>
Reviewed-by: Thi N. Tran <thi@us.ibm.com>
Reviewed-by: Sachin Gupta <sgupta2m@in.ibm.com>
Reviewed-by: Jennifer A. Stofer <stofer@us.ibm.com>
Diffstat (limited to 'import/chips')
-rw-r--r-- | import/chips/p9/utils/imageProcs/p9_tor.C | 15 | ||||
-rw-r--r-- | import/chips/p9/xip/p9_xip_image.h | 4 | ||||
-rw-r--r-- | import/chips/p9/xip/p9_xip_tool.C | 111 |
3 files changed, 121 insertions, 9 deletions
diff --git a/import/chips/p9/utils/imageProcs/p9_tor.C b/import/chips/p9/utils/imageProcs/p9_tor.C index 1e3dcc30..30f4c4b1 100644 --- a/import/chips/p9/utils/imageProcs/p9_tor.C +++ b/import/chips/p9/utils/imageProcs/p9_tor.C @@ -1191,12 +1191,14 @@ int tor_access_ring( void* i_ringSection, // Ring section ptr MY_INF("tor_access_ring(): No of DD levels: %d \n", ddLevelCount); } - for (uint8_t i = 0; i < ddLevelCount; i++) + // start at one since we use that as an offset + for (uint8_t i = 1; i <= ddLevelCount; i++) { - local = 2; + local = 2 * (i); ddLevelOffset = *((uint32_t*)i_ringSection + local); - ddLevel = htobe32(ddLevelOffset) >> 24 & 0x000000FF; - ddLevelOffset = htobe32(ddLevelOffset) & 0x00FFFFFF; + + ddLevel = be32toh(ddLevelOffset) >> 24 & 0x000000FF; + ddLevelOffset = be32toh(ddLevelOffset) & 0x00FFFFFF; if (i_dbgl > 1) { @@ -1206,12 +1208,11 @@ int tor_access_ring( void* i_ringSection, // Ring section ptr if ( ddLevel == i_ddLevel) { - ddLevelOffset = *((uint32_t*)i_ringSection + local); - ddLevelOffset = htobe32(ddLevelOffset) & 0x00FFFFFF; ddLevelOffset = ddLevelOffset + sizeof(TorNumDdLevels_t); local = local + 1; ddBlockSize = *((uint32_t*)i_ringSection + local); - ddBlockSize = htobe32(ddBlockSize); + ddBlockSize = be32toh(ddBlockSize); + bDdCheck = 1; break; } diff --git a/import/chips/p9/xip/p9_xip_image.h b/import/chips/p9/xip/p9_xip_image.h index e7994ec7..fc917903 100644 --- a/import/chips/p9/xip/p9_xip_image.h +++ b/import/chips/p9/xip/p9_xip_image.h @@ -1454,6 +1454,9 @@ p9_xip_decode_toc_dump(void* i_image, void* i_dump, /// Image has been broken and unable to restore original image. #define P9_XIP_CANT_RESTORE_IMAGE 18 +/// .rings seciton for specific dd level is larger than the allowable size +#define P9_XIP_SBE_DD_SIZE_ERR 19 + /// Applications can expand this macro to declare an array of string forms of /// the error codes if desired. #define P9_XIP_ERROR_STRINGS(var) \ @@ -1477,6 +1480,7 @@ p9_xip_decode_toc_dump(void* i_image, void* i_dump, "P9_XIP_HASH_COLLISION", \ "P9_XIP_NULL_BUFFER", \ "P9_XIP_CANT_RESTORE_IMAGE", \ + "P9_XIP_SBE_DD_SIZE_ERR", \ } /// Applications can use this macro to safely index the array of error diff --git a/import/chips/p9/xip/p9_xip_tool.C b/import/chips/p9/xip/p9_xip_tool.C index 78a5a697..8567e794 100644 --- a/import/chips/p9/xip/p9_xip_tool.C +++ b/import/chips/p9/xip/p9_xip_tool.C @@ -41,8 +41,6 @@ #include <string.h> #include <unistd.h> -#define __PPE__ - #include "p9_xip_image.h" #ifdef XIP_TOOL_ENABLE_DISSECT // Needed on ppe side to avoid TOR API #include "p9_tor.H" @@ -167,6 +165,7 @@ const char* g_usage = " p9_xip_tool <image> [-i<flag> ...] dis <section>\n" " p9_xip_tool <image> [-i<flag> ...] dissect <ring section> [short,normal(default),long]\n" " p9_xip_tool <image> [-i<flag> ...] disasm <text section>\n" + " p9_xip_tool <image> [-i<flag> ...] check-sbe-ring-section <dd level> <maximum size>\n" "\n" "This simple application uses the P9-XIP image APIs to normalize, search\n" "update and edit P9-XIP images. This program encapsulates several commands\n" @@ -2271,6 +2270,93 @@ openAndMapReadOnly(const char* i_imageFile, int* o_fd, void** o_image, const uin openAndMap(i_imageFile, 0, o_fd, o_image, i_maskIgnores); } +/// +/// @brief Checks .rings section created for SBE image to +/// see if it is less than the passed in size. +/// +/// @param[in] i_hwImage - pointer to an unsigned hw image. +/// @param[in] i_ddLevel - DD level .rings section to check +/// @param[in] i_maxSize - Maximum allowable section size +/// +/// @return IMGBUILD_SUCCESS if section is less than i_maxSize +/// +static +int check_sbe_ring_section_size( void* i_hwImage, + uint32_t i_ddLevel, + uint32_t i_maxSize ) +{ + int rc = 0; +#ifndef __PPE__ + + P9XipSection l_ringsSection; + + RingType_t l_ringType = ALLRING; + + uint8_t unused_parm = 0; + void** l_blockPtr = NULL; + uint32_t l_blockSize = 0; + + // Get the full .rings section from the HW image + rc = p9_xip_get_section(i_hwImage, P9_XIP_SECTION_HW_RINGS, &l_ringsSection); + + if (!rc) + { + // verify the .rings section is populated + if (l_ringsSection.iv_size == 0) + { + fprintf(stderr, "Ring section size in HW image is zero.\n"); + rc = P9_XIP_DATA_NOT_PRESENT; + return rc; + } + + // Make a pointer to the start of the rings section + void* ringsSection = (uint8_t*)i_hwImage + l_ringsSection.iv_offset; + + do + { + // Call the tor function will a null block pointer to get the + // section size + rc = tor_get_block_of_rings( ringsSection, + i_ddLevel, + SBE, + l_ringType, + BASE, + unused_parm, + l_blockPtr, + l_blockSize); + + if(rc) + { + fprintf(stderr, "error calling tor API rc = %d\n", rc); + break; + } + + if( l_blockSize == 0 ) + { + fprintf(stderr, "No rings for dd_level %#02x found\n", i_ddLevel); + break; + } + + fprintf(stderr, " SBE .ring section size for DD level %#02x ", i_ddLevel); + + // return failure if the block size would exceed the maximum allowed size + if( l_blockSize > i_maxSize ) + { + fprintf(stderr, "is %d bytes, which exceeds maximum size limit of %i\n", l_blockSize, i_maxSize); + rc = P9_XIP_SBE_DD_SIZE_ERR; + } + else + { + fprintf(stderr, "is %d bytes - OK\n", l_blockSize); + } + + } + while(0); + } + +#endif + return rc; +} // Parse and execute a pre-tokenized command @@ -2381,6 +2467,27 @@ command(const char* i_imageFile, const int i_argc, const char** i_argv, const ui exit(1); } + else if (strcmp(i_argv[0], "check-sbe-ring-section") == 0) + { + if(i_argc != 3) + { + fprintf(stderr, g_usage); + exit(1); + } + + openAndMapWritable(i_imageFile, &fd, &image, i_maskIgnores); + + // grab the size and dd level from the cmdline + const char* i_ddLevel = i_argv[1]; + + uint8_t l_ddLevel = strtol(i_ddLevel, 0, 0); + + uint32_t l_maxSize = strtol(i_argv[2], 0, 10); + + // validate that the dd level specific .rings section generated for the + // sbe image will not exceed the given size. + rc = check_sbe_ring_section_size(image, l_ddLevel, l_maxSize) ; + } else if (strcmp(i_argv[0], "TEST") == 0) { |