david/ipxe
david
/
ipxe
Archived
1
0
Fork 0
Commit Graph

916 Commits

Author SHA1 Message Date
Robin Smidsrød 7016164056 [settings] Add "version" builtin setting
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2013-07-13 22:15:51 +02:00
Michael Brown 66ea458125 [settings] Make "netX" settings block function as a symbolic link
Add a facility for settings blocks to act as symbolic links to other
settings blocks, and reimplement the "netX" virtual settings block
using this facility.

The primary advantage of this approach is that unscoped settings such
as ${mac} and ${filename} will now reflect the settings obtained from
the most recently opened network device: in most cases, this will mean
the settings obtained from the most recent DHCP attempt.  This should
improve conformance to the principle of least astonishment.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2013-07-13 15:11:45 +02:00
Michael Brown 3dbcce51ea [settings] Add "busdevfn" setting type
Allow network device's "busloc" setting to be formatted as a PCI
bus:dev.fn address using e.g. ${net0/busloc:busdevfn}.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2013-07-12 22:38:19 +02:00
Michael Brown 9f3bbaca07 [settings] Add "hexraw" setting type
Originally-implemented-by: Jeppe Toustrup <ipxe@tenzer.dk>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2013-07-12 15:14:36 +02:00
Michael Brown 7774ceed2f [settings] Use hex_decode() to parse hex settings
Use hex_decode() to parse "hex" and "hexhyp" settings.  Note that this
parser is stricter than the old parser; it now requires exactly two
hex digits for each byte.  (The old parser was based upon strtoul()
and so would allow leading whitespace and a leading plus or minus
sign.)

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2013-07-12 15:14:36 +02:00
Michael Brown 076f58c4bf [base16] Generalise base16_decode() to hex_decode()
Provide a generic hex_decode() routine which can be shared between the
Base16 code and the "hex" and "hexhyp" settings parsers.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2013-07-12 15:14:36 +02:00
Michael Brown 15d2f947f5 [settings] Eliminate settings "tag magic"
Create an explicit concept of "settings scope" and eliminate the magic
values used for numerical setting tags.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2013-05-01 19:52:12 +01:00
Michael Brown 0e2ba15a58 [settings] Expose build architecture and platform via settings
Expose the build architecture (e.g. "i386" or "x86_64") via
${buildarch} and the firmware platform (e.g. "pcbios" or "efi") via
${platform}.  These settings directly expose the ARCH and PLATFORM
variables from the Makefile.

Note that the build architecture reflects the architecture for which
iPXE was compiled, not the architecture on which iPXE is currently
running.  The "cpuid" command can be used to detect a 64-bit system at
runtime.

Requested-by: James A. Peltier <jpeltier@sfu.ca>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2013-04-06 11:33:34 +01:00
Michael Brown e68a6ca225 [cmdline] Add ability to perform a warm reboot
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2013-03-22 13:54:44 +00:00
Michael Brown 71cd508838 [efi] Add "reboot" command for EFI
Abstract out the ability to reboot the system to a separate reboot()
function (with platform-specific implementations), add an EFI
implementation, and make the existing "reboot" command available under
EFI.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2013-03-22 13:44:02 +00:00
Michael Brown 033f4c92ca [autoboot] Split main control flow out of main() into a new function ipxe()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2013-03-13 22:24:13 +00:00
Michael Brown 0acc52519d [tls] Concatenate received non-data records before processing
Allow non-data records to be split across multiple received I/O
buffers, to accommodate large certificate chains.

Reported-by: Nicola Volpini <Nicola.Volpini@kambi.com>
Tested-by: Nicola Volpini <Nicola.Volpini@kambi.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2013-01-31 09:59:36 +00:00
Michael Brown fd141fb669 [umalloc] Split largest_memblock() function out from init_eheap()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-11-06 17:44:40 +00:00
Michael Brown 54a861a7bd [list] Reduce overall code size by externalising many list functions
Typical saving is 10-20 bytes in each file using list functions.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-11-02 16:21:06 +00:00
Michael Brown 4867085c0c [build] Include version number within only a single object file
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-11-02 14:46:39 +00:00
Michael Brown c86790df5c [settings] Add fetchf_named_setting_copy()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-10-24 20:42:42 -07:00
Michael Brown 1d38168064 [autoboot] Avoid excess backspacing after displaying Ctrl-B prompt
Remove the newline from the "Press Ctrl-B..." prompt string, so that
prompt() does not attempt to backspace beyond the start of the line.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-10-23 14:07:50 -07:00
Michael Brown 0fd29e15b5 [nvo] Expose nvo_applies()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-10-15 18:32:16 +01:00
Michael Brown 08a6ae86a2 [nvo] Expose non-volatile options block name
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-10-15 18:32:16 +01:00
Michael Brown 5ad445fd0b [settings] Treat an empty formatted value as meaning "delete setting"
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-10-15 18:32:16 +01:00
Michael Brown 1c2b6d29ea [settings] Expose find_child_settings()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-10-15 18:32:16 +01:00
Michael Brown 51b65d5f9c [libc] Add wcslen() function
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-10-15 18:32:16 +01:00
Shao Miller a712dae709 [serial] Don't enable serial console without serial support
serial_console_init() would enable serial console support without
knowing if the serial driver succeeded or not.  As a result, the
serial console would interfere with a normal keyboard on a system
lacking serial support.

Reported-by: Jan ONDREJ (SAL) <ondrejj(at)salstar.sk>
Signed-off-by: Shao Miller <sha0.miller@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-10-05 15:18:57 +01:00
Michael Brown 25ec56e0ec [settings] Use a generic setting's own type as its default type
When fetching a named setting using a name that does not explicitly
specify a type, default to using the type stored when the setting was
created, rather than always defaulting to "string".  This allows the
behaviour of user-defined settings to match the behaviour of
predefined settings (which have a sensible default type).

For example:

  set server:ipv4 192.168.0.1
  echo ${server}

will now print "192.168.0.1", rather than trying to print out the raw
IPv4 address bytes as a string.

The downside of this change is that existing tricks for printing
special characters within scripts may require (backwards-compatible)
modification.  For example, the "clear screen" sequence:

  set esc:hex 1b
  set cls ${esc}[2J
  echo ${cls}

will now have to become

  set esc:hex 1b
  set cls ${esc:string}[2J  # Must now explicitly specify ":string"
  echo ${cls}

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-09-10 14:25:04 +01:00
Michael Brown 96be171be5 [iobuf] Allow allocation of I/O buffers with a specified alignment offset
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-08-31 21:22:52 +01:00
Michael Brown e2becce186 [malloc] Allow allocation of memory with a specified alignment offset
Allow for allocation of memory blocks having a specified offset from a
specified physical alignment, such as being 12 bytes before a 2kB
boundary.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-08-31 21:22:45 +01:00
Michael Brown 183a70e8b7 [console] Sleep while waiting for user input
Reduce CPU usage while waiting for user input.  This is particularly
important for virtual machines, where CPU is a shared resource.

Reported-by: Alessandro Salvatori <alessandro@embrane.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-07-24 09:56:36 +01:00
Michael Brown c3b4860ce3 [legal] Update FSF mailing address in GPL licence texts
Suggested-by: Daniel P. Berrange <berrange@redhat.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-07-20 19:55:45 +01:00
Michael Brown 5d3c368efb [image] Add "--replace" option
Expose image tail-recursion to iPXE scripts via the "--replace"
option.  This functions similarly to exec() under Unix: the
currently-executing script is replaced with the new image (as opposed
to running the new image as a subroutine).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-07-20 12:45:15 +01:00
Michael Brown d3c660b671 [image] Add "--autofree" option
Allow images to be automatically freed after execution completes
(successfully or otherwise).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-07-20 12:44:40 +01:00
Michael Brown 58ed3b1cee [libc] Add support for "%lc" and "%ls" format specifiers
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-07-19 16:33:33 +01:00
Michael Brown c5c257788f [settings] Expose exit status of failed command via ${errno}
Allow scripts to report errors in more detail by exposing the most
recent error via the ${errno} setting.  For example:

    chain ${filename} || goto failed
    ...
    :failed
    imgfree http://192.168.0.1/ipxe_error.php?error=${errno}

Note that ${errno} is valid only immediately after executing a failed
command.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-07-12 15:46:24 +01:00
Michael Brown 5b4958388d [cmdline] Store exit status of failed command in errno
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-07-12 15:42:29 +01:00
Michael Brown 6825b2e7bf [malloc] Increase heap size to 512kB
The maximum TCP throughput is fundamentally limited by the amount of
available receive buffer space.  Increase the heap size from 128kB to
512kB to allow the use of larger TCP windows.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-07-09 10:13:47 +01:00
Michael Brown 8d95e1d6ff [malloc] Discard cached items less aggressively
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-07-09 10:08:37 +01:00
Michael Brown 4a8a7bd91a [iobuf] Allocate I/O buffer descriptor separately to conserve aligned memory
I/O buffers are allocated on aligned boundaries.  The I/O buffer
descriptor (the struct io_buffer) is currently attached to the end of
the I/O buffer.  When the size of the buffer is close to its
alignment, this can waste large amounts of aligned memory.

For example, a network card using 2048-byte receive buffers will end
up allocating 2072 bytes on a 2048-byte boundary.  This effectively
wastes 50% of the available memory.

Improve the situation by allocating the descriptor separately from the
main I/O buffer if inline allocation would cause the total allocated
size to cross the alignment boundary.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-07-08 17:54:53 +01:00
Michael Brown f3d197a529 [cmdline] Do not ignore empty initial arguments in concat_args()
Reported-by: Oliver Rath <rath@mglug.de>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-07-04 13:37:08 +01:00
Michael Brown a5c016d93e [iobuf] Relax alignment requirement for small I/O buffers
iPXE currently aligns all I/O buffers on a 2kB boundary.  This is
overkill for transmitted packets, which are typically much smaller
than 2kB.

Align I/O buffers on their own size.  This reduces the alignment
requirement for small buffers, while preserving the guarantee that I/O
buffers will never cross boundaries that might cause problems for some
DMA engines.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-06-29 16:07:12 +01:00
Michael Brown 85917ba8dd [monojob] Check for keypresses only once per timer tick
Checking for keypresses takes a non-negligible amount of time, and
measurably affects our RTT.  Minimise the impact by checking for
keypresses only once per timer tick.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-06-28 16:02:37 +01:00
Michael Brown 7ea6764031 [settings] Move "domain" setting from dns.c to settings.c
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-06-20 14:39:03 +01:00
Michael Brown 021d7b21b7 [pending] Add concept of "pending operations"
iPXE is fundamentally asynchronous in operation: some operations
continue in the background even after the foreground has continued to
a new task.  For example, the closing FIN/ACK exchanges of a TCP
connection will take place in the background after an HTTP download
has completed.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-06-09 18:48:28 +01:00
Michael Brown 89a354d553 [monojob] Allow monojob to be completely silent
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-05-22 00:47:19 +01:00
Michael Brown 40e68e1119 [base64] Avoid overrunning input data buffer
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-05-20 16:47:57 +01:00
Michael Brown c124f21f56 [image] Avoid potential NULL pointer dereference
Detected using Valgrind.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-05-08 21:05:25 +01:00
Michael Brown 2e4be01690 [xferbuf] Add generic data-transfer buffer
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-05-08 19:16:46 +01:00
Michael Brown 6f3e7e90fc [malloc] Allow Valgrind to be used when all assertions are enabled
The free-memory-block traversal code triggers multiple warnings from
Valgrind when assertions are enabled, since the list consistency
checks performed by list_check() end up accessing areas that have been
marked as inaccessible.

Fix by ensuring that any memory areas that will be accessed by
list_check() are marked as defined when necessary.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-05-04 17:16:35 +01:00
Michael Brown df2773193e [malloc] Discard all cached data on shutdown
Allow detection of genuine memory leaks by ensuring that all cached
data is freed on shutdown.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-05-04 15:15:34 +01:00
Michael Brown de2616165b [xfer] Avoid using stack-allocated memory in xfer_printf()
xfer_printf() occasionally has to deal with strings that are
potentially long, such as HTTP URIs with multiple query parameters.
Allocating these on the stack can lead to stack overruns and memory
corruption.

Fix by using vasprintf() instead of a stack allocation.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-04-23 20:30:48 +01:00
Michael Brown 31e60de676 [settings] Add fetch_setting_copy()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-04-19 16:10:07 +01:00
Michael Brown 52e5ddce68 [tftp] Allow builds without TFTP support
Allow TFTP to be configured out by moving the next-server setting
definition (which is used by autoboot.c) from tftp.c to settings.c.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-04-17 11:50:11 +01:00
Michael Brown 831b16adde [settings] Split fetching and storing out of setting type handlers
Refactor setting type handlers to parse and format values, rather than
storing and fetching formatted values.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-04-17 10:46:50 +01:00
Michael Brown 1d33649516 [libc] Allow strtoul() to interpret negative numbers
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-04-17 10:42:08 +01:00
Michael Brown 275fdae9bb [image] Fix use-after-free in debug messages
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-03-30 20:50:25 +01:00
Michael Brown 3425726cf3 [menu] Add menu commands
Allow iPXE scripts to create menus.  For example:

    #!ipxe

    menu iSCSI boot demonstration
    item install         Install Fedora to ${root-path}
    item --default boot  Boot from ${root-path}
    item shell           Enter iPXE shell
    item exit            Exit to BIOS
    choose label && goto ${label}

    :boot
    sanboot ${root-path}

    :install
    sanhook ${root-path}
    chain http://${next-server}/fedora.ipxe

    :shell
    shell

    :exit

Inspired-by: Robin Smidsrød <robin@smidsrod.no>
Tested-by: Robin Smidsrød <robin@smidsrod.no>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-03-29 14:02:02 +01:00
Michael Brown 0d2fba2887 [menu] Add the abstract concept of a menu
Inspired-by: Robin Smidsrød <robin@smidsrod.no>
Tested-by: Robin Smidsrød <robin@smidsrod.no>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-03-29 13:44:48 +01:00
Michael Brown 0b1fe005b3 [parseopt] Allow "prompt" command to accept character literals for --key
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-03-29 00:21:19 +01:00
Michael Brown 730c972124 [image] Log image executions
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-03-27 11:11:28 +01:00
Michael Brown 82ecaaac91 [console] Remove "log message" usage from interactive console defaults
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-03-27 00:51:50 +01:00
Michael Brown cef3beaba4 [downloader] Use a more meaningful error message when out of memory
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-03-27 00:43:07 +01:00
Michael Brown 9445cb9f8b [downloader] Abort download immediately if buffer resizing fails
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-03-27 00:38:19 +01:00
Michael Brown 5a91f5646a [downloader] Log final status of all downloads
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-03-26 22:47:50 +01:00
Michael Brown c2875ae329 [console] Do not share ANSI escape context between lineconsole users
An ANSI escape sequence context cannot be shared between multiple
users.  Make the ANSI escape sequence context part of the line console
definition and provide individual contexts for each user.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-03-26 21:58:50 +01:00
Michael Brown 24b7296319 [console] Add "log message" console usage and an internal syslog() call
Provide an internal syslog() function (unrelated to the syslog
console) which can be used to create log messages with specified
priorities.

The build-time constant LOG_LEVEL can be used to select the minimum
required priority for log messages.  Any messages that do not have a
sufficient priority will be ignored (and will be optimised away at
compile-time).

The default LOG_LEVEL is LOG_NONE.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-03-26 19:58:14 +01:00
Michael Brown e024cd39a8 [console] Allow usage to be defined independently for each console
Add the concept of a "console usage", such as "standard output" or
"debug messages".  Allow usages to be associated with each console
independently.  For example, to send debugging output via the serial
port, while preventing it from appearing on the local console:

  #define CONSOLE_SERIAL CONSOLE_USAGE_ALL
  #define CONSOLE_PCBIOS ( CONSOLE_USAGE_ALL & ~CONSOLE_USAGE_DEBUG )

If no usages are explicitly specified, then a default set of usages
will be applied.  For example:

  #define CONSOLE_SERIAL

will have the same affect as

  #define CONSOLE_SERIAL CONSOLE_USAGE_ALL

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-03-26 17:40:01 +01:00
Michael Brown b35d454422 [console] Remove unused "btext" console
The "btext" console has been disabled by a "#if 0" since 2007.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-03-26 15:47:34 +01:00
Michael Brown a6d49c17c9 [console] Move putchar() and getchar() declarations to stdio.h
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-03-26 14:43:52 +01:00
Michael Brown 1c127a6962 [image] Simplify image management commands and internal API
Remove the name, cmdline, and action parameters from imgdownload() and
imgdownload_string().  These functions now simply download and return
an image.

Add the function imgacquire(), which will interpret a "name or URI
string" parameter and return either an existing image or a newly
downloaded image.

Use imgacquire() to merge similar image-management commands that
currently differ only by whether they take the name of an existing
image or the URI of a new image to download.  For example, "chain" and
"imgexec" can now be merged.

Extend imgstat and imgfree commands to take an optional list of
images.

Remove the arbitrary restriction on the length of image names.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-03-24 23:12:04 +00:00
Michael Brown 97dcc824bf [image] Add concept of trusted images
Trusted images may always be executed.  Untrusted images may be
executed only if the current image trust requirement allows untrusted
images.

Images can be marked as trusted using image_trust(), and marked as
untrusted using image_untrust().

The current image trust requirement can be changed using
image_set_trust().  It is possible to make the change permanent, in
which case any future attempts to change the image trust requirement
will fail.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-03-22 16:16:02 +00:00
Michael Brown 846bde90e6 [time] Define an API for getting the current time
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-03-19 22:13:27 +00:00
Michael Brown bd6805a8c1 [libc] Add mktime() function
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-03-19 17:35:46 +00:00
Michael Brown 851b93fbc3 [syslog] Separate out generic line-based console functionality
Abstract out the generic line-handling portions of the syslog
putchar() routine, to allow use by other console types.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2012-02-28 23:10:01 +00:00
Marin Hannache be90241ec2 [getopt] Accept "--" as an end-of-options marker
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-11-02 00:23:57 +00:00
Michael Brown 790035f78d [image] Eliminate the register_and_xxx_image() functions
All users of imgdownload() require registration of the image, so make
registration an integral part of imgdownload() itself and simplify the
"action" parameter to be one of image_select(), image_exec() et al.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-10-25 01:41:41 +01:00
Michael Brown 59e4c37741 [cmdline] Allow "sleep" command to be interrupted
Allow Ctrl-C to be used to abort a "sleep" command.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-10-24 15:52:57 +01:00
Michael Brown f177a6f09f [cmdline] Fix up "sleep" argument parsing
Use parse_integer() rather than strtoul() to allow parsing errors to
be reported in a meaningful way.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-10-24 15:52:14 +01:00
Michael Brown bf2da3122b [cmdline] Make "sleep" command available by default
The "sleep" command is generally useful to have.  For example:

  :dhcp_retry
  dhcp && goto dhcp_done
  sleep 5
  goto dhcp_retry
  :dhcp_done

Make the "sleep" command available by default, leaving TIME_CMD
controlling only the (fairly specialist) "time" command.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-10-24 15:39:05 +01:00
Michael Brown dc821ca961 [libc] Allow assertion failures to be counted
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-10-14 14:33:31 +01:00
Michael Brown 66cbae73bd [libc] Allow for zero-padded decimals in printf()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-07-06 14:52:53 +01:00
Michael Brown 3915b660fd [hw] Eliminate polling while waiting for window to open
Polling for the data-transfer window to become open is wasteful.  We
can eliminate the polling loop by using hw_step() as the handler for
an xfer_window_changed() event.

If the window is already open at the time of instantiation, then
xfer_window_changed() may never be called.  We can cover this case by
using hw_step() as the step() method of a one-shot process.  Since the
signature for an xfer_window_changed() method is identical to the
signature for a process step() method, the same function can be used
for both.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-06-28 14:45:11 +01:00
Michael Brown 5694b71b11 [resolv] Use a one-shot process for the numeric resolver
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-06-28 14:45:09 +01:00
Michael Brown ccc2655540 [process] Add support for one-shot processes
Some processes execute only once, and exist solely in order to defer
execution until after the relevant instantiator method has returned.
Such processes do not need to be automatically rescheduled when
executing.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-06-28 14:45:09 +01:00
Michael Brown e01ec74601 [process] Pass containing object pointer to process step() methods
Give the step() method a pointer to the containing object, rather than
a pointer to the process.  This is consistent with the operation of
interface methods, and allows a single function to serve as both an
interface method and a process step() method.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-06-28 14:45:08 +01:00
Michael Brown ba3633782b [xfer] Send xfer_window_changed() after xfer_vredirect()
Modify the default action for xfer_vredirect() to automatically send
xfer_window_changed() messages to both the new child and the parent
interfaces.  This will allow the elimination of processes that simply
poll on xfer_window() to determine when a redirection has completed
successfully.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-06-28 14:45:08 +01:00
Michael Brown c49659c4f2 [parseopt] Disambiguate the various EINVAL errors
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-05-18 09:39:27 +01:00
Michael Brown 5d2802e403 [sanboot] Add "sanhook" and "sanunhook" commands
Expose the multiple-SAN-drive capability of the iPXE core via the iPXE
command line by adding commands to hook and unhook additional drives.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-04-24 16:44:34 +01:00
Michael Brown 3ca5656208 [parseopt] Allow for pre-initialised option sets
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-04-24 15:32:06 +01:00
Greg Jednaszewski 3726b3d94a [cmdline] Add "iseq" command
Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-04-08 19:34:20 +01:00
Michael Brown 7aee315f61 [cmdline] Simplify "isset" command
There is no plausible scenario I can think of in which "isset" would
be used with more than one argument.  Simplify the code by specifying
that exactly one argument is required.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-04-08 03:19:06 +01:00
Michael Brown 06f1878fb8 [cmdline] Fix "isset" command
Commit b5f5f73 ("[cmdline] Expand settings within each command-line
token individually") introduced a regression into the "isset" command:
it is now possible for command-line arguments to be empty strings, and
so "isset" cannot simply check for a non-empty argument list.

Restore previous behaviour by checking for the presence of any
non-empty arguments, rather than checking for a non-empty argument
list.

Reported-by: Nemtallah Daher <n.daher@csuohio.edu>
Tested-by: Nemtallah Daher <n.daher@csuohio.edu>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-04-01 20:09:51 +01:00
Michael Brown 2f6e7bde77 [main] Add the "scriptlet" setting
A scriptlet is a single iPXE command that can be stored in
non-volatile option storage and used to override the default
"autoboot" behaviour without having to reflash the iPXE image.

For example, a scriptlet could contain

    autoboot || reboot

to instruct iPXE to reboot the system if booting fails.

Unlike an embedded image, the presence of a scriptlet does not inhibit
the initial "Press Ctrl-B..." prompt.  This allows the user to recover
from setting a faulty scriptlet.

Originally-implemented-by: Glenn Brown <glenn@myri.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-28 18:50:27 +01:00
Michael Brown b5f5f735c1 [cmdline] Expand settings within each command-line token individually
Perform settings expansion after tokenisation, and only at the point
of executing each command.  This allows statements such as

   dhcp && echo ${net0/ip}

to work correctly.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-28 17:35:23 +01:00
Michael Brown 1f4c5f90c3 [cmdline] Allow ";" as an unconditional command separator
It is currently possible to construct a sequence of commands to be
executed regardless of success or failure using "|| &&" as the command
separator.  (The "||" captures the failure case, the blank command
converts it to a success case.)

Allow ";" to be used as a more visually appealing (and
space-efficient) alternative.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-28 16:32:30 +01:00
Piotr Jaroszyński b604e8a388 [linux] Make malloc and linux_umalloc valgrindable
Make the allocators used by malloc and linux_umalloc valgrindable.
Include valgrind headers in the codebase to avoid a build dependency
on valgrind.

Signed-off-by: Piotr Jaroszyński <p.jaroszynski@gmail.com>
Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-27 21:03:05 +01:00
Michael Brown ac12324f52 [cmdline] Allow "echo -n" to inhibit trailing newline
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-27 12:49:18 +01:00
Michael Brown a246434299 [parseopt] Add support for boolean options
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-27 12:46:55 +01:00
Michael Brown 5590faf14a [monojob] Avoid overflow when calculating percentage progress
Normalise the progress figures to ensure that multiplication by 100
(to produce a percentage) cannot result in integer overflow.

Reported-by: Sven Dreyer <sven@dreyer-net.de>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-26 13:14:53 +00:00
Michael Brown 02a6f46c09 [settings] Match terminology in online documentation
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-23 21:21:12 +00:00
Michael Brown 071b4000d9 [settings] Avoid memory leak when unregistering autovivified settings blocks
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-23 20:17:24 +00:00
Michael Brown 8482451812 [settings] Impose a fixed order on settings
Improve the appearance of the "config" user interface by ensuring that
settings appear in some kind of logical order.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-23 11:57:29 +00:00
Michael Brown b36882be34 [settings] Fix setting expansion
Commit 5fbd020 ("[settings] Display canonical setting name in output
of "show" command") introduced a regression causing all setting
expansions (e.g. "${net0/mac}") to expand to an empty string.

Fix by returning the formatted value length from
fetchf_named_setting(), as expected by the caller.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-23 10:08:16 +00:00
Michael Brown 247ac80556 [settings] Display canonical setting name in "config" user interface
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-22 21:26:05 +00:00
Michael Brown 5fbd0207b2 [settings] Display canonical setting name in output of "show" command
Enable the "show" command to display the full, canonicalised name of
the fetched setting.  For example:

  iPXE> show mac
  net0/mac:hex = 52:54:00:12:34:56

  iPXE> dhcp && show ip
  DHCP (net0 52:54:00:12:34:56)... ok
  net0.dhcp/ip:ipv4 = 10.0.0.168

  iPXE> show net0/6
  net0.dhcp/dns:ipv4 = 10.0.0.6

Inspired-by: Glenn Brown <glenn@myri.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-22 20:13:50 +00:00
Michael Brown ba8dd80487 [settings] Provide fetch_setting_origin()
Inspired-by: Glenn Brown <glenn@myri.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-22 19:55:06 +00:00
Glenn Brown f732fa28c8 [settings] Expose settings_name()
Expose settings_name(), shrink the unnecessarily large static buffer,
properly name root settings block, and simplify.

Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-22 19:55:05 +00:00
Michael Brown f5fd4dec3b [settings] Formalise notion of setting applicability
Expose a function setting_applies() to allow a caller to determine
whether or not a particular setting is applicable to a particular
settings block.

Restrict DHCP-backed settings blocks to accepting only DHCP-based
settings.

Restrict network device settings blocks to accepting only DHCP-based
settings and network device-specific settings such as "mac".

Inspired-by: Glenn Brown <glenn@myri.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-22 19:54:58 +00:00
Michael Brown 1c0ff6e1a7 [console] Move include/console.h to include/ipxe/console.h
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-09 20:09:26 +00:00
Michael Brown 4562223420 [image] Avoid ending up with multiple selected images on re-registration
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-09 17:21:34 +00:00
Michael Brown 9fa4ac2e9a [image] Simplify use of imgdownload()
Allow imgdownload() to be called without first having to allocate (and
so keep track of) an image.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-09 16:57:34 +00:00
Michael Brown ae92700fd4 [image] Generalise "currently-running script" to "currently-running image"
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-09 13:38:56 +00:00
Michael Brown d17a84a056 [image] Move the register_and_{select|boot}_image() functions to imgmgmt.c
These functions are used only as the "action" parameters to
imgdownload() or imgfetch(), and so belong in imgmgmt.c rather than
image.c

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-09 13:11:35 +00:00
Michael Brown 3936136e5e [monojob] Display percentage progress, if available
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-07 23:55:57 +00:00
Michael Brown 202cf094eb [main] Remove shell prompt when using an embedded image
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-07 20:42:36 +00:00
Michael Brown 7752541bb7 [image] Use list_first_entry() to clarify logic in main()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-07 19:53:58 +00:00
Michael Brown c4b6c244b0 [prompt] Replace shell_banner() with a generic prompt() function
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-07 19:53:53 +00:00
Michael Brown 9d633bdc71 [console] Add a timeout parameter to getkey()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-07 19:37:30 +00:00
Michael Brown 2969a8567f [console] Avoid timer wraparound problems in getchar_timeout()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-07 19:22:20 +00:00
Michael Brown a281c4080b [cmdline] Add generic concat_args() function
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-07 19:21:43 +00:00
Michael Brown 659c55c1a9 [image] Allow image_set_cmdline() to clear the command line
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-07 02:43:56 +00:00
Michael Brown 34b6ecb2f1 [image] Simplify image management
Refactor the {load,exec} image operations as {probe,exec}.  This makes
the probe mechanism cleaner, eliminates some forward declarations,
avoids holding magic state in image->priv, eliminates the possibility
of screwing up between the "load" and "exec" stages, and makes the
documentation simpler since the concept of "loading" (as distinct from
"executing") no longer needs to be explained.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-07 00:37:50 +00:00
Michael Brown 7d5dcc9299 [parseopt] Refer to online documentation for command help
The online documentation (e.g. http://ipxe.org/cmd/ifopen), though not
yet complete, is far more comprehensive than could be provided within
the iPXE binary.  Save around 200 bytes (compressed) by removing the
command descriptions from the interactive help, and instead referring
users directly to the web page describing the relevant command.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-04 12:18:51 +00:00
Michael Brown 48a4001152 [settings] Make fetch_string_setting_copy() easier to use
Most callers of functions in the fetch_setting() family treat any
errors as meaning "non-existent setting".  In the case of
fetch_string_setting_copy(), an existent setting can still result in
an error due to memory allocation failure.

Allow the caller to distinguish between a non-existent setting and an
error in allocating memory for the copy, by returning success (and a
NULL buffer pointer) for a non-existent setting.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-03 20:03:08 +00:00
Michael Brown 09695f7be9 [settings] Avoid fetch_string_setting_copy() leaving an uninitialised pointer
For consistency with other functions in the fetch_setting() family,
ensure that fetch_string_setting_copy() always initialises the pointer
to the fetched setting even if fetching fails.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-03 17:13:44 +00:00
Michael Brown 3c9c27b8e6 [image] Allow download job to complete before acting upon image
Allow the monojob controlling the download to complete before calling
register_image() and friends.  This allows the trailing "ok" from
monojob.c to be printed before the image starts executing (and
possibly printing output of its own).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-03-02 19:29:24 +00:00
Michael Brown 990cbb8f2c [settings] Generalise expand_command() to expand_settings()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-01-28 00:16:18 +00:00
Michael Brown 962cada830 [init] Remove concept of "shutdown exit flags"
Remove the concept of shutdown exit flags, and replace it with a
counter used to keep track of exposed interfaces that require devices
to remain active.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-01-27 20:40:26 +00:00
Michael Brown 35a50399a5 [xfer] Expose xfer_uri_opener()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-01-27 18:46:07 +00:00
Michael Brown 17d28f4877 [nvo] Allow resizing of non-volatile stored option blocks
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-01-19 13:52:48 +00:00
Michael Brown 1651d4f6d7 [nvo] Remove the non-volatile options fragment list
Since its implementation several years ago, no driver has used a
fragment list containing more than a single fragment.  Simplify the
NVO core and the drivers that use it by removing the whole concept of
the fragment list, and using a simple (address,length) pair instead.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-01-11 21:24:40 +00:00
Michael Brown 17b6a3c506 [dhcp] Allow use of custom reallocation functions for DHCP option blocks
Allow functions other than realloc() to be used to reallocate DHCP
option block data, and specify the reallocation function at the time
of calling dhcpopt_init().

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2011-01-11 21:24:40 +00:00
Michael Brown cb838cc419 [settings] Add fetch_ipv4_array_setting()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-12-09 15:34:12 +00:00
Michael Brown 66531a5918 [debug] Add DBG_MD5() and related macros
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-12-09 13:13:31 +00:00
Michael Brown 9252fead9a [legal] Add missing copyright header and FILE_LICENCE macro
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-12-09 13:12:59 +00:00
Michael Brown ea0fcb9460 [fnrec] Enhance function recording
Enhance the information collected by the function recorder to include
the call site and entry/exit counts.  This allows fnrec.pl to produce
a call tree such as:

    step (from core/getkey.c:46 = 0x17e90) {
      ref_increment (from core/process.c:93 = 0x73ec) { }
      net_step (from core/process.c:96 = 0x73f1) {
        net_poll (from net/netdevice.c:741 = 0xbce6) {
          netdev_poll (from net/netdevice.c:700 = 0xbc58) { }
          netdev_rx_dequeue (from net/netdevice.c:709 = 0xbc65) { }
        }
      }
      ref_decrement (from core/process.c:96 = 0x73f9) { }
    }

Note that inlined functions are reported, confusingly, as extra calls
to the *containing* function.  Minimise this confusion by adding the
attribute "no_instrument_function" to all functions declared as
inline.  (Static functions that have been inlined autonomously by gcc
will still be problematic, but these are far fewer in number.)

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-12-09 13:11:27 +00:00
Shao Miller 3b51710156 [legal] Add FILE_LICENCE macro to some GPL-v2-or-later files
Changes were made to files where the licence text within the files
themselves confirms that the files are GPL version 2 or later.

Signed-off-by: Shao Miller <shao.miller@yrdsb.edu.on.ca>
Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-12-03 23:38:15 +00:00
Shao Miller 79a3799c41 [legal] Add FILE_LICENCE macro to some GPL-v2 files
Changes were made to files where the licence text within the files
themselves confirms that the files are GPL version 2.

Signed-off-by: Shao Miller <shao.miller@yrdsb.edu.on.ca>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-12-03 23:23:35 +00:00
Michael Brown 67b45186a5 [settings] Apply settings block name in register_settings()
Pass the settings block name as a parameter to register_settings(),
rather than defining it with settings_init() (and then possibly
changing it by directly manipulating settings->name).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-12-01 16:35:00 +00:00
Michael Brown 7bebe9579e [cmdline] Match user expectations for &&, ||, goto, and exit
The && and || operators should be left-associative, since that is how
they are treated in most other languages (including C and Unix
shell).  For example, in the command:

  dhcp net0 && goto dhcp_ok || echo No DHCP on net0

if the "dhcp net0" fails then the "echo" should be executed.

After an "exit" or a successful "goto", further commands on the same
line should never be executed.  For example:

  goto somewhere && echo This should never be printed
  exit 0 && echo This should never be printed
  exit 1 && echo This should never be printed

An "exit" should cause the current shell or script to terminate and
return the specified exit status to its caller.  For example:

  chain test.ipxe && echo Success || echo Failure
    [in test.ipxe]
    #!ipxe
    exit 0

should echo "Success".

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-11-29 14:19:59 +00:00
Michael Brown 01df5c510f [parseopt] Allow "0x"-prefixed hexadecimal values in integer-valued options
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-11-29 14:18:43 +00:00
Michael Brown b87ed3295e [nvo] Allow fragment list to be omitted
Allow the fragment list to be omitted when calling nvo_init().
Omitting the list will cause the whole of the NVS device to be used
for NVO storage.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-11-25 00:05:20 +00:00
Michael Brown 66679fe7df [cmdline] Fix multi-layer variable expansion (again)
Expansion of the (admittedly perverse) "aaa}bbb${ccc" will currently
fail because expand_command() does not check that the closing "}"
occurs later than the opening "${".

Fix by ensuring that the most recent opening "${" is used to match
against the first *subsequent* closing "}".

Total cost of this change: -12 bytes, bringing the overall cost of
this feature to -4 bytes.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-11-23 00:18:11 +00:00
Michael Brown c1327e43ab [cmdline] Fix multi-layer variable expansion
Expansion of ${${foo}} will currently fail, because the first
opening "${" will be incorrectly matched against the first closing
"}", leading to an attempt to expand the variable "${foo".

Fix by ensuring that the most recent opening "${" is used to match
against the first closing "}".

Total cost: 8 bytes.  :)

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-11-22 21:34:35 +00:00
Michael Brown ba92a46710 [cmdline] Add "isset" command
The "isset" command can be used to determine whether or not a setting
is present.  For example:

  isset ${net0/ip} || dhcp net0   # If we have no IP address, try DHCP

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-11-22 20:41:52 +00:00
Michael Brown 84aa702ff8 [script] Allow "exit" to exit a script
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-11-22 20:29:01 +00:00
Michael Brown 9ba988809d [cmdline] Add trivial logical operators to iPXE command lines
Make the "||" and "&&" operators available within iPXE commands.  For
example:

   dhcp net0 || set net0/ip 192.168.0.2

would attempt to acquire an IP address via DHCP, falling back to a
static address if DHCP fails.

As a side-effect, comments may now be appended to any line.  For
example:

  dhcp net0 || set net0/ip 192.168.0.2   # Try DHCP first, then static

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-11-22 01:47:07 +00:00
Michael Brown 216fd0a5cf [parseopt] Add generic option-parsing library
Command implementations tend to include a substantial amount of common
boilerplate code revolving around the parsing of command-line options
and arguments.  This increases the size cost of each command.

Introduce an option-parsing library that abstracts out the common
operations involved in command implementations.  This enables the size
of each individual command to be reduced, and also enhances
consistency between commands.

Total size of the library is 704 bytes, to be amortised across all
command implementations.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-11-21 20:38:26 +00:00
Michael Brown 312ae024d8 [settings] Add "hexhyp" setting type
Provide a "hexhyp" setting type, which functions identically to the
"hex" setting type except that it uses a hyphen instead of a colon as
the byte delimiter.

For example, if ${mac} expands to "52:54:00:12:34:56", then
${mac:hexhyp} will expand to "52-54-00-12-34-56".

Originally-implemented-by: Jarrod Johnson <jarrod.b.johnson@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-11-13 00:28:26 +00:00
Michael Brown 13e4b9ec49 [malloc] Avoid immediately clobbering reference count when freeing memory
Rearrange the fields in struct memory_block (without altering
MIN_MEMBLOCK_SIZE) so that the "count" field of a reference-counted
object is left intact when the memory containing the object is freed.
This allows for the possibility of detecting reference-counting errors
such as double-freeing.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-11-08 03:35:35 +00:00
Michael Brown 6e41f2cf18 [refcnt] Check reference validity on each use of ref_get() and ref_put()
Check that the reference count is valid (i.e. non-negative) on each
call to ref_get() and ref_put(), using an assert() at the point of
use.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-11-08 03:35:35 +00:00
Michael Brown fc69ab94d9 [malloc] Use list_for_each_entry_safe() when we may delete a list entry
free_memblock() currently uses list_for_each_entry() to iterate over
the free list, and may delete an entry over which it iterates.  While
there is no way that the deleted list entry could be overwritten
before we reference it, this does rely upon list_del() leaving the
"next" pointer intact, which is not guaranteed.  Discovered while
tracking down a list-corruption bug (as a result of having modified
list_del() to sanitise the deleted list entry).

Fix by using list_for_each_entry_safe().

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-11-08 03:15:56 +00:00
Michael Brown ea631f6fb8 [list] Add list_first_entry()
There are several points in the iPXE codebase where
list_for_each_entry() is (ab)used to extract only the first entry from
a list.  Add a macro list_first_entry() to make this code easier to
read.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-11-08 03:15:28 +00:00
Michael Brown de1381578b [process] Include step() function pointer in process debugging messages
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-11-08 02:22:53 +00:00
Michael Brown 3c35ae2f3b [int13] Add infrastructure to support EDD version 4.0
Support the extensions mandated by EDD 4.0, including:

 o  the ability to specify a flat physical address in a disk address
    packet,

 o  the ability to specify a sector count greater than 127 in a disk
    address packet,

 o  support for all functions within the Fixed Disk Access and EDD
    Support subsets,

 o  the ability to describe a device using EDD Device Path Information.

This implementation is based on draft revision 3 of the EDD 4.0
specification, with reference to the EDD 3.0 specification.  It is
possible that this implementation may need to change in order to
conform to the final published EDD 4.0 specification.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-09-22 17:09:56 +01:00
Michael Brown 220495f8bf [block] Replace gPXE block-device API with an iPXE asynchronous interface
The block device interface used in gPXE predates the invention of even
the old gPXE data-transfer interface, let alone the current iPXE
generic asynchronous interface mechanism.  Bring this old code up to
date, with the following benefits:

 o  Block device commands can be cancelled by the requestor.  The INT 13
    layer uses this to provide a global timeout on all INT 13 calls,
    with the result that an unexpected passive failure mode (such as
    an iSCSI target ACKing the request but never sending a response)
    will lead to a timeout that gets reported back to the INT 13 user,
    rather than simply freezing the system.

 o  INT 13,00 (reset drive) is now able to reset the underlying block
    device.  INT 13 users, such as DOS, that use INT 13,00 as a method
    for error recovery now have a chance of recovering.

 o  All block device commands are tagged, with a numerical tag that
    will show up in debugging output and in packet captures; this will
    allow easier interpretation of bug reports that include both
    sources of information.

 o  The extremely ugly hacks used to generate the boot firmware tables
    have been eradicated and replaced with a generic acpi_describe()
    method (exploiting the ability of iPXE interfaces to pass through
    methods to an underlying interface).  The ACPI tables are now
    built in a shared data block within .bss16, rather than each
    requiring dedicated space in .data16.

 o  The architecture-independent concept of a SAN device has been
    exposed to the iPXE core through the sanboot API, which provides
    calls to hook, unhook, boot, and describe SAN devices.  This
    allows for much more flexible usage patterns (such as hooking an
    empty SAN device and then running an OS installer via TFTP).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-09-14 20:37:15 +01:00
Michael Brown c8199aacaa [xfer] Add xfer_window_changed()
xfer_window_changed() can be used to notify peers that an interface is
now ready to accept data.  This can potentially be used to eliminate
the need for wasteful processes that simply poll xfer_window() until
the window becomes non-zero.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-09-05 03:12:17 +01:00
Michael Brown 25447294d5 [process] Add process_running()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-09-03 21:26:21 +01:00
Michael Brown 0329673833 [xfer] Add xfer_deliver_raw_meta()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-09-03 21:23:16 +01:00
Michael Brown 364b92521a [xfer] Generalise metadata "whence" field to "flags" field
iPXE has never supported SEEK_END; the usage of "whence" offers only
the options of SEEK_SET and SEEK_CUR and so is effectively a boolean
flag.  Further flags will be required to support additional metadata
required by the Fibre Channel network model, so repurpose the "whence"
field as a generic "flags" field.

xfer_seek() has always been used with SEEK_SET, so remove the "whence"
field altogether from its argument list.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-09-03 21:21:14 +01:00
Piotr Jaroszyński 1822b1deb9 [libc] Add strtoull()
Don't implement strtoul() on top of strtoull() as strtoull() is much
bigger and only used on linux currently. Instead refactor most of the
logic out of strtoul() into static inlines and reuse that. Also put it
in a separate object so it won't get linked in.

Signed-off-by: Piotr Jaroszyński <p.jaroszynski@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-08-19 12:22:07 +01:00
Piotr Jaroszyński 380d7c8d45 [settings] Export find_setting()
Signed-off-by: Piotr Jaroszyński <p.jaroszynski@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-08-17 14:39:10 +01:00
Michael Brown 9dc51afa2c [malloc] Add cache discard mechanism
Add a facility allowing cached data to be discarded in order to
satisfy memory allocations that would otherwise fail.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-07-21 11:58:50 +01:00
Piotr Jaroszyński 519a4be189 [settings] Unregister the children when unregistering the parent
The DHCP settings registered as a child of the netdevice settings are
not unregistered anywhere.  This prevents the netdevice from being
freed on shutdown.

Fix by automatically unregistering any child settings when the parent
settings are unregistered.

Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-07-15 20:31:53 +01:00
Michael Brown 3338a03982 [hci] Continue processing while prompting for shell banner
Continue calling step() while displaying the shell banner.  This
potentially allows TCP connections to close gracefully after a failed
boot attempt.

Inspired-by: Guo-Fu Tseng <cooldavid@cooldavid.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-07-14 12:43:10 +01:00
Michael Brown 7aa1d70e52 [debug] Expose pause() and more() debugging functions
Include the pause() and more() debugging functions within the general
iPXE debugging framework, by introducing DBGxxx_PAUSE() and
DBGxxx_MORE() macros.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-07-14 12:28:18 +01:00
Michael Brown 9f3c0c1f39 [debug] Remove unused guard_region() and check_region() functions
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-07-14 11:44:58 +01:00
Piotr Jaroszyński fd312fcc78 [image] Fix a memory leak in free_image()
image_set_cmdline() strdup()s cmdline, which free_image() doesn't
clean up.

Signed-off-by: Piotr Jaroszyński <p.jaroszynski@gmail.com>
Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-07-11 15:55:04 +01:00
Joshua Oreman 719ba316df [refcnt] Add ref_no_free handler
Since more reference-counted structures than embedded images might
want to mark themselves unfreeable, expose a dummy ref_no_free().

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-06-23 00:34:48 +01:00
Michael Brown 65bc070b05 [interface] Allow for non-pass-through interface methods
xfer_vredirect() should not be allowed to propagate to a pass-through
interface.  For example, when an HTTPS connection is opened, the
redirect message should cause the TLS layer to reopen the TCP socket,
rather than causing the HTTP layer to disconnect from the TLS layer.

Fix by allowing for non-pass-through interface methods, and setting
xfer_vredirect() to be one such method.

This is slightly ugly, in that it complicates the notion of an
interface method call by adding a "pass-through" / "non-pass-through"
piece of metadata.  However, the only current user of xfer_vredirect()
is iscsi.c, which uses it only because we don't yet have an
ioctl()-style call for retrieving the underlying socket address.
The new interface infrastructure allows for such a call to be created,
at which time this sole user of xfer_vredirect() can be removed,
xfer_vredirect() can cease to be an interface method and become simply
a wrapper around xfer_vreopen(), and the concept of a non-pass-through
interface method can be reverted.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-06-22 19:12:40 +01:00
Michael Brown 4327d5d39f [interface] Convert all data-xfer interfaces to generic interfaces
Remove data-xfer as an interface type, and replace data-xfer
interfaces with generic interfaces supporting the data-xfer methods.

Filter interfaces (as used by the TLS layer) are handled using the
generic pass-through interface capability.  A side-effect of this is
that deliver_raw() no longer exists as a data-xfer method.  (In
practice this doesn't lose any efficiency, since there are no
instances within the current codebase where xfer_deliver_raw() is used
to pass data to an interface supporting the deliver_raw() method.)

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-06-22 15:50:31 +01:00
Michael Brown 7b4fbd93a5 [interface] Convert all name-resolution interfaces to generic interfaces
Remove name-resolution as an interface type, and replace
name-resolution interfaces with generic interfaces supporting the
resolv_done() method.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-06-22 15:45:57 +01:00
Michael Brown a03dd97e6b [interface] Convert all job-control interfaces to generic interfaces
Remove job-control as an interface type, and replace job-control
interfaces with generic interfaces supporting the close() method.
(Both done() and kill() are absorbed into the function of close();
kill() is merely close(-ECANCELED).)

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-06-22 14:40:09 +01:00
Michael Brown e71b83b22b [interface] Expand object interface to allow for polymorphic interfaces
We have several types of object interface at present (data-xfer, job
control, name resolution), and there is some duplication of
functionality between them.  For example, job_done(), job_kill() and
xfer_close() are almost isomorphic to each other.

This updated version of the object interface mechanism allows for each
interface to export an arbitrary list of supported operations.
Advantages include:

  Operations methods now receive a pointer to the object, rather than
  a pointer to the interface.  This allows an object to, for example,
  implement a single close() method that can handle close() operations
  from any of its exposed interfaces.

  The close() operation is implemented as a generic operation (rather
  than having specific variants for data-xfer, job control, etc.).
  This will allow functions such as monojob_wait() to be used to wait
  for e.g.  a name resolution to complete.

  The amount of boilerplate code required in objects is reduced, not
  least because it is no longer necessary to include per-interface
  methods that simply use container_of() to derive a pointer to the
  object and then tail-call to a common per-object method.

  The cost of adding new operations is reduced; adding a new data-xfer
  operation such as stat() no longer incurs the penalty of adding a
  .stat member to the operations table of all existing data-xfer
  interfaces.

The data-xfer, job control and name resolution interfaces have not yet
been updated to use the new interface mechanism, but the code will
still compile and run.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-06-22 14:34:58 +01:00
Michael Brown 4bfd5b52c1 [refcnt] Add ref_init() wrapper function
Standardise on using ref_init() to initialise an embedded reference
count, to match the coding style used by other embedded objects.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-06-22 14:26:40 +01:00
Michael Brown 068ef5f72d [process] Hold reference to process during call to step()
It is conceivable that the process may terminate during the execution
of step().  If nothing else holds a reference to the containing
object, this would cause the object to be freed prior to returning
from step().

Add a ref_get()/ref_put() around the call to ->step() to prevent this
from happening.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-06-15 16:26:28 +01:00
Michael Brown bc83e4b5d3 [base16] Add generic base16 encoding and decoding routines
Base16 encoding is currently implemented in both iSCSI and SRP.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-05-28 15:41:37 +01:00
Michael Brown 97ea628484 [base64] Add ability to decode base64 strings
Inspired-by: Piotr Jaroszyński <p.jaroszynski@gmail.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-05-28 12:47:10 +01:00
Michael Brown dfcce165a5 [base64] Allow base64_encode() to handle arbitrary data
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-05-28 12:44:23 +01:00
Geoff Lywood 83efb3d750 [bitmap] Fix bitmaps on 64-bit
Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-05-27 01:18:17 +01:00
Michael Brown 84996b7b09 [lacp] Add simple LACP implementation
Some switch configurations will refuse to enable our port unless we
can speak LACP to inform the switch that we are alive.  Add a very
simple passive LACP implementation that is sufficient to convince at
least Linux's bonding driver (when tested using qemu attached to a tap
device enslaved to a bond device configured as "mode=802.3ad").

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-05-10 16:34:17 +01:00
Piotr Jaroszyński 61206c245d [uri] Special case NULL in churi()
resolve_uri() doesn't (and probably shouldn't) handle NULL relative_uri.

Signed-off-by: Piotr Jaroszyński <p.jaroszynski@gmail.com>
Reviewed-by: Stefan Hajnoczi <stefanha@gmail.com>
Signed-off-by: Marty Connor <mdc@etherboot.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-04-25 17:25:30 +01:00
Piotr Jaroszyński 4cb0bfe291 [uri] Fix NULL dereference in parse_uri()
Don't try to parse authority if it's not there.

Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-04-25 17:21:49 +01:00
Michael Brown b7c548a944 [main] Match "starting execution" and "initialising devices" message style
Add a trailing "ok" to the "initialising devices message", to match
the visual style of the "ok" now added to the "starting execution"
message.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-04-25 01:50:46 +01:00
Michael Brown 8406115834 [build] Rename gPXE to iPXE
Access to the gpxe.org and etherboot.org domains and associated
resources has been revoked by the registrant of the domain.  Work
around this problem by renaming project from gPXE to iPXE, and
updating URLs to match.

Also update README, LOG and COPYRIGHTS to remove obsolete information.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
2010-04-19 23:43:39 +01:00
Stefan Hajnoczi 6a6f26f74d [fnrec] Add function recorder for debugging
The function recorder is a crash and hang debugging tool.  It logs each
function call into a memory buffer while gPXE runs.  After the machine
is reset, and if the contents of memory have not been overwritten, gPXE
will detect the memory buffer and print out its contents.

This allows developers to see a trace of the last functions called
before a crash or hang.  The util/fnrec.sh script can be used to convert
the function addresses back into symbol names.

To build with fnrec:

    make FNREC=1

Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
Signed-off-by: Marty Connor <mdc@etherboot.org>
2010-03-04 11:38:29 -05:00
Stefan Hajnoczi 00a780e38f [proto] Remove unsupported IGMP protocol
The IGMP code came from legacy Etherboot and was never updated to work
as a gPXE protocol.  There has been no demand for this protocol, so this
patch removes it.

Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
Signed-off-by: Marty Connor <mdc@etherboot.org>
2010-01-31 19:22:43 -05:00
Stefan Hajnoczi 1548189ffa [proto] Remove unsupported NFS protocol
The NFS protocol code came from legacy Etherboot and was never updated
to work as a gPXE protocol.  There has been no demand for this protocol,
so this patch removes it.

I have an unfinished NFSv3 over TCP implementation for gPXE that can be
used as the base for new work, should we want to resurrect this
protocol.

Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
Signed-off-by: Marty Connor <mdc@etherboot.org>
2010-01-31 19:21:00 -05:00
Joshua Oreman e6f08b0aa7 [uri] Handle an empty unparse_uri() result properly
Previously, if none of the URI parts requested existed in the passed
URI, unparse_uri() would not touch the destination buffer at all; this
could lead to use of uninitialized data. Fix by setting buf[0] = '\0'
before unparsing whenever we have room to do so.

Signed-off-by: Joshua Oreman <oremanj@rwcr.net>
Signed-off-by: Marty Connor <mdc@etherboot.org>
2010-01-27 08:50:49 -05:00
Joshua Oreman 3d9dd93a14 [uri] Decode/encode URIs when parsing/unparsing
Currently, handling of URI escapes is ad-hoc; escaped strings are
stored as-is in the URI structure, and it is up to the individual
protocol to unescape as necessary. This is error-prone and expensive
in terms of code size. Modify this behavior by unescaping in
parse_uri() and escaping in unparse_uri() those fields that typically
handle URI escapes (hostname, user, password, path, query, fragment),
and allowing unparse_uri() to accept a subset of fields to print so
it can be easily used to generate e.g. the escaped HTTP path?query
request.

Signed-off-by: Joshua Oreman <oremanj@rwcr.net>
Signed-off-by: Marty Connor <mdc@etherboot.org>
2010-01-20 18:14:28 -05:00
Joshua Oreman ef9d1a32c6 [settings] Add automagic "netX" settings block for last opened netdev
A script loaded via autoboot may want to get some of the settings (MAC
address, IP address, et cetera) for the interface via which it was
loaded, in order to pass them to the operating system. Previously such
a script had no way to determine what to put in the X of ${netX/foo}.

Solve this problem by transparently forwarding accesses to the real
settings associated with the most recently opened network device,
so scripts in this situation can say literally ${netX/foo} and get
the foo setting they want.

Signed-off-by: Marty Connor <mdc@etherboot.org>
2010-01-20 17:52:02 -05:00
sobtwmxt 71e77b8cc2 [uri] Fix outdated comment in parse_uri()
Signed-off-by: Marty Connor <mdc@etherboot.org>
2009-11-20 20:42:03 -05:00
Joshua Oreman 9a0bd0711f [linker] Add mechanism for subsystem-dependent configuration options
It is often the case that some module of gPXE is only relevant if the
subsystem it depends on is already being included. For instance,
commands to manage wireless interfaces are quite useless if no
compiled-in driver has pulled in the wireless networking stack. There
may be a user-modifiable configuration options for these dependent
modules, but even if enabled, they should not be included when they
would be useless.

Solve this by allowing the creation of config_subsystem.c, for
configuration directives like those in the global config.c that should
only be considered when subsystem.c is included in the final gPXE
build.

For consistency, move core/config.c to the config/ directory, where
the other config_subsystem.c files will eventually reside.

Signed-off-by: Marty Connor <mdc@etherboot.org>
2009-11-20 20:30:58 -05:00
Michael Brown c9c411286a [job] Report progress of downloader jobs via job_progress() 2009-08-31 19:33:55 +01:00
Michael Brown 0fc13add31 [job] Add missing job_progress() interface method 2009-08-31 19:33:05 +01:00
Michael Brown 0c30dc6bc5 [infiniband] Add support for SRP over Infiniband
SRP is the SCSI RDMA Protocol.  It allows for a method of SAN booting
whereby the target is responsible for reading and writing data using
Remote DMA directly to the initiator's memory.  The software initiator
merely sends and receives SCSI commands; it never has to touch the
actual data.
2009-08-10 22:27:33 +01:00
Michael Brown 04878ef745 [process] Make it safe to call process_add() multiple times 2009-08-10 19:27:24 +01:00
Michael Brown 51172783e2 [debug] Use a delimiter to break up DBG_HD() output
Reading sixteen columns of hex digits can be difficult; include a "-"
character to split the output into two groups of eight columns.
2009-07-17 22:58:44 +01:00
Michael Brown b7e93a6a55 [xfer] Always nullify interface while sending close() message
Objects typically call xfer_close() as part of their response to a
close() message.  If the initiating object has already nullified the
xfer interface then this isn't a problem, but it can lead to
unexpected behaviour when the initiating object is aiming to reuse the
connection and so does not nullify the interface.

Fix by always temporarily nullifying the interface during xfer_close()
(as was already being done by xfer_vreopen() in order to work around
this specific problem).

Reported-by: infernix <infernix@infernix.net>
Tested-by: infernix <infernix@infernix.net>
2009-07-06 16:16:59 +01:00
Michael Brown 546cc62394 [pxe] Add startpxe and stoppxe commands
These commands can be used to activate or deactivate the PXE API (on a
specifiable network interface).

This is currently of limited use, since most image formats will call
shutdown() before booting the image, meaning that the underlying net
device gets shut down during remove_devices() anyway.
2009-06-28 20:50:23 +01:00
Shao Miller 68973f1c49 [settings] Fix setting_cmp() to handle nameless settings
setting_cmp() compares by option tag and then by name.  Empty names
will always match, which gives us a false positive.

Fix by explicitly checking for empty names.

Modified-by: Michael Brown <mcb30@etherboot.org>
Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-06-13 12:04:08 +01:00
Michael Brown 4c5f00f879 [script] Allow for DOS-style line endings in scripts
Windows text editors such as Notepad tend to use CRLF line endings,
which breaks gPXE's signature detection for script images.  Since
scripts are usually very small, they end up falling back to being
detected as valid PXE executable images (since there are no signature
checks for PXE executables).  Executing text files as x86 machine code
tends not to work well.

Fix by allowing for any isspace() character to terminate the "#!gpxe"
signature, and by ensuring that CR characters get stripped during
command line parsing.

Suggested-by: Shao Miller <Shao.Miller@yrdsb.edu.on.ca>
2009-06-03 10:13:29 +01:00
Michael Brown 3c06277bbb [settings] Allow for arbitrarily-named settings
This provides a mechanism for using arbitrarily-named variables within
gPXE, using the existing syntax for settings.
2009-05-26 11:05:58 +01:00
Michael Brown c5a88ed553 [settings] Fix erroneous bit-masking in fetch_uintz_setting() 2009-05-20 08:55:48 +01:00
Michael Brown c44a193d0d [legal] Add a selection of FILE_LICENCE declarations
Add FILE_LICENCE declarations to almost all files that make up the
various standard builds of gPXE.
2009-05-18 08:33:25 +01:00
Stefan Hajnoczi 38a1d0fe3f [gdb] Allow resynchronisation with gdb
This replaces the gdbstub's polite NAK behavior with retransmission of
the current outstanding reply packet.  It solves situations where gdb
and gPXE's gdbstub get out of sync due to the lack of flow control in
the gdb protocol spec.

Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-04-15 17:18:14 +01:00
Michael Brown edea441ad5 [resolv] Simplify xfer_redirect() logic
Now that we have xfer_vreopen() as the default .vredirect handler,
sending redirection events can become simpler.
2009-03-30 15:23:57 +01:00
Michael Brown 323cdf8c4c [xfer] Implement xfer_vreopen() to properly handle redirections
When handling a redirection event, we need to close the existing
connection before opening the new connection.
2009-03-30 13:24:56 +01:00
Daniel Verkamp a323a85d9b [digest] md5sum and sha1sum commands
Modified-by: Michael Brown <mcb30@etherboot.org>
Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-03-27 04:29:54 +00:00
Michael Brown 5bd32315d0 [settings] Fix broken assertion in fetch_string_setting_copy()
Reported-by: Stefan Hajnoczi <stefanha@gmail.com>
2009-03-26 09:50:52 +00:00
Michael Brown 3c68ff99ea [tables] Incorporate table data type information into table definition
Eliminate the potential for mismatches between table names and the
table entry data type by incorporating the data type into the
definition of the table, rather than specifying it explicitly in each
table accessor method.
2009-03-13 02:10:21 +00:00
Michael Brown 1266d7902b [tables] Redefine methods for accessing linker tables
Intel's C compiler (icc) chokes on the zero-length arrays that we
currently use as part of the mechanism for accessing linker table
entries.  Abstract away the zero-length arrays, to make a port to icc
easier.

Introduce macros such as for_each_table_entry() to simplify the common
case of iterating over all entries in a linker table.

Represent table names as #defined string constants rather than
unquoted literals; this avoids visual confusion between table names
and C variable or type names, and also allows us to force a
compilation error in the event of incorrect table names.
2009-03-13 02:06:30 +00:00
Daniel Verkamp 4397a2a4ca [time] Add the time command
Signed-off-by: Michael Brown <mcb30@etherboot.org>
2009-03-06 15:02:41 +00:00
Michael Brown ec24672db7 [settings] Allow for autovivification of settings blocks
Allow for settings blocks to be created on demand.  This allows for
constructions such as

  set defaults/filename http://bootserver/bootfile
  set defaults/priority 0xff
  dhcp net0
  chain ${filename}

which will boot from the DHCP-provided filename, or from
"http://bootserver/bootfile" if the DHCP server does not provide a
filename.

(Note that "priority" gets interpreted as a signed integer, so setting
"defaults/priority" to 0xff will cause the "defaults" settings block
to have an effective priority of -1.)
2009-03-06 14:40:44 +00:00
Michael Brown 4f3bab1a55 [image] Allow for zero embedded images
Having a default script containing

  #!gpxe
  autoboot

can cause problems when entering commands to load and start a kernel
manually; the default script image will still be present when the
kernel is started and so will be treated as an initrd.  It is possible
to work around this by typing "imgfree" before any other commands, but
this is counter-intuitive.

Fix by allowing the embedded image list to be empty (in which case we
just call autoboot()), and making this the default.

Reported by alkisg@gmail.com.
2009-02-24 05:57:56 +00:00
Michael Brown 6de4db5da0 [login] Add "login" command and UI 2009-02-17 12:02:16 +00:00
Michael Brown bea828b9ed [settings] Allow store_setting() to access the root settings block 2009-02-17 11:57:31 +00:00
Michael Brown 14eafc5b8d [comboot] Fix reference counting on replacement images
When chaining COMBOOT images, the old images now get freed correctly.
2009-02-17 01:45:12 +00:00
Michael Brown 8904cd55f1 [comboot] Allow for tail recursion of COMBOOT images
Multi-level menus via COMBOOT rely on the COMBOOT program being able
to exit and invoke a new COMBOOT program (the next menu).  This works,
but rapidly (within about five iterations) runs out of space in gPXE's
internal stack, since each new image is executed in a new function
context.

Fix by allowing tail recursion between images; an image can now
specify a replacement image for itself, and image_exec() will perform
the necessary tail recursion.
2009-02-17 00:47:35 +00:00
Michael Brown 349868b8fd [uri] Allow use of relative URIs when calling churi() 2009-02-16 04:56:55 +00:00
Michael Brown 076154a1c6 [image] Allow multiple embedded images
This patch extends the embedded image feature to allow multiple
embedded images instead of just one.

gPXE now always boots the first embedded image on startup instead of
doing the hardcoded DHCP boot (aka autoboot).

Based heavily upon a patch by Stefan Hajnoczi <stefanha@gmail.com>.
2009-02-16 00:30:36 +00:00
Michael Brown 8ae1cac050 [xfer] Make consistent assumptions that xfer metadata can never be NULL
The documentation in xfer.h and xfer.c does not say that the metadata
parameter is optional in calls such as xfer_deliver_iob_meta() and the
deliver_iob() method.  However, some code in net/ is prepared to
accept a NULL pointer, and xfer_deliver_as_iob() passes a NULL pointer
directly to the deliver_iob() method.

Fix this mess of conflicting assumptions by making everything assume
that the metadata parameter is mandatory, and fixing
xfer_deliver_as_iob() to pass in a dummy metadata structure (as is
already done in xfer_deliver_iob()).
2009-02-15 08:44:22 +00:00
Michael Brown d900ae05d7 [base64] Add base64 encoding functions 2009-02-13 14:54:13 +00:00
Michael Brown 4e6b62c946 [settings] Handle errors in fetchf_uristring()
fetchf_uristring() was failing to handle error values from
fetch_setting(), resulting in its attempting to allocate extremely
large temporary buffers on the stack (and so overrunning the stack and
locking up the machine).

Problem reported by Shao Miller <Shao.Miller@yrdsb.edu.on.ca>.
2009-02-12 09:16:53 +00:00
Michael Brown d2b0081740 [settings] Avoid duplicate settings block names
Automatically unregister any settings with the same name (and position
within the settings tree) as a newly registered settings block.

This functionality is generalised out from dhcp.c.
2009-01-31 07:32:20 +00:00
Michael Brown a128973ecb [settings] Add fetch_string_setting_copy() 2009-01-27 19:13:47 +00:00
Michael Brown ce9690ca39 [console] Allow KEY_xxx constants to cover F8 function key
F8 is represented by the ANSI escape sequence "^[[19~", which is not
representable as a KEY_xxx constant using the current encoding scheme.
Adapt the encoding scheme to allow F8 to be represented, since PXE
requires that we may need to prompt the user to press F8.
2009-01-25 21:10:48 +00:00
Michael Brown 3e220aa73e [main] Print an "initialising devices" banner
Some devices take a very long time to initialise.  This can make it
difficult to visually distinguish between the error cases of failing
to start executing C code and failing to initialise a device.

Add a "gPXE initialising devices..." message.  The trailing ellipsis
indicates to the user that this may take some time, and the presence
of the message indicates to the developer that relocation etc. all
succeeded.
2009-01-08 03:48:30 +00:00
Michael Brown d9b3d09910 [i386] Move iSCSI and AoE boot code to arch/i386/interface/pcbios 2008-11-19 19:20:45 +00:00
Michael Brown b59e0cc56e [i386] Change [u]int32_t to [unsigned] int, rather than [unsigned] long
This brings us in to line with Linux definitions, and also simplifies
adding x86_64 support since both platforms have 2-byte shorts, 4-byte
ints and 8-byte long longs.
2008-11-19 19:15:44 +00:00
Michael Brown dc60c24146 [i386] Rename __cdecl to __asmcall
__cdecl is a misleading name, since it currently encapsulates both
cdecl and regparm(0) attributes.  Rename to __asmcall.
2008-11-19 19:12:53 +00:00
Michael Brown ed196a3ed2 [settings] Ensure fetch_string_setting() returns a NUL-terminated string
This fixes a regression introduced in commit 612f4e7:

  [settings] Avoid returning uninitialised data on error in fetch_xxx_setting()

in which the memset() was moved from fetch_string_setting() to
fetch_setting(), in order that it would be useful for non-string
setting types.  However, this neglects to take into account the fact
that fetch_string_setting() shrinks its buffer by one byte (to allow
for the NUL) before calling fetch_setting().

Restore the memset() in fetch_string_setting(), so that the
terminating NUL is guaranteed to actually be a NUL.
2008-11-07 03:48:29 +00:00
Michael Brown 5e6b82104d [romprefix] Add vendor branding facilities and guidelines
Some hardware vendors have been known to remove all gPXE-related
branding from ROMs that they build.  While this is not prohibited by
the GPL, it is a little impolite.

Add a facility for adding branding messages via two #defines
(PRODUCT_NAME and PRODUCT_SHORT_NAME) in config/general.h.  This
should accommodate all known OEM-mandated branding requirements.
Vendors with branding requirements that cannot be satisfied by using
PRODUCT_NAME and/or PRODUCT_SHORT_NAME should contact us so that we
can extended this facility as necessary.
2008-10-31 19:10:28 +00:00
Michael Brown 0a6c66a830 [settings] Add the notion of a "tag magic" to numbered settings
Settings can be constructed using a dotted-decimal notation, to allow
for access to unnamed settings.  The default interpretation is as a
DHCP option number (with encapsulated options represented as
"<encapsulating option>.<encapsulated option>".

In several contexts (e.g. SMBIOS, Phantom CLP), it is useful to
interpret the dotted-decimal notation as referring to non-DHCP
options.  In this case, it becomes necessary for these contexts to
ignore standard DHCP options, otherwise we end up trying to, for
example, retrieve the boot filename from SMBIOS.

Allow settings blocks to specify a "tag magic".  When dotted-decimal
notation is used to construct a setting, the tag magic value of the
originating settings block will be ORed in to the tag number.
Store/fetch methods can then check for the magic number before
interpreting arbitrarily-numbered settings.
2008-10-30 21:47:14 +00:00
Michael Brown 3fe6bede74 [uri] Avoid interpreting DOS-style path names as opaque URIs
A DOS-style full path name such as "C:\Program Files\tftpboot\nbp.0"
satisfies the syntax requirements for a URI with a scheme of "C" and
an opaque portion of "\Program Files\tftpboot\nbp.0".

Add a check in parse_uri() to ignore schemes that are apparently only
a single character long; this avoids interpreting DOS-style paths in
this way, and shouldn't affect any practical URI scheme.
2008-10-24 04:08:43 +01:00
Michael Brown 612f4e7a99 [settings] Avoid returning uninitialised data on error in fetch_xxx_setting()
Callers (e.g. usr/autoboot.c) may not check the return values from
fetch_xxx_setting(), assuming that in error cases the returned setting
value will be "empty" (for some sensible value of "empty").

In particular, if the DHCP server did not specify a next-server
address, this would result in gPXE using uninitialised data for the
TFTP server IP address.
2008-10-22 22:07:13 +01:00
Michael Brown 81d92c6d34 [efi] Add EFI image format and basic runtime environment
We have EFI APIs for CPU I/O, PCI I/O, timers, console I/O, user
access and user memory allocation.

EFI executables are created using the vanilla GNU toolchain, with the
EXE header handcrafted in assembly and relocations generated by a
custom efilink utility.
2008-10-13 10:24:14 +01:00
Michael Brown 54c024e0af [sanboot] Quick and dirty hack to make SAN boot protocols selectable 2008-10-13 10:05:51 +01:00
Michael Brown 07e8f18f33 [monojob] Release reference on completed job
monojob_wait() was holding a reference to the completed job, meaning that
various objects would not be freed until the next job was plugged in to
the monojob interface.
2008-10-13 05:34:08 +01:00
Michael Brown 667819becc [timer] Remove now-obsolete references to TIMER_BIOS and TIMER_RDTSC 2008-10-13 00:23:18 +01:00
Michael Brown c0835339d0 [nap] Formalise the CPU sleeping API 2008-10-12 23:36:53 +01:00
Michael Brown 658c6dba59 [monojob] Allow for extremely slow system timers
The EFI timer runs at one tick per second, so using ">" rather than ">="
results in a two-second gap between dots.
2008-10-12 21:30:37 +01:00
Michael Brown 16f1e35775 [timer] Formalise the timer API
We now have two implementations for the timer API: one using the
time-of-day counter at 40:70 and one using RDTSC.  Both make use of
timer2_udelay().
2008-10-12 20:22:02 +01:00
Michael Brown e6f276ece3 [process] Add DBG2() messages to help track down frozen processes 2008-10-12 15:11:29 +01:00
Michael Brown 8c7deba349 [config] Split console configuration out to config/console.h 2008-10-12 02:30:31 +01:00
Michael Brown ee2df1d6d6 [ioapi] Remove old io.h file and switch all users over to <gpxe/io.h> 2008-10-12 01:06:27 +01:00
Michael Brown 6936c40fef [settings] Allow for setting fetchers to fail in fetchf_hex() 2008-09-26 03:39:35 +01:00
Michael Brown 35b7658877 [settings] Add the uristring setting type
This allows settings to be expanded in a way that is safe to include
within a URI string, such as

  kernel http://10.0.0.1/boot.php?mf=${manufacturer:uristring}

where the ${manufacturer} setting may contain characters that are not
permitted (or have reserved purposes) within a URI.

Since whitespace characters will be URI-encoded (e.g. "%20" for a
space character), this also works around the problem that spaces
within an expanded setting would cause the shell to split command-line
arguments incorrectly.
2008-09-24 07:22:42 +01:00
Michael Brown b350b10b35 [uri] Add uri_encode() and uri_decode() functions for URI character encoding 2008-09-24 07:21:47 +01:00
Daniel Verkamp e8b22f203f [comboot] Add COMBOOT and COM32 support 2008-08-28 23:52:19 +01:00
Michael Brown 8f8f5acf09 [settings] Avoid overwriting the start of .text in fetch_string_setting()
fetch_string_setting() was subtracting one from the length of the
to-be-NUL-terminated buffer in order to obtain the length of the
unterminated buffer to be passed to fetch_setting().  This works
extremely well unless the length of the to-be-NUL-terminated buffer is
zero, at which point we end up giving fetch_setting() a buffer of
length -1UL, thereby inviting it to overwrite as much memory as it
wants...
2008-08-14 03:03:53 +01:00
Michael Brown 5d4839b577 [iSCSI] Add support for mutual CHAP
Allow initiator to verify target authentication using CHAP.
2008-08-11 03:43:12 +01:00
Michael Brown 34a06b6ba7 [cmdline] Add setting expansion using ${...} syntax
Allow settings to be expanded in arbitrary commands, such as

  kernel http://10.0.0.1/boot.php?uuid=${uuid}

Also add the "echo" command, as being the easiest way to test this
features.
2008-07-27 01:08:20 +01:00