summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIrina Patru <irina.patru@intel.com>2016-04-22 12:27:12 +0300
committerMihai Serban <mihai.serban@intel.com>2016-05-10 15:53:18 +0300
commit32effe57cd6478425b2773c93b2f91ef5a40e8ae (patch)
treefc3d43164485eafb820938f43bf970d3b4832f20
parenteb94feb0984b65b2fe98fadc04f766f126514694 (diff)
downloadedison-u-boot-32effe57cd6478425b2773c93b2f91ef5a40e8ae.tar.gz
fastboot: Change gpt flashing to consider full images
Gpt flashing checks if the received partitioning image already has a MBR and GPT header inserted. Change-Id: I9aa03c23b6eace3f55aedf837a20ca3f14028c56 Signed-off-by: Irina Patru <irina.patru@intel.com> Reviewed-on: https://android.intel.com/498591 Reviewed-by: Serban, Mihai <mihai.serban@intel.com>
-rw-r--r--board/intel/edison/edison.c67
-rw-r--r--common/fb_mmc.c38
2 files changed, 76 insertions, 29 deletions
diff --git a/board/intel/edison/edison.c b/board/intel/edison/edison.c
index d80ac36b83..c1df3fdd39 100644
--- a/board/intel/edison/edison.c
+++ b/board/intel/edison/edison.c
@@ -19,6 +19,9 @@ DECLARE_GLOBAL_DATA_PTR;
#define PRODUCT_NAME "edison"
+#define BLOCK_SIZE 512
+#define ONE_MiB (1024 * 1024)
+
#define OSIP_MAGIC 0x24534f24;
struct osii_entry {
uint16_t os_rev_minor;
@@ -146,7 +149,7 @@ int fb_set_reboot_flag(void)
}
-int board_verify_gpt_parts(struct gpt_frag *frag)
+int board_verify_gpt_parts(void *_frag)
{
uint8_t u_boot_label[] = {
'u', 0, '-', 0, 'b', 0, 'o', 0, 'o', 0, 't', 0, 0, 0,
@@ -159,20 +162,49 @@ int board_verify_gpt_parts(struct gpt_frag *frag)
's', 0, 'e', 0, 'c', 0, 'u', 0, 'r', 0, 'i', 0, 't', 0, 'y', 0, 0, 0,
};
- if (memcmp(u_boot_label, frag->parts[0].label, sizeof(u_boot_label)))
- return -EINVAL;
- if (frag->parts[0].size_mib != 5)
- return -EINVAL;
-
- if (memcmp(factory_label, frag->parts[1].label, sizeof(factory_label)))
- return -EINVAL;
- if (frag->parts[1].size_mib != 1)
- return -EINVAL;
-
- if (memcmp(security_label, frag->parts[2].label, sizeof(security_label)))
- return -EINVAL;
- if (frag->parts[2].size_mib != 1)
- return -EINVAL;
+ struct gpt_frag *frag = _frag;
+ legacy_mbr *mbr = _frag;
+ gpt_header *gpt_h = _frag + (GPT_PRIMARY_PARTITION_TABLE_LBA * BLOCK_SIZE);
+ gpt_entry *gpt_e = _frag + (le64_to_cpu(gpt_h->partition_entry_lba) * BLOCK_SIZE);
+ unsigned long long part_size = 0;
+
+ if (mbr->signature == MSDOS_MBR_SIGNATURE) {
+ if (memcmp(u_boot_label, gpt_e->partition_name, sizeof(u_boot_label)))
+ return -EINVAL;
+ part_size = (gpt_e->ending_lba - gpt_e->starting_lba + 1) * BLOCK_SIZE / ONE_MiB;
+ if (part_size != 5)
+ return -EINVAL;
+
+ gpt_e++;
+ if (memcmp(factory_label, gpt_e->partition_name, sizeof(factory_label)))
+ return -EINVAL;
+ part_size = (gpt_e->ending_lba - gpt_e->starting_lba + 1) * BLOCK_SIZE / ONE_MiB;
+ if (part_size != 1)
+ return -EINVAL;
+
+ gpt_e++;
+ if (memcmp(security_label, gpt_e->partition_name, sizeof(security_label)))
+ return -EINVAL;
+ part_size = (gpt_e->ending_lba - gpt_e->starting_lba + 1) * BLOCK_SIZE / ONE_MiB;
+ if (part_size != 1)
+ return -EINVAL;
+ } else {
+
+ if (memcmp(u_boot_label, frag->parts[0].label, sizeof(u_boot_label)))
+ return -EINVAL;
+ if (frag->parts[0].size_mib != 5)
+ return -EINVAL;
+
+ if (memcmp(factory_label, frag->parts[1].label, sizeof(factory_label)))
+ return -EINVAL;
+ if (frag->parts[1].size_mib != 1)
+ return -EINVAL;
+
+ if (memcmp(security_label, frag->parts[2].label, sizeof(security_label)))
+ return -EINVAL;
+ if (frag->parts[2].size_mib != 1)
+ return -EINVAL;
+ }
return 0;
}
@@ -188,7 +220,10 @@ int board_populate_mbr_boot_code(legacy_mbr *mbr)
osip->number_of_pointers = 1;
osip->number_of_images = 1;
osip->header_size = sizeof(*osip) + sizeof(osip->osii[0]);
- osip->osii[0].image_lba = 0x00000800; /* 1 MiB */
+ if (mbr->signature == MSDOS_MBR_SIGNATURE)
+ osip->osii[0].image_lba = 0x00000028;
+ else
+ osip->osii[0].image_lba = 0x00000800; /* 1 MiB */
osip->osii[0].load_address = 0x01100000;
osip->osii[0].start_address = 0x01101000;
osip->osii[0].image_size_blocks = 0x00002800; /* 5 MiB */
diff --git a/common/fb_mmc.c b/common/fb_mmc.c
index a67391bb8f..088fe31a67 100644
--- a/common/fb_mmc.c
+++ b/common/fb_mmc.c
@@ -81,6 +81,15 @@ static int build_and_write_gpt(block_dev_desc_t *dev, void *_frag,
gpt_entry *gpt_e;
int ret = -EINVAL;
+ /* Check the type of partitioning image */
+ mbr = _frag;
+ if (mbr->signature == MSDOS_MBR_SIGNATURE) {
+ buf = _frag;
+ if (board_verify_gpt_parts(buf))
+ return -EINVAL;
+ goto add_boot_code;
+ }
+
if (verify_gpt_frag(frag, frag_size))
return -EINVAL;
@@ -92,18 +101,6 @@ static int build_and_write_gpt(block_dev_desc_t *dev, void *_frag,
gpt_h = buf + dev->blksz;
gpt_e = buf + dev->blksz * 2;
- /* Populate MBR */
- if ((ret = board_populate_mbr_boot_code(mbr)))
- goto error;
-
- mbr->partition_record[0].sys_ind = EFI_PMBR_OSTYPE_EFI_GPT;
- mbr->partition_record[0].start_sect = 1;
- if (dev->lba > 0xffffffff)
- mbr->partition_record[0].nr_sects = 0xffffffff;
- else
- mbr->partition_record[0].nr_sects = dev->lba - 1;
- mbr->signature = MSDOS_MBR_SIGNATURE;
-
/* Populate GPT Header */
gpt_h->signature = GPT_HEADER_SIGNATURE;
gpt_h->revision = GPT_HEADER_REVISION_V1;
@@ -160,9 +157,24 @@ static int build_and_write_gpt(block_dev_desc_t *dev, void *_frag,
gpt_h->num_partition_entries * gpt_h->sizeof_partition_entry);
gpt_h->header_crc32 = crc32(0, (void*)gpt_h, gpt_h->header_size);
+ /* Populate MBR */
+ mbr->partition_record[0].sys_ind = EFI_PMBR_OSTYPE_EFI_GPT;
+ mbr->partition_record[0].start_sect = 1;
+ if (dev->lba > 0xffffffff)
+ mbr->partition_record[0].nr_sects = 0xffffffff;
+ else
+ mbr->partition_record[0].nr_sects = dev->lba - 1;
+
+add_boot_code:
+ if ((ret = board_populate_mbr_boot_code(mbr)))
+ goto error;
+
+ mbr->signature = MSDOS_MBR_SIGNATURE;
+
ret = write_mbr_and_gpt_partitions(dev, buf);
error:
- free(buf);
+ if (buf != _frag)
+ free(buf);
return ret;
}