IxNpeDlImageMgr.c 19 KB

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