From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.redhat.com (mail.redhat.com [199.183.24.239]) by listman.redhat.com (Postfix) with ESMTP id 1F9D82F2DE for ; Wed, 27 Dec 2000 20:38:57 -0500 (EST) Received: (from mail@localhost) by mail.redhat.com (8.11.0/8.8.7) id eBS1cv813316 for axp-list@listman.redhat.com; Wed, 27 Dec 2000 20:38:57 -0500 Received: from alpha-gw.alpha-processor.com (alpha-gw.alpha-processor.com [192.233.59.9]) by mail.redhat.com (8.11.0/8.8.7) with SMTP id eBS1cuD13312 for ; Wed, 27 Dec 2000 20:38:56 -0500 Received: from barracuda.alpha-processor.com by alpha-gw.alpha-processor.com via smtpd (for mail.redhat.com [199.183.24.239]) with SMTP; 28 Dec 2000 01:40:40 UT Received: by barracuda.alpha-processor.com with Internet Mail Service (5.5.2650.21) id ; Wed, 27 Dec 2000 20:35:20 -0500 Message-ID: <051DFF3BBA73D3119A5800A0C95BD021C038EB@barracuda.alpha-processor.com> From: Soohoon Lee To: "'axp-list@redhat.com'" Subject: net aboot + initrd Date: Wed, 27 Dec 2000 20:35:20 -0500 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2650.21) Content-Type: multipart/mixed; boundary="----_=_NextPart_000_01C0706E.70C4C5D2" X-Loop: axp-list@redhat.com Sender: axp-list-admin@redhat.com Errors-To: axp-list-admin@redhat.com X-BeenThere: axp-list@redhat.com X-Mailman-Version: 2.0beta4 Precedence: bulk Reply-To: axp-list@redhat.com List-Id: Linux and Red Hat on Alpha processors This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_000_01C0706E.70C4C5D2 Content-Type: text/plain; charset="iso-8859-1" If there's anybody who wants to network boot linux with initrd support and don't want to compile kernel for network boot, try this one. You could use this for installation etc. without any media like floppies and cdrom. Usage: Apply attached patch file to aboot-0.7a. # make netabootwrap. You'll get netabootwrap executable. then run # netabootwrap -t netboot.img -k vmlinux.gz -i initrd.gz -a "root=/dev/hda2" then it will build netboot.img binary. It's aboot+vmlinux.gz+initrd.gz. all of the arguments are optional. To build an image for redhat installation, grab kernels/vmlinux.gz and images/ramdisk.img from redhat CDROM. and run # netabootwrap -i ramdisk.img if all the files are in the same directory. And boot it. I couldn't reach to David Huggins-Daines, so I'm posting here. Soohoon. ------_=_NextPart_000_01C0706E.70C4C5D2 Content-Type: application/octet-stream; name="netabootwrap.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="netabootwrap.patch" diff -Naur /usr/src/redhat/BUILD/aboot-0.7a/ChangeLog ab/ChangeLog=0A= --- /usr/src/redhat/BUILD/aboot-0.7a/ChangeLog Tue Jun 27 12:06:06 = 2000=0A= +++ ab/ChangeLog Wed Dec 27 21:15:46 2000=0A= @@ -1,3 +1,12 @@=0A= +2000-12-27 Soohoon Lee =0A= + * network boot with initrd support.=0A= + To make things easy(no recompile etc.) there's netabootwrap.=0A= + It'll merge net_aboot, kernel and initrd images and build=0A= + network bootable image. net_aboot.nh will not be usable=0A= + but netabootwrap has all the functions.=0A= + Without options, It'll look for vmlinux.gz and build=0A= + netboot.img, it's net_aboot + vmlinux.gz.=0A= +=0A= 2000-06-27 David Huggins-Daines =0A= =0A= * README: Removed the doc/ subdirectory, since it was out of sync=0A= diff -Naur /usr/src/redhat/BUILD/aboot-0.7a/Makefile ab/Makefile=0A= --- /usr/src/redhat/BUILD/aboot-0.7a/Makefile Tue Jun 27 11:54:57 = 2000=0A= +++ ab/Makefile Wed Dec 27 19:19:00 2000=0A= @@ -76,6 +76,13 @@=0A= =0A= netboot: vmlinux.bootp=0A= =0A= +bootloader.h: net_aboot.nh b2c=0A= + ./b2c net_aboot.nh bootloader.h bootloader=0A= +=0A= +netabootwrap: netabootwrap.c bootloader.h=0A= + $(CC) $@.c $(CFLAGS) -o $@ =0A= + =0A= +=0A= bootlx: aboot tools/objstrip=0A= tools/objstrip -vb aboot bootlx=0A= =0A= @@ -103,6 +110,7 @@=0A= cat net_aboot.nh $(VMLINUXGZ) net_pad > $@=0A= =0A= net_aboot.nh: net_aboot tools/objstrip=0A= + strip net_aboot=0A= tools/objstrip -vb net_aboot $@=0A= =0A= net_aboot: $(ABOOT_OBJS) $(ABOOT_OBJS) $(NET_OBJS) $(LIBS)=0A= @@ -114,7 +122,7 @@=0A= clean: sdisklabel/clean tools/clean lib/clean=0A= rm -f aboot abootconf net_aboot net_aboot.nh net_pad vmlinux.bootp = \=0A= $(ABOOT_OBJS) $(DISK_OBJS) $(NET_OBJS) bootlx \=0A= - include/ksize.h vmlinux.nh=0A= + include/ksize.h vmlinux.nh b2c bootloader.h netabootwrap=0A= =0A= distclean: clean=0A= find . -name \*~ | xargs rm -f=0A= diff -Naur /usr/src/redhat/BUILD/aboot-0.7a/b2c.c ab/b2c.c=0A= --- /usr/src/redhat/BUILD/aboot-0.7a/b2c.c Wed Dec 31 19:00:00 1969=0A= +++ ab/b2c.c Wed Dec 27 19:09:50 2000=0A= @@ -0,0 +1,70 @@=0A= +=0A= +=0A= +#include =0A= +#include =0A= +#include =0A= +#include =0A= +#include =0A= +=0A= +void print_usage(void )=0A= +{=0A= + printf("Usage: b2c bin_img tar_file.h symname\n");=0A= + exit(1);=0A= +}=0A= +=0A= +void open_file(char *fn, int *fd, int *sz)=0A= +{=0A= + struct stat buf;=0A= +=0A= + *fd =3D open(fn, O_RDONLY);=0A= + if (fd < 0) {=0A= + printf("cannot open %s\n", fn);=0A= + exit(1);=0A= + }=0A= +=0A= + fstat(*fd, &buf);=0A= +=0A= + if (buf.st_size <=3D 10*1024) {=0A= + printf("Is this a right file %s, size =3D %ld\n", fn, = buf.st_size);=0A= + exit(1);=0A= + }=0A= +=0A= + *sz =3D (int)buf.st_size;=0A= +}=0A= +=0A= +int main(int argc, char **argv)=0A= +{=0A= + int sfd, ssz, red, i;=0A= + int buf[1024];=0A= + char *sfn, *tfn, *symname;=0A= + FILE *tfd;=0A= +=0A= + if (argc !=3D 4) {=0A= + print_usage();=0A= + }=0A= +=0A= + sfn =3D argv[1];=0A= + tfn =3D argv[2];=0A= + symname =3D argv[3];=0A= +=0A= + open_file(sfn, &sfd, &ssz);=0A= +=0A= + tfd =3D fopen(tfn, "w");=0A= +=0A= + fprintf(tfd, "int %s[] =3D {\n", symname);=0A= +=0A= + while((red=3Dread(sfd, buf, 1024*sizeof(int)))) {=0A= + for (i=3D0; i=0A= #include =0A= #include =0A= +#include "netwrap.h"=0A= =0A= extern char boot_file[256];=0A= =0A= @@ -37,17 +38,16 @@=0A= printf("aboot: oops, unimplemented net-bfs function called!\n");=0A= }=0A= =0A= +extern char _end;=0A= +static char *src =3D 0;=0A= +static char *kern_src=3D0, *ird_src=3D0;=0A= +static int header_size=3D0, kern_size=3D0, ird_size=3D0;=0A= =0A= int=0A= net_bread (int fd, long blkno, long nblks, char * buf)=0A= {=0A= - static char * src =3D 0;=0A= - extern char _end;=0A= int nbytes;=0A= =0A= - if (!src)=0A= - src =3D (char *) (((unsigned long) &_end + 511) & ~511);=0A= -=0A= #ifdef DEBUG=0A= printf("net_bread: %p -> %p (%ld blocks at %ld)\n", src, buf,=0A= nblks, blkno);=0A= @@ -60,7 +60,6 @@=0A= return nbytes;=0A= }=0A= =0A= -=0A= struct bootfs netfs =3D {=0A= -1, 512,=0A= (int (*)(long, long, long)) dang, /* mount */=0A= @@ -71,19 +70,71 @@=0A= (int (*)(int, struct stat*)) dang, /* fstat */=0A= };=0A= =0A= +long=0A= +read_initrd()=0A= +{=0A= + int nblocks, nread;=0A= +=0A= + /* put it as high up in memory as possible */=0A= + initrd_start =3D free_mem_ptr - align_pagesize(ird_size);=0A= + initrd_size =3D ird_size;=0A= + /* update free_mem_ptr so malloc() still works */=0A= + free_mem_ptr =3D initrd_start;=0A= +#ifdef DEBUG=0A= + printf("memory_end %x %x\n", free_mem_ptr, initrd_start);=0A= +#endif=0A= +=0A= + nblocks =3D align_512(ird_size)/ 512;=0A= + printf("aboot: loading initrd (%d bytes/%d blocks) at %#lx\n",=0A= + ird_size, nblocks, initrd_start);=0A= + nread =3D (*bfs->bread)(-1, 0, nblocks, (char*) initrd_start);=0A= + return 0;=0A= +}=0A= +=0A= =0A= long=0A= load_kernel (void)=0A= {=0A= - long nbytes;=0A= -=0A= + struct header *header;=0A= bfs =3D &netfs;=0A= =0A= + header =3D (struct header *)align_512( (unsigned long)&_end );=0A= + header_size =3D header->header_size;=0A= + kern_src =3D (char *)align_512((unsigned long)header + = header_size);=0A= + kern_size =3D header->kern_size;=0A= + ird_src =3D (char *)align_512((unsigned long)kern_src + = kern_size);=0A= + ird_size =3D header->ird_size;=0A= +=0A= + if (!free_mem_ptr)=0A= + free_mem_ptr =3D memory_end();=0A= + free_mem_ptr =3D free_mem_ptr & ~(PAGE_SIZE-1);=0A= +=0A= +#ifdef DEBUG=0A= + printf("head %x %x kernel %x %x, initrd %x %x \n", header, = header_size, kern_src, kern_size, ird_src, ird_size);=0A= +#endif=0A= +=0A= + if (ird_size) {=0A= + src =3D ird_src;=0A= + if (read_initrd() < 0) {=0A= + return -1;=0A= + }=0A= + }=0A= +=0A= strcpy(boot_file, "network");=0A= +=0A= + //Move kernel to safe place before uncompression=0A= + src =3D (char*)free_mem_ptr - align_pagesize(kern_size);=0A= + (char*)free_mem_ptr =3D src;=0A= + memcpy(src, kern_src, kern_size);=0A= +=0A= uncompress_kernel(-1);=0A= =0A= memset((char*)bss_start, 0, bss_size); /* clear bss */=0A= =0A= + if (!kernel_args[0] && header->boot_arg[0]) { //have argument?=0A= + strncpy(kernel_args, header->boot_arg, header_size - = sizeof(int)*3);=0A= + }=0A= +=0A= while (kernel_args[0] =3D=3D 'i' && !kernel_args[1]) {=0A= printf("Enter kernel arguments:\n");=0A= printf("aboot> ");=0A= @@ -92,3 +143,4 @@=0A= }=0A= return 0;=0A= }=0A= +=0A= diff -Naur /usr/src/redhat/BUILD/aboot-0.7a/netabootwrap.c = ab/netabootwrap.c=0A= --- /usr/src/redhat/BUILD/aboot-0.7a/netabootwrap.c Wed Dec 31 19:00:00 = 1969=0A= +++ ab/netabootwrap.c Wed Dec 27 19:09:54 2000=0A= @@ -0,0 +1,186 @@=0A= +=0A= +#include =0A= +#include =0A= +#include =0A= +#include =0A= +#include =0A= +#include =0A= +#include =0A= +#include =0A= +#include "netwrap.h"=0A= +#include "bootloader.h"=0A= +=0A= +=0A= +char *tfn=3D"netboot.img", *kfn=3D"vmlinux.gz", *ifn=3DNULL, = *barg=3DNULL;=0A= +char *progname;=0A= +=0A= +void print_usage(void )=0A= +{=0A= + printf("Following shows options and default values or example = value\n");=0A= + printf("%s -t netboot.img -k vmlinux.gz -i initrd.gz -a = \"root=3D/dev/hda1 single\"\n", progname);=0A= + exit(1);=0A= +}=0A= +=0A= +void open_file(char *fn, int *fd, int *sz)=0A= +{=0A= + struct stat buf;=0A= +=0A= + *fd =3D open(fn, O_RDONLY);=0A= + if (fd < 0) {=0A= + fprintf(stderr, "%s: Cannot open %s\n", progname, fn);=0A= + print_usage();=0A= + exit(1);=0A= + }=0A= +=0A= + fstat(*fd, &buf);=0A= +=0A= + if (buf.st_size <=3D 10*1024) {=0A= + fprintf(stderr, "%s:Is this a right file %s, size =3D %d\n", = progname, fn, (int)buf.st_size);=0A= + print_usage();=0A= + exit(1);=0A= + }=0A= +=0A= + *sz =3D buf.st_size;=0A= +}=0A= +=0A= +void append_file(int tfd, int sfd)=0A= +{=0A= + char buf[4096];=0A= + int red;=0A= +=0A= + while ((red=3Dread(sfd, buf, 4096)))=0A= + write(tfd, buf, red);=0A= +}=0A= +=0A= +int main(int argc, char **argv)=0A= +{=0A= + int tfd=3D0, kfd=3D0, ifd=3D0, ksz=3D0, isz=3D0;=0A= + struct header hdr;=0A= + char *stmp;=0A= +=0A= + progname=3Dargv[0];=0A= +=0A= + /*=0A= + * Read switches.=0A= + */=0A= + for (argc--, argv++; argc > 0; argc--, argv++) {=0A= + if (argv[0][0] !=3D '-')=0A= + break;=0A= + switch (argv[0][1]) {=0A= +=0A= + case 't': /* override hostname */=0A= + if (argv[0][2]) {=0A= + stmp =3D &(argv[0][2]);=0A= + } else {=0A= + argc--;=0A= + argv++;=0A= + stmp =3D argv[0];=0A= + }=0A= + if (!stmp) {=0A= + fprintf(stderr,=0A= + "bootpd: missing hostname\n");=0A= + break;=0A= + }=0A= + tfn =3D stmp;=0A= + break;=0A= + case 'k': /* override hostname */=0A= + if (argv[0][2]) {=0A= + stmp =3D &(argv[0][2]);=0A= + } else {=0A= + argc--;=0A= + argv++;=0A= + stmp =3D argv[0];=0A= + }=0A= + if (!stmp) {=0A= + fprintf(stderr,=0A= + "bootpd: missing hostname\n");=0A= + break;=0A= + }=0A= + kfn =3D stmp;=0A= + break;=0A= + case 'i': /* override hostname */=0A= + if (argv[0][2]) {=0A= + stmp =3D &(argv[0][2]);=0A= + } else {=0A= + argc--;=0A= + argv++;=0A= + stmp =3D argv[0];=0A= + }=0A= + if (!stmp) {=0A= + fprintf(stderr,=0A= + "bootpd: missing hostname\n");=0A= + break;=0A= + }=0A= + ifn =3D stmp;=0A= + break;=0A= + case 'a': /* override hostname */=0A= + if (argv[0][2]) {=0A= + stmp =3D &(argv[0][2]);=0A= + } else {=0A= + argc--;=0A= + argv++;=0A= + stmp =3D argv[0];=0A= + }=0A= + if (!stmp) {=0A= + fprintf(stderr,=0A= + "bootpd: missing hostname\n");=0A= + break;=0A= + }=0A= + barg =3D stmp;=0A= + break;=0A= + default:=0A= + fprintf(stderr, "%s: unknown switch: -%c\n",=0A= + progname, argv[0][1]);=0A= + print_usage();=0A= + break;=0A= +=0A= + } /* switch */=0A= + } /* for args */=0A= +=0A= + open_file(kfn, &kfd, &ksz);=0A= +=0A= + if (ifn)=0A= + open_file(ifn, &ifd, &isz);=0A= +=0A= + printf("Target file name is %s\n", tfn);=0A= + unlink(tfn);=0A= + tfd =3D open(tfn, O_RDWR|O_CREAT, 0644);=0A= +=0A= + write(tfd, bootloader, sizeof(bootloader));=0A= +=0A= + hdr.header_size =3D sizeof(int)*3;=0A= + hdr.kern_size =3D ksz;=0A= + hdr.ird_size =3D isz;=0A= +=0A= + if (barg) printf("With arguments : %s \n", barg);=0A= + else printf("Without kernel argument\n");=0A= +=0A= + if (barg) {=0A= + if (strlen(barg) >=3D 200) {=0A= + printf("Argument is too long\n");=0A= + exit(1);=0A= + }=0A= + strncpy(hdr.boot_arg, barg, strlen(barg)+1);=0A= + hdr.header_size +=3D strlen(barg)+1;=0A= + }=0A= +=0A= + lseek(tfd, align_512(sizeof(bootloader)), SEEK_SET);=0A= + write(tfd, &hdr, hdr.header_size);=0A= +=0A= + printf("Binding kernel %s\n", kfn);=0A= + lseek(tfd, align_512((unsigned long)lseek(tfd, 0, SEEK_CUR)), = SEEK_SET);=0A= + append_file(tfd, kfd);=0A= +=0A= + if (ifn) {=0A= + printf("Binding initrd %s\n", ifn);=0A= + lseek(tfd, align_512((unsigned long)lseek(tfd, 0, SEEK_CUR)), = SEEK_SET);=0A= + append_file(tfd, ifd);=0A= + }=0A= +=0A= + close(tfd);=0A= + printf("Done.\n");=0A= + return 0;=0A= +}=0A= +=0A= +=0A= +=0A= diff -Naur /usr/src/redhat/BUILD/aboot-0.7a/netwrap.h ab/netwrap.h=0A= --- /usr/src/redhat/BUILD/aboot-0.7a/netwrap.h Wed Dec 31 19:00:00 = 1969=0A= +++ ab/netwrap.h Wed Dec 27 19:10:09 2000=0A= @@ -0,0 +1,17 @@=0A= +struct header {=0A= + int header_size;=0A= + int kern_size;=0A= + int ird_size; =0A= + char boot_arg[200]; =0A= +} ;=0A= +=0A= +unsigned long align_pagesize(unsigned long v)=0A= +{=0A= + return ((v + (PAGE_SIZE-1)) & ~(PAGE_SIZE-1));=0A= +}=0A= +=0A= +unsigned long align_512(unsigned long v)=0A= +{=0A= + return ((v + 511) & ~511);=0A= +}=0A= +=0A= ------_=_NextPart_000_01C0706E.70C4C5D2--