redboot.c - adds implicit creation of boardconfig partition
[librecmc/librecmc.git] / target / linux / generic-2.6 / patches-2.6.26 / 071-redboot_boardconfig.patch
1 Index: linux-2.6.26.2/drivers/mtd/redboot.c
2 ===================================================================
3 --- linux-2.6.26.2.orig/drivers/mtd/redboot.c   2008-08-19 19:32:17.000000000 +0200
4 +++ linux-2.6.26.2/drivers/mtd/redboot.c        2008-08-19 19:47:34.000000000 +0200
5 @@ -13,6 +13,8 @@
6  #include <linux/mtd/mtd.h>
7  #include <linux/mtd/partitions.h>
8  
9 +#define BOARD_CONFIG_PART              "boardconfig"
10 +
11  struct fis_image_desc {
12      unsigned char name[16];      // Null terminated name
13      uint32_t     flash_base;    // Address within FLASH of image
14 @@ -43,6 +45,7 @@
15                               struct mtd_partition **pparts,
16                               unsigned long fis_origin)
17  {
18 +       unsigned long max_offset = 0;
19         int nrparts = 0;
20         struct fis_image_desc *buf;
21         struct mtd_partition *parts;
22 @@ -217,14 +220,14 @@
23                 }
24         }
25  #endif
26 -       parts = kzalloc(sizeof(*parts)*nrparts + nulllen + namelen, GFP_KERNEL);
27 +       parts = kzalloc(sizeof(*parts) * (nrparts + 1) + nulllen + namelen + sizeof(BOARD_CONFIG_PART), GFP_KERNEL);
28  
29         if (!parts) {
30                 ret = -ENOMEM;
31                 goto out;
32         }
33  
34 -       nullname = (char *)&parts[nrparts];
35 +       nullname = (char *)&parts[nrparts + 1];
36  #ifdef CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED
37         if (nulllen > 0) {
38                 strcpy(nullname, nullstring);
39 @@ -243,6 +246,8 @@
40         }
41  #endif
42         for ( ; i<nrparts; i++) {
43 +               if(max_offset < buf[i].flash_base + buf[i].size)
44 +                       max_offset = buf[i].flash_base + buf[i].size;
45                 parts[i].size = fl->img->size;
46                 parts[i].offset = fl->img->flash_base;
47                 parts[i].name = names;
48 @@ -276,6 +281,14 @@
49                 fl = fl->next;
50                 kfree(tmp_fl);
51         }
52 +       if(master->size - max_offset >= master->erasesize)
53 +       {
54 +               parts[nrparts].size = master->size - max_offset;
55 +               parts[nrparts].offset = max_offset;
56 +               parts[nrparts].name = names;
57 +               strcpy(names, BOARD_CONFIG_PART);
58 +               nrparts++;
59 +       }
60         ret = nrparts;
61         *pparts = parts;
62   out: