NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

toolchain/42555: installboot(8) should not refer DEV_BSIZE in src/tools



>Number:         42555
>Category:       toolchain
>Synopsis:       installboot(8) should not refer DEV_BSIZE in src/tools
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Dec 31 17:15:00 +0000 2009
>Originator:     Izumi Tsutsui
>Release:        NetBSD 5.99.22
>Organization:
>Environment:
Build System: CYGWIN_NT-5.1-1.7.1 on Windows XP SP3
Architecture: i686
Machine: i386 (32bit)

Target System: NetBSD 5.99.22 updated around 20091227
Architecture: sparc 
Machine: sparc

>Description:
Some sources of installboot(8) refer DEV_BSIZE to get
hardware sector size to calculate sector numbers etc,
but DEV_BSIZE is not always a value for a target NetBSD system
but a value for host's environment.

Actually DEV_BSIZE is 1024 on Cygwin-1.7.1 so cross installboot(8)
for sparc on Cygwin fails to search a secondary boot file in
the target file system.

>How-To-Repeat:
Code inspection.
Or "build.sh -U -m sparc release" on Cygwin-1.7.1, then you will get:

---
/usr/src/obj.sparc/tooldir.CYGWIN_NT-5.1-1.7.1-i686/bin/nbinstallboot -v \
-m sparc miniroot.fs  /usr/src/obj.sparc/destdir.sparc/usr/mdec/bootxx /boot \
|| { ls -f miniroot.fs ; false; }
File system:         miniroot.fs
File system type:    ffs (blocksize 4096, needswap 1)
Primary bootstrap:   /usr/src/obj.sparc/destdir.sparc/usr/mdec/bootxx
Secondary bootstrap: /boot
nbinstallboot: Could not find secondary bootstrap `boot' in `miniroot.fs'
nbinstallboot: (Path must be relative to the file system in `miniroot.fs')
nbinstallboot: Set bootstrap operation failed
miniroot.fs

*** Failed target:  miniroot.fs
*** Failed command: \
/usr/src/obj.sparc/tooldir.CYGWIN_NT-5.1-1.7.1-i686/bin/nbinstallboot -v \
-m sparc miniroot.fs /usr/src/obj.sparc/destdir.sparc/usr/mdec/bootxx /boot \
|| { ls -f miniroot.fs ; false; }
*** Error code 1

Stop.
nbmake: stopped in /usr/src/distrib/miniroot
%

---

>Fix:
To specify sector size on installboot operation,
probably we have to add an option to pass sectorsize like newfs(8).
For now, it would be enough to add a sectorsize member into
struct ib_params, set it 512bytes by default and use it instead
of DEV_BSIZE value.


Index: ext2fs.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/installboot/ext2fs.c,v
retrieving revision 1.4
diff -u -r1.4 ext2fs.c
--- ext2fs.c    19 Oct 2009 18:41:17 -0000      1.4
+++ ext2fs.c    31 Dec 2009 16:31:49 -0000
@@ -108,7 +108,7 @@
        assert(size > 0);
        assert(blk != NULL);
 
-       rv = pread(params->fsfd, blk, size, blkno * DEV_BSIZE);
+       rv = pread(params->fsfd, blk, size, blkno * params->sectorsize);
        if (rv == -1) {
                warn("Reading block %llu in `%s'", 
                    (unsigned long long)blkno, params->filesystem);
@@ -127,7 +127,7 @@
 {
        uint8_t sbbuf[SBSIZE];
 
-       if (ext2fs_read_disk_block(params, SBOFF / DEV_BSIZE, SBSIZE,
+       if (ext2fs_read_disk_block(params, SBOFF / params->sectorsize, SBSIZE,
            sbbuf) == 0)
 
        e2fs_sbload((void *)sbbuf, &fs->e2fs);
Index: ffs.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/installboot/ffs.c,v
retrieving revision 1.27
diff -u -r1.27 ffs.c
--- ffs.c       5 Apr 2009 12:03:48 -0000       1.27
+++ ffs.c       31 Dec 2009 16:31:49 -0000
@@ -97,7 +97,7 @@
        assert(size > 0);
        assert(blk != NULL);
 
-       rv = pread(params->fsfd, blk, size, blkno * DEV_BSIZE);
+       rv = pread(params->fsfd, blk, size, blkno * params->sectorsize);
        if (rv == -1) {
                warn("Reading block %llu in `%s'", 
                    (unsigned long long)blkno, params->filesystem);
@@ -475,10 +475,10 @@
 raid_match(ib_params *params)
 {
        /* XXX Assumes 512 bytes / sector */
-       if (DEV_BSIZE != 512) {
+       if (params->sectorsize != 512) {
                warnx("Media is %d bytes/sector."
                        "  RAID is only supported on 512 bytes/sector media.",
-                       DEV_BSIZE);
+                       params->sectorsize);
                return 0;
        }
        return ffs_match_common(params, (off_t) RF_PROTECTED_SECTORS);
@@ -497,7 +497,7 @@
 
        fs = (struct fs *)sbbuf;
        for (i = 0; sblock_try[i] != -1; i++) {
-               loc = sblock_try[i] / DEV_BSIZE + offset;
+               loc = sblock_try[i] / params->sectorsize + offset;
                if (!ffs_read_disk_block(params, loc, SBLOCKSIZE, sbbuf))
                        continue;
                switch (fs->fs_magic) {
Index: fstypes.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/installboot/fstypes.c,v
retrieving revision 1.11
diff -u -r1.11 fstypes.c
--- fstypes.c   28 Apr 2008 20:24:16 -0000      1.11
+++ fstypes.c   31 Dec 2009 16:31:49 -0000
@@ -95,7 +95,7 @@
 
        for (i = 0; i < nblk; i++) {
                blocks[i].block = params->s2start +
-                   i * (params->fstype->blocksize / 512);
+                   i * (params->fstype->blocksize / params->sectorsize);
                blocks[i].blocksize = params->fstype->blocksize;
        }
        *maxblk = nblk;
Index: installboot.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/installboot/installboot.c,v
retrieving revision 1.31
diff -u -r1.31 installboot.c
--- installboot.c       5 Apr 2009 11:55:39 -0000       1.31
+++ installboot.c       31 Dec 2009 16:31:50 -0000
@@ -92,6 +92,8 @@
 #undef OFFSET
 #define OPTION(params, type, opt) (*(type *)((char *)(params) + (opt)->offset))
 
+#define DFL_SECSIZE    512     /* Don't use DEV_BSIZE. It's host's value. */
+
 int
 main(int argc, char *argv[])
 {
@@ -234,6 +236,8 @@
                op = "write";
                mode = O_RDWR;
        }
+       /* XXX should be specified via option */
+       params->sectorsize = DFL_SECSIZE;
        if ((params->fsfd = open(params->filesystem, mode, 0600)) == -1)
                err(1, "Opening file system `%s' read-%s",
                    params->filesystem, op);
Index: installboot.h
===================================================================
RCS file: /cvsroot/src/usr.sbin/installboot/installboot.h,v
retrieving revision 1.35
diff -u -r1.35 installboot.h
--- installboot.h       28 Apr 2008 20:24:16 -0000      1.35
+++ installboot.h       31 Dec 2009 16:31:50 -0000
@@ -80,6 +80,7 @@
        uint64_t         s1start;       /*  start block of stage1 */
        const char      *stage2;        /* name of stage2 bootstrap */
        uint64_t         s2start;       /*  start block of stage2 */
+       uint32_t         sectorsize;    /* sector size of target fs */
                /* parsed -o option=value data */
        const char      *command;       /* name of command string */
        const char      *console;       /* name of console */
Index: arch/hp300.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/installboot/arch/hp300.c,v
retrieving revision 1.11
diff -u -r1.11 hp300.c
--- arch/hp300.c        5 Apr 2009 11:55:39 -0000       1.11
+++ arch/hp300.c        31 Dec 2009 16:31:50 -0000
@@ -78,8 +78,7 @@
        int             i;
        unsigned int    secsize = HP300_SECTSIZE;
        uint64_t        boot_size, boot_offset;
-       char            label_buf[DEV_BSIZE];
-       struct disklabel *label = (void *)label_buf;
+       struct disklabel *label;
 
        assert(params != NULL);
        assert(params->fsfd != -1);
@@ -90,6 +89,12 @@
        retval = 0;
        bootstrap = MAP_FAILED;
 
+       label = malloc(params->sectorsize);
+       if (label == NULL) {
+               warn("Failed to allocate memory for disklabel");
+               goto done;
+       }
+
        if (params->flags & IB_APPEND) {
                if (!S_ISREG(params->fsstat.st_mode)) {
                        warnx(
@@ -103,8 +108,8 @@
                 * The bootstrap can be well over 8k, and must go into a BOOT
                 * partition. Read NetBSD label to locate BOOT partition.
                 */
-               if (pread(params->fsfd, label, DEV_BSIZE, 2 * DEV_BSIZE)
-                                                               != DEV_BSIZE) {
+               if (pread(params->fsfd, label, params->sectorsize, LABELSECTOR)
+                   != (ssize_t)params->sectorsize) {
                        warn("reading disklabel");
                        goto done;
                }
@@ -200,6 +205,8 @@
        retval = 1;
 
  done:
+       if (label != NULL)
+               free(label);
        if (bootstrap != MAP_FAILED)
                munmap(bootstrap, params->s1stat.st_size);
        return retval;
Index: arch/next68k.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/installboot/arch/next68k.c,v
retrieving revision 1.6
diff -u -r1.6 next68k.c
--- arch/next68k.c      5 Apr 2009 11:55:39 -0000       1.6
+++ arch/next68k.c      31 Dec 2009 16:31:50 -0000
@@ -51,8 +51,6 @@
 
 #include "installboot.h"
 
-#define        SECTOR_SIZE     DEV_BSIZE
-
 static uint16_t nextstep_checksum(const void *, const void *);
 static int next68k_setboot(ib_params *);
 
@@ -106,7 +104,7 @@
         * Read in the next68k disklabel
         */
        rv = pread(params->fsfd, next68klabel, NEXT68K_LABEL_SIZE,
-           NEXT68K_LABEL_SECTOR * SECTOR_SIZE + NEXT68K_LABEL_OFFSET);
+           NEXT68K_LABEL_SECTOR * params->sectorsize + NEXT68K_LABEL_OFFSET);
        if (rv == -1) {
                warn("Reading `%s'", params->filesystem);
                goto done;
@@ -128,7 +126,7 @@
        }
 
        cd_secsize = be32toh(next68klabel->cd_secsize);
-       sec_netonb_mult = (cd_secsize / SECTOR_SIZE);
+       sec_netonb_mult = (cd_secsize / params->sectorsize);
 
        /*
         * Allocate a buffer, with space to round up the input file
@@ -177,7 +175,8 @@
                        b0 = b1 = NEXT68K_LABEL_SIZE / cd_secsize;
                else {
                        if (2 * bootsize > (fp * cd_secsize - 
-                               NEXT68K_LABEL_DEFAULTBOOT0_1 * SECTOR_SIZE))
+                               NEXT68K_LABEL_DEFAULTBOOT0_1 *
+                               params->sectorsize))
                                /* can fit two copies starting after label */
                                b0 = NEXT68K_LABEL_SIZE / cd_secsize;
                        else
@@ -220,7 +219,8 @@
                *checksum = htobe16(nextstep_checksum (next68klabel,
                                        checksum));
                rv = pwrite(params->fsfd, next68klabel, NEXT68K_LABEL_SIZE,
-                   NEXT68K_LABEL_SECTOR * SECTOR_SIZE + NEXT68K_LABEL_OFFSET);
+                   NEXT68K_LABEL_SECTOR * params->sectorsize +
+                   NEXT68K_LABEL_OFFSET);
                if (rv == -1) {
                        warn("Writing `%s'", params->filesystem);
                        goto done;
@@ -240,7 +240,8 @@
        for (;;) {
                if (params->flags & IB_VERBOSE)
                        printf ("Writing boot program at %d\n", b0);
-               rv = pwrite(params->fsfd, bootbuf, bootsize, b0 * SECTOR_SIZE);
+               rv = pwrite(params->fsfd, bootbuf, bootsize,
+                   b0 * params->sectorsize);
                if (rv == -1) {
                        warn("Writing `%s' at %d", params->filesystem, b0);
                        goto done;



Home | Main Index | Thread Index | Old Index