IxNpeDlImageMgr.c 19 KB

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