Beispiel #1
0
unsigned long flash_init(void)
{
	int i;
	unsigned long size_b0, base_b0;
	unsigned long size_b1;

	/* Init: no FLASHes known */
	for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i)
		flash_info[i].flash_id = FLASH_UNKNOWN;

	/* Get Size of Boot and Main Flashes */
	size_b0 = flash_get_size((vu_long *) FLASH_BASE0_PRELIM,
			       &flash_info[0]);
	if (flash_info[0].flash_id == FLASH_UNKNOWN) {
		printf("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
			size_b0, size_b0 << 20);
		return 0;
	}
	size_b1 =
		flash_get_size((vu_long *) FLASH_BASE1_PRELIM,
			       &flash_info[1]);
	if (flash_info[1].flash_id == FLASH_UNKNOWN) {
		printf("## Unknown FLASH on Bank 1 - Size = 0x%08lx = %ld MB\n",
			size_b1, size_b1 << 20);
		return 0;
	}

	/* Calculate base addresses */
	base_b0 = -size_b0;

	/* Setup offsets for Boot Flash */
	flash_get_offsets(base_b0, &flash_info[0]);

	/* Protect board level data */
	(void) flash_protect(FLAG_PROTECT_SET,
			     base_b0,
			     flash_info[0].start[1] - 1, &flash_info[0]);

	/* Monitor protection ON by default */
	(void) flash_protect(FLAG_PROTECT_SET,
			     base_b0 + size_b0 - monitor_flash_len,
			     base_b0 + size_b0 - 1, &flash_info[0]);

	/* Protect the FPGA image */
	(void) flash_protect(FLAG_PROTECT_SET,
			     FLASH_BASE1_PRELIM,
			     FLASH_BASE1_PRELIM + CONFIG_SYS_FPGA_IMAGE_LEN -
			     1, &flash_info[1]);

	/* Protect the default boot image */
	(void) flash_protect(FLAG_PROTECT_SET,
			     FLASH_BASE1_PRELIM + CONFIG_SYS_FPGA_IMAGE_LEN,
			     FLASH_BASE1_PRELIM + CONFIG_SYS_FPGA_IMAGE_LEN +
			     0x600000 - 1, &flash_info[1]);

	/* Setup offsets for Main Flash */
	flash_get_offsets(FLASH_BASE1_PRELIM, &flash_info[1]);

	return size_b0 + size_b1;
}
unsigned long flash_init(void)
{
	unsigned long size_b0, size_b1, size_b2;
	int i;

	size_b0 = size_b1 = size_b2 = 0;
#ifdef DEBUG
	printf("Flash Memory Start 0x%x\n", CONFIG_SYS_FLASH_BASE);
	printf("Memory Map for the Flash\n");
	printf("0x20000000 - 0x200FFFFF Flash A Primary (1MB)\n");
	printf("0x20100000 - 0x201FFFFF Flash B Primary (1MB)\n");
	printf("0x20200000 - 0x2020FFFF Flash A Secondary (64KB)\n");
	printf("0x20280000 - 0x2028FFFF Flash B Secondary (64KB)\n");
	printf("Please type command flinfo for information on Sectors \n");
#endif
	for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
		flash_info[i].flash_id = FLASH_UNKNOWN;
	}

	size_b0 = flash_get_size(CONFIG_SYS_FLASH0_BASE, &flash_info[0], 0);
	size_b1 = flash_get_size(CONFIG_SYS_FLASH0_BASE, &flash_info[1], 1);
	size_b2 = flash_get_size(CONFIG_SYS_FLASH0_BASE, &flash_info[2], 2);

	if (flash_info[0].flash_id == FLASH_UNKNOWN || size_b0 == 0) {
		printf("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
		       size_b0, size_b0 >> 20);
	}
Beispiel #3
0
unsigned long flash_init (void)
{
    unsigned long size1, size2;
    int i;

    /* Init: no FLASHes known */
    for (i=0; i<CONFIG_SYS_MAX_FLASH_BANKS; ++i)
    {
	flash_info[i].flash_id = FLASH_UNKNOWN;
    }

    /* initialise 1st flash */
    size1 = flash_get_size((vu_long *)FLASH_BASE0_PRELIM, &flash_info[0]);

    if (flash_info[0].flash_id == FLASH_UNKNOWN)
    {
	printf ("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
	    size1, size1<<20);
    }

    /* initialise 2nd flash */
    size2 = flash_get_size((vu_long *)FLASH_BASE1_PRELIM, &flash_info[1]);

    if (flash_info[1].flash_id == FLASH_UNKNOWN)
    {
	printf ("## Unknown FLASH on Bank 1 - Size = 0x%08lx = %ld MB\n",
	    size2, size2<<20);
    }

    /* monitor protection ON by default */
    if (size1 == 512*1024)
    {
	(void)flash_protect(FLAG_PROTECT_SET,
		FLASH_BASE0_PRELIM,
		FLASH_BASE0_PRELIM+monitor_flash_len-1,
		&flash_info[0]);
    }
    if (size2 == 512*1024)
    {
	(void)flash_protect(FLAG_PROTECT_SET,
		FLASH_BASE1_PRELIM,
		FLASH_BASE1_PRELIM+monitor_flash_len-1,
		&flash_info[1]);
    }
    if (size2 == 4*1024*1024)
    {
	(void)flash_protect(FLAG_PROTECT_SET,
		CONFIG_SYS_FLASH_BASE,
		CONFIG_SYS_FLASH_BASE+monitor_flash_len-1,
		&flash_info[1]);
    }

    return (size1 + size2);
}
Beispiel #4
0
unsigned long flash_init(void)
{
	volatile immap_t *immap = (immap_t *) CFG_IMMR;
	volatile memctl8xx_t *memctl = &immap->im_memctl;
	unsigned long size;
	int i;

	/* Init: no FLASHes known */
	for (i = 0; i < CFG_MAX_FLASH_BANKS; ++i)
		flash_info[i].flash_id = FLASH_UNKNOWN;

	size = flash_get_size((vu_long *) FLASH_BASE0_PRELIM, &flash_info[0]);

	if (flash_info[0].flash_id == FLASH_UNKNOWN) {
		printf("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n", size, size << 20);
	}

	/* Remap FLASH according to real size */
	memctl->memc_or0 = CFG_OR_TIMING_FLASH | (-size & 0xFFFF8000);
	memctl->memc_br0 = (CFG_FLASH_BASE & BR_BA_MSK) | (memctl->memc_br0 & ~(BR_BA_MSK));

	/* Re-do sizing to get full correct info */
	size = flash_get_size((vu_long *) CFG_FLASH_BASE, &flash_info[0]);

	flash_get_offsets(CFG_FLASH_BASE, &flash_info[0]);

	/* monitor protection ON by default */
	flash_protect(FLAG_PROTECT_SET,
			CFG_FLASH_BASE, CFG_FLASH_BASE + monitor_flash_len - 1,
			&flash_info[0]);

	flash_protect ( FLAG_PROTECT_SET,
			CFG_ENV_ADDR,
			CFG_ENV_ADDR + CFG_ENV_SIZE - 1,
			&flash_info[0]);

#ifdef CFG_ENV_ADDR_REDUND
	flash_protect ( FLAG_PROTECT_SET,
			CFG_ENV_ADDR_REDUND,
			CFG_ENV_ADDR_REDUND + CFG_ENV_SIZE_REDUND - 1,
			&flash_info[0]);
#endif


	flash_info[0].size = size;

	return (size);
}
Beispiel #5
0
int FlashIAP::erase(uint32_t addr, uint32_t size)
{
    uint32_t current_sector_size;
    uint32_t flash_size = flash_get_size(&_flash);
    uint32_t flash_start_addr = flash_get_start_address(&_flash);
    uint32_t flash_end_addr = flash_start_addr + flash_size;
    uint32_t erase_end_addr = addr + size;

    if (erase_end_addr > flash_end_addr) {
        return -1;
    } else if (erase_end_addr < flash_end_addr){
        uint32_t following_sector_size = flash_get_sector_size(&_flash, erase_end_addr);
        if (!is_aligned(erase_end_addr, following_sector_size)) {
            return -1;
        }
    }

    int32_t ret = 0;
    _mutex->lock();
    while (size) {
        ret = flash_erase_sector(&_flash, addr);
        if (ret != 0) {
            ret = -1;
            break;
        }
        current_sector_size = flash_get_sector_size(&_flash, addr);
        size -= current_sector_size;
        addr += current_sector_size;
    }
    _mutex->unlock();
    return ret;
}
Beispiel #6
0
unsigned long flash_init(void)
{
	unsigned long size;
	int i;

	/* Init: no FLASHes known */
	for (i = 0; i < CFG_MAX_FLASH_BANKS; ++i)
		flash_info[i].flash_id = FLASH_UNKNOWN;

	size = flash_get_size((vu_long *)CFG_FLASH_BASE, &flash_info[0]);

#if 0
	/* monitor protection ON by default */
	flash_protect(FLAG_PROTECT_SET,
		CFG_FLASH_BASE, CFG_FLASH_BASE + monitor_flash_len - 1,
		&flash_info[0]);

	flash_protect(FLAG_PROTECT_SET,
		CFG_ENV_ADDR,
		CFG_ENV_ADDR + CFG_ENV_SIZE - 1,
		&flash_info[0]);

#ifdef CFG_ENV_ADDR_REDUND
	flash_protect(FLAG_PROTECT_SET,
		CFG_ENV_ADDR_REDUND,
		CFG_ENV_ADDR_REDUND + CFG_ENV_SIZE_REDUND - 1,
		&flash_info[0]);
#endif
#endif

	flash_info[0].size = size;

	return (size);
}
Beispiel #7
0
unsigned long flash_init (void)
{
	unsigned long size_b0;
	int i;

	/* Init: no FLASHes known */
	for (i=0; i<CFG_MAX_FLASH_BANKS; ++i) {
		flash_info[i].flash_id = FLASH_UNKNOWN;
	}

	/* Static FLASH Bank configuration here - FIXME XXX */

	size_b0 = flash_get_size((vu_long *)CFG_FLASH_BASE, &flash_info[0]);

	if (flash_info[0].flash_id == FLASH_UNKNOWN) {
		printf ("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
			size_b0, size_b0<<20);
	}

	/* Setup offsets */
	flash_get_offsets (-size_b0, &flash_info[0]);

	/* test-only: todo: Re-do sizing to get full correct info */

	/* Monitor protection ON by default */
	(void)flash_protect(FLAG_PROTECT_SET,
			    CFG_FLASH_BASE,
			    CFG_FLASH_BASE+CFG_MONITOR_LEN-1,
			    &flash_info[0]);

	flash_info[0].size = size_b0;

	return (size_b0);
}
Beispiel #8
0
/*-----------------------------------------------------------------------
 * flash_init()
 *
 * sets up flash_info and returns size of FLASH (bytes)
 */
unsigned long flash_init(void)
{
	unsigned long size = 0;
	int i = 0;
	extern void flash_preinit(void);
	extern void flash_afterinit(uint, ulong, ulong);

	ulong flashbase = CFG_FLASH_BASE;

	flash_preinit();

	/* There is only ONE FLASH device */
	memset(&flash_info[i], 0, sizeof(flash_info_t));
	flash_info[i].size = flash_get_size((FPW *) flashbase, &flash_info[i]);
	size += flash_info[i].size;

#if CFG_MONITOR_BASE >= CFG_FLASH_BASE
	/* monitor protection ON by default */
	flash_protect(FLAG_PROTECT_SET, CFG_MONITOR_BASE,
		      CFG_MONITOR_BASE + monitor_flash_len - 1,
		      flash_get_info(CFG_MONITOR_BASE));
#endif

#ifdef  CONFIG_ENV_IS_IN_FLASH
	/* ENV protection ON by default */
	flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR,
		      CONFIG_ENV_ADDR + CONFIG_ENV_SIZE - 1,
		      flash_get_info(CONFIG_ENV_ADDR));
#endif

	flash_afterinit(i, flash_info[i].start[0], flash_info[i].size);
	return size ? size : 1;
}
Beispiel #9
0
unsigned long
flash_init(void)
{
	int i;
	ulong size = 0;

	for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; i++) {
		switch (i) {
		case 0:
			flash_get_size((FPW *) PHYS_FLASH_1, &flash_info[i]);
			flash_get_offsets(PHYS_FLASH_1, &flash_info[i]);
			break;
		default:
			panic("configured too many flash banks!\n");
			break;
		}
		size += flash_info[i].size;
	}

	/* Protect monitor and environment sectors
	 */
	flash_protect(FLAG_PROTECT_SET,
		      CONFIG_SYS_FLASH_BASE,
		      CONFIG_SYS_FLASH_BASE + monitor_flash_len - 1, &flash_info[0]);

	flash_protect(FLAG_PROTECT_SET,
		      CONFIG_ENV_ADDR,
		      CONFIG_ENV_ADDR + CONFIG_ENV_SIZE - 1, &flash_info[0]);

	return size;
}
Beispiel #10
0
unsigned long flash_init (void)
{
	unsigned long size_b0;
	int i;
	uint pbcr;
	unsigned long base_b0;
	int size_val = 0;

	/* Init: no FLASHes known */
	for (i=0; i<CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
		flash_info[i].flash_id = FLASH_UNKNOWN;
	}

	/* Static FLASH Bank configuration here - FIXME XXX */

	size_b0 = flash_get_size((vu_long *)FLASH_BASE0_PRELIM, &flash_info[0]);

	if (flash_info[0].flash_id == FLASH_UNKNOWN) {
		printf ("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
			size_b0, size_b0<<20);
	}

	/* Setup offsets */
	flash_get_offsets (-size_b0, &flash_info[0]);

	/* Re-do sizing to get full correct info */
	mtdcr(EBC0_CFGADDR, PB0CR);
	pbcr = mfdcr(EBC0_CFGDATA);
	mtdcr(EBC0_CFGADDR, PB0CR);
	base_b0 = -size_b0;
	switch (size_b0) {
	case 1 << 20:
		size_val = 0;
		break;
	case 2 << 20:
		size_val = 1;
		break;
	case 4 << 20:
		size_val = 2;
		break;
	case 8 << 20:
		size_val = 3;
		break;
	case 16 << 20:
		size_val = 4;
		break;
	}
	pbcr = (pbcr & 0x0001ffff) | base_b0 | (size_val << 17);
	mtdcr(EBC0_CFGDATA, pbcr);

	/* Monitor protection ON by default */
	(void)flash_protect(FLAG_PROTECT_SET,
			    -CONFIG_SYS_MONITOR_LEN,
			    0xffffffff,
			    &flash_info[0]);

	flash_info[0].size = size_b0;

	return (size_b0);
}
Beispiel #11
0
int misc_init_r (void)
{
	/*
	 * Adjust flash start and offset to detected values
	 */
	gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
	gd->bd->bi_flashoffset = 0;

	/*
	 * Check if boot FLASH isn't max size
	 */
	if (gd->bd->bi_flashsize < (0 - CONFIG_SYS_FLASH0)) {
		set_lbc_or(0, gd->bd->bi_flashstart |
			   (CONFIG_SYS_OR0_PRELIM & 0x00007fff));
		set_lbc_br(0, gd->bd->bi_flashstart |
			   (CONFIG_SYS_BR0_PRELIM & 0x00007fff));

		/*
		 * Re-check to get correct base address
		 */
		flash_get_size(gd->bd->bi_flashstart, CONFIG_SYS_MAX_FLASH_BANKS - 1);
	}

	/*
	 * Check if only one FLASH bank is available
	 */
	if (gd->bd->bi_flashsize != CONFIG_SYS_MAX_FLASH_BANKS * (0 - CONFIG_SYS_FLASH0)) {
		set_lbc_or(1, 0);
		set_lbc_br(1, 0);

		/*
		 * Re-do flash protection upon new addresses
		 */
		flash_protect (FLAG_PROTECT_CLEAR,
			       gd->bd->bi_flashstart, 0xffffffff,
			       &flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);

		/* Monitor protection ON by default */
		flash_protect (FLAG_PROTECT_SET,
			       CONFIG_SYS_MONITOR_BASE, CONFIG_SYS_MONITOR_BASE + monitor_flash_len - 1,
			       &flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);

		/* Environment protection ON by default */
		flash_protect (FLAG_PROTECT_SET,
			       CONFIG_ENV_ADDR,
			       CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
			       &flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);

		/* Redundant environment protection ON by default */
		flash_protect (FLAG_PROTECT_SET,
			       CONFIG_ENV_ADDR_REDUND,
			       CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1,
			       &flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);
	}

	return 0;
}
int misc_init_r (void)
{
	volatile ccsr_lbc_t *memctl = (void *)(CFG_MPC85xx_LBC_ADDR);

	/*
	 * Adjust flash start and offset to detected values
	 */
	gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
	gd->bd->bi_flashoffset = 0;

	/*
	 * Check if boot FLASH isn't max size
	 */
	if (gd->bd->bi_flashsize < (0 - CFG_FLASH0)) {
		memctl->or0 = gd->bd->bi_flashstart | (CFG_OR0_PRELIM & 0x00007fff);
		memctl->br0 = gd->bd->bi_flashstart | (CFG_BR0_PRELIM & 0x00007fff);

		/*
		 * Re-check to get correct base address
		 */
		flash_get_size(gd->bd->bi_flashstart, CFG_MAX_FLASH_BANKS - 1);
	}

	/*
	 * Check if only one FLASH bank is available
	 */
	if (gd->bd->bi_flashsize != CFG_MAX_FLASH_BANKS * (0 - CFG_FLASH0)) {
		memctl->or1 = 0;
		memctl->br1 = 0;

		/*
		 * Re-do flash protection upon new addresses
		 */
		flash_protect (FLAG_PROTECT_CLEAR,
			       gd->bd->bi_flashstart, 0xffffffff,
			       &flash_info[CFG_MAX_FLASH_BANKS - 1]);

		/* Monitor protection ON by default */
		flash_protect (FLAG_PROTECT_SET,
			       CFG_MONITOR_BASE, CFG_MONITOR_BASE + monitor_flash_len - 1,
			       &flash_info[CFG_MAX_FLASH_BANKS - 1]);

		/* Environment protection ON by default */
		flash_protect (FLAG_PROTECT_SET,
			       CFG_ENV_ADDR,
			       CFG_ENV_ADDR + CFG_ENV_SECT_SIZE - 1,
			       &flash_info[CFG_MAX_FLASH_BANKS - 1]);

		/* Redundant environment protection ON by default */
		flash_protect (FLAG_PROTECT_SET,
			       CFG_ENV_ADDR_REDUND,
			       CFG_ENV_ADDR_REDUND + CFG_ENV_SIZE_REDUND - 1,
			       &flash_info[CFG_MAX_FLASH_BANKS - 1]);
	}

	return 0;
}
Beispiel #13
0
ulong flash_init (void)
{
	unsigned long total_b = 0;
	unsigned long size_b[CFG_MAX_FLASH_BANKS];
	int i;

	{
		vu_long * base_addr = (vu_long*)0x400;
		ulong temp;

		temp = *base_addr;
		*base_addr = 0x20764316;
		if (*base_addr != 0x20764316)
			nor_flash_base = 0;
		*base_addr = temp;
	}

	for (i = 0; i < CFG_MAX_FLASH_BANKS; i++) {
		flash_info[i].flash_id = FLASH_UNKNOWN;
		flash_info[i].sector_count = -1;
		flash_info[i].size = 0;

		/* call flash_get_size() to initialize sector address */
		size_b[i] = flash_get_size((vu_long *)nor_flash_base, &flash_info[i]);
		flash_info[i].size = size_b[i];
		if (flash_info[i].flash_id == FLASH_UNKNOWN) {
#ifdef FLASH_DEBUG
			printf("## Unknown FLASH on Bank %d - Size = 0x%08lx = %ld MB\n",
			       i, size_b[i], size_b[i] << 20);
#endif
			flash_info[i].sector_count = -1;
			flash_info[i].size = 0;
		}


		total_b += flash_info[i].size;
	}

#if 0	/* by scsuh. removed for simple usage */
	/* Monitor protection ON by default */
	(void)flash_protect(FLAG_PROTECT_SET, CFG_MONITOR_BASE,
			    CFG_MONITOR_BASE + CFG_MONITOR_LEN - 1,
			    &flash_info[0]);
#endif

#ifdef CFG_ENV_IS_IN_FLASH
	(void)flash_protect(FLAG_PROTECT_SET, CFG_ENV_ADDR,
			    CFG_ENV_ADDR + CFG_ENV_SECT_SIZE - 1,
			    &flash_info[0]);
	(void)flash_protect(FLAG_PROTECT_SET, CFG_ENV_ADDR_REDUND,
			    CFG_ENV_ADDR_REDUND + CFG_ENV_SECT_SIZE - 1,
			    &flash_info[0]);
#endif

	return total_b;
}
Beispiel #14
0
unsigned long flash_init(void)
{
	unsigned long total_b = 0;
	unsigned long size_b[CFG_MAX_FLASH_BANKS];
	unsigned short index = 0;
	int i;

	/* read FPGA base register FPGA_REG0 */

	DEBUGF("\n");
	DEBUGF("FLASH: Index: %d\n", index);

	/* Init: no FLASHes known */
	for (i = 0; i < CFG_MAX_FLASH_BANKS; ++i) {
		flash_info[i].flash_id = FLASH_UNKNOWN;
		flash_info[i].sector_count = -1;
		flash_info[i].size = 0;

		/* check whether the address is 0 */
		if (flash_addr_table[index][i] == 0) {
			continue;
		}

		/* call flash_get_size() to initialize sector address */
		size_b[i] = flash_get_size((vu_long *)
					   flash_addr_table[index][i],
					   &flash_info[i]);
		flash_info[i].size = size_b[i];
		if (flash_info[i].flash_id == FLASH_UNKNOWN) {
			printf("## Unknown FLASH on Bank %d - Size = 0x%08lx = %ld MB\n",
			       i, size_b[i], size_b[i] << 20);
			flash_info[i].sector_count = -1;
			flash_info[i].size = 0;
		}

		/* Monitor protection ON by default */
		(void)flash_protect(FLAG_PROTECT_SET, CFG_MONITOR_BASE,
				    CFG_MONITOR_BASE + CFG_MONITOR_LEN - 1,
				    &flash_info[2]);
#ifdef CONFIG_ENV_IS_IN_FLASH
		(void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR,
				    CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
				    &flash_info[2]);
		(void)flash_protect(FLAG_PROTECT_SET, CONFIG_ENV_ADDR_REDUND,
				    CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1,
				    &flash_info[2]);
#endif

		total_b += flash_info[i].size;
	}

	return total_b;
}
Beispiel #15
0
/*-----------------------------------------------------------------------
 */
unsigned long flash_init (void)
{
    volatile immap_t *immap = (immap_t *) CFG_IMMR;
    volatile memctl8xx_t *memctl = &immap->im_memctl;
    vu_long *bcsr = (vu_long *)BCSR_ADDR;
    unsigned long pd_size, total_size, bsize, or_am;
    int i;

    /* Init: no FLASHes known */
    for (i = 0; i < CFG_MAX_FLASH_BANKS; ++i) {
        flash_info[i].flash_id = FLASH_UNKNOWN;
        flash_info[i].size = 0;
        flash_info[i].sector_count = 0;
        flash_info[i].start[0] = 0xFFFFFFFF; /* For TFTP */
    }

    switch ((bcsr[2] & BCSR2_FLASH_PD_MASK) >> BCSR2_FLASH_PD_SHIFT) {
    case 2:
    case 4:
    case 6:
        pd_size = 0x800000;
        or_am = 0xFF800000;
        break;

    case 5:
    case 7:
        pd_size = 0x400000;
        or_am = 0xFFC00000;
        break;

    case 8:
        pd_size = 0x200000;
        or_am = 0xFFE00000;
        break;

    default:
        pd_size = 0;
        or_am = 0xFFE00000;
        printf("## Unsupported flash detected by BCSR: 0x%08X\n", bcsr[2]);
    }

    total_size = 0;
    for (i = 0; i < CFG_MAX_FLASH_BANKS && total_size < pd_size; ++i) {
        bsize = flash_get_size((vu_long *)(CFG_FLASH_BASE + total_size),
                               &flash_info[i]);

        if (flash_info[i].flash_id == FLASH_UNKNOWN) {
            printf ("## Unknown FLASH on Bank %d - Size = 0x%08lx = %ld MB\n",
                    i, bsize, bsize >> 20);
        }

        total_size += bsize;
    }
Beispiel #16
0
unsigned long flash_init (void)
{
	unsigned int i;
	unsigned long flash_size = 0;
	unsigned long bank_size;
	unsigned int bank = 0;

	/* Init: no FLASHes known */
	for (i=0; i < CFG_MAX_FLASH_BANKS; ++i) {
		flash_info[i].flash_id = FLASH_UNKNOWN;
		flash_info[i].sector_count = 0;
		flash_info[i].size = 0;
	}

	/* Initialise the BOOT Flash */
	if (bank == CFG_MAX_FLASH_BANKS) {
		puts ("Warning: not all Flashes are initialised !");
		return flash_size;
	}

	bank_size = flash_get_size (CFG_FLASH_BASE, flash_info + bank);
	if (bank_size) {
#if CFG_MONITOR_BASE >= CFG_FLASH_BASE && \
    CFG_MONITOR_BASE < CFG_FLASH_BASE + CFG_MAX_FLASH_SIZE
		/* monitor protection ON by default */
		flash_protect(FLAG_PROTECT_SET,
			      CFG_MONITOR_BASE,
			      CFG_MONITOR_BASE + monitor_flash_len - 1,
			      flash_info + bank);
#endif

#ifdef CFG_ENV_IS_IN_FLASH
		/* ENV protection ON by default */
		flash_protect(FLAG_PROTECT_SET,
			      CFG_ENV_ADDR,
			      CFG_ENV_ADDR + CFG_ENV_SECT_SIZE - 1,
			      flash_info + bank);
#endif

		/* HWC protection ON by default */
		flash_protect(FLAG_PROTECT_SET,
			      CFG_FLASH_BASE,
			      CFG_FLASH_BASE + 0x10000 - 1,
			      flash_info + bank);

		flash_size += bank_size;
		bank++;
	} else {
		puts ("Warning: the BOOT Flash is not initialised !");
	}

	return flash_size;
}
Beispiel #17
0
uint32_t flash_get_sector_size(const flash_t *obj, uint32_t address)
{
    (void)(obj);

    /* Test if passed address is in flash space. */
    if (address < flash_get_size(obj)) {
        return NRF_FICR->CODEPAGESIZE;
    }

    /* Something goes wrong, return invalid size error code. */
    return MBED_FLASH_INVALID_SIZE;
}
Beispiel #18
0
int FlashIAP::program(const void *buffer, uint32_t addr, uint32_t size)
{
    uint32_t page_size = get_page_size();
    uint32_t flash_size = flash_get_size(&_flash);
    uint32_t flash_start_addr = flash_get_start_address(&_flash);
    uint32_t chunk, prog_size;
    const uint8_t *buf = (uint8_t *) buffer;
    const uint8_t *prog_buf;

    // addr should be aligned to page size
    if (!is_aligned(addr, page_size) || (!buffer) ||
        ((addr + size) > (flash_start_addr + flash_size))) {
        return -1;
    }

    int ret = 0;
    _mutex->lock();
    while (size) {
        uint32_t current_sector_size = flash_get_sector_size(&_flash, addr);
        bool unaligned_src = (((size_t) buf / sizeof(uint32_t) * sizeof(uint32_t)) != (size_t) buf);
        chunk = std::min(current_sector_size - (addr % current_sector_size), size);
        // Need to use the internal page buffer in any of these two cases:
        // 1. Size is not page aligned
        // 2. Source buffer is not aligned to uint32_t. This is not supported by many targets (although
        //    the pointer they accept is of uint8_t).
        if (unaligned_src || (chunk < page_size)) {
            chunk = std::min(chunk, page_size);
            memcpy(_page_buf, buf, chunk);
            if (chunk < page_size) {
                memset(_page_buf + chunk, 0xFF, page_size - chunk);
            }
            prog_buf = _page_buf;
            prog_size = page_size;
        } else {
            chunk = chunk / page_size * page_size;
            prog_buf = buf;
            prog_size = chunk;
        }
        if (flash_program_page(&_flash, addr, prog_buf, prog_size)) {
            ret = -1;
            break;
        }
        size -= chunk;
        addr += chunk;
        buf += chunk;
    }
    _mutex->unlock();

    return ret;
}
unsigned long flash_init (void)
{
	unsigned int i;
	unsigned long flash_size = 0;

	flash_xd_nest = 0;

	flash_to_xd();

	/* Init: no FLASHes known */
	for (i=0; i<CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
		flash_info[i].flash_id = FLASH_UNKNOWN;
		flash_info[i].sector_count = 0;
		flash_info[i].size = 0;
	}

	DEBUGF("\n## Get flash size @ 0x%08x\n", CONFIG_SYS_FLASH_BASE);

	flash_size = flash_get_size (CONFIG_SYS_FLASH_BASE, flash_info);

	DEBUGF("## Flash bank size: %08lx\n", flash_size);

	if (flash_size) {
#if CONFIG_SYS_MONITOR_BASE >= CONFIG_SYS_FLASH_BASE && \
    CONFIG_SYS_MONITOR_BASE < CONFIG_SYS_FLASH_BASE + CONFIG_SYS_FLASH_MAX_SIZE
		/* monitor protection ON by default */
		flash_protect(FLAG_PROTECT_SET,
			      CONFIG_SYS_MONITOR_BASE,
			      CONFIG_SYS_MONITOR_BASE + monitor_flash_len - 1,
			      &flash_info[0]);
#endif

#ifdef CONFIG_ENV_IS_IN_FLASH
		/* ENV protection ON by default */
		flash_protect(FLAG_PROTECT_SET,
			      CONFIG_ENV_ADDR,
			      CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
			      &flash_info[0]);
#endif

	} else {
		puts ("Warning: the BOOT Flash is not initialised !");
	}

	flash_to_mem();

	return flash_size;
}
Beispiel #20
0
unsigned long flash_init(void)
{
	unsigned long size_b;
	int i;

	size_b = 0;
	for (i = 0; i < CFG_MAX_FLASH_BANKS; ++i) {
		flash_info[i].flash_id = FLASH_UNKNOWN;
	}

	size_b = flash_get_size(CFG_FLASH_BASE, &flash_info[0], 0);

	if (flash_info[0].flash_id == FLASH_UNKNOWN || size_b == 0) {
		printf("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
			size_b, size_b >> 20);
	}
Beispiel #21
0
/*-----------------------------------------------------------------------
 */
unsigned long flash_init (void)
{
	unsigned long size_b0 = 0;
	int i;

	/* Init: no FLASHes known */
	for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
		flash_info[i].flash_id = FLASH_UNKNOWN;
	}

	/* Static FLASH Bank configuration here (only one bank) */
	size_b0 = flash_get_size (CONFIG_SYS_FLASH_BASE, &flash_info[0]);
	if (flash_info[0].flash_id == FLASH_UNKNOWN || size_b0 == 0) {
		printf ("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
				size_b0, size_b0 >> 20);
	}
Beispiel #22
0
ulong flash_init(void)
{
	ulong size = 0;
	ulong fbase = 0;

	fbase = (ulong) CONFIG_SYS_FLASH_BASE;
	flash_get_size((FPWV *) fbase, &flash_info[0]);
	flash_get_offsets((ulong) fbase, &flash_info[0]);
	fbase += flash_info[0].size;
	size += flash_info[0].size;

	/* Protect monitor and environment sectors */
	flash_protect(FLAG_PROTECT_SET,
		      CONFIG_SYS_MONITOR_BASE,
		      CONFIG_SYS_MONITOR_BASE + monitor_flash_len - 1, &flash_info[0]);

	return size;
}
Beispiel #23
0
unsigned long flash_init (void)
{
    unsigned long size_b0;
    int i;
    uint pbcr;
    unsigned long base_b0;

    /* Init: no FLASHes known */
    for (i=0; i<CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
        flash_info[i].flash_id = FLASH_UNKNOWN;
    }

    /* Static FLASH Bank configuration here - FIXME XXX */

    size_b0 = flash_get_size((vu_long *)FLASH_BASE0_PRELIM, &flash_info[0]);

    if (flash_info[0].flash_id == FLASH_UNKNOWN) {
        printf ("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
                size_b0, size_b0<<20);
    }

    /* Setup offsets */
    flash_get_offsets (-size_b0, &flash_info[0]);

    /* Re-do sizing to get full correct info */
    mtdcr(EBC0_CFGADDR, PB0CR);
    pbcr = mfdcr(EBC0_CFGDATA);
    mtdcr(EBC0_CFGADDR, PB0CR);
    base_b0 = -size_b0;
    pbcr = (pbcr & 0x0001ffff) | base_b0 | (((size_b0/1024/1024)-1)<<17);
    mtdcr(EBC0_CFGDATA, pbcr);
    /*          printf("PB1CR = %x\n", pbcr); */

    /* Monitor protection ON by default */
    (void)flash_protect(FLAG_PROTECT_SET,
                        -monitor_flash_len,
                        0xffffffff,
                        &flash_info[0]);

    flash_info[0].size = size_b0;

    return (size_b0);
}
Beispiel #24
0
ulong flash_init(void)
{
	int i;
	ulong size = 0;
	ulong fbase = 0;

#if defined(CONFIG_SERIAL_FLASH) && defined(CONFIG_CF_DSPI)
	dspi_init();
#endif

	for (i = 0; i < CFG_MAX_FLASH_BANKS; i++) {
		memset(&flash_info[i], 0, sizeof(flash_info_t));

		switch (i) {
		case 0:
			fbase = (ulong) CFG_FLASH0_BASE;
			break;
		case 1:
			fbase = (ulong) CFG_FLASH1_BASE;
			break;
#if defined(CONFIG_SERIAL_FLASH) && defined(CONFIG_CF_DSPI)
		case 2:
			fbase = (ulong) CFG_FLASH2_BASE;
			break;
#endif
		}

		flash_get_size((FPWV *) fbase, &flash_info[i]);
		flash_get_offsets((ulong) fbase, &flash_info[i]);
		fbase += flash_info[i].size;
		size += flash_info[i].size;

		/* get the h/w and s/w protection status in sync */
		flash_sync_real_protect(&flash_info[i]);
	}

	/* Protect monitor and environment sectors */
	flash_protect(FLAG_PROTECT_SET,
		      CFG_MONITOR_BASE,
		      CFG_MONITOR_BASE + monitor_flash_len - 1, &flash_info[0]);

	return size;
}
Beispiel #25
0
unsigned long flash_init (void)
{
	volatile immap_t     *immap  = (immap_t *)CONFIG_SYS_IMMR;
	volatile memctl8xx_t *memctl = &immap->im_memctl;
	unsigned long size_b0;
	int i;

	/* Init: no FLASHes known */
	for (i=0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i)
		flash_info[i].flash_id = FLASH_UNKNOWN;

	/* Static FLASH Bank configuration here - FIXME XXX */

	size_b0 = flash_get_size((vu_long *)FLASH_BASE0_PRELIM, &flash_info[0]);

	if (flash_info[0].flash_id == FLASH_UNKNOWN) {
		printf ("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
			size_b0,
			size_b0 >> 20);
	}
Beispiel #26
0
unsigned long flash_init(void)
{
	unsigned long size;
	int i;

	/* Init: no FLASHes known */
	for (i=0; i<CONFIG_SYS_MAX_FLASH_BANKS; i++)
		flash_info[i].flash_id = FLASH_UNKNOWN;

	size = flash_get_size((vu_long *)FLASH_BASE0_PRELIM, &flash_info[0]);

	if (flash_info[0].flash_id == FLASH_UNKNOWN)
		printf ("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
			size, size<<20);

	/* Reconfigure CS0 to actual FLASH size */
	*IXP425_EXP_CS0 = (*IXP425_EXP_CS0 & ~0x00003C00) | ((ld(size) - 9) << 10);

	/* Monitor protection ON by default */
	flash_protect(FLAG_PROTECT_SET,
		      CONFIG_SYS_MONITOR_BASE, CONFIG_SYS_MONITOR_BASE + monitor_flash_len - 1,
		      &flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);

	/* Environment protection ON by default */
	flash_protect(FLAG_PROTECT_SET,
		      CONFIG_ENV_ADDR,
		      CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
		      &flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);

	/* Redundant environment protection ON by default */
	flash_protect(FLAG_PROTECT_SET,
		      CONFIG_ENV_ADDR_REDUND,
		      CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SIZE_REDUND - 1,
		      &flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);

	flash_info[0].size = size;

	return size;
}
Beispiel #27
0
/*-----------------------------------------------------------------------
 */
unsigned long flash_init(void)
{
	unsigned long size;
	int i;
	unsigned long address;

	/* The flash is positioned back to back, with the demultiplexing of the chip
	 * based on the A24 address line.
	 *
	 */

	address = CONFIG_SYS_FLASH_BASE;
	size = 0;

	/* Init: no FLASHes known */
	for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
		flash_info[i].flash_id = FLASH_UNKNOWN;
		size += flash_info[i].size = flash_get_size(address, i);
		address += CONFIG_SYS_FLASH_INCREMENT;
		if (flash_info[i].flash_id == FLASH_UNKNOWN) {
			printf
			    ("## Unknown FLASH on Bank %d - Size = 0x%08lx = %ld MB\n",
			     i, flash_info[0].size, flash_info[i].size << 20);
		}
	}

#if 0				/* test-only */
	/* Monitor protection ON by default */
#if (CONFIG_SYS_MONITOR_BASE >= CONFIG_SYS_FLASH_BASE)
	for (i = 0;
	     flash_info[0].start[i] < CONFIG_SYS_MONITOR_BASE + monitor_flash_len - 1;
	     i++)
		(void)flash_real_protect(&flash_info[0], i, 1);
#endif
#endif

	return (size);
}
Beispiel #28
0
unsigned long flash_init (void)
{
#ifdef __DEBUG_START_FROM_SRAM__
	return CONFIG_SYS_DUMMY_FLASH_SIZE;
#else
	unsigned long size_b0;
	int i;

	/* Init: no FLASHes known */
	for (i=0; i<CONFIG_SYS_MAX_FLASH_BANKS; ++i) {
		flash_info[i].flash_id = FLASH_UNKNOWN;
	}

	/* Static FLASH Bank configuration here - FIXME XXX */

	size_b0 = flash_get_size((vu_long *)CONFIG_SYS_FLASH_BASE, &flash_info[0]);

	if (flash_info[0].flash_id == FLASH_UNKNOWN) {
		printf ("## Unknown FLASH on Bank 0 - Size = 0x%08lx = %ld MB\n",
			size_b0, size_b0<<20);
	}

	/* Setup offsets */
	flash_get_offsets (0, &flash_info[0]);

	/* Monitor protection ON by default */
	(void)flash_protect(FLAG_PROTECT_SET,
			    -CONFIG_SYS_MONITOR_LEN,
			    0xffffffff,
			    &flash_info[0]);

	flash_info[0].size = size_b0;

	return (size_b0);
#endif
}
Beispiel #29
0
int misc_init_r (void)
{
    /*
     * Adjust flash start and offset to detected values
     */
    gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
    gd->bd->bi_flashoffset = 0;

    /*
     * Recalculate CS configuration if second FLASH bank is available
     */
    if (flash_info[0].size > 0) {
        set_lbc_or(1, ((-flash_info[0].size) & 0xffff8000) |
                   (CONFIG_SYS_OR1_PRELIM & 0x00007fff));
        set_lbc_br(1, gd->bd->bi_flashstart |
                   (CONFIG_SYS_BR1_PRELIM & 0x00007fff));
        /*
         * Re-check to get correct base address for bank 1
         */
        flash_get_size (gd->bd->bi_flashstart, 0);
    } else {
        set_lbc_or(1, 0);
        set_lbc_br(1, 0);
    }

    /*
     *  If bank 1 is equipped, bank 0 is mapped after bank 1
     */
    set_lbc_or(0, ((-flash_info[1].size) & 0xffff8000) |
               (CONFIG_SYS_OR0_PRELIM & 0x00007fff));
    set_lbc_br(0, (gd->bd->bi_flashstart + flash_info[0].size) |
               (CONFIG_SYS_BR0_PRELIM & 0x00007fff));

    /*
     * Re-check to get correct base address for bank 0
     */
    flash_get_size (gd->bd->bi_flashstart + flash_info[0].size, 1);

    /*
     * Re-do flash protection upon new addresses
     */
    flash_protect (FLAG_PROTECT_CLEAR,
                   gd->bd->bi_flashstart, 0xffffffff,
                   &flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);

    /* Monitor protection ON by default */
    flash_protect (FLAG_PROTECT_SET,
                   CONFIG_SYS_MONITOR_BASE, 0xffffffff,
                   &flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);

    /* Environment protection ON by default */
    flash_protect (FLAG_PROTECT_SET,
                   CONFIG_ENV_ADDR,
                   CONFIG_ENV_ADDR + CONFIG_ENV_SECT_SIZE - 1,
                   &flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);

#ifdef CONFIG_ENV_ADDR_REDUND
    /* Redundant environment protection ON by default */
    flash_protect (FLAG_PROTECT_SET,
                   CONFIG_ENV_ADDR_REDUND,
                   CONFIG_ENV_ADDR_REDUND + CONFIG_ENV_SECT_SIZE - 1,
                   &flash_info[CONFIG_SYS_MAX_FLASH_BANKS - 1]);
#endif

    return 0;
}
Beispiel #30
0
uint32_t FlashIAP::get_flash_size() const
{
    return flash_get_size(&_flash);
}