blob: 048448388216d687f16d30cc59cccb16f63ec3e8 [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
Jean-Christophe PLAGNIOL-VILLARDa1cf0272008-01-07 08:41:34 +0100136static UINT32* getIxNpeMicroCodeImageLibrary(void)
137{
138 char *s;
Jean-Christophe PLAGNIOL-VILLARDb4e2f892009-01-31 09:53:39 +0100139
Jean-Christophe PLAGNIOL-VILLARDa1cf0272008-01-07 08:41:34 +0100140 if ((s = getenv("npe_ucode")) != NULL)
141 return (UINT32*) simple_strtoul(s, NULL, 16);
142 else
Jean-Christophe PLAGNIOL-VILLARDb4e2f892009-01-31 09:53:39 +0100143 return NULL;
Jean-Christophe PLAGNIOL-VILLARDa1cf0272008-01-07 08:41:34 +0100144}
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200145
146/*
147 * static function prototypes.
148 */
149PRIVATE BOOL
150ixNpeDlImageMgrSignatureCheck (UINT32 *microCodeImageLibrary);
151
152PRIVATE void
153ixNpeDlImageMgrImageIdFormat (UINT32 rawImageId, IxNpeDlImageId *imageId);
154
155PRIVATE BOOL
156ixNpeDlImageMgrImageIdCompare (IxNpeDlImageId *imageIdA,
157 IxNpeDlImageId *imageIdB);
158
159PRIVATE BOOL
160ixNpeDlImageMgrNpeFunctionIdCompare (IxNpeDlImageId *imageIdA,
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200161 IxNpeDlImageId *imageIdB);
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200162
Michael Schwingen63ebcc42007-11-10 15:44:12 +0100163#if 0
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200164PRIVATE IX_STATUS
165ixNpeDlImageMgrImageFind_legacy (UINT32 *imageLibrary,
166 UINT32 imageId,
167 UINT32 **imagePtr,
168 UINT32 *imageSize);
169
170/*
171 * Function definition: ixNpeDlImageMgrMicrocodeImageLibraryOverride
172 *
173 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
174 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
175 */
176IX_STATUS
177ixNpeDlImageMgrMicrocodeImageLibraryOverride (
178 UINT32 *clientImageLibrary)
179{
180 IX_STATUS status = IX_SUCCESS;
181
182 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
183 "Entering ixNpeDlImageMgrMicrocodeImageLibraryOverride\n");
184
185 if (ixNpeDlImageMgrSignatureCheck (clientImageLibrary))
186 {
187 IxNpeMicroCodeImageLibrary = clientImageLibrary;
188 }
189 else
190 {
191 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrMicrocodeImageLibraryOverride: "
192 "Client-supplied image has invalid signature\n");
193 status = IX_FAIL;
194 }
195
196 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
197 "Exiting ixNpeDlImageMgrMicrocodeImageLibraryOverride: status = %d\n",
198 status);
199 return status;
200}
Michael Schwingen63ebcc42007-11-10 15:44:12 +0100201#endif
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200202
203/*
204 * Function definition: ixNpeDlImageMgrImageListExtract
205 *
206 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
207 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
208 */
209IX_STATUS
210ixNpeDlImageMgrImageListExtract (
211 IxNpeDlImageId *imageListPtr,
212 UINT32 *numImages)
213{
214 UINT32 rawImageId;
215 IxNpeDlImageId formattedImageId;
216 IX_STATUS status = IX_SUCCESS;
217 UINT32 imageCount = 0;
218 IxNpeDlImageMgrImageLibraryHeader *header;
219
220 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
221 "Entering ixNpeDlImageMgrImageListExtract\n");
222
Jean-Christophe PLAGNIOL-VILLARDa1cf0272008-01-07 08:41:34 +0100223 header = (IxNpeDlImageMgrImageLibraryHeader *) getIxNpeMicroCodeImageLibrary();
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200224
Jean-Christophe PLAGNIOL-VILLARDa1cf0272008-01-07 08:41:34 +0100225 if (ixNpeDlImageMgrSignatureCheck (getIxNpeMicroCodeImageLibrary()))
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200226 {
227 /* for each image entry in the image header ... */
228 while (header->entry[imageCount].eohMarker !=
229 IX_NPEDL_IMAGEMGR_END_OF_HEADER)
230 {
231 /*
232 * if the image list container from calling function has capacity,
233 * add the image id to the list
234 */
235 if ((imageListPtr != NULL) && (imageCount < *numImages))
236 {
237 rawImageId = header->entry[imageCount].image.id;
238 ixNpeDlImageMgrImageIdFormat (rawImageId, &formattedImageId);
239 imageListPtr[imageCount] = formattedImageId;
240 }
241 /* imageCount reflects no. of image entries in image library header */
242 imageCount++;
243 }
244
245 /*
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
248 */
249 if ((imageListPtr != NULL) && (imageCount > *numImages))
250 {
251 status = IX_FAIL;
252 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageListExtract: "
253 "number of Ids found exceeds list capacity\n");
254 ixNpeDlImageMgrStats.imageIdListOverflow++;
255 }
256 /* return number of image ids found in image library header */
257 *numImages = imageCount;
258 }
259 else
260 {
261 status = IX_FAIL;
262 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageListExtract: "
263 "invalid signature in image\n");
264 }
265
266 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
267 "Exiting ixNpeDlImageMgrImageListExtract: status = %d\n",
268 status);
269 return status;
270}
271
272
273/*
274 * Function definition: ixNpeDlImageMgrImageLocate
275 *
276 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
277 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
278 */
279IX_STATUS
280ixNpeDlImageMgrImageLocate (
281 IxNpeDlImageId *imageId,
282 UINT32 **imagePtr,
283 UINT32 *imageSize)
284{
285 UINT32 imageOffset;
286 UINT32 rawImageId;
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;
292
293 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
294 "Entering ixNpeDlImageMgrImageLocate\n");
295
Jean-Christophe PLAGNIOL-VILLARDa1cf0272008-01-07 08:41:34 +0100296 header = (IxNpeDlImageMgrImageLibraryHeader *) getIxNpeMicroCodeImageLibrary();
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200297
Jean-Christophe PLAGNIOL-VILLARDa1cf0272008-01-07 08:41:34 +0100298 if (ixNpeDlImageMgrSignatureCheck (getIxNpeMicroCodeImageLibrary()))
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200299 {
300 /* for each image entry in the image library header ... */
301 while (header->entry[imageCount].eohMarker !=
302 IX_NPEDL_IMAGEMGR_END_OF_HEADER)
303 {
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))
308 {
309 /*
310 * get pointer to the image in the image library using offset from
311 * 1st word in image library
312 */
Jean-Christophe PLAGNIOL-VILLARDa1cf0272008-01-07 08:41:34 +0100313 UINT32 *tmp=getIxNpeMicroCodeImageLibrary();
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200314 imageOffset = header->entry[imageCount].image.offset;
Jean-Christophe PLAGNIOL-VILLARDa1cf0272008-01-07 08:41:34 +0100315 *imagePtr = &tmp[imageOffset];
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200316 /* get the image size */
317 *imageSize = header->entry[imageCount].image.size;
318 status = IX_SUCCESS;
319 break;
320 }
321 imageCount++;
322 }
323 if (status != IX_SUCCESS)
324 {
325 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageLocate: "
326 "imageId not found in image library header\n");
327 ixNpeDlImageMgrStats.imageIdNotFound++;
328 }
329 }
330 else
331 {
332 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageLocate: "
333 "invalid signature in image library\n");
334 }
335
336 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
337 "Exiting ixNpeDlImageMgrImageLocate: status = %d\n", status);
338 return status;
339}
340
341/*
342 * Function definition: ixNpeDlImageMgrLatestImageExtract
343 *
344 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
345 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
346 */
347IX_STATUS
348ixNpeDlImageMgrLatestImageExtract (IxNpeDlImageId *imageId)
349{
350 UINT32 imageCount = 0;
351 UINT32 rawImageId;
352 IxNpeDlImageId formattedImageId;
353 IX_STATUS status = IX_FAIL;
354 IxNpeDlImageMgrImageLibraryHeader *header;
355
356
357 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
358 "Entering ixNpeDlImageMgrLatestImageExtract\n");
359
Jean-Christophe PLAGNIOL-VILLARDa1cf0272008-01-07 08:41:34 +0100360 header = (IxNpeDlImageMgrImageLibraryHeader *) getIxNpeMicroCodeImageLibrary();
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200361
Jean-Christophe PLAGNIOL-VILLARDa1cf0272008-01-07 08:41:34 +0100362 if (ixNpeDlImageMgrSignatureCheck (getIxNpeMicroCodeImageLibrary()))
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200363 {
364 /* for each image entry in the image library header ... */
365 while (header->entry[imageCount].eohMarker !=
366 IX_NPEDL_IMAGEMGR_END_OF_HEADER)
367 {
368 rawImageId = header->entry[imageCount].image.id;
369 ixNpeDlImageMgrImageIdFormat (rawImageId, &formattedImageId);
370 /*
371 * if a match for the npe Id and functionality Id of the imageId is
372 * found in the image library header...
373 */
374 if(ixNpeDlImageMgrNpeFunctionIdCompare(imageId, &formattedImageId))
375 {
376 if(imageId->major <= formattedImageId.major)
377 {
378 if(imageId->minor < formattedImageId.minor)
379 {
380 imageId->minor = formattedImageId.minor;
381 }
382 imageId->major = formattedImageId.major;
383 }
384 status = IX_SUCCESS;
385 }
386 imageCount++;
387 }
388 if (status != IX_SUCCESS)
389 {
390 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrLatestImageExtract: "
391 "imageId not found in image library header\n");
392 ixNpeDlImageMgrStats.imageIdNotFound++;
393 }
394 }
395 else
396 {
397 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrLatestImageGet: "
398 "invalid signature in image library\n");
399 }
400
401 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
402 "Exiting ixNpeDlImageMgrLatestImageGet: status = %d\n", status);
403 return status;
404}
405
406/*
407 * Function definition: ixNpeDlImageMgrSignatureCheck
408 *
409 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
410 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
411 */
412PRIVATE BOOL
413ixNpeDlImageMgrSignatureCheck (UINT32 *microCodeImageLibrary)
414{
415 IxNpeDlImageMgrImageLibraryHeader *header =
416 (IxNpeDlImageMgrImageLibraryHeader *) microCodeImageLibrary;
York Sun472d5462013-04-01 11:29:11 -0700417 BOOL result = true;
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200418
Jean-Christophe PLAGNIOL-VILLARDb4e2f892009-01-31 09:53:39 +0100419 if (!header || header->signature != IX_NPEDL_IMAGEMGR_SIGNATURE)
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200420 {
York Sun472d5462013-04-01 11:29:11 -0700421 result = false;
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200422 ixNpeDlImageMgrStats.invalidSignature++;
423 }
424
425 return result;
426}
427
428
429/*
430 * Function definition: ixNpeDlImageMgrImageIdFormat
431 *
432 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
433 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
434 */
435PRIVATE void
436ixNpeDlImageMgrImageIdFormat (
437 UINT32 rawImageId,
438 IxNpeDlImageId *imageId)
439{
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;
452
453}
454
455
456/*
457 * Function definition: ixNpeDlImageMgrImageIdCompare
458 *
459 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
460 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
461 */
462PRIVATE BOOL
463ixNpeDlImageMgrImageIdCompare (
464 IxNpeDlImageId *imageIdA,
465 IxNpeDlImageId *imageIdB)
466{
467 if ((imageIdA->npeId == imageIdB->npeId) &&
468 (imageIdA->functionalityId == imageIdB->functionalityId) &&
469 (imageIdA->major == imageIdB->major) &&
470 (imageIdA->minor == imageIdB->minor))
471 {
York Sun472d5462013-04-01 11:29:11 -0700472 return true;
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200473 }
474 else
475 {
York Sun472d5462013-04-01 11:29:11 -0700476 return false;
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200477 }
478}
479
480/*
481 * Function definition: ixNpeDlImageMgrNpeFunctionIdCompare
482 *
483 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
484 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
485 */
486PRIVATE BOOL
487ixNpeDlImageMgrNpeFunctionIdCompare (
488 IxNpeDlImageId *imageIdA,
489 IxNpeDlImageId *imageIdB)
490{
491 if ((imageIdA->npeId == imageIdB->npeId) &&
492 (imageIdA->functionalityId == imageIdB->functionalityId))
493 {
York Sun472d5462013-04-01 11:29:11 -0700494 return true;
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200495 }
496 else
497 {
York Sun472d5462013-04-01 11:29:11 -0700498 return false;
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200499 }
500}
501
502
503/*
504 * Function definition: ixNpeDlImageMgrStatsShow
505 */
506void
507ixNpeDlImageMgrStatsShow (void)
508{
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,
518 0,0,0);
519}
520
521
522/*
523 * Function definition: ixNpeDlImageMgrStatsReset
524 */
525void
526ixNpeDlImageMgrStatsReset (void)
527{
528 ixNpeDlImageMgrStats.invalidSignature = 0;
529 ixNpeDlImageMgrStats.imageIdListOverflow = 0;
530 ixNpeDlImageMgrStats.imageIdNotFound = 0;
531}
532
533
Michael Schwingen63ebcc42007-11-10 15:44:12 +0100534#if 0
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200535/*
536 * Function definition: ixNpeDlImageMgrImageFind_legacy
537 *
538 * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
539 * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
540 */
541PRIVATE IX_STATUS
542ixNpeDlImageMgrImageFind_legacy (
543 UINT32 *imageLibrary,
544 UINT32 imageId,
545 UINT32 **imagePtr,
546 UINT32 *imageSize)
547{
548 UINT32 imageOffset;
549 /* used to index image entries in image library header */
550 UINT32 imageCount = 0;
551 IX_STATUS status = IX_FAIL;
552 IxNpeDlImageMgrImageLibraryHeader *header;
York Sun472d5462013-04-01 11:29:11 -0700553 BOOL imageFound = false;
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200554
555 IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
556 "Entering ixNpeDlImageMgrImageFind\n");
557
558
559 /* If user didn't specify a library to use, use the default
560 * one from IxNpeMicrocode.h
561 */
562 if (imageLibrary == NULL)
563 {
564 imageLibrary = IxNpeMicroCodeImageLibrary;
565 }
566
567 if (ixNpeDlImageMgrSignatureCheck (imageLibrary))
568 {
569 header = (IxNpeDlImageMgrImageLibraryHeader *) imageLibrary;
570
571 /* for each image entry in the image library header ... */
572 while ((header->entry[imageCount].eohMarker !=
573 IX_NPEDL_IMAGEMGR_END_OF_HEADER) && !(imageFound))
574 {
575 /* if a match for imageId is found in the image library header... */
576 if (imageId == header->entry[imageCount].image.id)
577 {
578 /*
579 * get pointer to the image in the image library using offset from
580 * 1st word in image library
581 */
582 imageOffset = header->entry[imageCount].image.offset;
583 *imagePtr = &imageLibrary[imageOffset];
584 /* get the image size */
585 *imageSize = header->entry[imageCount].image.size;
586 status = IX_SUCCESS;
York Sun472d5462013-04-01 11:29:11 -0700587 imageFound = true;
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200588 }
589 imageCount++;
590 }
591 if (status != IX_SUCCESS)
592 {
593 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
594 "imageId not found in image library header\n");
595 ixNpeDlImageMgrStats.imageIdNotFound++;
596 }
597 }
598 else
599 {
600 IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
601 "invalid signature in image library\n");
602 }
603
604 IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
605 "Exiting ixNpeDlImageMgrImageFind: status = %d\n", status);
606 return status;
607}
Michael Schwingen63ebcc42007-11-10 15:44:12 +0100608#endif
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200609
610/*
611 * Function definition: ixNpeDlImageMgrImageFind
612 */
613IX_STATUS
614ixNpeDlImageMgrImageFind (
615 UINT32 *imageLibrary,
616 UINT32 imageId,
617 UINT32 **imagePtr,
618 UINT32 *imageSize)
619{
620 IxNpeDlImageMgrImageHeader *image;
621 UINT32 offset = 0;
622
623 /* If user didn't specify a library to use, use the default
624 * one from IxNpeMicrocode.h
625 */
626 if (imageLibrary == NULL)
627 {
628#ifdef IX_NPEDL_READ_MICROCODE_FROM_FILE
629 if (ixNpeMicrocode_binaryArray == NULL)
630 {
631 printk (KERN_ERR "ixp400.o: ERROR, no Microcode found in memory\n");
632 return IX_FAIL;
633 }
634 else
635 {
636 imageLibrary = ixNpeMicrocode_binaryArray;
637 }
638#else
Jean-Christophe PLAGNIOL-VILLARDa1cf0272008-01-07 08:41:34 +0100639 imageLibrary = getIxNpeMicroCodeImageLibrary();
Jean-Christophe PLAGNIOL-VILLARDb4e2f892009-01-31 09:53:39 +0100640 if (imageLibrary == NULL)
641 {
642 printf ("npe: ERROR, no Microcode found in memory\n");
643 return IX_FAIL;
644 }
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200645#endif /* IX_NPEDL_READ_MICROCODE_FROM_FILE */
646 }
647
Michael Schwingen63ebcc42007-11-10 15:44:12 +0100648#if 0
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200649 /* For backward's compatibility with previous image format */
650 if (ixNpeDlImageMgrSignatureCheck(imageLibrary))
651 {
652 return ixNpeDlImageMgrImageFind_legacy(imageLibrary,
653 imageId,
654 imagePtr,
655 imageSize);
656 }
Michael Schwingen63ebcc42007-11-10 15:44:12 +0100657#endif
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200658
659 while (*(imageLibrary+offset) == NPE_IMAGE_MARKER)
660 {
661 image = (IxNpeDlImageMgrImageHeader *)(imageLibrary+offset);
662 offset += sizeof(IxNpeDlImageMgrImageHeader)/sizeof(UINT32);
663
664 if (image->id == imageId)
665 {
666 *imagePtr = imageLibrary + offset;
667 *imageSize = image->size;
668 return IX_SUCCESS;
669 }
670 /* 2 consecutive NPE_IMAGE_MARKER's indicates end of library */
671 else if (image->id == NPE_IMAGE_MARKER)
672 {
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 */
677 return IX_FAIL;
678 }
679 offset += image->size;
680 }
681
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");
685 return IX_FAIL;
686}
687