From owner-svn-src-head@freebsd.org Tue Oct 18 05:43:14 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 84694C16F6B; Tue, 18 Oct 2016 05:43:14 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 5F742CB2; Tue, 18 Oct 2016 05:43:14 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u9I5hD65023919; Tue, 18 Oct 2016 05:43:13 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u9I5hDHJ023915; Tue, 18 Oct 2016 05:43:13 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201610180543.u9I5hDHJ023915@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Tue, 18 Oct 2016 05:43:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r307550 - head/usr.bin/mkimg X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Oct 2016 05:43:14 -0000 Author: imp Date: Tue Oct 18 05:43:12 2016 New Revision: 307550 URL: https://svnweb.freebsd.org/changeset/base/307550 Log: Add a new flag to mkimg (-a num) to specify the active partition for those partitioning schemes that have this concept. Implement it as an override for mbr's setting 0x80 in the flags for the first partition when we have boot code. Differential Revision: https://reviews.freebsd.org/D4403 Modified: head/usr.bin/mkimg/mbr.c head/usr.bin/mkimg/mkimg.1 head/usr.bin/mkimg/mkimg.c head/usr.bin/mkimg/mkimg.h Modified: head/usr.bin/mkimg/mbr.c ============================================================================== --- head/usr.bin/mkimg/mbr.c Tue Oct 18 04:02:00 2016 (r307549) +++ head/usr.bin/mkimg/mbr.c Tue Oct 18 05:43:12 2016 (r307550) @@ -92,7 +92,12 @@ mbr_write(lba_t imgsz __unused, void *bo TAILQ_FOREACH(part, &partlist, link) { size = round_track(part->size); dp = dpbase + part->index; - dp->dp_flag = (part->index == 0 && bootcode != NULL) ? 0x80 : 0; + if (active_partition != 0) + dp->dp_flag = + (part->index + 1 == active_partition) ? 0x80 : 0; + else + dp->dp_flag = + (part->index == 0 && bootcode != NULL) ? 0x80 : 0; mbr_chs(&dp->dp_scyl, &dp->dp_shd, &dp->dp_ssect, part->block); dp->dp_typ = ALIAS_TYPE2INT(part->type); Modified: head/usr.bin/mkimg/mkimg.1 ============================================================================== --- head/usr.bin/mkimg/mkimg.1 Tue Oct 18 04:02:00 2016 (r307549) +++ head/usr.bin/mkimg/mkimg.1 Tue Oct 18 05:43:12 2016 (r307550) @@ -40,6 +40,7 @@ .Op Fl c Ar capacity .Op Fl f Ar format .Op Fl o Ar outfile +.Op Fl a Ar active .Op Fl v .Op Fl y .Op Fl s Ar scheme Op Fl p Ar partition ... @@ -119,7 +120,7 @@ An empty partition table can be written partitioning scheme with the .Fl s option, but without specifying any partitions. -When the size required to for all the partitions is larger than the +When the size required for all the partitions is larger than the given capacity, then the disk image will be larger than the capacity given. .Pp @@ -139,6 +140,26 @@ utility will generate predictable values .Nm utility will create images that are identical. .Pp +The +.Ar active +option marks a partition as active, if the partitioning +scheme supports it. +Currently, only the +.Ar mbr +scheme supports this concept. +By default, +.Nm +will only mark the first partition as active when boot code is +specified. +Use the +.Ar active +option to override the active partition. +The number specified corresponds to the number after the 's' in the +partition's +.Xr geom 8 +name. +No partitions are marked active when the value is 0. +.Pp A set of long options exist to query about the .Nm utility itself. Modified: head/usr.bin/mkimg/mkimg.c ============================================================================== --- head/usr.bin/mkimg/mkimg.c Tue Oct 18 04:02:00 2016 (r307549) +++ head/usr.bin/mkimg/mkimg.c Tue Oct 18 05:43:12 2016 (r307550) @@ -70,6 +70,7 @@ u_int nheads = 1; u_int nsecs = 1; u_int secsz = 512; u_int blksz = 0; +uint32_t active_partition = 0; static void print_formats(int usage) @@ -145,6 +146,7 @@ usage(const char *why) fprintf(stderr, "\t--schemes\t- list partition schemes\n"); fprintf(stderr, "\t--version\t- show version information\n"); fputc('\n', stderr); + fprintf(stderr, "\t-a \t- mark num'th partion as active\n"); fprintf(stderr, "\t-b \t- file containing boot code\n"); fprintf(stderr, "\t-c \t- capacity (in bytes) of the disk\n"); fprintf(stderr, "\t-f \n"); @@ -468,9 +470,14 @@ main(int argc, char *argv[]) bcfd = -1; outfd = 1; /* Write to stdout by default */ - while ((c = getopt_long(argc, argv, "b:c:f:o:p:s:vyH:P:S:T:", + while ((c = getopt_long(argc, argv, "a:b:c:f:o:p:s:vyH:P:S:T:", longopts, NULL)) != -1) { switch (c) { + case 'a': /* ACTIVE PARTITION, if supported */ + error = parse_uint32(&active_partition, 1, 100, optarg); + if (error) + errc(EX_DATAERR, error, "Partition ordinal"); + break; case 'b': /* BOOT CODE */ if (bcfd != -1) usage("multiple bootcode given"); Modified: head/usr.bin/mkimg/mkimg.h ============================================================================== --- head/usr.bin/mkimg/mkimg.h Tue Oct 18 04:02:00 2016 (r307549) +++ head/usr.bin/mkimg/mkimg.h Tue Oct 18 05:43:12 2016 (r307550) @@ -59,6 +59,7 @@ extern u_int nheads; extern u_int nsecs; extern u_int secsz; /* Logical block size. */ extern u_int blksz; /* Physical block size. */ +extern uint32_t active_partition; static inline lba_t round_block(lba_t n)