jffs2_1pass.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862
  1. /*
  2. -------------------------------------------------------------------------
  3. * Filename: jffs2.c
  4. * Version: $Id: jffs2_1pass.c,v 1.7 2002/01/25 01:56:47 nyet Exp $
  5. * Copyright: Copyright (C) 2001, Russ Dill
  6. * Author: Russ Dill <Russ.Dill@asu.edu>
  7. * Description: Module to load kernel from jffs2
  8. *-----------------------------------------------------------------------*/
  9. /*
  10. * some portions of this code are taken from jffs2, and as such, the
  11. * following copyright notice is included.
  12. *
  13. * JFFS2 -- Journalling Flash File System, Version 2.
  14. *
  15. * Copyright (C) 2001 Red Hat, Inc.
  16. *
  17. * Created by David Woodhouse <dwmw2@cambridge.redhat.com>
  18. *
  19. * The original JFFS, from which the design for JFFS2 was derived,
  20. * was designed and implemented by Axis Communications AB.
  21. *
  22. * The contents of this file are subject to the Red Hat eCos Public
  23. * License Version 1.1 (the "Licence"); you may not use this file
  24. * except in compliance with the Licence. You may obtain a copy of
  25. * the Licence at http://www.redhat.com/
  26. *
  27. * Software distributed under the Licence is distributed on an "AS IS"
  28. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
  29. * See the Licence for the specific language governing rights and
  30. * limitations under the Licence.
  31. *
  32. * The Original Code is JFFS2 - Journalling Flash File System, version 2
  33. *
  34. * Alternatively, the contents of this file may be used under the
  35. * terms of the GNU General Public License version 2 (the "GPL"), in
  36. * which case the provisions of the GPL are applicable instead of the
  37. * above. If you wish to allow the use of your version of this file
  38. * only under the terms of the GPL and not to allow others to use your
  39. * version of this file under the RHEPL, indicate your decision by
  40. * deleting the provisions above and replace them with the notice and
  41. * other provisions required by the GPL. If you do not delete the
  42. * provisions above, a recipient may use your version of this file
  43. * under either the RHEPL or the GPL.
  44. *
  45. * $Id: jffs2_1pass.c,v 1.7 2002/01/25 01:56:47 nyet Exp $
  46. *
  47. */
  48. /* Ok, so anyone who knows the jffs2 code will probably want to get a papar
  49. * bag to throw up into before reading this code. I looked through the jffs2
  50. * code, the caching scheme is very elegant. I tried to keep the version
  51. * for a bootloader as small and simple as possible. Instead of worring about
  52. * unneccesary data copies, node scans, etc, I just optimized for the known
  53. * common case, a kernel, which looks like:
  54. * (1) most pages are 4096 bytes
  55. * (2) version numbers are somewhat sorted in acsending order
  56. * (3) multiple compressed blocks making up one page is uncommon
  57. *
  58. * So I create a linked list of decending version numbers (insertions at the
  59. * head), and then for each page, walk down the list, until a matching page
  60. * with 4096 bytes is found, and then decompress the watching pages in
  61. * reverse order.
  62. *
  63. */
  64. /*
  65. * Adapted by Nye Liu <nyet@zumanetworks.com> and
  66. * Rex Feany <rfeany@zumanetworks.com>
  67. * on Jan/2002 for U-Boot.
  68. *
  69. * Clipped out all the non-1pass functions, cleaned up warnings,
  70. * wrappers, etc. No major changes to the code.
  71. * Please, he really means it when he said have a paper bag
  72. * handy. We needed it ;).
  73. *
  74. */
  75. /*
  76. * Bugfixing by Kai-Uwe Bloem <kai-uwe.bloem@auerswald.de>, (C) Mar/2003
  77. *
  78. * - overhaul of the memory management. Removed much of the "paper-bagging"
  79. * in that part of the code, fixed several bugs, now frees memory when
  80. * partition is changed.
  81. * It's still ugly :-(
  82. * - fixed a bug in jffs2_1pass_read_inode where the file length calculation
  83. * was incorrect. Removed a bit of the paper-bagging as well.
  84. * - removed double crc calculation for fragment headers in jffs2_private.h
  85. * for speedup.
  86. * - scan_empty rewritten in a more "standard" manner (non-paperbag, that is).
  87. * - spinning wheel now spins depending on how much memory has been scanned
  88. * - lots of small changes all over the place to "improve" readability.
  89. * - implemented fragment sorting to ensure that the newest data is copied
  90. * if there are multiple copies of fragments for a certain file offset.
  91. *
  92. * The fragment sorting feature must be enabled by CONFIG_SYS_JFFS2_SORT_FRAGMENTS.
  93. * Sorting is done while adding fragments to the lists, which is more or less a
  94. * bubble sort. This takes a lot of time, and is most probably not an issue if
  95. * the boot filesystem is always mounted readonly.
  96. *
  97. * You should define it if the boot filesystem is mounted writable, and updates
  98. * to the boot files are done by copying files to that filesystem.
  99. *
  100. *
  101. * There's a big issue left: endianess is completely ignored in this code. Duh!
  102. *
  103. *
  104. * You still should have paper bags at hand :-(. The code lacks more or less
  105. * any comment, and is still arcane and difficult to read in places. As this
  106. * might be incompatible with any new code from the jffs2 maintainers anyway,
  107. * it should probably be dumped and replaced by something like jffs2reader!
  108. */
  109. #include <common.h>
  110. #include <config.h>
  111. #include <malloc.h>
  112. #include <linux/stat.h>
  113. #include <linux/time.h>
  114. #include <watchdog.h>
  115. #include <jffs2/jffs2.h>
  116. #include <jffs2/jffs2_1pass.h>
  117. #include <linux/mtd/compat.h>
  118. #include <asm/errno.h>
  119. #include "jffs2_private.h"
  120. #define NODE_CHUNK 1024 /* size of memory allocation chunk in b_nodes */
  121. #define SPIN_BLKSIZE 18 /* spin after having scanned 1<<BLKSIZE bytes */
  122. /* Debugging switches */
  123. #undef DEBUG_DIRENTS /* print directory entry list after scan */
  124. #undef DEBUG_FRAGMENTS /* print fragment list after scan */
  125. #undef DEBUG /* enable debugging messages */
  126. #ifdef DEBUG
  127. # define DEBUGF(fmt,args...) printf(fmt ,##args)
  128. #else
  129. # define DEBUGF(fmt,args...)
  130. #endif
  131. #include "summary.h"
  132. /* keeps pointer to currentlu processed partition */
  133. static struct part_info *current_part;
  134. #if (defined(CONFIG_JFFS2_NAND) && \
  135. defined(CONFIG_CMD_NAND) )
  136. #include <nand.h>
  137. /*
  138. * Support for jffs2 on top of NAND-flash
  139. *
  140. * NAND memory isn't mapped in processor's address space,
  141. * so data should be fetched from flash before
  142. * being processed. This is exactly what functions declared
  143. * here do.
  144. *
  145. */
  146. #define NAND_PAGE_SIZE 512
  147. #define NAND_PAGE_SHIFT 9
  148. #define NAND_PAGE_MASK (~(NAND_PAGE_SIZE-1))
  149. #ifndef NAND_CACHE_PAGES
  150. #define NAND_CACHE_PAGES 16
  151. #endif
  152. #define NAND_CACHE_SIZE (NAND_CACHE_PAGES*NAND_PAGE_SIZE)
  153. static u8* nand_cache = NULL;
  154. static u32 nand_cache_off = (u32)-1;
  155. static int read_nand_cached(u32 off, u32 size, u_char *buf)
  156. {
  157. struct mtdids *id = current_part->dev->id;
  158. u32 bytes_read = 0;
  159. size_t retlen;
  160. int cpy_bytes;
  161. while (bytes_read < size) {
  162. if ((off + bytes_read < nand_cache_off) ||
  163. (off + bytes_read >= nand_cache_off+NAND_CACHE_SIZE)) {
  164. nand_cache_off = (off + bytes_read) & NAND_PAGE_MASK;
  165. if (!nand_cache) {
  166. /* This memory never gets freed but 'cause
  167. it's a bootloader, nobody cares */
  168. nand_cache = malloc(NAND_CACHE_SIZE);
  169. if (!nand_cache) {
  170. printf("read_nand_cached: can't alloc cache size %d bytes\n",
  171. NAND_CACHE_SIZE);
  172. return -1;
  173. }
  174. }
  175. retlen = NAND_CACHE_SIZE;
  176. if (nand_read(&nand_info[id->num], nand_cache_off,
  177. &retlen, nand_cache) != 0 ||
  178. retlen != NAND_CACHE_SIZE) {
  179. printf("read_nand_cached: error reading nand off %#x size %d bytes\n",
  180. nand_cache_off, NAND_CACHE_SIZE);
  181. return -1;
  182. }
  183. }
  184. cpy_bytes = nand_cache_off + NAND_CACHE_SIZE - (off + bytes_read);
  185. if (cpy_bytes > size - bytes_read)
  186. cpy_bytes = size - bytes_read;
  187. memcpy(buf + bytes_read,
  188. nand_cache + off + bytes_read - nand_cache_off,
  189. cpy_bytes);
  190. bytes_read += cpy_bytes;
  191. }
  192. return bytes_read;
  193. }
  194. static void *get_fl_mem_nand(u32 off, u32 size, void *ext_buf)
  195. {
  196. u_char *buf = ext_buf ? (u_char*)ext_buf : (u_char*)malloc(size);
  197. if (NULL == buf) {
  198. printf("get_fl_mem_nand: can't alloc %d bytes\n", size);
  199. return NULL;
  200. }
  201. if (read_nand_cached(off, size, buf) < 0) {
  202. if (!ext_buf)
  203. free(buf);
  204. return NULL;
  205. }
  206. return buf;
  207. }
  208. static void *get_node_mem_nand(u32 off, void *ext_buf)
  209. {
  210. struct jffs2_unknown_node node;
  211. void *ret = NULL;
  212. if (NULL == get_fl_mem_nand(off, sizeof(node), &node))
  213. return NULL;
  214. if (!(ret = get_fl_mem_nand(off, node.magic ==
  215. JFFS2_MAGIC_BITMASK ? node.totlen : sizeof(node),
  216. ext_buf))) {
  217. printf("off = %#x magic %#x type %#x node.totlen = %d\n",
  218. off, node.magic, node.nodetype, node.totlen);
  219. }
  220. return ret;
  221. }
  222. static void put_fl_mem_nand(void *buf)
  223. {
  224. free(buf);
  225. }
  226. #endif
  227. #if defined(CONFIG_CMD_ONENAND)
  228. #include <linux/mtd/mtd.h>
  229. #include <linux/mtd/onenand.h>
  230. #include <onenand_uboot.h>
  231. #define ONENAND_PAGE_SIZE 2048
  232. #define ONENAND_PAGE_SHIFT 11
  233. #define ONENAND_PAGE_MASK (~(ONENAND_PAGE_SIZE-1))
  234. #ifndef ONENAND_CACHE_PAGES
  235. #define ONENAND_CACHE_PAGES 4
  236. #endif
  237. #define ONENAND_CACHE_SIZE (ONENAND_CACHE_PAGES*ONENAND_PAGE_SIZE)
  238. static u8* onenand_cache;
  239. static u32 onenand_cache_off = (u32)-1;
  240. static int read_onenand_cached(u32 off, u32 size, u_char *buf)
  241. {
  242. u32 bytes_read = 0;
  243. size_t retlen;
  244. int cpy_bytes;
  245. while (bytes_read < size) {
  246. if ((off + bytes_read < onenand_cache_off) ||
  247. (off + bytes_read >= onenand_cache_off + ONENAND_CACHE_SIZE)) {
  248. onenand_cache_off = (off + bytes_read) & ONENAND_PAGE_MASK;
  249. if (!onenand_cache) {
  250. /* This memory never gets freed but 'cause
  251. it's a bootloader, nobody cares */
  252. onenand_cache = malloc(ONENAND_CACHE_SIZE);
  253. if (!onenand_cache) {
  254. printf("read_onenand_cached: can't alloc cache size %d bytes\n",
  255. ONENAND_CACHE_SIZE);
  256. return -1;
  257. }
  258. }
  259. retlen = ONENAND_CACHE_SIZE;
  260. if (onenand_read(&onenand_mtd, onenand_cache_off, retlen,
  261. &retlen, onenand_cache) != 0 ||
  262. retlen != ONENAND_CACHE_SIZE) {
  263. printf("read_onenand_cached: error reading nand off %#x size %d bytes\n",
  264. onenand_cache_off, ONENAND_CACHE_SIZE);
  265. return -1;
  266. }
  267. }
  268. cpy_bytes = onenand_cache_off + ONENAND_CACHE_SIZE - (off + bytes_read);
  269. if (cpy_bytes > size - bytes_read)
  270. cpy_bytes = size - bytes_read;
  271. memcpy(buf + bytes_read,
  272. onenand_cache + off + bytes_read - onenand_cache_off,
  273. cpy_bytes);
  274. bytes_read += cpy_bytes;
  275. }
  276. return bytes_read;
  277. }
  278. static void *get_fl_mem_onenand(u32 off, u32 size, void *ext_buf)
  279. {
  280. u_char *buf = ext_buf ? (u_char *)ext_buf : (u_char *)malloc(size);
  281. if (NULL == buf) {
  282. printf("get_fl_mem_onenand: can't alloc %d bytes\n", size);
  283. return NULL;
  284. }
  285. if (read_onenand_cached(off, size, buf) < 0) {
  286. if (!ext_buf)
  287. free(buf);
  288. return NULL;
  289. }
  290. return buf;
  291. }
  292. static void *get_node_mem_onenand(u32 off, void *ext_buf)
  293. {
  294. struct jffs2_unknown_node node;
  295. void *ret = NULL;
  296. if (NULL == get_fl_mem_onenand(off, sizeof(node), &node))
  297. return NULL;
  298. ret = get_fl_mem_onenand(off, node.magic ==
  299. JFFS2_MAGIC_BITMASK ? node.totlen : sizeof(node),
  300. ext_buf);
  301. if (!ret) {
  302. printf("off = %#x magic %#x type %#x node.totlen = %d\n",
  303. off, node.magic, node.nodetype, node.totlen);
  304. }
  305. return ret;
  306. }
  307. static void put_fl_mem_onenand(void *buf)
  308. {
  309. free(buf);
  310. }
  311. #endif
  312. #if defined(CONFIG_CMD_FLASH)
  313. /*
  314. * Support for jffs2 on top of NOR-flash
  315. *
  316. * NOR flash memory is mapped in processor's address space,
  317. * just return address.
  318. */
  319. static inline void *get_fl_mem_nor(u32 off, u32 size, void *ext_buf)
  320. {
  321. u32 addr = off;
  322. struct mtdids *id = current_part->dev->id;
  323. extern flash_info_t flash_info[];
  324. flash_info_t *flash = &flash_info[id->num];
  325. addr += flash->start[0];
  326. if (ext_buf) {
  327. memcpy(ext_buf, (void *)addr, size);
  328. return ext_buf;
  329. }
  330. return (void*)addr;
  331. }
  332. static inline void *get_node_mem_nor(u32 off, void *ext_buf)
  333. {
  334. struct jffs2_unknown_node *pNode;
  335. /* pNode will point directly to flash - don't provide external buffer
  336. and don't care about size */
  337. pNode = get_fl_mem_nor(off, 0, NULL);
  338. return (void *)get_fl_mem_nor(off, pNode->magic == JFFS2_MAGIC_BITMASK ?
  339. pNode->totlen : sizeof(*pNode), ext_buf);
  340. }
  341. #endif
  342. /*
  343. * Generic jffs2 raw memory and node read routines.
  344. *
  345. */
  346. static inline void *get_fl_mem(u32 off, u32 size, void *ext_buf)
  347. {
  348. struct mtdids *id = current_part->dev->id;
  349. #if defined(CONFIG_CMD_FLASH)
  350. if (id->type == MTD_DEV_TYPE_NOR) {
  351. return get_fl_mem_nor(off, size, ext_buf);
  352. }
  353. #endif
  354. #if defined(CONFIG_JFFS2_NAND) && defined(CONFIG_CMD_NAND)
  355. if (id->type == MTD_DEV_TYPE_NAND)
  356. return get_fl_mem_nand(off, size, ext_buf);
  357. #endif
  358. #if defined(CONFIG_CMD_ONENAND)
  359. if (id->type == MTD_DEV_TYPE_ONENAND)
  360. return get_fl_mem_onenand(off, size, ext_buf);
  361. #endif
  362. printf("get_fl_mem: unknown device type, using raw offset!\n");
  363. return (void*)off;
  364. }
  365. static inline void *get_node_mem(u32 off, void *ext_buf)
  366. {
  367. struct mtdids *id = current_part->dev->id;
  368. #if defined(CONFIG_CMD_FLASH)
  369. if (id->type == MTD_DEV_TYPE_NOR)
  370. return get_node_mem_nor(off, ext_buf);
  371. #endif
  372. #if defined(CONFIG_JFFS2_NAND) && \
  373. defined(CONFIG_CMD_NAND)
  374. if (id->type == MTD_DEV_TYPE_NAND)
  375. return get_node_mem_nand(off, ext_buf);
  376. #endif
  377. #if defined(CONFIG_CMD_ONENAND)
  378. if (id->type == MTD_DEV_TYPE_ONENAND)
  379. return get_node_mem_onenand(off, ext_buf);
  380. #endif
  381. printf("get_node_mem: unknown device type, using raw offset!\n");
  382. return (void*)off;
  383. }
  384. static inline void put_fl_mem(void *buf, void *ext_buf)
  385. {
  386. struct mtdids *id = current_part->dev->id;
  387. /* If buf is the same as ext_buf, it was provided by the caller -
  388. we shouldn't free it then. */
  389. if (buf == ext_buf)
  390. return;
  391. switch (id->type) {
  392. #if defined(CONFIG_JFFS2_NAND) && defined(CONFIG_CMD_NAND)
  393. case MTD_DEV_TYPE_NAND:
  394. return put_fl_mem_nand(buf);
  395. #endif
  396. #if defined(CONFIG_CMD_ONENAND)
  397. case MTD_DEV_TYPE_ONENAND:
  398. return put_fl_mem_onenand(buf);
  399. #endif
  400. }
  401. }
  402. /* Compression names */
  403. static char *compr_names[] = {
  404. "NONE",
  405. "ZERO",
  406. "RTIME",
  407. "RUBINMIPS",
  408. "COPY",
  409. "DYNRUBIN",
  410. "ZLIB",
  411. #if defined(CONFIG_JFFS2_LZO)
  412. "LZO",
  413. #endif
  414. };
  415. /* Memory management */
  416. struct mem_block {
  417. u32 index;
  418. struct mem_block *next;
  419. struct b_node nodes[NODE_CHUNK];
  420. };
  421. static void
  422. free_nodes(struct b_list *list)
  423. {
  424. while (list->listMemBase != NULL) {
  425. struct mem_block *next = list->listMemBase->next;
  426. free( list->listMemBase );
  427. list->listMemBase = next;
  428. }
  429. }
  430. static struct b_node *
  431. add_node(struct b_list *list)
  432. {
  433. u32 index = 0;
  434. struct mem_block *memBase;
  435. struct b_node *b;
  436. memBase = list->listMemBase;
  437. if (memBase != NULL)
  438. index = memBase->index;
  439. #if 0
  440. putLabeledWord("add_node: index = ", index);
  441. putLabeledWord("add_node: memBase = ", list->listMemBase);
  442. #endif
  443. if (memBase == NULL || index >= NODE_CHUNK) {
  444. /* we need more space before we continue */
  445. memBase = mmalloc(sizeof(struct mem_block));
  446. if (memBase == NULL) {
  447. putstr("add_node: malloc failed\n");
  448. return NULL;
  449. }
  450. memBase->next = list->listMemBase;
  451. index = 0;
  452. #if 0
  453. putLabeledWord("add_node: alloced a new membase at ", *memBase);
  454. #endif
  455. }
  456. /* now we have room to add it. */
  457. b = &memBase->nodes[index];
  458. index ++;
  459. memBase->index = index;
  460. list->listMemBase = memBase;
  461. list->listCount++;
  462. return b;
  463. }
  464. static struct b_node *
  465. insert_node(struct b_list *list, u32 offset)
  466. {
  467. struct b_node *new;
  468. #ifdef CONFIG_SYS_JFFS2_SORT_FRAGMENTS
  469. struct b_node *b, *prev;
  470. #endif
  471. if (!(new = add_node(list))) {
  472. putstr("add_node failed!\r\n");
  473. return NULL;
  474. }
  475. new->offset = offset;
  476. #ifdef CONFIG_SYS_JFFS2_SORT_FRAGMENTS
  477. if (list->listTail != NULL && list->listCompare(new, list->listTail))
  478. prev = list->listTail;
  479. else if (list->listLast != NULL && list->listCompare(new, list->listLast))
  480. prev = list->listLast;
  481. else
  482. prev = NULL;
  483. for (b = (prev ? prev->next : list->listHead);
  484. b != NULL && list->listCompare(new, b);
  485. prev = b, b = b->next) {
  486. list->listLoops++;
  487. }
  488. if (b != NULL)
  489. list->listLast = prev;
  490. if (b != NULL) {
  491. new->next = b;
  492. if (prev != NULL)
  493. prev->next = new;
  494. else
  495. list->listHead = new;
  496. } else
  497. #endif
  498. {
  499. new->next = (struct b_node *) NULL;
  500. if (list->listTail != NULL) {
  501. list->listTail->next = new;
  502. list->listTail = new;
  503. } else {
  504. list->listTail = list->listHead = new;
  505. }
  506. }
  507. return new;
  508. }
  509. #ifdef CONFIG_SYS_JFFS2_SORT_FRAGMENTS
  510. /* Sort data entries with the latest version last, so that if there
  511. * is overlapping data the latest version will be used.
  512. */
  513. static int compare_inodes(struct b_node *new, struct b_node *old)
  514. {
  515. struct jffs2_raw_inode ojNew;
  516. struct jffs2_raw_inode ojOld;
  517. struct jffs2_raw_inode *jNew =
  518. (struct jffs2_raw_inode *)get_fl_mem(new->offset, sizeof(ojNew), &ojNew);
  519. struct jffs2_raw_inode *jOld =
  520. (struct jffs2_raw_inode *)get_fl_mem(old->offset, sizeof(ojOld), &ojOld);
  521. return jNew->version > jOld->version;
  522. }
  523. /* Sort directory entries so all entries in the same directory
  524. * with the same name are grouped together, with the latest version
  525. * last. This makes it easy to eliminate all but the latest version
  526. * by marking the previous version dead by setting the inode to 0.
  527. */
  528. static int compare_dirents(struct b_node *new, struct b_node *old)
  529. {
  530. struct jffs2_raw_dirent ojNew;
  531. struct jffs2_raw_dirent ojOld;
  532. struct jffs2_raw_dirent *jNew =
  533. (struct jffs2_raw_dirent *)get_fl_mem(new->offset, sizeof(ojNew), &ojNew);
  534. struct jffs2_raw_dirent *jOld =
  535. (struct jffs2_raw_dirent *)get_fl_mem(old->offset, sizeof(ojOld), &ojOld);
  536. int cmp;
  537. /* ascending sort by pino */
  538. if (jNew->pino != jOld->pino)
  539. return jNew->pino > jOld->pino;
  540. /* pino is the same, so use ascending sort by nsize, so
  541. * we don't do strncmp unless we really must.
  542. */
  543. if (jNew->nsize != jOld->nsize)
  544. return jNew->nsize > jOld->nsize;
  545. /* length is also the same, so use ascending sort by name
  546. */
  547. cmp = strncmp((char *)jNew->name, (char *)jOld->name, jNew->nsize);
  548. if (cmp != 0)
  549. return cmp > 0;
  550. /* we have duplicate names in this directory, so use ascending
  551. * sort by version
  552. */
  553. if (jNew->version > jOld->version) {
  554. /* since jNew is newer, we know jOld is not valid, so
  555. * mark it with inode 0 and it will not be used
  556. */
  557. jOld->ino = 0;
  558. return 1;
  559. }
  560. return 0;
  561. }
  562. #endif
  563. void
  564. jffs2_free_cache(struct part_info *part)
  565. {
  566. struct b_lists *pL;
  567. if (part->jffs2_priv != NULL) {
  568. pL = (struct b_lists *)part->jffs2_priv;
  569. free_nodes(&pL->frag);
  570. free_nodes(&pL->dir);
  571. free(pL->readbuf);
  572. free(pL);
  573. }
  574. }
  575. static u32
  576. jffs_init_1pass_list(struct part_info *part)
  577. {
  578. struct b_lists *pL;
  579. jffs2_free_cache(part);
  580. if (NULL != (part->jffs2_priv = malloc(sizeof(struct b_lists)))) {
  581. pL = (struct b_lists *)part->jffs2_priv;
  582. memset(pL, 0, sizeof(*pL));
  583. #ifdef CONFIG_SYS_JFFS2_SORT_FRAGMENTS
  584. pL->dir.listCompare = compare_dirents;
  585. pL->frag.listCompare = compare_inodes;
  586. #endif
  587. }
  588. return 0;
  589. }
  590. /* find the inode from the slashless name given a parent */
  591. static long
  592. jffs2_1pass_read_inode(struct b_lists *pL, u32 inode, char *dest)
  593. {
  594. struct b_node *b;
  595. struct jffs2_raw_inode *jNode;
  596. u32 totalSize = 0;
  597. u32 latestVersion = 0;
  598. uchar *lDest;
  599. uchar *src;
  600. long ret;
  601. int i;
  602. u32 counter = 0;
  603. #ifdef CONFIG_SYS_JFFS2_SORT_FRAGMENTS
  604. /* Find file size before loading any data, so fragments that
  605. * start past the end of file can be ignored. A fragment
  606. * that is partially in the file is loaded, so extra data may
  607. * be loaded up to the next 4K boundary above the file size.
  608. * This shouldn't cause trouble when loading kernel images, so
  609. * we will live with it.
  610. */
  611. for (b = pL->frag.listHead; b != NULL; b = b->next) {
  612. jNode = (struct jffs2_raw_inode *) get_fl_mem(b->offset,
  613. sizeof(struct jffs2_raw_inode), pL->readbuf);
  614. if ((inode == jNode->ino)) {
  615. /* get actual file length from the newest node */
  616. if (jNode->version >= latestVersion) {
  617. totalSize = jNode->isize;
  618. latestVersion = jNode->version;
  619. }
  620. }
  621. put_fl_mem(jNode, pL->readbuf);
  622. }
  623. #endif
  624. for (b = pL->frag.listHead; b != NULL; b = b->next) {
  625. jNode = (struct jffs2_raw_inode *) get_node_mem(b->offset,
  626. pL->readbuf);
  627. if ((inode == jNode->ino)) {
  628. #if 0
  629. putLabeledWord("\r\n\r\nread_inode: totlen = ", jNode->totlen);
  630. putLabeledWord("read_inode: inode = ", jNode->ino);
  631. putLabeledWord("read_inode: version = ", jNode->version);
  632. putLabeledWord("read_inode: isize = ", jNode->isize);
  633. putLabeledWord("read_inode: offset = ", jNode->offset);
  634. putLabeledWord("read_inode: csize = ", jNode->csize);
  635. putLabeledWord("read_inode: dsize = ", jNode->dsize);
  636. putLabeledWord("read_inode: compr = ", jNode->compr);
  637. putLabeledWord("read_inode: usercompr = ", jNode->usercompr);
  638. putLabeledWord("read_inode: flags = ", jNode->flags);
  639. #endif
  640. #ifndef CONFIG_SYS_JFFS2_SORT_FRAGMENTS
  641. /* get actual file length from the newest node */
  642. if (jNode->version >= latestVersion) {
  643. totalSize = jNode->isize;
  644. latestVersion = jNode->version;
  645. }
  646. #endif
  647. if(dest) {
  648. src = ((uchar *) jNode) + sizeof(struct jffs2_raw_inode);
  649. /* ignore data behind latest known EOF */
  650. if (jNode->offset > totalSize) {
  651. put_fl_mem(jNode, pL->readbuf);
  652. continue;
  653. }
  654. if (b->datacrc == CRC_UNKNOWN)
  655. b->datacrc = data_crc(jNode) ?
  656. CRC_OK : CRC_BAD;
  657. if (b->datacrc == CRC_BAD) {
  658. put_fl_mem(jNode, pL->readbuf);
  659. continue;
  660. }
  661. lDest = (uchar *) (dest + jNode->offset);
  662. #if 0
  663. putLabeledWord("read_inode: src = ", src);
  664. putLabeledWord("read_inode: dest = ", lDest);
  665. #endif
  666. switch (jNode->compr) {
  667. case JFFS2_COMPR_NONE:
  668. ret = (unsigned long) ldr_memcpy(lDest, src, jNode->dsize);
  669. break;
  670. case JFFS2_COMPR_ZERO:
  671. ret = 0;
  672. for (i = 0; i < jNode->dsize; i++)
  673. *(lDest++) = 0;
  674. break;
  675. case JFFS2_COMPR_RTIME:
  676. ret = 0;
  677. rtime_decompress(src, lDest, jNode->csize, jNode->dsize);
  678. break;
  679. case JFFS2_COMPR_DYNRUBIN:
  680. /* this is slow but it works */
  681. ret = 0;
  682. dynrubin_decompress(src, lDest, jNode->csize, jNode->dsize);
  683. break;
  684. case JFFS2_COMPR_ZLIB:
  685. ret = zlib_decompress(src, lDest, jNode->csize, jNode->dsize);
  686. break;
  687. #if defined(CONFIG_JFFS2_LZO)
  688. case JFFS2_COMPR_LZO:
  689. ret = lzo_decompress(src, lDest, jNode->csize, jNode->dsize);
  690. break;
  691. #endif
  692. default:
  693. /* unknown */
  694. putLabeledWord("UNKOWN COMPRESSION METHOD = ", jNode->compr);
  695. put_fl_mem(jNode, pL->readbuf);
  696. return -1;
  697. break;
  698. }
  699. }
  700. #if 0
  701. putLabeledWord("read_inode: totalSize = ", totalSize);
  702. putLabeledWord("read_inode: compr ret = ", ret);
  703. #endif
  704. }
  705. counter++;
  706. put_fl_mem(jNode, pL->readbuf);
  707. }
  708. #if 0
  709. putLabeledWord("read_inode: returning = ", totalSize);
  710. #endif
  711. return totalSize;
  712. }
  713. /* find the inode from the slashless name given a parent */
  714. static u32
  715. jffs2_1pass_find_inode(struct b_lists * pL, const char *name, u32 pino)
  716. {
  717. struct b_node *b;
  718. struct jffs2_raw_dirent *jDir;
  719. int len;
  720. u32 counter;
  721. u32 version = 0;
  722. u32 inode = 0;
  723. /* name is assumed slash free */
  724. len = strlen(name);
  725. counter = 0;
  726. /* we need to search all and return the inode with the highest version */
  727. for(b = pL->dir.listHead; b; b = b->next, counter++) {
  728. jDir = (struct jffs2_raw_dirent *) get_node_mem(b->offset,
  729. pL->readbuf);
  730. if ((pino == jDir->pino) && (len == jDir->nsize) &&
  731. (jDir->ino) && /* 0 for unlink */
  732. (!strncmp((char *)jDir->name, name, len))) { /* a match */
  733. if (jDir->version < version) {
  734. put_fl_mem(jDir, pL->readbuf);
  735. continue;
  736. }
  737. if (jDir->version == version && inode != 0) {
  738. /* I'm pretty sure this isn't legal */
  739. putstr(" ** ERROR ** ");
  740. putnstr(jDir->name, jDir->nsize);
  741. putLabeledWord(" has dup version =", version);
  742. }
  743. inode = jDir->ino;
  744. version = jDir->version;
  745. }
  746. #if 0
  747. putstr("\r\nfind_inode:p&l ->");
  748. putnstr(jDir->name, jDir->nsize);
  749. putstr("\r\n");
  750. putLabeledWord("pino = ", jDir->pino);
  751. putLabeledWord("nsize = ", jDir->nsize);
  752. putLabeledWord("b = ", (u32) b);
  753. putLabeledWord("counter = ", counter);
  754. #endif
  755. put_fl_mem(jDir, pL->readbuf);
  756. }
  757. return inode;
  758. }
  759. char *mkmodestr(unsigned long mode, char *str)
  760. {
  761. static const char *l = "xwr";
  762. int mask = 1, i;
  763. char c;
  764. switch (mode & S_IFMT) {
  765. case S_IFDIR: str[0] = 'd'; break;
  766. case S_IFBLK: str[0] = 'b'; break;
  767. case S_IFCHR: str[0] = 'c'; break;
  768. case S_IFIFO: str[0] = 'f'; break;
  769. case S_IFLNK: str[0] = 'l'; break;
  770. case S_IFSOCK: str[0] = 's'; break;
  771. case S_IFREG: str[0] = '-'; break;
  772. default: str[0] = '?';
  773. }
  774. for(i = 0; i < 9; i++) {
  775. c = l[i%3];
  776. str[9-i] = (mode & mask)?c:'-';
  777. mask = mask<<1;
  778. }
  779. if(mode & S_ISUID) str[3] = (mode & S_IXUSR)?'s':'S';
  780. if(mode & S_ISGID) str[6] = (mode & S_IXGRP)?'s':'S';
  781. if(mode & S_ISVTX) str[9] = (mode & S_IXOTH)?'t':'T';
  782. str[10] = '\0';
  783. return str;
  784. }
  785. static inline void dump_stat(struct stat *st, const char *name)
  786. {
  787. char str[20];
  788. char s[64], *p;
  789. if (st->st_mtime == (time_t)(-1)) /* some ctimes really hate -1 */
  790. st->st_mtime = 1;
  791. ctime_r((time_t *)&st->st_mtime, s/*,64*/); /* newlib ctime doesn't have buflen */
  792. if ((p = strchr(s,'\n')) != NULL) *p = '\0';
  793. if ((p = strchr(s,'\r')) != NULL) *p = '\0';
  794. /*
  795. printf("%6lo %s %8ld %s %s\n", st->st_mode, mkmodestr(st->st_mode, str),
  796. st->st_size, s, name);
  797. */
  798. printf(" %s %8ld %s %s", mkmodestr(st->st_mode,str), st->st_size, s, name);
  799. }
  800. static inline u32 dump_inode(struct b_lists * pL, struct jffs2_raw_dirent *d, struct jffs2_raw_inode *i)
  801. {
  802. char fname[256];
  803. struct stat st;
  804. if(!d || !i) return -1;
  805. strncpy(fname, (char *)d->name, d->nsize);
  806. fname[d->nsize] = '\0';
  807. memset(&st,0,sizeof(st));
  808. st.st_mtime = i->mtime;
  809. st.st_mode = i->mode;
  810. st.st_ino = i->ino;
  811. st.st_size = i->isize;
  812. dump_stat(&st, fname);
  813. if (d->type == DT_LNK) {
  814. unsigned char *src = (unsigned char *) (&i[1]);
  815. putstr(" -> ");
  816. putnstr(src, (int)i->dsize);
  817. }
  818. putstr("\r\n");
  819. return 0;
  820. }
  821. /* list inodes with the given pino */
  822. static u32
  823. jffs2_1pass_list_inodes(struct b_lists * pL, u32 pino)
  824. {
  825. struct b_node *b;
  826. struct jffs2_raw_dirent *jDir;
  827. for (b = pL->dir.listHead; b; b = b->next) {
  828. jDir = (struct jffs2_raw_dirent *) get_node_mem(b->offset,
  829. pL->readbuf);
  830. if ((pino == jDir->pino) && (jDir->ino)) { /* ino=0 -> unlink */
  831. u32 i_version = 0;
  832. struct jffs2_raw_inode ojNode;
  833. struct jffs2_raw_inode *jNode, *i = NULL;
  834. struct b_node *b2 = pL->frag.listHead;
  835. while (b2) {
  836. jNode = (struct jffs2_raw_inode *)
  837. get_fl_mem(b2->offset, sizeof(ojNode), &ojNode);
  838. if (jNode->ino == jDir->ino && jNode->version >= i_version) {
  839. i_version = jNode->version;
  840. if (i)
  841. put_fl_mem(i, NULL);
  842. if (jDir->type == DT_LNK)
  843. i = get_node_mem(b2->offset,
  844. NULL);
  845. else
  846. i = get_fl_mem(b2->offset,
  847. sizeof(*i),
  848. NULL);
  849. }
  850. b2 = b2->next;
  851. }
  852. dump_inode(pL, jDir, i);
  853. put_fl_mem(i, NULL);
  854. }
  855. put_fl_mem(jDir, pL->readbuf);
  856. }
  857. return pino;
  858. }
  859. static u32
  860. jffs2_1pass_search_inode(struct b_lists * pL, const char *fname, u32 pino)
  861. {
  862. int i;
  863. char tmp[256];
  864. char working_tmp[256];
  865. char *c;
  866. /* discard any leading slash */
  867. i = 0;
  868. while (fname[i] == '/')
  869. i++;
  870. strcpy(tmp, &fname[i]);
  871. while ((c = (char *) strchr(tmp, '/'))) /* we are still dired searching */
  872. {
  873. strncpy(working_tmp, tmp, c - tmp);
  874. working_tmp[c - tmp] = '\0';
  875. #if 0
  876. putstr("search_inode: tmp = ");
  877. putstr(tmp);
  878. putstr("\r\n");
  879. putstr("search_inode: wtmp = ");
  880. putstr(working_tmp);
  881. putstr("\r\n");
  882. putstr("search_inode: c = ");
  883. putstr(c);
  884. putstr("\r\n");
  885. #endif
  886. for (i = 0; i < strlen(c) - 1; i++)
  887. tmp[i] = c[i + 1];
  888. tmp[i] = '\0';
  889. #if 0
  890. putstr("search_inode: post tmp = ");
  891. putstr(tmp);
  892. putstr("\r\n");
  893. #endif
  894. if (!(pino = jffs2_1pass_find_inode(pL, working_tmp, pino))) {
  895. putstr("find_inode failed for name=");
  896. putstr(working_tmp);
  897. putstr("\r\n");
  898. return 0;
  899. }
  900. }
  901. /* this is for the bare filename, directories have already been mapped */
  902. if (!(pino = jffs2_1pass_find_inode(pL, tmp, pino))) {
  903. putstr("find_inode failed for name=");
  904. putstr(tmp);
  905. putstr("\r\n");
  906. return 0;
  907. }
  908. return pino;
  909. }
  910. static u32
  911. jffs2_1pass_resolve_inode(struct b_lists * pL, u32 ino)
  912. {
  913. struct b_node *b;
  914. struct b_node *b2;
  915. struct jffs2_raw_dirent *jDir;
  916. struct jffs2_raw_inode *jNode;
  917. u8 jDirFoundType = 0;
  918. u32 jDirFoundIno = 0;
  919. u32 jDirFoundPino = 0;
  920. char tmp[256];
  921. u32 version = 0;
  922. u32 pino;
  923. unsigned char *src;
  924. /* we need to search all and return the inode with the highest version */
  925. for(b = pL->dir.listHead; b; b = b->next) {
  926. jDir = (struct jffs2_raw_dirent *) get_node_mem(b->offset,
  927. pL->readbuf);
  928. if (ino == jDir->ino) {
  929. if (jDir->version < version) {
  930. put_fl_mem(jDir, pL->readbuf);
  931. continue;
  932. }
  933. if (jDir->version == version && jDirFoundType) {
  934. /* I'm pretty sure this isn't legal */
  935. putstr(" ** ERROR ** ");
  936. putnstr(jDir->name, jDir->nsize);
  937. putLabeledWord(" has dup version (resolve) = ",
  938. version);
  939. }
  940. jDirFoundType = jDir->type;
  941. jDirFoundIno = jDir->ino;
  942. jDirFoundPino = jDir->pino;
  943. version = jDir->version;
  944. }
  945. put_fl_mem(jDir, pL->readbuf);
  946. }
  947. /* now we found the right entry again. (shoulda returned inode*) */
  948. if (jDirFoundType != DT_LNK)
  949. return jDirFoundIno;
  950. /* it's a soft link so we follow it again. */
  951. b2 = pL->frag.listHead;
  952. while (b2) {
  953. jNode = (struct jffs2_raw_inode *) get_node_mem(b2->offset,
  954. pL->readbuf);
  955. if (jNode->ino == jDirFoundIno) {
  956. src = (unsigned char *)jNode + sizeof(struct jffs2_raw_inode);
  957. #if 0
  958. putLabeledWord("\t\t dsize = ", jNode->dsize);
  959. putstr("\t\t target = ");
  960. putnstr(src, jNode->dsize);
  961. putstr("\r\n");
  962. #endif
  963. strncpy(tmp, (char *)src, jNode->dsize);
  964. tmp[jNode->dsize] = '\0';
  965. put_fl_mem(jNode, pL->readbuf);
  966. break;
  967. }
  968. b2 = b2->next;
  969. put_fl_mem(jNode, pL->readbuf);
  970. }
  971. /* ok so the name of the new file to find is in tmp */
  972. /* if it starts with a slash it is root based else shared dirs */
  973. if (tmp[0] == '/')
  974. pino = 1;
  975. else
  976. pino = jDirFoundPino;
  977. return jffs2_1pass_search_inode(pL, tmp, pino);
  978. }
  979. static u32
  980. jffs2_1pass_search_list_inodes(struct b_lists * pL, const char *fname, u32 pino)
  981. {
  982. int i;
  983. char tmp[256];
  984. char working_tmp[256];
  985. char *c;
  986. /* discard any leading slash */
  987. i = 0;
  988. while (fname[i] == '/')
  989. i++;
  990. strcpy(tmp, &fname[i]);
  991. working_tmp[0] = '\0';
  992. while ((c = (char *) strchr(tmp, '/'))) /* we are still dired searching */
  993. {
  994. strncpy(working_tmp, tmp, c - tmp);
  995. working_tmp[c - tmp] = '\0';
  996. for (i = 0; i < strlen(c) - 1; i++)
  997. tmp[i] = c[i + 1];
  998. tmp[i] = '\0';
  999. /* only a failure if we arent looking at top level */
  1000. if (!(pino = jffs2_1pass_find_inode(pL, working_tmp, pino)) &&
  1001. (working_tmp[0])) {
  1002. putstr("find_inode failed for name=");
  1003. putstr(working_tmp);
  1004. putstr("\r\n");
  1005. return 0;
  1006. }
  1007. }
  1008. if (tmp[0] && !(pino = jffs2_1pass_find_inode(pL, tmp, pino))) {
  1009. putstr("find_inode failed for name=");
  1010. putstr(tmp);
  1011. putstr("\r\n");
  1012. return 0;
  1013. }
  1014. /* this is for the bare filename, directories have already been mapped */
  1015. if (!(pino = jffs2_1pass_list_inodes(pL, pino))) {
  1016. putstr("find_inode failed for name=");
  1017. putstr(tmp);
  1018. putstr("\r\n");
  1019. return 0;
  1020. }
  1021. return pino;
  1022. }
  1023. unsigned char
  1024. jffs2_1pass_rescan_needed(struct part_info *part)
  1025. {
  1026. struct b_node *b;
  1027. struct jffs2_unknown_node onode;
  1028. struct jffs2_unknown_node *node;
  1029. struct b_lists *pL = (struct b_lists *)part->jffs2_priv;
  1030. if (part->jffs2_priv == 0){
  1031. DEBUGF ("rescan: First time in use\n");
  1032. return 1;
  1033. }
  1034. /* if we have no list, we need to rescan */
  1035. if (pL->frag.listCount == 0) {
  1036. DEBUGF ("rescan: fraglist zero\n");
  1037. return 1;
  1038. }
  1039. /* but suppose someone reflashed a partition at the same offset... */
  1040. b = pL->dir.listHead;
  1041. while (b) {
  1042. node = (struct jffs2_unknown_node *) get_fl_mem(b->offset,
  1043. sizeof(onode), &onode);
  1044. if (node->nodetype != JFFS2_NODETYPE_DIRENT) {
  1045. DEBUGF ("rescan: fs changed beneath me? (%lx)\n",
  1046. (unsigned long) b->offset);
  1047. return 1;
  1048. }
  1049. b = b->next;
  1050. }
  1051. return 0;
  1052. }
  1053. #ifdef CONFIG_JFFS2_SUMMARY
  1054. static u32 sum_get_unaligned32(u32 *ptr)
  1055. {
  1056. u32 val;
  1057. u8 *p = (u8 *)ptr;
  1058. val = *p | (*(p + 1) << 8) | (*(p + 2) << 16) | (*(p + 3) << 24);
  1059. return __le32_to_cpu(val);
  1060. }
  1061. static u16 sum_get_unaligned16(u16 *ptr)
  1062. {
  1063. u16 val;
  1064. u8 *p = (u8 *)ptr;
  1065. val = *p | (*(p + 1) << 8);
  1066. return __le16_to_cpu(val);
  1067. }
  1068. #define dbg_summary(...) do {} while (0);
  1069. /*
  1070. * Process the stored summary information - helper function for
  1071. * jffs2_sum_scan_sumnode()
  1072. */
  1073. static int jffs2_sum_process_sum_data(struct part_info *part, uint32_t offset,
  1074. struct jffs2_raw_summary *summary,
  1075. struct b_lists *pL)
  1076. {
  1077. void *sp;
  1078. int i, pass;
  1079. void *ret;
  1080. for (pass = 0; pass < 2; pass++) {
  1081. sp = summary->sum;
  1082. for (i = 0; i < summary->sum_num; i++) {
  1083. struct jffs2_sum_unknown_flash *spu = sp;
  1084. dbg_summary("processing summary index %d\n", i);
  1085. switch (sum_get_unaligned16(&spu->nodetype)) {
  1086. case JFFS2_NODETYPE_INODE: {
  1087. struct jffs2_sum_inode_flash *spi;
  1088. if (pass) {
  1089. spi = sp;
  1090. ret = insert_node(&pL->frag,
  1091. (u32)part->offset +
  1092. offset +
  1093. sum_get_unaligned32(
  1094. &spi->offset));
  1095. if (ret == NULL)
  1096. return -1;
  1097. }
  1098. sp += JFFS2_SUMMARY_INODE_SIZE;
  1099. break;
  1100. }
  1101. case JFFS2_NODETYPE_DIRENT: {
  1102. struct jffs2_sum_dirent_flash *spd;
  1103. spd = sp;
  1104. if (pass) {
  1105. ret = insert_node(&pL->dir,
  1106. (u32) part->offset +
  1107. offset +
  1108. sum_get_unaligned32(
  1109. &spd->offset));
  1110. if (ret == NULL)
  1111. return -1;
  1112. }
  1113. sp += JFFS2_SUMMARY_DIRENT_SIZE(
  1114. spd->nsize);
  1115. break;
  1116. }
  1117. default : {
  1118. uint16_t nodetype = sum_get_unaligned16(
  1119. &spu->nodetype);
  1120. printf("Unsupported node type %x found"
  1121. " in summary!\n",
  1122. nodetype);
  1123. if ((nodetype & JFFS2_COMPAT_MASK) ==
  1124. JFFS2_FEATURE_INCOMPAT)
  1125. return -EIO;
  1126. return -EBADMSG;
  1127. }
  1128. }
  1129. }
  1130. }
  1131. return 0;
  1132. }
  1133. /* Process the summary node - called from jffs2_scan_eraseblock() */
  1134. int jffs2_sum_scan_sumnode(struct part_info *part, uint32_t offset,
  1135. struct jffs2_raw_summary *summary, uint32_t sumsize,
  1136. struct b_lists *pL)
  1137. {
  1138. struct jffs2_unknown_node crcnode;
  1139. int ret, ofs;
  1140. uint32_t crc;
  1141. ofs = part->sector_size - sumsize;
  1142. dbg_summary("summary found for 0x%08x at 0x%08x (0x%x bytes)\n",
  1143. offset, offset + ofs, sumsize);
  1144. /* OK, now check for node validity and CRC */
  1145. crcnode.magic = JFFS2_MAGIC_BITMASK;
  1146. crcnode.nodetype = JFFS2_NODETYPE_SUMMARY;
  1147. crcnode.totlen = summary->totlen;
  1148. crc = crc32_no_comp(0, (uchar *)&crcnode, sizeof(crcnode)-4);
  1149. if (summary->hdr_crc != crc) {
  1150. dbg_summary("Summary node header is corrupt (bad CRC or "
  1151. "no summary at all)\n");
  1152. goto crc_err;
  1153. }
  1154. if (summary->totlen != sumsize) {
  1155. dbg_summary("Summary node is corrupt (wrong erasesize?)\n");
  1156. goto crc_err;
  1157. }
  1158. crc = crc32_no_comp(0, (uchar *)summary,
  1159. sizeof(struct jffs2_raw_summary)-8);
  1160. if (summary->node_crc != crc) {
  1161. dbg_summary("Summary node is corrupt (bad CRC)\n");
  1162. goto crc_err;
  1163. }
  1164. crc = crc32_no_comp(0, (uchar *)summary->sum,
  1165. sumsize - sizeof(struct jffs2_raw_summary));
  1166. if (summary->sum_crc != crc) {
  1167. dbg_summary("Summary node data is corrupt (bad CRC)\n");
  1168. goto crc_err;
  1169. }
  1170. if (summary->cln_mkr)
  1171. dbg_summary("Summary : CLEANMARKER node \n");
  1172. ret = jffs2_sum_process_sum_data(part, offset, summary, pL);
  1173. if (ret == -EBADMSG)
  1174. return 0;
  1175. if (ret)
  1176. return ret; /* real error */
  1177. return 1;
  1178. crc_err:
  1179. putstr("Summary node crc error, skipping summary information.\n");
  1180. return 0;
  1181. }
  1182. #endif /* CONFIG_JFFS2_SUMMARY */
  1183. #ifdef DEBUG_FRAGMENTS
  1184. static void
  1185. dump_fragments(struct b_lists *pL)
  1186. {
  1187. struct b_node *b;
  1188. struct jffs2_raw_inode ojNode;
  1189. struct jffs2_raw_inode *jNode;
  1190. putstr("\r\n\r\n******The fragment Entries******\r\n");
  1191. b = pL->frag.listHead;
  1192. while (b) {
  1193. jNode = (struct jffs2_raw_inode *) get_fl_mem(b->offset,
  1194. sizeof(ojNode), &ojNode);
  1195. putLabeledWord("\r\n\tbuild_list: FLASH_OFFSET = ", b->offset);
  1196. putLabeledWord("\tbuild_list: totlen = ", jNode->totlen);
  1197. putLabeledWord("\tbuild_list: inode = ", jNode->ino);
  1198. putLabeledWord("\tbuild_list: version = ", jNode->version);
  1199. putLabeledWord("\tbuild_list: isize = ", jNode->isize);
  1200. putLabeledWord("\tbuild_list: atime = ", jNode->atime);
  1201. putLabeledWord("\tbuild_list: offset = ", jNode->offset);
  1202. putLabeledWord("\tbuild_list: csize = ", jNode->csize);
  1203. putLabeledWord("\tbuild_list: dsize = ", jNode->dsize);
  1204. putLabeledWord("\tbuild_list: compr = ", jNode->compr);
  1205. putLabeledWord("\tbuild_list: usercompr = ", jNode->usercompr);
  1206. putLabeledWord("\tbuild_list: flags = ", jNode->flags);
  1207. putLabeledWord("\tbuild_list: offset = ", b->offset); /* FIXME: ? [RS] */
  1208. b = b->next;
  1209. }
  1210. }
  1211. #endif
  1212. #ifdef DEBUG_DIRENTS
  1213. static void
  1214. dump_dirents(struct b_lists *pL)
  1215. {
  1216. struct b_node *b;
  1217. struct jffs2_raw_dirent *jDir;
  1218. putstr("\r\n\r\n******The directory Entries******\r\n");
  1219. b = pL->dir.listHead;
  1220. while (b) {
  1221. jDir = (struct jffs2_raw_dirent *) get_node_mem(b->offset,
  1222. pL->readbuf);
  1223. putstr("\r\n");
  1224. putnstr(jDir->name, jDir->nsize);
  1225. putLabeledWord("\r\n\tbuild_list: magic = ", jDir->magic);
  1226. putLabeledWord("\tbuild_list: nodetype = ", jDir->nodetype);
  1227. putLabeledWord("\tbuild_list: hdr_crc = ", jDir->hdr_crc);
  1228. putLabeledWord("\tbuild_list: pino = ", jDir->pino);
  1229. putLabeledWord("\tbuild_list: version = ", jDir->version);
  1230. putLabeledWord("\tbuild_list: ino = ", jDir->ino);
  1231. putLabeledWord("\tbuild_list: mctime = ", jDir->mctime);
  1232. putLabeledWord("\tbuild_list: nsize = ", jDir->nsize);
  1233. putLabeledWord("\tbuild_list: type = ", jDir->type);
  1234. putLabeledWord("\tbuild_list: node_crc = ", jDir->node_crc);
  1235. putLabeledWord("\tbuild_list: name_crc = ", jDir->name_crc);
  1236. putLabeledWord("\tbuild_list: offset = ", b->offset); /* FIXME: ? [RS] */
  1237. b = b->next;
  1238. put_fl_mem(jDir, pL->readbuf);
  1239. }
  1240. }
  1241. #endif
  1242. #define DEFAULT_EMPTY_SCAN_SIZE 4096
  1243. static inline uint32_t EMPTY_SCAN_SIZE(uint32_t sector_size)
  1244. {
  1245. if (sector_size < DEFAULT_EMPTY_SCAN_SIZE)
  1246. return sector_size;
  1247. else
  1248. return DEFAULT_EMPTY_SCAN_SIZE;
  1249. }
  1250. static u32
  1251. jffs2_1pass_build_lists(struct part_info * part)
  1252. {
  1253. struct b_lists *pL;
  1254. struct jffs2_unknown_node *node;
  1255. u32 nr_sectors = part->size/part->sector_size;
  1256. u32 i;
  1257. u32 counter4 = 0;
  1258. u32 counterF = 0;
  1259. u32 counterN = 0;
  1260. u32 max_totlen = 0;
  1261. u32 buf_size = DEFAULT_EMPTY_SCAN_SIZE;
  1262. char *buf;
  1263. /* turn off the lcd. Refreshing the lcd adds 50% overhead to the */
  1264. /* jffs2 list building enterprise nope. in newer versions the overhead is */
  1265. /* only about 5 %. not enough to inconvenience people for. */
  1266. /* lcd_off(); */
  1267. /* if we are building a list we need to refresh the cache. */
  1268. jffs_init_1pass_list(part);
  1269. pL = (struct b_lists *)part->jffs2_priv;
  1270. buf = malloc(buf_size);
  1271. puts ("Scanning JFFS2 FS: ");
  1272. /* start at the beginning of the partition */
  1273. for (i = 0; i < nr_sectors; i++) {
  1274. uint32_t sector_ofs = i * part->sector_size;
  1275. uint32_t buf_ofs = sector_ofs;
  1276. uint32_t buf_len;
  1277. uint32_t ofs, prevofs;
  1278. #ifdef CONFIG_JFFS2_SUMMARY
  1279. struct jffs2_sum_marker *sm;
  1280. void *sumptr = NULL;
  1281. uint32_t sumlen;
  1282. int ret;
  1283. #endif
  1284. WATCHDOG_RESET();
  1285. #ifdef CONFIG_JFFS2_SUMMARY
  1286. buf_len = sizeof(*sm);
  1287. /* Read as much as we want into the _end_ of the preallocated
  1288. * buffer
  1289. */
  1290. get_fl_mem(part->offset + sector_ofs + part->sector_size -
  1291. buf_len, buf_len, buf + buf_size - buf_len);
  1292. sm = (void *)buf + buf_size - sizeof(*sm);
  1293. if (sm->magic == JFFS2_SUM_MAGIC) {
  1294. sumlen = part->sector_size - sm->offset;
  1295. sumptr = buf + buf_size - sumlen;
  1296. /* Now, make sure the summary itself is available */
  1297. if (sumlen > buf_size) {
  1298. /* Need to kmalloc for this. */
  1299. sumptr = malloc(sumlen);
  1300. if (!sumptr) {
  1301. putstr("Can't get memory for summary "
  1302. "node!\n");
  1303. free(buf);
  1304. jffs2_free_cache(part);
  1305. return 0;
  1306. }
  1307. memcpy(sumptr + sumlen - buf_len, buf +
  1308. buf_size - buf_len, buf_len);
  1309. }
  1310. if (buf_len < sumlen) {
  1311. /* Need to read more so that the entire summary
  1312. * node is present
  1313. */
  1314. get_fl_mem(part->offset + sector_ofs +
  1315. part->sector_size - sumlen,
  1316. sumlen - buf_len, sumptr);
  1317. }
  1318. }
  1319. if (sumptr) {
  1320. ret = jffs2_sum_scan_sumnode(part, sector_ofs, sumptr,
  1321. sumlen, pL);
  1322. if (buf_size && sumlen > buf_size)
  1323. free(sumptr);
  1324. if (ret < 0) {
  1325. free(buf);
  1326. jffs2_free_cache(part);
  1327. return 0;
  1328. }
  1329. if (ret)
  1330. continue;
  1331. }
  1332. #endif /* CONFIG_JFFS2_SUMMARY */
  1333. buf_len = EMPTY_SCAN_SIZE(part->sector_size);
  1334. get_fl_mem((u32)part->offset + buf_ofs, buf_len, buf);
  1335. /* We temporarily use 'ofs' as a pointer into the buffer/jeb */
  1336. ofs = 0;
  1337. /* Scan only 4KiB of 0xFF before declaring it's empty */
  1338. while (ofs < EMPTY_SCAN_SIZE(part->sector_size) &&
  1339. *(uint32_t *)(&buf[ofs]) == 0xFFFFFFFF)
  1340. ofs += 4;
  1341. if (ofs == EMPTY_SCAN_SIZE(part->sector_size))
  1342. continue;
  1343. ofs += sector_ofs;
  1344. prevofs = ofs - 1;
  1345. scan_more:
  1346. while (ofs < sector_ofs + part->sector_size) {
  1347. if (ofs == prevofs) {
  1348. printf("offset %08x already seen, skip\n", ofs);
  1349. ofs += 4;
  1350. counter4++;
  1351. continue;
  1352. }
  1353. prevofs = ofs;
  1354. if (sector_ofs + part->sector_size <
  1355. ofs + sizeof(*node))
  1356. break;
  1357. if (buf_ofs + buf_len < ofs + sizeof(*node)) {
  1358. buf_len = min_t(uint32_t, buf_size, sector_ofs
  1359. + part->sector_size - ofs);
  1360. get_fl_mem((u32)part->offset + ofs, buf_len,
  1361. buf);
  1362. buf_ofs = ofs;
  1363. }
  1364. node = (struct jffs2_unknown_node *)&buf[ofs-buf_ofs];
  1365. if (*(uint32_t *)(&buf[ofs-buf_ofs]) == 0xffffffff) {
  1366. uint32_t inbuf_ofs;
  1367. uint32_t empty_start, scan_end;
  1368. empty_start = ofs;
  1369. ofs += 4;
  1370. scan_end = min_t(uint32_t, EMPTY_SCAN_SIZE(
  1371. part->sector_size)/8,
  1372. buf_len);
  1373. more_empty:
  1374. inbuf_ofs = ofs - buf_ofs;
  1375. while (inbuf_ofs < scan_end) {
  1376. if (*(uint32_t *)(&buf[inbuf_ofs]) !=
  1377. 0xffffffff)
  1378. goto scan_more;
  1379. inbuf_ofs += 4;
  1380. ofs += 4;
  1381. }
  1382. /* Ran off end. */
  1383. /* See how much more there is to read in this
  1384. * eraseblock...
  1385. */
  1386. buf_len = min_t(uint32_t, buf_size,
  1387. sector_ofs +
  1388. part->sector_size - ofs);
  1389. if (!buf_len) {
  1390. /* No more to read. Break out of main
  1391. * loop without marking this range of
  1392. * empty space as dirty (because it's
  1393. * not)
  1394. */
  1395. break;
  1396. }
  1397. scan_end = buf_len;
  1398. get_fl_mem((u32)part->offset + ofs, buf_len,
  1399. buf);
  1400. buf_ofs = ofs;
  1401. goto more_empty;
  1402. }
  1403. if (node->magic != JFFS2_MAGIC_BITMASK ||
  1404. !hdr_crc(node)) {
  1405. ofs += 4;
  1406. counter4++;
  1407. continue;
  1408. }
  1409. if (ofs + node->totlen >
  1410. sector_ofs + part->sector_size) {
  1411. ofs += 4;
  1412. counter4++;
  1413. continue;
  1414. }
  1415. /* if its a fragment add it */
  1416. switch (node->nodetype) {
  1417. case JFFS2_NODETYPE_INODE:
  1418. if (buf_ofs + buf_len < ofs + sizeof(struct
  1419. jffs2_raw_inode)) {
  1420. get_fl_mem((u32)part->offset + ofs,
  1421. buf_len, buf);
  1422. buf_ofs = ofs;
  1423. node = (void *)buf;
  1424. }
  1425. if (!inode_crc((struct jffs2_raw_inode *) node))
  1426. break;
  1427. if (insert_node(&pL->frag, (u32) part->offset +
  1428. ofs) == NULL) {
  1429. free(buf);
  1430. jffs2_free_cache(part);
  1431. return 0;
  1432. }
  1433. if (max_totlen < node->totlen)
  1434. max_totlen = node->totlen;
  1435. break;
  1436. case JFFS2_NODETYPE_DIRENT:
  1437. if (buf_ofs + buf_len < ofs + sizeof(struct
  1438. jffs2_raw_dirent) +
  1439. ((struct
  1440. jffs2_raw_dirent *)
  1441. node)->nsize) {
  1442. get_fl_mem((u32)part->offset + ofs,
  1443. buf_len, buf);
  1444. buf_ofs = ofs;
  1445. node = (void *)buf;
  1446. }
  1447. if (!dirent_crc((struct jffs2_raw_dirent *)
  1448. node) ||
  1449. !dirent_name_crc(
  1450. (struct
  1451. jffs2_raw_dirent *)
  1452. node))
  1453. break;
  1454. if (! (counterN%100))
  1455. puts ("\b\b. ");
  1456. if (insert_node(&pL->dir, (u32) part->offset +
  1457. ofs) == NULL) {
  1458. free(buf);
  1459. jffs2_free_cache(part);
  1460. return 0;
  1461. }
  1462. if (max_totlen < node->totlen)
  1463. max_totlen = node->totlen;
  1464. counterN++;
  1465. break;
  1466. case JFFS2_NODETYPE_CLEANMARKER:
  1467. if (node->totlen != sizeof(struct jffs2_unknown_node))
  1468. printf("OOPS Cleanmarker has bad size "
  1469. "%d != %zu\n",
  1470. node->totlen,
  1471. sizeof(struct jffs2_unknown_node));
  1472. break;
  1473. case JFFS2_NODETYPE_PADDING:
  1474. if (node->totlen < sizeof(struct jffs2_unknown_node))
  1475. printf("OOPS Padding has bad size "
  1476. "%d < %zu\n",
  1477. node->totlen,
  1478. sizeof(struct jffs2_unknown_node));
  1479. break;
  1480. case JFFS2_NODETYPE_SUMMARY:
  1481. break;
  1482. default:
  1483. printf("Unknown node type: %x len %d offset 0x%x\n",
  1484. node->nodetype,
  1485. node->totlen, ofs);
  1486. }
  1487. ofs += ((node->totlen + 3) & ~3);
  1488. counterF++;
  1489. }
  1490. }
  1491. free(buf);
  1492. putstr("\b\b done.\r\n"); /* close off the dots */
  1493. /* We don't care if malloc failed - then each read operation will
  1494. * allocate its own buffer as necessary (NAND) or will read directly
  1495. * from flash (NOR).
  1496. */
  1497. pL->readbuf = malloc(max_totlen);
  1498. /* turn the lcd back on. */
  1499. /* splash(); */
  1500. #if 0
  1501. putLabeledWord("dir entries = ", pL->dir.listCount);
  1502. putLabeledWord("frag entries = ", pL->frag.listCount);
  1503. putLabeledWord("+4 increments = ", counter4);
  1504. putLabeledWord("+file_offset increments = ", counterF);
  1505. #endif
  1506. #ifdef DEBUG_DIRENTS
  1507. dump_dirents(pL);
  1508. #endif
  1509. #ifdef DEBUG_FRAGMENTS
  1510. dump_fragments(pL);
  1511. #endif
  1512. /* give visual feedback that we are done scanning the flash */
  1513. led_blink(0x0, 0x0, 0x1, 0x1); /* off, forever, on 100ms, off 100ms */
  1514. return 1;
  1515. }
  1516. static u32
  1517. jffs2_1pass_fill_info(struct b_lists * pL, struct b_jffs2_info * piL)
  1518. {
  1519. struct b_node *b;
  1520. struct jffs2_raw_inode ojNode;
  1521. struct jffs2_raw_inode *jNode;
  1522. int i;
  1523. for (i = 0; i < JFFS2_NUM_COMPR; i++) {
  1524. piL->compr_info[i].num_frags = 0;
  1525. piL->compr_info[i].compr_sum = 0;
  1526. piL->compr_info[i].decompr_sum = 0;
  1527. }
  1528. b = pL->frag.listHead;
  1529. while (b) {
  1530. jNode = (struct jffs2_raw_inode *) get_fl_mem(b->offset,
  1531. sizeof(ojNode), &ojNode);
  1532. if (jNode->compr < JFFS2_NUM_COMPR) {
  1533. piL->compr_info[jNode->compr].num_frags++;
  1534. piL->compr_info[jNode->compr].compr_sum += jNode->csize;
  1535. piL->compr_info[jNode->compr].decompr_sum += jNode->dsize;
  1536. }
  1537. b = b->next;
  1538. }
  1539. return 0;
  1540. }
  1541. static struct b_lists *
  1542. jffs2_get_list(struct part_info * part, const char *who)
  1543. {
  1544. /* copy requested part_info struct pointer to global location */
  1545. current_part = part;
  1546. if (jffs2_1pass_rescan_needed(part)) {
  1547. if (!jffs2_1pass_build_lists(part)) {
  1548. printf("%s: Failed to scan JFFSv2 file structure\n", who);
  1549. return NULL;
  1550. }
  1551. }
  1552. return (struct b_lists *)part->jffs2_priv;
  1553. }
  1554. /* Print directory / file contents */
  1555. u32
  1556. jffs2_1pass_ls(struct part_info * part, const char *fname)
  1557. {
  1558. struct b_lists *pl;
  1559. long ret = 1;
  1560. u32 inode;
  1561. if (! (pl = jffs2_get_list(part, "ls")))
  1562. return 0;
  1563. if (! (inode = jffs2_1pass_search_list_inodes(pl, fname, 1))) {
  1564. putstr("ls: Failed to scan jffs2 file structure\r\n");
  1565. return 0;
  1566. }
  1567. #if 0
  1568. putLabeledWord("found file at inode = ", inode);
  1569. putLabeledWord("read_inode returns = ", ret);
  1570. #endif
  1571. return ret;
  1572. }
  1573. /* Load a file from flash into memory. fname can be a full path */
  1574. u32
  1575. jffs2_1pass_load(char *dest, struct part_info * part, const char *fname)
  1576. {
  1577. struct b_lists *pl;
  1578. long ret = 1;
  1579. u32 inode;
  1580. if (! (pl = jffs2_get_list(part, "load")))
  1581. return 0;
  1582. if (! (inode = jffs2_1pass_search_inode(pl, fname, 1))) {
  1583. putstr("load: Failed to find inode\r\n");
  1584. return 0;
  1585. }
  1586. /* Resolve symlinks */
  1587. if (! (inode = jffs2_1pass_resolve_inode(pl, inode))) {
  1588. putstr("load: Failed to resolve inode structure\r\n");
  1589. return 0;
  1590. }
  1591. if ((ret = jffs2_1pass_read_inode(pl, inode, dest)) < 0) {
  1592. putstr("load: Failed to read inode\r\n");
  1593. return 0;
  1594. }
  1595. DEBUGF ("load: loaded '%s' to 0x%lx (%ld bytes)\n", fname,
  1596. (unsigned long) dest, ret);
  1597. return ret;
  1598. }
  1599. /* Return information about the fs on this partition */
  1600. u32
  1601. jffs2_1pass_info(struct part_info * part)
  1602. {
  1603. struct b_jffs2_info info;
  1604. struct b_lists *pl;
  1605. int i;
  1606. if (! (pl = jffs2_get_list(part, "info")))
  1607. return 0;
  1608. jffs2_1pass_fill_info(pl, &info);
  1609. for (i = 0; i < JFFS2_NUM_COMPR; i++) {
  1610. printf ("Compression: %s\n"
  1611. "\tfrag count: %d\n"
  1612. "\tcompressed sum: %d\n"
  1613. "\tuncompressed sum: %d\n",
  1614. compr_names[i],
  1615. info.compr_info[i].num_frags,
  1616. info.compr_info[i].compr_sum,
  1617. info.compr_info[i].decompr_sum);
  1618. }
  1619. return 1;
  1620. }