Blame view

cmd/jffs2.c 15.2 KB
83d290c56   Tom Rini   SPDX: Convert all...
1
  // SPDX-License-Identifier: GPL-2.0+
c609719b8   wdenk   Initial revision
2
3
4
  /*
   * (C) Copyright 2002
   * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
700a0c648   Wolfgang Denk   Add common (with ...
5
   *
dd875c767   wdenk   * Patch by Robert...
6
7
   * (C) Copyright 2002
   * Robert Schwebel, Pengutronix, <r.schwebel@pengutronix.de>
700a0c648   Wolfgang Denk   Add common (with ...
8
   *
dd875c767   wdenk   * Patch by Robert...
9
10
   * (C) Copyright 2003
   * Kai-Uwe Bloem, Auerswald GmbH & Co KG, <linux-development@auerswald.de>
c609719b8   wdenk   Initial revision
11
   *
700a0c648   Wolfgang Denk   Add common (with ...
12
13
14
15
16
17
18
19
20
   * (C) Copyright 2005
   * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
   *
   *   Added support for reading flash partition table from environment.
   *   Parsing routines are based on driver/mtd/cmdline.c from the linux 2.4
   *   kernel tree.
   *
   *   $Id: cmdlinepart.c,v 1.17 2004/11/26 11:18:47 lavinen Exp $
   *   Copyright 2002 SYSGO Real-Time Solutions GmbH
700a0c648   Wolfgang Denk   Add common (with ...
21
22
23
24
25
26
27
28
29
30
   */
  
  /*
   * Three environment variables are used by the parsing routines:
   *
   * 'partition' - keeps current partition identifier
   *
   * partition  := <part-id>
   * <part-id>  := <dev-id>,part_num
   *
8f79e4c2d   Wolfgang Denk   Add configuration...
31
   *
700a0c648   Wolfgang Denk   Add common (with ...
32
33
34
35
36
   * 'mtdids' - linux kernel mtd device id <-> u-boot device id mapping
   *
   * mtdids=<idmap>[,<idmap>,...]
   *
   * <idmap>    := <dev-id>=<mtd-id>
1a7f8ccec   Kyungmin Park   Add JFFS2 command...
37
   * <dev-id>   := 'nand'|'nor'|'onenand'<dev-num>
700a0c648   Wolfgang Denk   Add common (with ...
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
   * <dev-num>  := mtd device number, 0...
   * <mtd-id>   := unique device tag used by linux kernel to find mtd device (mtd->name)
   *
   *
   * 'mtdparts' - partition list
   *
   * mtdparts=mtdparts=<mtd-def>[;<mtd-def>...]
   *
   * <mtd-def>  := <mtd-id>:<part-def>[,<part-def>...]
   * <mtd-id>   := unique device tag used by linux kernel to find mtd device (mtd->name)
   * <part-def> := <size>[@<offset>][<name>][<ro-flag>]
   * <size>     := standard linux memsize OR '-' to denote all remaining space
   * <offset>   := partition start offset within the device
   * <name>     := '(' NAME ')'
   * <ro-flag>  := when set to 'ro' makes partition read-only (not used, passed to kernel)
   *
   * Notes:
   * - each <mtd-id> used in mtdparts must albo exist in 'mtddis' mapping
   * - if the above variables are not set defaults for a given target are used
   *
   * Examples:
   *
   * 1 NOR Flash, with 1 single writable partition:
   * mtdids=nor0=edb7312-nor
   * mtdparts=mtdparts=edb7312-nor:-
   *
   * 1 NOR Flash with 2 partitions, 1 NAND with one
   * mtdids=nor0=edb7312-nor,nand0=edb7312-nand
   * mtdparts=mtdparts=edb7312-nor:256k(ARMboot)ro,-(root);edb7312-nand:-(home)
   *
   */
  
  /*
991b089d1   Michal Simek   Synchronize with ...
71
   * JFFS2/CRAMFS support
700a0c648   Wolfgang Denk   Add common (with ...
72
73
74
75
76
   */
  #include <common.h>
  #include <command.h>
  #include <malloc.h>
  #include <jffs2/jffs2.h>
700a0c648   Wolfgang Denk   Add common (with ...
77
78
  #include <linux/list.h>
  #include <linux/ctype.h>
700a0c648   Wolfgang Denk   Add common (with ...
79
  #include <cramfs/cramfs_fs.h>
c76fe4742   Jon Loeliger   common/cmd_[i-n]*...
80
  #if defined(CONFIG_CMD_NAND)
6ae3900a8   Masahiro Yamada   mtd: nand: Rename...
81
  #include <linux/mtd/rawnand.h>
ac7eb8a31   Wolfgang Denk   Update of new NAN...
82
  #include <nand.h>
c76fe4742   Jon Loeliger   common/cmd_[i-n]*...
83
  #endif
1a7f8ccec   Kyungmin Park   Add JFFS2 command...
84
85
86
87
88
89
  
  #if defined(CONFIG_CMD_ONENAND)
  #include <linux/mtd/mtd.h>
  #include <linux/mtd/onenand.h>
  #include <onenand_uboot.h>
  #endif
700a0c648   Wolfgang Denk   Add common (with ...
90
  /* enable/disable debugging messages */
038ccac51   Bartlomiej Sieka   Merge with /home/...
91
92
  #define	DEBUG_JFFS
  #undef	DEBUG_JFFS
700a0c648   Wolfgang Denk   Add common (with ...
93

ab4b956d3   Michal Simek   [FIX] Coding styl...
94
  #ifdef  DEBUG_JFFS
700a0c648   Wolfgang Denk   Add common (with ...
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
  # define DEBUGF(fmt, args...)	printf(fmt ,##args)
  #else
  # define DEBUGF(fmt, args...)
  #endif
  
  /* special size referring to all the remaining space in a partition */
  #define SIZE_REMAINING		0xFFFFFFFF
  
  /* special offset value, it is used when not provided by user
   *
   * this value is used temporarily during parsing, later such offests
   * are recalculated */
  #define OFFSET_NOT_SPECIFIED	0xFFFFFFFF
  
  /* minimum partition size */
  #define MIN_PART_SIZE		4096
  
  /* this flag needs to be set in part_info struct mask_flags
   * field for read-only partitions */
038ccac51   Bartlomiej Sieka   Merge with /home/...
114
  #define MTD_WRITEABLE_CMD		1
700a0c648   Wolfgang Denk   Add common (with ...
115

68d7d6510   Stefan Roese   Separate mtdparts...
116
  /* current active device and partition number */
76b5883da   Stefan Roese   jffs2/mtdparts: F...
117
118
119
120
121
122
123
124
125
  #ifdef CONFIG_CMD_MTDPARTS
  /* Use the ones declared in cmd_mtdparts.c */
  extern struct mtd_device *current_mtd_dev;
  extern u8 current_mtd_partnum;
  #else
  /* Use local ones */
  struct mtd_device *current_mtd_dev = NULL;
  u8 current_mtd_partnum = 0;
  #endif
700a0c648   Wolfgang Denk   Add common (with ...
126

68d7d6510   Stefan Roese   Separate mtdparts...
127
128
129
130
131
132
133
134
135
136
137
138
139
  #if defined(CONFIG_CMD_CRAMFS)
  extern int cramfs_check (struct part_info *info);
  extern int cramfs_load (char *loadoffset, struct part_info *info, char *filename);
  extern int cramfs_ls (struct part_info *info, char *filename);
  extern int cramfs_info (struct part_info *info);
  #else
  /* defining empty macros for function names is ugly but avoids ifdef clutter
   * all over the code */
  #define cramfs_check(x)		(0)
  #define cramfs_load(x,y,z)	(-1)
  #define cramfs_ls(x,y)		(0)
  #define cramfs_info(x)		(0)
  #endif
700a0c648   Wolfgang Denk   Add common (with ...
140

68d7d6510   Stefan Roese   Separate mtdparts...
141
  #ifndef CONFIG_CMD_MTDPARTS
700a0c648   Wolfgang Denk   Add common (with ...
142
  /**
68d7d6510   Stefan Roese   Separate mtdparts...
143
   * Check device number to be within valid range for given device type.
700a0c648   Wolfgang Denk   Add common (with ...
144
   *
68d7d6510   Stefan Roese   Separate mtdparts...
145
146
   * @param dev device to validate
   * @return 0 if device is valid, 1 otherwise
c609719b8   wdenk   Initial revision
147
   */
68d7d6510   Stefan Roese   Separate mtdparts...
148
  static int mtd_device_validate(u8 type, u8 num, u32 *size)
700a0c648   Wolfgang Denk   Add common (with ...
149
  {
68d7d6510   Stefan Roese   Separate mtdparts...
150
151
152
153
154
  	if (type == MTD_DEV_TYPE_NOR) {
  #if defined(CONFIG_CMD_FLASH)
  		if (num < CONFIG_SYS_MAX_FLASH_BANKS) {
  			extern flash_info_t flash_info[];
  			*size = flash_info[num].size;
180d3f74e   wdenk   * Fix problems ca...
155

68d7d6510   Stefan Roese   Separate mtdparts...
156
  			return 0;
700a0c648   Wolfgang Denk   Add common (with ...
157
  		}
c609719b8   wdenk   Initial revision
158

68d7d6510   Stefan Roese   Separate mtdparts...
159
160
161
162
163
164
165
166
167
  		printf("no such FLASH device: %s%d (valid range 0 ... %d
  ",
  				MTD_DEV_TYPE(type), num, CONFIG_SYS_MAX_FLASH_BANKS - 1);
  #else
  		printf("support for FLASH devices not present
  ");
  #endif
  	} else if (type == MTD_DEV_TYPE_NAND) {
  #if defined(CONFIG_JFFS2_NAND) && defined(CONFIG_CMD_NAND)
bfdba68ea   Grygorii Strashko   cmd: jffs2: use g...
168
169
170
  		struct mtd_info *mtd = get_nand_dev_by_index(num);
  		if (mtd) {
  			*size = mtd->size;
68d7d6510   Stefan Roese   Separate mtdparts...
171
  			return 0;
700a0c648   Wolfgang Denk   Add common (with ...
172
  		}
6705d81e9   wdenk   * Patch by Andrea...
173

68d7d6510   Stefan Roese   Separate mtdparts...
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
  		printf("no such NAND device: %s%d (valid range 0 ... %d)
  ",
  				MTD_DEV_TYPE(type), num, CONFIG_SYS_MAX_NAND_DEVICE - 1);
  #else
  		printf("support for NAND devices not present
  ");
  #endif
  	} else if (type == MTD_DEV_TYPE_ONENAND) {
  #if defined(CONFIG_CMD_ONENAND)
  		*size = onenand_mtd.size;
  		return 0;
  #else
  		printf("support for OneNAND devices not present
  ");
  #endif
  	} else
  		printf("Unknown defice type %d
  ", type);
c609719b8   wdenk   Initial revision
192

68d7d6510   Stefan Roese   Separate mtdparts...
193
  	return 1;
700a0c648   Wolfgang Denk   Add common (with ...
194
  }
998eaaecd   wdenk   * Configure PPCha...
195

700a0c648   Wolfgang Denk   Add common (with ...
196
  /**
68d7d6510   Stefan Roese   Separate mtdparts...
197
198
   * Parse device id string <dev-id> := 'nand'|'nor'|'onenand'<dev-num>,
   * return device type and number.
700a0c648   Wolfgang Denk   Add common (with ...
199
   *
68d7d6510   Stefan Roese   Separate mtdparts...
200
201
202
203
   * @param id string describing device id
   * @param ret_id output pointer to next char after parse completes (output)
   * @param dev_type parsed device type (output)
   * @param dev_num parsed device number (output)
700a0c648   Wolfgang Denk   Add common (with ...
204
205
   * @return 0 on success, 1 otherwise
   */
68d7d6510   Stefan Roese   Separate mtdparts...
206
  static int mtd_id_parse(const char *id, const char **ret_id, u8 *dev_type, u8 *dev_num)
c609719b8   wdenk   Initial revision
207
  {
68d7d6510   Stefan Roese   Separate mtdparts...
208
  	const char *p = id;
700a0c648   Wolfgang Denk   Add common (with ...
209

68d7d6510   Stefan Roese   Separate mtdparts...
210
211
212
213
214
215
216
217
218
219
220
221
222
  	*dev_type = 0;
  	if (strncmp(p, "nand", 4) == 0) {
  		*dev_type = MTD_DEV_TYPE_NAND;
  		p += 4;
  	} else if (strncmp(p, "nor", 3) == 0) {
  		*dev_type = MTD_DEV_TYPE_NOR;
  		p += 3;
  	} else if (strncmp(p, "onenand", 7) == 0) {
  		*dev_type = MTD_DEV_TYPE_ONENAND;
  		p += 7;
  	} else {
  		printf("incorrect device type in %s
  ", id);
700a0c648   Wolfgang Denk   Add common (with ...
223
224
  		return 1;
  	}
c609719b8   wdenk   Initial revision
225

68d7d6510   Stefan Roese   Separate mtdparts...
226
227
228
  	if (!isdigit(*p)) {
  		printf("incorrect device number in %s
  ", id);
700a0c648   Wolfgang Denk   Add common (with ...
229
230
  		return 1;
  	}
68d7d6510   Stefan Roese   Separate mtdparts...
231
232
233
  	*dev_num = simple_strtoul(p, (char **)&p, 0);
  	if (ret_id)
  		*ret_id = p;
700a0c648   Wolfgang Denk   Add common (with ...
234
235
  	return 0;
  }
68d7d6510   Stefan Roese   Separate mtdparts...
236

700a0c648   Wolfgang Denk   Add common (with ...
237
238
239
240
241
242
  /*
   * 'Static' version of command line mtdparts_init() routine. Single partition on
   * a single device configuration.
   */
  
  /**
b5b004ad8   Tomasz Figa   jffs2: Fix zero s...
243
244
245
246
247
248
249
   * Calculate sector size.
   *
   * @return sector size
   */
  static inline u32 get_part_sector_size_nand(struct mtdids *id)
  {
  #if defined(CONFIG_JFFS2_NAND) && defined(CONFIG_CMD_NAND)
151c06ec6   Scott Wood   mtd: nand: Remove...
250
  	struct mtd_info *mtd;
b5b004ad8   Tomasz Figa   jffs2: Fix zero s...
251

bfdba68ea   Grygorii Strashko   cmd: jffs2: use g...
252
  	mtd = get_nand_dev_by_index(id->num);
b5b004ad8   Tomasz Figa   jffs2: Fix zero s...
253

151c06ec6   Scott Wood   mtd: nand: Remove...
254
  	return mtd->erasesize;
b5b004ad8   Tomasz Figa   jffs2: Fix zero s...
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
  #else
  	BUG();
  	return 0;
  #endif
  }
  
  static inline u32 get_part_sector_size_nor(struct mtdids *id, struct part_info *part)
  {
  #if defined(CONFIG_CMD_FLASH)
  	extern flash_info_t flash_info[];
  
  	u32 end_phys, start_phys, sector_size = 0, size = 0;
  	int i;
  	flash_info_t *flash;
  
  	flash = &flash_info[id->num];
  
  	start_phys = flash->start[0] + part->offset;
141053d60   Peter Tyser   cmd_jffs2: Fix ge...
273
  	end_phys = start_phys + part->size - 1;
b5b004ad8   Tomasz Figa   jffs2: Fix zero s...
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
  
  	for (i = 0; i < flash->sector_count; i++) {
  		if (flash->start[i] >= end_phys)
  			break;
  
  		if (flash->start[i] >= start_phys) {
  			if (i == flash->sector_count - 1) {
  				size = flash->start[0] + flash->size - flash->start[i];
  			} else {
  				size = flash->start[i+1] - flash->start[i];
  			}
  
  			if (sector_size < size)
  				sector_size = size;
  		}
  	}
  
  	return sector_size;
  #else
  	BUG();
  	return 0;
  #endif
  }
  
  static inline u32 get_part_sector_size_onenand(void)
  {
  #if defined(CONFIG_CMD_ONENAND)
  	struct mtd_info *mtd;
  
  	mtd = &onenand_mtd;
  
  	return mtd->erasesize;
  #else
  	BUG();
  	return 0;
  #endif
  }
  
  static inline u32 get_part_sector_size(struct mtdids *id, struct part_info *part)
  {
  	if (id->type == MTD_DEV_TYPE_NAND)
  		return get_part_sector_size_nand(id);
  	else if (id->type == MTD_DEV_TYPE_NOR)
  		return get_part_sector_size_nor(id, part);
  	else if (id->type == MTD_DEV_TYPE_ONENAND)
  		return get_part_sector_size_onenand();
  	else
  		DEBUGF("Error: Unknown device type.
  ");
  
  	return 0;
  }
  
  /**
700a0c648   Wolfgang Denk   Add common (with ...
328
   * Parse and initialize global mtdids mapping and create global
8f79e4c2d   Wolfgang Denk   Add configuration...
329
   * device/partition list.
700a0c648   Wolfgang Denk   Add common (with ...
330
   *
76b5883da   Stefan Roese   jffs2/mtdparts: F...
331
332
333
   * 'Static' version of command line mtdparts_init() routine. Single partition on
   * a single device configuration.
   *
700a0c648   Wolfgang Denk   Add common (with ...
334
335
336
337
338
339
340
341
342
343
344
345
   * @return 0 on success, 1 otherwise
   */
  int mtdparts_init(void)
  {
  	static int initialized = 0;
  	u32 size;
  	char *dev_name;
  
  	DEBUGF("
  ---mtdparts_init---
  ");
  	if (!initialized) {
c4e0e6860   Wolfgang Denk   Make new "mtdpart...
346
347
  		struct mtdids *id;
  		struct part_info *part;
700a0c648   Wolfgang Denk   Add common (with ...
348
  		initialized = 1;
76b5883da   Stefan Roese   jffs2/mtdparts: F...
349
  		current_mtd_dev = (struct mtd_device *)
700a0c648   Wolfgang Denk   Add common (with ...
350
351
352
  			malloc(sizeof(struct mtd_device) +
  					sizeof(struct part_info) +
  					sizeof(struct mtdids));
76b5883da   Stefan Roese   jffs2/mtdparts: F...
353
  		if (!current_mtd_dev) {
700a0c648   Wolfgang Denk   Add common (with ...
354
355
356
357
  			printf("out of memory
  ");
  			return 1;
  		}
76b5883da   Stefan Roese   jffs2/mtdparts: F...
358
359
  		memset(current_mtd_dev, 0, sizeof(struct mtd_device) +
  		       sizeof(struct part_info) + sizeof(struct mtdids));
700a0c648   Wolfgang Denk   Add common (with ...
360

76b5883da   Stefan Roese   jffs2/mtdparts: F...
361
  		id = (struct mtdids *)(current_mtd_dev + 1);
c4e0e6860   Wolfgang Denk   Make new "mtdpart...
362
  		part = (struct part_info *)(id + 1);
c609719b8   wdenk   Initial revision
363

700a0c648   Wolfgang Denk   Add common (with ...
364
365
  		/* id */
  		id->mtd_id = "single part";
c609719b8   wdenk   Initial revision
366

700a0c648   Wolfgang Denk   Add common (with ...
367
368
  #if defined(CONFIG_JFFS2_DEV)
  		dev_name = CONFIG_JFFS2_DEV;
c609719b8   wdenk   Initial revision
369
  #else
700a0c648   Wolfgang Denk   Add common (with ...
370
  		dev_name = "nor0";
c609719b8   wdenk   Initial revision
371
  #endif
68d7d6510   Stefan Roese   Separate mtdparts...
372
373
  		if ((mtd_id_parse(dev_name, NULL, &id->type, &id->num) != 0) ||
  				(mtd_device_validate(id->type, id->num, &size) != 0)) {
700a0c648   Wolfgang Denk   Add common (with ...
374
375
  			printf("incorrect device: %s%d
  ", MTD_DEV_TYPE(id->type), id->num);
76b5883da   Stefan Roese   jffs2/mtdparts: F...
376
  			free(current_mtd_dev);
700a0c648   Wolfgang Denk   Add common (with ...
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
  			return 1;
  		}
  		id->size = size;
  		INIT_LIST_HEAD(&id->link);
  
  		DEBUGF("dev id: type = %d, num = %d, size = 0x%08lx, mtd_id = %s
  ",
  				id->type, id->num, id->size, id->mtd_id);
  
  		/* partition */
  		part->name = "static";
  		part->auto_name = 0;
  
  #if defined(CONFIG_JFFS2_PART_SIZE)
  		part->size = CONFIG_JFFS2_PART_SIZE;
  #else
  		part->size = SIZE_REMAINING;
  #endif
c609719b8   wdenk   Initial revision
395

700a0c648   Wolfgang Denk   Add common (with ...
396
397
398
399
  #if defined(CONFIG_JFFS2_PART_OFFSET)
  		part->offset = CONFIG_JFFS2_PART_OFFSET;
  #else
  		part->offset = 0x00000000;
c609719b8   wdenk   Initial revision
400
  #endif
76b5883da   Stefan Roese   jffs2/mtdparts: F...
401
  		part->dev = current_mtd_dev;
700a0c648   Wolfgang Denk   Add common (with ...
402
403
404
405
406
  		INIT_LIST_HEAD(&part->link);
  
  		/* recalculate size if needed */
  		if (part->size == SIZE_REMAINING)
  			part->size = id->size - part->offset;
c609719b8   wdenk   Initial revision
407

2903ad33a   Mike Frysinger   jffs2: fix hangs/...
408
  		part->sector_size = get_part_sector_size(id, part);
700a0c648   Wolfgang Denk   Add common (with ...
409
410
411
412
413
  		DEBUGF("part  : name = %s, size = 0x%08lx, offset = 0x%08lx
  ",
  				part->name, part->size, part->offset);
  
  		/* device */
76b5883da   Stefan Roese   jffs2/mtdparts: F...
414
415
416
417
418
  		current_mtd_dev->id = id;
  		INIT_LIST_HEAD(&current_mtd_dev->link);
  		current_mtd_dev->num_parts = 1;
  		INIT_LIST_HEAD(&current_mtd_dev->parts);
  		list_add(&part->link, &current_mtd_dev->parts);
c609719b8   wdenk   Initial revision
419
  	}
700a0c648   Wolfgang Denk   Add common (with ...
420

c609719b8   wdenk   Initial revision
421
422
  	return 0;
  }
68d7d6510   Stefan Roese   Separate mtdparts...
423
  #endif /* #ifndef CONFIG_CMD_MTDPARTS */
998eaaecd   wdenk   * Configure PPCha...
424

700a0c648   Wolfgang Denk   Add common (with ...
425
426
427
428
429
430
431
432
433
  /**
   * Return pointer to the partition of a requested number from a requested
   * device.
   *
   * @param dev device that is to be searched for a partition
   * @param part_num requested partition number
   * @return pointer to the part_info, NULL otherwise
   */
  static struct part_info* jffs2_part_info(struct mtd_device *dev, unsigned int part_num)
998eaaecd   wdenk   * Configure PPCha...
434
  {
700a0c648   Wolfgang Denk   Add common (with ...
435
436
437
  	struct list_head *entry;
  	struct part_info *part;
  	int num;
998eaaecd   wdenk   * Configure PPCha...
438

700a0c648   Wolfgang Denk   Add common (with ...
439
440
  	if (!dev)
  		return NULL;
998eaaecd   wdenk   * Configure PPCha...
441

700a0c648   Wolfgang Denk   Add common (with ...
442
443
444
445
446
  	DEBUGF("
  --- jffs2_part_info: partition number %d for device %s%d (%s)
  ",
  			part_num, MTD_DEV_TYPE(dev->id->type),
  			dev->id->num, dev->id->mtd_id);
998eaaecd   wdenk   * Configure PPCha...
447

700a0c648   Wolfgang Denk   Add common (with ...
448
449
450
451
452
453
454
  	if (part_num >= dev->num_parts) {
  		printf("invalid partition number %d for device %s%d (%s)
  ",
  				part_num, MTD_DEV_TYPE(dev->id->type),
  				dev->id->num, dev->id->mtd_id);
  		return NULL;
  	}
998eaaecd   wdenk   * Configure PPCha...
455

700a0c648   Wolfgang Denk   Add common (with ...
456
457
458
459
460
461
462
463
  	/* locate partition number, return it */
  	num = 0;
  	list_for_each(entry, &dev->parts) {
  		part = list_entry(entry, struct part_info, link);
  
  		if (part_num == num++) {
  			return part;
  		}
998eaaecd   wdenk   * Configure PPCha...
464
  	}
700a0c648   Wolfgang Denk   Add common (with ...
465
466
  
  	return NULL;
998eaaecd   wdenk   * Configure PPCha...
467
  }
ab4b956d3   Michal Simek   [FIX] Coding styl...
468
  /***************************************************/
a187559e3   Bin Meng   Use correct spell...
469
  /* U-Boot commands				   */
ab4b956d3   Michal Simek   [FIX] Coding styl...
470
  /***************************************************/
dd875c767   wdenk   * Patch by Robert...
471

700a0c648   Wolfgang Denk   Add common (with ...
472
473
474
475
476
477
478
479
480
481
  /**
   * Routine implementing fsload u-boot command. This routine tries to load
   * a requested file from jffs2/cramfs filesystem on a current partition.
   *
   * @param cmdtp command internal data
   * @param flag command flag
   * @param argc number of arguments supplied to the command
   * @param argv arguments list
   * @return 0 on success, 1 otherwise
   */
54841ab50   Wolfgang Denk   Make sure that ar...
482
  int do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
c609719b8   wdenk   Initial revision
483
  {
39539887e   wdenk   * Code cleanup (A...
484
  	char *fsname;
f39748ae8   wdenk   * Patch by Paul R...
485
  	char *filename;
39539887e   wdenk   * Code cleanup (A...
486
487
488
  	int size;
  	struct part_info *part;
  	ulong offset = load_addr;
f39748ae8   wdenk   * Patch by Paul R...
489
490
  
  	/* pre-set Boot file name */
00caae6d4   Simon Glass   env: Rename geten...
491
492
  	filename = env_get("bootfile");
  	if (!filename)
f39748ae8   wdenk   * Patch by Paul R...
493
  		filename = "uImage";
f39748ae8   wdenk   * Patch by Paul R...
494

c609719b8   wdenk   Initial revision
495
496
497
498
499
  	if (argc == 2) {
  		filename = argv[1];
  	}
  	if (argc == 3) {
  		offset = simple_strtoul(argv[1], NULL, 16);
4b9206ed5   wdenk   * Patches by Thom...
500
  		load_addr = offset;
c609719b8   wdenk   Initial revision
501
502
  		filename = argv[2];
  	}
700a0c648   Wolfgang Denk   Add common (with ...
503
504
505
  	/* make sure we are in sync with env variables */
  	if (mtdparts_init() !=0)
  		return 1;
76b5883da   Stefan Roese   jffs2/mtdparts: F...
506
  	if ((part = jffs2_part_info(current_mtd_dev, current_mtd_partnum))){
c609719b8   wdenk   Initial revision
507

991b089d1   Michal Simek   Synchronize with ...
508
509
  		/* check partition type for cramfs */
  		fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
dd875c767   wdenk   * Patch by Robert...
510
511
512
513
514
515
  		printf("### %s loading '%s' to 0x%lx
  ", fsname, filename, offset);
  
  		if (cramfs_check(part)) {
  			size = cramfs_load ((char *) offset, part, filename);
  		} else {
991b089d1   Michal Simek   Synchronize with ...
516
  			/* if this is not cramfs assume jffs2 */
dd875c767   wdenk   * Patch by Robert...
517
518
  			size = jffs2_1pass_load((char *)offset, part, filename);
  		}
c609719b8   wdenk   Initial revision
519
520
  
  		if (size > 0) {
dd875c767   wdenk   * Patch by Robert...
521
522
523
  			printf("### %s load complete: %d bytes loaded to 0x%lx
  ",
  				fsname, size, offset);
018f53032   Simon Glass   env: Rename commo...
524
  			env_set_hex("filesize", size);
c609719b8   wdenk   Initial revision
525
  		} else {
dd875c767   wdenk   * Patch by Robert...
526
527
  			printf("### %s LOAD ERROR<%x> for %s!
  ", fsname, size, filename);
c609719b8   wdenk   Initial revision
528
529
530
531
  		}
  
  		return !(size > 0);
  	}
87b8bd5ae   Wolfgang Denk   Fix return values...
532
  	return 1;
c609719b8   wdenk   Initial revision
533
  }
700a0c648   Wolfgang Denk   Add common (with ...
534
535
536
537
538
539
540
541
542
543
  /**
   * Routine implementing u-boot ls command which lists content of a given
   * directory on a current partition.
   *
   * @param cmdtp command internal data
   * @param flag command flag
   * @param argc number of arguments supplied to the command
   * @param argv arguments list
   * @return 0 on success, 1 otherwise
   */
54841ab50   Wolfgang Denk   Make sure that ar...
544
  int do_jffs2_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
c609719b8   wdenk   Initial revision
545
  {
a87589da7   wdenk   * Add support for...
546
  	char *filename = "/";
c609719b8   wdenk   Initial revision
547
548
549
550
551
  	int ret;
  	struct part_info *part;
  
  	if (argc == 2)
  		filename = argv[1];
700a0c648   Wolfgang Denk   Add common (with ...
552
553
554
  	/* make sure we are in sync with env variables */
  	if (mtdparts_init() !=0)
  		return 1;
76b5883da   Stefan Roese   jffs2/mtdparts: F...
555
  	if ((part = jffs2_part_info(current_mtd_dev, current_mtd_partnum))){
c609719b8   wdenk   Initial revision
556

dd875c767   wdenk   * Patch by Robert...
557
558
559
560
  		/* check partition type for cramfs */
  		if (cramfs_check(part)) {
  			ret = cramfs_ls (part, filename);
  		} else {
991b089d1   Michal Simek   Synchronize with ...
561
  			/* if this is not cramfs assume jffs2 */
dd875c767   wdenk   * Patch by Robert...
562
563
  			ret = jffs2_1pass_ls(part, filename);
  		}
c609719b8   wdenk   Initial revision
564

87b8bd5ae   Wolfgang Denk   Fix return values...
565
  		return ret ? 0 : 1;
c609719b8   wdenk   Initial revision
566
  	}
87b8bd5ae   Wolfgang Denk   Fix return values...
567
  	return 1;
c609719b8   wdenk   Initial revision
568
  }
700a0c648   Wolfgang Denk   Add common (with ...
569
570
571
572
573
574
575
576
577
578
  /**
   * Routine implementing u-boot fsinfo command. This routine prints out
   * miscellaneous filesystem informations/statistics.
   *
   * @param cmdtp command internal data
   * @param flag command flag
   * @param argc number of arguments supplied to the command
   * @param argv arguments list
   * @return 0 on success, 1 otherwise
   */
54841ab50   Wolfgang Denk   Make sure that ar...
579
  int do_jffs2_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
c609719b8   wdenk   Initial revision
580
  {
c609719b8   wdenk   Initial revision
581
  	struct part_info *part;
991b089d1   Michal Simek   Synchronize with ...
582
  	char *fsname;
dd875c767   wdenk   * Patch by Robert...
583
  	int ret;
c609719b8   wdenk   Initial revision
584

700a0c648   Wolfgang Denk   Add common (with ...
585
586
587
  	/* make sure we are in sync with env variables */
  	if (mtdparts_init() !=0)
  		return 1;
8f79e4c2d   Wolfgang Denk   Add configuration...
588

76b5883da   Stefan Roese   jffs2/mtdparts: F...
589
  	if ((part = jffs2_part_info(current_mtd_dev, current_mtd_partnum))){
dd875c767   wdenk   * Patch by Robert...
590
591
  
  		/* check partition type for cramfs */
991b089d1   Michal Simek   Synchronize with ...
592
593
594
  		fsname = (cramfs_check(part) ? "CRAMFS" : "JFFS2");
  		printf("### filesystem type is %s
  ", fsname);
c609719b8   wdenk   Initial revision
595

dd875c767   wdenk   * Patch by Robert...
596
597
598
  		if (cramfs_check(part)) {
  			ret = cramfs_info (part);
  		} else {
991b089d1   Michal Simek   Synchronize with ...
599
  			/* if this is not cramfs assume jffs2 */
dd875c767   wdenk   * Patch by Robert...
600
601
  			ret = jffs2_1pass_info(part);
  		}
c609719b8   wdenk   Initial revision
602

87b8bd5ae   Wolfgang Denk   Fix return values...
603
  		return ret ? 0 : 1;
c609719b8   wdenk   Initial revision
604
  	}
87b8bd5ae   Wolfgang Denk   Fix return values...
605
  	return 1;
c609719b8   wdenk   Initial revision
606
  }
700a0c648   Wolfgang Denk   Add common (with ...
607
  /***************************************************/
0d4983930   wdenk   Patch by Kenneth ...
608
609
  U_BOOT_CMD(
  	fsload,	3,	0,	do_jffs2_fsload,
2fb2604d5   Peter Tyser   Command usage cle...
610
  	"load binary file from a filesystem image",
8bde7f776   wdenk   * Code cleanup:
611
612
613
614
  	"[ off ] [ filename ]
  "
  	"    - load binary file from flash bank
  "
a89c33db9   Wolfgang Denk   General help mess...
615
  	"      with offset 'off'"
8bde7f776   wdenk   * Code cleanup:
616
  );
700a0c648   Wolfgang Denk   Add common (with ...
617
  U_BOOT_CMD(
314f6362c   Siva Durga Prasad Paladugu   cmd: jffs2: Renam...
618
  	fsls,	2,	1,	do_jffs2_ls,
2fb2604d5   Peter Tyser   Command usage cle...
619
  	"list files in a directory (default /)",
a89c33db9   Wolfgang Denk   General help mess...
620
  	"[ directory ]"
700a0c648   Wolfgang Denk   Add common (with ...
621
  );
8bde7f776   wdenk   * Code cleanup:
622

0d4983930   wdenk   Patch by Kenneth ...
623
624
  U_BOOT_CMD(
  	fsinfo,	1,	1,	do_jffs2_fsinfo,
2fb2604d5   Peter Tyser   Command usage cle...
625
  	"print information about filesystems",
a89c33db9   Wolfgang Denk   General help mess...
626
  	""
8bde7f776   wdenk   * Code cleanup:
627
  );
700a0c648   Wolfgang Denk   Add common (with ...
628
  /***************************************************/