wok-next rev 12273

syslinux: merge md5sum, ifmem, reboot & poweroff modules
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Apr 14 11:50:03 2012 +0200 (2012-04-14)
parents a7297503ad9b
children 5f2b786cc2b8
files syslinux/receipt syslinux/stuff/extra/ifmem.c syslinux/stuff/extra/md5sum.c
line diff
     1.1 --- a/syslinux/receipt	Fri Apr 13 02:16:05 2012 +0200
     1.2 +++ b/syslinux/receipt	Sat Apr 14 11:50:03 2012 +0200
     1.3 @@ -18,10 +18,9 @@
     1.4      cd $src
     1.5      cp $stuff/tools/isohybrid.sh .
     1.6      cp $stuff/tools/keytab-lilo.pl .
     1.7 -    cp $stuff/extra/ifmem.c com32/modules
     1.8      cp $stuff/extra/md5sum.c com32/modules
     1.9 -    grep -q ifmem.c32 com32/modules/Makefile ||
    1.10 -	sed -i 's/ifcpu64.c32/ifcpu64.c32 ifmem.c32 md5sum.c32/' com32/modules/Makefile
    1.11 +    grep -q md5sum.c32 com32/modules/Makefile ||
    1.12 +	sed -i 's/ifcpu64.c32/ifcpu64.c32 md5sum.c32/' com32/modules/Makefile
    1.13      make -C com32
    1.14      ./isohybrid.sh --build
    1.15      for i in /usr/share/kbd/keymaps/i386/*/*.map.gz; do
    1.16 @@ -37,11 +36,8 @@
    1.17  {
    1.18      mkdir -p $fs/boot/isolinux
    1.19      cp -a $src/core/isolinux.bin $fs/boot/isolinux
    1.20 -    cp -a $src/com32/modules/reboot.c32 $fs/boot/isolinux
    1.21 -    cp -a $src/com32/modules/ifmem.c32 $fs/boot/isolinux
    1.22      cp -a $src/com32/modules/md5sum.c32 $fs/boot/isolinux
    1.23      cp -a $src/com32/menu/vesamenu.c32 $fs/boot/isolinux
    1.24 -    cp -a $src/modules/poweroff.com $fs/boot/isolinux
    1.25      # $stuff/isolinux.msg is the old way the have a splash image.
    1.26      cp $stuff/*.cfg $stuff/*.txt $stuff/help.* $stuff/opts.* $fs/boot/isolinux
    1.27      while read cfg kbd loc ; do
    1.28 @@ -79,4 +75,7 @@
    1.29  post_install()
    1.30  {
    1.31      sed -i "s/XXXXXXXX/$(date +%Y%m%d)/" $1/boot/isolinux/isolinux.cfg
    1.32 +    for i in ifmem reboot poweroff; do
    1.33 +    	ln $fs/boot/isolinux/md5sum.c32 $fs/boot/isolinux/$i.c32
    1.34 +    done
    1.35  }
     2.1 --- a/syslinux/stuff/extra/ifmem.c	Fri Apr 13 02:16:05 2012 +0200
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,127 +0,0 @@
     2.4 -/* ----------------------------------------------------------------------- *
     2.5 - *
     2.6 - *   Copyright 2009 Pascal Bellard - All Rights Reserved
     2.7 - *
     2.8 - *   This program is free software; you can redistribute it and/or modify
     2.9 - *   it under the terms of the GNU General Public License as published by
    2.10 - *   the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
    2.11 - *   Boston MA 02110-1301, USA; either version 2 of the License, or
    2.12 - *   (at your option) any later version; incorporated herein by reference.
    2.13 - *
    2.14 - * ----------------------------------------------------------------------- */
    2.15 -
    2.16 -/*
    2.17 - * ifmem.c
    2.18 - *
    2.19 - * Run one command if the memory is large enought, and another if it isn't.
    2.20 - *
    2.21 - * Usage:
    2.22 - *
    2.23 - *    label boot_kernel
    2.24 - *        kernel ifmem.c
    2.25 - *        append size_in_KB boot_large [size_in_KB boot_medium] boot_small
    2.26 - *
    2.27 - *    label boot_large
    2.28 - *        kernel vmlinuz_large_memory
    2.29 - *        append ...
    2.30 - *
    2.31 - *    label boot_small
    2.32 - *        kernel vmlinuz_small_memory
    2.33 - *        append ...
    2.34 - */
    2.35 -
    2.36 -#include <inttypes.h>
    2.37 -#include <com32.h>
    2.38 -#include <console.h>
    2.39 -#include <stdio.h>
    2.40 -#include <string.h>
    2.41 -#include <alloca.h>
    2.42 -#include <stdlib.h>
    2.43 -#include <syslinux/boot.h>
    2.44 -
    2.45 -struct e820_data {
    2.46 -	uint64_t base;
    2.47 -	uint64_t len;
    2.48 -	uint32_t type;
    2.49 -	uint32_t extattr;
    2.50 -} __attribute__((packed));
    2.51 -
    2.52 -// Get memory size in Kb
    2.53 -static unsigned long memory_size(void)
    2.54 -{
    2.55 -	uint64_t bytes = 0;
    2.56 -	static com32sys_t ireg, oreg;
    2.57 -	static struct e820_data ed;
    2.58 -
    2.59 -	ireg.eax.w[0] = 0xe820;
    2.60 -	ireg.edx.l    = 0x534d4150;
    2.61 -	ireg.ecx.l    = sizeof(struct e820_data);
    2.62 -	ireg.edi.w[0] = OFFS(__com32.cs_bounce);
    2.63 -	ireg.es       = SEG(__com32.cs_bounce);
    2.64 -
    2.65 -	ed.extattr = 1;
    2.66 -
    2.67 -	do {
    2.68 -		memcpy(__com32.cs_bounce, &ed, sizeof ed);
    2.69 -
    2.70 -		__intcall(0x15, &ireg, &oreg);
    2.71 -		if (oreg.eflags.l & EFLAGS_CF ||
    2.72 -		    oreg.eax.l != 0x534d4150  ||
    2.73 -		    oreg.ecx.l < 20)
    2.74 -			break;
    2.75 -
    2.76 -		memcpy(&ed, __com32.cs_bounce, sizeof ed);
    2.77 -
    2.78 -		if (ed.type == 1)
    2.79 -			bytes += ed.len;
    2.80 -
    2.81 -		ireg.ebx.l = oreg.ebx.l;
    2.82 -	} while (ireg.ebx.l);
    2.83 -
    2.84 -	if (!bytes) {
    2.85 -		memset(&ireg, 0, sizeof ireg);
    2.86 -		ireg.eax.w[0] = 0x8800;
    2.87 -		__intcall(0x15, &ireg, &oreg);
    2.88 -		return ireg.eax.w[0];
    2.89 -	}
    2.90 -	return bytes >> 10;
    2.91 -}
    2.92 -
    2.93 -int main(int argc, char *argv[])
    2.94 -{
    2.95 -	int i;
    2.96 -	unsigned long ram_size;
    2.97 -
    2.98 -	openconsole(&dev_null_r, &dev_stdcon_w);
    2.99 -  
   2.100 -	if (argc < 4) {
   2.101 -		perror("\nUsage: ifmem.c32 size_KB boot_large_memory boot_small_memory\n");
   2.102 -		return 1;
   2.103 -	}
   2.104 -
   2.105 -	// find target according to ram size
   2.106 -	ram_size = memory_size();
   2.107 -	printf("Total memory found %luK.\n",ram_size);
   2.108 -	ram_size += (1 << 10); // add 1M to round boundaries...
   2.109 -  
   2.110 -	i = 1;
   2.111 -	do { 
   2.112 -		char *s = argv[i];
   2.113 -		char *p = s;
   2.114 -		unsigned long scale = 1;
   2.115 -
   2.116 -		while (*p >= '0' && *p <= '9') p++;
   2.117 -		switch (*p | 0x20) {
   2.118 -			case 'g': scale <<= 10;
   2.119 -			case 'm': scale <<= 10;
   2.120 -			default : *p = 0; break;
   2.121 -		}
   2.122 -		i++; // seek to label
   2.123 -		if (ram_size >= scale * strtoul(s, NULL, 0)) break;
   2.124 -		i++; // next size or default label
   2.125 -	} while (i + 1 < argc);
   2.126 -
   2.127 -	if (i != argc)  syslinux_run_command(argv[i]);
   2.128 -	else		syslinux_run_default();
   2.129 -	return -1;
   2.130 -}
     3.1 --- a/syslinux/stuff/extra/md5sum.c	Fri Apr 13 02:16:05 2012 +0200
     3.2 +++ b/syslinux/stuff/extra/md5sum.c	Sat Apr 14 11:50:03 2012 +0200
     3.3 @@ -299,14 +299,13 @@
     3.4  	return hash_value;
     3.5  }
     3.6  
     3.7 -int main(int argc, char **argv)
     3.8 +static int main_md5sum(int argc, char **argv)
     3.9  {
    3.10  	int files = 0, tested = 0, good = 0;
    3.11  	static char clear_eol[] = "                                ";
    3.12  
    3.13  	(void) argc;
    3.14  	/* -c implied */
    3.15 -	openconsole(&dev_rawcon_r, &dev_stdcon_w);
    3.16  
    3.17  	do {
    3.18  		FILE *fp;
    3.19 @@ -356,5 +355,209 @@
    3.20  	} while (*++argv);
    3.21  	printf("\r%d files OK, %d broken, %d not checked.%s\n",
    3.22  		good, tested - good, files - tested, clear_eol);
    3.23 +	return 0;
    3.24  }
    3.25  
    3.26 +/*
    3.27 + * ifmem.c
    3.28 + *
    3.29 + * Run one command if the memory is large enought, and another if it isn't.
    3.30 + *
    3.31 + * Usage:
    3.32 + *
    3.33 + *    label boot_kernel
    3.34 + *        kernel ifmem.c
    3.35 + *        append size_in_KB boot_large [size_in_KB boot_medium] boot_small
    3.36 + *
    3.37 + *    label boot_large
    3.38 + *        kernel vmlinuz_large_memory
    3.39 + *        append ...
    3.40 + *
    3.41 + *    label boot_small
    3.42 + *        kernel vmlinuz_small_memory
    3.43 + *        append ...
    3.44 + */
    3.45 +
    3.46 +#include <inttypes.h>
    3.47 +#include <alloca.h>
    3.48 +#include <syslinux/boot.h>
    3.49 +
    3.50 +struct e820_data {
    3.51 +	uint64_t base;
    3.52 +	uint64_t len;
    3.53 +	uint32_t type;
    3.54 +	uint32_t extattr;
    3.55 +} __attribute__((packed));
    3.56 +
    3.57 +// Get memory size in Kb
    3.58 +static unsigned long memory_size(void)
    3.59 +{
    3.60 +	uint64_t bytes = 0;
    3.61 +	static com32sys_t ireg, oreg;
    3.62 +	static struct e820_data ed;
    3.63 +
    3.64 +	ireg.eax.w[0] = 0xe820;
    3.65 +	ireg.edx.l    = 0x534d4150;
    3.66 +	ireg.ecx.l    = sizeof(struct e820_data);
    3.67 +	ireg.edi.w[0] = OFFS(__com32.cs_bounce);
    3.68 +	ireg.es       = SEG(__com32.cs_bounce);
    3.69 +
    3.70 +	ed.extattr = 1;
    3.71 +
    3.72 +	do {
    3.73 +		memcpy(__com32.cs_bounce, &ed, sizeof ed);
    3.74 +
    3.75 +		__intcall(0x15, &ireg, &oreg);
    3.76 +		if (oreg.eflags.l & EFLAGS_CF ||
    3.77 +		    oreg.eax.l != 0x534d4150  ||
    3.78 +		    oreg.ecx.l < 20)
    3.79 +			break;
    3.80 +
    3.81 +		memcpy(&ed, __com32.cs_bounce, sizeof ed);
    3.82 +
    3.83 +		if (ed.type == 1)
    3.84 +			bytes += ed.len;
    3.85 +
    3.86 +		ireg.ebx.l = oreg.ebx.l;
    3.87 +	} while (ireg.ebx.l);
    3.88 +
    3.89 +	if (!bytes) {
    3.90 +		memset(&ireg, 0, sizeof ireg);
    3.91 +		ireg.eax.w[0] = 0x8800;
    3.92 +		__intcall(0x15, &ireg, &oreg);
    3.93 +		return ireg.eax.w[0];
    3.94 +	}
    3.95 +	return bytes >> 10;
    3.96 +}
    3.97 +
    3.98 +static int main_ifmem(int argc, char *argv[])
    3.99 +{
   3.100 +	int i;
   3.101 +	unsigned long ram_size;
   3.102 +
   3.103 +	if (argc < 4) {
   3.104 +		perror("\nUsage: ifmem.c32 size_KB boot_large_memory boot_small_memory\n");
   3.105 +		return 1;
   3.106 +	}
   3.107 +
   3.108 +	// find target according to ram size
   3.109 +	ram_size = memory_size();
   3.110 +	printf("Total memory found %luK.\n",ram_size);
   3.111 +	ram_size += (1 << 10); // add 1M to round boundaries...
   3.112 +  
   3.113 +	i = 1;
   3.114 +	do { 
   3.115 +		char *s = argv[i];
   3.116 +		char *p = s;
   3.117 +		unsigned long scale = 1;
   3.118 +
   3.119 +		while (*p >= '0' && *p <= '9') p++;
   3.120 +		switch (*p | 0x20) {
   3.121 +			case 'g': scale <<= 10;
   3.122 +			case 'm': scale <<= 10;
   3.123 +			default : *p = 0; break;
   3.124 +		}
   3.125 +		i++; // seek to label
   3.126 +		if (ram_size >= scale * strtoul(s, NULL, 0)) break;
   3.127 +		i++; // next size or default label
   3.128 +	} while (i + 1 < argc);
   3.129 +
   3.130 +	if (i != argc)  syslinux_run_command(argv[i]);
   3.131 +	else		syslinux_run_default();
   3.132 +	return -1;
   3.133 +}
   3.134 +
   3.135 +#include <syslinux/reboot.h>
   3.136 +
   3.137 +static int main_reboot(int argc, char *argv[])
   3.138 +{
   3.139 +    int warm = 0;
   3.140 +    int i;
   3.141 +
   3.142 +    for (i = 1; i < argc; i++) {
   3.143 +	if (!strcmp(argv[i], "-w") || !strcmp(argv[i], "--warm"))
   3.144 +	    warm = 1;
   3.145 +    }
   3.146 +
   3.147 +    syslinux_reboot(warm);
   3.148 +}
   3.149 +
   3.150 +/* APM poweroff module.
   3.151 + * based on poweroff.asm,  Copyright 2009 Sebastian Herbszt
   3.152 + */
   3.153 +
   3.154 +static int main_poweroff(int argc, char *argv[])
   3.155 +{
   3.156 +	static com32sys_t ireg, oreg;
   3.157 +	static char notsupported[] ="APM 1.1+ not supported";
   3.158 +	unsigned i;
   3.159 +	static struct {
   3.160 +		unsigned short ax;
   3.161 +		unsigned short bx;
   3.162 +		unsigned short cx;
   3.163 +		char *msg;
   3.164 +	} inst[] = {
   3.165 +		{ 0x5300,	// APM Installation Check (00h)
   3.166 +		  0, 		// APM BIOS (0000h)
   3.167 +		  0, "APM not present" },
   3.168 +		{ 0x5301,	// APM Real Mode Interface Connect (01h)
   3.169 +		  0, 		// APM BIOS (0000h)
   3.170 +		  0, "APM RM interface connect failed" },
   3.171 +		{ 0x530E,	// APM Driver Version (0Eh)
   3.172 +		  0, 		// APM BIOS (0000h)
   3.173 +		  0x0101,	// APM Driver Version version 1.1
   3.174 +		  notsupported },
   3.175 +		{ 0x5307,	// Set Power State (07h)
   3.176 +		  1,		// All devices power managed by the APM
   3.177 +		  3,		// Power state off
   3.178 +		  "Power off failed" }
   3.179 +	};
   3.180 +
   3.181 +	(void) argc;
   3.182 +	(void) argv;
   3.183 +	for (i = 0; i < sizeof(inst)/sizeof(inst[0]); i++) {
   3.184 +		char *msg = inst[i].msg;
   3.185 +		
   3.186 +		ireg.eax.w[0] = inst[i].ax;
   3.187 +		ireg.ebx.w[0] = inst[i].bx;
   3.188 +		ireg.ecx.w[0] = inst[i].cx;
   3.189 +		__intcall(0x15, &ireg, &oreg);
   3.190 +		if ((oreg.eflags.l & EFLAGS_CF) == 0) {
   3.191 +			switch (inst[i].ax) {
   3.192 +			case 0x5300 :
   3.193 +				if (oreg.ebx.w[0] != 0x504D /* 'PM' */) break;
   3.194 +				msg = "Power management disabled";
   3.195 +				if (oreg.ecx.w[0] & 8) break; // bit 3 APM BIOS Power Management disabled
   3.196 +			case 0x530E :
   3.197 +				msg = notsupported;
   3.198 +				if (oreg.eax.w[0] < 0x101) break;
   3.199 +			default : continue;
   3.200 +			}
   3.201 +		}
   3.202 +		printf("%s.\n", msg);
   3.203 +		return 1;
   3.204 +	}
   3.205 +	return 0;
   3.206 +}
   3.207 +
   3.208 +int main(int argc, char *argv[])
   3.209 +{
   3.210 +	unsigned i;
   3.211 +	static struct {
   3.212 +		char *name;
   3.213 +		int (*main)(int argc, char *argv[]);
   3.214 +	} bin[] = {
   3.215 +		{ "md5sum",	main_md5sum },
   3.216 +		{ "ifmem",	main_ifmem  },
   3.217 +		{ "reboot",	main_reboot },
   3.218 +		{ "poweroff",	main_poweroff }
   3.219 +	};
   3.220 +
   3.221 +	openconsole(&dev_null_r, &dev_stdcon_w);
   3.222 +  
   3.223 +	if (strstr(argv[0], "c32box")) { argc--; argv++; }
   3.224 +	for (i = 0; i < sizeof(bin)/sizeof(bin[0]); i++)
   3.225 +		if (strstr(argv[0], bin[i].name))
   3.226 +			return bin[i].main(argc, argv);
   3.227 +	return 1;
   3.228 +}