static void import_efi_partition(struct efi_entry *entry, int count, u8 silent) { struct fastboot_ptentry e; int ret = 0; ret = memcmp(entry->type_uuid, partition_type, sizeof(partition_type)); if (ret != 0) { DBG("memcmp failed for count=%d, ret = %d. entry->type_uuid " "and partition_type are mismatched.\n", count, ret); return; } strcpy(e.name, (convert_ptn_name_to_unicode(entry))); e.start = entry->first_lba; e.length = (entry->last_lba - entry->first_lba + 1) * 512; e.flags = 0; if (!strcmp(e.name, "environment")) e.flags |= FASTBOOT_PTENTRY_FLAGS_WRITE_ENV; fastboot_flash_add_ptn(&e, count); if (!silent) { if (e.length > 0x100000) DBG("%8d %7dM %s\n", e.start, (u32)(e.length/0x100000), e.name); else DBG("%8d %7dK %s\n", e.start, (u32)(e.length/0x400), e.name); } }
void fastboot_flash_partition_init(void) { fastboot_ptentry fb_part; int index, part_total; char partition_sets[128]; char part_name[16] = "nanda"; char *pa_index; int boot_part_flag; printf("--------fastboot partitions--------\n"); part_total = sunxi_partition_get_total_num(); printf("-total partitions:%d-\n", part_total); printf("%-12s %-12s %-12s\n", "-name-", "-start-", "-size-"); memset(partition_sets, ' ', 128); boot_part_flag = 0; pa_index = partition_sets; for(index = 0; index < part_total && index < MBR_MAX_PART_COUNT; index++) { sunxi_partition_get_name(index, &fb_part.name[0]); fb_part.start = sunxi_partition_get_offset(index) * 512; fb_part.length = sunxi_partition_get_size(index) * 512; fb_part.flags = 0; printf("%-12s: %-12x %-12x\n", fb_part.name, fb_part.start, fb_part.length); fastboot_flash_add_ptn(&fb_part); if(!strcmp(fb_part.name, "boot")) { boot_part_flag = 1; } if(boot_part_flag) { strcpy(pa_index, part_name); pa_index += strlen(part_name); *pa_index = '@'; pa_index ++; strcpy(pa_index, fb_part.name); pa_index += strlen(fb_part.name); *pa_index = ':' ; pa_index ++; part_name[4] ++; } } pa_index--; *pa_index = '\0'; printf("-----------------------------------\n"); setenv("partitions", partition_sets); }
void import_efi_partition(struct efi_entry *entry) { struct fastboot_ptentry e; int n; #ifdef USE_ONLY_GPT_DATA_PARTITIONS if (memcmp(entry->type_uuid, windows_partition_type, sizeof(windows_partition_type)) && memcmp(entry->type_uuid, linux_partition_type, sizeof(linux_partition_type))) return; #else if (!memcmp(entry->type_uuid, empty_partition_type, sizeof(empty_partition_type))) return; #endif for (n = 0; n < (sizeof(e.name)-1); n++) e.name[n] = entry->name[n]; e.name[n] = 0; e.start = entry->first_lba; e.length = (entry->last_lba - entry->first_lba + 1) * 512; e.flags = 0; if (!strcmp(e.name,"environment")) e.flags |= FASTBOOT_PTENTRY_FLAGS_WRITE_ENV; fastboot_flash_add_ptn(&e); }
void import_efi_partition(struct efi_entry *entry) { struct fastboot_ptentry e; int n; if (memcmp(entry->type_uuid, partition_type, sizeof(partition_type))) return; for (n = 0; n < (sizeof(e.name)-1); n++) e.name[n] = entry->name[n]; e.name[n] = 0; e.start = entry->first_lba; e.length = (entry->last_lba - entry->first_lba + 1) * 512; e.flags = 0; if (!strcmp(e.name,"environment")) e.flags |= FASTBOOT_PTENTRY_FLAGS_WRITE_ENV; fastboot_flash_add_ptn(&e); if (e.length > 0x100000) printf("%8d %7dM %s\n", e.start, (u32)(e.length/0x100000), e.name); else printf("%8d %7dK %s\n", e.start, (u32)(e.length/0x400), e.name); }
void fastboot_partition_init(void) { fastboot_ptentry fb_part; int index, part_total; char partition_sets[PARTITION_SETS_MAX_SIZE]; char part_name[16]; char *partition_index = partition_sets; int offset = 0; int temp_offset = 0; int storage_type = uboot_spare_head.boot_data.storage_type; printf("--------fastboot partitions--------\n"); part_total = sunxi_partition_get_total_num(); if((part_total <= 0) || (part_total > SUNXI_MBR_MAX_PART_COUNT)) { printf("mbr not exist\n"); return ; } printf("-total partitions:%d-\n", part_total); printf("%-12s %-12s %-12s\n", "-name-", "-start-", "-size-"); memset(partition_sets, 0, PARTITION_SETS_MAX_SIZE); for(index = 0; index < part_total && index < SUNXI_MBR_MAX_PART_COUNT; index++) { sunxi_partition_get_name(index, &fb_part.name[0]); fb_part.start = sunxi_partition_get_offset(index) * 512; fb_part.length = sunxi_partition_get_size(index) * 512; fb_part.flags = 0; printf("%-12s: %-12x %-12x\n", fb_part.name, fb_part.start, fb_part.length); memset(part_name, 0, 16); if(!storage_type) { sprintf(part_name, "nand%c", 'a' + index); } else { if(index == 0) { strcpy(part_name, "mmcblk0p2"); } else if( (index+1)==part_total) { strcpy(part_name, "mmcblk0p1"); } else { sprintf(part_name, "mmcblk0p%d", index + 4); } } temp_offset = strlen(fb_part.name) + strlen(part_name) + 2; if(temp_offset >= PARTITION_SETS_MAX_SIZE) { printf("partition_sets is too long, please reduces partition name\n"); break; } fastboot_flash_add_ptn(&fb_part); sprintf(partition_index, "%s@%s:", fb_part.name, part_name); offset += temp_offset; partition_index = partition_sets + offset; } partition_sets[offset-1] = '\0'; partition_sets[PARTITION_SETS_MAX_SIZE - 1] = '\0'; printf("-----------------------------------\n"); setenv("partitions", partition_sets); }
static int add_partition_from_environment(char *s, char **retptr) { unsigned long size; unsigned long offset = 0; char *name; int name_len; int delim; unsigned int flags; struct fastboot_ptentry part; size = memparse(s, &s); if (0 == size) { printf("Error:FASTBOOT size of parition is 0\n"); return 1; } /* fetch partition name and flags */ flags = 0; /* this is going to be a regular partition */ delim = 0; /* check for offset */ if (*s == '@') { s++; offset = memparse(s, &s); } else { printf("Error:FASTBOOT offset of parition is not given\n"); return 1; } /* now look for name */ if (*s == '(') delim = ')'; if (delim) { char *p; name = ++s; p = strchr((const char *)name, delim); if (!p) { printf("Error:FASTBOOT no closing %c found in partition name\n", delim); return 1; } name_len = p - name; s = p + 1; } else { printf("Error:FASTBOOT no partition name for \'%s\'\n", s); return 1; } /* test for options */ while (1) { if (strncmp(s, "i", 1) == 0) { flags |= FASTBOOT_PTENTRY_FLAGS_WRITE_I; s += 1; } else if (strncmp(s, "yaffs", 5) == 0) { /* yaffs */ flags |= FASTBOOT_PTENTRY_FLAGS_WRITE_YAFFS; s += 5; } else if (strncmp(s, "swecc", 5) == 0) { /* swecc */ flags |= FASTBOOT_PTENTRY_FLAGS_WRITE_SW_ECC; s += 5; } else if (strncmp(s, "hwecc", 5) == 0) { /* hwecc */ flags |= FASTBOOT_PTENTRY_FLAGS_WRITE_HW_ECC; s += 5; } else { break; } if (strncmp(s, "|", 1) == 0) s += 1; } /* enter this partition (offset will be calculated later if it is zero at this point) */ part.length = size; part.start = offset; part.flags = flags; if (name) { if (name_len >= sizeof(part.name)) { printf("Error:FASTBOOT partition name is too long\n"); return 1; } strncpy(&part.name[0], name, name_len); /* name is not null terminated */ part.name[name_len] = '\0'; } else { printf("Error:FASTBOOT no name\n"); return 1; } /* Check if this overlaps a static partition */ if (check_against_static_partition(&part)) { printf("Adding: %s, offset 0x%8.8x, size 0x%8.8x, flags 0x%8.8x\n", part.name, part.start, part.length, part.flags); fastboot_flash_add_ptn(&part); } /* return (updated) pointer command line string */ *retptr = s; /* return partition table */ return 0; }
/* booti <addr> [ mmc0 | mmc1 [ <partition> ] ] */ int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { unsigned addr = 0; char *ptn = "boot"; int mmcc = -1; boot_img_hdr *hdr = (void *)boothdr; #ifdef CONFIG_SECURE_BOOT u_int32_t load_addr; uint32_t image_size; #endif if (argc < 2) return -1; if (!strncmp(argv[1], "mmc", 3)) mmcc = simple_strtoul(argv[1]+3, NULL, 10); else addr = simple_strtoul(argv[1], NULL, 16); if (argc > 2) ptn = argv[2]; if (mmcc != -1) { #ifdef CONFIG_MMC struct fastboot_ptentry *pte; struct mmc *mmc; disk_partition_t info; block_dev_desc_t *dev_desc = NULL; unsigned sector, partno = -1; memset((void *)&info, 0 , sizeof(disk_partition_t)); /* i.MX use MBR as partition table, so this will have to find the start block and length for the partition name and register the fastboot pte we define the partition number of each partition in config file */ mmc = find_mmc_device(mmcc); if (!mmc) { printf("booti: cannot find '%d' mmc device\n", mmcc); goto fail; } dev_desc = get_dev("mmc", mmcc); if (NULL == dev_desc) { printf("** Block device MMC %d not supported\n", mmcc); goto fail; } /* below was i.MX mmc operation code */ if (mmc_init(mmc)) { printf("mmc%d init failed\n", mmcc); goto fail; } #ifdef CONFIG_ANDROID_BOOT_PARTITION_MMC #ifdef CONFIG_ANDROID_RECOVERY_PARTITION_MMC if (!strcmp(ptn, "boot")) partno = CONFIG_ANDROID_BOOT_PARTITION_MMC; if (!strcmp(ptn, "recovery")) partno = CONFIG_ANDROID_RECOVERY_PARTITION_MMC; if (get_partition_info(dev_desc, partno, &info)) { printf("booti: device don't have such partition:%s\n", ptn); goto fail; } #endif #endif #ifdef CONFIG_FASTBOOT fastboot_ptentry the_partition = { .start = info.start, .length = info.start * info.blksz, .flags = 0, .partition_id = 0, }; strncpy(the_partition.name, ptn, 10); fastboot_flash_add_ptn(&the_partition); /* fastboot_flash_dump_ptn(); */ pte = fastboot_flash_find_ptn(ptn); if (!pte) { printf("booti: cannot find '%s' partition\n", ptn); goto fail; } if (mmc->block_dev.block_read(mmcc, pte->start, 1, (void *)hdr) < 0) { printf("booti: mmc failed to read bootimg header\n"); goto fail; } /* flush cache after read */ flush_cache((ulong)hdr, 512); /* FIXME */ if (memcmp(hdr->magic, BOOT_MAGIC, 8)) { printf("booti: bad boot image magic\n"); goto fail; } sector = pte->start + (hdr->page_size / 512); #else if (mmc->block_dev.block_read(mmcc, info.start, 1, (void *)hdr) < 0) { printf("booti: mmc failed to read bootimg header\n"); goto fail; } /* flush cache after read */ flush_cache((ulong)hdr, 512); /* FIXME */ if (memcmp(hdr->magic, BOOT_MAGIC, 8)) { printf("booti: bad boot image magic\n"); goto fail; } sector = info.start + (hdr->page_size / 512); #endif if (mmc->block_dev.block_read(mmcc, sector, (hdr->kernel_size / 512) + 1, (void *)hdr->kernel_addr) < 0) { printf("booti: mmc failed to read kernel\n"); goto fail; } /* flush cache after read */ flush_cache((ulong)hdr->kernel_addr, hdr->kernel_size); /* FIXME */ sector += ALIGN_SECTOR(hdr->kernel_size, hdr->page_size) / 512; if (mmc->block_dev.block_read(mmcc, sector, (hdr->ramdisk_size / 512) + 1, (void *)hdr->ramdisk_addr) < 0) { printf("booti: mmc failed to read kernel\n"); goto fail; } /* flush cache after read */ flush_cache((ulong)hdr->ramdisk_addr, hdr->ramdisk_size); /* FIXME */ #else return -1; #endif } else { unsigned kaddr, raddr; /* set this aside somewhere safe */ memcpy(hdr, (void *) addr, sizeof(*hdr)); if (memcmp(hdr->magic, BOOT_MAGIC, 8)) { printf("booti: bad boot image magic\n"); return 1; } bootimg_print_image_hdr(hdr); kaddr = addr + hdr->page_size; raddr = kaddr + ALIGN_SECTOR(hdr->kernel_size, hdr->page_size); memmove((void *) hdr->kernel_addr, (void *)kaddr, hdr->kernel_size); memmove((void *) hdr->ramdisk_addr, (void *)raddr, hdr->ramdisk_size); } printf("kernel @ %08x (%d)\n", hdr->kernel_addr, hdr->kernel_size); printf("ramdisk @ %08x (%d)\n", hdr->ramdisk_addr, hdr->ramdisk_size); #ifdef CONFIG_SECURE_BOOT #define IVT_SIZE 0x20 #define CSF_PAD_SIZE 0x2000 extern uint32_t authenticate_image(uint32_t ddr_start, uint32_t image_size); image_size = hdr->ramdisk_addr + hdr->ramdisk_size - hdr->kernel_addr - IVT_SIZE - CSF_PAD_SIZE; if (authenticate_image(hdr->kernel_addr, image_size)) printf("Authentication Successful\n"); else printf("Authentication Failed\n"); #endif do_booti_linux(hdr); puts ("booti: Control returned to monitor - resetting...\n"); do_reset (cmdtp, flag, argc, argv); return 1; fail: #ifdef CONFIG_FASTBOOT return do_fastboot(NULL, 0, 0, NULL); #else return -1; #endif }
void fastboot_flash_partition_init(void) { fastboot_ptentry fb_part; int index, part_total; char partition_sets[1024]; char part_name[32]; char *pa_index; int part_name_count; printf("--------fastboot partitions--------\n"); part_total = sunxi_partition_get_total_num(); if((part_total <= 0) || (part_total > MBR_MAX_PART_COUNT)) { printf("mbr not exist\n"); return ; } printf("-total partitions:%d-\n", part_total); printf("%-12s %-12s %-12s\n", "-name-", "-start-", "-size-"); memset(partition_sets, ' ', sizeof(partition_sets)); memset(part_name, 0, sizeof(part_name)); if(!storage_type) { memcpy(part_name, "nanda", 5); } else { memcpy(part_name, "mmcblk0p2", 9); part_name_count = 2; } pa_index = partition_sets; for(index = 0; index < part_total && index < MBR_MAX_PART_COUNT; index++) { sunxi_partition_get_name(index, &fb_part.name[0]); fb_part.start = sunxi_partition_get_offset(index) * 512; fb_part.length = sunxi_partition_get_size(index) * 512; fb_part.flags = 0; printf("%-12s: %-12x %-12x\n", fb_part.name, fb_part.start>>9, fb_part.length>>9); fastboot_flash_add_ptn(&fb_part); strcpy(pa_index, fb_part.name); pa_index += strlen(fb_part.name); *pa_index = '@' ; pa_index ++; strcpy(pa_index, part_name); pa_index += strlen(part_name); *pa_index = ':'; pa_index ++; if(!storage_type) { part_name[4] ++; } else { part_name_count ++; if(part_name_count < 5) { part_name_count = 5; part_name[8] = '5'; } else if(part_name_count < 10) { part_name[8] ++; } else if(part_name_count == 10) { part_name[8] = '1'; part_name[9] = '0'; } else { part_name[9] ++; } } } pa_index--; if(storage_type) { if(part_name_count > 10) { pa_index--; } else { *(pa_index - 1) = '1'; } } *pa_index = '\0'; printf("-----------------------------------\n"); setenv("partitions", partition_sets); }