2 * @file IxNpeDlImageMgr.c
4 * @author Intel Corporation
5 * @date 09 January 2002
7 * @brief This file contains the implementation of the private API for the
8 * IXP425 NPE Downloader ImageMgr module
12 * IXP400 SW Release version 2.0
14 * -- Copyright Notice --
17 * Copyright 2001-2005, Intel Corporation.
18 * All rights reserved.
21 * SPDX-License-Identifier: BSD-3-Clause
23 * -- End of Copyright Notice --
28 * Put the system defined include files required.
33 * Put the user defined include files required.
35 #include "IxNpeDlImageMgr_p.h"
36 #include "IxNpeDlMacros_p.h"
39 * define the flag which toggles the firmare inclusion
41 #define IX_NPE_MICROCODE_FIRMWARE_INCLUDED 1
42 #include "IxNpeMicrocode.h"
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
48 #define NPE_IMAGE_MARKER 0xfeedf00d
51 * Typedefs whose scope is limited to this file.
55 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
56 * TO BE DEPRECATED IN A FUTURE RELEASE
63 } IxNpeDlImageMgrImageEntry;
66 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
67 * TO BE DEPRECATED IN A FUTURE RELEASE
71 IxNpeDlImageMgrImageEntry image;
73 } IxNpeDlImageMgrHeaderEntry;
76 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
77 * TO BE DEPRECATED IN A FUTURE RELEASE
82 /* 1st entry in the header (there may be more than one) */
83 IxNpeDlImageMgrHeaderEntry entry[1];
84 } IxNpeDlImageMgrImageLibraryHeader;
88 * NPE Image Header definition, used in new NPE Image Library format
95 } IxNpeDlImageMgrImageHeader;
97 /* module statistics counters */
100 UINT32 invalidSignature;
101 UINT32 imageIdListOverflow;
102 UINT32 imageIdNotFound;
103 } IxNpeDlImageMgrStats;
107 * Variable declarations global to this file only. Externs are followed by
110 static IxNpeDlImageMgrStats ixNpeDlImageMgrStats;
112 static UINT32* getIxNpeMicroCodeImageLibrary(void)
116 if ((s = getenv("npe_ucode")) != NULL)
117 return (UINT32*) simple_strtoul(s, NULL, 16);
123 * static function prototypes.
126 ixNpeDlImageMgrSignatureCheck (UINT32 *microCodeImageLibrary);
129 ixNpeDlImageMgrImageIdFormat (UINT32 rawImageId, IxNpeDlImageId *imageId);
132 ixNpeDlImageMgrImageIdCompare (IxNpeDlImageId *imageIdA,
133 IxNpeDlImageId *imageIdB);
136 ixNpeDlImageMgrNpeFunctionIdCompare (IxNpeDlImageId *imageIdA,
137 IxNpeDlImageId *imageIdB);
141 ixNpeDlImageMgrImageFind_legacy (UINT32 *imageLibrary,
147 * Function definition: ixNpeDlImageMgrMicrocodeImageLibraryOverride
149 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
150 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
153 ixNpeDlImageMgrMicrocodeImageLibraryOverride (
154 UINT32 *clientImageLibrary)
156 IX_STATUS status = IX_SUCCESS;
158 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
159 "Entering ixNpeDlImageMgrMicrocodeImageLibraryOverride\n");
161 if (ixNpeDlImageMgrSignatureCheck (clientImageLibrary))
163 IxNpeMicroCodeImageLibrary = clientImageLibrary;
167 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrMicrocodeImageLibraryOverride: "
168 "Client-supplied image has invalid signature\n");
172 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
173 "Exiting ixNpeDlImageMgrMicrocodeImageLibraryOverride: status = %d\n",
180 * Function definition: ixNpeDlImageMgrImageListExtract
182 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
183 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
186 ixNpeDlImageMgrImageListExtract (
187 IxNpeDlImageId *imageListPtr,
191 IxNpeDlImageId formattedImageId;
192 IX_STATUS status = IX_SUCCESS;
193 UINT32 imageCount = 0;
194 IxNpeDlImageMgrImageLibraryHeader *header;
196 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
197 "Entering ixNpeDlImageMgrImageListExtract\n");
199 header = (IxNpeDlImageMgrImageLibraryHeader *) getIxNpeMicroCodeImageLibrary();
201 if (ixNpeDlImageMgrSignatureCheck (getIxNpeMicroCodeImageLibrary()))
203 /* for each image entry in the image header ... */
204 while (header->entry[imageCount].eohMarker !=
205 IX_NPEDL_IMAGEMGR_END_OF_HEADER)
208 * if the image list container from calling function has capacity,
209 * add the image id to the list
211 if ((imageListPtr != NULL) && (imageCount < *numImages))
213 rawImageId = header->entry[imageCount].image.id;
214 ixNpeDlImageMgrImageIdFormat (rawImageId, &formattedImageId);
215 imageListPtr[imageCount] = formattedImageId;
217 /* imageCount reflects no. of image entries in image library header */
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
225 if ((imageListPtr != NULL) && (imageCount > *numImages))
228 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageListExtract: "
229 "number of Ids found exceeds list capacity\n");
230 ixNpeDlImageMgrStats.imageIdListOverflow++;
232 /* return number of image ids found in image library header */
233 *numImages = imageCount;
238 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageListExtract: "
239 "invalid signature in image\n");
242 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
243 "Exiting ixNpeDlImageMgrImageListExtract: status = %d\n",
250 * Function definition: ixNpeDlImageMgrImageLocate
252 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
253 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
256 ixNpeDlImageMgrImageLocate (
257 IxNpeDlImageId *imageId,
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;
269 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
270 "Entering ixNpeDlImageMgrImageLocate\n");
272 header = (IxNpeDlImageMgrImageLibraryHeader *) getIxNpeMicroCodeImageLibrary();
274 if (ixNpeDlImageMgrSignatureCheck (getIxNpeMicroCodeImageLibrary()))
276 /* for each image entry in the image library header ... */
277 while (header->entry[imageCount].eohMarker !=
278 IX_NPEDL_IMAGEMGR_END_OF_HEADER)
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))
286 * get pointer to the image in the image library using offset from
287 * 1st word in image library
289 UINT32 *tmp=getIxNpeMicroCodeImageLibrary();
290 imageOffset = header->entry[imageCount].image.offset;
291 *imagePtr = &tmp[imageOffset];
292 /* get the image size */
293 *imageSize = header->entry[imageCount].image.size;
299 if (status != IX_SUCCESS)
301 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageLocate: "
302 "imageId not found in image library header\n");
303 ixNpeDlImageMgrStats.imageIdNotFound++;
308 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageLocate: "
309 "invalid signature in image library\n");
312 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
313 "Exiting ixNpeDlImageMgrImageLocate: status = %d\n", status);
318 * Function definition: ixNpeDlImageMgrLatestImageExtract
320 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
321 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
324 ixNpeDlImageMgrLatestImageExtract (IxNpeDlImageId *imageId)
326 UINT32 imageCount = 0;
328 IxNpeDlImageId formattedImageId;
329 IX_STATUS status = IX_FAIL;
330 IxNpeDlImageMgrImageLibraryHeader *header;
333 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
334 "Entering ixNpeDlImageMgrLatestImageExtract\n");
336 header = (IxNpeDlImageMgrImageLibraryHeader *) getIxNpeMicroCodeImageLibrary();
338 if (ixNpeDlImageMgrSignatureCheck (getIxNpeMicroCodeImageLibrary()))
340 /* for each image entry in the image library header ... */
341 while (header->entry[imageCount].eohMarker !=
342 IX_NPEDL_IMAGEMGR_END_OF_HEADER)
344 rawImageId = header->entry[imageCount].image.id;
345 ixNpeDlImageMgrImageIdFormat (rawImageId, &formattedImageId);
347 * if a match for the npe Id and functionality Id of the imageId is
348 * found in the image library header...
350 if(ixNpeDlImageMgrNpeFunctionIdCompare(imageId, &formattedImageId))
352 if(imageId->major <= formattedImageId.major)
354 if(imageId->minor < formattedImageId.minor)
356 imageId->minor = formattedImageId.minor;
358 imageId->major = formattedImageId.major;
364 if (status != IX_SUCCESS)
366 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrLatestImageExtract: "
367 "imageId not found in image library header\n");
368 ixNpeDlImageMgrStats.imageIdNotFound++;
373 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrLatestImageGet: "
374 "invalid signature in image library\n");
377 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
378 "Exiting ixNpeDlImageMgrLatestImageGet: status = %d\n", status);
383 * Function definition: ixNpeDlImageMgrSignatureCheck
385 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
386 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
389 ixNpeDlImageMgrSignatureCheck (UINT32 *microCodeImageLibrary)
391 IxNpeDlImageMgrImageLibraryHeader *header =
392 (IxNpeDlImageMgrImageLibraryHeader *) microCodeImageLibrary;
395 if (!header || header->signature != IX_NPEDL_IMAGEMGR_SIGNATURE)
398 ixNpeDlImageMgrStats.invalidSignature++;
406 * Function definition: ixNpeDlImageMgrImageIdFormat
408 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
409 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
412 ixNpeDlImageMgrImageIdFormat (
414 IxNpeDlImageId *imageId)
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;
433 * Function definition: ixNpeDlImageMgrImageIdCompare
435 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
436 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
439 ixNpeDlImageMgrImageIdCompare (
440 IxNpeDlImageId *imageIdA,
441 IxNpeDlImageId *imageIdB)
443 if ((imageIdA->npeId == imageIdB->npeId) &&
444 (imageIdA->functionalityId == imageIdB->functionalityId) &&
445 (imageIdA->major == imageIdB->major) &&
446 (imageIdA->minor == imageIdB->minor))
457 * Function definition: ixNpeDlImageMgrNpeFunctionIdCompare
459 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
460 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
463 ixNpeDlImageMgrNpeFunctionIdCompare (
464 IxNpeDlImageId *imageIdA,
465 IxNpeDlImageId *imageIdB)
467 if ((imageIdA->npeId == imageIdB->npeId) &&
468 (imageIdA->functionalityId == imageIdB->functionalityId))
480 * Function definition: ixNpeDlImageMgrStatsShow
483 ixNpeDlImageMgrStatsShow (void)
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,
499 * Function definition: ixNpeDlImageMgrStatsReset
502 ixNpeDlImageMgrStatsReset (void)
504 ixNpeDlImageMgrStats.invalidSignature = 0;
505 ixNpeDlImageMgrStats.imageIdListOverflow = 0;
506 ixNpeDlImageMgrStats.imageIdNotFound = 0;
512 * Function definition: ixNpeDlImageMgrImageFind_legacy
514 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
515 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
518 ixNpeDlImageMgrImageFind_legacy (
519 UINT32 *imageLibrary,
525 /* used to index image entries in image library header */
526 UINT32 imageCount = 0;
527 IX_STATUS status = IX_FAIL;
528 IxNpeDlImageMgrImageLibraryHeader *header;
529 BOOL imageFound = false;
531 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
532 "Entering ixNpeDlImageMgrImageFind\n");
535 /* If user didn't specify a library to use, use the default
536 * one from IxNpeMicrocode.h
538 if (imageLibrary == NULL)
540 imageLibrary = IxNpeMicroCodeImageLibrary;
543 if (ixNpeDlImageMgrSignatureCheck (imageLibrary))
545 header = (IxNpeDlImageMgrImageLibraryHeader *) imageLibrary;
547 /* for each image entry in the image library header ... */
548 while ((header->entry[imageCount].eohMarker !=
549 IX_NPEDL_IMAGEMGR_END_OF_HEADER) && !(imageFound))
551 /* if a match for imageId is found in the image library header... */
552 if (imageId == header->entry[imageCount].image.id)
555 * get pointer to the image in the image library using offset from
556 * 1st word in image library
558 imageOffset = header->entry[imageCount].image.offset;
559 *imagePtr = &imageLibrary[imageOffset];
560 /* get the image size */
561 *imageSize = header->entry[imageCount].image.size;
567 if (status != IX_SUCCESS)
569 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
570 "imageId not found in image library header\n");
571 ixNpeDlImageMgrStats.imageIdNotFound++;
576 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
577 "invalid signature in image library\n");
580 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
581 "Exiting ixNpeDlImageMgrImageFind: status = %d\n", status);
587 * Function definition: ixNpeDlImageMgrImageFind
590 ixNpeDlImageMgrImageFind (
591 UINT32 *imageLibrary,
596 IxNpeDlImageMgrImageHeader *image;
599 /* If user didn't specify a library to use, use the default
600 * one from IxNpeMicrocode.h
602 if (imageLibrary == NULL)
604 #ifdef IX_NPEDL_READ_MICROCODE_FROM_FILE
605 if (ixNpeMicrocode_binaryArray == NULL)
607 printk (KERN_ERR "ixp400.o: ERROR, no Microcode found in memory\n");
612 imageLibrary = ixNpeMicrocode_binaryArray;
615 imageLibrary = getIxNpeMicroCodeImageLibrary();
616 if (imageLibrary == NULL)
618 printf ("npe: ERROR, no Microcode found in memory\n");
621 #endif /* IX_NPEDL_READ_MICROCODE_FROM_FILE */
625 /* For backward's compatibility with previous image format */
626 if (ixNpeDlImageMgrSignatureCheck(imageLibrary))
628 return ixNpeDlImageMgrImageFind_legacy(imageLibrary,
635 while (*(imageLibrary+offset) == NPE_IMAGE_MARKER)
637 image = (IxNpeDlImageMgrImageHeader *)(imageLibrary+offset);
638 offset += sizeof(IxNpeDlImageMgrImageHeader)/sizeof(UINT32);
640 if (image->id == imageId)
642 *imagePtr = imageLibrary + offset;
643 *imageSize = image->size;
646 /* 2 consecutive NPE_IMAGE_MARKER's indicates end of library */
647 else if (image->id == NPE_IMAGE_MARKER)
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 */
655 offset += image->size;
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");