int do_tftpd(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { gpio_init(); if(DETECT()) { printf(" \n## Enter Rescue Mode ##\n"); printf(" \n3: System Boot system code via TFTP.\n"); setenv("autostart", "no"); /* Wait forever for an image */ if (NetLoop(TFTPD) < 0) return 1; } else { if(check_image(0)) { printf(" \nEnter Recuse Mode for image error\n"); printf(" \n3: System Boot system code via TFTP.\n"); if (NetLoop(TFTPD) < 0) return 1; } /* show LED POWER after success image integrity check */ LEDON(); printf(" \n3: System Boot system code via Flash.\n"); do_bootm(cmdtp, 0, argc, argv); } return 0; }
/* ******************************************************************************* * __boot * * Description: * void * * Parameters: * void * * Return value: * void * * note: * void * ******************************************************************************* */ static void __boot(void) { char response[68]; if(all_download_bytes > CFG_FASTBOOT_MKBOOTIMAGE_PAGE_SIZE) { char start[32]; char *bootm[3] = { "bootm", NULL, NULL, }; char *go[3] = { "go", NULL, NULL, }; struct fastboot_boot_img_hdr *fb_hdr = (struct fastboot_boot_img_hdr *) trans_data.base_recv_buffer; /* Skip the mkbootimage header */ image_header_t *hdr = (image_header_t *) &trans_data.base_recv_buffer[CFG_FASTBOOT_MKBOOTIMAGE_PAGE_SIZE]; bootm[1] = go[1] = start; sprintf(start, "0x%x", (uint)hdr); printf("start addr %s\n", start); /* Execution should jump to kernel so send the response now and wait a bit. */ sprintf(response, "OKAY"); // fastboot_tx_status(response, strlen(response)); __msdelay (1000); /* 1 sec */ if (ntohl(hdr->ih_magic) == IH_MAGIC) { /* Looks like a kernel.. */ printf ("Booting kernel..\n"); /* * Check if the user sent a bootargs down. * If not, do not override what is already there */ if (strlen ((char *) &fb_hdr->cmdline[0])) { printf("Image has cmdline:"); printf("%s\n", &fb_hdr->cmdline[0]); setenv ("bootargs", (char *) &fb_hdr->cmdline[0]); } do_bootm (NULL, 0, 2, bootm); } else { /* Raw image, maybe another uboot */ printf ("Booting raw image..\n"); do_go (NULL, 0, 2, go); } printf ("ERROR : bootting failed\n"); printf ("You should reset the board\n"); } else { sprintf(response, "FAILinvalid boot image"); } }
int do_tftpd(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { const int press_times = 1; int i = 0; asus_gpio_init(); if (DETECT()) /* Reset button */ { printf(" \n## Enter Rescue Mode ##\n"); printf(" \n3: System Boot system code via TFTP.\n"); setenv("autostart", "no"); /* Wait forever for an image */ if (NetLoop(TFTPD) < 0) return 1; } else if (DETECT_WPS()) /* WPS button */ { /* Make sure WPS button is pressed at least press_times * 0.01s. */ while (DETECT_WPS() && i++ < press_times) { udelay(10000); } if (i >= press_times) { while (DETECT_WPS()) { udelay(90000); i++; if (i & 1) LEDON(); else LEDOFF(); } LEDOFF(); asus_gpio_uninit(); reset_to_default(); do_reset (NULL, 0, 0, NULL); } } else { if(check_trx(argc, argv)) { printf(" \nEnter Recuse Mode for trx error\n"); printf(" \n3: System Boot system code via TFTP.\n"); if (NetLoop(TFTPD) < 0) return 1; } printf(" \n3: System Boot system code via Flash.\n"); do_bootm(cmdtp, 0, argc, argv); } return 0; }
int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd) { const char *ep = getenv("autostart"); if (ep && !strcmp(ep, "yes")) { char *local_args[2]; local_args[0] = (char *)cmd; local_args[1] = NULL; printf("Automatic boot of image at addr 0x%08lX ...\n", load_addr); return do_bootm(cmdtp, 0, 1, local_args); } return 0; }
void cm5200_fwupdate(void) { cmd_tbl_t *bcmd; char *rsargs; char *tmp = NULL; char ka[16]; char *argv[3] = { "bootm", ka, NULL }; /* Check if rescue system is disabled... */ if (getenv("norescue")) { printf(LOG_PREFIX "Rescue System disabled.\n"); return; } /* Check if we have a USB storage device and load image */ if (load_rescue_image(LOAD_ADDR)) return; bcmd = find_cmd("bootm"); if (!bcmd) return; sprintf(ka, "%lx", (ulong)LOAD_ADDR); /* prepare our bootargs */ rsargs = getenv("rs-args"); if (!rsargs) rsargs = RS_BOOTARGS; else { tmp = malloc(strlen(rsargs+1)); if (!tmp) { printf(LOG_PREFIX "Memory allocation failed\n"); return; } strcpy(tmp, rsargs); rsargs = tmp; } setenv("bootargs", rsargs); if (rsargs == tmp) free(rsargs); printf(LOG_PREFIX "Starting update system (bootargs=%s)...\n", rsargs); do_bootm(bcmd, 0, 2, argv); }
/* Calls bootm with the parameters given */ static int call_bootm(int argc, char * const argv[], const char *subcommand[]) { char *bootm_argv[5]; int i = 0; int ret = 0; int j; /* create paramter array */ bootm_argv[0] = "do_bootm"; switch (argc) { case 3: bootm_argv[4] = argv[2]; /* fdt addr */ case 2: bootm_argv[3] = argv[1]; /* initrd addr */ case 1: bootm_argv[2] = argv[0]; /* kernel addr */ } /* * - do the work - * exec subcommands of do_bootm to init the images * data structure */ while (subcommand[i] != NULL) { bootm_argv[1] = (char *)subcommand[i]; debug("args %d: %s %s ", argc, bootm_argv[0], bootm_argv[1]); for (j = 0; j < argc; j++) debug("%s ", bootm_argv[j + 2]); debug("\n"); ret = do_bootm(find_cmd("do_bootm"), 0, argc+2, bootm_argv); debug("Subcommand retcode: %d\n", ret); i++; } if (ret) { printf("ERROR prep subcommand failed!\n"); return -1; } return 0; }
/*----------------------------------------------------------------------------- * do_fdosboot -- *----------------------------------------------------------------------------- */ int do_fdosboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { char *name; char *ep; int size; int rcode = 0; char buf [12]; int drive = CONFIG_SYS_FDC_DRIVE_NUMBER; /* pre-set load_addr */ if ((ep = getenv("loadaddr")) != NULL) { load_addr = simple_strtoul(ep, NULL, 16); } /* pre-set Boot file name */ if ((name = getenv("bootfile")) == NULL) { name = "uImage"; } switch (argc) { case 1: break; case 2: /* only one arg - accept two forms: * just load address, or just boot file name. * The latter form must be written "filename" here. */ if (argv[1][0] == '"') { /* just boot filename */ name = argv [1]; } else { /* load address */ load_addr = simple_strtoul(argv[1], NULL, 16); } break; case 3: load_addr = simple_strtoul(argv[1], NULL, 16); name = argv [2]; break; default: return cmd_usage(cmdtp); } /* Init physical layer */ if (!fdc_fdos_init (drive)) { return (-1); } /* Open file */ if (dos_open (name) < 0) { printf ("Unable to open %s\n", name); return 1; } if ((size = dos_read (load_addr)) < 0) { printf ("boot error\n"); return 1; } flush_cache (load_addr, size); #ifdef CONFIG_AML_SECU_BOOT_V2 extern int g_nIMGReadFlag; g_nIMGReadFlag = 0; #endif //#ifdef CONFIG_AML_SECU_BOOT_V2 sprintf(buf, "%x", size); setenv("filesize", buf); printf("Floppy DOS load complete: %d bytes loaded to 0x%lx\n", size, load_addr); /* Check if we should attempt an auto-start */ if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) { char *local_args[2]; local_args[0] = argv[0]; local_args[1] = NULL; printf ("Automatic boot of image at addr 0x%08lX ...\n", load_addr); rcode = do_bootm (cmdtp, 0, 1, local_args); } return rcode; }
int do_docboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { char *boot_device = NULL; char *ep; int dev; ulong cnt; ulong addr; ulong offset = 0; image_header_t *hdr; int rcode = 0; #if defined(CONFIG_FIT) const void *fit_hdr = NULL; #endif show_boot_progress (34); switch (argc) { case 1: addr = CONFIG_SYS_LOAD_ADDR; boot_device = getenv ("bootdevice"); break; case 2: addr = simple_strtoul(argv[1], NULL, 16); boot_device = getenv ("bootdevice"); break; case 3: addr = simple_strtoul(argv[1], NULL, 16); boot_device = argv[2]; break; case 4: addr = simple_strtoul(argv[1], NULL, 16); boot_device = argv[2]; offset = simple_strtoul(argv[3], NULL, 16); break; default: cmd_usage(cmdtp); show_boot_progress (-35); return 1; } show_boot_progress (35); if (!boot_device) { puts ("\n** No boot device **\n"); show_boot_progress (-36); return 1; } show_boot_progress (36); dev = simple_strtoul(boot_device, &ep, 16); if ((dev >= CONFIG_SYS_MAX_DOC_DEVICE) || (doc_dev_desc[dev].ChipID == DOC_ChipID_UNKNOWN)) { printf ("\n** Device %d not available\n", dev); show_boot_progress (-37); return 1; } show_boot_progress (37); printf ("\nLoading from device %d: %s at 0x%lX (offset 0x%lX)\n", dev, doc_dev_desc[dev].name, doc_dev_desc[dev].physadr, offset); if (doc_rw (doc_dev_desc + dev, 1, offset, SECTORSIZE, NULL, (u_char *)addr)) { printf ("** Read error on %d\n", dev); show_boot_progress (-38); return 1; } show_boot_progress (38); switch (genimg_get_format ((void *)addr)) { case IMAGE_FORMAT_LEGACY: hdr = (image_header_t *)addr; image_print_contents (hdr); cnt = image_get_image_size (hdr); break; #if defined(CONFIG_FIT) case IMAGE_FORMAT_FIT: fit_hdr = (const void *)addr; puts ("Fit image detected...\n"); cnt = fit_get_size (fit_hdr); break; #endif default: show_boot_progress (-39); puts ("** Unknown image type\n"); return 1; } show_boot_progress (39); cnt -= SECTORSIZE; if (doc_rw (doc_dev_desc + dev, 1, offset + SECTORSIZE, cnt, NULL, (u_char *)(addr+SECTORSIZE))) { printf ("** Read error on %d\n", dev); show_boot_progress (-40); return 1; } show_boot_progress (40); #if defined(CONFIG_FIT) /* This cannot be done earlier, we need complete FIT image in RAM first */ if (genimg_get_format ((void *)addr) == IMAGE_FORMAT_FIT) { if (!fit_check_format (fit_hdr)) { show_boot_progress (-130); puts ("** Bad FIT image format\n"); return 1; } show_boot_progress (131); fit_print_contents (fit_hdr); } #endif /* Loading ok, update default load address */ load_addr = addr; /* Check if we should attempt an auto-start */ if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) { char *local_args[2]; extern int do_bootm (cmd_tbl_t *, int, int, char *[]); local_args[0] = argv[0]; local_args[1] = NULL; printf ("Automatic boot of image at addr 0x%08lX ...\n", addr); do_bootm (cmdtp, 0, 1, local_args); rcode = 1; } return rcode; }
/* * Command loadpci: wait for signal from host and boot image. */ int do_loadpci(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { unsigned int *ptr = 0; int count = 0; int count2 = 0; int status; int i; char addr[16]; char str[] = "\\|/-"; char *local_args[2]; /* * Mark sync address */ ptr = 0; *ptr = 0xffffffff; puts("\nWaiting for image from pci host -"); /* * Wait for host to write the start address */ while (*ptr == 0xffffffff) { count++; if (!(count % 100)) { count2++; putc(0x08); /* backspace */ putc(str[count2 % 4]); } /* Abort if ctrl-c was pressed */ if (ctrlc()) { puts("\nAbort\n"); return 0; } udelay(1000); } if (*ptr == PCI_RECONFIG_MAGIC) { /* * Save own pci configuration in PRAM */ memset((char *)PCI_REGS_ADDR, 0, PCI_REGS_LEN); ptr = (unsigned int *)PCI_REGS_ADDR + 1; for (i=0; i<0x40; i+=4) { pci_read_config_dword(PCIDEVID_405GP, i, ptr++); } ptr = (unsigned int *)PCI_REGS_ADDR; *ptr = crc32(0, (uchar *)PCI_REGS_ADDR+4, PCI_REGS_LEN-4); printf("\nStoring PCI Configuration Regs...\n"); } else { sprintf(addr, "%08x", *ptr); /* * Boot image via bootm */ printf("\nBooting Image at addr 0x%s ...\n", addr); setenv("loadaddr", addr); local_args[0] = argv[0]; local_args[1] = NULL; status = do_bootm (cmdtp, 0, 1, local_args); } return 0; }
static int netboot_common (proto_t proto, cmd_tbl_t *cmdtp, int argc, char * const argv[]) { char *s; char *end; int rcode = 0; int size; ulong addr; /* pre-set load_addr */ if ((s = getenv("loadaddr")) != NULL) { load_addr = simple_strtoul(s, NULL, 16); } switch (argc) { case 1: break; case 2: /* * Only one arg - accept two forms: * Just load address, or just boot file name. The latter * form must be written in a format which can not be * mis-interpreted as a valid number. */ addr = simple_strtoul(argv[1], &end, 16); /* use default loadaddr address is 0 */ if (!addr) addr = load_addr; else if (end == (argv[1] + strlen(argv[1]))) load_addr = addr; else copy_filename(BootFile, argv[1], sizeof(BootFile)); break; case 3: addr = simple_strtoul(argv[1], &end, 16); /* use default loadaddr address is 0 */ if (!addr) addr = load_addr; else if (end == (argv[1] + strlen(argv[1]))) load_addr = addr; copy_filename (BootFile, argv[2], sizeof(BootFile)); break; default: show_boot_progress (-80); return cmd_usage(cmdtp); } show_boot_progress (80); if ((size = NetLoop(proto)) < 0) { show_boot_progress (-81); return 1; } show_boot_progress (81); /* NetLoop ok, update environment */ netboot_update_env(); /* done if no file was loaded (no errors though) */ if (size == 0) { show_boot_progress (-82); return 0; } /* flush cache */ flush_cache(load_addr, size); /* Loading ok, check if we should attempt an auto-start */ if (((s = getenv("autostart")) != NULL) && (strcmp(s,"yes") == 0)) { char *local_args[2]; local_args[0] = argv[0]; local_args[1] = NULL; printf ("Automatic boot of image at addr 0x%08lX ...\n", load_addr); show_boot_progress (82); rcode = do_bootm (cmdtp, 0, 1, local_args); } if (rcode < 0) show_boot_progress (-83); else show_boot_progress (84); return rcode; }
int do_stage_boot(cmd_tbl_t * cmdtb, int flag, int argc, char *argv[]) { char *path_to_image, *path_to_scr, *path_to_initrd, *all_partions; ulong addr; int j,i=1,step=0,len,index,device,initrd=0; char * kernel_addr, *bootargs; char * args_to_func[5]; char device_prt[4]; if(argc < 2){ printf("No args, try help stage_boot\n"); return 0; } path_to_initrd = (char *)malloc((strlen(SCRIPT_PATH)+strlen(getenv("initrd_name")))*sizeof(char)); strcpy(path_to_initrd,SCRIPT_PATH); strcat(path_to_initrd,getenv("initrd_name")); path_to_image = (char *)malloc((strlen(SCRIPT_PATH)+strlen(getenv("image_name")))*sizeof(char)); strcpy(path_to_image,SCRIPT_PATH); strcat(path_to_image,getenv("image_name")); path_to_scr = (char *)malloc((strlen(SCRIPT_PATH)+strlen(getenv("script_name")))*sizeof(char)); strcpy(path_to_scr,SCRIPT_PATH); strcat(path_to_scr,getenv("script_name")); all_partions = (char *)malloc(strlen(getenv("device_partition"))*sizeof(char)); strcpy(all_partions,getenv("device_partition")); kernel_addr = getenv("kernel_addr_r"); #if !defined(CONFIG_MACH_AVANTA_LP_FPGA) ide_init(); #endif for(device=1;device<argc;device++) { #if !defined(CONFIG_MACH_AVANTA_LP_FPGA) /* step 1 load script from ide */ len=strlen(all_partions); for(index=0;index<len && i==1 && strcmp(argv[device],"hd_scr")==0 ;index++) { step=1; for(j=0;j<3;j++,index++) device_prt[j]=all_partions[index]; device_prt[3]='\0'; printf("\ntry to load script from ide %s\n",device_prt); args_to_func[0]="ext2load"; args_to_func[1]=INTERFACE_HD; args_to_func[2]=device_prt; args_to_func[3]=LOAD_ADDR; args_to_func[4]=path_to_scr; i = do_ext2load(cmdtb, 1, 5 , args_to_func); addr = simple_strtoul(args_to_func[3], NULL, 16); } /* finish step 1 */ /* step 2 boot PXE */ if (i== 1 && strcmp(argv[device],"pxe") == 0) { step = 2; save_env(); setenv("boot_from_pxe","1"); setenv("autoload","no"); setenv("pxefile_addr_r",LOAD_ADDR); args_to_func[0]="dhcp"; args_to_func[1]=getenv("pxefile_addr_r"); i = do_dhcp(cmdtb, 1, 1, args_to_func); if(i==0) i = do_pxe_get(cmdtb, 1 , 1, args_to_func); setenv("boot_from_pxe","0"); if(i==1) restore_env(); } /* finish step 2 */ /* step 3 load linux image from ide */ if( i == 1 && strcmp(argv[device],"hd_img")==0 ) { step = 3; len=strlen(all_partions); for(index=0;index<len && i==1 ;index++) { for(j=0;j<3;j++,index++) device_prt[j]=all_partions[index]; device_prt[3]='\0'; printf("\ntry to load image from ide %s\n", device_prt); args_to_func[0]="ext2load"; args_to_func[1]=INTERFACE_HD; args_to_func[2]=device_prt; args_to_func[3]=getenv("kernel_addr_r"); args_to_func[4]=path_to_image; i = do_ext2load(cmdtb, 1, 5 , args_to_func); addr = simple_strtoul(args_to_func[3], NULL, 16); if( i==0 ){ int temp; args_to_func[3]=getenv("ramdisk_addr_r"); args_to_func[4]=path_to_initrd; temp = do_ext2load(cmdtb, 1, 5 , args_to_func); if(temp == 0) { initrd = 1; args_to_func[1] = getenv("kernel_addr_r"); args_to_func[2] = getenv("ramdisk_addr_r"); } } } } /* finish step 3 */ /*step 4 load script from tftp */ if( i == 1 && strcmp(argv[device],"net_scr")==0 ) { printf("\ntry to load script from tftp\n"); step = 4; args_to_func[0]="tftp"; args_to_func[1]=LOAD_ADDR; args_to_func[2]=getenv("script_name"); i = do_tftpb(cmdtb, 1, 3,args_to_func); addr = simple_strtoul(args_to_func[1], NULL, 16); } #endif /* finish step 4 */ /*step 5 load linux image from tftp */ if( i == 1 && strcmp(argv[device],"net_img")==0 ) { printf("\ntry to load image from tftp\n"); step = 5; args_to_func[0]="tftp"; args_to_func[1]=getenv("kernel_addr_r"); args_to_func[2]=getenv("image_name"); i = do_tftpb(cmdtb, 1, 3,args_to_func); addr = simple_strtoul(args_to_func[1], NULL, 16); } /* finish step 5 */ } free(path_to_image); free(path_to_scr); path_to_image = getenv("bootargs_dflt"); if(!path_to_image) { printf("missing environment variable: bootargs_dflt\n"); return 0; } if (step == 3 && initrd ==1){ setenv("bootargs_dflt","console=ttyS0,115200 earlyprintk=ttyS0 root=/dev/sda2 ro pm_disable"); } bootargs = (char *)malloc(sizeof(char)*(strlen(getenv("bootargs_dflt"))+17)); strcpy(bootargs,"setenv bootargs "); #ifndef CONFIG_SYS_HUSH_PARSER if (run_command(strcat(bootargs,getenv("bootargs_dflt")), flag) < 0) { printf("missing environment variable: bootargs_dflt\n"); return 0; } #else marvell_recursive_parse = 1; if (parse_string_outer(strcat(bootargs,getenv("bootargs_dflt")), FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0){ printf("missing environment variable: bootargs_dflt\n"); marvell_recursive_parse = 0; return 0; } marvell_recursive_parse = 0; #endif if(i==0) { if(step == 1 || step == 4) source(addr,NULL); else if ((step == 3 && initrd ==0 )|| step == 5) do_bootm(cmdtb, 1,1,(char * const*)kernel_addr); else if (step ==2) do_pxe_boot(cmdtb, 2, 1,(char * const *)NULL); else if (step == 3 && initrd ==1){ do_bootm(cmdtb, 1,2,args_to_func); } } else { printf("Unable to load image/script\n"); } return 1; }
int do_loadpci (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { char *s; ulong addr = 0, count = 0; u32 off; int cmd, rcode = 0; /* pre-set load_addr */ if ((s = getenv("loadaddr")) != NULL) { addr = simple_strtoul(s, NULL, 16); } switch (argc) { case 1: break; case 2: addr = simple_strtoul(argv[1], NULL, 16); break; default: printf ("Usage:\n%s\n", cmdtp->usage); return 1; } printf ("## Ready for image download ...\n"); show_startup_phase(12); while (1) { /* Alive indicator */ i2155x_write_scrapad(BOOT_PROTO, BOOT_PROTO_READY); /* Toggle status LEDs */ cmd = (count / 200) % 4; /* downscale */ set_led(4, cmd == 0 ? LED_1 : LED_0); set_led(5, cmd == 1 ? LED_1 : LED_0); set_led(6, cmd == 2 ? LED_1 : LED_0); set_led(7, cmd == 3 ? LED_1 : LED_0); udelay(1000); count++; cmd = i2155x_read_scrapad(BOOT_CMD); if (cmd == BOOT_CMD_MOVE) { off = i2155x_read_scrapad(BOOT_DATA); off += addr; i2155x_set_bar_base(3, off); printf ("## BAR3 Addr moved = 0x%08x\n", off); i2155x_write_scrapad(BOOT_CMD, ~cmd); show_startup_phase(13); } else if (cmd == BOOT_CMD_BOOT) { set_led(4, LED_1); set_led(5, LED_1); set_led(6, LED_1); set_led(7, LED_1); i2155x_write_scrapad(BOOT_CMD, ~cmd); show_startup_phase(14); break; } /* Abort if ctrl-c was pressed */ if (ctrlc()) { printf("\nAbort\n"); return 0; } } /* Repoint to the default shared memory */ i2155x_set_bar_base(3, PN62_SMEM_DEFAULT); load_addr = addr; printf ("## Start Addr = 0x%08lx\n", addr); show_startup_phase(15); /* Loading ok, check if we should attempt an auto-start */ if (((s = getenv("autostart")) != NULL) && (strcmp(s,"yes") == 0)) { char *local_args[2]; local_args[0] = argv[0]; local_args[1] = NULL; printf ("Automatic boot of image at addr 0x%08lX ...\n", load_addr); rcode = do_bootm (cmdtp, 0, 1, local_args); } #ifdef CONFIG_AUTOSCRIPT if (load_addr) { char *s; if (((s = getenv("autoscript")) != NULL) && (strcmp(s,"yes") == 0)) { printf("Running autoscript at addr 0x%08lX ...\n", load_addr); rcode = autoscript (bd, load_addr); } } #endif return rcode; }
/**************************************************************************** * main routine do_fdcboot */ int do_fdcboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { FD_GEO_STRUCT *pFG = (FD_GEO_STRUCT *)floppy_type; FDC_COMMAND_STRUCT *pCMD = &cmd; unsigned long addr,imsize; image_header_t *hdr; /* used for fdc boot */ unsigned char boot_drive; int i,nrofblk; char *ep; int rcode = 0; #if defined(CONFIG_FIT) const void *fit_hdr; #endif switch (argc) { case 1: addr = CFG_LOAD_ADDR; boot_drive=CFG_FDC_DRIVE_NUMBER; break; case 2: addr = simple_strtoul(argv[1], NULL, 16); boot_drive=CFG_FDC_DRIVE_NUMBER; break; case 3: addr = simple_strtoul(argv[1], NULL, 16); boot_drive=simple_strtoul(argv[2], NULL, 10); break; default: printf ("Usage:\n%s\n", cmdtp->usage); return 1; } /* setup FDC and scan for drives */ if(fdc_setup(boot_drive,pCMD,pFG)==FALSE) { printf("\n** Error in setup FDC **\n"); return 1; } if(fdc_check_drive(pCMD,pFG)==FALSE) { printf("\n** Error in check_drives **\n"); return 1; } if((pCMD->flags&(1<<boot_drive))==0) { /* drive not available */ printf("\n** Drive %d not availabe **\n",boot_drive); return 1; } if((pCMD->flags&(0x10<<boot_drive))==0) { /* no disk inserted */ printf("\n** No disk inserted in drive %d **\n",boot_drive); return 1; } /* ok, we have a valid source */ pCMD->drive=boot_drive; /* read first block */ pCMD->blnr=0; if(fdc_read_data((unsigned char *)addr,1,pCMD,pFG)==FALSE) { printf("\nRead error:"); for(i=0;i<7;i++) printf("result%d: 0x%02X\n",i,pCMD->result[i]); return 1; } switch (genimg_get_format ((void *)addr)) { case IMAGE_FORMAT_LEGACY: hdr = (image_header_t *)addr; image_print_contents (hdr); imsize = image_get_image_size (hdr); break; #if defined(CONFIG_FIT) case IMAGE_FORMAT_FIT: fit_hdr = (const void *)addr; if (!fit_check_format (fit_hdr)) { puts ("** Bad FIT image format\n"); return 1; } puts ("Fit image detected...\n"); imsize = fit_get_size (fit_hdr); break; #endif default: puts ("** Unknown image type\n"); return 1; } nrofblk=imsize/512; if((imsize%512)>0) nrofblk++; printf("Loading %ld Bytes (%d blocks) at 0x%08lx..\n",imsize,nrofblk,addr); pCMD->blnr=0; if(fdc_read_data((unsigned char *)addr,nrofblk,pCMD,pFG)==FALSE) { /* read image block */ printf("\nRead error:"); for(i=0;i<7;i++) printf("result%d: 0x%02X\n",i,pCMD->result[i]); return 1; } printf("OK %ld Bytes loaded.\n",imsize); flush_cache (addr, imsize); #if defined(CONFIG_FIT) /* This cannot be done earlier, we need complete FIT image in RAM first */ if (genimg_get_format ((void *)addr) == IMAGE_FORMAT_FIT) fit_print_contents ((const void *)addr); #endif /* Loading ok, update default load address */ load_addr = addr; /* Check if we should attempt an auto-start */ if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) { char *local_args[2]; extern int do_bootm (cmd_tbl_t *, int, int, char *[]); local_args[0] = argv[0]; local_args[1] = NULL; printf ("Automatic boot of image at addr 0x%08lX ...\n", addr); do_bootm (cmdtp, 0, 1, local_args); rcode ++; } return rcode; }
static int nand_load_image(cmd_tbl_t *cmdtp, nand_info_t *nand, ulong offset, ulong addr, char *cmd) { int r; char *ep, *s; size_t cnt; image_header_t *hdr; #if defined(CONFIG_FIT) const void *fit_hdr = NULL; #endif s = strchr(cmd, '.'); if (s != NULL && (strcmp(s, ".jffs2") && strcmp(s, ".e") && strcmp(s, ".i"))) { printf("Unknown nand load suffix '%s'\n", s); show_boot_progress(-53); return 1; } printf("\nLoading from %s, offset 0x%lx\n", nand->name, offset); cnt = nand->writesize; r = nand_read_skip_bad(nand, offset, &cnt, (u_char *) addr); if (r) { puts("** Read error\n"); show_boot_progress (-56); return 1; } show_boot_progress (56); switch (genimg_get_format ((void *)addr)) { case IMAGE_FORMAT_LEGACY: hdr = (image_header_t *)addr; show_boot_progress (57); image_print_contents (hdr); cnt = image_get_image_size (hdr); break; #if defined(CONFIG_FIT) case IMAGE_FORMAT_FIT: fit_hdr = (const void *)addr; puts ("Fit image detected...\n"); cnt = fit_get_size (fit_hdr); break; #endif default: show_boot_progress (-57); puts ("** Unknown image type\n"); return 1; } show_boot_progress (57); r = nand_read_skip_bad(nand, offset, &cnt, (u_char *) addr); if (r) { puts("** Read error\n"); show_boot_progress (-58); return 1; } show_boot_progress (58); #if defined(CONFIG_FIT) /* This cannot be done earlier, we need complete FIT image in RAM first */ if (genimg_get_format ((void *)addr) == IMAGE_FORMAT_FIT) { if (!fit_check_format (fit_hdr)) { show_boot_progress (-150); puts ("** Bad FIT image format\n"); return 1; } show_boot_progress (151); fit_print_contents (fit_hdr); } #endif /* Loading ok, update default load address */ load_addr = addr; /* Check if we should attempt an auto-start */ if (((ep = getenv("autostart")) != NULL) && (strcmp(ep, "yes") == 0)) { char *local_args[2]; extern int do_bootm(cmd_tbl_t *, int, int, char *[]); local_args[0] = cmd; local_args[1] = NULL; printf("Automatic boot of image at addr 0x%08lx ...\n", addr); do_bootm(cmdtp, 0, 1, local_args); return 1; } return 0; }
static int netboot_common(proto_t proto, cmd_tbl_t *cmdtp, int argc, char *argv[]) { char *s; int rcode = 0; int size; /* pre-set load_addr */ if((s = getenv("loadaddr")) != NULL) { load_addr = simple_strtoul(s, NULL, 16); } switch(argc) { case 1: break; case 2: /* only one arg - accept two forms: * just load address, or just boot file name. * The latter form must be written "filename" here. */ if(argv[1][0] == '"') { /* just boot filename */ copy_filename(BootFile, argv[1], sizeof(BootFile)); } else { /* load address */ load_addr = simple_strtoul(argv[1], NULL, 16); } break; case 3: load_addr = simple_strtoul(argv[1], NULL, 16); copy_filename(BootFile, argv[2], sizeof(BootFile)); break; default: #ifdef CFG_LONGHELP if(cmdtp->help != NULL) { printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->help); } else { printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->usage); } #else printf("Usage:\n%s %s\n", cmdtp->name, cmdtp->usage); #endif return 1; } if((size = NetLoop(proto)) < 0) { return(1); } /* NetLoop ok, update environment */ netboot_update_env(); /* done if no file was loaded (no errors though) */ if(size == 0) { return(0); } /* flush cache */ flush_cache(load_addr, size); /* Loading ok, check if we should attempt an auto-start */ if(((s = getenv("autostart")) != NULL) && (strcmp(s, "yes") == 0)) { char *local_args[2]; local_args[0] = argv[0]; local_args[1] = NULL; printf("Automatic boot of image at addr 0x%08lX ...\n", load_addr); rcode = do_bootm(cmdtp, 0, 1, local_args); } #ifdef CONFIG_AUTOSCRIPT if(((s = getenv("autoscript")) != NULL) && (strcmp(s,"yes") == 0)) { printf("Running autoscript at addr 0x%08lX ...\n", load_addr); rcode = autoscript(load_addr); } #endif return rcode; }
/****************************************************************************** * scsi boot command intepreter. Derived from diskboot */ int do_scsiboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { char *boot_device = NULL; char *ep; int dev, part = 0; ulong addr, cnt, checksum; disk_partition_t info; image_header_t *hdr; int rcode = 0; switch (argc) { case 1: addr = CFG_LOAD_ADDR; boot_device = getenv ("bootdevice"); break; case 2: addr = simple_strtoul(argv[1], NULL, 16); boot_device = getenv ("bootdevice"); break; case 3: addr = simple_strtoul(argv[1], NULL, 16); boot_device = argv[2]; break; default: printf ("Usage:\n%s\n", cmdtp->usage); return 1; } if (!boot_device) { puts ("\n** No boot device **\n"); return 1; } dev = simple_strtoul(boot_device, &ep, 16); printf("booting from dev %d\n",dev); if (scsi_dev_desc[dev].type == DEV_TYPE_UNKNOWN) { printf ("\n** Device %d not available\n", dev); return 1; } if (*ep) { if (*ep != ':') { puts ("\n** Invalid boot device, use `dev[:part]' **\n"); return 1; } part = simple_strtoul(++ep, NULL, 16); } if (get_partition_info (&scsi_dev_desc[dev], part, &info)) { printf("error reading partinfo\n"); return 1; } if ((strncmp((char *)(info.type), BOOT_PART_TYPE, sizeof(info.type)) != 0) && (strncmp((char *)(info.type), BOOT_PART_COMP, sizeof(info.type)) != 0)) { printf ("\n** Invalid partition type \"%.32s\"" " (expect \"" BOOT_PART_TYPE "\")\n", info.type); return 1; } printf ("\nLoading from SCSI device %d, partition %d: " "Name: %.32s Type: %.32s\n", dev, part, info.name, info.type); debug ("First Block: %ld, # of blocks: %ld, Block Size: %ld\n", info.start, info.size, info.blksz); if (scsi_read (dev, info.start, 1, (ulong *)addr) != 1) { printf ("** Read error on %d:%d\n", dev, part); return 1; } hdr = (image_header_t *)addr; if (ntohl(hdr->ih_magic) == IH_MAGIC) { printf("\n** Bad Magic Number **\n"); return 1; } checksum = ntohl(hdr->ih_hcrc); hdr->ih_hcrc = 0; if (crc32 (0, (uchar *)hdr, sizeof(image_header_t)) != checksum) { puts ("\n** Bad Header Checksum **\n"); return 1; } hdr->ih_hcrc = htonl(checksum); /* restore checksum for later use */ print_image_hdr (hdr); cnt = (ntohl(hdr->ih_size) + sizeof(image_header_t)); cnt += info.blksz - 1; cnt /= info.blksz; cnt -= 1; if (scsi_read (dev, info.start+1, cnt, (ulong *)(addr+info.blksz)) != cnt) { printf ("** Read error on %d:%d\n", dev, part); return 1; } /* Loading ok, update default load address */ load_addr = addr; flush_cache (addr, (cnt+1)*info.blksz); /* Check if we should attempt an auto-start */ if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) { char *local_args[2]; extern int do_bootm (cmd_tbl_t *, int, int, char *[]); local_args[0] = argv[0]; local_args[1] = NULL; printf ("Automatic boot of image at addr 0x%08lX ...\n", addr); rcode = do_bootm (cmdtp, 0, 1, local_args); } return rcode; }
int do_docboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { char *boot_device = NULL; char *ep; int dev; ulong cnt; ulong addr; ulong offset = 0; image_header_t *hdr; int rcode = 0; switch (argc) { case 1: addr = CFG_LOAD_ADDR; boot_device = getenv ("bootdevice"); break; case 2: addr = simple_strtoul(argv[1], NULL, 16); boot_device = getenv ("bootdevice"); break; case 3: addr = simple_strtoul(argv[1], NULL, 16); boot_device = argv[2]; break; case 4: addr = simple_strtoul(argv[1], NULL, 16); boot_device = argv[2]; offset = simple_strtoul(argv[3], NULL, 16); break; default: printf ("Usage:\n%s\n", cmdtp->usage); SHOW_BOOT_PROGRESS (-1); return 1; } if (!boot_device) { puts ("\n** No boot device **\n"); SHOW_BOOT_PROGRESS (-1); return 1; } dev = simple_strtoul(boot_device, &ep, 16); if ((dev >= CFG_MAX_DOC_DEVICE) || (doc_dev_desc[dev].ChipID == DOC_ChipID_UNKNOWN)) { printf ("\n** Device %d not available\n", dev); SHOW_BOOT_PROGRESS (-1); return 1; } printf ("\nLoading from device %d: %s at 0x%lX (offset 0x%lX)\n", dev, doc_dev_desc[dev].name, doc_dev_desc[dev].physadr, offset); if (doc_rw (doc_dev_desc + dev, 1, offset, SECTORSIZE, NULL, (u_char *)addr)) { printf ("** Read error on %d\n", dev); SHOW_BOOT_PROGRESS (-1); return 1; } hdr = (image_header_t *)addr; if (hdr->ih_magic == IH_MAGIC) { print_image_hdr (hdr); cnt = (ntohl(hdr->ih_size) + sizeof(image_header_t)); cnt -= SECTORSIZE; } else { puts ("\n** Bad Magic Number **\n"); SHOW_BOOT_PROGRESS (-1); return 1; } if (doc_rw (doc_dev_desc + dev, 1, offset + SECTORSIZE, cnt, NULL, (u_char *)(addr+SECTORSIZE))) { printf ("** Read error on %d\n", dev); SHOW_BOOT_PROGRESS (-1); return 1; } /* Loading ok, update default load address */ load_addr = addr; /* Check if we should attempt an auto-start */ if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) { char *local_args[2]; extern int do_bootm (cmd_tbl_t *, int, int, char *[]); local_args[0] = argv[0]; local_args[1] = NULL; printf ("Automatic boot of image at addr 0x%08lX ...\n", addr); do_bootm (cmdtp, 0, 1, local_args); rcode = 1; } return rcode; }
/* * Command loadpci: wait for signal from host and boot image. */ int do_loadpci(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { u32 *ptr = 0; int count = 0; int count2 = 0; char addr[16]; char str[] = "\\|/-"; char *local_args[2]; u32 la, ptm1la; #if defined(CONFIG_440) ptm1la = in32r(PCIX0_PTM1LA); #else ptm1la = in32r(PTM1LA); #endif while(1) { /* * Mark sync address */ ptr = (u32 *)ptm1la; memset(ptr, 0, 0x20); *ptr = 0xffffffff; puts("\nWaiting for action from pci host -"); /* * Wait for host to write the start address */ while (*ptr == 0xffffffff) { count++; if (!(count % 100)) { count2++; putc(0x08); /* backspace */ putc(str[count2 % 4]); } /* Abort if ctrl-c was pressed */ if (ctrlc()) { puts("\nAbort\n"); return 0; } udelay(1000); } printf("\nGot bootcode %08x: ", *ptr); la = ptm1la + (*ptr & ADDRMASK); sprintf(addr, "%08x", la); switch (*ptr & ~ADDRMASK) { case 0: /* * Boot image via bootm */ printf("booting image at addr 0x%s ...\n", addr); setenv("loadaddr", addr); do_bootm(cmdtp, 0, 0, NULL); break; case 1: /* * Boot image via autoscr */ printf("executing script at addr 0x%s ...\n", addr); local_args[0] = addr; local_args[1] = NULL; do_autoscript(cmdtp, 0, 1, local_args); break; case 2: /* * Call run_cmd */ printf("running command at addr 0x%s ...\n", addr); run_command((char*)la, 0); break; default: printf("unhandled boot method\n"); break; } } }
static int rx_handler (const unsigned char *buffer, unsigned int buffer_size) { int ret = 1; /* Use 65 instead of 64 null gets dropped strcpy's need the extra byte */ char response[65]; if (download_size) { /* Something to download */ if (buffer_size) { /* Handle possible overflow */ unsigned int transfer_size = download_size - download_bytes; if (buffer_size < transfer_size) transfer_size = buffer_size; /* Save the data to the transfer buffer */ memcpy (interface.transfer_buffer + download_bytes, buffer, transfer_size); download_bytes += transfer_size; /* Check if transfer is done */ if (download_bytes >= download_size) { /* Reset global transfer variable, Keep download_bytes because it will be used in the next possible flashing command */ download_size = 0; if (download_error) { /* There was an earlier error */ sprintf(response, "ERROR"); } else { /* Everything has transferred, send the OK response */ sprintf(response, "OKAY"); } fastboot_tx_status(response, strlen(response)); printf ("\ndownloading of %d bytes finished\n", download_bytes); #if defined(CONFIG_STORAGE_NAND) /* Pad to block length In most cases, padding the download to be block aligned is correct. The exception is when the following flash writes to the oob area. This happens when the image is a YAFFS image. Since we do not know what the download is until it is flashed, go ahead and pad it, but save the true size in case if should have been unpadded */ download_bytes_unpadded = download_bytes; if (interface.nand_block_size) { if (download_bytes % interface.nand_block_size) { unsigned int pad = interface.nand_block_size - (download_bytes % interface.nand_block_size); unsigned int i; for (i = 0; i < pad; i++) { if (download_bytes >= interface.transfer_buffer_size) break; interface.transfer_buffer[download_bytes] = 0; download_bytes++; } } } #endif } /* Provide some feedback */ if (download_bytes && 0 == (download_bytes % (16 * interface.nand_block_size))) { /* Some feeback that the download is happening */ if (download_error) printf("X"); else printf("."); if (0 == (download_bytes % (80 * 16 * interface.nand_block_size))) printf("\n"); } } else { /* Ignore empty buffers */ printf ("Warning empty download buffer\n"); printf ("Ignoring\n"); } ret = 0; } else { /* A command */ /* Cast to make compiler happy with string functions */ const char *cmdbuf = (char *) buffer; /* Generic failed response */ sprintf(response, "FAIL"); /* reboot Reboot the board. */ if(memcmp(cmdbuf, "reboot", 6) == 0) { sprintf(response,"OKAY"); fastboot_tx_status(response, strlen(response)); udelay (1000000); /* 1 sec */ do_reset (NULL, 0, 0, NULL); /* This code is unreachable, leave it to make the compiler happy */ return 0; } /* getvar Get common fastboot variables Board has a chance to handle other variables */ if(memcmp(cmdbuf, "getvar:", 7) == 0) { strcpy(response,"OKAY"); if(!strcmp(cmdbuf + strlen("version"), "version")) { strcpy(response + 4, FASTBOOT_VERSION); } else if(!strcmp(cmdbuf + strlen("product"), "product")) { if (interface.product_name) strcpy(response + 4, interface.product_name); } else if(!strcmp(cmdbuf + strlen("serialno"), "serialno")) { if (interface.serial_no) strcpy(response + 4, interface.serial_no); } else if(!strcmp(cmdbuf + strlen("downloadsize"), "downloadsize")) { if (interface.transfer_buffer_size) sprintf(response + 4, "08x", interface.transfer_buffer_size); } else { fastboot_getvar(cmdbuf + 7, response + 4); } ret = 0; } /* erase Erase a register flash partition Board has to set up flash partitions */ if(memcmp(cmdbuf, "erase:", 6) == 0){ #if defined(CONFIG_STORAGE_NAND) struct fastboot_ptentry *ptn; ptn = fastboot_flash_find_ptn(cmdbuf + 6); if(ptn == 0) { sprintf(response, "FAILpartition does not exist"); } else { char start[32], length[32]; int status, repeat, repeat_max; printf("erasing '%s'\n", ptn->name); char *lock[5] = { "nand", "lock", NULL, NULL, NULL, }; char *unlock[5] = { "nand", "unlock", NULL, NULL, NULL, }; char *erase[5] = { "nand", "erase", NULL, NULL, NULL, }; lock[2] = unlock[2] = erase[2] = start; lock[3] = unlock[3] = erase[3] = length; repeat_max = 1; if (ptn->flags & FASTBOOT_PTENTRY_FLAGS_REPEAT_MASK) repeat_max = ptn->flags & FASTBOOT_PTENTRY_FLAGS_REPEAT_MASK; sprintf (length, "0x%x", ptn->length); for (repeat = 0; repeat < repeat_max; repeat++) { sprintf (start, "0x%x", ptn->start + (repeat * ptn->length)); do_nand (NULL, 0, 4, unlock); status = do_nand (NULL, 0, 4, erase); do_nand (NULL, 0, 4, lock); if (status) break; } if (status) { sprintf(response,"FAILfailed to erase partition"); } else { printf("partition '%s' erased\n", ptn->name); sprintf(response, "OKAY"); } } #elif defined(CONFIG_STORAGE_EMMC) struct fastboot_ptentry *ptn; /* Save the MMC controller number */ mmc_controller_no = CFG_FASTBOOT_MMC_NO; /* Find the partition and erase it */ ptn = fastboot_flash_find_ptn(cmdbuf + 6); if (ptn == 0) { sprintf(response, "FAIL: partition doesn't exist"); } else { /* Call MMC erase function here */ char start[32], length[32]; char slot_no[32]; char *erase[5] = { "mmc", NULL, "erase", NULL, NULL, }; char *mmc_init[2] = {"mmcinit", NULL,}; mmc_init[1] = slot_no; erase[1] = slot_no; erase[3] = start; erase[4] = length; sprintf(slot_no, "%d", mmc_controller_no); sprintf(length, "0x%x", ptn->length); sprintf(start, "0x%x", ptn->start); printf("Initializing '%s'\n", ptn->name); if (do_mmc(NULL, 0, 2, mmc_init)) sprintf(response, "FAIL: Init of MMC card"); else sprintf(response, "OKAY"); printf("Erasing '%s'\n", ptn->name); if (do_mmc(NULL, 0, 5, erase)) { printf("Erasing '%s' FAILED!\n", ptn->name); sprintf(response, "FAIL: Erase partition"); } else { printf("Erasing '%s' DONE!\n", ptn->name); sprintf(response, "OKAY"); } } #endif ret = 0; } /* download download something .. What happens to it depends on the next command after data */ if(memcmp(cmdbuf, "download:", 9) == 0) { /* save the size */ download_size = simple_strtoul (cmdbuf + 9, NULL, 16); /* Reset the bytes count, now it is safe */ download_bytes = 0; /* Reset error */ download_error = 0; printf ("Starting download of %d bytes\n", download_size); if (0 == download_size) { /* bad user input */ sprintf(response, "FAILdata invalid size"); } else if (download_size > interface.transfer_buffer_size) { /* set download_size to 0 because this is an error */ download_size = 0; sprintf(response, "FAILdata too large"); } else { /* The default case, the transfer fits completely in the interface buffer */ sprintf(response, "DATA%08x", download_size); } ret = 0; } /* boot boot what was downloaded WARNING WARNING WARNING This is not what you expect. The fastboot client does its own packaging of the kernel. The layout is defined in the android header file bootimage.h. This layeout is copiedlooks like this, ** ** +-----------------+ ** | boot header | 1 page ** +-----------------+ ** | kernel | n pages ** +-----------------+ ** | ramdisk | m pages ** +-----------------+ ** | second stage | o pages ** +-----------------+ ** We only care about the kernel. So we have to jump past a page. What is a page size ? The fastboot client uses 2048 The is the default value of CFG_FASTBOOT_MKBOOTIMAGE_PAGE_SIZE */ if(memcmp(cmdbuf, "boot", 4) == 0) { if ((download_bytes) && (CFG_FASTBOOT_MKBOOTIMAGE_PAGE_SIZE < download_bytes)) { char start[32]; char *bootm[3] = { "bootm", NULL, NULL, }; char *go[3] = { "go", NULL, NULL, }; /* * Use this later to determine if a command line was passed * for the kernel. */ struct fastboot_boot_img_hdr *fb_hdr = (struct fastboot_boot_img_hdr *) interface.transfer_buffer; /* Skip the mkbootimage header */ image_header_t *hdr = (image_header_t *) &interface.transfer_buffer[CFG_FASTBOOT_MKBOOTIMAGE_PAGE_SIZE]; bootm[1] = go[1] = start; sprintf (start, "0x%x", hdr); /* Execution should jump to kernel so send the response now and wait a bit. */ sprintf(response, "OKAY"); fastboot_tx_status(response, strlen(response)); udelay (1000000); /* 1 sec */ if (ntohl(hdr->ih_magic) == IH_MAGIC) { /* Looks like a kernel.. */ printf ("Booting kernel..\n"); /* * Check if the user sent a bootargs down. * If not, do not override what is already there */ if (strlen ((char *) &fb_hdr->cmdline[0])) set_env ("bootargs", (char *) &fb_hdr->cmdline[0]); do_bootm (NULL, 0, 2, bootm); } else { /* Raw image, maybe another uboot */ printf ("Booting raw image..\n"); do_go (NULL, 0, 2, go); } printf ("ERROR : bootting failed\n"); printf ("You should reset the board\n"); } sprintf(response, "FAILinvalid boot image"); ret = 0; } /* flash Flash what was downloaded */ if(memcmp(cmdbuf, "flash:", 6) == 0) { #if defined(CONFIG_STORAGE_NAND) if (download_bytes) { struct fastboot_ptentry *ptn; ptn = fastboot_flash_find_ptn(cmdbuf + 6); if (ptn == 0) { sprintf(response, "FAILpartition does not exist"); } else if ((download_bytes > ptn->length) && !(ptn->flags & FASTBOOT_PTENTRY_FLAGS_WRITE_ENV)) { sprintf(response, "FAILimage too large for partition"); /* TODO : Improve check for yaffs write */ } else { /* Check if this is not really a flash write but rather a saveenv */ if (ptn->flags & FASTBOOT_PTENTRY_FLAGS_WRITE_ENV) { /* Since the response can only be 64 bytes, there is no point in having a large error message. */ char err_string[32]; if (saveenv_to_ptn(ptn, &err_string[0])) { printf("savenv '%s' failed : %s\n", ptn->name, err_string); sprintf(response, "FAIL%s", err_string); } else { printf("partition '%s' saveenv-ed\n", ptn->name); sprintf(response, "OKAY"); } } else { /* Normal case */ if (write_to_ptn(ptn)) { printf("flashing '%s' failed\n", ptn->name); sprintf(response, "FAILfailed to flash partition"); } else { printf("partition '%s' flashed\n", ptn->name); sprintf(response, "OKAY"); } } } } else { sprintf(response, "FAILno image downloaded"); } #elif defined(CONFIG_STORAGE_EMMC) if (download_bytes) { struct fastboot_ptentry *ptn; /* Save the MMC controller number */ mmc_controller_no = CFG_FASTBOOT_MMC_NO; /* Next is the partition name */ ptn = fastboot_flash_find_ptn(cmdbuf + 6); if (ptn == 0) { printf("Partition:'%s' does not exist\n", ptn->name); sprintf(response, "FAILpartition does not exist"); } else if ((download_bytes > ptn->length) && !(ptn->flags & FASTBOOT_PTENTRY_FLAGS_WRITE_ENV)) { printf("Image too large for the partition\n"); sprintf(response, "FAILimage too large for partition"); } else if (ptn->flags & FASTBOOT_PTENTRY_FLAGS_WRITE_ENV) { /* Check if this is not really a flash write, * but instead a saveenv */ unsigned int i = 0; /* Env file is expected with a NULL delimeter between * env variables So replace New line Feeds (0x0a) with * NULL (0x00) */ for (i = 0; i < download_bytes; i++) { if (interface.transfer_buffer[i] == 0x0a) interface.transfer_buffer[i] = 0x00; } memset(env_ptr->data, 0, ENV_SIZE); memcpy(env_ptr->data, interface.transfer_buffer, download_bytes); do_saveenv(NULL, 0, 1, NULL); printf("saveenv to '%s' DONE!\n", ptn->name); sprintf(response, "OKAY"); } else { /* Normal case */ char source[32], dest[32], length[32]; char slot_no[32]; printf("writing to partition '%s'\n", ptn->name); char *mmc_write[6] = {"mmc", NULL, "write", NULL, NULL, NULL}; char *mmc_init[2] = {"mmcinit", NULL,}; mmc_init[1] = slot_no; mmc_write[1] = slot_no; mmc_write[3] = source; mmc_write[4] = dest; mmc_write[5] = length; sprintf(slot_no, "%d", mmc_controller_no); sprintf(source, "0x%x", interface.transfer_buffer); sprintf(dest, "0x%x", ptn->start); sprintf(length, "0x%x", download_bytes); printf("Initializing '%s'\n", ptn->name); if (do_mmc(NULL, 0, 2, mmc_init)) sprintf(response, "FAIL:Init of MMC card"); else sprintf(response, "OKAY"); printf("Writing '%s'\n", ptn->name); if (do_mmc(NULL, 0, 6, mmc_write)) { printf("Writing '%s' FAILED!\n", ptn->name); sprintf(response, "FAIL: Write partition"); } else { printf("Writing '%s' DONE!\n", ptn->name); sprintf(response, "OKAY"); } } } else { sprintf(response, "FAILno image downloaded"); } #endif ret = 0; } /* continue Stop doing fastboot */ if (memcmp(cmdbuf, "continue", 8) == 0) { sprintf(response, "OKAY"); continue_booting = 1; ret = 0; } /* upload Upload just the data in a partition */ if ((memcmp(cmdbuf, "upload:", 7) == 0) || (memcmp(cmdbuf, "uploadraw:", 10) == 0)) { #if defined(CONFIG_STORAGE_NAND) unsigned int adv, delim_index, len; struct fastboot_ptentry *ptn; unsigned int is_raw = 0; /* Is this a raw read ? */ if (memcmp(cmdbuf, "uploadraw:", 10) == 0) { is_raw = 1; adv = 10; } else { adv = 7; } /* Scan to the next ':' to find when the size starts */ len = strlen(cmdbuf); for (delim_index = adv; delim_index < len; delim_index++) { if (cmdbuf[delim_index] == ':') { /* WARNING, cmdbuf is being modified. */ *((char *) &cmdbuf[delim_index]) = 0; break; } } ptn = fastboot_flash_find_ptn(cmdbuf + adv); if (ptn == 0) { sprintf(response, "FAILpartition does not exist"); } else { /* This is how much the user is expecting */ unsigned int user_size; /* * This is the maximum size needed for * this partition */ unsigned int size; /* This is the length of the data */ unsigned int length; /* * Used to check previous write of * the parition */ char env_ptn_length_var[128]; char *env_ptn_length_val; user_size = 0; if (delim_index < len) user_size = simple_strtoul(cmdbuf + delim_index + 1, NULL, 16); /* Make sure output is padded to block size */ length = ptn->length; sprintf(env_ptn_length_var, "%s_nand_size", ptn->name); env_ptn_length_val = getenv(env_ptn_length_var); if (env_ptn_length_val) { length = simple_strtoul(env_ptn_length_val, NULL, 16); /* Catch possible problems */ if (!length) length = ptn->length; } size = length / interface.nand_block_size; size *= interface.nand_block_size; if (length % interface.nand_block_size) size += interface.nand_block_size; if (is_raw) size += (size / interface.nand_block_size) * interface.nand_oob_size; if (size > interface.transfer_buffer_size) { sprintf(response, "FAILdata too large"); } else if (user_size == 0) { /* Send the data response */ sprintf(response, "DATA%08x", size); } else if (user_size != size) { /* This is the wrong size */ sprintf(response, "FAIL"); } else { /* * This is where the transfer * buffer is populated */ unsigned char *buf = interface.transfer_buffer; char start[32], length[32], type[32], addr[32]; char *read[6] = { "nand", NULL, NULL, NULL, NULL, NULL, }; /* * Setting upload_size causes * transfer to happen in main loop */ upload_size = size; upload_bytes = 0; upload_error = 0; /* * Poison the transfer buffer, 0xff * is erase value of nand */ memset(buf, 0xff, upload_size); /* Which flavor of read to use */ if (is_raw) sprintf(type, "read.raw"); else sprintf(type, "read.i"); sprintf(addr, "0x%x", interface.transfer_buffer); sprintf(start, "0x%x", ptn->start); sprintf(length, "0x%x", upload_size); read[1] = type; read[2] = addr; read[3] = start; read[4] = length; set_ptn_ecc(ptn); do_nand(NULL, 0, 5, read); /* Send the data response */ sprintf(response, "DATA%08x", size); } } #endif ret = 0; } fastboot_tx_status(response, strlen(response)); } /* End of command */ return ret; }
static int netboot_common (int proto, cmd_tbl_t *cmdtp, int argc, char *argv[]) { char *s; int rcode = 0; int size; printf("\n netboot_common, argc= %d \n", argc); /* pre-set load_addr */ if ((s = getenv("loadaddr")) != NULL) { load_addr = simple_strtoul(s, NULL, 16); } switch (argc) { case 1: break; case 2: /* only one arg - accept two forms: * just load address, or just boot file name. * The latter form must be written "filename" here. */ if (argv[1][0] == '"') { /* just boot filename */ copy_filename (BootFile, argv[1], sizeof(BootFile)); } else { /* load address */ load_addr = simple_strtoul(argv[1], NULL, 16); } break; case 3: load_addr = simple_strtoul(argv[1], NULL, 16); copy_filename (BootFile, argv[2], sizeof(BootFile)); #ifdef DEBUG printf("load addr= 0x%08x\n", load_addr); printf("boot file= %s\n", BootFile); #endif break; default: printf ("Usage:\n%s\n", cmdtp->usage); return 1; } if ((size = NetLoop(proto)) < 0) return 1; printf("NetBootFileXferSize= %08x\n", size); /* NetLoop ok, update environment */ #if (CONFIG_COMMANDS & CFG_CMD_ENV) netboot_update_env(); #endif /* done if no file was loaded (no errors though) */ if (size == 0) return 0; /* flush cache */ flush_cache(load_addr, size); /* Loading ok, check if we should attempt an auto-start */ if (((s = getenv("autostart")) != NULL) && (strcmp(s,"yes") == 0)) { char *local_args[2]; local_args[0] = argv[0]; local_args[1] = NULL; if(modifies) { setenv("autostart", "no"); setenv ("bootfile", BootFile); #ifdef DEBUG s = getenv("bootfile"); printf("save bootfile= %s\n", s); #endif #if (CONFIG_COMMANDS & CFG_CMD_ENV) saveenv(); #endif } printf ("Automatic boot of image at addr 0x%08lX ...\n", load_addr); rcode = do_bootm (cmdtp, 0, 1, local_args); } #ifdef CONFIG_AUTOSCRIPT if (((s = getenv("autoscript")) != NULL) && (strcmp(s,"yes") == 0)) { printf("Running autoscript at addr 0x%08lX ...\n", load_addr); rcode = autoscript (load_addr); } #endif return rcode; }
/****************************************************************************** * scsi boot command intepreter. Derived from diskboot */ int do_scsiboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { char *boot_device = NULL; char *ep; int dev, part = 0; ulong addr, cnt; disk_partition_t info; image_header_t *hdr; int rcode = 0; #if defined(CONFIG_FIT) const void *fit_hdr = NULL; #endif switch (argc) { case 1: addr = CONFIG_SYS_LOAD_ADDR; boot_device = getenv ("bootdevice"); break; case 2: addr = simple_strtoul(argv[1], NULL, 16); boot_device = getenv ("bootdevice"); break; case 3: addr = simple_strtoul(argv[1], NULL, 16); boot_device = argv[2]; break; default: cmd_usage(cmdtp); return 1; } if (!boot_device) { puts ("\n** No boot device **\n"); return 1; } dev = simple_strtoul(boot_device, &ep, 16); printf("booting from dev %d\n",dev); if (scsi_dev_desc[dev].type == DEV_TYPE_UNKNOWN) { printf ("\n** Device %d not available\n", dev); return 1; } if (*ep) { if (*ep != ':') { puts ("\n** Invalid boot device, use `dev[:part]' **\n"); return 1; } part = simple_strtoul(++ep, NULL, 16); } if (get_partition_info (&scsi_dev_desc[dev], part, &info)) { printf("error reading partinfo\n"); return 1; } if ((strncmp((char *)(info.type), BOOT_PART_TYPE, sizeof(info.type)) != 0) && (strncmp((char *)(info.type), BOOT_PART_COMP, sizeof(info.type)) != 0)) { printf ("\n** Invalid partition type \"%.32s\"" " (expect \"" BOOT_PART_TYPE "\")\n", info.type); return 1; } printf ("\nLoading from SCSI device %d, partition %d: " "Name: %.32s Type: %.32s\n", dev, part, info.name, info.type); debug ("First Block: %ld, # of blocks: %ld, Block Size: %ld\n", info.start, info.size, info.blksz); if (scsi_read (dev, info.start, 1, (ulong *)addr) != 1) { printf ("** Read error on %d:%d\n", dev, part); return 1; } switch (genimg_get_format ((void *)addr)) { case IMAGE_FORMAT_LEGACY: hdr = (image_header_t *)addr; if (!image_check_hcrc (hdr)) { puts ("\n** Bad Header Checksum **\n"); return 1; } image_print_contents (hdr); cnt = image_get_image_size (hdr); break; #if defined(CONFIG_FIT) case IMAGE_FORMAT_FIT: fit_hdr = (const void *)addr; puts ("Fit image detected...\n"); cnt = fit_get_size (fit_hdr); break; #endif default: puts ("** Unknown image type\n"); return 1; } cnt += info.blksz - 1; cnt /= info.blksz; cnt -= 1; if (scsi_read (dev, info.start+1, cnt, (ulong *)(addr+info.blksz)) != cnt) { printf ("** Read error on %d:%d\n", dev, part); return 1; } #if defined(CONFIG_FIT) /* This cannot be done earlier, we need complete FIT image in RAM first */ if (genimg_get_format ((void *)addr) == IMAGE_FORMAT_FIT) { if (!fit_check_format (fit_hdr)) { puts ("** Bad FIT image format\n"); return 1; } fit_print_contents (fit_hdr); } #endif /* Loading ok, update default load address */ load_addr = addr; flush_cache (addr, (cnt+1)*info.blksz); /* Check if we should attempt an auto-start */ if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) { char *local_args[2]; extern int do_bootm (cmd_tbl_t *, int, int, char *[]); local_args[0] = argv[0]; local_args[1] = NULL; printf ("Automatic boot of image at addr 0x%08lX ...\n", addr); rcode = do_bootm (cmdtp, 0, 1, local_args); } return rcode; }