summaryrefslogtreecommitdiffstats
path: root/discover/grub2/script.c
Commit message (Collapse)AuthorAgeFilesLines
* discover/grub2: Allow unset and invalid defaultsJeremy Kerr2014-12-111-1/+34
| | | | | | | | | | | | | | If the default environment variable is unset or invalid (i.e., references a non-existent boot option), then GRUB2 will fallback to the first boot option present. This is preventing petitboot from autobooting where no default is explicitly set, or is stale. This change adds this fallback behaviour to petitboot. Because we don't know if the first option will be a default at parse time (as no other options matched the default env var), we need to keep options in a list, and register them with the discover server once the parse is complete. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Fix uninitialised var warningsJeremy Kerr2014-04-161-1/+1
| | | | | | | | | | | | | | We get a couple of uninitialised var warning when compiling with certain CFLAGS (-fprofile-arcs -ftest-coverage at this stage). In statement_if_execute: We'll never actually use this uninitialised (as there must be at least one conditional in the parsed statement), but we should address the warning nonetheless. As passed to strtok_r: strtok will initialise this, but it isn't obvious to the compiler. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Add support for for-loopsJeremy Kerr2014-01-301-0/+23
| | | | | | | | | GRUB2 syntax allows for for-loops; this change adds supoprt in the parser grammar and script execution code to implement them. In the execution code, we simply update the for-loop variable and re-execute the body statements. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Perform word-expansion non-destructivelyJeremy Kerr2014-01-301-99/+83
| | | | | | | | | | | | | | | In order to implement for-loops, we may need to evaluate the same chunk of script more than once, and perform that evaluation in a different context (particularly, with different environment variables). Currently, the process_expansion code destroys the result of the parse-tree (ie, the token list) when performing expansions. This means that we can only perform the expansions once. This change preserves the token list while creating the argv array. This means that we can expand the list multiple times. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: skip menuentries that don't define a boot optionJeremy Kerr2014-01-301-0/+3
| | | | | | | | | | menuentries may perform arbitrary commands; we only want ones that define a boot option. This change doesn't add a boot option if we haven't seen at least a boot image defined in the menuentry. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub: Add feature variable for --id support.Jeremy Kerr2014-01-301-0/+3
| | | | | | | Since we support --id arguments on menuentries, add the corresponding feature variable. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Use script_env_set when initialising the environmentJeremy Kerr2014-01-301-6/+2
| | | | | | | | | | No need to duplicate the environment-adding code in init_env, as we can just use script_env_set. Since script_env_set does its own talloc, we don't need to talloc our strings here either. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub: Use --id values for default option detectionBen Stoltz2014-01-171-7/+24
| | | | | | | | Fix Petitboot's grub.cfg parser to handle --id=label argument to menuentry, and use it (in preference to the option name) when looking for a default option. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Populate $prefix from config file locationJeremy Kerr2013-11-271-2/+16
| | | | | | | Rather than always using the default prefix, we should determine it from the location of the grub2 config file. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Fix potentially-uninitialised variablesJeremy Kerr2013-11-131-1/+1
| | | | | | | We've been compiling with --enable-debug; this change fixes some problems exposed by the optimiser. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: strdup strings used in the environmentJeremy Kerr2013-10-011-4/+6
| | | | | | | Use a copy of the name & value pairs that we pass to the environment, as the data loaded from load_env will be talloc_free-ed. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Add default prefixJeremy Kerr2013-10-011-1/+3
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Clean up error-handling for grub2 parser & lexerJeremy Kerr2013-09-261-1/+2
| | | | | | | Rather than printf() & exit(), use the pb logging functions and abort the parse. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Reimplement default optionsJeremy Kerr2013-09-251-2/+23
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Support var=value assignmentsJeremy Kerr2013-09-241-0/+12
| | | | | | We want to allow assignments outside of the 'set' builtin. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Implement statement_block_executeJeremy Kerr2013-09-241-0/+9
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: unknown commands should failJeremy Kerr2013-09-241-1/+1
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Populate option idsJeremy Kerr2013-09-241-0/+3
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Implement 'elif'Jeremy Kerr2013-09-241-4/+6
| | | | | | | Rather than just having one conditional in an if statement, we use a list of conditionals instead. This allows us to implement elif. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Create 'conditional' statementsJeremy Kerr2013-09-241-10/+24
| | | | | | | | Rather than holding the condition and conditional-statements in struct grub2_statment_if, create a new conditional type that contains these. We can then use this to implement elif statements. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Add function supportJeremy Kerr2013-09-241-0/+33
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Function infrastructure improvementsJeremy Kerr2013-09-241-21/+35
| | | | | | | | For user-defined functions, we'll need a data pointer to the function's execution callback. Add this as a void *, and change references from 'command' to 'function'. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Add option state in menuentry processingJeremy Kerr2013-09-241-0/+16
| | | | | | | This will allow menuentry-specific commands to populate boot option data. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Add a reference to the context from grub2_scriptJeremy Kerr2013-09-241-2/+5
| | | | | | We'll need the context to add boot options. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Hook up flex/bison parser to discover serverJeremy Kerr2013-09-241-1/+1
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Implement multiple-arv variable splittingJeremy Kerr2013-09-241-10/+95
| | | | | | | If we expand a variable containing word-delimiter chars, we need to create new argv items. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Add initial command executionJeremy Kerr2013-09-241-5/+71
| | | | | | .. with a simple 'set' command to update the environment Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Add menuentry executionJeremy Kerr2013-09-241-0/+13
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Handle var tokens in lexerJeremy Kerr2013-09-241-55/+25
| | | | | | | Rather than post-processing to expand variables, use the lexer to identify variable tokens as a type of grub2_word. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Remove debug printfsJeremy Kerr2013-09-241-5/+0
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Initial environment handlingJeremy Kerr2013-09-241-9/+26
| | | | | | A simple linked-list implementation of string pairs. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Add initial execution codeJeremy Kerr2013-09-241-2/+63
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Add var expansion codeJeremy Kerr2013-09-241-0/+96
| | | | | | Still todo: splitting. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Add initial script infrastructureJeremy Kerr2013-09-241-0/+12
Now that we can parse scripts, we want some infrastructure for execution. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
OpenPOWER on IntegriCloud