]> git.sur5r.net Git - u-boot/blobdiff - drivers/mtd/ubi/build.c
Merge branch 'next' of git://git.denx.de/u-boot-mpc83xx
[u-boot] / drivers / mtd / ubi / build.c
index 17cabb2ae9952f5be88c467d3feaf5c81f1a7b78..6d86c0b6bcfed229152f009701a4a228c14e51b4 100644 (file)
@@ -2,19 +2,7 @@
  * Copyright (c) International Business Machines Corp., 2006
  * Copyright (c) Nokia Corporation, 2007
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * SPDX-License-Identifier:    GPL-2.0+
  *
  * Author: Artem Bityutskiy (Битюцкий Артём),
  *         Frank Haverkamp
 #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 +464,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 +524,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 +776,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 +1033,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;
 }
@@ -1059,6 +1053,7 @@ void __exit ubi_exit(void)
        misc_deregister(&ubi_ctrl_cdev);
        class_remove_file(ubi_class, &ubi_version);
        class_destroy(ubi_class);
+       mtd_devs = 0;
 }
 module_exit(ubi_exit);