CVS commit: src/sys/arch/powerpc/stand/mkbootimage

2016-01-21 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Thu Jan 21 17:14:05 UTC 2016

Modified Files:
src/sys/arch/powerpc/stand/mkbootimage: mkbootimage.c

Log Message:
PR/50685: David Binderman: fix memory leak


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 \
src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c
diff -u src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c:1.18 src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c:1.19
--- src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c:1.18	Tue Apr 22 17:37:52 2014
+++ src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c	Thu Jan 21 12:14:05 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: mkbootimage.c,v 1.18 2014/04/22 21:37:52 phx Exp $	*/
+/*	$NetBSD: mkbootimage.c,v 1.19 2016/01/21 17:14:05 christos Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -336,7 +336,7 @@ prep_build_image(char *kernel, char *boo
 	lseek(prep_fd, 0x400, SEEK_SET);
 
 	/* Copy boot image */
-	elf_img = (unsigned char *)malloc(elf_img_len);
+	elf_img = malloc(elf_img_len);
 	if (!elf_img)
 		errx(3, "Can't malloc: %s", strerror(errno));
 	if (read(elf_fd, elf_img, elf_img_len) != elf_img_len)
@@ -347,7 +347,7 @@ prep_build_image(char *kernel, char *boo
 
 	if (inkernflag) {
 		/* Copy kernel */
-		kern_img = (unsigned char *)malloc(kern_stat.st_size);
+		kern_img = malloc(kern_stat.st_size);
 
 		if (kern_img == NULL)
 			errx(3, "Can't malloc: %s", strerror(errno));
@@ -502,7 +502,7 @@ rs6000_build_image(char *kernel, char *b
 	lseek(rs6000_fd, 0x400, SEEK_SET);
 
 	/* Copy boot image */
-	elf_img = (unsigned char *)malloc(elf_img_len);
+	elf_img = malloc(elf_img_len);
 	if (!elf_img)
 		errx(3, "Can't malloc: %s", strerror(errno));
 	if (read(elf_fd, elf_img, elf_img_len) != elf_img_len)
@@ -516,7 +516,7 @@ rs6000_build_image(char *kernel, char *b
 	lseek(rs6000_fd, elf_pad, SEEK_CUR);
 
 	/* Copy kernel */
-	kern_img = (unsigned char *)malloc(kern_stat.st_size);
+	kern_img = malloc(kern_stat.st_size);
 
 	if (kern_img == NULL)
 		errx(3, "Can't malloc: %s", strerror(errno));
@@ -735,7 +735,7 @@ bebox_build_image(char *kernel, char *bo
 		bebox_write_header(bebox_fd, elf_img_len, kern_stat.st_size);
 
 		/* Copy kernel */
-		kern_img = (unsigned char *)malloc(kern_stat.st_size);
+		kern_img = malloc(kern_stat.st_size);
 
 		if (kern_img == NULL)
 			errx(3, "Can't malloc: %s", strerror(errno));
@@ -786,7 +786,7 @@ bebox_build_image(char *kernel, char *bo
 	toff = bebox_write_header(bebox_fd, elf_img_len, tmp);
 
 	/* Copy boot image */
-	elf_img = (unsigned char *)malloc(elf_img_len);
+	elf_img = malloc(elf_img_len);
 	if (!elf_img)
 		errx(3, "Can't malloc: %s", strerror(errno));
 	if (read(elf_fd, elf_img, elf_img_len) != elf_img_len)
@@ -802,7 +802,7 @@ bebox_build_image(char *kernel, char *bo
 	/* Now go back and write in the block header */
 	endoff = lseek(bebox_fd, 0, SEEK_END);
 	lseek(bebox_fd, 0, SEEK_SET);
-	header_img = (unsigned char *)malloc(BEBOX_HEADER_SIZE);
+	header_img = malloc(BEBOX_HEADER_SIZE);
 	if (!header_img)
 		errx(3, "Can't malloc: %s", strerror(errno));
 	memset(header_img, 0, BEBOX_HEADER_SIZE);
@@ -837,6 +837,7 @@ bebox_build_image(char *kernel, char *bo
 	write(bebox_fd, header_img, flength - endoff);
 
 	close(bebox_fd);
+	free(header_img);
 
 	return 0;
 }



CVS commit: src/sys/arch/powerpc/stand/mkbootimage

2014-04-22 Thread Frank Wille
Module Name:src
Committed By:   phx
Date:   Tue Apr 22 21:37:52 UTC 2014

Modified Files:
src/sys/arch/powerpc/stand/mkbootimage: bebox_bootrec.h mkbootimage.c
pef.h

Log Message:
Fixed mkbootimage for 64-bit architectures. Now I can create a working
BeBox boot.fs under NetBSD/amd64.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 \
src/sys/arch/powerpc/stand/mkbootimage/bebox_bootrec.h
cvs rdiff -u -r1.17 -r1.18 \
src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/powerpc/stand/mkbootimage/pef.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/powerpc/stand/mkbootimage/bebox_bootrec.h
diff -u src/sys/arch/powerpc/stand/mkbootimage/bebox_bootrec.h:1.3 src/sys/arch/powerpc/stand/mkbootimage/bebox_bootrec.h:1.4
--- src/sys/arch/powerpc/stand/mkbootimage/bebox_bootrec.h:1.3	Mon Dec 24 14:01:24 2012
+++ src/sys/arch/powerpc/stand/mkbootimage/bebox_bootrec.h	Tue Apr 22 21:37:52 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: bebox_bootrec.h,v 1.3 2012/12/24 14:01:24 kiyohara Exp $	*/
+/*	$NetBSD: bebox_bootrec.h,v 1.4 2014/04/22 21:37:52 phx Exp $	*/
 
 #define	BEBOX_HEADER_SIZE		0x6400
 #define	BEBOX_BLOCK_SIZE		0x200
@@ -136,9 +136,9 @@ u_char bebox_image_data12[] = {
 };
 
 struct bebox_image_block {
-	long offset;
+	int32_t offset;
 	u_char *data;
-	int size;
+	int32_t size;
 };
 
 #define	BEBOX_IMG(x)		__CONCAT(bebox_image_data,x)
@@ -162,7 +162,7 @@ struct bebox_image_block bebox_image_blo
 	{ -1 }
 };
 
-long bebox_mtime_offset[] = {
+int32_t bebox_mtime_offset[] = {
 	0x0004,
 	0x048c,
 	0x0490,

Index: src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c
diff -u src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c:1.17 src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c:1.18
--- src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c:1.17	Tue Jul  9 13:10:33 2013
+++ src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c	Tue Apr 22 21:37:52 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: mkbootimage.c,v 1.17 2013/07/09 13:10:33 joerg Exp $	*/
+/*	$NetBSD: mkbootimage.c,v 1.18 2014/04/22 21:37:52 phx Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -685,10 +685,9 @@ bebox_build_image(char *kernel, char *bo
 	unsigned char *elf_img = NULL, *kern_img = NULL, *header_img = NULL;
 	int i, ch, tmp, kgzlen, err, hsize = BEBOX_HEADER_SIZE;
 	int elf_fd, bebox_fd, kern_fd, elf_img_len = 0;
+	off_t lenpos, kstart, kend, toff, endoff, flength;
 	uint32_t swapped[128];
-	off_t lenpos, kstart, kend, toff, endoff;
-	unsigned long length;
-	long flength, *offset;
+	int32_t *offset;
 	gzFile gzf;
 	struct stat kern_stat;
 	struct bebox_image_block *p;
@@ -818,14 +817,15 @@ bebox_build_image(char *kernel, char *bo
 
 	/* fix the file size in the header */
 	tmp = endoff - BEBOX_HEADER_SIZE;
-	*(long *)(header_img + BEBOX_FILE_SIZE_OFFSET) =
-	(long)sa_htobe32(tmp);
-	*(long *)(header_img + BEBOX_FILE_SIZE_ALIGN_OFFSET) =
-	(long)sa_htobe32(roundup(tmp, BEBOX_FILE_BLOCK_SIZE));
+	*(int32_t *)(header_img + BEBOX_FILE_SIZE_OFFSET) =
+	(int32_t)sa_htobe32(tmp);
+	*(int32_t *)(header_img + BEBOX_FILE_SIZE_ALIGN_OFFSET) =
+	(int32_t)sa_htobe32(roundup(tmp, BEBOX_FILE_BLOCK_SIZE));
 
 	gettimeofday(&tp, 0);
 	for (offset = bebox_mtime_offset; *offset != -1; offset++)
-		*(long *)(header_img + *offset) = (long)sa_htobe32(tp.tv_sec);
+		*(int32_t *)(header_img + *offset) =
+		(int32_t)sa_htobe32(tp.tv_sec);
 
 	write(bebox_fd, header_img, BEBOX_HEADER_SIZE);
 

Index: src/sys/arch/powerpc/stand/mkbootimage/pef.h
diff -u src/sys/arch/powerpc/stand/mkbootimage/pef.h:1.2 src/sys/arch/powerpc/stand/mkbootimage/pef.h:1.3
--- src/sys/arch/powerpc/stand/mkbootimage/pef.h:1.2	Sat Oct 16 05:05:09 2010
+++ src/sys/arch/powerpc/stand/mkbootimage/pef.h	Tue Apr 22 21:37:52 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: pef.h,v 1.2 2010/10/16 05:05:09 kiyohara Exp $	*/
+/*	$NetBSD: pef.h,v 1.3 2014/04/22 21:37:52 phx Exp $	*/
 
 /*-
  * Copyright (C) 1995-1997 Gary Thomas (g...@linuxppc.org)
@@ -34,17 +34,17 @@
 
 struct FileHeader
 {
-	unsigned long magic;
-	unsigned long fileTypeID;
-	unsigned long archID;
-	unsigned long versionNumber;
-	unsigned long dateTimeStamp;
-	unsigned long definVersion;
-	unsigned long implVersion;
-	unsigned long currentVersion;
-	unsigned short numSections;
-	unsigned short loadableSections;
-	unsigned long memoryAddress;
+	uint32_t magic;
+	uint32_t fileTypeID;
+	uint32_t archID;
+	uint32_t versionNumber;
+	uint32_t dateTimeStamp;
+	uint32_t definVersion;
+	uint32_t implVersion;
+	uint32_t currentVersion;
+	uint16_t numSections;
+	uint16_t loadableSections;
+	uint32_t memoryAddress;
 };
 
 #define PEF_MAGIC 0x4A6F7921  /* Joy! */
@@ -53,16 +53,16 @@ struct FileHeader
 
 struct SectionHeader
 {
-	unsigned long sectionName;
-	unsigned long sectionAddress;
-	unsigned long execSize;
-	unsigned long initSize;
-	unsi

CVS commit: src/sys/arch/powerpc/stand/mkbootimage

2013-07-09 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Tue Jul  9 13:10:33 UTC 2013

Modified Files:
src/sys/arch/powerpc/stand/mkbootimage: mkbootimage.c

Log Message:
Fix format string.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 \
src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c
diff -u src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c:1.16 src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c:1.17
--- src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c:1.16	Wed Dec 19 13:47:20 2012
+++ src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c	Tue Jul  9 13:10:33 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: mkbootimage.c,v 1.16 2012/12/19 13:47:20 kiyohara Exp $	*/
+/*	$NetBSD: mkbootimage.c,v 1.17 2013/07/09 13:10:33 joerg Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -396,7 +396,7 @@ prep_build_image(char *kernel, char *boo
 	else
 		flength -= (2880 * 512);
 	if (flength > 0 && !saloneflag)
-		fprintf(stderr, "%s: Image %s is %d bytes larger than single"
+		fprintf(stderr, "%s: Image %s is %ld bytes larger than single"
 		" floppy. Can only be used for netboot.\n", getprogname(),
 		outname, flength);
 



CVS commit: src/sys/arch/powerpc/stand/mkbootimage

2013-07-09 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Tue Jul  9 13:10:55 UTC 2013

Modified Files:
src/sys/arch/powerpc/stand/mkbootimage: Makefile

Log Message:
Don't depend on libz.a for the tools build, /usr/lib/libz.a might not
exist.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/powerpc/stand/mkbootimage/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/powerpc/stand/mkbootimage/Makefile
diff -u src/sys/arch/powerpc/stand/mkbootimage/Makefile:1.4 src/sys/arch/powerpc/stand/mkbootimage/Makefile:1.5
--- src/sys/arch/powerpc/stand/mkbootimage/Makefile:1.4	Wed Jan 26 21:35:14 2011
+++ src/sys/arch/powerpc/stand/mkbootimage/Makefile	Tue Jul  9 13:10:55 2013
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.4 2011/01/26 21:35:14 joerg Exp $
+#	$NetBSD: Makefile,v 1.5 2013/07/09 13:10:55 joerg Exp $
 
 BINDIR=	/usr/mdec
 PROG=	mkbootimage
@@ -15,7 +15,9 @@ LIBSA=${.CURDIR}/../../../../lib/libsa
 
 CPPFLAGS= -I${LIBSA} -I${.CURDIR} -I${BFDTOP}/include
 CPPFLAGS+=	-DATTRIBUTE_PACKED=
+.if !defined(HOSTPROGNAME)
 DPADD+=	${LIBZ}
+.endif
 LDADD+=	-lz
 
 .include 



CVS commit: src/sys/arch/powerpc/stand/mkbootimage

2012-12-24 Thread KIYOHARA Takashi
Module Name:src
Committed By:   kiyohara
Date:   Mon Dec 24 14:01:25 UTC 2012

Modified Files:
src/sys/arch/powerpc/stand/mkbootimage: bebox_bootrec.h

Log Message:
Change name of boot image(mount point?) to 'NetBSD' from 'fd'.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 \
src/sys/arch/powerpc/stand/mkbootimage/bebox_bootrec.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/powerpc/stand/mkbootimage/bebox_bootrec.h
diff -u src/sys/arch/powerpc/stand/mkbootimage/bebox_bootrec.h:1.2 src/sys/arch/powerpc/stand/mkbootimage/bebox_bootrec.h:1.3
--- src/sys/arch/powerpc/stand/mkbootimage/bebox_bootrec.h:1.2	Sat May 24 17:34:03 2008
+++ src/sys/arch/powerpc/stand/mkbootimage/bebox_bootrec.h	Mon Dec 24 14:01:24 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: bebox_bootrec.h,v 1.2 2008/05/24 17:34:03 kiyohara Exp $	*/
+/*	$NetBSD: bebox_bootrec.h,v 1.3 2012/12/24 14:01:24 kiyohara Exp $	*/
 
 #define	BEBOX_HEADER_SIZE		0x6400
 #define	BEBOX_BLOCK_SIZE		0x200
@@ -14,8 +14,8 @@ u_char bebox_image_data0[] = {
 	0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x0b, 0x40,	/* avail size */
 	0x00, 0x00, 0x02, 0x00, 0xff, 0xff, 0xff, 0xff,
 	0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x0b, 0x40,	/* used block */
-	0x01, 0x00, 0x00, 0x00, 0x66, 0x64, 0x00, 0x00,
-	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+	0x01, 0x00, 0x00, 0x00, 0x4e, 0x65, 0x74, 0x42,
+	0x53, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,



CVS commit: src/sys/arch/powerpc/stand/mkbootimage

2012-12-19 Thread KIYOHARA Takashi
Module Name:src
Committed By:   kiyohara
Date:   Wed Dec 19 13:47:21 UTC 2012

Modified Files:
src/sys/arch/powerpc/stand/mkbootimage: mkbootimage.c

Log Message:
Obsolete options '-s'(standalone) on bebox.  bebox can boot no-standalone image
from FD or HDD.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 \
src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c
diff -u src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c:1.15 src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c:1.16
--- src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c:1.15	Sat May 19 14:47:37 2012
+++ src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c	Wed Dec 19 13:47:20 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: mkbootimage.c,v 1.15 2012/05/19 14:47:37 kiyohara Exp $	*/
+/*	$NetBSD: mkbootimage.c,v 1.16 2012/12/19 13:47:20 kiyohara Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -604,8 +604,6 @@ bebox_write_header(int bebox_fd, int elf
 	struct SectionHeader textHdr, dataHdr, ldrHdr;
 	struct LoaderHeader lh;
 
-	if (saloneflag)
-		hsize = 0;
 
 	ldrOffset = ULALIGN(sizeof (fileHdr) + sizeof (textHdr) +
 	sizeof (dataHdr) + sizeof (ldrHdr));
@@ -697,9 +695,6 @@ bebox_build_image(char *kernel, char *bo
 	struct timeval tp;
 	Elf32_External_Phdr phdr;
 
-	if (saloneflag)
-		hsize = 0;
-
 	elf_fd = open_file("bootloader", boot, &hdr, &elf_stat);
 	if (inkernflag) {
 		kern_fd = open_file("kernel", kernel, &khdr, &kern_stat);
@@ -805,11 +800,6 @@ bebox_build_image(char *kernel, char *bo
 		close(kern_fd);
 	close(elf_fd);
 
-	if (saloneflag) {
-		close(bebox_fd);
-		return 0;
-	}
-
 	/* Now go back and write in the block header */
 	endoff = lseek(bebox_fd, 0, SEEK_END);
 	lseek(bebox_fd, 0, SEEK_SET);



CVS commit: src/sys/arch/powerpc/stand/mkbootimage

2012-05-19 Thread KIYOHARA Takashi
Module Name:src
Committed By:   kiyohara
Date:   Sat May 19 14:47:38 UTC 2012

Modified Files:
src/sys/arch/powerpc/stand/mkbootimage: mkbootimage.c

Log Message:
prep's boot supports to load kernel from HDD.  We can specify option -I
(no in-kernel).


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 \
src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c
diff -u src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c:1.14 src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c:1.15
--- src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c:1.14	Wed Jan 26 21:35:14 2011
+++ src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c	Sat May 19 14:47:37 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: mkbootimage.c,v 1.14 2011/01/26 21:35:14 joerg Exp $	*/
+/*	$NetBSD: mkbootimage.c,v 1.15 2012/05/19 14:47:37 kiyohara Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -299,8 +299,11 @@ prep_build_image(char *kernel, char *boo
 	Elf32_External_Phdr phdr;
 
 	elf_fd = open_file("bootloader", boot, &hdr, &elf_stat);
-	kern_fd = open_file("kernel", kernel, &khdr, &kern_stat);
-	kern_len = kern_stat.st_size + PREP_MAGICSIZE + KERNLENSIZE;
+	if (inkernflag) {
+		kern_fd = open_file("kernel", kernel, &khdr, &kern_stat);
+		kern_len = kern_stat.st_size + PREP_MAGICSIZE + KERNLENSIZE;
+	} else
+		kern_len = PREP_MAGICSIZE + KERNLENSIZE;
 
 	for (i = 0; i < ELFGET16(hdr.e_phnum); i++) {
 		lseek(elf_fd, ELFGET32(hdr.e_phoff) + sizeof(phdr) * i,
@@ -342,17 +345,20 @@ prep_build_image(char *kernel, char *boo
 	write(prep_fd, elf_img, elf_img_len);
 	free(elf_img);
 
-	/* Copy kernel */
-	kern_img = (unsigned char *)malloc(kern_stat.st_size);
+	if (inkernflag) {
+		/* Copy kernel */
+		kern_img = (unsigned char *)malloc(kern_stat.st_size);
 
-	if (kern_img == NULL)
-		errx(3, "Can't malloc: %s", strerror(errno));
+		if (kern_img == NULL)
+			errx(3, "Can't malloc: %s", strerror(errno));
 
-	/* we need to jump back after having read the headers */
-	lseek(kern_fd, 0, SEEK_SET);
-	if (read(kern_fd, (void *)kern_img, kern_stat.st_size) !=
-	kern_stat.st_size)
-		errx(3, "Can't read kernel '%s' : %s", kernel, strerror(errno));
+		/* we need to jump back after having read the headers */
+		lseek(kern_fd, 0, SEEK_SET);
+		if (read(kern_fd, (void *)kern_img, kern_stat.st_size) !=
+		kern_stat.st_size)
+			errx(3, "Can't read kernel '%s' : %s",
+			kernel, strerror(errno));
+	}
 
 	gzf = gzdopen(dup(prep_fd), "a");
 	if (gzf == NULL)
@@ -368,8 +374,10 @@ prep_build_image(char *kernel, char *boo
 
 	/* write in the compressed kernel */
 	kstart = lseek(prep_fd, 0, SEEK_CUR);
-	kgzlen = gzwrite(gzf, kern_img, kern_stat.st_size);
-	gzclose(gzf);
+	if (inkernflag) {
+		kgzlen = gzwrite(gzf, kern_img, kern_stat.st_size);
+		gzclose(gzf);
+	}
 	kend = lseek(prep_fd, 0, SEEK_CUR);
 
 	/* jump back to the length position now that we know the length */
@@ -392,8 +400,10 @@ prep_build_image(char *kernel, char *boo
 		" floppy. Can only be used for netboot.\n", getprogname(),
 		outname, flength);
 
-	free(kern_img);
-	close(kern_fd);
+	if (inkernflag) {
+		free(kern_img);
+		close(kern_fd);
+	}
 	close(prep_fd);
 	close(elf_fd);
 



CVS commit: src/sys/arch/powerpc/stand/mkbootimage

2011-01-26 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Wed Jan 26 21:35:14 UTC 2011

Modified Files:
src/sys/arch/powerpc/stand/mkbootimage: Makefile mkbootimage.c

Log Message:
Fix tools build on !NetBSD. Fix printfs to use correct types.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/powerpc/stand/mkbootimage/Makefile
cvs rdiff -u -r1.13 -r1.14 \
src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/powerpc/stand/mkbootimage/Makefile
diff -u src/sys/arch/powerpc/stand/mkbootimage/Makefile:1.3 src/sys/arch/powerpc/stand/mkbootimage/Makefile:1.4
--- src/sys/arch/powerpc/stand/mkbootimage/Makefile:1.3	Sat Nov  7 17:56:14 2009
+++ src/sys/arch/powerpc/stand/mkbootimage/Makefile	Wed Jan 26 21:35:14 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.3 2009/11/07 17:56:14 skrll Exp $
+#	$NetBSD: Makefile,v 1.4 2011/01/26 21:35:14 joerg Exp $
 
 BINDIR=	/usr/mdec
 PROG=	mkbootimage
@@ -15,7 +15,7 @@
 
 CPPFLAGS= -I${LIBSA} -I${.CURDIR} -I${BFDTOP}/include
 CPPFLAGS+=	-DATTRIBUTE_PACKED=
-DPADD=	${LIBZ}
-LDADD=	-lz
+DPADD+=	${LIBZ}
+LDADD+=	-lz
 
 .include 

Index: src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c
diff -u src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c:1.13 src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c:1.14
--- src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c:1.13	Sat Oct 16 05:14:14 2010
+++ src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c	Wed Jan 26 21:35:14 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: mkbootimage.c,v 1.13 2010/10/16 05:14:14 kiyohara Exp $	*/
+/*	$NetBSD: mkbootimage.c,v 1.14 2011/01/26 21:35:14 joerg Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -527,19 +527,19 @@
 	write(rs6000_fd, (void *)rs6000_magic, RS6000_MAGICSIZE);
 	lenpos = lseek(rs6000_fd, 0, SEEK_CUR);
 	if (verboseflag)
-		printf("wrote magic at pos 0x%x\n", lenpos);
+		printf("wrote magic at pos 0x%lx\n", (unsigned long)lenpos);
 	tmp = sa_htobe32(0);
 	write(rs6000_fd, (void *)&tmp, KERNLENSIZE);
 
 	/* write in the compressed kernel */
 	kstart = lseek(rs6000_fd, 0, SEEK_CUR);
 	if (verboseflag)
-		printf("kernel start at pos 0x%x\n", kstart);
+		printf("kernel start at pos 0x%lx\n", (unsigned long)kstart);
 	kgzlen = gzwrite(gzf, kern_img, kern_stat.st_size);
 	gzclose(gzf);
 	kend = lseek(rs6000_fd, 0, SEEK_CUR);
 	if (verboseflag)
-		printf("kernel end at pos 0x%x\n", kend);
+		printf("kernel end at pos 0x%lx\n", (unsigned long)kend);
 
 	/* jump back to the length position now that we know the length */
 	lseek(rs6000_fd, lenpos, SEEK_SET);



CVS commit: src/sys/arch/powerpc/stand/mkbootimage

2010-10-15 Thread KIYOHARA Takashi
Module Name:src
Committed By:   kiyohara
Date:   Sat Oct 16 05:14:15 UTC 2010

Modified Files:
src/sys/arch/powerpc/stand/mkbootimage: mkbootimage.c

Log Message:
Add option -I (no-inkernel).  bebox loads kernel from HDD.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 \
src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c
diff -u src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c:1.12 src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c:1.13
--- src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c:1.12	Sat Oct 16 05:05:09 2010
+++ src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c	Sat Oct 16 05:14:14 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: mkbootimage.c,v 1.12 2010/10/16 05:05:09 kiyohara Exp $	*/
+/*	$NetBSD: mkbootimage.c,v 1.13 2010/10/16 05:14:14 kiyohara Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -70,6 +70,7 @@
 
 /* Globals */
 
+int inkernflag = 1;
 int saloneflag = 0;
 int verboseflag = 0;
 int lfloppyflag = 0;
@@ -125,10 +126,10 @@
 		fprintf(stderr, "\n\n");
 	}
 #ifdef USE_SYSCTL
-	fprintf(stderr, "usage: %s [-lsv] [-m machine] [-b bootfile] "
+	fprintf(stderr, "usage: %s [-Ilsv] [-m machine] [-b bootfile] "
 	"[-k kernel] [-r rawdev] bootimage\n", getprogname());
 #else
-	fprintf(stderr, "usage: %s [-lsv] -m machine [-b bootfile] "
+	fprintf(stderr, "usage: %s [-Ilsv] -m machine [-b bootfile] "
 	"[-k kernel] [-r rawdev] bootimage\n", getprogname());
 #endif
 	exit(1);
@@ -690,8 +691,11 @@
 		hsize = 0;
 
 	elf_fd = open_file("bootloader", boot, &hdr, &elf_stat);
-	kern_fd = open_file("kernel", kernel, &khdr, &kern_stat);
-	kern_len = kern_stat.st_size + BEBOX_MAGICSIZE + KERNLENSIZE;
+	if (inkernflag) {
+		kern_fd = open_file("kernel", kernel, &khdr, &kern_stat);
+		kern_len = kern_stat.st_size + BEBOX_MAGICSIZE + KERNLENSIZE;
+	} else
+		kern_len = BEBOX_MAGICSIZE + KERNLENSIZE;
 
 	for (i = 0; i < ELFGET16(hdr.e_phnum); i++) {
 		lseek(elf_fd, ELFGET32(hdr.e_phoff) + sizeof(phdr) * i,
@@ -719,26 +723,34 @@
 	}
 	lseek(bebox_fd, hsize, SEEK_SET);
 
-	/* write the header with the wrong values to get the offset right */
-	bebox_write_header(bebox_fd, elf_img_len, kern_stat.st_size);
-
-	/* Copy kernel */
-	kern_img = (unsigned char *)malloc(kern_stat.st_size);
-
-	if (kern_img == NULL)
-		errx(3, "Can't malloc: %s", strerror(errno));
-
-	/* we need to jump back after having read the headers */
-	lseek(kern_fd, 0, SEEK_SET);
-	if (read(kern_fd, (void *)kern_img, kern_stat.st_size) !=
-	kern_stat.st_size)
-		errx(3, "Can't read kernel '%s' : %s", kernel, strerror(errno));
-
-	gzf = gzdopen(dup(bebox_fd), "a");
-	if (gzf == NULL)
-		errx(3, "Can't init compression: %s", strerror(errno));
-	if (gzsetparams(gzf, Z_BEST_COMPRESSION, Z_DEFAULT_STRATEGY) != Z_OK)
-		errx(3, "%s", gzerror(gzf, &err));
+	if (inkernflag) {
+		/*
+		 * write the header with the wrong values to get the offset
+		 * right
+		 */
+		bebox_write_header(bebox_fd, elf_img_len, kern_stat.st_size);
+
+		/* Copy kernel */
+		kern_img = (unsigned char *)malloc(kern_stat.st_size);
+
+		if (kern_img == NULL)
+			errx(3, "Can't malloc: %s", strerror(errno));
+
+		/* we need to jump back after having read the headers */
+		lseek(kern_fd, 0, SEEK_SET);
+		if (read(kern_fd, (void *)kern_img, kern_stat.st_size) !=
+		kern_stat.st_size)
+			errx(3, "Can't read kernel '%s' : %s",
+			kernel, strerror(errno));
+
+		gzf = gzdopen(dup(bebox_fd), "a");
+		if (gzf == NULL)
+			errx(3, "Can't init compression: %s", strerror(errno));
+		if (gzsetparams(gzf, Z_BEST_COMPRESSION, Z_DEFAULT_STRATEGY) !=
+		Z_OK)
+			errx(3, "%s", gzerror(gzf, &err));
+	} else
+		bebox_write_header(bebox_fd, elf_img_len, 0);
 
 	/* write a magic number and size before the kernel */
 	write(bebox_fd, (void *)bebox_magic, BEBOX_MAGICSIZE);
@@ -746,12 +758,17 @@
 	tmp = sa_htobe32(0);
 	write(bebox_fd, (void *)&tmp, KERNLENSIZE);
 
-	/* write in the compressed kernel */
-	kstart = lseek(bebox_fd, 0, SEEK_CUR);
-	kgzlen = gzwrite(gzf, kern_img, kern_stat.st_size);
-	gzclose(gzf);
-	kend = lseek(bebox_fd, 0, SEEK_CUR);
-	free(kern_img);
+	if (inkernflag) {
+		/* write in the compressed kernel */
+		kstart = lseek(bebox_fd, 0, SEEK_CUR);
+		kgzlen = gzwrite(gzf, kern_img, kern_stat.st_size);
+		gzclose(gzf);
+		kend = lseek(bebox_fd, 0, SEEK_CUR);
+		free(kern_img);
+	} else {
+		kstart = kend = lseek(bebox_fd, 0, SEEK_CUR);
+		kgzlen = 0;
+	}
 
 	/* jump back to the length position now that we know the length */
 	lseek(bebox_fd, lenpos, SEEK_SET);
@@ -774,7 +791,8 @@
 	write(bebox_fd, elf_img, elf_img_len);
 	free(elf_img);
 
-	close(kern_fd);
+	if (inkernflag)
+		close(kern_fd);
 	close(elf_fd);
 
 	if (saloneflag) {
@@ -837,13 +855,17 @@
 	setprogname(argv[0]);
 	kern_len = 0;
 
-	while ((ch = get

CVS commit: src/sys/arch/powerpc/stand/mkbootimage

2010-10-15 Thread KIYOHARA Takashi
Module Name:src
Committed By:   kiyohara
Date:   Sat Oct 16 05:05:09 UTC 2010

Modified Files:
src/sys/arch/powerpc/stand/mkbootimage: mkbootimage.c pef.h

Log Message:
Remove unnecessary white-spaces and Tabs.
Replace white-spaces to Tab.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 \
src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/powerpc/stand/mkbootimage/pef.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c
diff -u src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c:1.11 src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c:1.12
--- src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c:1.11	Mon Sep  1 19:03:44 2008
+++ src/sys/arch/powerpc/stand/mkbootimage/mkbootimage.c	Sat Oct 16 05:05:09 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: mkbootimage.c,v 1.11 2008/09/01 19:03:44 martin Exp $	*/
+/*	$NetBSD: mkbootimage.c,v 1.12 2010/10/16 05:05:09 kiyohara Exp $	*/
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -232,7 +232,7 @@
 
 	memset(mbr, 0, sizeof(mbr));
 	mbrp = (struct mbr_partition *)&mbr[MBR_PART_OFFSET];
- 
+
 	/* Set entry point and boot image size skipping over elf header */
 	entry  = sa_htole32(0x400);
 	length = sa_htole32(elf_stat.st_size - sizeof(hdr) + 0x400);
@@ -241,7 +241,7 @@
 	 * Set magic number for msdos partition
 	 */
 	*(unsigned short *)&mbr[MBR_MAGIC_OFFSET] = sa_htole16(MBR_MAGIC);
-  
+
 	/*
 	 * Build a "PReP" partition table entry in the boot record
 	 *  - "PReP" may only look at the system_indicator
@@ -256,15 +256,15 @@
 	 * one partition on the diskette and it shall contain the rest of the
 	 * diskette.
 	 */
-	mbrp->mbrp_shd   = 0;	/* zero-based			 */
-	mbrp->mbrp_ssect = 2;	/* one-based			 */
-	mbrp->mbrp_scyl  = 0;	/* zero-based			 */
-	mbrp->mbrp_ehd   = 1;	/* assumes two heads		 */
+	mbrp->mbrp_shd   = 0;	/* zero-based */
+	mbrp->mbrp_ssect = 2;	/* one-based */
+	mbrp->mbrp_scyl  = 0;	/* zero-based */
+	mbrp->mbrp_ehd   = 1;	/* assumes two heads */
 	if (lfloppyflag)
-		mbrp->mbrp_esect = 36;  /* 2.88MB floppy	 */
+		mbrp->mbrp_esect = 36;  /* 2.88MB floppy */
 	else
-		mbrp->mbrp_esect = 18;	/* assumes 18 sectors/track  */
-	mbrp->mbrp_ecyl  = 79;	/* assumes 80 cylinders/diskette */
+		mbrp->mbrp_esect = 18;	/* assumes 18 sectors/track */
+	mbrp->mbrp_ecyl  = 79;	/* assumes 80 cylinders/diskette */
 
 	/*
 	 * The "PReP" software ignores the above fields and just looks at
@@ -275,13 +275,13 @@
 	 * the beginning sector is zero-based!
 	 */
 
-	/* This has to be 0 on the PowerStack? */   
+	/* This has to be 0 on the PowerStack? */
 	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));
-	write(prep_fd, &length, sizeof(length));  
+	write(prep_fd, &length, sizeof(length));
 }
 
 static int
@@ -397,7 +397,7 @@
 	close(elf_fd);
 
 	return 0;
-}	
+}
 
 /* Fill in the needed information on the boot and config records.  Most of
  * this is just AIX garbage that we don't really need to boot.
@@ -595,7 +595,7 @@
 
 	if (saloneflag)
 		hsize = 0;
-	
+
 	ldrOffset = ULALIGN(sizeof (fileHdr) + sizeof (textHdr) +
 	sizeof (dataHdr) + sizeof (ldrHdr));
 	dataOffset = ULALIGN(ldrOffset + sizeof (lh));
@@ -605,70 +605,70 @@
 	memset(&fileHdr, 0, sizeof (fileHdr));
 	fileHdr.magic = sa_htobe32(PEF_MAGIC);
 	fileHdr.fileTypeID = sa_htobe32(PEF_FILE);
-fileHdr.archID = sa_htobe32(PEF_PPC);
-fileHdr.versionNumber = sa_htobe32(1);
-fileHdr.numSections = sa_htobe16(3);
-fileHdr.loadableSections = sa_htobe16(2);
-write(bebox_fd, &fileHdr, sizeof (fileHdr));
+	fileHdr.archID = sa_htobe32(PEF_PPC);
+	fileHdr.versionNumber = sa_htobe32(1);
+	fileHdr.numSections = sa_htobe16(3);
+	fileHdr.loadableSections = sa_htobe16(2);
+	write(bebox_fd, &fileHdr, sizeof (fileHdr));
 
 	/* Create the Section Header for TEXT */
 	memset(&textHdr, 0, sizeof (textHdr));
-textHdr.sectionName = sa_htobe32(-1);
-textHdr.sectionAddress = sa_htobe32(0);
-textHdr.execSize = sa_htobe32(elf_image_len);
-textHdr.initSize = sa_htobe32(elf_image_len);
-textHdr.rawSize = sa_htobe32(elf_image_len);
-textHdr.fileOffset = sa_htobe32(textOffset);
-textHdr.regionKind = CodeSection;
-textHdr.shareKind = ContextShare;
-textHdr.alignment = 4;  /* 16 byte alignment */
-write(bebox_fd, &textHdr, sizeof (textHdr));
+	textHdr.sectionName = sa_htobe32(-1);
+	textHdr.sectionAddress = sa_htobe32(0);
+	textHdr.execSize = sa_htobe32(elf_image_len);
+	textHdr.initSize = sa_htobe32(elf_image_len);
+	textHdr.rawSize = sa_htobe32(elf_image_len);
+	textHdr.fileOffset = sa_htobe32(textOffset);
+	textHdr.regionKind = CodeSection;
+	textHdr.shareKind = Contex