Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5e0db828 authored by Cylen Yao's avatar Cylen Yao Committed by Todd Poynor
Browse files

libdiskconfig: set MBR signature when creating MBR



When formatting a blank SD card, it needs to set MBR signature when creating MBR.
If not, the 'format' operation will fail.

Change-Id: I860731243797d4da83f370af52822536983009ee
Signed-off-by: default avatarCylen Yao <cylen.yao@mediatek.com>
parent 8c56cebd
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -208,6 +208,26 @@ fail:
}


static struct write_list *
mk_mbr_sig()
{
    struct write_list *item;
    if (!(item = alloc_wl(sizeof(uint16_t)))) {
        ALOGE("Unable to allocate memory for MBR signature.");
        return NULL;
    }

    {
        /* DO NOT DEREFERENCE */
        struct pc_boot_record *mbr = (void *)PC_MBR_DISK_OFFSET;
        /* grab the offset in mbr where to write mbr signature. */
        item->offset = (loff_t)((uint32_t)((uint8_t *)(&mbr->mbr_sig)));
    }

    *((uint16_t*)item->data) = PC_BIOS_BOOT_SIG;
    return item;
}

struct write_list *
config_mbr(struct disk_info *dinfo)
{
@@ -276,6 +296,13 @@ config_mbr(struct disk_info *dinfo)
        wlist_add(&wr_list, temp_wr);
    }

    if ((temp_wr = mk_mbr_sig()))
        wlist_add(&wr_list, temp_wr);
    else {
        ALOGE("Cannot set MBR signature");
        goto fail;
    }

    return wr_list;

nospace: