#!/usr/bin/env perl # # Script for generating redboot configs, based on brcmImage.pl # # Copyright (C) 2015 Álvaro Fernández Rojas # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # use strict; use Getopt::Std; use File::stat; my $version = "0.1"; my %arg = ( o => 'redboot.script', s => 0x1000, f => 0xbe430000, a => 0x80010000, l => 0x7c0000, t => 20, ); my $prog = $0; $prog =~ s/^.*\///; getopts("r:k:o:s:f:a:l:t:vh", \%arg); die "usage: $prog ~opts~ -r : input rootfs file -k : input kernel file -o : output image file, default $arg{o} -s : redboot script size, default ".sprintf('%d', parse_num($arg{s}))." -f : flash base, default ".sprintf('0x%x', parse_num($arg{f}))." -a : Kernel load address, default ".sprintf('0x%x', parse_num($arg{a}))." -l : linux partition size, default ".sprintf('0x%x', parse_num($arg{l}))." -t : redboot script timeout, default ".sprintf('%d', parse_num($arg{t}))." -v : be more verbose -h : help, version $version EXAMPLES: $prog -k kern -r rootfs " if $arg{h} || !$arg{k} || !$arg{r}; sub parse_num { my $num = @_[0]; if (index(lc($num), lc("0x")) == 0) { return hex($num); } else { return $num + 0; } } sub gen_script { my $kernel_off = parse_num($arg{s}); my $kernel_addr = parse_num($arg{f}); my $kernel_len = stat($arg{k})->size; my $rootfs_off = $kernel_off + $kernel_len; my $rootfs_addr = $kernel_addr + $kernel_len; my $rootfs_len = parse_num($arg{l}) - $kernel_len; my $rootfs_size = stat($arg{r})->size; my $load_addr = parse_num($arg{a}); my $timeout = parse_num($arg{t}); if ($arg{v}) { printf "kernel_off: 0x%x(%u)\n", $kernel_off, $kernel_off; printf "kernel_addr: 0x%x(%u)\n", $kernel_addr, $kernel_addr; printf "kernel_len: 0x%x(%u)\n", $kernel_len, $kernel_len; printf "rootfs_off: 0x%x(%u)\n", $rootfs_off, $rootfs_off; printf "rootfs_addr: 0x%x(%u)\n", $rootfs_addr, $rootfs_addr; printf "rootfs_len: 0x%x(%u)\n", $rootfs_len, $rootfs_len; printf "rootfs_size: 0x%x(%u)\n", $rootfs_size, $rootfs_size; } open(FO, ">$arg{o}"); printf FO "fis init -f\n"; printf FO "\n"; printf FO "fconfig boot_script true\n"; printf FO "fconfig boot_script_data\n"; printf FO "fis load -b 0x%x -d kernel\n", $load_addr; printf FO "exec -c \"noinitrd\" 0x%x\n", $load_addr; printf FO "\n"; printf FO "fconfig boot_script_timeout %d\n", $timeout; printf FO "\n"; printf FO "fis create -o 0x%x -f 0x%x -l 0x%x kernel\n", $kernel_off, $kernel_addr, $kernel_len; printf FO "\n"; printf FO "fis create -o 0x%x -s 0x%x -f 0x%x -l 0x%x rootfs\n", $rootfs_off, $rootfs_size, $rootfs_addr, $rootfs_len; printf FO "\n"; printf FO "reset\n"; close FO; } # MAIN gen_script(); m/tree/target/linux?id=401b201d0495ca23a68ebf3c41bf527b4fbb6f0d'>linux/generic/patches-4.1/532-jffs2_eofdetect.patch
blob: 9cbe183138889dc558857d2d565562acfcbd7afa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
--- a/fs/jffs2/build.c
+++ b/fs/jffs2/build.c
@@ -114,6 +114,16 @@ static int jffs2_build_filesystem(struct
 	dbg_fsbuild("scanned flash completely\n");
 	jffs2_dbg_dump_block_lists_nolock(c);
 
+	if (c->flags & (1 << 7)) {
+		printk("%s(): unlocking the mtd device... ", __func__);
+		mtd_unlock(c->mtd, 0, c->mtd->size);
+		printk("done.\n");
+
+		printk("%s(): erasing all blocks after the end marker... ", __func__);
+		jffs2_erase_pending_blocks(c, -1);
+		printk("done.\n");
+	}
+
 	dbg_fsbuild("pass 1 starting\n");
 	c->flags |= JFFS2_SB_FLAG_BUILDING;
 	/* Now scan the directory tree, increasing nlink according to every dirent found. */
--- a/fs/jffs2/scan.c
+++ b/fs/jffs2/scan.c
@@ -148,8 +148,14 @@ int jffs2_scan_medium(struct jffs2_sb_in
 		/* reset summary info for next eraseblock scan */
 		jffs2_sum_reset_collected(s);
 
-		ret = jffs2_scan_eraseblock(c, jeb, buf_size?flashbuf:(flashbuf+jeb->offset),
-						buf_size, s);
+		if (c->flags & (1 << 7)) {
+			if (mtd_block_isbad(c->mtd, jeb->offset))
+				ret = BLK_STATE_BADBLOCK;
+			else
+				ret = BLK_STATE_ALLFF;
+		} else
+			ret = jffs2_scan_eraseblock(c, jeb, buf_size?flashbuf:(flashbuf+jeb->offset),
+							buf_size, s);
 
 		if (ret < 0)
 			goto out;
@@ -561,6 +567,17 @@ full_scan:
 			return err;
 	}
 
+	if ((buf[0] == 0xde) &&
+		(buf[1] == 0xad) &&
+		(buf[2] == 0xc0) &&
+		(buf[3] == 0xde)) {
+		/* end of filesystem. erase everything after this point */
+		printk("%s(): End of filesystem marker found at 0x%x\n", __func__, jeb->offset);
+		c->flags |= (1 << 7);
+
+		return BLK_STATE_ALLFF;
+	}
+
 	/* We temporarily use 'ofs' as a pointer into the buffer/jeb */
 	ofs = 0;
 	max_ofs = EMPTY_SCAN_SIZE(c->sector_size);