示例#1
0
int cloner_init(struct cloner *cloner)
{
#ifdef CONFIG_JZ_NAND_MGR
	if(cloner->args->use_nand_mgr) {
		nand_probe_burner(&(cloner->args->PartInfo),
				&(cloner->args->nand_params[0]),
				cloner->args->nr_nand_args,
				cloner->args->nand_erase,cloner->args->offsets,cloner->args->nand_erase_count);
	}
#endif	/*CONFIG_JZ_NAND_MGR*/
#ifdef CONFIG_MTD_NAND_JZ
	if(cloner->args->use_nand_mtd) {
		mtd_nand_probe_burner(&cloner->args->MTDPartInfo,
				&cloner->args->nand_params,
				cloner->args->nr_nand_args,
				cloner->args->nand_erase,
				&cloner->spl_title,
				&cloner->spl_title_sz);
	}
#endif	/*CONFIG_JZ_NAND_MGR*/
#ifdef CONFIG_JZ_MMC
	if (cloner->args->use_mmc) {
		if (cloner->args->mmc_erase) {
			mmc_erase(cloner);
		}
	}
#endif	/*CONFIG_JZ_MMC*/

#ifdef CONFIG_JZ_SPI
#ifdef CONFIG_MTD_SPINAND
	if(cloner->args->use_spi_nand){
		ssi_rate = (&cloner->args->spi_args)->rate;
		printf("******** ssi_rate = %d oldrate = %d spi_erase = %d\n",ssi_rate,(&cloner->args->spi_args)->rate,cloner->args->spi_erase);
		get_burner_nandinfo(cloner,&nand_param_from_burner);
		mtd_spinand_probe_burner(&(cloner->args->spi_erase),&nand_param_from_burner);
	}
#endif

	if(cloner->args->use_spi_nor){
		if (cloner->args->spi_erase == SPI_ERASE_PART) {
			spi_erase(cloner);
		}
		printf("cloner->args->spi_args.rate:%d\n",cloner->args->spi_args.rate);
	}
#endif
#if CONFIG_MTD_SFCNAND

	if(cloner->args->use_sfc_nand){
		ssi_rate = (&cloner->args->spi_args)->rate;
		get_burner_nandinfo(cloner,&nand_param_from_burner);
		mtd_sfcnand_probe_burner(&(cloner->args->spi_erase),cloner->args->spi_args.sfc_quad_mode,&nand_param_from_burner);
	}
#endif
#ifdef CONFIG_JZ_SFC
	if(cloner->args->use_sfc_nor){
		get_norflash_params_from_burner((unsigned char *)cloner->args + sizeof(struct arguments));
		if (cloner->args->spi_erase == SPI_ERASE_PART) {
			sfc_erase(cloner);
		}
		printf("cloner->args->spi_args.rate:%d\n",cloner->args->spi_args.rate);
	}
#endif
	return 0;
}
示例#2
0
/*
 *  Erase the flash device(s) addressed.
 */
int
fl_erase_device(void *base, int size, int verbose)
{
	struct fl_map *map;
	struct fl_device *dev;
	int mask, ok, block;
	int timeout;

	if(tgt_flashwrite_enable() == 0) {
		printf("Flash can't be write enabled\n");
		return(-2);	/* Flash can't be write enabled */
	}

	dev = fl_devident(base, &map);
	if(dev == NULL) {
		printf("No flash found at %x\n",(u_int32_t)base);
		return(-3);	/* No flash device found at address */
	}

	/*
	 * Sanity checks!
	 */
	if(size == -1 && (int)base == map->fl_map_base) {
		size = map->fl_map_size;	/* Entire flash */
	}

        if(dev->fl_varsecsize != NULL) {
                int offset = (int)(base - map->fl_map_base) + map->fl_map_offset;
                int totalsize;
		printf("offset=%x,base=%x\n",offset,map->fl_map_base);

                for(block=0, totalsize=0; totalsize < offset; block++) {
                        totalsize += dev->fl_varsecsize[block] * map->fl_map_chips;
                }

                mask = ((dev->fl_varsecsize[block] * map->fl_map_width / map->fl_map_chips) - 1);
                if((int)base & mask) {
                        size += (int)base & mask;
                        base = (void *)((int)base & ~mask);
                } else if((size + ((int)base - map->fl_map_base)) > map->fl_map_size) {
                        return(-4);	/* End beyound end of flash */
                }
                base -= map->fl_map_base;

        } else {
                mask = ((dev->fl_secsize * map->fl_map_width / map->fl_map_chips) - 1);
                if((int)base & mask) {
                        size += (int)base & mask;
                        base = (void *)((int)base & ~mask);
                } else if((size + ((int)base - map->fl_map_base)) > map->fl_map_size) {
                        return(-4);	/* End beyound end of flash */
                }

                base -= map->fl_map_base;
                block = (int)base / map->fl_map_chips / dev->fl_secsize;
                size = (size + mask) & ~mask; /* Round up to catch entire flash */
        }
        
        tgt_flashwrite_enable();
        fl_write_protect_unlock(map, dev, 0);/* Disable write protection of SST49LF040B/SST49LF008A */
        
	while(size > 0) {
		int boffs = (int)base;
#if 0
		if(size == map->fl_map_size &&
			dev->fl_cap & (FL_CAP_DE|FL_CAP_A7)) {
			/*
			 * Erase entire devices using the BULK erase feature
			 */
			if(verbose) {
				printf("Erasing all FLASH blocks. ");
			}

			(*dev->functions->erase_chip)(map, dev);

			size = 0;
		}
		else {
#endif
			/*
			 * Not entire flash or no BULK erase feature. We
			 * use sector/block erase.
			 */
			if(verbose) {
				printf("\rErasing FLASH block %3d      \b\b\b\b\b", block);
			}

			if((*dev->functions->erase_sector)(map, dev, boffs) != 0) {

				printf("\nError: Failed to enter erase mode\n");
				(*dev->functions->erase_suspend)(map, dev);
				(*dev->functions->reset)(map, dev);
				return(-4);
			}

                        if(dev->fl_varsecsize != NULL) {
                                base += dev->fl_varsecsize[block] * map->fl_map_chips;
                                size -= dev->fl_varsecsize[block] * map->fl_map_chips;
                                block++;
                        } else {
                                base += dev->fl_secsize * map->fl_map_chips;
                                size -= dev->fl_secsize * map->fl_map_chips;
                                block++;
                        }
//		}

		delay(1000);
		for(timeout = 0 ;
		    ((ok = (*dev->functions->isbusy)(map, dev, 0xffffffff, boffs, TRUE)) == 1)
				&& (timeout < PFLASH_MAX_TIMEOUT); timeout++) {
				delay(1000);
			if(verbose) {
				dotik(256, 0);
			}
		}
		delay(1000);

		if(!(timeout < PFLASH_MAX_TIMEOUT)) {
			(*dev->functions->erase_suspend)(map, dev);
		}
		(*dev->functions->reset)(map, dev);

		if(verbose) {
			if(!(timeout < PFLASH_MAX_TIMEOUT)) {
/* XXX if timed out what should really happen here? This doesn't look right. */
				printf("\b\b, command timed out!\n");
			} else {
				printf("\b Done.\n");
			}
		}
	}

	tgt_flashwrite_disable();
    fl_write_protect_lock(map, dev, 0);/* Enable write protection of SST49LF040B/SST49LF008A */
	return(ok);
}



int fl_program(void *fl_base, void *data_base, int data_size, int verbose)
{
        char *nvrambuf;
        char *nvramsecbuf;
	    char *nvram;
		int offs,count,left;
		struct fl_device *dev=fl_devident(fl_base,0);
		int nvram_size=dev->fl_secsize;

	nvramsecbuf = (char *)malloc(nvram_size);
	if(nvramsecbuf == 0) {
		printf("Warning! Unable to malloc nvrambuffer!\n");
		return(-1);
	}
      nvram = fl_base;
	  left = data_size;
	  while(left)
	  {

		offs = (int)nvram &(nvram_size - 1);
        nvram  = (int)nvram & ~(nvram_size - 1);
		count = min(nvram_size-offs,left);
		 

        memcpy(nvramsecbuf, nvram, nvram_size);		
		nvrambuf = nvramsecbuf + offs;
		memcpy(nvrambuf,data_base,count);
#ifdef NVRAM_IN_FLASH
#ifndef LS3B_SPI_BOOT        
		if(fl_erase_device(nvram, nvram_size, verbose)) {
		printf("Error! Nvram erase failed!\n");
		free(nvramsecbuf);
                return(0);
        }
        
		if(fl_program_device(nvram, nvramsecbuf, nvram_size, verbose)) {
		printf("Error! Nvram program failed!\n");
		free(nvramsecbuf);
                return(0);
        }
#else
        spi_erase( (unsigned long)(nvram)- tgt_flashmap()->fl_map_base, nvram_size);
		if( spi_program(nvramsecbuf, (unsigned long)(nvram)- tgt_flashmap()->fl_map_base, nvram_size, 0) ) { 
		     printf("Error! Nvram program failed!\n");
		     free(nvramsecbuf);
		     return(0);
		}
#endif
#endif

		data_base += count;
		nvram += nvram_size;
		left -= count;
		}
	free(nvramsecbuf);
        return 0;
}