Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file IxNpeDlImageMgr.c |
| 3 | * |
| 4 | * @author Intel Corporation |
| 5 | * @date 09 January 2002 |
| 6 | * |
| 7 | * @brief This file contains the implementation of the private API for the |
| 8 | * IXP425 NPE Downloader ImageMgr module |
| 9 | * |
| 10 | * |
| 11 | * @par |
| 12 | * IXP400 SW Release version 2.0 |
| 13 | * |
| 14 | * -- Copyright Notice -- |
| 15 | * |
| 16 | * @par |
| 17 | * Copyright 2001-2005, Intel Corporation. |
| 18 | * All rights reserved. |
| 19 | * |
| 20 | * @par |
Wolfgang Denk | cb3761e | 2013-07-28 22:12:47 +0200 | [diff] [blame] | 21 | * SPDX-License-Identifier: BSD-3-Clause |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 22 | * @par |
| 23 | * -- End of Copyright Notice -- |
| 24 | */ |
| 25 | |
| 26 | |
| 27 | /* |
| 28 | * Put the system defined include files required. |
| 29 | */ |
| 30 | #include "IxOsal.h" |
| 31 | |
| 32 | /* |
| 33 | * Put the user defined include files required. |
| 34 | */ |
| 35 | #include "IxNpeDlImageMgr_p.h" |
| 36 | #include "IxNpeDlMacros_p.h" |
| 37 | |
| 38 | /* |
| 39 | * define the flag which toggles the firmare inclusion |
| 40 | */ |
| 41 | #define IX_NPE_MICROCODE_FIRMWARE_INCLUDED 1 |
| 42 | #include "IxNpeMicrocode.h" |
| 43 | |
| 44 | /* |
| 45 | * Indicates the start of an NPE Image, in new NPE Image Library format. |
| 46 | * 2 consecutive occurances indicates the end of the NPE Image Library |
| 47 | */ |
| 48 | #define NPE_IMAGE_MARKER 0xfeedf00d |
| 49 | |
| 50 | /* |
| 51 | * Typedefs whose scope is limited to this file. |
| 52 | */ |
| 53 | |
| 54 | /* |
| 55 | * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT |
| 56 | * TO BE DEPRECATED IN A FUTURE RELEASE |
| 57 | */ |
| 58 | typedef struct |
| 59 | { |
| 60 | UINT32 size; |
| 61 | UINT32 offset; |
| 62 | UINT32 id; |
| 63 | } IxNpeDlImageMgrImageEntry; |
| 64 | |
| 65 | /* |
| 66 | * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT |
| 67 | * TO BE DEPRECATED IN A FUTURE RELEASE |
| 68 | */ |
| 69 | typedef union |
| 70 | { |
| 71 | IxNpeDlImageMgrImageEntry image; |
| 72 | UINT32 eohMarker; |
| 73 | } IxNpeDlImageMgrHeaderEntry; |
| 74 | |
| 75 | /* |
| 76 | * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT |
| 77 | * TO BE DEPRECATED IN A FUTURE RELEASE |
| 78 | */ |
| 79 | typedef struct |
| 80 | { |
| 81 | UINT32 signature; |
| 82 | /* 1st entry in the header (there may be more than one) */ |
| 83 | IxNpeDlImageMgrHeaderEntry entry[1]; |
| 84 | } IxNpeDlImageMgrImageLibraryHeader; |
| 85 | |
| 86 | |
| 87 | /* |
| 88 | * NPE Image Header definition, used in new NPE Image Library format |
| 89 | */ |
| 90 | typedef struct |
| 91 | { |
| 92 | UINT32 marker; |
| 93 | UINT32 id; |
| 94 | UINT32 size; |
| 95 | } IxNpeDlImageMgrImageHeader; |
| 96 | |
| 97 | /* module statistics counters */ |
| 98 | typedef struct |
| 99 | { |
| 100 | UINT32 invalidSignature; |
| 101 | UINT32 imageIdListOverflow; |
| 102 | UINT32 imageIdNotFound; |
| 103 | } IxNpeDlImageMgrStats; |
| 104 | |
| 105 | |
| 106 | /* |
| 107 | * Variable declarations global to this file only. Externs are followed by |
| 108 | * static variables. |
| 109 | */ |
| 110 | static IxNpeDlImageMgrStats ixNpeDlImageMgrStats; |
| 111 | |
Jean-Christophe PLAGNIOL-VILLARD | a1cf027 | 2008-01-07 08:41:34 +0100 | [diff] [blame] | 112 | static UINT32* getIxNpeMicroCodeImageLibrary(void) |
| 113 | { |
| 114 | char *s; |
Jean-Christophe PLAGNIOL-VILLARD | b4e2f89 | 2009-01-31 09:53:39 +0100 | [diff] [blame] | 115 | |
Jean-Christophe PLAGNIOL-VILLARD | a1cf027 | 2008-01-07 08:41:34 +0100 | [diff] [blame] | 116 | if ((s = getenv("npe_ucode")) != NULL) |
| 117 | return (UINT32*) simple_strtoul(s, NULL, 16); |
| 118 | else |
Jean-Christophe PLAGNIOL-VILLARD | b4e2f89 | 2009-01-31 09:53:39 +0100 | [diff] [blame] | 119 | return NULL; |
Jean-Christophe PLAGNIOL-VILLARD | a1cf027 | 2008-01-07 08:41:34 +0100 | [diff] [blame] | 120 | } |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 121 | |
| 122 | /* |
| 123 | * static function prototypes. |
| 124 | */ |
| 125 | PRIVATE BOOL |
| 126 | ixNpeDlImageMgrSignatureCheck (UINT32 *microCodeImageLibrary); |
| 127 | |
| 128 | PRIVATE void |
| 129 | ixNpeDlImageMgrImageIdFormat (UINT32 rawImageId, IxNpeDlImageId *imageId); |
| 130 | |
| 131 | PRIVATE BOOL |
| 132 | ixNpeDlImageMgrImageIdCompare (IxNpeDlImageId *imageIdA, |
| 133 | IxNpeDlImageId *imageIdB); |
| 134 | |
| 135 | PRIVATE BOOL |
| 136 | ixNpeDlImageMgrNpeFunctionIdCompare (IxNpeDlImageId *imageIdA, |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 137 | IxNpeDlImageId *imageIdB); |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 138 | |
Michael Schwingen | 63ebcc4 | 2007-11-10 15:44:12 +0100 | [diff] [blame] | 139 | #if 0 |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 140 | PRIVATE IX_STATUS |
| 141 | ixNpeDlImageMgrImageFind_legacy (UINT32 *imageLibrary, |
| 142 | UINT32 imageId, |
| 143 | UINT32 **imagePtr, |
| 144 | UINT32 *imageSize); |
| 145 | |
| 146 | /* |
| 147 | * Function definition: ixNpeDlImageMgrMicrocodeImageLibraryOverride |
| 148 | * |
| 149 | * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT |
| 150 | * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE |
| 151 | */ |
| 152 | IX_STATUS |
| 153 | ixNpeDlImageMgrMicrocodeImageLibraryOverride ( |
| 154 | UINT32 *clientImageLibrary) |
| 155 | { |
| 156 | IX_STATUS status = IX_SUCCESS; |
| 157 | |
| 158 | IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT, |
| 159 | "Entering ixNpeDlImageMgrMicrocodeImageLibraryOverride\n"); |
| 160 | |
| 161 | if (ixNpeDlImageMgrSignatureCheck (clientImageLibrary)) |
| 162 | { |
| 163 | IxNpeMicroCodeImageLibrary = clientImageLibrary; |
| 164 | } |
| 165 | else |
| 166 | { |
| 167 | IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrMicrocodeImageLibraryOverride: " |
| 168 | "Client-supplied image has invalid signature\n"); |
| 169 | status = IX_FAIL; |
| 170 | } |
| 171 | |
| 172 | IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT, |
| 173 | "Exiting ixNpeDlImageMgrMicrocodeImageLibraryOverride: status = %d\n", |
| 174 | status); |
| 175 | return status; |
| 176 | } |
Michael Schwingen | 63ebcc4 | 2007-11-10 15:44:12 +0100 | [diff] [blame] | 177 | #endif |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 178 | |
| 179 | /* |
| 180 | * Function definition: ixNpeDlImageMgrImageListExtract |
| 181 | * |
| 182 | * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT |
| 183 | * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE |
| 184 | */ |
| 185 | IX_STATUS |
| 186 | ixNpeDlImageMgrImageListExtract ( |
| 187 | IxNpeDlImageId *imageListPtr, |
| 188 | UINT32 *numImages) |
| 189 | { |
| 190 | UINT32 rawImageId; |
| 191 | IxNpeDlImageId formattedImageId; |
| 192 | IX_STATUS status = IX_SUCCESS; |
| 193 | UINT32 imageCount = 0; |
| 194 | IxNpeDlImageMgrImageLibraryHeader *header; |
| 195 | |
| 196 | IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT, |
| 197 | "Entering ixNpeDlImageMgrImageListExtract\n"); |
| 198 | |
Jean-Christophe PLAGNIOL-VILLARD | a1cf027 | 2008-01-07 08:41:34 +0100 | [diff] [blame] | 199 | header = (IxNpeDlImageMgrImageLibraryHeader *) getIxNpeMicroCodeImageLibrary(); |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 200 | |
Jean-Christophe PLAGNIOL-VILLARD | a1cf027 | 2008-01-07 08:41:34 +0100 | [diff] [blame] | 201 | if (ixNpeDlImageMgrSignatureCheck (getIxNpeMicroCodeImageLibrary())) |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 202 | { |
| 203 | /* for each image entry in the image header ... */ |
| 204 | while (header->entry[imageCount].eohMarker != |
| 205 | IX_NPEDL_IMAGEMGR_END_OF_HEADER) |
| 206 | { |
| 207 | /* |
| 208 | * if the image list container from calling function has capacity, |
| 209 | * add the image id to the list |
| 210 | */ |
| 211 | if ((imageListPtr != NULL) && (imageCount < *numImages)) |
| 212 | { |
| 213 | rawImageId = header->entry[imageCount].image.id; |
| 214 | ixNpeDlImageMgrImageIdFormat (rawImageId, &formattedImageId); |
| 215 | imageListPtr[imageCount] = formattedImageId; |
| 216 | } |
| 217 | /* imageCount reflects no. of image entries in image library header */ |
| 218 | imageCount++; |
| 219 | } |
| 220 | |
| 221 | /* |
| 222 | * if image list container from calling function was too small to |
| 223 | * contain all image ids in the header, set return status to FAIL |
| 224 | */ |
| 225 | if ((imageListPtr != NULL) && (imageCount > *numImages)) |
| 226 | { |
| 227 | status = IX_FAIL; |
| 228 | IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageListExtract: " |
| 229 | "number of Ids found exceeds list capacity\n"); |
| 230 | ixNpeDlImageMgrStats.imageIdListOverflow++; |
| 231 | } |
| 232 | /* return number of image ids found in image library header */ |
| 233 | *numImages = imageCount; |
| 234 | } |
| 235 | else |
| 236 | { |
| 237 | status = IX_FAIL; |
| 238 | IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageListExtract: " |
| 239 | "invalid signature in image\n"); |
| 240 | } |
| 241 | |
| 242 | IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT, |
| 243 | "Exiting ixNpeDlImageMgrImageListExtract: status = %d\n", |
| 244 | status); |
| 245 | return status; |
| 246 | } |
| 247 | |
| 248 | |
| 249 | /* |
| 250 | * Function definition: ixNpeDlImageMgrImageLocate |
| 251 | * |
| 252 | * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT |
| 253 | * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE |
| 254 | */ |
| 255 | IX_STATUS |
| 256 | ixNpeDlImageMgrImageLocate ( |
| 257 | IxNpeDlImageId *imageId, |
| 258 | UINT32 **imagePtr, |
| 259 | UINT32 *imageSize) |
| 260 | { |
| 261 | UINT32 imageOffset; |
| 262 | UINT32 rawImageId; |
| 263 | IxNpeDlImageId formattedImageId; |
| 264 | /* used to index image entries in image library header */ |
| 265 | UINT32 imageCount = 0; |
| 266 | IX_STATUS status = IX_FAIL; |
| 267 | IxNpeDlImageMgrImageLibraryHeader *header; |
| 268 | |
| 269 | IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT, |
| 270 | "Entering ixNpeDlImageMgrImageLocate\n"); |
| 271 | |
Jean-Christophe PLAGNIOL-VILLARD | a1cf027 | 2008-01-07 08:41:34 +0100 | [diff] [blame] | 272 | header = (IxNpeDlImageMgrImageLibraryHeader *) getIxNpeMicroCodeImageLibrary(); |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 273 | |
Jean-Christophe PLAGNIOL-VILLARD | a1cf027 | 2008-01-07 08:41:34 +0100 | [diff] [blame] | 274 | if (ixNpeDlImageMgrSignatureCheck (getIxNpeMicroCodeImageLibrary())) |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 275 | { |
| 276 | /* for each image entry in the image library header ... */ |
| 277 | while (header->entry[imageCount].eohMarker != |
| 278 | IX_NPEDL_IMAGEMGR_END_OF_HEADER) |
| 279 | { |
| 280 | rawImageId = header->entry[imageCount].image.id; |
| 281 | ixNpeDlImageMgrImageIdFormat (rawImageId, &formattedImageId); |
| 282 | /* if a match for imageId is found in the image library header... */ |
| 283 | if (ixNpeDlImageMgrImageIdCompare (imageId, &formattedImageId)) |
| 284 | { |
| 285 | /* |
| 286 | * get pointer to the image in the image library using offset from |
| 287 | * 1st word in image library |
| 288 | */ |
Jean-Christophe PLAGNIOL-VILLARD | a1cf027 | 2008-01-07 08:41:34 +0100 | [diff] [blame] | 289 | UINT32 *tmp=getIxNpeMicroCodeImageLibrary(); |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 290 | imageOffset = header->entry[imageCount].image.offset; |
Jean-Christophe PLAGNIOL-VILLARD | a1cf027 | 2008-01-07 08:41:34 +0100 | [diff] [blame] | 291 | *imagePtr = &tmp[imageOffset]; |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 292 | /* get the image size */ |
| 293 | *imageSize = header->entry[imageCount].image.size; |
| 294 | status = IX_SUCCESS; |
| 295 | break; |
| 296 | } |
| 297 | imageCount++; |
| 298 | } |
| 299 | if (status != IX_SUCCESS) |
| 300 | { |
| 301 | IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageLocate: " |
| 302 | "imageId not found in image library header\n"); |
| 303 | ixNpeDlImageMgrStats.imageIdNotFound++; |
| 304 | } |
| 305 | } |
| 306 | else |
| 307 | { |
| 308 | IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageLocate: " |
| 309 | "invalid signature in image library\n"); |
| 310 | } |
| 311 | |
| 312 | IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT, |
| 313 | "Exiting ixNpeDlImageMgrImageLocate: status = %d\n", status); |
| 314 | return status; |
| 315 | } |
| 316 | |
| 317 | /* |
| 318 | * Function definition: ixNpeDlImageMgrLatestImageExtract |
| 319 | * |
| 320 | * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT |
| 321 | * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE |
| 322 | */ |
| 323 | IX_STATUS |
| 324 | ixNpeDlImageMgrLatestImageExtract (IxNpeDlImageId *imageId) |
| 325 | { |
| 326 | UINT32 imageCount = 0; |
| 327 | UINT32 rawImageId; |
| 328 | IxNpeDlImageId formattedImageId; |
| 329 | IX_STATUS status = IX_FAIL; |
| 330 | IxNpeDlImageMgrImageLibraryHeader *header; |
| 331 | |
| 332 | |
| 333 | IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT, |
| 334 | "Entering ixNpeDlImageMgrLatestImageExtract\n"); |
| 335 | |
Jean-Christophe PLAGNIOL-VILLARD | a1cf027 | 2008-01-07 08:41:34 +0100 | [diff] [blame] | 336 | header = (IxNpeDlImageMgrImageLibraryHeader *) getIxNpeMicroCodeImageLibrary(); |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 337 | |
Jean-Christophe PLAGNIOL-VILLARD | a1cf027 | 2008-01-07 08:41:34 +0100 | [diff] [blame] | 338 | if (ixNpeDlImageMgrSignatureCheck (getIxNpeMicroCodeImageLibrary())) |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 339 | { |
| 340 | /* for each image entry in the image library header ... */ |
| 341 | while (header->entry[imageCount].eohMarker != |
| 342 | IX_NPEDL_IMAGEMGR_END_OF_HEADER) |
| 343 | { |
| 344 | rawImageId = header->entry[imageCount].image.id; |
| 345 | ixNpeDlImageMgrImageIdFormat (rawImageId, &formattedImageId); |
| 346 | /* |
| 347 | * if a match for the npe Id and functionality Id of the imageId is |
| 348 | * found in the image library header... |
| 349 | */ |
| 350 | if(ixNpeDlImageMgrNpeFunctionIdCompare(imageId, &formattedImageId)) |
| 351 | { |
| 352 | if(imageId->major <= formattedImageId.major) |
| 353 | { |
| 354 | if(imageId->minor < formattedImageId.minor) |
| 355 | { |
| 356 | imageId->minor = formattedImageId.minor; |
| 357 | } |
| 358 | imageId->major = formattedImageId.major; |
| 359 | } |
| 360 | status = IX_SUCCESS; |
| 361 | } |
| 362 | imageCount++; |
| 363 | } |
| 364 | if (status != IX_SUCCESS) |
| 365 | { |
| 366 | IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrLatestImageExtract: " |
| 367 | "imageId not found in image library header\n"); |
| 368 | ixNpeDlImageMgrStats.imageIdNotFound++; |
| 369 | } |
| 370 | } |
| 371 | else |
| 372 | { |
| 373 | IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrLatestImageGet: " |
| 374 | "invalid signature in image library\n"); |
| 375 | } |
| 376 | |
| 377 | IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT, |
| 378 | "Exiting ixNpeDlImageMgrLatestImageGet: status = %d\n", status); |
| 379 | return status; |
| 380 | } |
| 381 | |
| 382 | /* |
| 383 | * Function definition: ixNpeDlImageMgrSignatureCheck |
| 384 | * |
| 385 | * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT |
| 386 | * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE |
| 387 | */ |
| 388 | PRIVATE BOOL |
| 389 | ixNpeDlImageMgrSignatureCheck (UINT32 *microCodeImageLibrary) |
| 390 | { |
| 391 | IxNpeDlImageMgrImageLibraryHeader *header = |
| 392 | (IxNpeDlImageMgrImageLibraryHeader *) microCodeImageLibrary; |
York Sun | 472d546 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 393 | BOOL result = true; |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 394 | |
Jean-Christophe PLAGNIOL-VILLARD | b4e2f89 | 2009-01-31 09:53:39 +0100 | [diff] [blame] | 395 | if (!header || header->signature != IX_NPEDL_IMAGEMGR_SIGNATURE) |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 396 | { |
York Sun | 472d546 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 397 | result = false; |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 398 | ixNpeDlImageMgrStats.invalidSignature++; |
| 399 | } |
| 400 | |
| 401 | return result; |
| 402 | } |
| 403 | |
| 404 | |
| 405 | /* |
| 406 | * Function definition: ixNpeDlImageMgrImageIdFormat |
| 407 | * |
| 408 | * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT |
| 409 | * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE |
| 410 | */ |
| 411 | PRIVATE void |
| 412 | ixNpeDlImageMgrImageIdFormat ( |
| 413 | UINT32 rawImageId, |
| 414 | IxNpeDlImageId *imageId) |
| 415 | { |
| 416 | imageId->npeId = (rawImageId >> |
| 417 | IX_NPEDL_IMAGEID_NPEID_OFFSET) & |
| 418 | IX_NPEDL_NPEIMAGE_FIELD_MASK; |
| 419 | imageId->functionalityId = (rawImageId >> |
| 420 | IX_NPEDL_IMAGEID_FUNCTIONID_OFFSET) & |
| 421 | IX_NPEDL_NPEIMAGE_FIELD_MASK; |
| 422 | imageId->major = (rawImageId >> |
| 423 | IX_NPEDL_IMAGEID_MAJOR_OFFSET) & |
| 424 | IX_NPEDL_NPEIMAGE_FIELD_MASK; |
| 425 | imageId->minor = (rawImageId >> |
| 426 | IX_NPEDL_IMAGEID_MINOR_OFFSET) & |
| 427 | IX_NPEDL_NPEIMAGE_FIELD_MASK; |
| 428 | |
| 429 | } |
| 430 | |
| 431 | |
| 432 | /* |
| 433 | * Function definition: ixNpeDlImageMgrImageIdCompare |
| 434 | * |
| 435 | * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT |
| 436 | * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE |
| 437 | */ |
| 438 | PRIVATE BOOL |
| 439 | ixNpeDlImageMgrImageIdCompare ( |
| 440 | IxNpeDlImageId *imageIdA, |
| 441 | IxNpeDlImageId *imageIdB) |
| 442 | { |
| 443 | if ((imageIdA->npeId == imageIdB->npeId) && |
| 444 | (imageIdA->functionalityId == imageIdB->functionalityId) && |
| 445 | (imageIdA->major == imageIdB->major) && |
| 446 | (imageIdA->minor == imageIdB->minor)) |
| 447 | { |
York Sun | 472d546 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 448 | return true; |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 449 | } |
| 450 | else |
| 451 | { |
York Sun | 472d546 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 452 | return false; |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 453 | } |
| 454 | } |
| 455 | |
| 456 | /* |
| 457 | * Function definition: ixNpeDlImageMgrNpeFunctionIdCompare |
| 458 | * |
| 459 | * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT |
| 460 | * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE |
| 461 | */ |
| 462 | PRIVATE BOOL |
| 463 | ixNpeDlImageMgrNpeFunctionIdCompare ( |
| 464 | IxNpeDlImageId *imageIdA, |
| 465 | IxNpeDlImageId *imageIdB) |
| 466 | { |
| 467 | if ((imageIdA->npeId == imageIdB->npeId) && |
| 468 | (imageIdA->functionalityId == imageIdB->functionalityId)) |
| 469 | { |
York Sun | 472d546 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 470 | return true; |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 471 | } |
| 472 | else |
| 473 | { |
York Sun | 472d546 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 474 | return false; |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 475 | } |
| 476 | } |
| 477 | |
| 478 | |
| 479 | /* |
| 480 | * Function definition: ixNpeDlImageMgrStatsShow |
| 481 | */ |
| 482 | void |
| 483 | ixNpeDlImageMgrStatsShow (void) |
| 484 | { |
| 485 | ixOsalLog (IX_OSAL_LOG_LVL_USER, |
| 486 | IX_OSAL_LOG_DEV_STDOUT, |
| 487 | "\nixNpeDlImageMgrStatsShow:\n" |
| 488 | "\tInvalid Image Signatures: %u\n" |
| 489 | "\tImage Id List capacity too small: %u\n" |
| 490 | "\tImage Id not found: %u\n\n", |
| 491 | ixNpeDlImageMgrStats.invalidSignature, |
| 492 | ixNpeDlImageMgrStats.imageIdListOverflow, |
| 493 | ixNpeDlImageMgrStats.imageIdNotFound, |
| 494 | 0,0,0); |
| 495 | } |
| 496 | |
| 497 | |
| 498 | /* |
| 499 | * Function definition: ixNpeDlImageMgrStatsReset |
| 500 | */ |
| 501 | void |
| 502 | ixNpeDlImageMgrStatsReset (void) |
| 503 | { |
| 504 | ixNpeDlImageMgrStats.invalidSignature = 0; |
| 505 | ixNpeDlImageMgrStats.imageIdListOverflow = 0; |
| 506 | ixNpeDlImageMgrStats.imageIdNotFound = 0; |
| 507 | } |
| 508 | |
| 509 | |
Michael Schwingen | 63ebcc4 | 2007-11-10 15:44:12 +0100 | [diff] [blame] | 510 | #if 0 |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 511 | /* |
| 512 | * Function definition: ixNpeDlImageMgrImageFind_legacy |
| 513 | * |
| 514 | * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT |
| 515 | * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE |
| 516 | */ |
| 517 | PRIVATE IX_STATUS |
| 518 | ixNpeDlImageMgrImageFind_legacy ( |
| 519 | UINT32 *imageLibrary, |
| 520 | UINT32 imageId, |
| 521 | UINT32 **imagePtr, |
| 522 | UINT32 *imageSize) |
| 523 | { |
| 524 | UINT32 imageOffset; |
| 525 | /* used to index image entries in image library header */ |
| 526 | UINT32 imageCount = 0; |
| 527 | IX_STATUS status = IX_FAIL; |
| 528 | IxNpeDlImageMgrImageLibraryHeader *header; |
York Sun | 472d546 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 529 | BOOL imageFound = false; |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 530 | |
| 531 | IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT, |
| 532 | "Entering ixNpeDlImageMgrImageFind\n"); |
| 533 | |
| 534 | |
| 535 | /* If user didn't specify a library to use, use the default |
| 536 | * one from IxNpeMicrocode.h |
| 537 | */ |
| 538 | if (imageLibrary == NULL) |
| 539 | { |
| 540 | imageLibrary = IxNpeMicroCodeImageLibrary; |
| 541 | } |
| 542 | |
| 543 | if (ixNpeDlImageMgrSignatureCheck (imageLibrary)) |
| 544 | { |
| 545 | header = (IxNpeDlImageMgrImageLibraryHeader *) imageLibrary; |
| 546 | |
| 547 | /* for each image entry in the image library header ... */ |
| 548 | while ((header->entry[imageCount].eohMarker != |
| 549 | IX_NPEDL_IMAGEMGR_END_OF_HEADER) && !(imageFound)) |
| 550 | { |
| 551 | /* if a match for imageId is found in the image library header... */ |
| 552 | if (imageId == header->entry[imageCount].image.id) |
| 553 | { |
| 554 | /* |
| 555 | * get pointer to the image in the image library using offset from |
| 556 | * 1st word in image library |
| 557 | */ |
| 558 | imageOffset = header->entry[imageCount].image.offset; |
| 559 | *imagePtr = &imageLibrary[imageOffset]; |
| 560 | /* get the image size */ |
| 561 | *imageSize = header->entry[imageCount].image.size; |
| 562 | status = IX_SUCCESS; |
York Sun | 472d546 | 2013-04-01 11:29:11 -0700 | [diff] [blame] | 563 | imageFound = true; |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 564 | } |
| 565 | imageCount++; |
| 566 | } |
| 567 | if (status != IX_SUCCESS) |
| 568 | { |
| 569 | IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: " |
| 570 | "imageId not found in image library header\n"); |
| 571 | ixNpeDlImageMgrStats.imageIdNotFound++; |
| 572 | } |
| 573 | } |
| 574 | else |
| 575 | { |
| 576 | IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: " |
| 577 | "invalid signature in image library\n"); |
| 578 | } |
| 579 | |
| 580 | IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT, |
| 581 | "Exiting ixNpeDlImageMgrImageFind: status = %d\n", status); |
| 582 | return status; |
| 583 | } |
Michael Schwingen | 63ebcc4 | 2007-11-10 15:44:12 +0100 | [diff] [blame] | 584 | #endif |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 585 | |
| 586 | /* |
| 587 | * Function definition: ixNpeDlImageMgrImageFind |
| 588 | */ |
| 589 | IX_STATUS |
| 590 | ixNpeDlImageMgrImageFind ( |
| 591 | UINT32 *imageLibrary, |
| 592 | UINT32 imageId, |
| 593 | UINT32 **imagePtr, |
| 594 | UINT32 *imageSize) |
| 595 | { |
| 596 | IxNpeDlImageMgrImageHeader *image; |
| 597 | UINT32 offset = 0; |
| 598 | |
| 599 | /* If user didn't specify a library to use, use the default |
| 600 | * one from IxNpeMicrocode.h |
| 601 | */ |
| 602 | if (imageLibrary == NULL) |
| 603 | { |
| 604 | #ifdef IX_NPEDL_READ_MICROCODE_FROM_FILE |
| 605 | if (ixNpeMicrocode_binaryArray == NULL) |
| 606 | { |
| 607 | printk (KERN_ERR "ixp400.o: ERROR, no Microcode found in memory\n"); |
| 608 | return IX_FAIL; |
| 609 | } |
| 610 | else |
| 611 | { |
| 612 | imageLibrary = ixNpeMicrocode_binaryArray; |
| 613 | } |
| 614 | #else |
Jean-Christophe PLAGNIOL-VILLARD | a1cf027 | 2008-01-07 08:41:34 +0100 | [diff] [blame] | 615 | imageLibrary = getIxNpeMicroCodeImageLibrary(); |
Jean-Christophe PLAGNIOL-VILLARD | b4e2f89 | 2009-01-31 09:53:39 +0100 | [diff] [blame] | 616 | if (imageLibrary == NULL) |
| 617 | { |
| 618 | printf ("npe: ERROR, no Microcode found in memory\n"); |
| 619 | return IX_FAIL; |
| 620 | } |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 621 | #endif /* IX_NPEDL_READ_MICROCODE_FROM_FILE */ |
| 622 | } |
| 623 | |
Michael Schwingen | 63ebcc4 | 2007-11-10 15:44:12 +0100 | [diff] [blame] | 624 | #if 0 |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 625 | /* For backward's compatibility with previous image format */ |
| 626 | if (ixNpeDlImageMgrSignatureCheck(imageLibrary)) |
| 627 | { |
| 628 | return ixNpeDlImageMgrImageFind_legacy(imageLibrary, |
| 629 | imageId, |
| 630 | imagePtr, |
| 631 | imageSize); |
| 632 | } |
Michael Schwingen | 63ebcc4 | 2007-11-10 15:44:12 +0100 | [diff] [blame] | 633 | #endif |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 634 | |
| 635 | while (*(imageLibrary+offset) == NPE_IMAGE_MARKER) |
| 636 | { |
| 637 | image = (IxNpeDlImageMgrImageHeader *)(imageLibrary+offset); |
| 638 | offset += sizeof(IxNpeDlImageMgrImageHeader)/sizeof(UINT32); |
| 639 | |
| 640 | if (image->id == imageId) |
| 641 | { |
| 642 | *imagePtr = imageLibrary + offset; |
| 643 | *imageSize = image->size; |
| 644 | return IX_SUCCESS; |
| 645 | } |
| 646 | /* 2 consecutive NPE_IMAGE_MARKER's indicates end of library */ |
| 647 | else if (image->id == NPE_IMAGE_MARKER) |
| 648 | { |
| 649 | IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: " |
| 650 | "imageId not found in image library header\n"); |
| 651 | ixNpeDlImageMgrStats.imageIdNotFound++; |
| 652 | /* reached end of library, image not found */ |
| 653 | return IX_FAIL; |
| 654 | } |
| 655 | offset += image->size; |
| 656 | } |
| 657 | |
| 658 | /* If we get here, our image library may be corrupted */ |
| 659 | IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: " |
| 660 | "image library format may be invalid or corrupted\n"); |
| 661 | return IX_FAIL; |
| 662 | } |
| 663 | |