Bug 202098 - [EFI] boot/loader.efi: handle parameters and override BOOTP root-path
Summary: [EFI] boot/loader.efi: handle parameters and override BOOTP root-path
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Some People
Assignee: Ian Lepore
URL:
Keywords: feature, patch, uefi
Depends on:
Blocks: 203349
  Show dependency treegraph
 
Reported: 2015-08-05 07:42 UTC by Ganael LAPLANCHE
Modified: 2016-01-19 21:47 UTC (History)
3 users (show)

See Also:
ian: mfc-stable9-
ian: mfc-stable10+


Attachments
Initialize environment using argv[] (830 bytes, text/x-csrc)
2015-08-05 07:42 UTC, Ganael LAPLANCHE
no flags Details
Use dhcp.root-path.override to override BOOTP root path (921 bytes, patch)
2015-08-05 07:43 UTC, Ganael LAPLANCHE
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ganael LAPLANCHE 2015-08-05 07:42:29 UTC
Created attachment 159563 [details]
Initialize environment using argv[]

Hi,

As discussed here on -hackers@ :

https://lists.freebsd.org/pipermail/freebsd-hackers/2015-August/048071.html

and for the record, here are two simple patches that allows the EFI loader to set environment variables from arguments and locally override the root path offered through BOOTP (through a new variable called "dhcp.root-path.override").

This allows to chainload loader.efi and pass your root-path (and any other variable) this way (e.g. with iPXE) :

#!ipxe
chain http://path.to/loader.efi dhcp.root-path.override=server_ip:/path/to/root some_other_var=value

Those patches are quite basic and will probably need refactoring, but you get the idea :p

Regards,
Ganael.
Comment 1 Ganael LAPLANCHE 2015-08-05 07:43:20 UTC
Created attachment 159564 [details]
Use dhcp.root-path.override to override BOOTP root path
Comment 2 Ian Lepore freebsd_committer 2015-12-15 03:38:23 UTC
Finally got around to doing something with this, sorry for the long delay.

I took the attached patch and reworked it so that any value delivered from the server that gets automatically set into the dhcp.* env vars can now be overridden with values the platform-specific part of loader(8) has preloaded into the environment.  The rootpath and hostname global vars used by other networking code in libstand will be overridden in addition to the automatic dhcp.* vars.

I also took the patch from the mailing list thread that sets env vars from the efi loader command line and prepared it for commit.

The patches have been turned into a pair of phabricator reviews:

https://reviews.freebsd.org/D4559
https://reviews.freebsd.org/D4561
Comment 3 commit-hook freebsd_committer 2015-12-22 03:03:52 UTC
A commit references this bug:

Author: ian
Date: Tue Dec 22 03:02:52 UTC 2015
New revision: 292583
URL: https://svnweb.freebsd.org/changeset/base/292583

Log:
  Allow dhcp/bootp server-provided values to be overriden from environment
  variables in loader(8) and other libstand applications.

  Sometimes a dhcp server provides incorrect information along with the IP
  address. It would be useful to have a way to override this with
  locally-supplied information, such as command line parameters passed from a
  prior-stage bootloader. This change allows pre-existing env vars to take
  precedence over values delivered by the dhcp or bootp server.

  The bootp/dhcp code in libstand automatically creates environment variables
  from the data provided by the server (dhcp.root-path, dhcp.domain-name,
  etc). It also transcribes the values to some global variables such as
  'rootpath' and 'hostname'.

  This change does two things:

      When adding dhcp.* vars to the environment, don't replace existing
      vars/values.

      When setting the global vars rootpath and hostname, use the
      dhcp.root-path and dhcp.host-name env var values if they exist.

  This allows the platform-specific part of loader(8) to obtain override
  values in some platform-specific way and store them in the environment
  before opening the network device. The set of values that can be overriden
  is currently limited to just string options. The values that are delivered
  as binary data are things that probably shouldn't be overridden (IP,
  netmask, gateway, etc).

  The original patch this evolved from was submitted by martymac@

  PR:		202098
  Differential Revision:	https://reviews.freebsd.org/D4559

Changes:
  head/lib/libstand/bootp.c
Comment 4 commit-hook freebsd_committer 2015-12-22 03:07:55 UTC
A commit references this bug:

Author: ian
Date: Tue Dec 22 03:07:38 UTC 2015
New revision: 292584
URL: https://svnweb.freebsd.org/changeset/base/292584

Log:
  Set env vars from values on the efi loader command line.

  Examine each cmdline arg and if it contains an '=' convert it to ascii and
  pass it to putenv(). This allows var=value settings to come in on the
  command line.

  This will allow overriding dhcp server-provided data in loader(8), as
  discussed in PR 202098

  PR:		202098
  Differential Revision:	https://reviews.freebsd.org/D4561

Changes:
  head/sys/boot/efi/loader/main.c
Comment 5 commit-hook freebsd_committer 2016-01-19 21:35:19 UTC
A commit references this bug:

Author: ian
Date: Tue Jan 19 21:35:10 UTC 2016
New revision: 294343
URL: https://svnweb.freebsd.org/changeset/base/294343

Log:
  MFC r292583:

    Allow dhcp/bootp server-provided values to be overriden from environment
    variables in loader(8) and other libstand applications.

    Sometimes a dhcp server provides incorrect information along with the IP
    address. It would be useful to have a way to override this with
    locally-supplied information, such as command line parameters passed from a
    prior-stage bootloader. This change allows pre-existing env vars to take
    precedence over values delivered by the dhcp or bootp server.

    The bootp/dhcp code in libstand automatically creates environment variables
    from the data provided by the server (dhcp.root-path, dhcp.domain-name,
    etc). It also transcribes the values to some global variables such as
    'rootpath' and 'hostname'.

    This change does two things:

        When adding dhcp.* vars to the environment, don't replace existing
        vars/values.

        When setting the global vars rootpath and hostname, use the
        dhcp.root-path and dhcp.host-name env var values if they exist.

    This allows the platform-specific part of loader(8) to obtain override
    values in some platform-specific way and store them in the environment
    before opening the network device. The set of values that can be overriden
    is currently limited to just string options. The values that are delivered
    as binary data are things that probably shouldn't be overridden (IP,
    netmask, gateway, etc).

    The original patch this evolved from was submitted by martymac@

  PR:           202098
  Relnotes:	Yes

Changes:
_U  stable/10/
  stable/10/lib/libstand/bootp.c
Comment 6 commit-hook freebsd_committer 2016-01-19 21:40:22 UTC
A commit references this bug:

Author: ian
Date: Tue Jan 19 21:39:22 UTC 2016
New revision: 294345
URL: https://svnweb.freebsd.org/changeset/base/294345

Log:
  MFC r292584:

    Set env vars from values on the efi loader command line.

    Examine each cmdline arg and if it contains an '=' convert it to ascii and
    pass it to putenv(). This allows var=value settings to come in on the
    command line.

    This will allow overriding dhcp server-provided data in loader(8), as
    discussed in PR 202098

  PR:           202098
  Relnotes:	Yes (this goes together with r294343)

Changes:
_U  stable/10/
  stable/10/sys/boot/efi/loader/main.c
Comment 7 Ian Lepore freebsd_committer 2016-01-19 21:47:25 UTC
Fixed committed, MFC'd to 10-stable.  Efi loader code doesn't appear to exist in 9-stable.