diff options
author | raj <raj@FreeBSD.org> | 2009-06-03 16:28:29 +0000 |
---|---|---|
committer | raj <raj@FreeBSD.org> | 2009-06-03 16:28:29 +0000 |
commit | 931cd337e418ee9dd7fc19cea7f33a65b0222442 (patch) | |
tree | b4f771cd37e606a082a2499207de66ee317e980d /sys/boot/uboot/lib/disk.c | |
parent | 25e7b6da03bce340e2284cf2ac8c65bce897a1b2 (diff) | |
download | FreeBSD-src-931cd337e418ee9dd7fc19cea7f33a65b0222442.zip FreeBSD-src-931cd337e418ee9dd7fc19cea7f33a65b0222442.tar.gz |
Make GPT style partitiong endian-safe in U-Boot support library.
Submitted by: Piotr Ziecik
Obtained from: Semihalf
Diffstat (limited to 'sys/boot/uboot/lib/disk.c')
-rw-r--r-- | sys/boot/uboot/lib/disk.c | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/sys/boot/uboot/lib/disk.c b/sys/boot/uboot/lib/disk.c index 1725d07..4cbdbea 100644 --- a/sys/boot/uboot/lib/disk.c +++ b/sys/boot/uboot/lib/disk.c @@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> +#include <sys/endian.h> #include <sys/queue.h> #include <netinet/in.h> #include <machine/stdarg.h> @@ -122,6 +123,15 @@ struct devsw uboot_storage = { stor_print }; +static void +uuid_letoh(uuid_t *uuid) +{ + + uuid->time_low = le32toh(uuid->time_low); + uuid->time_mid = le16toh(uuid->time_mid); + uuid->time_hi_and_version = le16toh(uuid->time_hi_and_version); +} + static int stor_init(void) { @@ -251,7 +261,7 @@ stor_open_gpt(struct open_dev *od, struct uboot_devdesc *dev) } /* Check the slice table magic. */ - if (*((uint16_t *)(buf + DOSMAGICOFFSET)) != DOSMAGIC) { + if (le16toh(*((uint16_t *)(buf + DOSMAGICOFFSET))) != DOSMAGIC) { err = ENXIO; goto out; } @@ -286,9 +296,10 @@ stor_open_gpt(struct open_dev *od, struct uboot_devdesc *dev) /* Check GPT header */ if (bcmp(hdr->hdr_sig, GPT_HDR_SIG, sizeof(hdr->hdr_sig)) != 0 || - hdr->hdr_lba_self != 1 || hdr->hdr_revision < 0x00010000 || - hdr->hdr_entsz < sizeof(*ent) || - od->od_bsize % hdr->hdr_entsz != 0) { + le64toh(hdr->hdr_lba_self) != 1 || + le32toh(hdr->hdr_revision) < 0x00010000 || + le32toh(hdr->hdr_entsz) < sizeof(*ent) || + od->od_bsize % le32toh(hdr->hdr_entsz) != 0) { debugf("Invalid GPT header!\n"); err = EINVAL; goto out; @@ -296,9 +307,9 @@ stor_open_gpt(struct open_dev *od, struct uboot_devdesc *dev) /* Count number of valid partitions */ part = 0; - eps = od->od_bsize / hdr->hdr_entsz; - slba = hdr->hdr_lba_table; - elba = slba + hdr->hdr_entries / eps; + eps = od->od_bsize / le32toh(hdr->hdr_entsz); + slba = le64toh(hdr->hdr_lba_table); + elba = slba + le32toh(hdr->hdr_entries) / eps; for (lba = slba; lba < elba; lba++) { err = stor_readdev(dev, lba, 1, buf); @@ -312,8 +323,9 @@ stor_open_gpt(struct open_dev *od, struct uboot_devdesc *dev) for (i = 0; i < eps; i++) { if (uuid_is_nil(&ent[i].ent_type, NULL) || - ent[i].ent_lba_start == 0 || - ent[i].ent_lba_end < ent[i].ent_lba_start) + le64toh(ent[i].ent_lba_start) == 0 || + le64toh(ent[i].ent_lba_end) < + le64toh(ent[i].ent_lba_start)) continue; part += 1; @@ -343,8 +355,9 @@ stor_open_gpt(struct open_dev *od, struct uboot_devdesc *dev) for (i = 0; i < eps; i++) { if (uuid_is_nil(&ent[i].ent_type, NULL) || - ent[i].ent_lba_start == 0 || - ent[i].ent_lba_end < ent[i].ent_lba_start) + le64toh(ent[i].ent_lba_start) == 0 || + le64toh(ent[i].ent_lba_end) < + le64toh(ent[i].ent_lba_start)) continue; od->od_partitions[part].gp_index = (lba - slba) @@ -352,9 +365,11 @@ stor_open_gpt(struct open_dev *od, struct uboot_devdesc *dev) od->od_partitions[part].gp_type = ent[i].ent_type; od->od_partitions[part].gp_start = - ent[i].ent_lba_start; + le64toh(ent[i].ent_lba_start); od->od_partitions[part].gp_end = - ent[i].ent_lba_end; + le64toh(ent[i].ent_lba_end); + + uuid_letoh(&od->od_partitions[part].gp_type); part += 1; } } |