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; }
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; }
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; }
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(); }
static int env_sf_load(void) { int ret; char *buf = NULL; buf = (char *)memalign(ARCH_DMA_MINALIGN, CONFIG_ENV_SIZE); if (!buf) { set_default_env("!malloc() failed"); return -EIO; } ret = setup_flash_device(); if (ret) goto out; ret = spi_flash_read(env_flash, CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, buf); if (ret) { set_default_env("!spi_flash_read() failed"); goto err_read; } ret = env_import(buf, 1); if (!ret) gd->env_valid = ENV_VALID; err_read: spi_flash_free(env_flash); env_flash = NULL; out: free(buf); return ret; }
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; }
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"); }
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; }
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; }
static int get_sh_eth_mac_raw(unsigned char *buf, int size) { struct spi_flash *spi; int ret; spi = spi_flash_probe(0, 0, 1000000, SPI_MODE_3); if (spi == NULL) { printf("%s: spi_flash probe failed.\n", __func__); return 1; } ret = spi_flash_read(spi, SH7753EVB_ETHERNET_MAC_BASE, size, buf); if (ret) { printf("%s: spi_flash read failed.\n", __func__); spi_flash_free(spi); return 1; } spi_flash_free(spi); return 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); }
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; }
static int writeImageToSerialFlash(PartitionInfo_S *psPartitionInfo, void *pvBuf, int nBufLength) { int nRet; unsigned int nBus = 0; unsigned int nCS = 0; unsigned int nSpeed = 1000000; unsigned int nMode = SPI_MODE_3; ImageInfo_S *psImageInfo = &psPartitionInfo->m_sImageInfo; struct spi_flash *psFlash; int nOffset = psPartitionInfo->m_nBeginAddr; int nLength = psPartitionInfo->m_nEndAddr-psPartitionInfo->m_nBeginAddr; psFlash = spi_flash_probe(nBus, nCS, nSpeed, nMode); if (!psFlash) { printf("Failed to initialize SPI flash at %u:%u\n", nBus, nCS); return FALSE; } if (nOffset + nLength > psFlash->size) { printf("ERROR: attempting past flash size (%#x)\n", psFlash->size); return FALSE; } nRet = spi_flash_erase(psFlash, nOffset&(~(psFlash->sector_size-1)), nLength&(~(psFlash->sector_size-1))); if (nRet) { printf("SPI flash erase failed\n"); return FALSE; } nLength = psImageInfo->m_nImageSize; if (psImageInfo->m_eImageType==EM_IMAGE_TYPE_BOOTSTRAP) { *(int *)(pvBuf+psImageInfo->m_nImageOffset+0x14) = nLength; } nRet = spi_flash_write(psFlash, nOffset, nLength, pvBuf+psImageInfo->m_nImageOffset); if (nRet) { printf("SPI flash write failed\n"); return FALSE; } spi_flash_free(psFlash); return TRUE; }
void env_relocate_spec(void) { 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, 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: puts("*** Warning - read\n"); spi_flash_free(env_flash); env_flash = NULL; err_probe: puts("*** Warning - probe\n"); err_crc: puts("*** Warning - CRC\n"); puts("*** Warning - bad CRC, using default environment\n\n"); if (default_environment_size > CONFIG_ENV_SIZE) { gd->env_valid = 0; puts("*** Error - default environment is too large\n\n"); return; } memset(env_ptr, 0, sizeof(env_t)); memcpy(env_ptr->data, default_environment, default_environment_size); env_ptr->crc = crc32(0, env_ptr->data, ENV_SIZE); gd->env_valid = 1; }
static int env_sf_load(void) { int ret; int read1_fail, read2_fail; env_t *tmp_env1, *tmp_env2; tmp_env1 = (env_t *)memalign(ARCH_DMA_MINALIGN, CONFIG_ENV_SIZE); tmp_env2 = (env_t *)memalign(ARCH_DMA_MINALIGN, CONFIG_ENV_SIZE); if (!tmp_env1 || !tmp_env2) { set_default_env("!malloc() failed"); ret = -EIO; goto out; } ret = setup_flash_device(); if (ret) goto out; read1_fail = spi_flash_read(env_flash, CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, tmp_env1); read2_fail = spi_flash_read(env_flash, CONFIG_ENV_OFFSET_REDUND, CONFIG_ENV_SIZE, tmp_env2); ret = env_import_redund((char *)tmp_env1, read1_fail, (char *)tmp_env2, read2_fail); spi_flash_free(env_flash); env_flash = NULL; out: free(tmp_env1); free(tmp_env2); return ret; }
void env_relocate_spec(void) { int ret; int crc1_ok = 0, crc2_ok = 0; env_t *tmp_env1 = NULL; env_t *tmp_env2 = NULL; env_t *ep = NULL; tmp_env1 = (env_t *)malloc(CONFIG_ENV_SIZE); tmp_env2 = (env_t *)malloc(CONFIG_ENV_SIZE); if (!tmp_env1 || !tmp_env2) { set_default_env("!malloc() failed"); goto out; } 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"); goto out; } ret = spi_flash_read(env_flash, CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, tmp_env1); if (ret) { set_default_env("!spi_flash_read() failed"); goto err_read; } if (crc32(0, tmp_env1->data, ENV_SIZE) == tmp_env1->crc) crc1_ok = 1; ret = spi_flash_read(env_flash, CONFIG_ENV_OFFSET_REDUND, CONFIG_ENV_SIZE, tmp_env2); if (!ret) { if (crc32(0, tmp_env2->data, ENV_SIZE) == tmp_env2->crc) crc2_ok = 1; } if (!crc1_ok && !crc2_ok) { set_default_env("!bad CRC"); goto err_read; } else if (crc1_ok && !crc2_ok) { gd->env_valid = 1; } else if (!crc1_ok && crc2_ok) { gd->env_valid = 2; } else if (tmp_env1->flags == ACTIVE_FLAG && tmp_env2->flags == OBSOLETE_FLAG) { gd->env_valid = 1; } else if (tmp_env1->flags == OBSOLETE_FLAG && tmp_env2->flags == ACTIVE_FLAG) { gd->env_valid = 2; } else if (tmp_env1->flags == tmp_env2->flags) { gd->env_valid = 2; } else if (tmp_env1->flags == 0xFF) { gd->env_valid = 2; } else { /* * this differs from code in env_flash.c, but I think a sane * default path is desirable. */ gd->env_valid = 2; } if (gd->env_valid == 1) ep = tmp_env1; else ep = tmp_env2; ret = env_import((char *)ep, 0); if (!ret) { error("Cannot import environment: errno = %d\n", errno); set_default_env("env_import failed"); } err_read: spi_flash_free(env_flash); env_flash = NULL; out: free(tmp_env1); free(tmp_env2); }
void cs4340_upload_firmware(struct phy_device *phydev) { char line_temp[0x50] = {0}; char reg_addr[0x50] = {0}; char reg_data[0x50] = {0}; int i, line_cnt = 0, column_cnt = 0; struct cortina_reg_config fw_temp; char *addr = NULL; #if defined(CONFIG_SYS_CORTINA_FW_IN_NOR) || \ defined(CONFIG_SYS_CORTINA_FW_IN_REMOTE) addr = (char *)CONFIG_CORTINA_FW_ADDR; #elif defined(CONFIG_SYS_CORTINA_FW_IN_NAND) int ret; size_t fw_length = CONFIG_CORTINA_FW_LENGTH; addr = malloc(CONFIG_CORTINA_FW_LENGTH); ret = nand_read(get_nand_dev_by_index(0), (loff_t)CONFIG_CORTINA_FW_ADDR, &fw_length, (u_char *)addr); if (ret == -EUCLEAN) { printf("NAND read of Cortina firmware at 0x%x failed %d\n", CONFIG_CORTINA_FW_ADDR, ret); } #elif defined(CONFIG_SYS_CORTINA_FW_IN_SPIFLASH) int ret; struct spi_flash *ucode_flash; addr = malloc(CONFIG_CORTINA_FW_LENGTH); ucode_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS, CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE); if (!ucode_flash) { puts("SF: probe for Cortina ucode failed\n"); } else { ret = spi_flash_read(ucode_flash, CONFIG_CORTINA_FW_ADDR, CONFIG_CORTINA_FW_LENGTH, addr); if (ret) puts("SF: read for Cortina ucode failed\n"); spi_flash_free(ucode_flash); } #elif defined(CONFIG_SYS_CORTINA_FW_IN_MMC) int dev = CONFIG_SYS_MMC_ENV_DEV; u32 cnt = CONFIG_CORTINA_FW_LENGTH / 512; u32 blk = CONFIG_CORTINA_FW_ADDR / 512; struct mmc *mmc = find_mmc_device(CONFIG_SYS_MMC_ENV_DEV); if (!mmc) { puts("Failed to find MMC device for Cortina ucode\n"); } else { addr = malloc(CONFIG_CORTINA_FW_LENGTH); printf("MMC read: dev # %u, block # %u, count %u ...\n", dev, blk, cnt); mmc_init(mmc); (void)mmc->block_dev.block_read(&mmc->block_dev, blk, cnt, addr); } #endif while (*addr != 'Q') { i = 0; while (*addr != 0x0a) { line_temp[i++] = *addr++; if (0x50 < i) { printf("Not found Cortina PHY ucode at 0x%p\n", (char *)CONFIG_CORTINA_FW_ADDR); return; } } addr++; /* skip '\n' */ line_cnt++; column_cnt = i; line_temp[column_cnt] = '\0'; if (CONFIG_CORTINA_FW_LENGTH < line_cnt) return; for (i = 0; i < column_cnt; i++) { if (isspace(line_temp[i++])) break; } memcpy(reg_addr, line_temp, i); memcpy(reg_data, &line_temp[i], column_cnt - i); strim(reg_addr); strim(reg_data); fw_temp.reg_addr = (simple_strtoul(reg_addr, NULL, 0)) & 0xffff; fw_temp.reg_value = (simple_strtoul(reg_data, NULL, 0)) & 0xffff; phy_write(phydev, 0x00, fw_temp.reg_addr, fw_temp.reg_value); } }
/* Init common part of FM, index is fm num# like fm as above */ int fm_init_common(int index, struct ccsr_fman *reg) { int rc; #if defined(CONFIG_SYS_QE_FMAN_FW_IN_NOR) void *addr = (void *)CONFIG_SYS_QE_FMAN_FW_ADDR; #elif defined(CONFIG_SYS_QE_FMAN_FW_IN_NAND) size_t fw_length = CONFIG_SYS_QE_FMAN_FW_LENGTH; void *addr = malloc(CONFIG_SYS_QE_FMAN_FW_LENGTH); rc = nand_read(&nand_info[0], (loff_t)CONFIG_SYS_QE_FMAN_FW_ADDR, &fw_length, (u_char *)addr); if (rc == -EUCLEAN) { printf("NAND read of FMAN firmware at offset 0x%x failed %d\n", CONFIG_SYS_QE_FMAN_FW_ADDR, rc); } #elif defined(CONFIG_SYS_QE_FW_IN_SPIFLASH) struct spi_flash *ucode_flash; void *addr = malloc(CONFIG_SYS_QE_FMAN_FW_LENGTH); int ret = 0; ucode_flash = spi_flash_probe(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS, CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE); if (!ucode_flash) printf("SF: probe for ucode failed\n"); else { ret = spi_flash_read(ucode_flash, CONFIG_SYS_QE_FMAN_FW_ADDR, CONFIG_SYS_QE_FMAN_FW_LENGTH, addr); if (ret) printf("SF: read for ucode failed\n"); spi_flash_free(ucode_flash); } #elif defined(CONFIG_SYS_QE_FMAN_FW_IN_MMC) int dev = CONFIG_SYS_MMC_ENV_DEV; void *addr = malloc(CONFIG_SYS_QE_FMAN_FW_LENGTH); u32 cnt = CONFIG_SYS_QE_FMAN_FW_LENGTH / 512; u32 blk = CONFIG_SYS_QE_FMAN_FW_ADDR / 512; struct mmc *mmc = find_mmc_device(CONFIG_SYS_MMC_ENV_DEV); if (!mmc) printf("\nMMC cannot find device for ucode\n"); else { printf("\nMMC read: dev # %u, block # %u, count %u ...\n", dev, blk, cnt); mmc_init(mmc); (void)mmc->block_dev.block_read(dev, blk, cnt, addr); /* flush cache after read */ flush_cache((ulong)addr, cnt * 512); } #elif defined(CONFIG_SYS_QE_FMAN_FW_IN_REMOTE) void *addr = (void *)CONFIG_SYS_QE_FMAN_FW_ADDR; #endif /* Upload the Fman microcode if it's present */ rc = fman_upload_firmware(index, ®->fm_imem, addr); if (rc) return rc; setenv_addr("fman_ucode", addr); fm_init_muram(index, ®->muram); fm_init_qmi(®->fm_qmi_common); fm_init_fpm(®->fm_fpm); /* clear DMA status */ setbits_be32(®->fm_dma.fmdmsr, FMDMSR_CLEAR_ALL); /* set DMA mode */ setbits_be32(®->fm_dma.fmdmmr, FMDMMR_SBER); return fm_init_bmi(index, ®->fm_bmi_common); }