static void cb_oem(struct usb_ep *ep, struct usb_request *req) { char buf[FORMAT_LEN]; #ifdef CONFIG_SPL_SPI_SUPPORT char *sf_erase[4] = {"sf", "erase", "0", "20000"}; int status; char *sf_probe[3] = {"sf", "probe", "0"}; if (strncmp(req->buf + 4, "spi", 3) == 0) { boot_from_spi = 1; status = do_spi_flash(NULL, 0, 3, sf_probe); if (status) { fastboot_tx_write_str("FAIL:Could not probe SPI"); return; } status = do_spi_flash(NULL, 0, 4, sf_erase); if (status) { fastboot_tx_write_str("FAIL:Could not erase SPI"); return; } fastboot_tx_write_str("OKAY"); return; }else if (strncmp(req->buf + 4, "mmc", 3) == 0) { boot_from_spi = 0; fastboot_tx_write_str("OKAY"); return; } #endif strlcpy(buf, req->buf + 4, FORMAT_LEN); if (fastboot_oem(buf) == 0) fastboot_tx_write_str("OKAY"); else { fastboot_tx_write_str("FAIL: Unable to create partitions"); } return; }
int mv_man_test_sf(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { printf("*****Testing NOR Flash now****\n"); argv[1]="probe"; argv[2]="0"; do_spi_flash(cmdtp,flag,3,argv); printf("******************************\n"); if(strncmp(flash->name,SF_DEVICE_VENDER_ID,10) == 0) { printf("NOR Flash Works!!\n"); g_testReport|= (0x01<<MAN_FUNC_ID_SF); } else printf("NOR Flash Failed!!\n"); return 1; }
static int fastboot_flash(const char *partition) { int status = 0; struct fastboot_ptentry *ptn; char source[32], dest[32], length[32]; char *dev[3] = { "mmc", "dev", "1" }; char *mmc_write[5] = {"mmc", "write", NULL, NULL, NULL}; char *mmc_init[2] = {"mmc", "rescan",}; #ifdef CONFIG_SPL_SPI_SUPPORT char *sf_probe[3] = {"sf", "probe", "0"}; char *sf_write_xloader[5] = {"sf", "write", NULL, "0", "20000"}; char *sf_update_xloader[5] = {"sf", "update", NULL, "0", "20000"}; char *sf_write_bootloader[5] = {"sf", "write", NULL, "80000", "80000"}; char *sf_update_bootloader[5] = {"sf", "update", NULL, "80000", "80000"}; /*Check if this is for xloader or bootloader. Also, check if we have to flash to SPI*/ if (strcmp(partition, "xloader") == 0 && boot_from_spi) { printf("Flashing %s to SPI\n", partition); status = do_spi_flash(NULL, 0, 3, sf_probe); if (status) { fastboot_tx_write_str("FAIL:Could not probe SPI"); return status; } sf_write_xloader[2] = source; sf_update_xloader[2] = source; sprintf(source, "0x%x", (unsigned int)fb_cfg.transfer_buffer); printf("Updating X-LOADER to SPI\n"); status = do_spi_flash(NULL, 0, 5, sf_update_xloader); if(status) { fastboot_tx_write_str("FAIL:Could not update xloader to SPI"); return status; } printf("Writing X-LOADER to SPI\n"); status = do_spi_flash(NULL, 0, 5, sf_write_xloader); if (status) { fastboot_tx_write_str("FAIL:Could not write xloader to SPI"); return status; } printf("Writing xloader DONE\n"); fastboot_tx_write_str("OKAY"); return 0; } if (strcmp(partition, "bootloader") == 0 && boot_from_spi) { printf("Flashing %s to SPI\n", partition); status = do_spi_flash(NULL, 0, 3, sf_probe); if (status) { fastboot_tx_write_str("FAIL:Could not probe SPI"); return status; } sf_write_bootloader[2] = source; sf_update_bootloader[2] = source; sprintf(source, "0x%x", (unsigned int)fb_cfg.transfer_buffer); printf("Updating bootloader to SPI\n"); status = do_spi_flash(NULL, 0, 5, sf_update_bootloader); if (status) { fastboot_tx_write_str("FAIL:Could not update bootloader to SPI"); return status; } printf("Writing bootloader to SPI\n"); status = do_spi_flash(NULL, 0, 5, sf_write_bootloader); if (status) { fastboot_tx_write_str("FAIL:Could not write bootloader to SPI"); return status; } printf("Writing bootloader DONE\n"); fastboot_tx_write_str("OKAY"); return 0; } #endif if (!strcmp(partition, "zImage") || !strcmp(partition, "zimage")) { return fastboot_update_zimage(); } ptn = fastboot_flash_find_ptn(partition); if (ptn == 0) { printf("Partition:[%s] does not exist\n", partition); fastboot_tx_write_str("FAIL:Partition does not exist"); } else if ((download_bytes> ptn->length) && !(ptn->flags & FASTBOOT_PTENTRY_FLAGS_WRITE_ENV)) { printf("Image too large for the partition\n"); fastboot_tx_write_str("FAIL: image too large for partition"); } else { source[0] = '\0'; dest[0] = '\0'; length[0] = '\0'; mmc_write[2] = source; mmc_write[3] = dest; mmc_write[4] = length; sprintf(source, "0x%x", (unsigned int)fb_cfg.transfer_buffer); sprintf(dest, "0x%x", ptn->start); sprintf(length, "0x%x", (download_bytes/512) + 1); status = do_mmcops(NULL, 0, 3, dev); if (status) { printf("Unable to set MMC device\n"); fastboot_tx_write_str("FAIL: init of MMC"); goto exit; } status = do_mmcops(NULL, 0, 2, mmc_init); if (status) { fastboot_tx_write_str("FAIL:Init of MMC card"); goto exit; } if ( ((sparse_header_t *)fb_cfg.transfer_buffer)->magic == SPARSE_HEADER_MAGIC) { printf("fastboot: %s is in sparse format %u %llu \n", ptn->name, ptn->start, ptn->length); status = do_unsparse(fb_cfg.transfer_buffer, ptn->start, ptn->length); if (status) { printf("Writing '%s' FAILED!\n", ptn->name); fastboot_tx_write_str("FAIL: Write partition"); } else { printf("Writing sparsed: '%s' DONE!\n", ptn->name); printf("Writing '%s' DONE!\n", ptn->name); fastboot_tx_write_str("OKAY"); } } else { printf("Writing non-sparsed format '%s'\n", ptn->name); status = do_mmcops(NULL, 0, 5, mmc_write); if (status) { printf("Writing '%s' FAILED!\n", ptn->name); fastboot_tx_write_str("FAIL: Write partition"); goto exit; } else { printf("Writing '%s' DONE!\n", ptn->name); fastboot_tx_write_str("OKAY"); } } } exit: return status; }