示例#1
0
文件: sf.c 项目: koenkooi/u-boot
static int setup_flash_device(void)
{
#ifdef CONFIG_DM_SPI_FLASH
	struct udevice *new;
	int	ret;

	/* speed and mode will be read from DT */
	ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
				     0, 0, &new);
	if (ret) {
		set_default_env("!spi_flash_probe_bus_cs() failed");
		return ret;
	}

	env_flash = dev_get_uclass_priv(new);
#else

	if (!env_flash) {
		env_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS,
			CONFIG_ENV_SPI_CS,
			CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
		if (!env_flash) {
			set_default_env("!spi_flash_probe() failed");
			return -EIO;
		}
	}
#endif
	return 0;
}
示例#2
0
static int init_pcie_bridge_from_spi(void *buf, size_t size)
{
	struct spi_flash *spi;
	int ret;
	unsigned long pcie_addr;

	spi = spi_flash_probe(0, 0, 1000000, SPI_MODE_3);
	if (!spi) {
		printf("%s: spi_flash probe error.\n", __func__);
		return 1;
	}

	if (is_sh7757_b0())
		pcie_addr = SH7757LCR_PCIEBRG_ADDR_B0;
	else
		pcie_addr = SH7757LCR_PCIEBRG_ADDR;

	ret = spi_flash_read(spi, pcie_addr, size, buf);
	if (ret) {
		printf("%s: spi_flash read error.\n", __func__);
		spi_flash_free(spi);
		return 1;
	}
	spi_flash_free(spi);

	return 0;
}
示例#3
0
/*
 * The main entry for SPI booting. It's necessary that SDRAM is already
 * configured and available since this code loads the main U-Boot image
 * from SPI into SDRAM and starts it from there.
 */
void spl_spi_load_image(void)
{
	struct spi_flash *flash;
	struct image_header *header;

	/*
	 * Load U-Boot image from SPI flash into RAM
	 */

	flash = spi_flash_probe(CONFIG_SPL_SPI_BUS, CONFIG_SPL_SPI_CS,
				CONFIG_SF_DEFAULT_SPEED, SPI_MODE_3);
	if (!flash) {
		puts("SPI probe failed.\n");
		hang();
	}

	/* use CONFIG_SYS_TEXT_BASE as temporary storage area */
	header = (struct image_header *)(CONFIG_SYS_TEXT_BASE);

	/* Load u-boot, mkimage header is 64 bytes. */
	spi_flash_read(flash, CONFIG_SYS_SPI_U_BOOT_OFFS, 0x40,
			(void *) header);
	spl_parse_image_header(header);
	spi_flash_read(flash, CONFIG_SYS_SPI_U_BOOT_OFFS,
		       spl_image.size, (void *)spl_image.load_addr);
}
示例#4
0
static void board_identify(void)
{
	struct spi_flash *sf;
	sf = spi_flash_probe(CONFIG_SF_DEFAULT_BUS, CONFIG_SF_DEFAULT_CS,
			     CONFIG_SF_DEFAULT_SPEED, CONFIG_SF_DEFAULT_MODE);
	boot_mode_sf = (sf != NULL);
}
示例#5
0
void env_relocate_spec(void)
{
	int ret;
	char *buf = NULL;

	buf = (char *)memalign(ARCH_DMA_MINALIGN, CONFIG_ENV_SIZE);
	env_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
			CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
	if (!env_flash) {
		set_default_env("!spi_flash_probe() failed");
		if (buf)
			free(buf);
		return;
	}

	ret = spi_flash_read(env_flash,
		CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, buf);
	if (ret) {
		set_default_env("!spi_flash_read() failed");
		goto out;
	}

	ret = env_import(buf, 1);
	if (ret)
		gd->env_valid = 1;
out:
	spi_flash_free(env_flash);
	if (buf)
		free(buf);
	env_flash = NULL;
}
示例#6
0
void spi_SaveS3info(u32 pos, u32 size, u8 *buf, u32 len)
{
	struct spi_flash *flash;

	spi_init();
	flash = spi_flash_probe(0, 0);
	if (!flash) {
		printk(BIOS_DEBUG, "Could not find SPI device\n");
		/* Dont make flow stop. */
		return;
	}

	flash->spi->rw = SPI_WRITE_FLAG;
	spi_claim_bus(flash->spi);

	flash->erase(flash, pos, size);
	flash->write(flash, pos, sizeof(len), &len);

	u32 nvram_pos;
	for (nvram_pos = 0; nvram_pos < len - CONFIG_AMD_SB_SPI_TX_LEN; nvram_pos += CONFIG_AMD_SB_SPI_TX_LEN) {
		flash->write(flash, nvram_pos + pos + 4, CONFIG_AMD_SB_SPI_TX_LEN, (u8 *)(buf + nvram_pos));
	}
	flash->write(flash, nvram_pos + pos + 4, len % CONFIG_AMD_SB_SPI_TX_LEN, (u8 *)(buf + nvram_pos));

	flash->spi->rw = SPI_WRITE_FLAG;
	spi_release_bus(flash->spi);

	return;
}
示例#7
0
int do_write_mac(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	int i, ret;
	char mac_string[256];
	struct spi_flash *spi;
	unsigned char *buf;

	if (argc != 5) {
		buf = malloc(256);
		if (!buf) {
			printf("%s: malloc error.\n", __func__);
			return 1;
		}

		get_sh_eth_mac_raw(buf, 256);

		/* print current MAC address */
		for (i = 0; i < 4; i++) {
			get_sh_eth_mac(i, mac_string, buf);
			if (i < 2)
				printf(" ETHERC ch%d = %s\n", i, mac_string);
			else
				printf("GETHERC ch%d = %s\n", i-2, mac_string);
		}
		free(buf);
		return 0;
	}

	/* new setting */
	memset(mac_string, 0xff, sizeof(mac_string));
	sprintf(mac_string, "%s\t%s\t%s\t%s",
		argv[1], argv[2], argv[3], argv[4]);

	/* write MAC data to SPI rom */
	spi = spi_flash_probe(0, 0, 1000000, SPI_MODE_3);
	if (!spi) {
		printf("%s: spi_flash probe error.\n", __func__);
		return 1;
	}

	ret = spi_flash_erase(spi, SH7757LCR_ETHERNET_MAC_BASE_SPI,
				SH7757LCR_SPI_SECTOR_SIZE);
	if (ret) {
		printf("%s: spi_flash erase error.\n", __func__);
		return 1;
	}

	ret = spi_flash_write(spi, SH7757LCR_ETHERNET_MAC_BASE_SPI,
				sizeof(mac_string), mac_string);
	if (ret) {
		printf("%s: spi_flash write error.\n", __func__);
		spi_flash_free(spi);
		return 1;
	}
	spi_flash_free(spi);

	puts("The writing of the MAC address to SPI ROM was completed.\n");

	return 0;
}
示例#8
0
static int sf_env_relocate_spec(unsigned int offset)
{
	int ret;

	env_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
			CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
	if (!env_flash)
		goto err_probe;

	ret = spi_flash_read(env_flash, offset, CONFIG_ENV_SIZE, env_ptr);
	if (ret)
		goto err_read;

	if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc)
		goto err_crc;

	gd->env_valid = 1;

	return 0;

err_read:
	spi_flash_free(env_flash);
	env_flash = NULL;
err_probe:
err_crc:
	return 1;
}
示例#9
0
int zynq_board_read_rom_ethaddr(unsigned char *ethaddr)
{
#if defined(CONFIG_ZYNQ_GEM_EEPROM_ADDR) && \
    defined(CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET)
	if (eeprom_read(CONFIG_ZYNQ_GEM_EEPROM_ADDR,
			CONFIG_ZYNQ_GEM_I2C_MAC_OFFSET,
			ethaddr, 6))
		printf("I2C EEPROM MAC address read failed\n");
#endif

#if defined(CONFIG_ZYNQ_QSPI) && \
    defined(CONFIG_ZYNQ_GEM_SPI_MAC_OFFSET)
#define CMD_OTPREAD_ARRAY_FAST		0x4b
	struct spi_flash *flash;
	flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS,
				CONFIG_SF_DEFAULT_CS,
				CONFIG_SF_DEFAULT_SPEED,
				CONFIG_SF_DEFAULT_MODE);
	if (!flash) {
		printf("SPI(bus:%u cs:%u) probe failed\n",
			CONFIG_SF_DEFAULT_BUS,
			CONFIG_SF_DEFAULT_CS);
		return 0;
	}
	/* set the cmd to otp read */
	flash->read_cmd = CMD_OTPREAD_ARRAY_FAST;
	if (spi_flash_read(flash, CONFIG_ZYNQ_GEM_SPI_MAC_OFFSET, 6, ethaddr))
		printf("SPI MAC address read failed\n");

	if (flash)
		spi_flash_free(flash);
#endif
	return 0;
}
示例#10
0
文件: env_sf.c 项目: 0s4l/u-boot-xlnx
void env_relocate_spec(void)
{
	char buf[CONFIG_ENV_SIZE];
	int ret;

	env_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
			CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
	if (!env_flash) {
		set_default_env("!spi_flash_probe() failed");
		return;
	}

	ret = spi_flash_read(env_flash,
		CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, buf);
	if (ret) {
		set_default_env("!spi_flash_read() failed");
		goto out;
	}

	ret = env_import(buf, 1);
	if (ret)
		gd->env_valid = 1;
out:
	spi_flash_free(env_flash);
	env_flash = NULL;
}
示例#11
0
void env_relocate_spec(void)
{
	int ret;
    
	//printf("+env_relocate_spec/spi_flash_probe=%d,%d,%d,%d\n\r",CONFIG_ENV_SPI_BUS,CONFIG_ENV_SPI_CS,CONFIG_ENV_SPI_MAX_HZ,CONFIG_ENV_SPI_MODE);
	env_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
	if (!env_flash)
		goto err_probe;

	ret = spi_flash_read(env_flash, CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, env_ptr);
	if (ret)
		goto err_read;

	if (crc32(0, env_ptr->data, ENV_SIZE) != env_ptr->crc)
		goto err_crc;

	gd->env_valid = 1;

	return;

err_read:
	spi_flash_free(env_flash);
	env_flash = NULL;
err_probe:
err_crc:
	puts("*** Warning - bad CRC, using default environment\n\n");

	set_default_env();
}
示例#12
0
static int  get_mac_addr(u8 *addr)
{
	int ret;
	struct spi_flash *flash;

	flash = spi_flash_probe(CFG_MAC_ADDR_SPI_BUS, CFG_MAC_ADDR_SPI_CS,
			CFG_MAC_ADDR_SPI_MAX_HZ, CFG_MAC_ADDR_SPI_MODE);
	if (!flash) {
		printf(" Error - unable to probe SPI flash.\n");
		goto err_probe;
	}

	ret = spi_flash_read(flash, CFG_MAC_ADDR_OFFSET, 6, addr);
	if (ret) {
		printf("Error - unable to read MAC address from SPI flash.\n");
		goto err_read;
	}

err_read:
	/* cannot call free currently since the free function calls free() for
	 * spi_flash structure though it is not directly allocated through
	 * malloc()
	 */
	/* spi_flash_free(flash); */
err_probe:
	return ret;
}
示例#13
0
void spi_env_relocate_spec(void)
{
	int ret;
    env_t env_buf;
    
	env_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
			CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
	if (!env_flash)
		goto err_probe;

	ret = spi_flash_read(env_flash, CONFIG_ENV_IN_SPI_OFFSET, CONFIG_ENV_SIZE, &env_buf);
	if (ret)
		goto err_read;

		env_import(&env_buf, 1);
		gd->env_valid = 1;

		return;

err_read:
	spi_flash_free(env_flash);
	env_flash = NULL;
err_probe:
//err_crc:
	set_default_env("!bad CRC");
}
示例#14
0
static int initr_spiflash(void)
{
        spi_flash_probe(CONFIG_SF_DEFAULT_BUS,
			CONFIG_SF_DEFAULT_CS,
			CONFIG_SF_DEFAULT_SPEED,
			CONFIG_SF_DEFAULT_MODE);
        return 0;
}
示例#15
0
int main(int argc, char **argv) {
	int ret;
	unsigned int cs = 0, max_hz = 0, spi_mode = 0; /* Dummy for now */


	if (getuid() != 0) {
		fprintf(stderr, "Error: Not started with 'root'\n");
		return -1;
	}

	if (bcm2835_init() != 1) {
		fprintf(stderr, "bcm2835_init() failed\n");
		return -2;
	}

	ret = spi_flash_probe(cs, max_hz, spi_mode);

	printf("spi_flash_probe=%d\n", ret);

	if (ret == 0) {
		printf("Detected %s with sector size %d total %d bytes\n", spi_flash_get_name(), spi_flash_get_sector_size(), spi_flash_get_size());
	}

#if 0
	int i;
	uint8_t buffer[16];

	ret = spi_flash_cmd_erase(0, 4096);

	printf("spi_flash_cmd_erase=%d\n", ret);

	ret = spi_flash_cmd_read_fast(0, sizeof(buffer), buffer);

	printf("spi_flash_cmd_read_fast=%d\n", ret);

	for (i = 0; i < sizeof(buffer); i++) {
		printf("%.2x[%c]", buffer[i], isprint(buffer[i]) ? buffer[i] : '.');
	}

	printf("\n");

	ret = spi_flash_cmd_write_multi(0, 6, (const void *)"Arjan");

	printf("spi_flash_cmd_write_multi=%d\n", ret);

	ret = spi_flash_cmd_read_fast(0, sizeof(buffer), buffer);

	printf("spi_flash_cmd_read_fast=%d\n", ret);

	for (i = 0; i < sizeof(buffer); i++) {
		printf("%.2x[%c]", buffer[i], isprint(buffer[i]) ? buffer[i] : '.');
	}
#endif

	printf("\nDone!\n");

	return 0;
}
示例#16
0
inline int init_flash(void)
{
	flash_device = spi_flash_probe(0, 0, 0, 0);

	if (!flash_device)
		return -1;

	return 0;
}
示例#17
0
unsigned long spi_flash_init(void)
{
	flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS, CONFIG_ENV_SPI_MAX_HZ, SPI_MODE_3);
	if (!flash) {
		printf("Failed to initialize SPI flash at %u:%u\n", CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS);
		return 1;
	}
	return 0;
}
示例#18
0
/*
 * The main entry for SPI booting. It's necessary that SDRAM is already
 * configured and available since this code loads the main U-Boot image
 * from SPI into SDRAM and starts it from there.
 */
void spi_boot(void)
{
	void (*uboot)(void) __noreturn;
	u32 offset, code_len, copy_len = 0;
#ifndef CONFIG_FSL_CORENET
	unsigned char *buf = NULL;
#endif
	struct spi_flash *flash;

	flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
			CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
	if (flash == NULL) {
		puts("\nspi_flash_probe failed");
		hang();
	}

#ifdef CONFIG_FSL_CORENET
	offset = CONFIG_SYS_SPI_FLASH_U_BOOT_OFFS;
	code_len = CONFIG_SYS_SPI_FLASH_U_BOOT_SIZE;
#else
	/*
	* Load U-Boot image from SPI flash into RAM
	*/
	buf = malloc(flash->page_size);
	if (buf == NULL) {
		puts("\nmalloc failed");
		hang();
	}
	memset(buf, 0, flash->page_size);

	spi_flash_read(flash, CONFIG_CFG_DATA_SECTOR,
		       flash->page_size, (void *)buf);
	offset = *(u32 *)(buf + ESPI_BOOT_IMAGE_ADDR);
	/* Skip spl code */
	offset += CONFIG_SYS_SPI_FLASH_U_BOOT_OFFS;
	/* Get the code size from offset 0x48 */
	code_len = *(u32 *)(buf + ESPI_BOOT_IMAGE_SIZE);
	/* Skip spl code */
	code_len = code_len - CONFIG_SPL_MAX_SIZE;
#endif
	/* copy code to DDR */
	printf("Loading second stage boot loader ");
	while (copy_len <= code_len) {
		spi_flash_read(flash, offset + copy_len, 0x2000,
			       (void *)(CONFIG_SYS_SPI_FLASH_U_BOOT_DST
			       + copy_len));
		copy_len = copy_len + 0x2000;
		putc('.');
	}

	/*
	* Jump to U-Boot image
	*/
	flush_cache(CONFIG_SYS_SPI_FLASH_U_BOOT_DST, code_len);
	uboot = (void *)CONFIG_SYS_SPI_FLASH_U_BOOT_START;
	(*uboot)();
}
示例#19
0
u32 OemAgesaSaveS3Info(S3_DATA_TYPE S3DataType, u32 DataSize, void *Data)
{
	u32 pos;
	struct spi_flash *flash;
	u8 *new_data;
	u32 bytes_to_process;
	u32 nvram_pos;

	if (S3DataType == S3DataTypeNonVolatile)
		pos = S3_DATA_NONVOLATILE_POS;
	else
		pos = S3_DATA_VOLATILE_POS;

	spi_init();
	flash = spi_flash_probe(0, 0, 0, 0);
	if (!flash) {
		printk(BIOS_DEBUG, "%s: Could not find SPI device\n", __func__);
		/* Don't make flow stop. */
		return AGESA_SUCCESS;
	}

	flash->spi->rw = SPI_WRITE_FLAG;
	spi_claim_bus(flash->spi);

	// initialize the incoming data array
	new_data = (u8 *)malloc(DataSize + (u32)sizeof(DataSize));
	memcpy(new_data, &DataSize, (u32)sizeof(DataSize)); // the size gets written first
	memcpy(new_data + (u32)sizeof(DataSize), Data, DataSize);
	DataSize += (u32)sizeof(DataSize); // add in the size of the data

	for ( ; DataSize > 0; DataSize -= bytes_to_process) {
		bytes_to_process = ( DataSize >= flash->sector_size) ? flash->sector_size : DataSize;
		if (memcmp((u8 *)pos, (u8 *)new_data, bytes_to_process)) {
			printk(BIOS_DEBUG, "%s: Data mismatch - write the data\n", __func__);
			flash->erase(flash, pos, flash->sector_size);
			for (nvram_pos = 0; \
			     nvram_pos < bytes_to_process - (bytes_to_process % CONFIG_AMD_SB_SPI_TX_LEN); \
			     nvram_pos += CONFIG_AMD_SB_SPI_TX_LEN) {
				flash->write(flash, pos + nvram_pos, CONFIG_AMD_SB_SPI_TX_LEN, \
				             (u8 *)(new_data + nvram_pos));
			}
			flash->write(flash, pos + nvram_pos, bytes_to_process % CONFIG_AMD_SB_SPI_TX_LEN, \
			             (u8 *)(new_data + nvram_pos));
		}
		else
			printk(BIOS_DEBUG, "%s: existing nvram data matched\n", __func__);

		new_data += bytes_to_process;
		pos += bytes_to_process;
	}
	free(new_data);
	flash->spi->rw = SPI_WRITE_FLAG;
	spi_release_bus(flash->spi);

	return AGESA_SUCCESS;
}
示例#20
0
文件: cmd_arc.c 项目: OpenNoah/u-boot
static int set_arc_product(int argc, char *const argv[])
{
	int err = 0;
	char *mystrerr = "ERROR: Failed to save factory info in spi location";

	if (argc != 5)
		return -1;

	/* Check serial number */
	if (strlen(argv[1]) != MAX_SERIAL_SIZE)
		return -1;

	/* Check HWaddrs */
	if (ishwaddr(argv[2]) || ishwaddr(argv[3]) || ishwaddr(argv[4]))
		return -1;

	strcpy(smac[3], argv[1]);
	strcpy(smac[2], argv[2]);
	strcpy(smac[1], argv[3]);
	strcpy(smac[0], argv[4]);

	flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
				CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);

	/*
	 * Save factory defaults
	 */

	if (spi_flash_write(flash, FIRM_ADDR1, sizeof(smac), smac)) {
		printf("%s: %s [1]\n", __func__, mystrerr);
		err++;
	}
	if (spi_flash_write(flash, FIRM_ADDR2, sizeof(smac), smac)) {
		printf("%s: %s [2]\n", __func__, mystrerr);
		err++;
	}

	if (spi_flash_write(flash, FIRM_ADDR3, sizeof(smac), smac)) {
		printf("%s: %s [3]\n", __func__, mystrerr);
		err++;
	}

	if (spi_flash_write(flash, FIRM_ADDR4, sizeof(smac), smac)) {
		printf("%s: %s [4]\n", __func__, mystrerr);
		err++;
	}

	if (err == 4) {
		printf("%s: %s [ALL]\n", __func__, mystrerr);
		return -2;
	}

	return 0;
}
示例#21
0
void boot_device_init(void)
{
	int bus = CONFIG_BOOT_MEDIA_SPI_BUS;
	int cs = 0;

	if (spi_flash_info != NULL)
		return;

	spi_flash_info = spi_flash_probe(bus, cs);

	mmap_helper_device_init(&mdev, _cbfs_cache, _cbfs_cache_size);
}
示例#22
0
spiflash_logic_t *spiflash_logic_open(unsigned long long address,
				      unsigned long long length)
{
	struct mtd_info_ex *mtd_info_ex;
	spiflash_logic_t *spiflash_logic;
	struct spi_flash *spiflash;

	spiflash = spi_flash_probe(0,0,0,0);
	if (spiflash == NULL) {
		printf("no devices available\n");
		return NULL;
	}

	mtd_info_ex = get_spiflash_info();
	if (mtd_info_ex == NULL) {
		printf("get spi flash info failed\n");
		return NULL;
	}

	/* Reject open, which are not block aligned */
	if ((address & (mtd_info_ex->erasesize - 1))
	    || (length & (mtd_info_ex->erasesize - 1))) {
		printf("Attempt to open non block aligned, "
			"spi flash blocksize: 0x%08x, address: 0x%08llx,"
			" length: 0x%08llx\n",
			mtd_info_ex->erasesize, address, length);
		return NULL;
	}

	if ((address > spiflash->size)
	    || (length > spiflash->size)
	    || ((address + length) > spiflash->size)) {
		printf("Attempt to open outside the flash area, "
			"spi flash chipsize: 0x%08x, address: 0x%08llx,"
			" length: 0x%08llx\n",
			spiflash->size, address, length);
		return NULL;
	}

	spiflash_logic = malloc(sizeof(spiflash_logic_t));
	if (!spiflash_logic) {
		printf("no many memory.\n");
		return NULL;
	}

	spiflash_logic->spiflash  = spiflash;
	spiflash_logic->address   = address;
	spiflash_logic->length    = length;
	spiflash_logic->erasesize = mtd_info_ex->erasesize;

	return spiflash_logic;
}
static void boot_device_rw_init(void)
{
	const int bus = CONFIG_BOOT_DEVICE_SPI_FLASH_BUS;
	const int cs = 0;

	if (car_get_var(sfg) != NULL)
		return;

	/* Ensure any necessary setup is performed by the drivers. */
	spi_init();

	car_set_var(sfg, spi_flash_probe(bus, cs));
}
示例#24
0
static int splash_sf_read_raw(u32 bmp_load_addr, int offset, size_t read_size)
{
	if (!sf) {
		sf = spi_flash_probe(CONFIG_SF_DEFAULT_BUS,
				     CONFIG_SF_DEFAULT_CS,
				     CONFIG_SF_DEFAULT_SPEED,
				     CONFIG_SF_DEFAULT_MODE);
		if (!sf)
			return -ENODEV;
	}

	return spi_flash_read(sf, offset, read_size, (void *)bmp_load_addr);
}
示例#25
0
void spi_spl_load_image(uint32_t offs, unsigned int size, void *vdst)
{
	struct spi_flash *flash;

	flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
			CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
	if (flash == NULL) {
		puts("\nspi_flash_probe failed");
		hang();
	}

	spi_flash_read(flash, offs, size, vdst);
}
static void boot_device_rw_init(void)
{
	const int bus = CONFIG_BOOT_DEVICE_SPI_FLASH_BUS;
	const int cs = 0;

	if (car_get_var(sfg_init_done) == true)
		return;

	/* Ensure any necessary setup is performed by the drivers. */
	spi_init();

	if (!spi_flash_probe(bus, cs, car_get_var_ptr(&sfg)))
		car_set_var(sfg_init_done, true);
}
示例#27
0
文件: nvm.c 项目: siro20/coreboot
static int nvm_init(void)
{
	if (flash != NULL)
		return 0;

	spi_init();
	flash = spi_flash_probe(0, 0);
	if (!flash) {
		printk(BIOS_DEBUG, "Could not find SPI device\n");
		return -1;
	}

	return 0;
}
示例#28
0
static void erase_environment(void)
{
	struct spi_flash *flash;

	printf("Erasing environment..\n");
	flash = spi_flash_probe(0, 0, 1000000, SPI_MODE_3);
	if (!flash) {
		printf("Erasing flash failed\n");
		return;
	}

	spi_flash_erase(flash, CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE);
	spi_flash_free(flash);
	do_reset(NULL, 0, 0, NULL);
}
示例#29
0
uint32 spi_flash_get_size(void)
{
	sint8 ret  = M2M_SUCCESS;
	uint32 u32FlashId = 0, u32FlashPwr = 0;
	if(!gu32InernalFlashSize)
	{
		ret = spi_flash_probe(&u32FlashId);
		if((u32FlashId != 0xffffffff)&&(ret == M2M_SUCCESS))
		{
			/*flash size is the third byte from the FLASH RDID*/
			u32FlashPwr = ((u32FlashId>>16)&0xff) - 0x11; /*2MBIT is the min*/
			/*That number power 2 to get the flash size*/
			gu32InernalFlashSize = 1<<u32FlashPwr;
			M2M_INFO("Flash Size %d MBit\n",gu32InernalFlashSize);
		}
示例#30
0
文件: env_sf.c 项目: makerbot/u-boot
void env_relocate_spec(void)
{
	int ret;
    char buf[CONFIG_ENV_SIZE];
    env_t *tmp_env;

    tmp_env = (env_t*)buf;

	env_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS,
			CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE);
	if (!env_flash) {
		set_default_env("!spi_flash_probe() failed");
		return;
	}

	ret = spi_flash_read(env_flash, CONFIG_ENV_OFFSET,
				CONFIG_ENV_SIZE, tmp_env);
	if (ret) {
		set_default_env("!spi_flash_read() failed");
		goto out;
	}

	if (crc32(0, tmp_env->data, ENV_SIZE) == tmp_env->crc) {
		gd->env_valid = 1;
	} else {
		ret = spi_flash_read(env_flash, CONFIG_ENV_OFFSET_REDUND,
					CONFIG_ENV_SIZE, tmp_env);
		if (ret) {
			set_default_env("!spi_flash_read() failed");
			goto out;
		}
		if (crc32(0, tmp_env->data, ENV_SIZE) != tmp_env->crc) {
			set_default_env("!both CRC failed");
			goto out;
		}
		gd->env_valid = 2;
	}

	ret = env_import(buf, 0);
	if (!ret) {
		error("Cannot import environment: errno = %d\n", errno);
		set_default_env("env_import failed");
	}

out:
	spi_flash_free(env_flash);
	env_flash = NULL;
}