Merge branch 'master' of git://git.denx.de/u-boot-arm
[platform/kernel/u-boot.git] / drivers / mtd / ubi / build.c
index bdf75c9..2588822 100644 (file)
 #include <ubi_uboot.h>
 #include "ubi.h"
 
+#if (CONFIG_SYS_MALLOC_LEN < (512 << 10))
+#error Malloc area too small for UBI, increase CONFIG_SYS_MALLOC_LEN to >= 512k
+#endif
+
 /* Maximum length of the 'mtd=' parameter */
 #define MTD_PARAM_LEN_MAX 64
 
@@ -472,19 +476,19 @@ static int attach_by_scanning(struct ubi_device *ubi)
        if (err)
                goto out_si;
 
-       err = ubi_wl_init_scan(ubi, si);
+       err = ubi_eba_init_scan(ubi, si);
        if (err)
                goto out_vtbl;
 
-       err = ubi_eba_init_scan(ubi, si);
+       err = ubi_wl_init_scan(ubi, si);
        if (err)
-               goto out_wl;
+               goto out_eba;
 
        ubi_scan_destroy_si(si);
        return 0;
 
-out_wl:
-       ubi_wl_close(ubi);
+out_eba:
+       ubi_eba_close(ubi);
 out_vtbl:
        vfree(ubi->vtbl);
 out_si:
@@ -532,10 +536,10 @@ static int io_init(struct ubi_device *ubi)
         */
 
        ubi->peb_size   = ubi->mtd->erasesize;
-       ubi->peb_count  = ubi->mtd->size / ubi->mtd->erasesize;
+       ubi->peb_count  = mtd_div_by_eb(ubi->mtd->size, ubi->mtd);
        ubi->flash_size = ubi->mtd->size;
 
-       if (ubi->mtd->block_isbad && ubi->mtd->block_markbad)
+       if (mtd_can_have_bb(ubi->mtd))
                ubi->bad_allowed = 1;
 
        ubi->min_io_size = ubi->mtd->writesize;
@@ -784,19 +788,20 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
        if (err)
                goto out_free;
 
+       err = -ENOMEM;
        ubi->peb_buf1 = vmalloc(ubi->peb_size);
        if (!ubi->peb_buf1)
                goto out_free;
 
        ubi->peb_buf2 = vmalloc(ubi->peb_size);
        if (!ubi->peb_buf2)
-                goto out_free;
+               goto out_free;
 
 #ifdef CONFIG_MTD_UBI_DEBUG
        mutex_init(&ubi->dbg_buf_mutex);
        ubi->dbg_peb_buf = vmalloc(ubi->peb_size);
        if (!ubi->dbg_peb_buf)
-                goto out_free;
+               goto out_free;
 #endif
 
        err = attach_by_scanning(ubi);
@@ -1040,6 +1045,7 @@ out_version:
 out_class:
        class_destroy(ubi_class);
 out:
+       mtd_devs = 0;
        ubi_err("UBI error: cannot initialize UBI, error %d", err);
        return err;
 }