@@ -1040,6 +1040,34 @@ static void sd_lock_command(SDState *sd)
sd->card_status &= ~CARD_IS_LOCKED;
}
+/*
+ * This requires a disk image that has two boot partitions inserted at the
+ * beginning of it. The size of the boot partitions are configured in the
+ * ext_csd structure, which is hardcoded in qemu. They are currently set to
+ * 1MB each.
+ */
+static uint32_t sd_bootpart_offset(SDState *sd)
+{
+ unsigned int access = sd->ext_csd[EXT_CSD_PART_CONFIG] &
+ EXT_CSD_PART_CONFIG_ACC_MASK;
+ unsigned int boot_capacity = sd->ext_csd[EXT_CSD_BOOT_MULT] << 17;
+
+ if (!sd->emmc) {
+ return 0;
+ }
+
+ switch (access) {
+ case EXT_CSD_PART_CONFIG_ACC_DEFAULT:
+ return boot_capacity * 2;
+ case EXT_CSD_PART_CONFIG_ACC_BOOT0:
+ return 0;
+ case EXT_CSD_PART_CONFIG_ACC_BOOT0 + 1:
+ return boot_capacity * 1;
+ default:
+ g_assert_not_reached();
+ }
+}
+
static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)
{
uint32_t rca = 0x0000;
@@ -1355,6 +1383,9 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)
return sd_r1;
}
+ if (sd->emmc) {
+ addr += sd_bootpart_offset(sd);
+ }
sd->state = sd_sendingdata_state;
sd->data_start = addr;
sd->data_offset = 0;
@@ -1374,6 +1405,9 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)
return sd_r1;
}
+ if (sd->emmc) {
+ addr += sd_bootpart_offset(sd);
+ }
sd->state = sd_sendingdata_state;
sd->data_start = addr;
sd->data_offset = 0;
@@ -1430,6 +1464,9 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)
return sd_r1;
}
+ if (sd->emmc) {
+ addr += sd_bootpart_offset(sd);
+ }
sd->state = sd_receivingdata_state;
sd->data_start = addr;
sd->data_offset = 0;
@@ -1460,6 +1497,9 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)
return sd_r1;
}
+ if (sd->emmc) {
+ addr += sd_bootpart_offset(sd);
+ }
sd->state = sd_receivingdata_state;
sd->data_start = addr;
sd->data_offset = 0;