/* Check the GPT header signature */
if (le64_to_cpu(gpt_h->signature) != GPT_HEADER_SIGNATURE_UBOOT) {
- printf("%s signature is wrong: 0x%llX != 0x%llX\n",
- "GUID Partition Table Header",
- le64_to_cpu(gpt_h->signature),
- GPT_HEADER_SIGNATURE_UBOOT);
+ log_debug("%s signature is wrong: %#llX != %#llX\n",
+ "GUID Partition Table Header",
+ le64_to_cpu(gpt_h->signature),
+ GPT_HEADER_SIGNATURE_UBOOT);
return -1;
}
memcpy(&gpt_h->header_crc32, &crc32_backup, sizeof(crc32_backup));
if (calc_crc32 != le32_to_cpu(crc32_backup)) {
- printf("%s CRC is wrong: 0x%x != 0x%x\n",
- "GUID Partition Table Header",
- le32_to_cpu(crc32_backup), calc_crc32);
+ log_debug("%s: CRC is wrong: %#x != %#x\n",
+ "GUID Partition Table Header",
+ le32_to_cpu(crc32_backup), calc_crc32);
return -1;
}
* Check that the my_lba entry points to the LBA that contains the GPT
*/
if (le64_to_cpu(gpt_h->my_lba) != lba) {
- printf("GPT: my_lba incorrect: %llX != " LBAF "\n",
- le64_to_cpu(gpt_h->my_lba),
- lba);
+ log_debug("GPT: my_lba incorrect: %llX != " LBAF "\n",
+ le64_to_cpu(gpt_h->my_lba), lba);
return -1;
}
* within the disk.
*/
if (le64_to_cpu(gpt_h->first_usable_lba) > lastlba) {
- printf("GPT: first_usable_lba incorrect: %llX > " LBAF "\n",
- le64_to_cpu(gpt_h->first_usable_lba), lastlba);
+ log_debug("GPT: first_usable_lba incorrect: %llX > " LBAF "\n",
+ le64_to_cpu(gpt_h->first_usable_lba), lastlba);
return -1;
}
if (le64_to_cpu(gpt_h->last_usable_lba) > lastlba) {
- printf("GPT: last_usable_lba incorrect: %llX > " LBAF "\n",
- le64_to_cpu(gpt_h->last_usable_lba), lastlba);
+ log_debug("GPT: last_usable_lba incorrect: %llX > " LBAF "\n",
+ le64_to_cpu(gpt_h->last_usable_lba), lastlba);
return -1;
}
le32_to_cpu(gpt_h->sizeof_partition_entry));
if (calc_crc32 != le32_to_cpu(gpt_h->partition_entry_array_crc32)) {
- printf("%s: 0x%x != 0x%x\n",
- "GUID Partition Table Entry Array CRC is wrong",
- le32_to_cpu(gpt_h->partition_entry_array_crc32),
- calc_crc32);
+ log_debug("%s: %#x != %#x\n",
+ "GUID Partition Table Entry Array CRC is wrong",
+ le32_to_cpu(gpt_h->partition_entry_array_crc32),
+ calc_crc32);
return -1;
}
if (part > le32_to_cpu(gpt_head->num_partition_entries) ||
!is_pte_valid(&gpt_pte[part - 1])) {
- log_debug("*** ERROR: Invalid partition number %d ***\n", part);
+ log_debug("Invalid partition number %d\n", part);
free(gpt_pte);
return -EPERM;
}
/* Setup the Protective MBR */
ALLOC_CACHE_ALIGN_BUFFER_PAD(legacy_mbr, p_mbr, 1, dev_desc->blksz);
if (p_mbr == NULL) {
- printf("%s: calloc failed!\n", __func__);
- return -1;
+ log_debug("calloc failed!\n");
+ return -ENOMEM;
}
/* Read MBR to backup boot code if it exists */
if (blk_dread(dev_desc, 0, 1, p_mbr) != 1) {
- pr_err("** Can't read from device %d **\n", dev_desc->devnum);
- return -1;
+ log_debug("** Can't read from device %d **\n",
+ dev_desc->devnum);
+ return -EIO;
}
/* Clear all data in MBR except of backed up boot code */
/* Write MBR sector to the MMC device */
if (blk_dwrite(dev_desc, 0, 1, p_mbr) != 1) {
- printf("** Can't write to device %d **\n",
- dev_desc->devnum);
- return -1;
+ log_debug("** Can't write to device %d **\n", dev_desc->devnum);
+ return -EIO;
}
return 0;
return 0;
err:
- printf("** Can't write to device %d **\n", dev_desc->devnum);
- return -1;
+ log_debug("** Can't write to device %d **\n", dev_desc->devnum);
+ return -EIO;
}
int gpt_fill_pte(struct blk_desc *dev_desc,
*/
if (((start < hdr_end && hdr_start < (start + size)) ||
(start < pte_end && pte_start < (start + size)))) {
- printf("Partition overlap\n");
- return -1;
+ log_debug("Partition overlap\n");
+ return -ENOSPC;
}
gpt_e[i].starting_lba = cpu_to_le64(start);
if (offset > (last_usable_lba + 1)) {
- printf("Partitions layout exceds disk size\n");
- return -1;
+ log_debug("Partitions layout exceeds disk size\n");
+ return -E2BIG;
}
/* partition ending lba */
if ((i == parts - 1) && (size == 0))
if (strlen(str_type_guid)) {
if (uuid_str_to_bin(str_type_guid, bin_type_guid,
UUID_STR_FORMAT_GUID)) {
- printf("Partition no. %d: invalid type guid: %s\n",
- i, str_type_guid);
- return -1;
+ log_debug("Partition no. %d: invalid type guid: %s\n",
+ i, str_type_guid);
+ return -EINVAL;
}
} else {
/* default partition type GUID */
bin_uuid = gpt_e[i].unique_partition_guid.b;
if (uuid_str_to_bin(str_uuid, bin_uuid, UUID_STR_FORMAT_GUID)) {
- printf("Partition no. %d: invalid guid: %s\n",
- i, str_uuid);
- return -1;
+ log_debug("Partition no. %d: invalid guid: %s\n",
+ i, str_uuid);
+ return -EINVAL;
}
#endif
size = PAD_TO_BLOCKSIZE(sizeof(gpt_header), dev_desc);
gpt_h = malloc_cache_aligned(size);
if (gpt_h == NULL) {
- printf("%s: calloc failed!\n", __func__);
- return -1;
+ log_debug("calloc failed!\n");
+ return -ENOMEM;
}
memset(gpt_h, 0, size);
dev_desc);
gpt_e = malloc_cache_aligned(size);
if (gpt_e == NULL) {
- printf("%s: calloc failed!\n", __func__);
+ log_debug("calloc failed!\n");
free(gpt_h);
- return -1;
+ return -ENOMEM;
}
memset(gpt_e, 0, size);
if (is_gpt_valid(dev_desc,
GPT_PRIMARY_PARTITION_TABLE_LBA,
gpt_head, gpt_pte) != 1) {
- printf("%s: *** ERROR: Invalid GPT ***\n",
- __func__);
+ log_debug("Invalid GPT\n");
return -1;
}
* Check that the alternate_lba entry points to the last LBA
*/
if (le64_to_cpu(gpt_head->alternate_lba) != (dev_desc->lba - 1)) {
- printf("%s: *** ERROR: Misplaced Backup GPT ***\n",
- __func__);
+ log_debug("Misplaced Backup GPT\n");
return -1;
}
if (is_gpt_valid(dev_desc, (dev_desc->lba - 1),
gpt_head, gpt_pte) != 1) {
- printf("%s: *** ERROR: Invalid Backup GPT ***\n",
- __func__);
+ log_debug("Invalid Backup GPT\n");
return -1;
}
lba = 0; /* MBR is always at 0 */
cnt = 1; /* MBR (1 block) */
if (blk_dwrite(dev_desc, lba, cnt, buf) != cnt) {
- printf("%s: failed writing '%s' (%d blks at 0x" LBAF ")\n",
- __func__, "MBR", cnt, lba);
+ log_debug("failed writing '%s' (%d blks at 0x" LBAF ")\n",
+ "MBR", cnt, lba);
return 1;
}
lba = GPT_PRIMARY_PARTITION_TABLE_LBA;
cnt = 1; /* GPT Header (1 block) */
if (blk_dwrite(dev_desc, lba, cnt, gpt_h) != cnt) {
- printf("%s: failed writing '%s' (%d blks at 0x" LBAF ")\n",
- __func__, "Primary GPT Header", cnt, lba);
+ log_debug("failed writing '%s' (%d blks at 0x" LBAF ")\n",
+ "Primary GPT Header", cnt, lba);
return 1;
}
lba = le64_to_cpu(gpt_h->partition_entry_lba);
cnt = gpt_e_blk_cnt;
if (blk_dwrite(dev_desc, lba, cnt, gpt_e) != cnt) {
- printf("%s: failed writing '%s' (%d blks at 0x" LBAF ")\n",
- __func__, "Primary GPT Entries", cnt, lba);
+ log_debug("failed writing '%s' (%d blks at 0x" LBAF ")\n",
+ "Primary GPT Entries", cnt, lba);
return 1;
}
lba = le64_to_cpu(gpt_h->partition_entry_lba);
cnt = gpt_e_blk_cnt;
if (blk_dwrite(dev_desc, lba, cnt, gpt_e) != cnt) {
- printf("%s: failed writing '%s' (%d blks at 0x" LBAF ")\n",
- __func__, "Backup GPT Entries", cnt, lba);
+ log_debug("failed writing '%s' (%d blks at 0x" LBAF ")\n",
+ "Backup GPT Entries", cnt, lba);
return 1;
}
lba = le64_to_cpu(gpt_h->my_lba);
cnt = 1; /* GPT Header (1 block) */
if (blk_dwrite(dev_desc, lba, cnt, gpt_h) != cnt) {
- printf("%s: failed writing '%s' (%d blks at 0x" LBAF ")\n",
- __func__, "Backup GPT Header", cnt, lba);
+ log_debug("failed writing '%s' (%d blks at 0x" LBAF ")\n",
+ "Backup GPT Header", cnt, lba);
return 1;
}
{
/* Confirm valid arguments prior to allocation. */
if (!dev_desc || !pgpt_head) {
- printf("%s: Invalid Argument(s)\n", __func__);
+ log_debug("Invalid Argument(s)\n");
return 0;
}
/* Read MBR Header from device */
if (blk_dread(dev_desc, 0, 1, (ulong *)mbr) != 1) {
- printf("*** ERROR: Can't read MBR header ***\n");
+ log_debug("Can't read MBR header\n");
return 0;
}
/* Read GPT Header from device */
if (blk_dread(dev_desc, (lbaint_t)lba, 1, pgpt_head) != 1) {
- printf("*** ERROR: Can't read GPT header ***\n");
+ log_debug("Can't read GPT header\n");
return 0;
}
/* Invalid but nothing to yell about. */
if (le64_to_cpu(pgpt_head->signature) == GPT_HEADER_CHROMEOS_IGNORE) {
- debug("ChromeOS 'IGNOREME' GPT header found and ignored\n");
+ log_debug("ChromeOS 'IGNOREME' GPT header found and ignored\n");
return 2;
}
if (r != 1) {
if (r != 2)
- printf("%s: *** ERROR: Invalid GPT ***\n", __func__);
+ log_debug("Invalid GPT\n");
if (is_gpt_valid(dev_desc, (dev_desc->lba - 1), gpt_head,
pgpt_pte) != 1) {
- printf("%s: *** ERROR: Invalid Backup GPT ***\n",
- __func__);
+ log_debug("Invalid Backup GPT\n");
return 0;
}
if (r != 2)
- printf("%s: *** Using Backup GPT ***\n",
- __func__);
+ log_debug(" Using Backup GPT\n");
}
return 1;
}
gpt_entry *pte = NULL;
if (!dev_desc || !pgpt_head) {
- printf("%s: Invalid Argument(s)\n", __func__);
+ log_debug("Invalid Argument(s)\n");
return NULL;
}
count = le32_to_cpu(pgpt_head->num_partition_entries) *
le32_to_cpu(pgpt_head->sizeof_partition_entry);
- debug("%s: count = %u * %u = %lu\n", __func__,
- (u32) le32_to_cpu(pgpt_head->num_partition_entries),
- (u32) le32_to_cpu(pgpt_head->sizeof_partition_entry),
- (ulong)count);
+ log_debug("count = %u * %u = %lu\n",
+ (u32)le32_to_cpu(pgpt_head->num_partition_entries),
+ (u32)le32_to_cpu(pgpt_head->sizeof_partition_entry),
+ (ulong)count);
/* Allocate memory for PTE, remember to FREE */
if (count != 0) {
}
if (count == 0 || pte == NULL) {
- printf("%s: ERROR: Can't allocate %#lX bytes for GPT Entries\n",
- __func__, (ulong)count);
+ log_debug("ERROR: Can't allocate %#lX bytes for GPT Entries\n",
+ (ulong)count);
return NULL;
}
blk = le64_to_cpu(pgpt_head->partition_entry_lba);
blk_cnt = BLOCK_CNT(count, dev_desc);
if (blk_dread(dev_desc, blk, (lbaint_t)blk_cnt, pte) != blk_cnt) {
- printf("*** ERROR: Can't read GPT Entries ***\n");
+ log_debug("Can't read GPT Entries\n");
free(pte);
return NULL;
}
efi_guid_t unused_guid;
if (!pte) {
- printf("%s: Invalid Argument(s)\n", __func__);
+ log_debug("Invalid Argument(s)\n");
return 0;
}
if (memcmp(pte->partition_type_guid.b, unused_guid.b,
sizeof(unused_guid.b)) == 0) {
- debug("%s: Found an unused PTE GUID at 0x%08X\n", __func__,
- (unsigned int)(uintptr_t)pte);
+ log_debug("Found an unused PTE GUID at 0x%08X\n",
+ (unsigned int)(uintptr_t)pte);
return 0;
} else {