mirror of
https://git.codelinaro.org/clo/qsdk/oss/boot/u-boot-2016.git
synced 2026-03-02 15:33:55 +01:00
Merge "qca : Add u-boot CLI command "flasherase""
This commit is contained in:
commit
fb5a032cfa
1 changed files with 89 additions and 32 deletions
|
|
@ -79,9 +79,48 @@ uint32_t part_size, uint32_t file_size, char *layout)
|
|||
return CMD_RET_SUCCESS;
|
||||
}
|
||||
|
||||
static int fl_erase(int flash_type, uint32_t offset, uint32_t part_size,
|
||||
char *layout)
|
||||
{
|
||||
char runcmd[256];
|
||||
int nand_dev = CONFIG_NAND_FLASH_INFO_IDX;
|
||||
|
||||
if (flash_type == SMEM_BOOT_NAND_FLASH) {
|
||||
|
||||
snprintf(runcmd, sizeof(runcmd), "nand device %d && ", nand_dev);
|
||||
if (strcmp(layout, "default") != 0) {
|
||||
snprintf(runcmd + strlen(runcmd), sizeof(runcmd),
|
||||
"ipq_nand %s && ", layout);
|
||||
}
|
||||
|
||||
snprintf(runcmd + strlen(runcmd), sizeof(runcmd),
|
||||
"nand erase 0x%x 0x%x ",
|
||||
offset, part_size);
|
||||
|
||||
} else if (flash_type == SMEM_BOOT_MMC_FLASH) {
|
||||
|
||||
snprintf(runcmd, sizeof(runcmd),
|
||||
"mmc erase 0x%x 0x%x ",
|
||||
offset, part_size);
|
||||
|
||||
} else if (flash_type == SMEM_BOOT_SPI_FLASH) {
|
||||
|
||||
snprintf(runcmd, sizeof(runcmd),
|
||||
"sf probe && "
|
||||
"sf erase 0x%x 0x%x ",
|
||||
offset, part_size);
|
||||
}
|
||||
|
||||
if (run_command(runcmd, 0) != CMD_RET_SUCCESS)
|
||||
return CMD_RET_FAILURE;
|
||||
|
||||
return CMD_RET_SUCCESS;
|
||||
}
|
||||
|
||||
static int do_flash(cmd_tbl_t *cmdtp, int flag, int argc,
|
||||
char * const argv[])
|
||||
{
|
||||
int flash_cmd = 0;
|
||||
uint32_t load_addr, offset, part_size, file_size, adj_size;
|
||||
uint32_t size_block, start_block, file_size_cpy;
|
||||
char *part_name = NULL, *filesize, *loadaddr;
|
||||
|
|
@ -102,30 +141,40 @@ char * const argv[])
|
|||
qca_smem_flash_info_t *sfi = &qca_smem_flash_info;
|
||||
nand_info_t *nand = &nand_info[CONFIG_NAND_FLASH_INFO_IDX];
|
||||
|
||||
if ((argc < 2) || (argc > 4))
|
||||
return CMD_RET_USAGE;
|
||||
if (strcmp(argv[0], "flash") == 0)
|
||||
flash_cmd = 1;
|
||||
|
||||
if (argc == 2) {
|
||||
loadaddr = getenv("fileaddr");
|
||||
if (loadaddr != NULL)
|
||||
load_addr = simple_strtoul(loadaddr, NULL, 16);
|
||||
else
|
||||
if (flash_cmd) {
|
||||
if ((argc < 2) || (argc > 4))
|
||||
return CMD_RET_USAGE;
|
||||
|
||||
filesize = getenv("filesize");
|
||||
if (filesize != NULL)
|
||||
file_size = simple_strtoul(filesize, NULL, 16);
|
||||
else
|
||||
if (argc == 2) {
|
||||
loadaddr = getenv("fileaddr");
|
||||
if (loadaddr != NULL)
|
||||
load_addr = simple_strtoul(loadaddr, NULL, 16);
|
||||
else
|
||||
return CMD_RET_USAGE;
|
||||
|
||||
filesize = getenv("filesize");
|
||||
if (filesize != NULL)
|
||||
file_size = simple_strtoul(filesize, NULL, 16);
|
||||
else
|
||||
return CMD_RET_USAGE;
|
||||
|
||||
} else if (argc == 4) {
|
||||
load_addr = simple_strtoul(argv[2], NULL, 16);
|
||||
file_size = simple_strtoul(argv[3], NULL, 16);
|
||||
|
||||
} else
|
||||
return CMD_RET_USAGE;
|
||||
|
||||
} else if (argc == 4) {
|
||||
load_addr = simple_strtoul(argv[2], NULL, 16);
|
||||
file_size = simple_strtoul(argv[3], NULL, 16);
|
||||
file_size_cpy = file_size;
|
||||
}
|
||||
else {
|
||||
if (argc != 2)
|
||||
return CMD_RET_USAGE;
|
||||
}
|
||||
|
||||
} else
|
||||
return CMD_RET_USAGE;
|
||||
|
||||
file_size_cpy = file_size;
|
||||
flash_type = sfi->flash_type;
|
||||
part_name = argv[1];
|
||||
|
||||
|
|
@ -220,25 +269,28 @@ char * const argv[])
|
|||
}
|
||||
}
|
||||
|
||||
if (flash_type == SMEM_BOOT_NAND_FLASH) {
|
||||
if (flash_cmd) {
|
||||
if (flash_type == SMEM_BOOT_NAND_FLASH) {
|
||||
|
||||
adj_size = file_size % nand->writesize;
|
||||
if (adj_size)
|
||||
file_size = file_size + (nand->writesize - adj_size);
|
||||
}
|
||||
|
||||
if (flash_type == SMEM_BOOT_MMC_FLASH) {
|
||||
|
||||
if (disk_info.blksz) {
|
||||
file_size = file_size / disk_info.blksz;
|
||||
adj_size = file_size_cpy % disk_info.blksz;
|
||||
adj_size = file_size % nand->writesize;
|
||||
if (adj_size)
|
||||
file_size = file_size + 1;
|
||||
file_size = file_size + (nand->writesize - adj_size);
|
||||
}
|
||||
}
|
||||
|
||||
ret = write_to_flash(flash_type, load_addr, offset, part_size,
|
||||
if (flash_type == SMEM_BOOT_MMC_FLASH) {
|
||||
|
||||
if (disk_info.blksz) {
|
||||
file_size = file_size / disk_info.blksz;
|
||||
adj_size = file_size_cpy % disk_info.blksz;
|
||||
if (adj_size)
|
||||
file_size = file_size + 1;
|
||||
}
|
||||
}
|
||||
|
||||
ret = write_to_flash(flash_type, load_addr, offset, part_size,
|
||||
file_size, layout);
|
||||
} else
|
||||
ret = fl_erase(flash_type, offset, part_size, layout);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -250,3 +302,8 @@ U_BOOT_CMD(
|
|||
"flash the image at load_addr, given file_size in hex\n"
|
||||
);
|
||||
|
||||
U_BOOT_CMD(
|
||||
flasherase, 4, 0, do_flash,
|
||||
"flerase part_name \n",
|
||||
"erases on flash the given partition \n"
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue