blob: e05c228537c1122830d3b31c421de5fc1ce972fb [file] [log] [blame]
Wolfgang Denkba94a1b2006-05-30 15:56:48 +02001/**
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 */
82typedef 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 */
93typedef 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 */
103typedef 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 */
114typedef struct
115{
116 UINT32 marker;
117 UINT32 id;
118 UINT32 size;
119} IxNpeDlImageMgrImageHeader;
120
121/* module statistics counters */
122typedef 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 */
134static IxNpeDlImageMgrStats ixNpeDlImageMgrStats;
135
136/* default image */
137#ifdef IX_NPEDL_READ_MICROCODE_FROM_FILE
138static UINT32 *IxNpeMicroCodeImageLibrary = NULL; /* Gets set to proper value at runtime */
139#else
140static UINT32 *IxNpeMicroCodeImageLibrary = (UINT32 *)IxNpeMicrocode_array;
141#endif
142
143
144/*
145 * static function prototypes.
146 */
147PRIVATE BOOL
148ixNpeDlImageMgrSignatureCheck (UINT32 *microCodeImageLibrary);
149
150PRIVATE void
151ixNpeDlImageMgrImageIdFormat (UINT32 rawImageId, IxNpeDlImageId *imageId);
152
153PRIVATE BOOL
154ixNpeDlImageMgrImageIdCompare (IxNpeDlImageId *imageIdA,
155 IxNpeDlImageId *imageIdB);
156
157PRIVATE BOOL
158ixNpeDlImageMgrNpeFunctionIdCompare (IxNpeDlImageId *imageIdA,
159 IxNpeDlImageId *imageIdB);
160
161PRIVATE IX_STATUS
162ixNpeDlImageMgrImageFind_legacy (UINT32 *imageLibrary,
163 UINT32 imageId,
164 UINT32 **imagePtr,
165 UINT32 *imageSize);
166
167/*
168 * Function definition: ixNpeDlImageMgrMicrocodeImageLibraryOverride
169 *
170 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
171 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
172 */
173IX_STATUS
174ixNpeDlImageMgrMicrocodeImageLibraryOverride (
175 UINT32 *clientImageLibrary)
176{
177 IX_STATUS status = IX_SUCCESS;
178
179 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
180 "Entering ixNpeDlImageMgrMicrocodeImageLibraryOverride\n");
181
182 if (ixNpeDlImageMgrSignatureCheck (clientImageLibrary))
183 {
184 IxNpeMicroCodeImageLibrary = clientImageLibrary;
185 }
186 else
187 {
188 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrMicrocodeImageLibraryOverride: "
189 "Client-supplied image has invalid signature\n");
190 status = IX_FAIL;
191 }
192
193 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
194 "Exiting ixNpeDlImageMgrMicrocodeImageLibraryOverride: status = %d\n",
195 status);
196 return status;
197}
198
199
200/*
201 * Function definition: ixNpeDlImageMgrImageListExtract
202 *
203 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
204 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
205 */
206IX_STATUS
207ixNpeDlImageMgrImageListExtract (
208 IxNpeDlImageId *imageListPtr,
209 UINT32 *numImages)
210{
211 UINT32 rawImageId;
212 IxNpeDlImageId formattedImageId;
213 IX_STATUS status = IX_SUCCESS;
214 UINT32 imageCount = 0;
215 IxNpeDlImageMgrImageLibraryHeader *header;
216
217 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
218 "Entering ixNpeDlImageMgrImageListExtract\n");
219
220 header = (IxNpeDlImageMgrImageLibraryHeader *) IxNpeMicroCodeImageLibrary;
221
222 if (ixNpeDlImageMgrSignatureCheck (IxNpeMicroCodeImageLibrary))
223 {
224 /* for each image entry in the image header ... */
225 while (header->entry[imageCount].eohMarker !=
226 IX_NPEDL_IMAGEMGR_END_OF_HEADER)
227 {
228 /*
229 * if the image list container from calling function has capacity,
230 * add the image id to the list
231 */
232 if ((imageListPtr != NULL) && (imageCount < *numImages))
233 {
234 rawImageId = header->entry[imageCount].image.id;
235 ixNpeDlImageMgrImageIdFormat (rawImageId, &formattedImageId);
236 imageListPtr[imageCount] = formattedImageId;
237 }
238 /* imageCount reflects no. of image entries in image library header */
239 imageCount++;
240 }
241
242 /*
243 * if image list container from calling function was too small to
244 * contain all image ids in the header, set return status to FAIL
245 */
246 if ((imageListPtr != NULL) && (imageCount > *numImages))
247 {
248 status = IX_FAIL;
249 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageListExtract: "
250 "number of Ids found exceeds list capacity\n");
251 ixNpeDlImageMgrStats.imageIdListOverflow++;
252 }
253 /* return number of image ids found in image library header */
254 *numImages = imageCount;
255 }
256 else
257 {
258 status = IX_FAIL;
259 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageListExtract: "
260 "invalid signature in image\n");
261 }
262
263 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
264 "Exiting ixNpeDlImageMgrImageListExtract: status = %d\n",
265 status);
266 return status;
267}
268
269
270/*
271 * Function definition: ixNpeDlImageMgrImageLocate
272 *
273 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
274 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
275 */
276IX_STATUS
277ixNpeDlImageMgrImageLocate (
278 IxNpeDlImageId *imageId,
279 UINT32 **imagePtr,
280 UINT32 *imageSize)
281{
282 UINT32 imageOffset;
283 UINT32 rawImageId;
284 IxNpeDlImageId formattedImageId;
285 /* used to index image entries in image library header */
286 UINT32 imageCount = 0;
287 IX_STATUS status = IX_FAIL;
288 IxNpeDlImageMgrImageLibraryHeader *header;
289
290 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
291 "Entering ixNpeDlImageMgrImageLocate\n");
292
293 header = (IxNpeDlImageMgrImageLibraryHeader *) IxNpeMicroCodeImageLibrary;
294
295 if (ixNpeDlImageMgrSignatureCheck (IxNpeMicroCodeImageLibrary))
296 {
297 /* for each image entry in the image library header ... */
298 while (header->entry[imageCount].eohMarker !=
299 IX_NPEDL_IMAGEMGR_END_OF_HEADER)
300 {
301 rawImageId = header->entry[imageCount].image.id;
302 ixNpeDlImageMgrImageIdFormat (rawImageId, &formattedImageId);
303 /* if a match for imageId is found in the image library header... */
304 if (ixNpeDlImageMgrImageIdCompare (imageId, &formattedImageId))
305 {
306 /*
307 * get pointer to the image in the image library using offset from
308 * 1st word in image library
309 */
310 imageOffset = header->entry[imageCount].image.offset;
311 *imagePtr = &IxNpeMicroCodeImageLibrary[imageOffset];
312 /* get the image size */
313 *imageSize = header->entry[imageCount].image.size;
314 status = IX_SUCCESS;
315 break;
316 }
317 imageCount++;
318 }
319 if (status != IX_SUCCESS)
320 {
321 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageLocate: "
322 "imageId not found in image library header\n");
323 ixNpeDlImageMgrStats.imageIdNotFound++;
324 }
325 }
326 else
327 {
328 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageLocate: "
329 "invalid signature in image library\n");
330 }
331
332 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
333 "Exiting ixNpeDlImageMgrImageLocate: status = %d\n", status);
334 return status;
335}
336
337/*
338 * Function definition: ixNpeDlImageMgrLatestImageExtract
339 *
340 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
341 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
342 */
343IX_STATUS
344ixNpeDlImageMgrLatestImageExtract (IxNpeDlImageId *imageId)
345{
346 UINT32 imageCount = 0;
347 UINT32 rawImageId;
348 IxNpeDlImageId formattedImageId;
349 IX_STATUS status = IX_FAIL;
350 IxNpeDlImageMgrImageLibraryHeader *header;
351
352
353 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
354 "Entering ixNpeDlImageMgrLatestImageExtract\n");
355
356 header = (IxNpeDlImageMgrImageLibraryHeader *) IxNpeMicroCodeImageLibrary;
357
358 if (ixNpeDlImageMgrSignatureCheck (IxNpeMicroCodeImageLibrary))
359 {
360 /* for each image entry in the image library header ... */
361 while (header->entry[imageCount].eohMarker !=
362 IX_NPEDL_IMAGEMGR_END_OF_HEADER)
363 {
364 rawImageId = header->entry[imageCount].image.id;
365 ixNpeDlImageMgrImageIdFormat (rawImageId, &formattedImageId);
366 /*
367 * if a match for the npe Id and functionality Id of the imageId is
368 * found in the image library header...
369 */
370 if(ixNpeDlImageMgrNpeFunctionIdCompare(imageId, &formattedImageId))
371 {
372 if(imageId->major <= formattedImageId.major)
373 {
374 if(imageId->minor < formattedImageId.minor)
375 {
376 imageId->minor = formattedImageId.minor;
377 }
378 imageId->major = formattedImageId.major;
379 }
380 status = IX_SUCCESS;
381 }
382 imageCount++;
383 }
384 if (status != IX_SUCCESS)
385 {
386 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrLatestImageExtract: "
387 "imageId not found in image library header\n");
388 ixNpeDlImageMgrStats.imageIdNotFound++;
389 }
390 }
391 else
392 {
393 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrLatestImageGet: "
394 "invalid signature in image library\n");
395 }
396
397 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
398 "Exiting ixNpeDlImageMgrLatestImageGet: status = %d\n", status);
399 return status;
400}
401
402/*
403 * Function definition: ixNpeDlImageMgrSignatureCheck
404 *
405 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
406 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
407 */
408PRIVATE BOOL
409ixNpeDlImageMgrSignatureCheck (UINT32 *microCodeImageLibrary)
410{
411 IxNpeDlImageMgrImageLibraryHeader *header =
412 (IxNpeDlImageMgrImageLibraryHeader *) microCodeImageLibrary;
413 BOOL result = TRUE;
414
415 if (header->signature != IX_NPEDL_IMAGEMGR_SIGNATURE)
416 {
417 result = FALSE;
418 ixNpeDlImageMgrStats.invalidSignature++;
419 }
420
421 return result;
422}
423
424
425/*
426 * Function definition: ixNpeDlImageMgrImageIdFormat
427 *
428 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
429 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
430 */
431PRIVATE void
432ixNpeDlImageMgrImageIdFormat (
433 UINT32 rawImageId,
434 IxNpeDlImageId *imageId)
435{
436 imageId->npeId = (rawImageId >>
437 IX_NPEDL_IMAGEID_NPEID_OFFSET) &
438 IX_NPEDL_NPEIMAGE_FIELD_MASK;
439 imageId->functionalityId = (rawImageId >>
440 IX_NPEDL_IMAGEID_FUNCTIONID_OFFSET) &
441 IX_NPEDL_NPEIMAGE_FIELD_MASK;
442 imageId->major = (rawImageId >>
443 IX_NPEDL_IMAGEID_MAJOR_OFFSET) &
444 IX_NPEDL_NPEIMAGE_FIELD_MASK;
445 imageId->minor = (rawImageId >>
446 IX_NPEDL_IMAGEID_MINOR_OFFSET) &
447 IX_NPEDL_NPEIMAGE_FIELD_MASK;
448
449}
450
451
452/*
453 * Function definition: ixNpeDlImageMgrImageIdCompare
454 *
455 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
456 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
457 */
458PRIVATE BOOL
459ixNpeDlImageMgrImageIdCompare (
460 IxNpeDlImageId *imageIdA,
461 IxNpeDlImageId *imageIdB)
462{
463 if ((imageIdA->npeId == imageIdB->npeId) &&
464 (imageIdA->functionalityId == imageIdB->functionalityId) &&
465 (imageIdA->major == imageIdB->major) &&
466 (imageIdA->minor == imageIdB->minor))
467 {
468 return TRUE;
469 }
470 else
471 {
472 return FALSE;
473 }
474}
475
476/*
477 * Function definition: ixNpeDlImageMgrNpeFunctionIdCompare
478 *
479 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
480 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
481 */
482PRIVATE BOOL
483ixNpeDlImageMgrNpeFunctionIdCompare (
484 IxNpeDlImageId *imageIdA,
485 IxNpeDlImageId *imageIdB)
486{
487 if ((imageIdA->npeId == imageIdB->npeId) &&
488 (imageIdA->functionalityId == imageIdB->functionalityId))
489 {
490 return TRUE;
491 }
492 else
493 {
494 return FALSE;
495 }
496}
497
498
499/*
500 * Function definition: ixNpeDlImageMgrStatsShow
501 */
502void
503ixNpeDlImageMgrStatsShow (void)
504{
505 ixOsalLog (IX_OSAL_LOG_LVL_USER,
506 IX_OSAL_LOG_DEV_STDOUT,
507 "\nixNpeDlImageMgrStatsShow:\n"
508 "\tInvalid Image Signatures: %u\n"
509 "\tImage Id List capacity too small: %u\n"
510 "\tImage Id not found: %u\n\n",
511 ixNpeDlImageMgrStats.invalidSignature,
512 ixNpeDlImageMgrStats.imageIdListOverflow,
513 ixNpeDlImageMgrStats.imageIdNotFound,
514 0,0,0);
515}
516
517
518/*
519 * Function definition: ixNpeDlImageMgrStatsReset
520 */
521void
522ixNpeDlImageMgrStatsReset (void)
523{
524 ixNpeDlImageMgrStats.invalidSignature = 0;
525 ixNpeDlImageMgrStats.imageIdListOverflow = 0;
526 ixNpeDlImageMgrStats.imageIdNotFound = 0;
527}
528
529
530/*
531 * Function definition: ixNpeDlImageMgrImageFind_legacy
532 *
533 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
534 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
535 */
536PRIVATE IX_STATUS
537ixNpeDlImageMgrImageFind_legacy (
538 UINT32 *imageLibrary,
539 UINT32 imageId,
540 UINT32 **imagePtr,
541 UINT32 *imageSize)
542{
543 UINT32 imageOffset;
544 /* used to index image entries in image library header */
545 UINT32 imageCount = 0;
546 IX_STATUS status = IX_FAIL;
547 IxNpeDlImageMgrImageLibraryHeader *header;
548 BOOL imageFound = FALSE;
549
550 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
551 "Entering ixNpeDlImageMgrImageFind\n");
552
553
554 /* If user didn't specify a library to use, use the default
555 * one from IxNpeMicrocode.h
556 */
557 if (imageLibrary == NULL)
558 {
559 imageLibrary = IxNpeMicroCodeImageLibrary;
560 }
561
562 if (ixNpeDlImageMgrSignatureCheck (imageLibrary))
563 {
564 header = (IxNpeDlImageMgrImageLibraryHeader *) imageLibrary;
565
566 /* for each image entry in the image library header ... */
567 while ((header->entry[imageCount].eohMarker !=
568 IX_NPEDL_IMAGEMGR_END_OF_HEADER) && !(imageFound))
569 {
570 /* if a match for imageId is found in the image library header... */
571 if (imageId == header->entry[imageCount].image.id)
572 {
573 /*
574 * get pointer to the image in the image library using offset from
575 * 1st word in image library
576 */
577 imageOffset = header->entry[imageCount].image.offset;
578 *imagePtr = &imageLibrary[imageOffset];
579 /* get the image size */
580 *imageSize = header->entry[imageCount].image.size;
581 status = IX_SUCCESS;
582 imageFound = TRUE;
583 }
584 imageCount++;
585 }
586 if (status != IX_SUCCESS)
587 {
588 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
589 "imageId not found in image library header\n");
590 ixNpeDlImageMgrStats.imageIdNotFound++;
591 }
592 }
593 else
594 {
595 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
596 "invalid signature in image library\n");
597 }
598
599 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
600 "Exiting ixNpeDlImageMgrImageFind: status = %d\n", status);
601 return status;
602}
603
604
605/*
606 * Function definition: ixNpeDlImageMgrImageFind
607 */
608IX_STATUS
609ixNpeDlImageMgrImageFind (
610 UINT32 *imageLibrary,
611 UINT32 imageId,
612 UINT32 **imagePtr,
613 UINT32 *imageSize)
614{
615 IxNpeDlImageMgrImageHeader *image;
616 UINT32 offset = 0;
617
618 /* If user didn't specify a library to use, use the default
619 * one from IxNpeMicrocode.h
620 */
621 if (imageLibrary == NULL)
622 {
623#ifdef IX_NPEDL_READ_MICROCODE_FROM_FILE
624 if (ixNpeMicrocode_binaryArray == NULL)
625 {
626 printk (KERN_ERR "ixp400.o: ERROR, no Microcode found in memory\n");
627 return IX_FAIL;
628 }
629 else
630 {
631 imageLibrary = ixNpeMicrocode_binaryArray;
632 }
633#else
634 imageLibrary = IxNpeMicroCodeImageLibrary;
635#endif /* IX_NPEDL_READ_MICROCODE_FROM_FILE */
636 }
637
638 /* For backward's compatibility with previous image format */
639 if (ixNpeDlImageMgrSignatureCheck(imageLibrary))
640 {
641 return ixNpeDlImageMgrImageFind_legacy(imageLibrary,
642 imageId,
643 imagePtr,
644 imageSize);
645 }
646
647 while (*(imageLibrary+offset) == NPE_IMAGE_MARKER)
648 {
649 image = (IxNpeDlImageMgrImageHeader *)(imageLibrary+offset);
650 offset += sizeof(IxNpeDlImageMgrImageHeader)/sizeof(UINT32);
651
652 if (image->id == imageId)
653 {
654 *imagePtr = imageLibrary + offset;
655 *imageSize = image->size;
656 return IX_SUCCESS;
657 }
658 /* 2 consecutive NPE_IMAGE_MARKER's indicates end of library */
659 else if (image->id == NPE_IMAGE_MARKER)
660 {
661 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
662 "imageId not found in image library header\n");
663 ixNpeDlImageMgrStats.imageIdNotFound++;
664 /* reached end of library, image not found */
665 return IX_FAIL;
666 }
667 offset += image->size;
668 }
669
670 /* If we get here, our image library may be corrupted */
671 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
672 "image library format may be invalid or corrupted\n");
673 return IX_FAIL;
674}
675