OpenWrt – Diff between revs 2 and 3
?pathlinks?
Rev 2 | Rev 3 | |||
---|---|---|---|---|
Line 6... | Line 6... | |||
6 | drivers/mtd/ubi/build.c | 36 ++++++++++++++++++++++++++++++++++++ |
6 | drivers/mtd/ubi/build.c | 36 ++++++++++++++++++++++++++++++++++++ |
|
7 | 1 file changed, 36 insertions(+) |
7 | 1 file changed, 36 insertions(+) |
|
Line 8... | Line 8... | |||
8 | |
8 | |
|
9 | --- a/drivers/mtd/ubi/build.c |
9 | --- a/drivers/mtd/ubi/build.c |
|
10 | +++ b/drivers/mtd/ubi/build.c |
10 | +++ b/drivers/mtd/ubi/build.c |
|
11 | @@ -1226,6 +1226,73 @@ static struct mtd_info * __init open_mtd |
11 | @@ -1226,6 +1226,49 @@ static struct mtd_info * __init open_mtd |
|
12 | return mtd; |
12 | return mtd; |
|
Line 13... | Line 13... | |||
13 | } |
13 | } |
|
14 | |
14 | |
|
Line 18... | Line 18... | |||
18 | + */ |
18 | + */ |
|
19 | +static void __init ubi_auto_attach(void) |
19 | +static void __init ubi_auto_attach(void) |
|
20 | +{ |
20 | +{ |
|
21 | + int err; |
21 | + int err; |
|
22 | + struct mtd_info *mtd; |
22 | + struct mtd_info *mtd; |
|
23 | + loff_t offset = 0; |
- | ||
24 | + size_t len; |
- | ||
25 | + char magic[4]; |
- | ||
26 | + |
23 | + |
|
27 | + /* try attaching mtd device named "ubi" or "data" */ |
24 | + /* try attaching mtd device named "ubi" or "data" */ |
|
28 | + mtd = open_mtd_device("ubi"); |
25 | + mtd = open_mtd_device("ubi"); |
|
29 | + if (IS_ERR(mtd)) |
26 | + if (IS_ERR(mtd)) |
|
30 | + mtd = open_mtd_device("data"); |
27 | + mtd = open_mtd_device("data"); |
|
31 | + |
28 | + |
|
32 | + if (IS_ERR(mtd)) |
29 | + if (!IS_ERR(mtd)) { |
|
33 | + return; |
30 | + size_t len; |
|
- | 31 | + char magic[4]; |
||
34 | + |
32 | + |
|
35 | + /* get the first not bad block */ |
33 | + /* check for a valid ubi magic */ |
|
36 | + if (mtd_can_have_bb(mtd)) |
34 | + err = mtd_read(mtd, 0, 4, &len, (void *) magic); |
|
37 | + while (mtd_block_isbad(mtd, offset)) { |
35 | + if (!err && len == 4 && strncmp(magic, "UBI#", 4)) { |
|
- | 36 | + pr_err("UBI error: no valid UBI magic found inside mtd%d\n", mtd->index); |
||
38 | + offset += mtd->erasesize; |
37 | + put_mtd_device(mtd); |
|
- | 38 | + return; |
||
- | 39 | + } |
||
39 | + |
40 | + |
|
- | 41 | + /* auto-add only media types where UBI makes sense */ |
||
40 | + if (offset > mtd->size) { |
42 | + if (mtd->type == MTD_NANDFLASH || |
|
- | 43 | + mtd->type == MTD_NORFLASH || |
||
- | 44 | + mtd->type == MTD_DATAFLASH || |
||
- | 45 | + mtd->type == MTD_MLCNANDFLASH) { |
||
- | 46 | + mutex_lock(&ubi_devices_mutex); |
||
41 | + pr_err("UBI error: Failed to find a non-bad " |
47 | + pr_notice("UBI: auto-attach mtd%d\n", mtd->index); |
|
- | 48 | + err = ubi_attach_mtd_dev(mtd, UBI_DEV_NUM_AUTO, 0, 0); |
||
- | 49 | + mutex_unlock(&ubi_devices_mutex); |
||
- | 50 | + if (err < 0) { |
||
42 | + "block on mtd%d\n", mtd->index); |
51 | + pr_err("UBI error: cannot attach mtd%d\n", mtd->index); |
|
43 | + goto cleanup; |
52 | + put_mtd_device(mtd); |
|
44 | + } |
53 | + } |
|
45 | + } |
54 | + } |
|
46 | + |
- | ||
47 | + /* check if the read from flash was successful */ |
- | ||
48 | + err = mtd_read(mtd, offset, 4, &len, (void *) magic); |
- | ||
49 | + if ((err && !mtd_is_bitflip(err)) || len != 4) { |
- | ||
50 | + pr_err("UBI error: unable to read from mtd%d\n", mtd->index); |
- | ||
51 | + goto cleanup; |
- | ||
52 | + } |
- | ||
53 | + |
- | ||
54 | + /* check for a valid ubi magic */ |
- | ||
55 | + if (strncmp(magic, "UBI#", 4)) { |
- | ||
56 | + pr_err("UBI error: no valid UBI magic found inside mtd%d\n", mtd->index); |
- | ||
57 | + goto cleanup; |
- | ||
58 | + } |
55 | + } |
|
59 | + |
- | ||
60 | + /* don't auto-add media types where UBI doesn't makes sense */ |
- | ||
61 | + if (mtd->type != MTD_NANDFLASH && |
- | ||
62 | + mtd->type != MTD_NORFLASH && |
- | ||
63 | + mtd->type != MTD_DATAFLASH && |
- | ||
64 | + mtd->type != MTD_MLCNANDFLASH) |
- | ||
65 | + goto cleanup; |
- | ||
66 | + |
- | ||
67 | + mutex_lock(&ubi_devices_mutex); |
- | ||
68 | + pr_notice("UBI: auto-attach mtd%d\n", mtd->index); |
- | ||
69 | + err = ubi_attach_mtd_dev(mtd, UBI_DEV_NUM_AUTO, 0, 0); |
- | ||
70 | + mutex_unlock(&ubi_devices_mutex); |
- | ||
71 | + if (err < 0) { |
- | ||
72 | + pr_err("UBI error: cannot attach mtd%d\n", mtd->index); |
- | ||
73 | + goto cleanup; |
- | ||
74 | + } |
- | ||
75 | + |
- | ||
76 | + return; |
- | ||
77 | + |
- | ||
78 | +cleanup: |
- | ||
79 | + put_mtd_device(mtd); |
- | ||
80 | +} |
56 | +} |
|
81 | + |
57 | + |
|
82 | static int __init ubi_init(void) |
58 | static int __init ubi_init(void) |
|
83 | { |
59 | { |
|
84 | int err, i, k; |
60 | int err, i, k; |
|
85 | @@ -1309,6 +1376,12 @@ static int __init ubi_init(void) |
61 | @@ -1309,6 +1352,12 @@ static int __init ubi_init(void) |
|
86 | } |
62 | } |
|
87 | } |
63 | } |
|
Line 88... | Line 64... | |||
88 | |
64 | |
|
89 | + /* auto-attach mtd devices only if built-in to the kernel and no ubi.mtd |
65 | + /* auto-attach mtd devices only if built-in to the kernel and no ubi.mtd |