#include <common.h>
#include <malloc.h>
#include <nand.h>
+#include <errno.h>
#include <linux/err.h>
#include <asm/io.h>
#include <asm/sizes.h>
-#include <asm/errno.h>
-#include <asm/arch/mxs_gpmi-regs.h>
-#include <asm/arch/mxs_gpmi-bch-regs.h>
+#include <asm/arch/regs-base.h>
+#include <asm/arch/regs-gpmi.h>
+#include <asm/arch/regs-bch.h>
#define FCB_START_BLOCK 0
#define NUM_FCB_BLOCKS 1
u32 bb_num[2040 / 4];
};
-#define BF_VAL(v, bf) (((v) & BM_##bf) >> BP_##bf)
+#define BF_VAL(v, bf) (((v) & bf##_MASK) >> bf##_OFFSET)
static nand_info_t *mtd = &nand_info[0];
return bb_mark_offset;
}
-static struct mx28_fcb *create_fcb(void *buf, int fw1_start_block, int fw2_start_block,
- size_t fw_size)
+static struct mx28_fcb *create_fcb(void *buf, int fw1_start_block,
+ int fw2_start_block, size_t fw_size)
{
- volatile void *gpmi_base = __ioremap(GPMI_BASE_ADDR, SZ_4K, 1);
- volatile void *bch_base = __ioremap(BCH_BASE_ADDR, SZ_4K, 1);
+ struct mx28_gpmi_regs *gpmi_base =
+ (struct mx28_gpmi_regs *)MXS_GPMI_BASE;
+ struct mx28_bch_regs *bch_base =
+ (struct mx28_bch_regs *)MXS_BCH_BASE;
u32 fl0, fl1;
u32 t0, t1;
int metadata_size;
return ERR_PTR(-ENOMEM);
}
- fl0 = readl(bch_base + HW_BCH_FLASH0LAYOUT0);
- fl1 = readl(bch_base + HW_BCH_FLASH0LAYOUT1);
- t0 = readl(gpmi_base + HW_GPMI_TIMING0);
- t1 = readl(gpmi_base + HW_GPMI_TIMING1);
+ fl0 = readl(&bch_base->hw_bch_flash0layout0);
+ fl1 = readl(&bch_base->hw_bch_flash0layout1);
+ t0 = readl(&gpmi_base->hw_gpmi_timing0);
+ t1 = readl(&gpmi_base->hw_gpmi_timing1);
- metadata_size = BF_VAL(fl0, BCH_FLASH0LAYOUT0_META_SIZE);
+ metadata_size = BF_VAL(fl0, BCH_FLASHLAYOUT0_META_SIZE);
fcb = buf + ALIGN(metadata_size, 4);
fcb_offs = (void *)fcb - buf;
fcb->total_page_size = mtd->writesize + mtd->oobsize;
fcb->sectors_per_block = mtd->erasesize / mtd->writesize;
- fcb->ecc_block0_type = BF_VAL(fl0, BCH_FLASH0LAYOUT0_ECC0);
- fcb->ecc_block0_size = BF_VAL(fl0, BCH_FLASH0LAYOUT0_DATA0_SIZE);
- fcb->ecc_blockn_type = BF_VAL(fl1, BCH_FLASH0LAYOUT1_ECCN);
- fcb->ecc_blockn_size = BF_VAL(fl1, BCH_FLASH0LAYOUT1_DATAN_SIZE);
+ fcb->ecc_block0_type = BF_VAL(fl0, BCH_FLASHLAYOUT0_ECC0);
+ fcb->ecc_block0_size = BF_VAL(fl0, BCH_FLASHLAYOUT0_DATA0_SIZE);
+ fcb->ecc_blockn_type = BF_VAL(fl1, BCH_FLASHLAYOUT1_ECCN);
+ fcb->ecc_blockn_size = BF_VAL(fl1, BCH_FLASHLAYOUT1_DATAN_SIZE);
- fcb->metadata_size = BF_VAL(fl0, BCH_FLASH0LAYOUT0_META_SIZE);
- fcb->ecc_blocks_per_page = BF_VAL(fl0, BCH_FLASH0LAYOUT0_NBLOCKS);
- fcb->bch_mode = readl(bch_base + HW_BCH_MODE);
+ fcb->metadata_size = BF_VAL(fl0, BCH_FLASHLAYOUT0_META_SIZE);
+ fcb->ecc_blocks_per_page = BF_VAL(fl0, BCH_FLASHLAYOUT0_NBLOCKS);
+ fcb->bch_mode = readl(&bch_base->hw_bch_mode);
/*
fcb->boot_patch = 0;
fcb->patch_sectors = 0;
}
chip->select_chip(mtd, 0);
chip->cmdfunc(mtd, NAND_CMD_READ0, 0x00, page);
- ret = chip->ecc.read_page_raw(mtd, chip, buf);
+ ret = chip->ecc.read_page_raw(mtd, chip, buf, page);
if (ret) {
printf("Failed to read FCB from page %u: %d\n", page, ret);
return ret;
} \
} while (0)
-int do_update(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+#ifndef CONFIG_ENV_OFFSET_REDUND
+#define TOTAL_ENV_SIZE CONFIG_ENV_SIZE
+#else
+#define TOTAL_ENV_SIZE (CONFIG_ENV_SIZE * 2)
+#endif
+
+int do_update(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
int ret;
int block;
unsigned long mtd_num_blocks = mtd->size / mtd->erasesize;
unsigned long env_start_block = CONFIG_ENV_OFFSET / mtd->erasesize;
unsigned long env_end_block = env_start_block +
- DIV_ROUND_UP(CONFIG_ENV_SIZE, mtd->erasesize) - 1;
+ DIV_ROUND_UP(TOTAL_ENV_SIZE, mtd->erasesize) - 1;
int optind;
int fw1_set = 0;
int fw2_set = 0;
extra_blocks * mtd->erasesize;
erase_opts.quiet = 1;
- printf("Erasing flash @ %08lx..%08lx\n", erase_opts.offset,
+ printf("Erasing flash @ %08llx..%08llx\n", erase_opts.offset,
erase_opts.offset + erase_opts.length - 1);
ret = nand_erase_opts(mtd, &erase_opts);
fcb->fw1_start_page * page_size,
fcb->fw1_start_page * page_size + size, addr);
ret = nand_write_skip_bad(mtd, fcb->fw1_start_page * page_size,
- &size, addr);
+ &size, addr, WITH_DROP_FFS);
if (ret) {
printf("Failed to program flash: %d\n", ret);
return ret;
printf("Programming redundant U-Boot image to block %lu\n",
fw2_start_block);
erase_opts.offset = fcb->fw2_start_page * page_size;
- printf("Erasing flash @ %08lx..%08lx\n", erase_opts.offset,
+ printf("Erasing flash @ %08llx..%08llx\n", erase_opts.offset,
erase_opts.offset + erase_opts.length - 1);
ret = nand_erase_opts(mtd, &erase_opts);
fcb->fw2_start_page * page_size,
fcb->fw2_start_page * page_size + size, addr);
ret = nand_write_skip_bad(mtd, fcb->fw2_start_page * page_size,
- &size, addr);
+ &size, addr, WITH_DROP_FFS);
if (ret) {
printf("Failed to program flash: %d\n", ret);
return ret;