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