diff options
| author | Claus Michael Olsen <cmolsen@us.ibm.com> | 2017-09-21 22:58:58 -0500 |
|---|---|---|
| committer | Joshua Hunsberger <jahunsbe@us.ibm.com> | 2017-10-23 19:24:18 -0500 |
| commit | 1a1d1bdf7dc4d1ac259aae451d607d6f069f913b (patch) | |
| tree | 756789eeca6e5570086ff5613866583ce5a4bc91 /import/chips/p9/utils | |
| parent | 1faad3a5ca8a28c311a85ccafae4159e5a52afe1 (diff) | |
| download | talos-hcode-1a1d1bdf7dc4d1ac259aae451d607d6f069f913b.tar.gz talos-hcode-1a1d1bdf7dc4d1ac259aae451d607d6f069f913b.zip | |
Overlays and multi-DD XIP related updates to xip_image and dd_container
to support WIN32 for manu team.
Also,
- various updates to dd_container error handling,
- improved DD support query checking.
Change-Id: I706e56258894c3453cf01aa1a637fe888af1db00
Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/46596
Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com>
Reviewed-by: Richard J. Knight <rjknight@us.ibm.com>
Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com>
Tested-by: HWSV CI <hwsv-ci+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: Jennifer A. Stofer <stofer@us.ibm.com>
Diffstat (limited to 'import/chips/p9/utils')
| -rw-r--r-- | import/chips/p9/utils/imageProcs/p9_dd_container.c | 42 | ||||
| -rw-r--r-- | import/chips/p9/utils/imageProcs/p9_dd_container.h | 23 | ||||
| -rw-r--r-- | import/chips/p9/utils/imageProcs/p9_dd_container_tool.c | 84 |
3 files changed, 86 insertions, 63 deletions
diff --git a/import/chips/p9/utils/imageProcs/p9_dd_container.c b/import/chips/p9/utils/imageProcs/p9_dd_container.c index 7e9e733f..574fd5d5 100644 --- a/import/chips/p9/utils/imageProcs/p9_dd_container.c +++ b/import/chips/p9/utils/imageProcs/p9_dd_container.c @@ -23,10 +23,14 @@ /* */ /* IBM_PROLOG_END_TAG */ -#include <stdint.h> +#ifdef WIN32 + #include "endian.h" +#else + #include <endian.h> +#endif + #include <stddef.h> #include <stdlib.h> -#include <endian.h> #include <string.h> #include <stdio.h> @@ -36,17 +40,17 @@ int p9_dd_validate(struct p9_dd_cont* i_cont) { if (!i_cont) { - return P9_DD_FAILURE_DOES_NOT_EXIST; + return DDCO_DDCO_DOES_NOT_EXIST; } - if (be32toh(i_cont->iv_magic) != P9_DD_CONTAINER_MAGIC) + if (be32toh(i_cont->iv_magic) != DD_CONTAINER_MAGIC) { - return P9_DD_FAILURE_BROKEN; + return DDCO_FAILURE_MAGIC_NOT_FOUND; } // may want to check here for holes or overlap as to stored blocks - return P9_DD_SUCCESS; + return DDCO_SUCCESS; } // iterates through all dd level blocks @@ -84,14 +88,14 @@ void p9_dd_betoh(struct p9_dd_block* i_block_be, int p9_dd_get(uint8_t* i_cont, uint8_t i_dd, uint8_t** o_buf, uint32_t* o_size) { struct p9_dd_cont* cont = (struct p9_dd_cont*)i_cont; - struct p9_dd_iter iter = P9_DD_ITER_INIT(cont); + struct p9_dd_iter iter = {cont, 0}; struct p9_dd_block* block; struct p9_dd_block block_he; int rc; rc = p9_dd_validate(cont); - if (rc != P9_DD_SUCCESS) + if (rc != DDCO_SUCCESS) { return rc; } @@ -103,11 +107,11 @@ int p9_dd_get(uint8_t* i_cont, uint8_t i_dd, uint8_t** o_buf, uint32_t* o_size) p9_dd_betoh(block, &block_he); *o_buf = p9_dd_addr(cont, block_he.iv_offset); *o_size = block_he.iv_size; - return P9_DD_SUCCESS; + return DDCO_SUCCESS; } } - return P9_DD_FAILURE_NOT_FOUND; + return DDCO_DDLEVEL_NOT_FOUND; } uint32_t p9_dd_size_meta(struct p9_dd_cont* i_cont) @@ -150,7 +154,7 @@ struct p9_dd_cont* p9_dd_create(void) return cont; } - cont->iv_magic = htobe32(P9_DD_CONTAINER_MAGIC); + cont->iv_magic = htobe32(DD_CONTAINER_MAGIC); cont->iv_num = 0; return cont; @@ -179,28 +183,28 @@ int p9_dd_add( uint32_t this_offs; struct p9_dd_block* this_block; - struct p9_dd_iter iter = P9_DD_ITER_INIT(NULL); + struct p9_dd_iter iter = {NULL, 0}; // handle duplicates and initial setup of empty container rc = p9_dd_get(*io_cont, i_dd, &dupl_buf, &dupl_size); switch (rc) { - case P9_DD_FAILURE_NOT_FOUND : + case DDCO_DDLEVEL_NOT_FOUND : break; - case P9_DD_FAILURE_DOES_NOT_EXIST : + case DDCO_DDCO_DOES_NOT_EXIST : cont = p9_dd_create(); if (!cont) { - return P9_DD_FAILURE_NOMEM; + return DDCO_FAILURE_NOMEM; } break; - case P9_DD_SUCCESS : - return P9_DD_FAILURE_DUPLICATE; + case DDCO_SUCCESS : + return DDCO_DUPLICATE_DDLEVEL; default : return rc; @@ -214,7 +218,7 @@ int p9_dd_add( if (!cont) { - return P9_DD_FAILURE_NOMEM; + return DDCO_FAILURE_NOMEM; } // offsets and size of existing bufs @@ -258,5 +262,5 @@ int p9_dd_add( *io_cont = (uint8_t*)cont; *o_cont_size = enlarged; - return P9_DD_SUCCESS; + return DDCO_SUCCESS; } diff --git a/import/chips/p9/utils/imageProcs/p9_dd_container.h b/import/chips/p9/utils/imageProcs/p9_dd_container.h index 6a373587..b6173cb8 100644 --- a/import/chips/p9/utils/imageProcs/p9_dd_container.h +++ b/import/chips/p9/utils/imageProcs/p9_dd_container.h @@ -26,16 +26,20 @@ #ifndef _P9_DD_CONTAINER_H_ #define _P9_DD_CONTAINER_H_ -#include <stdint.h> +#ifdef WIN32 + #include "win32_stdint.h" +#else + #include <stdint.h> +#endif -#define P9_DD_CONTAINER_MAGIC 0x4444434F // "DDCO" +#define DD_CONTAINER_MAGIC 0x4444434F // "DDCO" -#define P9_DD_SUCCESS 0 -#define P9_DD_FAILURE_BROKEN 1 -#define P9_DD_FAILURE_NOMEM 2 -#define P9_DD_FAILURE_NOT_FOUND 3 -#define P9_DD_FAILURE_DOES_NOT_EXIST 4 -#define P9_DD_FAILURE_DUPLICATE 5 +#define DDCO_SUCCESS 0 +#define DDCO_FAILURE_MAGIC_NOT_FOUND 1 +#define DDCO_FAILURE_NOMEM 2 +#define DDCO_DDLEVEL_NOT_FOUND 3 +#define DDCO_DDCO_DOES_NOT_EXIST 4 +#define DDCO_DUPLICATE_DDLEVEL 5 // header for each dd level block inside container struct p9_dd_block @@ -62,9 +66,6 @@ struct p9_dd_iter uint8_t iv_idx; }; -// initialisation of iterator -#define P9_DD_ITER_INIT(dd_cont) { .iv_cont = (dd_cont), .iv_idx = 0 } - #ifdef __cplusplus extern "C" { #endif diff --git a/import/chips/p9/utils/imageProcs/p9_dd_container_tool.c b/import/chips/p9/utils/imageProcs/p9_dd_container_tool.c index 016796e4..ddfda548 100644 --- a/import/chips/p9/utils/imageProcs/p9_dd_container_tool.c +++ b/import/chips/p9/utils/imageProcs/p9_dd_container_tool.c @@ -95,7 +95,7 @@ static const struct option options[] = static const char* optionstr = "c:nbo:h:d"; -int p9_dd_tool_read(uint8_t** buf, uint32_t* size, char* fn, int mandatory) +void p9_dd_tool_read(uint8_t** buf, uint32_t* size, char* fn, int mandatory) { FILE* fp; uint32_t read; @@ -106,13 +106,13 @@ int p9_dd_tool_read(uint8_t** buf, uint32_t* size, char* fn, int mandatory) { if (mandatory) { - printf("failed to open %s for reading\n", fn); - exit(-1); + printf("ERROR: p9_dd_tool_read(): Failed to open %s for reading\n", fn); + exit(EXIT_FAILURE); } *buf = NULL; *size = 0; - return *size; + return; } fseek(fp, 0, SEEK_END); @@ -125,26 +125,26 @@ int p9_dd_tool_read(uint8_t** buf, uint32_t* size, char* fn, int mandatory) if (!*buf) { - printf("failed to allocate buffer\n"); + printf("ERROR: p9_dd_tool_read(): Failed to allocate buffer\n"); fclose(fp); - exit(-1); + exit(EXIT_FAILURE); } read = fread(*buf, 1, *size, fp); if (read != *size) { - printf("failed to read %s\n", fn); - exit(-1); + printf("ERROR: p9_dd_tool_read(): Failed to read %s\n", fn); + exit(EXIT_FAILURE); } } fclose(fp); - return *size; + return; } -int p9_dd_tool_write(uint8_t* buf, uint32_t size, char* fn) +void p9_dd_tool_write(uint8_t* buf, uint32_t size, char* fn) { FILE* fp; uint32_t written; @@ -153,20 +153,21 @@ int p9_dd_tool_write(uint8_t* buf, uint32_t size, char* fn) if (!fp) { - printf("failed to open %s for writing\n", fn); - exit(-1); + printf("ERROR: p9_dd_tool_write(): Failed to open %s for writing\n", fn); + exit(EXIT_FAILURE); } written = fwrite(buf, 1, size, fp); if (written != size) { - printf("failed to write to %s\n", fn); - exit(-1); + printf("ERROR: p9_dd_tool_write(): Failed to write to %s\n", fn); + exit(EXIT_FAILURE); } fclose(fp); - return size; + + return; } int p9_dd_tool_add(int dd, char* fn_block, char* fn_cont) @@ -184,13 +185,17 @@ int p9_dd_tool_add(int dd, char* fn_block, char* fn_cont) { rc = p9_dd_add(&cont, &cont_size, dd, block, block_size); - if (rc == P9_DD_SUCCESS) + if (rc == DDCO_SUCCESS) + { + p9_dd_tool_write(cont, cont_size, fn_cont); + } + else if (rc == DDCO_DUPLICATE_DDLEVEL) { - rc = p9_dd_tool_write(cont, cont_size, fn_cont); + printf("WARNING: p9_dd_tool_add(): DD level already present in container.\n"); } else { - printf("failed, p9_dd_add returned %d\n", rc); + printf("ERROR: p9_dd_tool_add(): p9_dd_add() returned rc=0x%08x\n", rc); } } @@ -212,13 +217,13 @@ int p9_dd_tool_get(int dd, char* fn_block, char* fn_cont) rc = p9_dd_get(cont, dd, &block, &block_size); - if (rc == P9_DD_SUCCESS) + if (rc == DDCO_SUCCESS) { - rc = p9_dd_tool_write(block, block_size, fn_block); + p9_dd_tool_write(block, block_size, fn_block); } else { - printf("failed, p9_dd_get returned %d\n", rc); + printf("ERROR: p9_dd_tool_get(): p9_dd_get() returned %d\n", rc); } free(cont); @@ -230,7 +235,7 @@ int p9_dd_tool_list(char* fn_cont) { uint32_t cont_size; uint8_t* cont; - struct p9_dd_iter iter = P9_DD_ITER_INIT(NULL); + struct p9_dd_iter iter = {NULL, 0}; struct p9_dd_block* block; struct p9_dd_block block_he; @@ -250,6 +255,7 @@ int p9_dd_tool_list(char* fn_cont) int main(int argc, char* argv[]) { + int rc = DDCO_SUCCESS; char* fn_block = NULL; char* fn_cont = NULL; int dd = 0; @@ -258,8 +264,8 @@ int main(int argc, char* argv[]) if (argc == 1) { - printf("%s", usage); - exit(-1); + printf("ERROR: Missing arguments\n\n%s", usage); + exit(EXIT_FAILURE); } while (-1 != (option = getopt_long(argc, argv, optionstr, options, NULL))) @@ -285,8 +291,8 @@ int main(int argc, char* argv[]) case 'n' : if (sscanf(optarg, "0x%x", &dd) != 1) { - printf("%s", usage); - exit(-1); + printf("ERROR: Missing DD level. Must specify a DD level after --dd\n\n%s", usage); + exit(EXIT_FAILURE); } break; @@ -298,8 +304,8 @@ int main(int argc, char* argv[]) case 'o' : if (fn_cont) { - printf("%s", usage); - exit(-1); + printf("ERROR: Only one DD container is allowed\n\n%s", usage); + exit(EXIT_FAILURE); } fn_cont = strdup(optarg); @@ -314,8 +320,8 @@ int main(int argc, char* argv[]) exit(0); default : - printf("%s", usage); - exit(-1); + printf("ERROR: Missing argument\n\n%s", usage); + exit(EXIT_FAILURE); } switch (command) @@ -331,10 +337,15 @@ int main(int argc, char* argv[]) case COMMAND_ADD : if (fn_cont && fn_block && dd) { - p9_dd_tool_add(dd, fn_block, fn_cont); + rc = p9_dd_tool_add(dd, fn_block, fn_cont); dd = 0; free(fn_block); fn_block = NULL; + + if (rc == DDCO_DUPLICATE_DDLEVEL) + { + rc = DDCO_SUCCESS; + } } break; @@ -342,7 +353,7 @@ int main(int argc, char* argv[]) case COMMAND_GET : if (fn_cont && fn_block && dd) { - p9_dd_tool_get(dd, fn_block, fn_cont); + rc = p9_dd_tool_get(dd, fn_block, fn_cont); dd = 0; free(fn_block); fn_block = NULL; @@ -352,5 +363,12 @@ int main(int argc, char* argv[]) } } - return 0; + if (rc == DDCO_SUCCESS) + { + exit(EXIT_SUCCESS); + } + else + { + exit(EXIT_FAILURE); + } } |

