wok-next rev 18674
syslinux/c32box.c32: load custom config
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat Dec 05 18:24:53 2015 +0100 (2015-12-05) |
parents | 86d61e110274 |
children | 1e69cfd7f652 |
files | syslinux/stuff/extra/md5sum.c |
line diff
1.1 --- a/syslinux/stuff/extra/md5sum.c Sat Dec 05 16:17:00 2015 +0200 1.2 +++ b/syslinux/stuff/extra/md5sum.c Sat Dec 05 18:24:53 2015 +0100 1.3 @@ -23,6 +23,8 @@ 1.4 #include <fcntl.h> 1.5 #include <console.h> 1.6 #include <com32.h> 1.7 +#include <syslinux/config.h> 1.8 +#include <syslinux/disk.h> 1.9 1.10 #define ALIGN1 1.11 1.12 @@ -716,6 +718,73 @@ 1.13 return 0; 1.14 } 1.15 1.16 +static int got_config; 1.17 +static char *custom_cmdline = ""; 1.18 +static int custom_initrdlen; 1.19 +static char *custom_initrdbase; 1.20 +static char *custom_buffer; 1.21 +static struct disk_info diskinfo; 1.22 + 1.23 +static int has_custom_config(void) 1.24 +{ 1.25 + const union syslinux_derivative_info *sdi; 1.26 + 1.27 + if (got_config) 1.28 + goto done; 1.29 + sdi = syslinux_derivative_info(); 1.30 + if (sdi->c.filesystem != SYSLINUX_FS_ISOLINUX) 1.31 + goto fail; 1.32 + disk_get_params(sdi->iso.drive_number, &diskinfo); 1.33 + custom_buffer = disk_read_sectors(&diskinfo, 32768 / diskinfo.bps, 1); 1.34 + got_config = (16 + *(unsigned long *) (custom_buffer + 80)) 1.35 + * 2048 / diskinfo.bps; 1.36 + free(custom_buffer); 1.37 + custom_buffer = disk_read_sectors(&diskinfo, got_config, 1); 1.38 + if (!memcmp(custom_buffer,"#!boot ",7)) { 1.39 + char *p = custom_buffer+7+32+1; 1.40 + 1.41 + if (!memcmp(p,"append=",7)) { 1.42 + custom_cmdline = p + 7; 1.43 + p = strchr(p,'\n'); 1.44 + *p++ = 0; 1.45 + } 1.46 + if (!memcmp(p,"initrd:",7)) { 1.47 + custom_initrdlen = strtoul(p + 7, &custom_initrdbase, 10); 1.48 + custom_initrdbase++; 1.49 + } 1.50 + return 1; 1.51 + } 1.52 +fail: 1.53 + got_config = -1; 1.54 +done: 1.55 + return got_config > 0; 1.56 +} 1.57 + 1.58 +static int loadcustominitrd(void **data) 1.59 +{ 1.60 + int n, len; 1.61 + char *p; 1.62 + 1.63 + p = *data = malloc(custom_initrdlen); 1.64 + if (!p) return 0; 1.65 + len = custom_initrdlen; 1.66 + while (1) { 1.67 + n = 2048 + custom_buffer - custom_initrdbase; 1.68 + if (n > len) 1.69 + n = len; 1.70 + memcpy(p, custom_initrdbase, n); 1.71 + p += n; 1.72 + len -= n; 1.73 + if (len == 0) 1.74 + break; 1.75 + free(custom_buffer); 1.76 + got_config += diskinfo.bps; 1.77 + custom_initrdbase = custom_buffer = 1.78 + disk_read_sectors(&diskinfo, got_config, 2048 / diskinfo.bps); 1.79 + } 1.80 + return 1; 1.81 +} 1.82 + 1.83 /* Stitch together the command line from a set of argv's */ 1.84 static char *make_cmdline(char **argv) 1.85 { 1.86 @@ -731,6 +800,8 @@ 1.87 for (i = 0; i < 255; i++) 1.88 if (syslinux_getadv(i, &size)) 1.89 bytes += ++size; 1.90 + if (has_custom_config()) 1.91 + bytes += strlen(custom_cmdline) + 1; 1.92 1.93 p = cmdline = malloc(bytes); 1.94 if (!cmdline) 1.95 @@ -754,6 +825,11 @@ 1.96 if (p > cmdline) 1.97 p--; /* Remove the last space */ 1.98 *p = '\0'; 1.99 + 1.100 + if (has_custom_config()) { 1.101 + *p++ = ' '; 1.102 + strcat(p, custom_cmdline); 1.103 + } 1.104 1.105 return cmdline; 1.106 } 1.107 @@ -816,7 +892,7 @@ 1.108 return found; 1.109 } 1.110 1.111 -static char *bestextfilename(char *filename) 1.112 +static const char *bestextfilename(char *filename) 1.113 { 1.114 char *found; 1.115 1.116 @@ -964,6 +1040,15 @@ 1.117 } 1.118 } 1.119 1.120 + if (has_custom_config() && custom_initrdlen) { 1.121 + void *data; 1.122 + 1.123 + if (!opt_quiet) 1.124 + printf("Loading custom initrd... "); 1.125 + if (loadcustominitrd(&data)) 1.126 + initramfs_add_data(initramfs, data, custom_initrdlen, custom_initrdlen, 4); 1.127 + } 1.128 + 1.129 /* Handle dtb and eventually other setup data */ 1.130 setup_data = setup_data_init(); 1.131 if (!setup_data)