Lines Matching refs:dev_desc
46 static int is_gpt_valid(struct blk_desc *dev_desc, u64 lba,
48 static gpt_entry *alloc_read_gpt_entries(struct blk_desc *dev_desc,
197 int get_disk_guid(struct blk_desc * dev_desc, char *guid) in get_disk_guid() argument
199 ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz); in get_disk_guid()
204 if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA, in get_disk_guid()
207 if (is_gpt_valid(dev_desc, dev_desc->lba - 1, in get_disk_guid()
224 void part_print_efi(struct blk_desc *dev_desc) in part_print_efi() argument
226 ALLOC_CACHE_ALIGN_BUFFER_PAD(gpt_header, gpt_head, 1, dev_desc->blksz); in part_print_efi()
233 if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA, in part_print_efi()
236 if (is_gpt_valid(dev_desc, (dev_desc->lba - 1), in part_print_efi()
281 int part_get_info_efi(struct blk_desc *dev_desc, int part, in part_get_info_efi() argument
288 gpt_head = memalign(ARCH_DMA_MINALIGN, dev_desc->blksz); in part_get_info_efi()
294 if (gpt_head && (gpt_head->last_usable_lba + 0x22) != dev_desc->lba) { in part_get_info_efi()
307 if (is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA, in part_get_info_efi()
310 if (is_gpt_valid(dev_desc, (dev_desc->lba - 1), in part_get_info_efi()
333 info->blksz = dev_desc->blksz; in part_get_info_efi()
356 static void gpt_entry_modify(struct blk_desc *dev_desc, in gpt_entry_modify() argument
368 if (gpt_pte[i - 1].ending_lba <= (dev_desc->lba - 0x22)) in gpt_entry_modify()
371 gpt_pte[i - 1].ending_lba = dev_desc->lba - 0x41; in gpt_entry_modify()
378 static int part_efi_repair(struct blk_desc *dev_desc, gpt_entry *gpt_pte, in part_efi_repair() argument
392 gpt_head->my_lba = dev_desc->lba - 1; in part_efi_repair()
394 gpt_head->partition_entry_lba = dev_desc->lba - 0x21; in part_efi_repair()
395 gpt_head->last_usable_lba = cpu_to_le64(dev_desc->lba - 34); in part_efi_repair()
396 gpt_entry_modify(dev_desc, gpt_pte, gpt_head); in part_efi_repair()
400 if (blk_dwrite(dev_desc, dev_desc->lba - 1, 1, gpt_head) != 1) { in part_efi_repair()
407 blk_cnt = BLOCK_CNT(count, dev_desc); in part_efi_repair()
408 if (blk_dwrite(dev_desc, blk, (lbaint_t)blk_cnt, gpt_pte) != in part_efi_repair()
417 gpt_head->alternate_lba = dev_desc->lba - 1; in part_efi_repair()
419 gpt_head->last_usable_lba = cpu_to_le64(dev_desc->lba - 34); in part_efi_repair()
420 gpt_entry_modify(dev_desc, gpt_pte, gpt_head); in part_efi_repair()
424 if (blk_dwrite(dev_desc, 1, 1, gpt_head) != 1) { in part_efi_repair()
431 blk_cnt = BLOCK_CNT(count, dev_desc); in part_efi_repair()
432 if (blk_dwrite(dev_desc, blk, (lbaint_t)blk_cnt, gpt_pte) != in part_efi_repair()
445 static int part_test_efi(struct blk_desc *dev_desc) in part_test_efi() argument
447 ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, legacymbr, 1, dev_desc->blksz); in part_test_efi()
451 if ((blk_dread(dev_desc, 0, 1, (ulong *)legacymbr) != 1) in part_test_efi()
465 h_gpt_head = memalign(ARCH_DMA_MINALIGN, dev_desc->blksz); in part_test_efi()
467 b_gpt_head = memalign(ARCH_DMA_MINALIGN, dev_desc->blksz); in part_test_efi()
469 head_gpt_valid = is_gpt_valid(dev_desc, GPT_PRIMARY_PARTITION_TABLE_LBA, in part_test_efi()
471 backup_gpt_valid = is_gpt_valid(dev_desc, (dev_desc->lba - 1), in part_test_efi()
477 if (part_efi_repair(dev_desc, h_gpt_pte, h_gpt_head, in part_test_efi()
485 if (part_efi_repair(dev_desc, h_gpt_pte, h_gpt_head, in part_test_efi()
489 if (part_efi_repair(dev_desc, b_gpt_pte, b_gpt_head, in part_test_efi()
515 static int set_protective_mbr(struct blk_desc *dev_desc) in set_protective_mbr() argument
527 if (blk_dread(dev_desc, 0, 1, p_mbr) != 1) { in set_protective_mbr()
528 pr_err("** Can't read from device %d **\n", dev_desc->devnum); in set_protective_mbr()
536 p_mbr->partition_record[0].nr_sects = (u32) dev_desc->lba - 1; in set_protective_mbr()
539 if (blk_dwrite(dev_desc, 0, 1, p_mbr) != 1) { in set_protective_mbr()
541 dev_desc->devnum); in set_protective_mbr()
548 int write_gpt_table(struct blk_desc *dev_desc, in write_gpt_table() argument
552 * sizeof(gpt_entry)), dev_desc); in write_gpt_table()
555 debug("max lba: %x\n", (u32) dev_desc->lba); in write_gpt_table()
557 if (set_protective_mbr(dev_desc) < 0) in write_gpt_table()
571 if (blk_dwrite(dev_desc, 1, 1, gpt_h) != 1) in write_gpt_table()
574 if (blk_dwrite(dev_desc, le64_to_cpu(gpt_h->partition_entry_lba), in write_gpt_table()
580 if (blk_dwrite(dev_desc, (lbaint_t)le64_to_cpu(gpt_h->last_usable_lba) in write_gpt_table()
584 if (blk_dwrite(dev_desc, (lbaint_t)le64_to_cpu(gpt_h->my_lba), 1, in write_gpt_table()
592 printf("** Can't write to device %d **\n", dev_desc->devnum); in write_gpt_table()
596 int gpt_fill_pte(struct blk_desc *dev_desc, in gpt_fill_pte() argument
619 dev_desc->blksz; in gpt_fill_pte()
716 static uint32_t partition_entries_offset(struct blk_desc *dev_desc) in partition_entries_offset() argument
732 PAD_TO_BLOCKSIZE(CONFIG_EFI_PARTITION_ENTRIES_OFF, dev_desc); in partition_entries_offset()
733 offset_blks = offset_bytes / dev_desc->blksz; in partition_entries_offset()
746 offset_bytes = PAD_TO_BLOCKSIZE(config_offset, dev_desc); in partition_entries_offset()
747 offset_blks = offset_bytes / dev_desc->blksz; in partition_entries_offset()
763 int gpt_fill_header(struct blk_desc *dev_desc, gpt_header *gpt_h, in gpt_fill_header() argument
770 gpt_h->alternate_lba = cpu_to_le64(dev_desc->lba - 1); in gpt_fill_header()
771 gpt_h->last_usable_lba = cpu_to_le64(dev_desc->lba - 34); in gpt_fill_header()
773 cpu_to_le64(partition_entries_offset(dev_desc)); in gpt_fill_header()
787 int gpt_restore(struct blk_desc *dev_desc, char *str_disk_guid, in gpt_restore() argument
794 size = PAD_TO_BLOCKSIZE(sizeof(gpt_header), dev_desc); in gpt_restore()
803 dev_desc); in gpt_restore()
813 ret = gpt_fill_header(dev_desc, gpt_h, str_disk_guid, parts_count); in gpt_restore()
818 ret = gpt_fill_pte(dev_desc, gpt_h, gpt_e, partitions, parts_count); in gpt_restore()
823 ret = write_gpt_table(dev_desc, gpt_h, gpt_e); in gpt_restore()
854 int gpt_verify_headers(struct blk_desc *dev_desc, gpt_header *gpt_head, in gpt_verify_headers() argument
861 if (is_gpt_valid(dev_desc, in gpt_verify_headers()
868 if (is_gpt_valid(dev_desc, (dev_desc->lba - 1), in gpt_verify_headers()
878 int gpt_verify_partitions(struct blk_desc *dev_desc, in gpt_verify_partitions() argument
887 ret = gpt_verify_headers(dev_desc, gpt_head, gpt_pte); in gpt_verify_partitions()
956 int is_valid_gpt_buf(struct blk_desc *dev_desc, void *buf) in is_valid_gpt_buf() argument
963 dev_desc->blksz); in is_valid_gpt_buf()
966 != cpu_to_le64(dev_desc->lba) && in is_valid_gpt_buf()
974 dev_desc->lba)) in is_valid_gpt_buf()
979 dev_desc->blksz); in is_valid_gpt_buf()
986 int write_mbr_and_gpt_partitions(struct blk_desc *dev_desc, void *buf) in write_mbr_and_gpt_partitions() argument
994 if (is_valid_gpt_buf(dev_desc, buf)) in write_mbr_and_gpt_partitions()
999 dev_desc->blksz); in write_mbr_and_gpt_partitions()
1003 dev_desc->blksz); in write_mbr_and_gpt_partitions()
1006 dev_desc); in write_mbr_and_gpt_partitions()
1011 if (blk_dwrite(dev_desc, lba, cnt, buf) != cnt) { in write_mbr_and_gpt_partitions()
1020 if (blk_dwrite(dev_desc, lba, cnt, gpt_h) != cnt) { in write_mbr_and_gpt_partitions()
1028 if (blk_dwrite(dev_desc, lba, cnt, gpt_e) != cnt) { in write_mbr_and_gpt_partitions()
1039 if (blk_dwrite(dev_desc, lba, cnt, gpt_e) != cnt) { in write_mbr_and_gpt_partitions()
1047 if (blk_dwrite(dev_desc, lba, cnt, gpt_h) != cnt) { in write_mbr_and_gpt_partitions()
1120 static int is_gpt_valid(struct blk_desc *dev_desc, u64 lba, in is_gpt_valid() argument
1124 if (!dev_desc || !pgpt_head) { in is_gpt_valid()
1133 ALLOC_CACHE_ALIGN_BUFFER(legacy_mbr, mbr, dev_desc->blksz); in is_gpt_valid()
1136 if (blk_dread(dev_desc, 0, 1, (ulong *)mbr) != 1) { in is_gpt_valid()
1142 if (blk_dread(dev_desc, (lbaint_t)lba, 1, pgpt_head) != 1) { in is_gpt_valid()
1147 if (validate_gpt_header(pgpt_head, (lbaint_t)lba, dev_desc->lba)) in is_gpt_valid()
1150 if (dev_desc->sig_type == SIG_TYPE_NONE) { in is_gpt_valid()
1153 dev_desc->sig_type = SIG_TYPE_GUID; in is_gpt_valid()
1154 memcpy(&dev_desc->guid_sig, &pgpt_head->disk_guid, in is_gpt_valid()
1157 dev_desc->sig_type = SIG_TYPE_MBR; in is_gpt_valid()
1158 dev_desc->mbr_sig = mbr->unique_mbr_signature; in is_gpt_valid()
1163 *pgpt_pte = alloc_read_gpt_entries(dev_desc, pgpt_head); in is_gpt_valid()
1188 static gpt_entry *alloc_read_gpt_entries(struct blk_desc *dev_desc, in alloc_read_gpt_entries() argument
1195 if (!dev_desc || !pgpt_head) { in alloc_read_gpt_entries()
1211 PAD_TO_BLOCKSIZE(count, dev_desc)); in alloc_read_gpt_entries()
1222 blk_cnt = BLOCK_CNT(count, dev_desc); in alloc_read_gpt_entries()
1223 if (blk_dread(dev_desc, blk, (lbaint_t)blk_cnt, pte) != blk_cnt) { in alloc_read_gpt_entries()