dm: core: fix devfdt_remap_addr_index()
[oweals/u-boot.git] / drivers / mtd / nand / mxc_nand_spl.c
index edc589e5b7012d650fc14db4e120d3c32db36651..6c03db8428f65d42fad0ec88cf879212c2da7033 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2009
  * Magnus Lilja <lilja.magnus@gmail.com>
@@ -7,21 +8,6 @@
  *
  * (C) Copyright 2006-2008
  * Stefan Roese, DENX Software Engineering, sr at denx.de.
- *
- * 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
  */
 
 #include <common.h>
@@ -245,7 +231,7 @@ static int nfc_read_page(unsigned int page_address, unsigned char *buf)
        nfc_nand_read_page(page_address);
 
        if (nfc_nand_check_ecc())
-               return -1;
+               return -EBADMSG;
 
        src = (u32 *)&nfc->main_area[0][0];
        dst = (u32 *)buf;
@@ -290,7 +276,7 @@ static int is_badblock(int pagenumber)
        return 0;
 }
 
-static int nand_load(unsigned int from, unsigned int size, unsigned char *buf)
+int nand_spl_load_image(uint32_t from, unsigned int size, void *buf)
 {
        int i;
        unsigned int page;
@@ -303,6 +289,7 @@ static int nand_load(unsigned int from, unsigned int size, unsigned char *buf)
        page = from / CONFIG_SYS_NAND_PAGE_SIZE;
        i = 0;
 
+       size = roundup(size, CONFIG_SYS_NAND_PAGE_SIZE);
        while (i < size / CONFIG_SYS_NAND_PAGE_SIZE) {
                if (nfc_read_page(page, buf) < 0)
                        return -1;
@@ -332,6 +319,7 @@ static int nand_load(unsigned int from, unsigned int size, unsigned char *buf)
        return 0;
 }
 
+#ifndef CONFIG_SPL_FRAMEWORK
 /*
  * The main entry for NAND booting. It's necessary that SDRAM is already
  * configured and available since this code loads the main U-Boot image
@@ -345,9 +333,10 @@ void nand_boot(void)
         * CONFIG_SYS_NAND_U_BOOT_OFFS and CONFIG_SYS_NAND_U_BOOT_SIZE must
         * be aligned to full pages
         */
-       if (!nand_load(CONFIG_SYS_NAND_U_BOOT_OFFS, CONFIG_SYS_NAND_U_BOOT_SIZE,
-                      (uchar *)CONFIG_SYS_NAND_U_BOOT_DST)) {
-               /* Copy from NAND successful, start U-boot */
+       if (!nand_spl_load_image(CONFIG_SYS_NAND_U_BOOT_OFFS,
+                       CONFIG_SYS_NAND_U_BOOT_SIZE,
+                       (uchar *)CONFIG_SYS_NAND_U_BOOT_DST)) {
+               /* Copy from NAND successful, start U-Boot */
                uboot = (void *)CONFIG_SYS_NAND_U_BOOT_START;
                uboot();
        } else {
@@ -355,3 +344,7 @@ void nand_boot(void)
                hang();
        }
 }
+#endif
+
+void nand_init(void) {}
+void nand_deselect(void) {}