aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/mkimg/ebr.c
diff options
context:
space:
mode:
authorMarcel Moolenaar <marcel@FreeBSD.org>2014-10-03 20:48:11 +0000
committerMarcel Moolenaar <marcel@FreeBSD.org>2014-10-03 20:48:11 +0000
commit2c83b36f4526a42b55c82cb16525acbaa4fcd041 (patch)
treeaa30e6160da2363f94c57d30253e149d81bf5f84 /usr.bin/mkimg/ebr.c
parentc36047bdb7c059efbbebc0a87b8bb1d7be3f9ffa (diff)
downloadsrc-2c83b36f4526a42b55c82cb16525acbaa4fcd041.tar.gz
src-2c83b36f4526a42b55c82cb16525acbaa4fcd041.zip
Add mkimg_chs() for those schemes that need the LBA broken down into
cylinder, head and track numbers. Return ~0U for these values when mkimg wasn't given both -T and -H (i.e. no geometry) or the cylinder would be larger than the provided maximum. Use mkimgs_chs() for the EBR, MBR and PC98 schemes to fill in the appropriate fields. Make sure to use a "rounded" size so that the partition is always a multiple of the track size. We reserved the room for it in the metadata callback so that's a valid thing to do. Bump the mkimg version number. While doing that again: have mkimg.o depend on the Makefile so that a version change triggers a rebuild as needed.
Notes
Notes: svn path=/head/; revision=272485
Diffstat (limited to 'usr.bin/mkimg/ebr.c')
-rw-r--r--usr.bin/mkimg/ebr.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/usr.bin/mkimg/ebr.c b/usr.bin/mkimg/ebr.c
index 43601cc89227..28931ea4de8c 100644
--- a/usr.bin/mkimg/ebr.c
+++ b/usr.bin/mkimg/ebr.c
@@ -58,12 +58,14 @@ ebr_metadata(u_int where, lba_t blk)
}
static void
-ebr_chs(u_char *cyl, u_char *hd, u_char *sec, uint32_t lba __unused)
+ebr_chs(u_char *cylp, u_char *hdp, u_char *secp, lba_t lba)
{
+ u_int cyl, hd, sec;
- *cyl = 0xff; /* XXX */
- *hd = 0xff; /* XXX */
- *sec = 0xff; /* XXX */
+ mkimg_chs(lba, 1023, &cyl, &hd, &sec);
+ *cylp = cyl;
+ *hdp = hd;
+ *secp = (sec & 0x3f) | ((cyl >> 2) & 0xc0);
}
static int
@@ -72,7 +74,7 @@ ebr_write(lba_t imgsz __unused, void *bootcode __unused)
u_char *ebr;
struct dos_partition *dp;
struct part *part, *next;
- lba_t block;
+ lba_t block, size;
int error;
ebr = malloc(secsz);
@@ -84,24 +86,26 @@ ebr_write(lba_t imgsz __unused, void *bootcode __unused)
error = 0;
STAILQ_FOREACH_SAFE(part, &partlist, link, next) {
block = part->block - nsecs;
+ size = round_track(part->size);
dp = (void *)(ebr + DOSPARTOFF);
ebr_chs(&dp->dp_scyl, &dp->dp_shd, &dp->dp_ssect, nsecs);
dp->dp_typ = ALIAS_TYPE2INT(part->type);
ebr_chs(&dp->dp_ecyl, &dp->dp_ehd, &dp->dp_esect,
- part->block + part->size - 1);
+ part->block + size - 1);
le32enc(&dp->dp_start, nsecs);
- le32enc(&dp->dp_size, part->size);
+ le32enc(&dp->dp_size, size);
/* Add link entry */
if (next != NULL) {
+ size = round_track(next->size);
dp++;
ebr_chs(&dp->dp_scyl, &dp->dp_shd, &dp->dp_ssect,
next->block - nsecs);
dp->dp_typ = DOSPTYP_EXT;
ebr_chs(&dp->dp_ecyl, &dp->dp_ehd, &dp->dp_esect,
- next->block + next->size - 1);
+ next->block + size - 1);
le32enc(&dp->dp_start, next->block - nsecs);
- le32enc(&dp->dp_size, next->size + nsecs);
+ le32enc(&dp->dp_size, size + nsecs);
}
error = image_write(block, ebr, 1);