wok-6.x diff syslinux/stuff/extra/md5sum.c @ rev 12287
syslinux: merge md5sum, kbdmap and linux. kbdmap will append the kernel cmdline
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sun Apr 15 17:51:38 2012 +0200 (2012-04-15) |
parents | af17de69f535 |
children | 04df72fcbe66 |
line diff
1.1 --- a/syslinux/stuff/extra/md5sum.c Sat Apr 14 11:50:03 2012 +0200 1.2 +++ b/syslinux/stuff/extra/md5sum.c Sun Apr 15 17:51:38 2012 +0200 1.3 @@ -306,7 +306,7 @@ 1.4 1.5 (void) argc; 1.6 /* -c implied */ 1.7 - 1.8 + argv++; 1.9 do { 1.10 FILE *fp; 1.11 char eol, *line, buffer[256]; 1.12 @@ -355,6 +355,7 @@ 1.13 } while (*++argv); 1.14 printf("\r%d files OK, %d broken, %d not checked.%s\n", 1.15 good, tested - good, files - tested, clear_eol); 1.16 + sleep(5); 1.17 return 0; 1.18 } 1.19 1.20 @@ -540,6 +541,304 @@ 1.21 return 0; 1.22 } 1.23 1.24 +/* 1.25 + * Copyright 2009 Intel Corporation; author: H. Peter Anvin 1.26 + */ 1.27 + 1.28 +#include <syslinux/keyboard.h> 1.29 +#include <syslinux/loadfile.h> 1.30 +#include <syslinux/adv.h> 1.31 + 1.32 +static int main_kbdmap(int argc, char *argv[]) 1.33 +{ 1.34 + const struct syslinux_keyboard_map *const kmap = syslinux_keyboard_map(); 1.35 + size_t map_size, size, i; 1.36 + char *kbdmap, *msg; 1.37 + 1.38 + msg = "Usage: kbdmap archive.cpio mapfile [cmdline].."; 1.39 + if (argc < 3) 1.40 + goto kbdmap_error; 1.41 + 1.42 + msg = "Load error"; 1.43 + if (kmap->version != 1 || 1.44 + loadfile(argv[1], (void **) &kbdmap, &map_size) || 1.45 + strncmp(kbdmap, "07070", 5)) 1.46 + goto kbdmap_error; 1.47 + 1.48 + // search for mapfile in cpio archive 1.49 + for (i = 0; i < map_size;) { 1.50 + int len, j; 1.51 + char *name; 1.52 + 1.53 + for (j = size = 0; j < 8; j++) { 1.54 + char c = kbdmap[54 + i + j] - '0'; 1.55 + if (c > 9) c += '0' + 10 - 'A'; 1.56 + size <<= 4; 1.57 + size += c; 1.58 + } 1.59 + i += 110; 1.60 + name = kbdmap + i; 1.61 + len = 1 + strlen(name); 1.62 + i += len; 1.63 + i += ((-i)&3); 1.64 + if (!strcmp(name, argv[2])) { 1.65 + kbdmap += i; 1.66 + break; 1.67 + } 1.68 + i += size + ((-size)&3); 1.69 + } 1.70 + 1.71 + msg = "Filename error"; 1.72 + if (i >= map_size) 1.73 + goto kbdmap_error; 1.74 + 1.75 + msg = "Format error"; 1.76 + if (size != kmap->length) 1.77 + goto kbdmap_error; 1.78 + 1.79 + memcpy(kmap->map, kbdmap, size); 1.80 + 1.81 + // Save extra cmdline arguments 1.82 + for (i = 3; i < (size_t) argc; i++) { 1.83 + syslinux_setadv(i - 2, strlen(argv[i]), argv[i]); 1.84 + } 1.85 + 1.86 + return 0; 1.87 + 1.88 +kbdmap_error: 1.89 + printf("%s.\n",msg); 1.90 + return 1; 1.91 +} 1.92 + 1.93 +/* ----------------------------------------------------------------------- * 1.94 + * 1.95 + * Copyright 2007-2008 H. Peter Anvin - All Rights Reserved 1.96 + * Copyright 2009 Intel Corporation; author: H. Peter Anvin 1.97 + * 1.98 + * Permission is hereby granted, free of charge, to any person 1.99 + * obtaining a copy of this software and associated documentation 1.100 + * files (the "Software"), to deal in the Software without 1.101 + * restriction, including without limitation the rights to use, 1.102 + * copy, modify, merge, publish, distribute, sublicense, and/or 1.103 + * sell copies of the Software, and to permit persons to whom 1.104 + * the Software is furnished to do so, subject to the following 1.105 + * conditions: 1.106 + * 1.107 + * The above copyright notice and this permission notice shall 1.108 + * be included in all copies or substantial portions of the Software. 1.109 + * 1.110 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 1.111 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 1.112 + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 1.113 + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 1.114 + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 1.115 + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 1.116 + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 1.117 + * OTHER DEALINGS IN THE SOFTWARE. 1.118 + * 1.119 + * ----------------------------------------------------------------------- */ 1.120 + 1.121 +/* 1.122 + * linux.c 1.123 + * 1.124 + * Sample module to load Linux kernels. This module can also create 1.125 + * a file out of the DHCP return data if running under PXELINUX. 1.126 + * 1.127 + * If -dhcpinfo is specified, the DHCP info is written into the file 1.128 + * /dhcpinfo.dat in the initramfs. 1.129 + * 1.130 + * Usage: linux.c32 [-dhcpinfo] kernel arguments... 1.131 + */ 1.132 + 1.133 +#include <stdbool.h> 1.134 +#include <stdlib.h> 1.135 +#include <stdio.h> 1.136 +#include <string.h> 1.137 +#include <console.h> 1.138 +#include <syslinux/loadfile.h> 1.139 +#include <syslinux/linux.h> 1.140 +#include <syslinux/pxe.h> 1.141 + 1.142 +const char *progname = "linux.c32"; 1.143 + 1.144 +/* Find the last instance of a particular command line argument 1.145 + (which should include the final =; do not use for boolean arguments) */ 1.146 +static char *find_argument(char **argv, const char *argument) 1.147 +{ 1.148 + int la = strlen(argument); 1.149 + char **arg; 1.150 + char *ptr = NULL; 1.151 + 1.152 + for (arg = argv; *arg; arg++) { 1.153 + if (!memcmp(*arg, argument, la)) 1.154 + ptr = *arg + la; 1.155 + } 1.156 + 1.157 + return ptr; 1.158 +} 1.159 + 1.160 +/* Search for a boolean argument; return its position, or 0 if not present */ 1.161 +static int find_boolean(char **argv, const char *argument) 1.162 +{ 1.163 + char **arg; 1.164 + 1.165 + for (arg = argv; *arg; arg++) { 1.166 + if (!strcmp(*arg, argument)) 1.167 + return (arg - argv) + 1; 1.168 + } 1.169 + 1.170 + return 0; 1.171 +} 1.172 + 1.173 +/* Stitch together the command line from a set of argv's */ 1.174 +static char *make_cmdline(char **argv) 1.175 +{ 1.176 + char **arg; 1.177 + size_t bytes, size; 1.178 + char *cmdline, *p; 1.179 + int i; 1.180 + 1.181 + bytes = 1; /* Just in case we have a zero-entry cmdline */ 1.182 + for (arg = argv; *arg; arg++) { 1.183 + bytes += strlen(*arg) + 1; 1.184 + } 1.185 + for (i = 0; i < 255; i++) 1.186 + if (syslinux_getadv(i, &size)) 1.187 + bytes += ++size; 1.188 + 1.189 + p = cmdline = malloc(bytes); 1.190 + if (!cmdline) 1.191 + return NULL; 1.192 + 1.193 + for (arg = argv; *arg; arg++) { 1.194 + int len = strlen(*arg); 1.195 + memcpy(p, *arg, len); 1.196 + p[len] = ' '; 1.197 + p += len + 1; 1.198 + } 1.199 + 1.200 + for (i = 0; i < 255; i++) { 1.201 + const void *q = syslinux_getadv(i, &size); 1.202 + if (q == NULL) continue; 1.203 + memcpy(p, q, size); 1.204 + p[size] = ' '; 1.205 + p += size + 1; 1.206 + } 1.207 + 1.208 + if (p > cmdline) 1.209 + p--; /* Remove the last space */ 1.210 + *p = '\0'; 1.211 + 1.212 + return cmdline; 1.213 +} 1.214 + 1.215 +static int main_linux(int argc, char *argv[]) 1.216 +{ 1.217 + const char *kernel_name; 1.218 + struct initramfs *initramfs; 1.219 + char *cmdline; 1.220 + char *boot_image; 1.221 + void *kernel_data; 1.222 + size_t kernel_len; 1.223 + bool opt_dhcpinfo = false; 1.224 + bool opt_quiet = false; 1.225 + void *dhcpdata; 1.226 + size_t dhcplen; 1.227 + char **argp, *arg, *p; 1.228 + 1.229 + openconsole(&dev_null_r, &dev_stdcon_w); 1.230 + 1.231 + (void)argc; 1.232 + argp = argv + 1; 1.233 + 1.234 + while ((arg = *argp) && arg[0] == '-') { 1.235 + if (!strcmp("-dhcpinfo", arg)) { 1.236 + opt_dhcpinfo = true; 1.237 + } else { 1.238 + fprintf(stderr, "%s: unknown option: %s\n", progname, arg); 1.239 + return 1; 1.240 + } 1.241 + argp++; 1.242 + } 1.243 + 1.244 + if (!arg) { 1.245 + fprintf(stderr, "%s: missing kernel name\n", progname); 1.246 + return 1; 1.247 + } 1.248 + 1.249 + kernel_name = arg; 1.250 + 1.251 + boot_image = malloc(strlen(kernel_name) + 12); 1.252 + if (!boot_image) 1.253 + goto bail; 1.254 + strcpy(boot_image, "BOOT_IMAGE="); 1.255 + strcpy(boot_image + 11, kernel_name); 1.256 + /* argp now points to the kernel name, and the command line follows. 1.257 + Overwrite the kernel name with the BOOT_IMAGE= argument, and thus 1.258 + we have the final argument. */ 1.259 + *argp = boot_image; 1.260 + 1.261 + if (find_boolean(argp, "quiet")) 1.262 + opt_quiet = true; 1.263 + 1.264 + if (!opt_quiet) 1.265 + printf("Loading %s... ", kernel_name); 1.266 + if (loadfile(kernel_name, &kernel_data, &kernel_len)) { 1.267 + if (opt_quiet) 1.268 + printf("Loading %s ", kernel_name); 1.269 + printf("failed!\n"); 1.270 + goto bail; 1.271 + } 1.272 + if (!opt_quiet) 1.273 + printf("ok\n"); 1.274 + 1.275 + cmdline = make_cmdline(argp); 1.276 + if (!cmdline) 1.277 + goto bail; 1.278 + 1.279 + /* Initialize the initramfs chain */ 1.280 + initramfs = initramfs_init(); 1.281 + if (!initramfs) 1.282 + goto bail; 1.283 + 1.284 + if ((arg = find_argument(argp, "initrd="))) { 1.285 + do { 1.286 + p = strchr(arg, ','); 1.287 + if (p) 1.288 + *p = '\0'; 1.289 + 1.290 + if (!opt_quiet) 1.291 + printf("Loading %s... ", arg); 1.292 + if (initramfs_load_archive(initramfs, arg)) { 1.293 + if (opt_quiet) 1.294 + printf("Loading %s ", kernel_name); 1.295 + printf("failed!\n"); 1.296 + goto bail; 1.297 + } 1.298 + if (!opt_quiet) 1.299 + printf("ok\n"); 1.300 + 1.301 + if (p) 1.302 + *p++ = ','; 1.303 + } while ((arg = p)); 1.304 + } 1.305 + 1.306 + /* Append the DHCP info */ 1.307 + if (opt_dhcpinfo && 1.308 + !pxe_get_cached_info(PXENV_PACKET_TYPE_DHCP_ACK, &dhcpdata, &dhcplen)) { 1.309 + if (initramfs_add_file(initramfs, dhcpdata, dhcplen, dhcplen, 1.310 + "/dhcpinfo.dat", 0, 0755)) 1.311 + goto bail; 1.312 + } 1.313 + 1.314 + /* This should not return... */ 1.315 + syslinux_boot_linux(kernel_data, kernel_len, initramfs, cmdline); 1.316 + 1.317 +bail: 1.318 + fprintf(stderr, "Kernel load failure (insufficient memory?)\n"); 1.319 + return 1; 1.320 +} 1.321 + 1.322 int main(int argc, char *argv[]) 1.323 { 1.324 unsigned i; 1.325 @@ -550,7 +849,9 @@ 1.326 { "md5sum", main_md5sum }, 1.327 { "ifmem", main_ifmem }, 1.328 { "reboot", main_reboot }, 1.329 - { "poweroff", main_poweroff } 1.330 + { "poweroff", main_poweroff }, 1.331 + { "kbdmap", main_kbdmap }, 1.332 + { "linux", main_linux } 1.333 }; 1.334 1.335 openconsole(&dev_null_r, &dev_stdcon_w); 1.336 @@ -559,5 +860,8 @@ 1.337 for (i = 0; i < sizeof(bin)/sizeof(bin[0]); i++) 1.338 if (strstr(argv[0], bin[i].name)) 1.339 return bin[i].main(argc, argv); 1.340 + printf("No %s in c32box modules\n", argv[0]); 1.341 + for (i = 0; i < sizeof(bin)/sizeof(bin[0]); i++) 1.342 + printf(" %s \n",bin[i].name); 1.343 return 1; 1.344 }