# HG changeset patch # User Pascal Bellard # Date 1449336293 -3600 # Node ID cc264cb074e22054c0f60fdeec16284fd7f4ed38 # Parent 86d61e11027469706e2682b4ec00a6488a8da25f syslinux/c32box.c32: load custom config diff -r 86d61e110274 -r cc264cb074e2 syslinux/stuff/extra/md5sum.c --- a/syslinux/stuff/extra/md5sum.c Sat Dec 05 16:17:00 2015 +0200 +++ b/syslinux/stuff/extra/md5sum.c Sat Dec 05 18:24:53 2015 +0100 @@ -23,6 +23,8 @@ #include #include #include +#include +#include #define ALIGN1 @@ -716,6 +718,73 @@ return 0; } +static int got_config; +static char *custom_cmdline = ""; +static int custom_initrdlen; +static char *custom_initrdbase; +static char *custom_buffer; +static struct disk_info diskinfo; + +static int has_custom_config(void) +{ + const union syslinux_derivative_info *sdi; + + if (got_config) + goto done; + sdi = syslinux_derivative_info(); + if (sdi->c.filesystem != SYSLINUX_FS_ISOLINUX) + goto fail; + disk_get_params(sdi->iso.drive_number, &diskinfo); + custom_buffer = disk_read_sectors(&diskinfo, 32768 / diskinfo.bps, 1); + got_config = (16 + *(unsigned long *) (custom_buffer + 80)) + * 2048 / diskinfo.bps; + free(custom_buffer); + custom_buffer = disk_read_sectors(&diskinfo, got_config, 1); + if (!memcmp(custom_buffer,"#!boot ",7)) { + char *p = custom_buffer+7+32+1; + + if (!memcmp(p,"append=",7)) { + custom_cmdline = p + 7; + p = strchr(p,'\n'); + *p++ = 0; + } + if (!memcmp(p,"initrd:",7)) { + custom_initrdlen = strtoul(p + 7, &custom_initrdbase, 10); + custom_initrdbase++; + } + return 1; + } +fail: + got_config = -1; +done: + return got_config > 0; +} + +static int loadcustominitrd(void **data) +{ + int n, len; + char *p; + + p = *data = malloc(custom_initrdlen); + if (!p) return 0; + len = custom_initrdlen; + while (1) { + n = 2048 + custom_buffer - custom_initrdbase; + if (n > len) + n = len; + memcpy(p, custom_initrdbase, n); + p += n; + len -= n; + if (len == 0) + break; + free(custom_buffer); + got_config += diskinfo.bps; + custom_initrdbase = custom_buffer = + disk_read_sectors(&diskinfo, got_config, 2048 / diskinfo.bps); + } + return 1; +} + /* Stitch together the command line from a set of argv's */ static char *make_cmdline(char **argv) { @@ -731,6 +800,8 @@ for (i = 0; i < 255; i++) if (syslinux_getadv(i, &size)) bytes += ++size; + if (has_custom_config()) + bytes += strlen(custom_cmdline) + 1; p = cmdline = malloc(bytes); if (!cmdline) @@ -754,6 +825,11 @@ if (p > cmdline) p--; /* Remove the last space */ *p = '\0'; + + if (has_custom_config()) { + *p++ = ' '; + strcat(p, custom_cmdline); + } return cmdline; } @@ -816,7 +892,7 @@ return found; } -static char *bestextfilename(char *filename) +static const char *bestextfilename(char *filename) { char *found; @@ -964,6 +1040,15 @@ } } + if (has_custom_config() && custom_initrdlen) { + void *data; + + if (!opt_quiet) + printf("Loading custom initrd... "); + if (loadcustominitrd(&data)) + initramfs_add_data(initramfs, data, custom_initrdlen, custom_initrdlen, 4); + } + /* Handle dtb and eventually other setup data */ setup_data = setup_data_init(); if (!setup_data)