static int load_rescue_image(ulong addr) { disk_partition_t info; int devno; int partno; int i; char fwdir[64]; char nxri[128]; char *tmp; char dev[7]; char addr_str[16]; char *argv[6] = { "fatload", "usb", dev, addr_str, nxri, NULL }; block_dev_desc_t *stor_dev = NULL; cmd_tbl_t *bcmd; /* Get name of firmware directory */ tmp = getenv("fw-dir"); /* Copy it into fwdir */ strncpy(fwdir, tmp ? tmp : FW_DIR, sizeof(fwdir)); fwdir[sizeof(fwdir) - 1] = 0; /* Terminate string */ printf(LOG_PREFIX "Checking for firmware image directory '%s' on USB" " storage...\n", fwdir); usb_stop(); if (usb_init() != 0) return 1; /* Check for storage device */ if (usb_stor_scan(1) != 0) { usb_stop(); return 1; } /* Detect storage device */ for (devno = 0; devno < USB_MAX_STOR_DEV; devno++) { stor_dev = usb_stor_get_dev(devno); if (stor_dev->type != DEV_TYPE_UNKNOWN) break; } if (!stor_dev || stor_dev->type == DEV_TYPE_UNKNOWN) { printf(LOG_PREFIX "No valid storage device found...\n"); usb_stop(); return 1; } /* Detect partition */ for (partno = -1, i = 0; i < 6; i++) { if (get_partition_info(stor_dev, i, &info) == 0) { if (fat_register_device(stor_dev, i) == 0) { /* Check if rescue image is present */ FW_DEBUG("Looking for firmware directory '%s'" " on partition %d\n", fwdir, i); if (do_fat_read(fwdir, NULL, 0, LS_NO) == -1) { FW_DEBUG("No NX rescue image on " "partition %d.\n", i); partno = -2; } else { partno = i; FW_DEBUG("Partition %d contains " "firmware directory\n", partno); break; } } } } if (partno < 0) { switch (partno) { case -1: printf(LOG_PREFIX "Error: No valid (FAT) partition " "detected\n"); break; case -2: printf(LOG_PREFIX "Error: No NX rescue image on FAT " "partition\n"); break; default: printf(LOG_PREFIX "Error: Failed with code %d\n", partno); } usb_stop(); return 1; } /* Load the rescue image */ bcmd = find_cmd("fatload"); if (!bcmd) { printf(LOG_PREFIX "Error - 'fatload' command not present.\n"); usb_stop(); return 1; } tmp = getenv("nx-rescue-image"); sprintf(nxri, "%s/%s", fwdir, tmp ? tmp : RESCUE_IMAGE); sprintf(dev, "%d:%d", devno, partno); sprintf(addr_str, "%lx", addr); FW_DEBUG("fat_fsload device='%s', addr='%s', file: %s\n", dev, addr_str, nxri); if (do_fat_fsload(bcmd, 0, 5, argv) != 0) { usb_stop(); return 1; } /* Stop USB */ usb_stop(); return 0; }
void try_update_modem(void) { struct mmc *mmc; block_dev_desc_t *dev_desc=NULL; block_dev_desc_t *p_block_dev = NULL; disk_partition_t info; int ret; int size; p_block_dev = get_dev("mmc", 1); if(NULL == p_block_dev){ return -1; } mmc = find_mmc_device(0); if(mmc){ ret = mmc_init(mmc); if(ret < 0){ printf("mmc init failed %d\n", ret); return; } }else{ printf("no mmc card found\n"); return; } dev_desc = &mmc->block_dev; if(dev_desc==NULL){ printf("no mmc block device found\n"); return; } ret = fat_register_device(dev_desc, 1); if(ret < 0){ printf("fat regist fail %d\n", ret); return; } ret = file_fat_detectfs(); if(ret){ printf("detect fs failed\n"); return; } do{ printf("reading %s\n", SD_NV_NAME); ret = do_fat_read(SD_NV_NAME, BUF_ADDR, 0, LS_NO); if(ret <= 0){ printf("sd file read error %d\n", ret); break; } size = FIXNV_SIZE + 4; nv_patch(BUF_ADDR, ret); nv_write_partition(p_block_dev, PARTITION_FIX_NV1, (char *)BUF_ADDR, size); nv_write_partition(p_block_dev, PARTITION_FIX_NV2, (char *)BUF_ADDR, size); file_fat_rm(SD_NV_NAME); }while(0); do{ printf("reading %s\n", SD_MODEM_NAME); ret = do_fat_read(SD_MODEM_NAME, BUF_ADDR, 0, LS_NO); if(ret <= 0){ printf("sd file read error %d\n", ret); break; } size = ret; nv_write_partition(p_block_dev, PARTITION_MODEM, (char *)BUF_ADDR, size); file_fat_rm(SD_MODEM_NAME); }while(0); do{ printf("reading %s\n", SD_DSP_NAME); ret = do_fat_read(SD_DSP_NAME, BUF_ADDR, 0, LS_NO); if(ret <= 0){ printf("sd file read error %d\n", ret); break; } size = ret; nv_write_partition(p_block_dev, PARTITION_DSP, (char *)BUF_ADDR, size); file_fat_rm(SD_DSP_NAME); }while(0); do{ printf("reading %s\n", SD_VM_NAME); ret = do_fat_read(SD_VM_NAME, BUF_ADDR, 0, LS_NO); if(ret <= 0){ printf("sd file read error %d\n", ret); break; } size = ret; nv_write_partition(p_block_dev, PARTITION_VM, (char *)BUF_ADDR, size); file_fat_rm(SD_VM_NAME); }while(0); printf("update done\n"); return; }