9948858d054bc5aa8a9ad413d6a50e7467c60bb9
[openwrt/svn-archive/archive.git] / target / linux / ar7 / patches-3.18 / 920-ar7part.patch
1 --- a/drivers/mtd/ar7part.c
2 +++ b/drivers/mtd/ar7part.c
3 @@ -30,11 +30,14 @@
4
5 #include <uapi/linux/magic.h>
6
7 +#include <asm/mach-ar7/prom.h>
8 +
9 #define AR7_PARTS 4
10 #define ROOT_OFFSET 0xe0000
11
12 #define LOADER_MAGIC1 le32_to_cpu(0xfeedfa42)
13 #define LOADER_MAGIC2 le32_to_cpu(0xfeed1281)
14 +#define LOADER_MAGIC3 le32_to_cpu(0x434d4d4c)
15
16 struct ar7_bin_rec {
17 unsigned int checksum;
18 @@ -42,12 +45,16 @@ struct ar7_bin_rec {
19 unsigned int address;
20 };
21
22 +int create_titan_partitions(struct mtd_info *master,
23 + struct mtd_partition **pparts,
24 + struct mtd_part_parser_data *data);
25 +
26 static int create_mtd_partitions(struct mtd_info *master,
27 struct mtd_partition **pparts,
28 struct mtd_part_parser_data *data)
29 {
30 struct ar7_bin_rec header;
31 - unsigned int offset;
32 + unsigned int offset, mtd_start, mtd_end;
33 size_t len;
34 unsigned int pre_size = master->erasesize, post_size = 0;
35 unsigned int root_offset = ROOT_OFFSET;
36 @@ -55,6 +62,16 @@ static int create_mtd_partitions(struct
37 int retries = 10;
38 struct mtd_partition *ar7_parts;
39
40 + const char *prom_str = prom_getenv("ProductID");
41 + char mtd_name[] = "mtd1";
42 + if(prom_str &&
43 + (strcmp(prom_str, "CYWL")==0 ||
44 + strcmp(prom_str, "CYWM")==0 ||
45 + strcmp(prom_str, "CYLM")==0 ||
46 + strcmp(prom_str, "CYLL")==0)){
47 + return create_titan_partitions(master, pparts, data);
48 + }
49 +
50 ar7_parts = kzalloc(sizeof(*ar7_parts) * AR7_PARTS, GFP_KERNEL);
51 if (!ar7_parts)
52 return -ENOMEM;
53 @@ -83,34 +100,39 @@ static int create_mtd_partitions(struct
54
55 pre_size = offset;
56
57 - if (!ar7_parts[1].offset) {
58 - ar7_parts[1].offset = master->size - master->erasesize;
59 - post_size = master->erasesize;
60 - }
61 -
62 switch (header.checksum) {
63 - case LOADER_MAGIC1:
64 - while (header.length) {
65 - offset += sizeof(header) + header.length;
66 - mtd_read(master, offset, sizeof(header), &len,
67 - (uint8_t *)&header);
68 - }
69 - root_offset = offset + sizeof(header) + 4;
70 - break;
71 case LOADER_MAGIC2:
72 + for (retries = 0; retries <= 9; retries++) {
73 + mtd_name[3] = '0' + retries;
74 + prom_str = prom_getenv(mtd_name);
75 + if (prom_str == NULL)
76 + continue;
77 + sscanf(prom_str, "%i,%i", &mtd_start, &mtd_end);
78 + if (pre_size == (mtd_start & 0x1ffffff)) {
79 + ar7_parts[1].offset = mtd_end &= 0x1ffffff;
80 + ar7_parts[1].size = post_size = master->size - mtd_end;
81 + break;
82 + }
83 + }
84 + case LOADER_MAGIC1:
85 + root_offset = (header.checksum == LOADER_MAGIC1) ? 4 : 0;
86 while (header.length) {
87 offset += sizeof(header) + header.length;
88 mtd_read(master, offset, sizeof(header), &len,
89 (uint8_t *)&header);
90 }
91 - root_offset = offset + sizeof(header) + 4 + 0xff;
92 - root_offset &= ~(uint32_t)0xff;
93 + root_offset += offset + sizeof(header);
94 break;
95 default:
96 printk(KERN_WARNING "Unknown magic: %08x\n", header.checksum);
97 break;
98 }
99
100 + if (!ar7_parts[1].offset) {
101 + post_size = master->erasesize;
102 + ar7_parts[1].offset = master->size - post_size;
103 + }
104 +
105 mtd_read(master, root_offset, sizeof(header), &len, (u8 *)&header);
106 if (header.checksum != SQUASHFS_MAGIC) {
107 root_offset += master->erasesize - 1;
108 --- a/drivers/mtd/titanpart.c
109 +++ b/drivers/mtd/titanpart.c
110 @@ -149,7 +149,7 @@ static void titan_add_partition(char * e
111 }
112 int create_titan_partitions(struct mtd_info *master,
113 struct mtd_partition **pparts,
114 - unsigned long origin)
115 + struct mtd_part_parser_data *data)
116 {
117 struct nsp_img_hdr_head hdr;
118 struct nsp_img_hdr_section_info sect_info;