#include <common.h> | |
#include <malloc.h> | |
#include "obm2osl.h" | |
#include "tim.h" | |
#include "cmdline.h" | |
#include "asr_flash.h" | |
void flash_getinfo(void *info) | |
{ | |
char cmd[128]; | |
#ifdef CONFIG_ASR_QSPI | |
sprintf(cmd, "spi_flash info %x", (unsigned)info); | |
run_command(cmd, 0); | |
#endif | |
} | |
void flash_read(unsigned int load_addr, unsigned int flash_addr, unsigned int len) | |
{ | |
char cmd[128]; | |
#if defined(CONFIG_ASR_QSPI) | |
sprintf(cmd, "spi_flash read %x %x %x", load_addr, | |
flash_addr, len); | |
run_command(cmd, 0); | |
#elif defined(CONFIG_ASR_EMMC_BOOT) | |
flash_addr /= 512; | |
len = (len + 511)/512; | |
sprintf(cmd, "mmc read %x %x %x", load_addr, flash_addr, len); | |
run_command(cmd, 0); | |
#elif defined(CONFIG_PXA_SPI_NOR) | |
sprintf(cmd, "sf probe 0:%d", CONFIG_ENV_SPI_CS); | |
run_command(cmd, 0); | |
sprintf(cmd, "sf read %x %x %x", load_addr, | |
flash_addr, len); | |
run_command(cmd, 0); | |
#else | |
sprintf(cmd, "nand read %x %x %x", load_addr, | |
flash_addr, len); | |
run_command(cmd, 0); | |
#endif | |
} | |
void flash_write(unsigned int mem_pa, unsigned int flash_entry_to, unsigned int mem_sz) | |
{ | |
char cmd[128]; | |
#if defined(CONFIG_ASR_QSPI) | |
/* add + to avoid "Length not block aligned" when erase */ | |
sprintf(cmd, "spi_flash erase %x +%x", | |
(u32)flash_entry_to, (u32)mem_sz); | |
run_command(cmd, 0); | |
sprintf(cmd, "spi_flash write %x %x %x", (u32)mem_pa, | |
(u32)flash_entry_to, (u32)mem_sz); | |
run_command(cmd, 0); | |
#elif defined(CONFIG_ASR_EMMC_BOOT) | |
flash_entry_to /= 512; | |
mem_sz /= 512; | |
sprintf(cmd, "mmc write %x %x %x", load_addr, | |
(u32)flash_entry_to, (u32)mem_sz); | |
run_command(cmd, 0); | |
#elif defined(CONFIG_PXA_SPI_NOR) | |
sprintf(cmd, "sf probe 0:%d", CONFIG_ENV_SPI_CS); | |
run_command(cmd, 0); | |
sprintf(cmd, "sf erase %x %x", | |
(u32)flash_entry_to, (u32)mem_sz); | |
run_command(cmd, 0); | |
sprintf(cmd, "sf write %x %x %x", (u32)mem_pa, | |
(u32)flash_entry_to, (u32)mem_sz); | |
run_command(cmd, 0); | |
#else | |
sprintf(cmd, "nand erase %x %x", | |
(u32)flash_entry_to, (u32)mem_sz); | |
run_command(cmd, 0); | |
sprintf(cmd, "nand write %x %x %x", (u32)mem_pa, | |
(u32)flash_entry_to, (u32)mem_sz); | |
run_command(cmd, 0); | |
#endif | |
} | |
void flash_erase(unsigned int flash_entry_to, unsigned int mem_sz) | |
{ | |
char cmd[128]; | |
#if defined(CONFIG_ASR_QSPI) | |
/* add + to avoid "Length not block aligned" when erase */ | |
sprintf(cmd, "spi_flash erase %x +%x", | |
(u32)flash_entry_to, (u32)mem_sz); | |
run_command(cmd, 0); | |
#elif defined(CONFIG_ASR_EMMC_BOOT) | |
flash_entry_to /= 512; | |
mem_sz /= 512; | |
sprintf(cmd, "mmc erase %x %x", (u32)flash_entry_to, (u32)mem_sz); | |
run_command(cmd, 0); | |
#elif defined(CONFIG_PXA_SPI_NOR) | |
sprintf(cmd, "sf probe 0:%d", CONFIG_ENV_SPI_CS); | |
run_command(cmd, 0); | |
sprintf(cmd, "sf erase %x %x", | |
(u32)flash_entry_to, (u32)mem_sz); | |
run_command(cmd, 0); | |
#else | |
sprintf(cmd, "nand erase %x %x", | |
(u32)flash_entry_to, (u32)mem_sz); | |
run_command(cmd, 0); | |
#endif | |
} |