Lines Matching refs:gpt_h

89 static int validate_gpt_header(gpt_header *gpt_h, lbaint_t lba,  in validate_gpt_header()  argument
96 if (le64_to_cpu(gpt_h->signature) != GPT_HEADER_SIGNATURE_UBOOT) { in validate_gpt_header()
99 le64_to_cpu(gpt_h->signature), in validate_gpt_header()
105 memcpy(&crc32_backup, &gpt_h->header_crc32, sizeof(crc32_backup)); in validate_gpt_header()
106 memset(&gpt_h->header_crc32, 0, sizeof(gpt_h->header_crc32)); in validate_gpt_header()
108 calc_crc32 = efi_crc32((const unsigned char *)gpt_h, in validate_gpt_header()
109 le32_to_cpu(gpt_h->header_size)); in validate_gpt_header()
111 memcpy(&gpt_h->header_crc32, &crc32_backup, sizeof(crc32_backup)); in validate_gpt_header()
123 if (le64_to_cpu(gpt_h->my_lba) != lba) { in validate_gpt_header()
125 le64_to_cpu(gpt_h->my_lba), lba); in validate_gpt_header()
133 if (le64_to_cpu(gpt_h->first_usable_lba) > lastlba) { in validate_gpt_header()
135 le64_to_cpu(gpt_h->first_usable_lba), lastlba); in validate_gpt_header()
138 if (le64_to_cpu(gpt_h->last_usable_lba) > lastlba) { in validate_gpt_header()
140 le64_to_cpu(gpt_h->last_usable_lba), lastlba); in validate_gpt_header()
145 LBAF "\n", le64_to_cpu(gpt_h->first_usable_lba), in validate_gpt_header()
146 le64_to_cpu(gpt_h->last_usable_lba), lastlba); in validate_gpt_header()
151 static int validate_gpt_entries(gpt_header *gpt_h, gpt_entry *gpt_e) in validate_gpt_entries() argument
157 le32_to_cpu(gpt_h->num_partition_entries) * in validate_gpt_entries()
158 le32_to_cpu(gpt_h->sizeof_partition_entry)); in validate_gpt_entries()
160 if (calc_crc32 != le32_to_cpu(gpt_h->partition_entry_array_crc32)) { in validate_gpt_entries()
163 le32_to_cpu(gpt_h->partition_entry_array_crc32), in validate_gpt_entries()
171 static void prepare_backup_gpt_header(gpt_header *gpt_h) in prepare_backup_gpt_header() argument
177 val = le64_to_cpu(gpt_h->my_lba); in prepare_backup_gpt_header()
178 gpt_h->my_lba = gpt_h->alternate_lba; in prepare_backup_gpt_header()
179 gpt_h->alternate_lba = cpu_to_le64(val); in prepare_backup_gpt_header()
180 gpt_h->partition_entry_lba = in prepare_backup_gpt_header()
181 cpu_to_le64(le64_to_cpu(gpt_h->last_usable_lba) + 1); in prepare_backup_gpt_header()
182 gpt_h->header_crc32 = 0; in prepare_backup_gpt_header()
184 calc_crc32 = efi_crc32((const unsigned char *)gpt_h, in prepare_backup_gpt_header()
185 le32_to_cpu(gpt_h->header_size)); in prepare_backup_gpt_header()
186 gpt_h->header_crc32 = cpu_to_le32(calc_crc32); in prepare_backup_gpt_header()
363 gpt_header *gpt_h, gpt_entry *gpt_e) in write_gpt_table() argument
365 const int pte_blk_cnt = BLOCK_CNT((gpt_h->num_partition_entries in write_gpt_table()
376 le32_to_cpu(gpt_h->num_partition_entries) * in write_gpt_table()
377 le32_to_cpu(gpt_h->sizeof_partition_entry)); in write_gpt_table()
378 gpt_h->partition_entry_array_crc32 = cpu_to_le32(calc_crc32); in write_gpt_table()
380 calc_crc32 = efi_crc32((const unsigned char *)gpt_h, in write_gpt_table()
381 le32_to_cpu(gpt_h->header_size)); in write_gpt_table()
382 gpt_h->header_crc32 = cpu_to_le32(calc_crc32); in write_gpt_table()
385 if (blk_dwrite(dev_desc, 1, 1, gpt_h) != 1) in write_gpt_table()
388 if (blk_dwrite(dev_desc, le64_to_cpu(gpt_h->partition_entry_lba), in write_gpt_table()
392 prepare_backup_gpt_header(gpt_h); in write_gpt_table()
394 if (blk_dwrite(dev_desc, (lbaint_t)le64_to_cpu(gpt_h->last_usable_lba) in write_gpt_table()
398 if (blk_dwrite(dev_desc, (lbaint_t)le64_to_cpu(gpt_h->my_lba), 1, in write_gpt_table()
399 gpt_h) != 1) in write_gpt_table()
411 gpt_header *gpt_h, gpt_entry *gpt_e, in gpt_fill_pte() argument
414 lbaint_t offset = (lbaint_t)le64_to_cpu(gpt_h->first_usable_lba); in gpt_fill_pte()
416 le64_to_cpu(gpt_h->last_usable_lba); in gpt_fill_pte()
427 size_t hdr_start = gpt_h->my_lba; in gpt_fill_pte()
430 size_t pte_start = gpt_h->partition_entry_lba; in gpt_fill_pte()
432 gpt_h->num_partition_entries * gpt_h->sizeof_partition_entry / in gpt_fill_pte()
466 gpt_e[i].ending_lba = gpt_h->last_usable_lba; in gpt_fill_pte()
576 int gpt_fill_header(struct blk_desc *dev_desc, gpt_header *gpt_h, in gpt_fill_header() argument
579 gpt_h->signature = cpu_to_le64(GPT_HEADER_SIGNATURE_UBOOT); in gpt_fill_header()
580 gpt_h->revision = cpu_to_le32(GPT_HEADER_REVISION_V1); in gpt_fill_header()
581 gpt_h->header_size = cpu_to_le32(sizeof(gpt_header)); in gpt_fill_header()
582 gpt_h->my_lba = cpu_to_le64(1); in gpt_fill_header()
583 gpt_h->alternate_lba = cpu_to_le64(dev_desc->lba - 1); in gpt_fill_header()
584 gpt_h->last_usable_lba = cpu_to_le64(dev_desc->lba - 34); in gpt_fill_header()
585 gpt_h->partition_entry_lba = in gpt_fill_header()
587 gpt_h->first_usable_lba = in gpt_fill_header()
588 cpu_to_le64(le64_to_cpu(gpt_h->partition_entry_lba) + 32); in gpt_fill_header()
589 gpt_h->num_partition_entries = cpu_to_le32(GPT_ENTRY_NUMBERS); in gpt_fill_header()
590 gpt_h->sizeof_partition_entry = cpu_to_le32(sizeof(gpt_entry)); in gpt_fill_header()
591 gpt_h->header_crc32 = 0; in gpt_fill_header()
592 gpt_h->partition_entry_array_crc32 = 0; in gpt_fill_header()
594 if (uuid_str_to_bin(str_guid, gpt_h->disk_guid.b, UUID_STR_FORMAT_GUID)) in gpt_fill_header()
603 gpt_header *gpt_h; in gpt_restore() local
608 gpt_h = malloc_cache_aligned(size); in gpt_restore()
609 if (gpt_h == NULL) { in gpt_restore()
613 memset(gpt_h, 0, size); in gpt_restore()
620 free(gpt_h); in gpt_restore()
626 ret = gpt_fill_header(dev_desc, gpt_h, str_disk_guid, parts_count); in gpt_restore()
631 ret = gpt_fill_pte(dev_desc, gpt_h, gpt_e, partitions, parts_count); in gpt_restore()
636 ret = write_gpt_table(dev_desc, gpt_h, gpt_e); in gpt_restore()
640 free(gpt_h); in gpt_restore()
701 static void restore_primary_gpt_header(gpt_header *gpt_h, struct blk_desc *dev_desc) in restore_primary_gpt_header() argument
707 val = le64_to_cpu(gpt_h->my_lba); in restore_primary_gpt_header()
708 gpt_h->my_lba = gpt_h->alternate_lba; in restore_primary_gpt_header()
709 gpt_h->alternate_lba = cpu_to_le64(val); in restore_primary_gpt_header()
710 gpt_h->partition_entry_lba = cpu_to_le64(partition_entries_offset(dev_desc)); in restore_primary_gpt_header()
712 gpt_h->header_crc32 = 0; in restore_primary_gpt_header()
714 calc_crc32 = efi_crc32((const unsigned char *)gpt_h, in restore_primary_gpt_header()
715 le32_to_cpu(gpt_h->header_size)); in restore_primary_gpt_header()
716 gpt_h->header_crc32 = cpu_to_le32(calc_crc32); in restore_primary_gpt_header()
720 gpt_header *gpt_h, gpt_entry *gpt_e) in write_one_gpt_table() argument
722 const int pte_blk_cnt = BLOCK_CNT((gpt_h->num_partition_entries in write_one_gpt_table()
727 start = le64_to_cpu(gpt_h->my_lba); in write_one_gpt_table()
728 if (blk_dwrite(dev_desc, start, 1, gpt_h) != 1) { in write_one_gpt_table()
733 start = le64_to_cpu(gpt_h->partition_entry_lba); in write_one_gpt_table()
867 gpt_header *gpt_h; in is_valid_gpt_buf() local
871 gpt_h = buf + (GPT_PRIMARY_PARTITION_TABLE_LBA * in is_valid_gpt_buf()
873 if (validate_gpt_header(gpt_h, GPT_PRIMARY_PARTITION_TABLE_LBA, in is_valid_gpt_buf()
878 gpt_e = buf + (le64_to_cpu(gpt_h->partition_entry_lba) * in is_valid_gpt_buf()
880 if (validate_gpt_entries(gpt_h, gpt_e)) in is_valid_gpt_buf()
888 gpt_header *gpt_h; in write_mbr_and_gpt_partitions() local
898 gpt_h = buf + (GPT_PRIMARY_PARTITION_TABLE_LBA * in write_mbr_and_gpt_partitions()
902 gpt_e = buf + (le64_to_cpu(gpt_h->partition_entry_lba) * in write_mbr_and_gpt_partitions()
904 gpt_e_blk_cnt = BLOCK_CNT((le32_to_cpu(gpt_h->num_partition_entries) * in write_mbr_and_gpt_partitions()
905 le32_to_cpu(gpt_h->sizeof_partition_entry)), in write_mbr_and_gpt_partitions()
920 if (blk_dwrite(dev_desc, lba, cnt, gpt_h) != cnt) { in write_mbr_and_gpt_partitions()
926 lba = le64_to_cpu(gpt_h->partition_entry_lba); in write_mbr_and_gpt_partitions()
934 prepare_backup_gpt_header(gpt_h); in write_mbr_and_gpt_partitions()
937 lba = le64_to_cpu(gpt_h->partition_entry_lba); in write_mbr_and_gpt_partitions()
945 lba = le64_to_cpu(gpt_h->my_lba); in write_mbr_and_gpt_partitions()
947 if (blk_dwrite(dev_desc, lba, cnt, gpt_h) != cnt) { in write_mbr_and_gpt_partitions()