enigma2 20150309 -> 20150316
[opendreambox.git] / meta-bsp / common / recipes / linux / linux-dreambox-3.2 / 0009-fixed-partition-is-ubi-maintained-check.patch
1 From 43ab2e3df470c90602974bb552a22e2b56c408f4 Mon Sep 17 00:00:00 2001
2 From: Andreas Monzner <andreas.monzner@dream-property.net>
3 Date: Wed, 31 Jul 2013 23:47:23 +0200
4 Subject: [PATCH] fixed partition is ubi maintained check
5
6 ---
7  drivers/mtd/brcmnand/brcmnand_base.c | 38 +++++++++++++++++++++++++++---------
8  1 file changed, 29 insertions(+), 9 deletions(-)
9
10 diff --git a/drivers/mtd/brcmnand/brcmnand_base.c b/drivers/mtd/brcmnand/brcmnand_base.c
11 index 00a9ed5..dff454a 100644
12 --- a/drivers/mtd/brcmnand/brcmnand_base.c
13 +++ b/drivers/mtd/brcmnand/brcmnand_base.c
14 @@ -4094,6 +4094,28 @@ if (oobarea) { printk("Read OOB: "); print_oobbuf(write_oob, 512); }
15  #define edu_write_verify(...) (0)
16  #endif
17  
18 +static int is_ubi_maintained(struct brcmnand_chip * chip, loff_t offset)
19 +{
20 +       int ret = 0;
21 +       int *num_parts = (int*)(chip+1);
22 +       if (*num_parts) {
23 +               struct mtd_partition **parts = (struct mtd_partition**)(num_parts+1);
24 +               struct mtd_partition *part = *parts;
25 +               int mtd_num = 0;
26 +               while (mtd_num < *num_parts) {
27 +                       if (offset >= part->offset && offset < (part->offset + part->size)) {
28 +                               struct mtd_info *mtd = get_mtd_device(NULL, mtd_num);
29 +                               if (IS_ERR(mtd))
30 +                                       return ret;
31 +                               ret |= (mtd->flags & (1<<31));
32 +                       }
33 +                       ++part;
34 +                       ++mtd_num;
35 +               }
36 +       }
37 +
38 +       return !!ret;
39 +}
40  
41  /**
42   * brcmnand_posted_write - [BrcmNAND Interface] Write a buffer to the flash cache
43 @@ -4173,7 +4195,7 @@ if (gdebug > 3) {printk("%s: oob=\n", __FUNCTION__); print_oobbuf(oobarea, 16);}
44                 else { // Need BBT
45  //printk("80 block mark bad\n");
46  #ifdef CONFIG_MTD_BRCMNAND_MARK_BADBLOCKS
47 -                       if (!(mtd->flags & (1<<31))) { // MTD device NOT maintained by UBI ?
48 +                       if (!is_ubi_maintained(chip, offset)) { // MTD device NOT maintained by UBI ?
49                                 printk(KERN_WARNING "%s: Marking bad block @%08x\n", __FUNCTION__, (unsigned int) offset);
50                                 ret = chip->block_markbad(mtd, offset);
51                                 ret = -EINVAL;
52 @@ -4554,7 +4576,7 @@ printk("****** Workaround, using OP_PROGRAM_PAGE instead of OP_PROGRAM_SPARE_ARE
53                 int ret;
54  
55  #ifdef CONFIG_MTD_BRCMNAND_MARK_BADBLOCKS
56 -               if (!(mtd->flags & (1<<31))) { // MTD device NOT maintained by UBI ?
57 +               if (!is_ubi_maintained(chip, offset)) { // MTD device NOT maintained by UBI ?
58                         printk(KERN_WARNING "%s: Marking bad block @%08x\n", __FUNCTION__, (unsigned int) offset);
59                         ret = chip->block_markbad(mtd, offset);
60                         return -EINVAL;
61 @@ -5672,9 +5694,7 @@ printk("-->%s, offset=%0llx, len=%08x\n", __FUNCTION__, from, len);}
62         brcmnand_release_device(mtd);
63  
64  #ifdef CONFIG_MTD_BRCMNAND_CORRECTABLE_ERR_HANDLING
65 -       if (mtd->flags & (1<<31))
66 -               ;
67 -       else if (unlikely(ret == -EUCLEAN && !atomic_read(&inrefresh))) {
68 +       if (unlikely(ret == -EUCLEAN && !atomic_read(&inrefresh) && !is_ubi_maintained(chip, from))) {
69                 atomic_inc(&inrefresh);
70                 if(brcmnand_refresh_blk(mtd, from) == 0) { 
71                         ret = 0; 
72 @@ -7312,9 +7332,7 @@ static int brcmnand_erase(struct mtd_info *mtd, struct erase_info *instr)
73                 mtd_erase_callback(instr);
74  
75  #ifdef CONFIG_MTD_BRCMNAND_CORRECTABLE_ERR_HANDLING
76 -               if (mtd->flags & (1<<31))
77 -                       ;
78 -               else if (chip->cet) {
79 +               if (chip->cet) {
80                         if (chip->cet->flags != BRCMNAND_CET_DISABLED && 
81                                         chip->cet->flags != BRCMNAND_CET_LAZY && allowbbt != 1) {
82                                 len = instr->state == MTD_ERASE_DONE ? instr->len : instr->fail_addr - instr->addr;
83 @@ -7327,7 +7345,9 @@ static int brcmnand_erase(struct mtd_info *mtd, struct erase_info *instr)
84                                                 addr = addr + block_size;
85                                                 continue;
86                                         }
87 -                                       if(brcmnand_cet_erasecallback(mtd, addr) < 0) {
88 +                                       if (is_ubi_maintained(chip, addr))
89 +                                               ;
90 +                                       else if(brcmnand_cet_erasecallback(mtd, addr) < 0) {
91                                                 printk(KERN_INFO "Error in CET erase callback, disabling CET\n");
92                                                 chip->cet->flags = BRCMNAND_CET_DISABLED;
93                                         }
94 -- 
95 1.8.3.2
96