wok rev 16022

syslinux/iso2exe: add zimage support
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Mar 06 19:57:41 2014 +0000 (2014-03-06)
parents 73fb2ebfd59a
children e1d1bc3c15d0
files syslinux/stuff/iso2exe/README syslinux/stuff/iso2exe/boot.c syslinux/stuff/iso2exe/bootlinux.c syslinux/stuff/iso2exe/init
line diff
     1.1 --- a/syslinux/stuff/iso2exe/README	Thu Mar 06 00:03:58 2014 +0100
     1.2 +++ b/syslinux/stuff/iso2exe/README	Thu Mar 06 19:57:41 2014 +0000
     1.3 @@ -78,14 +78,12 @@
     1.4  
     1.5  Limitations:
     1.6  
     1.7 -- Only DOS 3, 4 and 6 boot supported. Checked with http://www.allbootdisks.com/
     1.8 +- Only DOS 3 to 7 boot supported. Checked with http://www.allbootdisks.com/
     1.9    NT/XP support via boot device creation.
    1.10  
    1.11  - Real mode support only. VM86 is not supported. Will not boot directly, but
    1.12    a removable boot media is created.
    1.13  
    1.14 -- Image/zImage format not supported, bzImage only. Can't boot memtest or ipxe.
    1.15 -
    1.16  - The DOS Linux loader and the ISO initramfs must fit in ~30Kb.
    1.17  
    1.18  - Linux kernels before version 2.6.30 don't support multiple initramfs load.
    1.19 @@ -100,5 +98,3 @@
    1.20  
    1.21  - floppy bootstrap
    1.22  
    1.23 -- zImage support ?
    1.24 -
     2.1 --- a/syslinux/stuff/iso2exe/boot.c	Thu Mar 06 00:03:58 2014 +0100
     2.2 +++ b/syslinux/stuff/iso2exe/boot.c	Thu Mar 06 19:57:41 2014 +0000
     2.3 @@ -67,6 +67,13 @@
     2.4  	return 0;
     2.5  }
     2.6  
     2.7 +static int chkstatus(int status, char *name)
     2.8 +{
     2.9 +	if (status == -1)
    2.10 +		printf("%s not found.\n",name);
    2.11 +	return status;
    2.12 +}
    2.13 +
    2.14  static char *iso;
    2.15  static int fakeopen(char *file)
    2.16  {
    2.17 @@ -78,14 +85,15 @@
    2.18  	if (*file == '\\') {
    2.19  		static fd = -1;
    2.20  		if (fd >= 0) close(fd);
    2.21 -		return open(file, O_RDONLY);
    2.22 +		fd = chkstatus(open(file, O_RDONLY), file);
    2.23 +		return fd;
    2.24  	}
    2.25  	if (iso) {
    2.26 -		isoreset(iso);
    2.27 -		return isoopen(file);
    2.28 +		chkstatus(isoreset(iso), iso);
    2.29 +		return chkstatus(isoopen(file), file);
    2.30  	}
    2.31  	close(isofd);
    2.32 -	isofd = open(file, O_RDONLY);
    2.33 +	isofd = chkstatus(open(file, O_RDONLY), file);
    2.34  	if (isofd != -1) {
    2.35  		isofileofs = 0;
    2.36  		isofilesize = LONG_MAX;
    2.37 @@ -100,7 +108,7 @@
    2.38  	
    2.39  	argv[0] = progname();
    2.40  	bootiso(argv);	// iso ? parsing is /init.exe stuff !
    2.41 -	if (argc == 2)
    2.42 +	if (argc >= 2)
    2.43  		bootiso(argv + 1);
    2.44  
    2.45  	chdirname(*argv);
    2.46 @@ -127,7 +135,7 @@
    2.47  	}
    2.48  	if (cmdfile) {
    2.49  		int fd;
    2.50 -		fd = open(cmdfile, O_RDONLY);;
    2.51 +		fd = chkstatus(open(cmdfile, O_RDONLY), chkstatus);
    2.52  		if (fd != -1) {
    2.53  			read(fd, args, sizeof(args));
    2.54  			close(fd);
     3.1 --- a/syslinux/stuff/iso2exe/bootlinux.c	Thu Mar 06 00:03:58 2014 +0100
     3.2 +++ b/syslinux/stuff/iso2exe/bootlinux.c	Thu Mar 06 19:57:41 2014 +0000
     3.3 @@ -1,7 +1,7 @@
     3.4  #include <stdio.h>
     3.5  #include "iso9660.h"
     3.6  
     3.7 -static unsigned version;
     3.8 +static unsigned setup_version;
     3.9  #define SETUPSECTORS	0x1F1
    3.10  #define ROFLAG		0x1F2
    3.11  #define SYSSIZE		0x1F4
    3.12 @@ -24,9 +24,9 @@
    3.13  
    3.14  #define PAGE_BITS	12
    3.15  #define PAGE_SIZE	4096
    3.16 -#define BUFFERSZ	PAGE_SIZE
    3.17 +#define BUFFERSZ	2048		// lower than mix setup
    3.18  static char buffer[BUFFERSZ];
    3.19 -static unsigned long initrd_addr, initrd_size;
    3.20 +static unsigned long initrd_addr = 0, initrd_size;
    3.21  
    3.22  static int may_exit_dos = 1;
    3.23  static void die(char *msg)
    3.24 @@ -45,12 +45,10 @@
    3.25  #endasm
    3.26  } 
    3.27  
    3.28 -static struct mem {
    3.29 +static struct {
    3.30  	unsigned long base;
    3.31  	int align;
    3.32 -} kernelmem = { 0x100000, 0 };
    3.33 -
    3.34 -#define initrdmem kernelmem
    3.35 +} mem = { 0x100000, 0 };
    3.36  
    3.37  static void movehi(void)
    3.38  {
    3.39 @@ -61,7 +59,7 @@
    3.40  zero1:
    3.41  		push	di
    3.42  		loop	zero1
    3.43 -		push	dword [_kernelmem]	// 1A p->base
    3.44 +		push	dword [_mem]	// 1A mem.base
    3.45  		push	#-1		// 18
    3.46  		push	di		// 16
    3.47  		xor	eax, eax
    3.48 @@ -90,7 +88,18 @@
    3.49  #endasm
    3.50  }
    3.51  
    3.52 -#undef ZIMAGE_SUPPORT	/* Does not work... */
    3.53 +#define ZIMAGE_SUPPORT
    3.54 +
    3.55 +#ifdef ZIMAGE_SUPPORT
    3.56 +static int zimage = 0;
    3.57 +static unsigned zimage_base;
    3.58 +static unsigned getss(void)
    3.59 +{
    3.60 +#asm
    3.61 +	mov	ax, ss
    3.62 +#endasm
    3.63 +}
    3.64 +#endif
    3.65  
    3.66  static int versiondos;
    3.67  static int dosversion(void)
    3.68 @@ -114,11 +123,11 @@
    3.69  #endasm
    3.70  }
    3.71  
    3.72 -static void load(struct mem *p, unsigned long size)
    3.73 +static void load(unsigned long size)
    3.74  {
    3.75  	if (vm86())
    3.76  		die("Need real mode");
    3.77 -	switch (p->align) {
    3.78 +	switch (mem.align) {
    3.79  	case 0:	// kernel
    3.80  		switch (dosversion()) {
    3.81  		case 3: case 4: case 6: case 7: break;
    3.82 @@ -126,29 +135,27 @@
    3.83  			printf("DOS %d not supported.\nTrying anyway...\n",
    3.84  				versiondos);
    3.85  		}
    3.86 -		p->align = PAGE_SIZE;
    3.87 +		mem.align = PAGE_SIZE;
    3.88  		break;
    3.89  	case PAGE_SIZE: // first initrd : keep 16M..48M for the kernel
    3.90 -		if (extendedramsizeinkb() > 0xF000U && p->base < 0x3000000)
    3.91 -			p->base = 0x3000000;
    3.92 -		initrd_addr = p->base;
    3.93 -		p->align = 4;
    3.94 +		if (extendedramsizeinkb() > 0xF000U && mem.base < 0x3000000)
    3.95 +			mem.base = 0x3000000;
    3.96 +		initrd_addr = mem.base;
    3.97 +		mem.align = 4;
    3.98  	}
    3.99  	while (size) {
   3.100  		int n, s = sizeof(buffer);
   3.101  		for (n = 0; n < s; n++) buffer[n] = 0;
   3.102  		if (s > size) s = size;
   3.103 -		n = isoread(buffer, s);
   3.104 +		if ((n = isoread(buffer, s)) < 0) break;
   3.105  		movehi();
   3.106 -		if (n != -1) {
   3.107 -			p->base += n;
   3.108 -			size -= n;
   3.109 -		}
   3.110 -		if (s != n) break;
   3.111 +		mem.base += n;
   3.112 +		size -= n;
   3.113 +		if (s != n) break;	// end of file
   3.114  	}
   3.115 -	initrd_size = p->base - initrd_addr;
   3.116 -	p->base += p->align - 1;
   3.117 -	p->base &= - p->align;
   3.118 +	initrd_size = mem.base - initrd_addr;
   3.119 +	mem.base += mem.align - 1;
   3.120 +	mem.base &= - mem.align;
   3.121  }
   3.122  
   3.123  static unsigned setupofs = 0;
   3.124 @@ -189,13 +196,13 @@
   3.125  			setup = (1 + buffer[SETUPSECTORS]) << 9;
   3.126  			if (setup == 512) setup = 5 << 9;
   3.127  			syssize = * (unsigned long  *) (buffer + SYSSIZE) << 4;
   3.128 -			version = * (unsigned short *) (buffer + VERSION);
   3.129 +			setup_version = * (unsigned short *) (buffer + VERSION);
   3.130  #define HDRS	0x53726448
   3.131  			if (* (unsigned long *) (buffer + HEADER) != HDRS)
   3.132 -				version = 0;
   3.133 -			if (version < 0x204)
   3.134 +				setup_version = 0;
   3.135 +			if (setup_version < 0x204)
   3.136  				syssize &= 0x000FFFFFUL;
   3.137 -			if (version) {
   3.138 +			if (setup_version) {
   3.139  #ifdef REALMODE_SWITCH
   3.140  				extern int far_realmode_switch();
   3.141  #asm
   3.142 @@ -213,7 +220,7 @@
   3.143  				* (unsigned short *) (buffer + RMSWSEG) = 
   3.144  					getcs();
   3.145  #endif
   3.146 -				kernelmem.base =
   3.147 +				mem.base =
   3.148  					* (unsigned long *) (buffer + SYSTEMCODE);
   3.149  				* (unsigned short *) (buffer + HEAPPTR) = 
   3.150  					0x9B00;
   3.151 @@ -221,34 +228,16 @@
   3.152  				* (unsigned short *) (buffer + LOADERTYPE) |= 
   3.153  					0x80FF;
   3.154  			}
   3.155 -			if (!version || !(buffer[LOADFLAGS] & 1)) {
   3.156 +			if (!setup_version || !(buffer[LOADFLAGS] & 1)) {
   3.157  #ifdef ZIMAGE_SUPPORT
   3.158 -#asm
   3.159 -		pusha
   3.160 -		mov	cx, #0x8000
   3.161 -		mov	es, cx
   3.162 -		xor	si, si
   3.163 -		xor	di, di
   3.164 -		rep
   3.165 -		  movsw			// move 64K data
   3.166 -		push	es
   3.167 -		pop	ds
   3.168 -		push	es
   3.169 -		pop	ss
   3.170 -		mov	ch, #0x70
   3.171 -		mov	es, cx
   3.172 -		mov	ch, #0x80
   3.173 -		rep
   3.174 -		 seg	cs
   3.175 -		  movsw			// move 64K code
   3.176 -		popa
   3.177 -		jmpi	relocated, #0x7000
   3.178 -relocated:
   3.179 -#endasm
   3.180 -				kernelmem.base = 0x10000;
   3.181 -				if (syssize > 0x60000)	/* 384K max */
   3.182 +				zimage = 1;
   3.183 +				zimage_base = getss() + 0x1000L;
   3.184 +				mem.base = zimage_base * 16L; 
   3.185 +				if (mem.base + syssize > SETUP_SEGMENT*16L - 32)
   3.186 +					die("Out of memory");
   3.187 +#else
   3.188 +				die("Not a bzImage format");
   3.189  #endif
   3.190 -				die("Not a bzImage format");
   3.191  			}
   3.192  		}
   3.193  		movesetup();
   3.194 @@ -281,16 +270,18 @@
   3.195  		loop	next
   3.196  		pop	ds
   3.197  		mov	.loadkernel.kernel_version[bp], edx
   3.198 +		push	ds
   3.199  noversion:
   3.200 +		pop	ds
   3.201  #endasm
   3.202 -	load(&kernelmem, syssize);
   3.203 +	load(syssize);
   3.204  	return kernel_version;
   3.205  }
   3.206  
   3.207  void loadinitrd(void)
   3.208  {
   3.209 -	if (version)
   3.210 -		load(&initrdmem, isofilesize);
   3.211 +	if (setup_version && zimage == 0)
   3.212 +		load(isofilesize);
   3.213  }
   3.214  
   3.215  void bootlinux(char *cmdline)
   3.216 @@ -298,6 +289,9 @@
   3.217  #asm
   3.218  	push	#SETUP_SEGMENT
   3.219  	pop	es
   3.220 +	push	es
   3.221 +	pop	ss
   3.222 +	mov	sp, #CMDLINE_OFFSET
   3.223  	mov	eax, _initrd_addr
   3.224  	or	eax, eax
   3.225  	jz	no_initrd
   3.226 @@ -308,7 +302,7 @@
   3.227  no_initrd:
   3.228  #endasm
   3.229  	if (cmdline) {
   3.230 -		if (version <= 0x201) {
   3.231 +		if (setup_version <= 0x201) {
   3.232  #asm
   3.233  		mov	di, #0x0020
   3.234  		mov	ax, #0xA33F
   3.235 @@ -334,12 +328,45 @@
   3.236  		jne	copy
   3.237  #endasm
   3.238  	}
   3.239 +#ifdef ZIMAGE_SUPPORT
   3.240 +	if (zimage) {
   3.241  #asm
   3.242 -	push	es
   3.243 +		mov	eax, _mem
   3.244 +		shr	eax, #4		// top
   3.245 +		mov	bx, _zimage_base
   3.246 +		mov	dx, #0x1000
   3.247 +		push	cs
   3.248 +		pop	ds
   3.249 +		mov	es, ax
   3.250 +		push	es
   3.251 +		mov	si, #sysmove
   3.252 +		xor	di, di
   3.253 +		push	di
   3.254 +		mov	cx, #endsysmove-sysmove
   3.255 +		rep
   3.256 +		  movsb
   3.257 +		retf
   3.258 +sysmove:
   3.259 +		mov	ds, bx
   3.260 +		mov	es, dx
   3.261 +		xor	di, di
   3.262 +		xor	si, si
   3.263 +		mov	cl, #8
   3.264 +		rep
   3.265 +		  movsw
   3.266 +		inc	bx
   3.267 +		inc	dx
   3.268 +		cmp	ax,bx
   3.269 +		jne	sysmove
   3.270 +#endasm
   3.271 +	}
   3.272 +#endif
   3.273 +#asm
   3.274 +	push	ss
   3.275  	pop	ds
   3.276  	push	ds
   3.277 -	pop	ss
   3.278 -	mov	sp, #CMDLINE_OFFSET
   3.279 +	pop	es
   3.280  	jmpi	0, #0x9020
   3.281 +endsysmove:
   3.282  #endasm
   3.283  }
     4.1 --- a/syslinux/stuff/iso2exe/init	Thu Mar 06 00:03:58 2014 +0100
     4.2 +++ b/syslinux/stuff/iso2exe/init	Thu Mar 06 19:57:41 2014 +0000
     4.3 @@ -348,6 +348,12 @@
     4.4  	[ -s /media/cdrom/$1 ] && echo -en "\"$2\"	\"$3\""
     4.5  }
     4.6  
     4.7 +cdexe()
     4.8 +{
     4.9 +	[ $(get 0 /media/cdrom/$1 2> /dev/null || echo 0) -ne 23117 ] &&
    4.10 +	echo -en "\"$2\"	\"$3\""
    4.11 +}
    4.12 +
    4.13  fddata()
    4.14  {
    4.15  	[ $(get 28 /mnt/$ISO 1 2> /dev/null || echo 0) -ne 0 ] &&
    4.16 @@ -537,11 +543,11 @@
    4.17  			"usbbootkey"	"USB boot key (read only)" \
    4.18  $(fddata		"fdbootstrap"	"Floppy bootstrap") \
    4.19  			"tazboot"	"Get tazboot.exe Linux loader" \
    4.20 -$(cdfile boot/memtest	"memtest"	"Get Memtest86") \
    4.21 +$(cdexe boot/memtest	"memtest"	"Get Memtest86") \
    4.22  $(cdfile boot/memtest	"fdmemtest"	"Create a Memtest86 boot floppy") \
    4.23 -$(cdfile Xboot/gpxe	"pxe"		"Get SliTaz Web boot utility") \
    4.24 +$(cdexe boot/gpxe	"pxe"		"Get SliTaz Web boot utility") \
    4.25  $(cdfile boot/gpxe	"fdpxe"		"Create a SliTaz Web boot floppy") \
    4.26 -$(cdfile boot/ipxe	"pxe"		"Get SliTaz Web boot utility") \
    4.27 +$(cdexe boot/ipxe	"pxe"		"Get SliTaz Web boot utility") \
    4.28  $(cdfile boot/ipxe	"fdpxe"		"Create a SliTaz Web boot floppy") \
    4.29  $(xfile reboot		"restart"	"Restart the computer") \
    4.30  $(xfile poweroff	"stop"		"Power off") \