Home | History | Annotate | Download | only in modules
      1 /* ----------------------------------------------------------------------- *
      2  *
      3  *   Copyright 2008 H. Peter Anvin - All Rights Reserved
      4  *
      5  *   This program is free software; you can redistribute it and/or modify
      6  *   it under the terms of the GNU General Public License as published by
      7  *   the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
      8  *   Boston MA 02110-1301, USA; either version 2 of the License, or
      9  *   (at your option) any later version; incorporated herein by reference.
     10  *
     11  * ----------------------------------------------------------------------- */
     12 
     13 /*
     14  * sanboot.c
     15  *
     16  * Invoke the gPXE "sanboot" command, if available.
     17  */
     18 
     19 #include <alloca.h>
     20 #include <inttypes.h>
     21 #include <stdio.h>
     22 #include <console.h>
     23 #include <com32.h>
     24 #include <string.h>
     25 
     26 #include <sys/gpxe.h>
     27 #include <syslinux/pxe_api.h>
     28 
     29 struct segoff16 {
     30     uint16_t offs, seg;
     31 };
     32 
     33 struct s_PXENV_FILE_EXEC {
     34     uint16_t Status;
     35     struct segoff16 Command;
     36 };
     37 
     38 static void sanboot(const char **args)
     39 {
     40     char *q;
     41     struct s_PXENV_FILE_EXEC *fx;
     42 
     43     fx = lmalloc(sizeof *fx);
     44     if (!fx)
     45 	return;
     46 
     47     q = (char *)(fx + 1);
     48 
     49     fx->Status = 1;
     50     fx->Command.offs = OFFS(q);
     51     fx->Command.seg = SEG(q);
     52 
     53     q = stpcpy(q, "sanboot");
     54 
     55     while (*args) {
     56 	*q++ = ' ';
     57 	q = stpcpy(q, *args);
     58 	args++;
     59     }
     60 
     61     pxe_call(PXENV_FILE_EXEC, fx);
     62 
     63     /* This should not return... */
     64 }
     65 
     66 int main(int argc, const char *argv[])
     67 {
     68     if (argc < 2) {
     69 	printf("Usage: sanboot rootpath\n");
     70 	return 1;
     71     }
     72 
     73     if (!is_gpxe()) {
     74 	printf("sanboot: gPXE API not detected\n");
     75 	return 1;
     76     }
     77 
     78     sanboot(argv + 1);
     79 
     80     /* sanboot() should not return... */
     81     printf("SAN boot failed.\n");
     82     return 1;
     83 }
     84