Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/prep/stand/mkbootimage Convert to use libsa byteord...



details:   https://anonhg.NetBSD.org/src/rev/59c70f5c38ff
branches:  trunk
changeset: 526126:59c70f5c38ff
user:      kleink <kleink%NetBSD.org@localhost>
date:      Thu Apr 25 23:30:26 2002 +0000

description:
Convert to use libsa byteorder interfaces.

diffstat:

 sys/arch/prep/stand/mkbootimage/Makefile      |  11 +++++++-
 sys/arch/prep/stand/mkbootimage/mkbootimage.c |  34 +++++++++++++-------------
 2 files changed, 26 insertions(+), 19 deletions(-)

diffs (120 lines):

diff -r b4060a3e62df -r 59c70f5c38ff sys/arch/prep/stand/mkbootimage/Makefile
--- a/sys/arch/prep/stand/mkbootimage/Makefile  Thu Apr 25 23:23:23 2002 +0000
+++ b/sys/arch/prep/stand/mkbootimage/Makefile  Thu Apr 25 23:30:26 2002 +0000
@@ -1,8 +1,15 @@
-#      $NetBSD: Makefile,v 1.2 2001/12/12 01:49:50 tv Exp $
+#      $NetBSD: Makefile,v 1.3 2002/04/25 23:30:26 kleink Exp $
 
 PROG=  mkbootimage
+SRCS=  mkbootimage.c byteorder.c
 NOMAN= # defined
 
-CPPFLAGS= -I${.CURDIR}
+LIBSA=${.CURDIR}/../../../../lib/libsa
+
+.PATH.c: ${LIBSA}
 
+CPPFLAGS= -I${LIBSA} -I${.CURDIR}
+
+.ifndef HOSTPROG
 .include <bsd.prog.mk>
+.endif
diff -r b4060a3e62df -r 59c70f5c38ff sys/arch/prep/stand/mkbootimage/mkbootimage.c
--- a/sys/arch/prep/stand/mkbootimage/mkbootimage.c     Thu Apr 25 23:23:23 2002 +0000
+++ b/sys/arch/prep/stand/mkbootimage/mkbootimage.c     Thu Apr 25 23:30:26 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mkbootimage.c,v 1.2 2002/03/02 07:05:30 matt Exp $     */
+/*     $NetBSD: mkbootimage.c,v 1.3 2002/04/25 23:30:26 kleink Exp $   */
 
 /*-
  * Copyright (C) 1999, 2000 NONAKA Kimihiro (nonaka%netbsd.org@localhost)
@@ -43,9 +43,8 @@
 #include <sys/uio.h>
 #include <sys/disklabel_mbr.h>
 #include <sys/exec_elf.h>
-#include <machine/bswap.h>
-#include <machine/endian.h>
 
+#include "byteorder.h"
 #include "magic.h"
 
 int
@@ -109,14 +108,14 @@
                fprintf(stderr, "input '%s' is not ELF32 format\n", argv[1]);
                exit(3);
        }
-       if (be16toh(hdr.e_machine) != EM_PPC) {
+       if (sa_be16toh(hdr.e_machine) != EM_PPC) {
                fprintf(stderr, "input '%s' is not PowerPC exec binary\n",
                        argv[1]);
                exit(3);
        }
 
-       for (i = 0; i < be16toh(hdr.e_phnum); i++) {
-               lseek(elf_fd, be32toh(hdr.e_phoff) + sizeof(phdr) * i,
+       for (i = 0; i < sa_be16toh(hdr.e_phnum); i++) {
+               lseek(elf_fd, sa_be32toh(hdr.e_phoff) + sizeof(phdr) * i,
                        SEEK_SET);
                if (read(elf_fd, &phdr, sizeof(phdr)) != sizeof(phdr)) {
                        fprintf(stderr, "Can't read input '%s' phdr : %s\n",
@@ -124,13 +123,13 @@
                        exit(3);
                 }
 
-               if ((be32toh(phdr.p_type) != PT_LOAD) ||
-                   !(be32toh(phdr.p_flags) & PF_X))
+               if ((sa_be32toh(phdr.p_type) != PT_LOAD) ||
+                   !(sa_be32toh(phdr.p_flags) & PF_X))
                        continue;
 
                fstat(elf_fd, &elf_stat);
-               elf_img_len = elf_stat.st_size - be32toh(phdr.p_offset);
-               lseek(elf_fd, be32toh(phdr.p_offset), SEEK_SET);
+               elf_img_len = elf_stat.st_size - sa_be32toh(phdr.p_offset);
+               lseek(elf_fd, sa_be32toh(phdr.p_offset), SEEK_SET);
 
                break;
        }
@@ -138,13 +137,13 @@
        memset(mbr, 0, sizeof(mbr));
  
        /* Set entry point and boot image size skipping over elf header */
-       entry  = htole32(0x400);
-       length = htole32(elf_stat.st_size - sizeof(hdr) + 0x400);
+       entry  = sa_htole32(0x400);
+       length = sa_htole32(elf_stat.st_size - sizeof(hdr) + 0x400);
 
        /*
         * Set magic number for msdos partition
         */
-       *(unsigned short *)&mbr[MBR_MAGICOFF] = htole16(MBR_MAGIC);
+       *(unsigned short *)&mbr[MBR_MAGICOFF] = sa_htole16(MBR_MAGIC);
   
        /*
         * Build a "PReP" partition table entry in the boot record
@@ -177,8 +176,8 @@
         */
 
        /* This has to be 0 on the PowerStack? */   
-       mbrp->mbrp_start = htole32(0);
-       mbrp->mbrp_size  = htole32(2 * 18 * 80 - 1);
+       mbrp->mbrp_start = sa_htole32(0);
+       mbrp->mbrp_size  = sa_htole32(2 * 18 * 80 - 1);
 
        write(prep_fd, mbr, sizeof(mbr));
        write(prep_fd, &entry, sizeof(entry));
@@ -217,11 +216,12 @@
                        exit(3);
                }
                write(prep_fd, (void *)magic, MAGICSIZE);
-               tmp = htobe32(kern_stat.st_size);
+               tmp = sa_htobe32(kern_stat.st_size);
                write(prep_fd, (void *)&tmp, KERNLENSIZE);
                write(prep_fd, (void *)kern_img, kern_stat.st_size);
 
-               length = htole32(0x400 + elf_img_len + 8 + kern_stat.st_size);
+               length = sa_htole32(0x400 + elf_img_len + 8 +
+                   kern_stat.st_size);
                lseek(prep_fd, sizeof(mbr) + 4, SEEK_SET);
                write(prep_fd, &length, sizeof(length));  
 



Home | Main Index | Thread Index | Old Index