summaryrefslogtreecommitdiffstats
path: root/discover/grub2/script.c
Commit message (Collapse)AuthorAgeFilesLines
* discover/grub2: make statements_execute non-staticJeremy Kerr2019-11-291-1/+1
| | | | | | | We want to execute newly-parsed statements, so expose statements_execute() to the rest of the grub2 parser code. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Add a reference from script to parserJeremy Kerr2019-11-291-0/+1
| | | | | | | Future commands will need to access the parser, so add a reference from struct grub2_script. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Allow to separate the --id argument using a space charJavier Martinez Canillas2019-06-211-3/+10
| | | | | | | | | | | | The GRUB menuentry command allows to separate the arguments for options using either a '=' or a ' '. The latter is the convention used when the menu entries are defined in the GRUB config file, but this is currently not supported by Petitboot. Add tests to cover both using '--id=foo' and '--id foo' as options. Signed-off-by: Javier Martinez Canillas <javierm@redhat.com> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* discover/grub2: Allow using title for default even if id was definedJavier Martinez Canillas2019-06-211-5/+3
| | | | | | | | | | | | | | | A default menu entry can be chosen using any of the following attributes: index, title or id (if the entry was defined with the --id option). But Petitboot doesn't honor this correctly and only compares the default with the menu entry title if the entry doesn't have an id defined. This is wrong since an index or title can be used even if an id was defined. This issue wasn't covered by the test that sets a default using a title because the menu entries didn't have an id defined. Add an id to them. Signed-off-by: Javier Martinez Canillas <javierm@redhat.com> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* Various fixups and checks to make scan-build happySamuel Mendoza-Jonas2019-05-301-1/+4
| | | | Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* discover/grub: Add blscfg command support to parse BootLoaderSpec filesJavier Martinez Canillas2018-03-231-1/+1
| | | | | | | | | | | | | | | | | The BootLoaderSpec (BLS) defines a file format for boot configurations, so bootloaders can parse these files and create their boot menu entries by using the information provided by them [0]. This allow to configure the boot items as drop-in files in a directory instead of having to parse and modify a bootloader configuration file. The GRUB 2 bootloader provides a blscfg command that parses these files and creates menu entries using this information. Add support for it. [0]: https://www.freedesktop.org/wiki/Specifications/BootLoaderSpec/ Signed-off-by: Javier Martinez Canillas <javierm@redhat.com> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* discover/grub2: Do not set $0 in functionsAlan Dunn2016-04-261-1/+1
| | | | | | | | | | | | | | | GRUB2 does not set $0 in functions, so don't set it in our GRUB2 script parser. (As it doesn't have a value in GRUB2 scripts, probably no GRUB2 script depends on the value of $0.) Additionally, dash and bash set environment variable 0 to the name of the script (even in functions), so the current behavior of $0 doesn't really match shell scripts either. Tested: Existing tests pass. Signed-off-by: Alan Dunn <amdunn@google.com> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* discover/grub2: Fix handling of positional parametersAlan Dunn2016-03-151-1/+1
| | | | | | | | | | | | | | Positional parameters are set in the environment with '$' prepended to the name. This causes lookups to fail because parameter lookups don't include the '$'. TESTED: Added a test that covers positional parameters in GRUB2 parser. Build succeeds, tests pass. Bootstrapped-by: Nancy Yuen <yuenn@google.com> Signed-off-by: Alan Dunn <amdunn@google.com> Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
* 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