IxNpeDlImageMgr.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. /**
  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. * SPDX-License-Identifier: BSD-3-Clause
  22. * @par
  23. * -- End of Copyright Notice --
  24. */
  25. /*
  26. * Put the system defined include files required.
  27. */
  28. #include "IxOsal.h"
  29. /*
  30. * Put the user defined include files required.
  31. */
  32. #include "IxNpeDlImageMgr_p.h"
  33. #include "IxNpeDlMacros_p.h"
  34. /*
  35. * define the flag which toggles the firmare inclusion
  36. */
  37. #define IX_NPE_MICROCODE_FIRMWARE_INCLUDED 1
  38. #include "IxNpeMicrocode.h"
  39. /*
  40. * Indicates the start of an NPE Image, in new NPE Image Library format.
  41. * 2 consecutive occurances indicates the end of the NPE Image Library
  42. */
  43. #define NPE_IMAGE_MARKER 0xfeedf00d
  44. /*
  45. * Typedefs whose scope is limited to this file.
  46. */
  47. /*
  48. * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
  49. * TO BE DEPRECATED IN A FUTURE RELEASE
  50. */
  51. typedef struct
  52. {
  53. UINT32 size;
  54. UINT32 offset;
  55. UINT32 id;
  56. } IxNpeDlImageMgrImageEntry;
  57. /*
  58. * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
  59. * TO BE DEPRECATED IN A FUTURE RELEASE
  60. */
  61. typedef union
  62. {
  63. IxNpeDlImageMgrImageEntry image;
  64. UINT32 eohMarker;
  65. } IxNpeDlImageMgrHeaderEntry;
  66. /*
  67. * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
  68. * TO BE DEPRECATED IN A FUTURE RELEASE
  69. */
  70. typedef struct
  71. {
  72. UINT32 signature;
  73. /* 1st entry in the header (there may be more than one) */
  74. IxNpeDlImageMgrHeaderEntry entry[1];
  75. } IxNpeDlImageMgrImageLibraryHeader;
  76. /*
  77. * NPE Image Header definition, used in new NPE Image Library format
  78. */
  79. typedef struct
  80. {
  81. UINT32 marker;
  82. UINT32 id;
  83. UINT32 size;
  84. } IxNpeDlImageMgrImageHeader;
  85. /* module statistics counters */
  86. typedef struct
  87. {
  88. UINT32 invalidSignature;
  89. UINT32 imageIdListOverflow;
  90. UINT32 imageIdNotFound;
  91. } IxNpeDlImageMgrStats;
  92. /*
  93. * Variable declarations global to this file only. Externs are followed by
  94. * static variables.
  95. */
  96. static IxNpeDlImageMgrStats ixNpeDlImageMgrStats;
  97. static UINT32* getIxNpeMicroCodeImageLibrary(void)
  98. {
  99. char *s;
  100. if ((s = getenv("npe_ucode")) != NULL)
  101. return (UINT32*) simple_strtoul(s, NULL, 16);
  102. else
  103. return NULL;
  104. }
  105. /*
  106. * static function prototypes.
  107. */
  108. PRIVATE BOOL
  109. ixNpeDlImageMgrSignatureCheck (UINT32 *microCodeImageLibrary);
  110. PRIVATE void
  111. ixNpeDlImageMgrImageIdFormat (UINT32 rawImageId, IxNpeDlImageId *imageId);
  112. PRIVATE BOOL
  113. ixNpeDlImageMgrImageIdCompare (IxNpeDlImageId *imageIdA,
  114. IxNpeDlImageId *imageIdB);
  115. PRIVATE BOOL
  116. ixNpeDlImageMgrNpeFunctionIdCompare (IxNpeDlImageId *imageIdA,
  117. IxNpeDlImageId *imageIdB);
  118. #if 0
  119. PRIVATE IX_STATUS
  120. ixNpeDlImageMgrImageFind_legacy (UINT32 *imageLibrary,
  121. UINT32 imageId,
  122. UINT32 **imagePtr,
  123. UINT32 *imageSize);
  124. /*
  125. * Function definition: ixNpeDlImageMgrMicrocodeImageLibraryOverride
  126. *
  127. * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
  128. * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
  129. */
  130. IX_STATUS
  131. ixNpeDlImageMgrMicrocodeImageLibraryOverride (
  132. UINT32 *clientImageLibrary)
  133. {
  134. IX_STATUS status = IX_SUCCESS;
  135. IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
  136. "Entering ixNpeDlImageMgrMicrocodeImageLibraryOverride\n");
  137. if (ixNpeDlImageMgrSignatureCheck (clientImageLibrary))
  138. {
  139. IxNpeMicroCodeImageLibrary = clientImageLibrary;
  140. }
  141. else
  142. {
  143. IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrMicrocodeImageLibraryOverride: "
  144. "Client-supplied image has invalid signature\n");
  145. status = IX_FAIL;
  146. }
  147. IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
  148. "Exiting ixNpeDlImageMgrMicrocodeImageLibraryOverride: status = %d\n",
  149. status);
  150. return status;
  151. }
  152. #endif
  153. /*
  154. * Function definition: ixNpeDlImageMgrImageListExtract
  155. *
  156. * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
  157. * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
  158. */
  159. IX_STATUS
  160. ixNpeDlImageMgrImageListExtract (
  161. IxNpeDlImageId *imageListPtr,
  162. UINT32 *numImages)
  163. {
  164. UINT32 rawImageId;
  165. IxNpeDlImageId formattedImageId;
  166. IX_STATUS status = IX_SUCCESS;
  167. UINT32 imageCount = 0;
  168. IxNpeDlImageMgrImageLibraryHeader *header;
  169. IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
  170. "Entering ixNpeDlImageMgrImageListExtract\n");
  171. header = (IxNpeDlImageMgrImageLibraryHeader *) getIxNpeMicroCodeImageLibrary();
  172. if (ixNpeDlImageMgrSignatureCheck (getIxNpeMicroCodeImageLibrary()))
  173. {
  174. /* for each image entry in the image header ... */
  175. while (header->entry[imageCount].eohMarker !=
  176. IX_NPEDL_IMAGEMGR_END_OF_HEADER)
  177. {
  178. /*
  179. * if the image list container from calling function has capacity,
  180. * add the image id to the list
  181. */
  182. if ((imageListPtr != NULL) && (imageCount < *numImages))
  183. {
  184. rawImageId = header->entry[imageCount].image.id;
  185. ixNpeDlImageMgrImageIdFormat (rawImageId, &formattedImageId);
  186. imageListPtr[imageCount] = formattedImageId;
  187. }
  188. /* imageCount reflects no. of image entries in image library header */
  189. imageCount++;
  190. }
  191. /*
  192. * if image list container from calling function was too small to
  193. * contain all image ids in the header, set return status to FAIL
  194. */
  195. if ((imageListPtr != NULL) && (imageCount > *numImages))
  196. {
  197. status = IX_FAIL;
  198. IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageListExtract: "
  199. "number of Ids found exceeds list capacity\n");
  200. ixNpeDlImageMgrStats.imageIdListOverflow++;
  201. }
  202. /* return number of image ids found in image library header */
  203. *numImages = imageCount;
  204. }
  205. else
  206. {
  207. status = IX_FAIL;
  208. IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageListExtract: "
  209. "invalid signature in image\n");
  210. }
  211. IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
  212. "Exiting ixNpeDlImageMgrImageListExtract: status = %d\n",
  213. status);
  214. return status;
  215. }
  216. /*
  217. * Function definition: ixNpeDlImageMgrImageLocate
  218. *
  219. * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
  220. * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
  221. */
  222. IX_STATUS
  223. ixNpeDlImageMgrImageLocate (
  224. IxNpeDlImageId *imageId,
  225. UINT32 **imagePtr,
  226. UINT32 *imageSize)
  227. {
  228. UINT32 imageOffset;
  229. UINT32 rawImageId;
  230. IxNpeDlImageId formattedImageId;
  231. /* used to index image entries in image library header */
  232. UINT32 imageCount = 0;
  233. IX_STATUS status = IX_FAIL;
  234. IxNpeDlImageMgrImageLibraryHeader *header;
  235. IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
  236. "Entering ixNpeDlImageMgrImageLocate\n");
  237. header = (IxNpeDlImageMgrImageLibraryHeader *) getIxNpeMicroCodeImageLibrary();
  238. if (ixNpeDlImageMgrSignatureCheck (getIxNpeMicroCodeImageLibrary()))
  239. {
  240. /* for each image entry in the image library header ... */
  241. while (header->entry[imageCount].eohMarker !=
  242. IX_NPEDL_IMAGEMGR_END_OF_HEADER)
  243. {
  244. rawImageId = header->entry[imageCount].image.id;
  245. ixNpeDlImageMgrImageIdFormat (rawImageId, &formattedImageId);
  246. /* if a match for imageId is found in the image library header... */
  247. if (ixNpeDlImageMgrImageIdCompare (imageId, &formattedImageId))
  248. {
  249. /*
  250. * get pointer to the image in the image library using offset from
  251. * 1st word in image library
  252. */
  253. UINT32 *tmp=getIxNpeMicroCodeImageLibrary();
  254. imageOffset = header->entry[imageCount].image.offset;
  255. *imagePtr = &tmp[imageOffset];
  256. /* get the image size */
  257. *imageSize = header->entry[imageCount].image.size;
  258. status = IX_SUCCESS;
  259. break;
  260. }
  261. imageCount++;
  262. }
  263. if (status != IX_SUCCESS)
  264. {
  265. IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageLocate: "
  266. "imageId not found in image library header\n");
  267. ixNpeDlImageMgrStats.imageIdNotFound++;
  268. }
  269. }
  270. else
  271. {
  272. IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageLocate: "
  273. "invalid signature in image library\n");
  274. }
  275. IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
  276. "Exiting ixNpeDlImageMgrImageLocate: status = %d\n", status);
  277. return status;
  278. }
  279. /*
  280. * Function definition: ixNpeDlImageMgrLatestImageExtract
  281. *
  282. * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
  283. * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
  284. */
  285. IX_STATUS
  286. ixNpeDlImageMgrLatestImageExtract (IxNpeDlImageId *imageId)
  287. {
  288. UINT32 imageCount = 0;
  289. UINT32 rawImageId;
  290. IxNpeDlImageId formattedImageId;
  291. IX_STATUS status = IX_FAIL;
  292. IxNpeDlImageMgrImageLibraryHeader *header;
  293. IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
  294. "Entering ixNpeDlImageMgrLatestImageExtract\n");
  295. header = (IxNpeDlImageMgrImageLibraryHeader *) getIxNpeMicroCodeImageLibrary();
  296. if (ixNpeDlImageMgrSignatureCheck (getIxNpeMicroCodeImageLibrary()))
  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. /*
  305. * if a match for the npe Id and functionality Id of the imageId is
  306. * found in the image library header...
  307. */
  308. if(ixNpeDlImageMgrNpeFunctionIdCompare(imageId, &formattedImageId))
  309. {
  310. if(imageId->major <= formattedImageId.major)
  311. {
  312. if(imageId->minor < formattedImageId.minor)
  313. {
  314. imageId->minor = formattedImageId.minor;
  315. }
  316. imageId->major = formattedImageId.major;
  317. }
  318. status = IX_SUCCESS;
  319. }
  320. imageCount++;
  321. }
  322. if (status != IX_SUCCESS)
  323. {
  324. IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrLatestImageExtract: "
  325. "imageId not found in image library header\n");
  326. ixNpeDlImageMgrStats.imageIdNotFound++;
  327. }
  328. }
  329. else
  330. {
  331. IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrLatestImageGet: "
  332. "invalid signature in image library\n");
  333. }
  334. IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
  335. "Exiting ixNpeDlImageMgrLatestImageGet: status = %d\n", status);
  336. return status;
  337. }
  338. /*
  339. * Function definition: ixNpeDlImageMgrSignatureCheck
  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. */
  344. PRIVATE BOOL
  345. ixNpeDlImageMgrSignatureCheck (UINT32 *microCodeImageLibrary)
  346. {
  347. IxNpeDlImageMgrImageLibraryHeader *header =
  348. (IxNpeDlImageMgrImageLibraryHeader *) microCodeImageLibrary;
  349. BOOL result = true;
  350. if (!header || header->signature != IX_NPEDL_IMAGEMGR_SIGNATURE)
  351. {
  352. result = false;
  353. ixNpeDlImageMgrStats.invalidSignature++;
  354. }
  355. return result;
  356. }
  357. /*
  358. * Function definition: ixNpeDlImageMgrImageIdFormat
  359. *
  360. * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
  361. * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
  362. */
  363. PRIVATE void
  364. ixNpeDlImageMgrImageIdFormat (
  365. UINT32 rawImageId,
  366. IxNpeDlImageId *imageId)
  367. {
  368. imageId->npeId = (rawImageId >>
  369. IX_NPEDL_IMAGEID_NPEID_OFFSET) &
  370. IX_NPEDL_NPEIMAGE_FIELD_MASK;
  371. imageId->functionalityId = (rawImageId >>
  372. IX_NPEDL_IMAGEID_FUNCTIONID_OFFSET) &
  373. IX_NPEDL_NPEIMAGE_FIELD_MASK;
  374. imageId->major = (rawImageId >>
  375. IX_NPEDL_IMAGEID_MAJOR_OFFSET) &
  376. IX_NPEDL_NPEIMAGE_FIELD_MASK;
  377. imageId->minor = (rawImageId >>
  378. IX_NPEDL_IMAGEID_MINOR_OFFSET) &
  379. IX_NPEDL_NPEIMAGE_FIELD_MASK;
  380. }
  381. /*
  382. * Function definition: ixNpeDlImageMgrImageIdCompare
  383. *
  384. * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
  385. * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
  386. */
  387. PRIVATE BOOL
  388. ixNpeDlImageMgrImageIdCompare (
  389. IxNpeDlImageId *imageIdA,
  390. IxNpeDlImageId *imageIdB)
  391. {
  392. if ((imageIdA->npeId == imageIdB->npeId) &&
  393. (imageIdA->functionalityId == imageIdB->functionalityId) &&
  394. (imageIdA->major == imageIdB->major) &&
  395. (imageIdA->minor == imageIdB->minor))
  396. {
  397. return true;
  398. }
  399. else
  400. {
  401. return false;
  402. }
  403. }
  404. /*
  405. * Function definition: ixNpeDlImageMgrNpeFunctionIdCompare
  406. *
  407. * FOR BACKWARD-COMPATIBILITY WITH OLD NPE IMAGE LIBRARY FORMAT
  408. * AND/OR LEGACY API FUNCTIONS. TO BE DEPRECATED IN A FUTURE RELEASE
  409. */
  410. PRIVATE BOOL
  411. ixNpeDlImageMgrNpeFunctionIdCompare (
  412. IxNpeDlImageId *imageIdA,
  413. IxNpeDlImageId *imageIdB)
  414. {
  415. if ((imageIdA->npeId == imageIdB->npeId) &&
  416. (imageIdA->functionalityId == imageIdB->functionalityId))
  417. {
  418. return true;
  419. }
  420. else
  421. {
  422. return false;
  423. }
  424. }
  425. /*
  426. * Function definition: ixNpeDlImageMgrStatsShow
  427. */
  428. void
  429. ixNpeDlImageMgrStatsShow (void)
  430. {
  431. ixOsalLog (IX_OSAL_LOG_LVL_USER,
  432. IX_OSAL_LOG_DEV_STDOUT,
  433. "\nixNpeDlImageMgrStatsShow:\n"
  434. "\tInvalid Image Signatures: %u\n"
  435. "\tImage Id List capacity too small: %u\n"
  436. "\tImage Id not found: %u\n\n",
  437. ixNpeDlImageMgrStats.invalidSignature,
  438. ixNpeDlImageMgrStats.imageIdListOverflow,
  439. ixNpeDlImageMgrStats.imageIdNotFound,
  440. 0,0,0);
  441. }
  442. /*
  443. * Function definition: ixNpeDlImageMgrStatsReset
  444. */
  445. void
  446. ixNpeDlImageMgrStatsReset (void)
  447. {
  448. ixNpeDlImageMgrStats.invalidSignature = 0;
  449. ixNpeDlImageMgrStats.imageIdListOverflow = 0;
  450. ixNpeDlImageMgrStats.imageIdNotFound = 0;
  451. }
  452. #if 0
  453. /*
  454. * Function definition: ixNpeDlImageMgrImageFind_legacy
  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. */
  459. PRIVATE IX_STATUS
  460. ixNpeDlImageMgrImageFind_legacy (
  461. UINT32 *imageLibrary,
  462. UINT32 imageId,
  463. UINT32 **imagePtr,
  464. UINT32 *imageSize)
  465. {
  466. UINT32 imageOffset;
  467. /* used to index image entries in image library header */
  468. UINT32 imageCount = 0;
  469. IX_STATUS status = IX_FAIL;
  470. IxNpeDlImageMgrImageLibraryHeader *header;
  471. BOOL imageFound = false;
  472. IX_NPEDL_TRACE0 (IX_NPEDL_FN_ENTRY_EXIT,
  473. "Entering ixNpeDlImageMgrImageFind\n");
  474. /* If user didn't specify a library to use, use the default
  475. * one from IxNpeMicrocode.h
  476. */
  477. if (imageLibrary == NULL)
  478. {
  479. imageLibrary = IxNpeMicroCodeImageLibrary;
  480. }
  481. if (ixNpeDlImageMgrSignatureCheck (imageLibrary))
  482. {
  483. header = (IxNpeDlImageMgrImageLibraryHeader *) imageLibrary;
  484. /* for each image entry in the image library header ... */
  485. while ((header->entry[imageCount].eohMarker !=
  486. IX_NPEDL_IMAGEMGR_END_OF_HEADER) && !(imageFound))
  487. {
  488. /* if a match for imageId is found in the image library header... */
  489. if (imageId == header->entry[imageCount].image.id)
  490. {
  491. /*
  492. * get pointer to the image in the image library using offset from
  493. * 1st word in image library
  494. */
  495. imageOffset = header->entry[imageCount].image.offset;
  496. *imagePtr = &imageLibrary[imageOffset];
  497. /* get the image size */
  498. *imageSize = header->entry[imageCount].image.size;
  499. status = IX_SUCCESS;
  500. imageFound = true;
  501. }
  502. imageCount++;
  503. }
  504. if (status != IX_SUCCESS)
  505. {
  506. IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
  507. "imageId not found in image library header\n");
  508. ixNpeDlImageMgrStats.imageIdNotFound++;
  509. }
  510. }
  511. else
  512. {
  513. IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
  514. "invalid signature in image library\n");
  515. }
  516. IX_NPEDL_TRACE1 (IX_NPEDL_FN_ENTRY_EXIT,
  517. "Exiting ixNpeDlImageMgrImageFind: status = %d\n", status);
  518. return status;
  519. }
  520. #endif
  521. /*
  522. * Function definition: ixNpeDlImageMgrImageFind
  523. */
  524. IX_STATUS
  525. ixNpeDlImageMgrImageFind (
  526. UINT32 *imageLibrary,
  527. UINT32 imageId,
  528. UINT32 **imagePtr,
  529. UINT32 *imageSize)
  530. {
  531. IxNpeDlImageMgrImageHeader *image;
  532. UINT32 offset = 0;
  533. /* If user didn't specify a library to use, use the default
  534. * one from IxNpeMicrocode.h
  535. */
  536. if (imageLibrary == NULL)
  537. {
  538. #ifdef IX_NPEDL_READ_MICROCODE_FROM_FILE
  539. if (ixNpeMicrocode_binaryArray == NULL)
  540. {
  541. printk (KERN_ERR "ixp400.o: ERROR, no Microcode found in memory\n");
  542. return IX_FAIL;
  543. }
  544. else
  545. {
  546. imageLibrary = ixNpeMicrocode_binaryArray;
  547. }
  548. #else
  549. imageLibrary = getIxNpeMicroCodeImageLibrary();
  550. if (imageLibrary == NULL)
  551. {
  552. printf ("npe: ERROR, no Microcode found in memory\n");
  553. return IX_FAIL;
  554. }
  555. #endif /* IX_NPEDL_READ_MICROCODE_FROM_FILE */
  556. }
  557. #if 0
  558. /* For backward's compatibility with previous image format */
  559. if (ixNpeDlImageMgrSignatureCheck(imageLibrary))
  560. {
  561. return ixNpeDlImageMgrImageFind_legacy(imageLibrary,
  562. imageId,
  563. imagePtr,
  564. imageSize);
  565. }
  566. #endif
  567. while (*(imageLibrary+offset) == NPE_IMAGE_MARKER)
  568. {
  569. image = (IxNpeDlImageMgrImageHeader *)(imageLibrary+offset);
  570. offset += sizeof(IxNpeDlImageMgrImageHeader)/sizeof(UINT32);
  571. if (image->id == imageId)
  572. {
  573. *imagePtr = imageLibrary + offset;
  574. *imageSize = image->size;
  575. return IX_SUCCESS;
  576. }
  577. /* 2 consecutive NPE_IMAGE_MARKER's indicates end of library */
  578. else if (image->id == NPE_IMAGE_MARKER)
  579. {
  580. IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
  581. "imageId not found in image library header\n");
  582. ixNpeDlImageMgrStats.imageIdNotFound++;
  583. /* reached end of library, image not found */
  584. return IX_FAIL;
  585. }
  586. offset += image->size;
  587. }
  588. /* If we get here, our image library may be corrupted */
  589. IX_NPEDL_ERROR_REPORT ("ixNpeDlImageMgrImageFind: "
  590. "image library format may be invalid or corrupted\n");
  591. return IX_FAIL;
  592. }