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 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions
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.
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
47 * -- End of Copyright Notice --
52 * Put the system defined include files required.
57 * Put the user defined include files required.
59 #include "IxNpeDlImageMgr_p.h"
60 #include "IxNpeDlMacros_p.h"
63 * define the flag which toggles the firmare inclusion
65 #define IX_NPE_MICROCODE_FIRMWARE_INCLUDED 1
66 #include "IxNpeMicrocode.h"
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
72 #define NPE_IMAGE_MARKER 0xfeedf00d
75 * Typedefs whose scope is limited to this file.
79 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
80 * TO BE DEPRECATED IN A FUTURE RELEASE
87 } IxNpeDlImageMgrImageEntry
;
90 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
91 * TO BE DEPRECATED IN A FUTURE RELEASE
95 IxNpeDlImageMgrImageEntry image
;
97 } IxNpeDlImageMgrHeaderEntry
;
100 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
101 * TO BE DEPRECATED IN A FUTURE RELEASE
106 /* 1st entry in the header (there may be more than one) */
107 IxNpeDlImageMgrHeaderEntry entry
[1];
108 } IxNpeDlImageMgrImageLibraryHeader
;
112 * NPE Image Header definition, used in new NPE Image Library format
119 } IxNpeDlImageMgrImageHeader
;
121 /* module statistics counters */
124 UINT32 invalidSignature
;
125 UINT32 imageIdListOverflow
;
126 UINT32 imageIdNotFound
;
127 } IxNpeDlImageMgrStats
;
131 * Variable declarations global to this file only. Externs are followed by
134 static IxNpeDlImageMgrStats ixNpeDlImageMgrStats
;
136 static UINT32
* getIxNpeMicroCodeImageLibrary(void)
140 if ((s
= getenv("npe_ucode")) != NULL
)
141 return (UINT32
*) simple_strtoul(s
, NULL
, 16);
147 * static function prototypes.
150 ixNpeDlImageMgrSignatureCheck (UINT32
*microCodeImageLibrary
);
153 ixNpeDlImageMgrImageIdFormat (UINT32 rawImageId
, IxNpeDlImageId
*imageId
);
156 ixNpeDlImageMgrImageIdCompare (IxNpeDlImageId
*imageIdA
,
157 IxNpeDlImageId
*imageIdB
);
160 ixNpeDlImageMgrNpeFunctionIdCompare (IxNpeDlImageId
*imageIdA
,
161 IxNpeDlImageId
*imageIdB
);
165 ixNpeDlImageMgrImageFind_legacy (UINT32
*imageLibrary
,
171 * Function definition: ixNpeDlImageMgrMicrocodeImageLibraryOverride
173 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
174 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
177 ixNpeDlImageMgrMicrocodeImageLibraryOverride (
178 UINT32
*clientImageLibrary
)
180 IX_STATUS status
= IX_SUCCESS
;
182 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT
,
183 "Entering ixNpeDlImageMgrMicrocodeImageLibraryOverride\n");
185 if (ixNpeDlImageMgrSignatureCheck (clientImageLibrary
))
187 IxNpeMicroCodeImageLibrary
= clientImageLibrary
;
191 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrMicrocodeImageLibraryOverride: "
192 "Client-supplied image has invalid signature\n");
196 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT
,
197 "Exiting ixNpeDlImageMgrMicrocodeImageLibraryOverride: status = %d\n",
204 * Function definition: ixNpeDlImageMgrImageListExtract
206 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
207 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
210 ixNpeDlImageMgrImageListExtract (
211 IxNpeDlImageId
*imageListPtr
,
215 IxNpeDlImageId formattedImageId
;
216 IX_STATUS status
= IX_SUCCESS
;
217 UINT32 imageCount
= 0;
218 IxNpeDlImageMgrImageLibraryHeader
*header
;
220 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT
,
221 "Entering ixNpeDlImageMgrImageListExtract\n");
223 header
= (IxNpeDlImageMgrImageLibraryHeader
*) getIxNpeMicroCodeImageLibrary();
225 if (ixNpeDlImageMgrSignatureCheck (getIxNpeMicroCodeImageLibrary()))
227 /* for each image entry in the image header ... */
228 while (header
->entry
[imageCount
].eohMarker
!=
229 IX_NPEDL_IMAGEMGR_END_OF_HEADER
)
232 * if the image list container from calling function has capacity,
233 * add the image id to the list
235 if ((imageListPtr
!= NULL
) && (imageCount
< *numImages
))
237 rawImageId
= header
->entry
[imageCount
].image
.id
;
238 ixNpeDlImageMgrImageIdFormat (rawImageId
, &formattedImageId
);
239 imageListPtr
[imageCount
] = formattedImageId
;
241 /* imageCount reflects no. of image entries in image library header */
246 * if image list container from calling function was too small to
247 * contain all image ids in the header, set return status to FAIL
249 if ((imageListPtr
!= NULL
) && (imageCount
> *numImages
))
252 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageListExtract: "
253 "number of Ids found exceeds list capacity\n");
254 ixNpeDlImageMgrStats
.imageIdListOverflow
++;
256 /* return number of image ids found in image library header */
257 *numImages
= imageCount
;
262 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageListExtract: "
263 "invalid signature in image\n");
266 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT
,
267 "Exiting ixNpeDlImageMgrImageListExtract: status = %d\n",
274 * Function definition: ixNpeDlImageMgrImageLocate
276 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
277 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
280 ixNpeDlImageMgrImageLocate (
281 IxNpeDlImageId
*imageId
,
287 IxNpeDlImageId formattedImageId
;
288 /* used to index image entries in image library header */
289 UINT32 imageCount
= 0;
290 IX_STATUS status
= IX_FAIL
;
291 IxNpeDlImageMgrImageLibraryHeader
*header
;
293 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT
,
294 "Entering ixNpeDlImageMgrImageLocate\n");
296 header
= (IxNpeDlImageMgrImageLibraryHeader
*) getIxNpeMicroCodeImageLibrary();
298 if (ixNpeDlImageMgrSignatureCheck (getIxNpeMicroCodeImageLibrary()))
300 /* for each image entry in the image library header ... */
301 while (header
->entry
[imageCount
].eohMarker
!=
302 IX_NPEDL_IMAGEMGR_END_OF_HEADER
)
304 rawImageId
= header
->entry
[imageCount
].image
.id
;
305 ixNpeDlImageMgrImageIdFormat (rawImageId
, &formattedImageId
);
306 /* if a match for imageId is found in the image library header... */
307 if (ixNpeDlImageMgrImageIdCompare (imageId
, &formattedImageId
))
310 * get pointer to the image in the image library using offset from
311 * 1st word in image library
313 UINT32
*tmp
=getIxNpeMicroCodeImageLibrary();
314 imageOffset
= header
->entry
[imageCount
].image
.offset
;
315 *imagePtr
= &tmp
[imageOffset
];
316 /* get the image size */
317 *imageSize
= header
->entry
[imageCount
].image
.size
;
323 if (status
!= IX_SUCCESS
)
325 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageLocate: "
326 "imageId not found in image library header\n");
327 ixNpeDlImageMgrStats
.imageIdNotFound
++;
332 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageLocate: "
333 "invalid signature in image library\n");
336 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT
,
337 "Exiting ixNpeDlImageMgrImageLocate: status = %d\n", status
);
342 * Function definition: ixNpeDlImageMgrLatestImageExtract
344 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
345 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
348 ixNpeDlImageMgrLatestImageExtract (IxNpeDlImageId
*imageId
)
350 UINT32 imageCount
= 0;
352 IxNpeDlImageId formattedImageId
;
353 IX_STATUS status
= IX_FAIL
;
354 IxNpeDlImageMgrImageLibraryHeader
*header
;
357 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT
,
358 "Entering ixNpeDlImageMgrLatestImageExtract\n");
360 header
= (IxNpeDlImageMgrImageLibraryHeader
*) getIxNpeMicroCodeImageLibrary();
362 if (ixNpeDlImageMgrSignatureCheck (getIxNpeMicroCodeImageLibrary()))
364 /* for each image entry in the image library header ... */
365 while (header
->entry
[imageCount
].eohMarker
!=
366 IX_NPEDL_IMAGEMGR_END_OF_HEADER
)
368 rawImageId
= header
->entry
[imageCount
].image
.id
;
369 ixNpeDlImageMgrImageIdFormat (rawImageId
, &formattedImageId
);
371 * if a match for the npe Id and functionality Id of the imageId is
372 * found in the image library header...
374 if(ixNpeDlImageMgrNpeFunctionIdCompare(imageId
, &formattedImageId
))
376 if(imageId
->major
<= formattedImageId
.major
)
378 if(imageId
->minor
< formattedImageId
.minor
)
380 imageId
->minor
= formattedImageId
.minor
;
382 imageId
->major
= formattedImageId
.major
;
388 if (status
!= IX_SUCCESS
)
390 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrLatestImageExtract: "
391 "imageId not found in image library header\n");
392 ixNpeDlImageMgrStats
.imageIdNotFound
++;
397 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrLatestImageGet: "
398 "invalid signature in image library\n");
401 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT
,
402 "Exiting ixNpeDlImageMgrLatestImageGet: status = %d\n", status
);
407 * Function definition: ixNpeDlImageMgrSignatureCheck
409 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
410 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
413 ixNpeDlImageMgrSignatureCheck (UINT32
*microCodeImageLibrary
)
415 IxNpeDlImageMgrImageLibraryHeader
*header
=
416 (IxNpeDlImageMgrImageLibraryHeader
*) microCodeImageLibrary
;
419 if (!header
|| header
->signature
!= IX_NPEDL_IMAGEMGR_SIGNATURE
)
422 ixNpeDlImageMgrStats
.invalidSignature
++;
430 * Function definition: ixNpeDlImageMgrImageIdFormat
432 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
433 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
436 ixNpeDlImageMgrImageIdFormat (
438 IxNpeDlImageId
*imageId
)
440 imageId
->npeId
= (rawImageId
>>
441 IX_NPEDL_IMAGEID_NPEID_OFFSET
) &
442 IX_NPEDL_NPEIMAGE_FIELD_MASK
;
443 imageId
->functionalityId
= (rawImageId
>>
444 IX_NPEDL_IMAGEID_FUNCTIONID_OFFSET
) &
445 IX_NPEDL_NPEIMAGE_FIELD_MASK
;
446 imageId
->major
= (rawImageId
>>
447 IX_NPEDL_IMAGEID_MAJOR_OFFSET
) &
448 IX_NPEDL_NPEIMAGE_FIELD_MASK
;
449 imageId
->minor
= (rawImageId
>>
450 IX_NPEDL_IMAGEID_MINOR_OFFSET
) &
451 IX_NPEDL_NPEIMAGE_FIELD_MASK
;
457 * Function definition: ixNpeDlImageMgrImageIdCompare
459 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
460 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
463 ixNpeDlImageMgrImageIdCompare (
464 IxNpeDlImageId
*imageIdA
,
465 IxNpeDlImageId
*imageIdB
)
467 if ((imageIdA
->npeId
== imageIdB
->npeId
) &&
468 (imageIdA
->functionalityId
== imageIdB
->functionalityId
) &&
469 (imageIdA
->major
== imageIdB
->major
) &&
470 (imageIdA
->minor
== imageIdB
->minor
))
481 * Function definition: ixNpeDlImageMgrNpeFunctionIdCompare
483 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
484 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
487 ixNpeDlImageMgrNpeFunctionIdCompare (
488 IxNpeDlImageId
*imageIdA
,
489 IxNpeDlImageId
*imageIdB
)
491 if ((imageIdA
->npeId
== imageIdB
->npeId
) &&
492 (imageIdA
->functionalityId
== imageIdB
->functionalityId
))
504 * Function definition: ixNpeDlImageMgrStatsShow
507 ixNpeDlImageMgrStatsShow (void)
509 ixOsalLog (IX_OSAL_LOG_LVL_USER
,
510 IX_OSAL_LOG_DEV_STDOUT
,
511 "\nixNpeDlImageMgrStatsShow:\n"
512 "\tInvalid Image Signatures: %u\n"
513 "\tImage Id List capacity too small: %u\n"
514 "\tImage Id not found: %u\n\n",
515 ixNpeDlImageMgrStats
.invalidSignature
,
516 ixNpeDlImageMgrStats
.imageIdListOverflow
,
517 ixNpeDlImageMgrStats
.imageIdNotFound
,
523 * Function definition: ixNpeDlImageMgrStatsReset
526 ixNpeDlImageMgrStatsReset (void)
528 ixNpeDlImageMgrStats
.invalidSignature
= 0;
529 ixNpeDlImageMgrStats
.imageIdListOverflow
= 0;
530 ixNpeDlImageMgrStats
.imageIdNotFound
= 0;
536 * Function definition: ixNpeDlImageMgrImageFind_legacy
538 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
539 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
542 ixNpeDlImageMgrImageFind_legacy (
543 UINT32
*imageLibrary
,
549 /* used to index image entries in image library header */
550 UINT32 imageCount
= 0;
551 IX_STATUS status
= IX_FAIL
;
552 IxNpeDlImageMgrImageLibraryHeader
*header
;
553 BOOL imageFound
= FALSE
;
555 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT
,
556 "Entering ixNpeDlImageMgrImageFind\n");
559 /* If user didn't specify a library to use, use the default
560 * one from IxNpeMicrocode.h
562 if (imageLibrary
== NULL
)
564 imageLibrary
= IxNpeMicroCodeImageLibrary
;
567 if (ixNpeDlImageMgrSignatureCheck (imageLibrary
))
569 header
= (IxNpeDlImageMgrImageLibraryHeader
*) imageLibrary
;
571 /* for each image entry in the image library header ... */
572 while ((header
->entry
[imageCount
].eohMarker
!=
573 IX_NPEDL_IMAGEMGR_END_OF_HEADER
) && !(imageFound
))
575 /* if a match for imageId is found in the image library header... */
576 if (imageId
== header
->entry
[imageCount
].image
.id
)
579 * get pointer to the image in the image library using offset from
580 * 1st word in image library
582 imageOffset
= header
->entry
[imageCount
].image
.offset
;
583 *imagePtr
= &imageLibrary
[imageOffset
];
584 /* get the image size */
585 *imageSize
= header
->entry
[imageCount
].image
.size
;
591 if (status
!= IX_SUCCESS
)
593 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
594 "imageId not found in image library header\n");
595 ixNpeDlImageMgrStats
.imageIdNotFound
++;
600 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
601 "invalid signature in image library\n");
604 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT
,
605 "Exiting ixNpeDlImageMgrImageFind: status = %d\n", status
);
611 * Function definition: ixNpeDlImageMgrImageFind
614 ixNpeDlImageMgrImageFind (
615 UINT32
*imageLibrary
,
620 IxNpeDlImageMgrImageHeader
*image
;
623 /* If user didn't specify a library to use, use the default
624 * one from IxNpeMicrocode.h
626 if (imageLibrary
== NULL
)
628 #ifdef IX_NPEDL_READ_MICROCODE_FROM_FILE
629 if (ixNpeMicrocode_binaryArray
== NULL
)
631 printk (KERN_ERR
"ixp400.o: ERROR, no Microcode found in memory\n");
636 imageLibrary
= ixNpeMicrocode_binaryArray
;
639 imageLibrary
= getIxNpeMicroCodeImageLibrary();
640 if (imageLibrary
== NULL
)
642 printf ("npe: ERROR, no Microcode found in memory\n");
645 #endif /* IX_NPEDL_READ_MICROCODE_FROM_FILE */
649 /* For backward's compatibility with previous image format */
650 if (ixNpeDlImageMgrSignatureCheck(imageLibrary
))
652 return ixNpeDlImageMgrImageFind_legacy(imageLibrary
,
659 while (*(imageLibrary
+offset
) == NPE_IMAGE_MARKER
)
661 image
= (IxNpeDlImageMgrImageHeader
*)(imageLibrary
+offset
);
662 offset
+= sizeof(IxNpeDlImageMgrImageHeader
)/sizeof(UINT32
);
664 if (image
->id
== imageId
)
666 *imagePtr
= imageLibrary
+ offset
;
667 *imageSize
= image
->size
;
670 /* 2 consecutive NPE_IMAGE_MARKER's indicates end of library */
671 else if (image
->id
== NPE_IMAGE_MARKER
)
673 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
674 "imageId not found in image library header\n");
675 ixNpeDlImageMgrStats
.imageIdNotFound
++;
676 /* reached end of library, image not found */
679 offset
+= image
->size
;
682 /* If we get here, our image library may be corrupted */
683 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
684 "image library format may be invalid or corrupted\n");