IxNpeDlImageMgr.c 19 KB

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