Index: u-boot/drivers/nand/nand_bbt.c =================================================================== --- u-boot.orig/drivers/nand/nand_bbt.c 2007-02-25 14:57:29.000000000 +0100 +++ u-boot/drivers/nand/nand_bbt.c 2007-02-25 15:03:52.000000000 +0100 @@ -1065,6 +1065,15 @@ static char *part_names[] = { "u-boot", "u-boot_env", "kernel", "splash", "rootfs" }; + +static int skip_offs(const struct nand_chip *this, unsigned int offs) +{ + int block = (int) (offs >> (this->bbt_erase_shift - 1)); + u_int8_t bbt = (this->bbt[block >> 3] >> (block & 0x06)) & 0x03; + + return bbt == 3; +} + int nand_create_mtd_dynpart(struct mtd_info *mtd) { struct nand_chip *this = mtd->priv; @@ -1083,12 +1092,23 @@ unsigned int bb_delta = 0; unsigned int offs = 0; char mtdpart[32]; - for (offs = cur_offs; offs < cur_offs + part_size[part] + bb_delta; - offs += this->erasesize) { - int block = (int) (offs >> (this->bbt_erase_shift - 1)); - u_int8_t bbt = (this->bbt[block >> 3] >> (block & 0x06)) & 0x03; - if (bbt == 0x03) - bb_delta += this->erasesize; + + for (offs = cur_offs; + offs < cur_offs + part_size[part] + bb_delta; + offs += mtd->erasesize) { + if (skip_offs(this, offs)) + bb_delta += mtd->erasesize; + } + + /* + * Absorb bad blocks immediately following this partition also + * into the partition, in order to make next partition start + * with a good block. This simplifies handling of the + * environment partition. + */ + while (offs < this->chipsize && skip_offs(this, offs)) { + bb_delta += mtd->erasesize; + offs += mtd->erasesize; } if (cur_offs + part_size[part] + bb_delta > this->chipsize)