wok rev 13551

syslinux: update c32box/linux
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Nov 02 10:44:52 2012 +0100 (2012-11-02)
parents 58a7a832888e
children 87f71f65d8e8
files syslinux/stuff/extra/md5sum.c
line diff
     1.1 --- a/syslinux/stuff/extra/md5sum.c	Fri Nov 02 09:16:58 2012 +0200
     1.2 +++ b/syslinux/stuff/extra/md5sum.c	Fri Nov 02 10:44:52 2012 +0100
     1.3 @@ -306,6 +306,7 @@
     1.4  		printf("%s ",argv[i]);
     1.5  	}
     1.6  	sleep(5);
     1.7 +	return 0;
     1.8  }
     1.9  
    1.10  static int main_md5sum(int argc, char **argv)
    1.11 @@ -583,7 +584,7 @@
    1.12      setlinuxarg(1, argc - 3, argv + 3);
    1.13  
    1.14      msg="Append to kernel parameters: ";
    1.15 -    for (i = 3; i < argc; i++, msg = " ")
    1.16 +    for (i = 3; i < (size_t) argc; i++, msg = " ")
    1.17  	printf("%s%s",msg,argv[i]);
    1.18      printf("\nNow select 'Start SliTaz' in top menu.");
    1.19      printf("\n\n                            Hit RETURN to continue.\n");
    1.20 @@ -637,7 +638,7 @@
    1.21  /* ----------------------------------------------------------------------- *
    1.22   *
    1.23   *   Copyright 2007-2008 H. Peter Anvin - All Rights Reserved
    1.24 - *   Copyright 2009 Intel Corporation; author: H. Peter Anvin
    1.25 + *   Copyright 2009-2012 Intel Corporation; author: H. Peter Anvin
    1.26   *
    1.27   *   Permission is hereby granted, free of charge, to any person
    1.28   *   obtaining a copy of this software and associated documentation
    1.29 @@ -674,6 +675,7 @@
    1.30   * Usage: linux.c32 [-dhcpinfo] kernel arguments...
    1.31   */
    1.32  
    1.33 +#include <errno.h>
    1.34  #include <stdbool.h>
    1.35  #include <stdlib.h>
    1.36  #include <stdio.h>
    1.37 @@ -718,18 +720,14 @@
    1.38  static char *make_cmdline(char **argv)
    1.39  {
    1.40      char **arg;
    1.41 -    size_t bytes, size;
    1.42 +    size_t bytes;
    1.43      char *cmdline, *p;
    1.44 -    int i;
    1.45  
    1.46      bytes = 1;			/* Just in case we have a zero-entry cmdline */
    1.47      for (arg = argv; *arg; arg++) {
    1.48  	bytes += strlen(*arg) + 1;
    1.49      }
    1.50 -    for (i = 0; i < 255; i++)
    1.51 -    	if (syslinux_getadv(i, &size))
    1.52 -    		bytes += ++size;
    1.53 -  
    1.54 +
    1.55      p = cmdline = malloc(bytes);
    1.56      if (!cmdline)
    1.57  	return NULL;
    1.58 @@ -741,14 +739,6 @@
    1.59  	p += len + 1;
    1.60      }
    1.61  
    1.62 -    for (i = 0; i < 255; i++) {
    1.63 -    	const void *q = syslinux_getadv(i, &size);
    1.64 -    	if (q == NULL) continue;
    1.65 -    	memcpy(p, q, size);
    1.66 -	p[size] = ' ';
    1.67 -	p += size + 1;
    1.68 -    }
    1.69 -
    1.70      if (p > cmdline)
    1.71  	p--;			/* Remove the last space */
    1.72      *p = '\0';
    1.73 @@ -756,10 +746,31 @@
    1.74      return cmdline;
    1.75  }
    1.76  
    1.77 +static int setup_data_file(struct setup_data *setup_data,
    1.78 +			   uint32_t type, const char *filename,
    1.79 +			   bool opt_quiet)
    1.80 +{
    1.81 +    if (!opt_quiet)
    1.82 +	printf("Loading %s... ", filename);
    1.83 +
    1.84 +    if (setup_data_load(setup_data, type, filename)) {
    1.85 +	if (opt_quiet)
    1.86 +	    printf("Loading %s ", filename);
    1.87 +	printf("failed\n");
    1.88 +	return -1;
    1.89 +    }
    1.90 +	    
    1.91 +    if (!opt_quiet)
    1.92 +	printf("ok\n");
    1.93 +    
    1.94 +    return 0;
    1.95 +}
    1.96 +
    1.97  static int main_linux(int argc, char *argv[])
    1.98  {
    1.99      const char *kernel_name;
   1.100      struct initramfs *initramfs;
   1.101 +    struct setup_data *setup_data;
   1.102      char *cmdline;
   1.103      char *boot_image;
   1.104      void *kernel_data;
   1.105 @@ -768,7 +779,9 @@
   1.106      bool opt_quiet = false;
   1.107      void *dhcpdata;
   1.108      size_t dhcplen;
   1.109 -    char **argp, *arg, *p;
   1.110 +    char **argp, **argl, *arg, *p;
   1.111 +
   1.112 +    openconsole(&dev_null_r, &dev_stdcon_w);
   1.113  
   1.114      (void)argc;
   1.115      argp = argv + 1;
   1.116 @@ -790,9 +803,12 @@
   1.117  
   1.118      kernel_name = arg;
   1.119  
   1.120 +    errno = 0;
   1.121      boot_image = malloc(strlen(kernel_name) + 12);
   1.122 -    if (!boot_image)
   1.123 +    if (!boot_image) {
   1.124 +	fprintf(stderr, "Error allocating BOOT_IMAGE string: ");
   1.125  	goto bail;
   1.126 +    }
   1.127      strcpy(boot_image, "BOOT_IMAGE=");
   1.128      strcpy(boot_image + 11, kernel_name);
   1.129      /* argp now points to the kernel name, and the command line follows.
   1.130 @@ -805,23 +821,30 @@
   1.131  
   1.132      if (!opt_quiet)
   1.133  	printf("Loading %s... ", kernel_name);
   1.134 +    errno = 0;
   1.135      if (loadfile(kernel_name, &kernel_data, &kernel_len)) {
   1.136  	if (opt_quiet)
   1.137  	    printf("Loading %s ", kernel_name);
   1.138 -	printf("failed!\n");
   1.139 +	printf("failed: ");
   1.140  	goto bail;
   1.141      }
   1.142      if (!opt_quiet)
   1.143  	printf("ok\n");
   1.144  
   1.145 +    errno = 0;
   1.146      cmdline = make_cmdline(argp);
   1.147 -    if (!cmdline)
   1.148 +    if (!cmdline) {
   1.149 +	fprintf(stderr, "make_cmdline() failed: ");
   1.150  	goto bail;
   1.151 +    }
   1.152  
   1.153      /* Initialize the initramfs chain */
   1.154 +    errno = 0;
   1.155      initramfs = initramfs_init();
   1.156 -    if (!initramfs)
   1.157 +    if (!initramfs) {
   1.158 +	fprintf(stderr, "initramfs_init() failed: ");
   1.159  	goto bail;
   1.160 +    }
   1.161  
   1.162      if ((arg = find_argument(argp, "initrd="))) {
   1.163  	do {
   1.164 @@ -831,10 +854,11 @@
   1.165  
   1.166  	    if (!opt_quiet)
   1.167  		printf("Loading %s... ", arg);
   1.168 +	    errno = 0;
   1.169  	    if (initramfs_load_archive(initramfs, arg)) {
   1.170  		if (opt_quiet)
   1.171  		    printf("Loading %s ", kernel_name);
   1.172 -		printf("failed!\n");
   1.173 +		printf("failed: ");
   1.174  		goto bail;
   1.175  	    }
   1.176  	    if (!opt_quiet)
   1.177 @@ -848,16 +872,58 @@
   1.178      /* Append the DHCP info */
   1.179      if (opt_dhcpinfo &&
   1.180  	!pxe_get_cached_info(PXENV_PACKET_TYPE_DHCP_ACK, &dhcpdata, &dhcplen)) {
   1.181 +	errno = 0;
   1.182  	if (initramfs_add_file(initramfs, dhcpdata, dhcplen, dhcplen,
   1.183 -			       "/dhcpinfo.dat", 0, 0755))
   1.184 +			       "/dhcpinfo.dat", 0, 0755)) {
   1.185 +	    fprintf(stderr, "Unable to add DHCP info: ");
   1.186  	    goto bail;
   1.187 +	}
   1.188 +    }
   1.189 +
   1.190 +    /* Handle dtb and eventually other setup data */
   1.191 +    setup_data = setup_data_init();
   1.192 +    if (!setup_data)
   1.193 +	goto bail;
   1.194 +
   1.195 +    for (argl = argv; (arg = *argl); argl++) {
   1.196 +	if (!memcmp(arg, "dtb=", 4)) {
   1.197 +	    if (setup_data_file(setup_data, SETUP_DTB, arg+4, opt_quiet))
   1.198 +		goto bail;
   1.199 +	} else if (!memcmp(arg, "blob.", 5)) {
   1.200 +	    uint32_t type;
   1.201 +	    char *ep;
   1.202 +
   1.203 +	    type = strtoul(arg + 5, &ep, 10);
   1.204 +	    if (ep[0] != '=' || !ep[1])
   1.205 +		continue;
   1.206 +
   1.207 +	    if (!type)
   1.208 +		continue;
   1.209 +
   1.210 +	    if (setup_data_file(setup_data, type, ep+1, opt_quiet))
   1.211 +		goto bail;
   1.212 +	}
   1.213      }
   1.214  
   1.215      /* This should not return... */
   1.216 -    syslinux_boot_linux(kernel_data, kernel_len, initramfs, cmdline);
   1.217 +    errno = 0;
   1.218 +    syslinux_boot_linux(kernel_data, kernel_len, initramfs,
   1.219 +			setup_data, cmdline);
   1.220 +    fprintf(stderr, "syslinux_boot_linux() failed: ");
   1.221  
   1.222  bail:
   1.223 -    fprintf(stderr, "Kernel load failure (insufficient memory?)\n");
   1.224 +    switch(errno) {
   1.225 +    case ENOENT:
   1.226 +	fprintf(stderr, "File not found\n");
   1.227 +	break;
   1.228 +    case ENOMEM:
   1.229 +	fprintf(stderr, "Out of memory\n");
   1.230 +	break;
   1.231 +    default:
   1.232 +	fprintf(stderr, "Error %d\n", errno);
   1.233 +	break;
   1.234 +    }
   1.235 +    fprintf(stderr, "%s: Boot aborted!\n", progname);
   1.236      return 1;
   1.237  }
   1.238