[ipxe-devel] [PATCH] [hci] Add setdirname command

Nils Carlson nils.carlson at ericsson.com
Fri Jan 21 15:43:54 UTC 2011


Hi Andrew,

On Fri, 21 Jan 2011, Andrew Bobulsky wrote:

> Hello Nils,
>
> Is this for defining the "TFTP Prefix:" one usually sees in a PXELINUX
> boot or is it something else?  Is there a specific usage scenario for
> it?
>

Well, typically on our boot server we have a little layout that looks like 
this:

tftp://server/one/long/path/kernel
tftp://server/one/long/path/initrd
tftp://server/one/long/path/pxelinux.0
tftp://server/one/long/path/pxelinux.cfg/default

All we get from dhcp is

filename=tftp://server/one/long/path/pxelinux.0

and

next-server=server

pxelinux works relatively the path of filename.

Now the server is a separate product, all we own on the server is our 
directory, and in an upgrade we can't change the dhcp server 
configuration, just the contents of the files. So we actually upload
undionly.kkpxe with a symlink from pxelinux.0. The undionly.kkpxe has a 
built in script

set use-cached 1
dhcp net0
setdirname _basedir ${filename}
imgfetch -n bootscript 
tftp://${next-server}/${_basedir}/pxelinux.cfg/default
imgload bootscript
imgexec bootscript

which lets us drop in a second script with whatever other parameters we 
need at tftp://server/one/long/path/pxelinux.cfg/default.
All the time we keep the structure exactly the same as for the pxelinux 
case, so its quite elegant. And we can gradually replace pxelinux and 
eventually phase in newer features like booting from http, ftp or 
multicast or some such.

/Nils



> I'm just curious.  Not much of a developer here myself, but I'm
> intrigued by something that helps keep PXELINUX strictly to the PXE
> boot scenarios that specifically require it, rather than having to
> bolt it on to solve funny netboot problems :)
>




> Thanks,
> Andrew Bobulsky
>
>
> On Fri, Jan 21, 2011 at 10:10 AM, Nils Carlson
> <nils.carlson at ericsson.com> wrote:
>> Add a setdirname command allowing us to retrieve the directory
>> from a filename. Simplifies the replacement of pxelinux with
>> ipxe.
>>
>> Signed-off-by: Nils Carlson <nils.carlson at ericsson.com>
>> ---
>>  src/hci/commands/nvo_cmd.c |   52 ++++++++++++++++++++++++++++++++++++++++++++
>>  1 files changed, 52 insertions(+), 0 deletions(-)
>>
>> diff --git a/src/hci/commands/nvo_cmd.c b/src/hci/commands/nvo_cmd.c
>> index 3513c8d..784c14c 100644
>> --- a/src/hci/commands/nvo_cmd.c
>> +++ b/src/hci/commands/nvo_cmd.c
>> @@ -16,6 +16,7 @@
>>  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
>>  */
>>
>> +#include <libgen.h>
>>  #include <stdint.h>
>>  #include <stdlib.h>
>>  #include <stdio.h>
>> @@ -178,6 +179,53 @@ static int clear_exec ( int argc, char **argv ) {
>>        return 0;
>>  }
>>
>> +/** "setdirname" options */
>> +struct setdirname_options {};
>> +
>> +/** "setdirname" option list */
>> +static struct option_descriptor setdirname_opts[] = {};
>> +
>> +/** "clear" command descriptor */
>> +static struct command_descriptor setdirname_cmd =
>> +       COMMAND_DESC ( struct setdirname_options, setdirname_opts, 2, 2,
>> +                      "<setting> <path>", "" );
>> +
>> +/**
>> + * "setdirname" command
>> + *
>> + * @v argc             Argument count
>> + * @v argv             Argument list
>> + * @ret rc             Return status code
>> + */
>> +static int setdirname_exec ( int argc, char **argv ) {
>> +       struct setdirname_options opts;
>> +       int rc;
>> +       char buf[256];
>> +       unsigned int len;
>> +
>> +       /* Parse options */
>> +       if ( ( rc = parse_options ( argc, argv, &setdirname_cmd, &opts ) ) != 0 )
>> +               return rc;
>> +
>> +       len = strlen(argv[optind + 1]);
>> +       if ( len > (sizeof(buf) - 1) ) {
>> +               printf( "Path %s too long to save dirname\n", argv[optind + 1] );
>> +               return 1;
>> +       }
>> +
>> +       strncpy( buf, argv[optind + 1], sizeof(buf) - 1 );
>> +
>> +       if ( ( rc = storef_named_setting ( argv[optind], dirname(buf) ) ) != 0 ) {
>> +               printf ( "Could not set \"%s\" to dirname of \"%s\": %s\n",
>> +                        argv[optind], argv[optind + 1], strerror ( rc ) );
>> +               return 1;
>> +       }
>> +
>> +       return 0;
>> +}
>> +
>> +
>> +
>>  /** Non-volatile option commands */
>>  struct command nvo_commands[] __command = {
>>        {
>> @@ -192,4 +240,8 @@ struct command nvo_commands[] __command = {
>>                .name = "clear",
>>                .exec = clear_exec,
>>        },
>> +       {
>> +               .name = "setdirname",
>> +               .exec = setdirname_exec,
>> +       },
>>  };
>> --
>> 1.6.0.2
>>
>> _______________________________________________
>> ipxe-devel mailing list
>> ipxe-devel at lists.ipxe.org
>> https://lists.ipxe.org/mailman/listinfo/ipxe-devel
>>
>


More information about the ipxe-devel mailing list