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