summaryrefslogtreecommitdiffstats
path: root/discover/grub2
Commit message (Collapse)AuthorAgeFilesLines
* discover/grub2: implement 'source' commandJeremy Kerr2019-11-292-1/+51
| | | | | | | | | | This change add support for the grub2 'source' command, executing a referenced script in the current parse context. We impose a limit of 10 (concurrent) source commands, to prevent infinite recursion. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: make statements_execute non-staticJeremy Kerr2019-11-292-1/+4
| | | | | | | 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: expose internal parse functionJeremy Kerr2019-11-293-5/+22
| | | | | | | | | Upcoming changes will need a method to parse a secondary file (to support the 'source' command), but not execute it as a new script. This change exposes the parsing code, separate from the execution code. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Add a reference from script to parserJeremy Kerr2019-11-292-0/+2
| | | | | | | 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 (device)/path references in general script usageJeremy Kerr2019-11-293-9/+47
| | | | | | | | | | | Currently, we have support for grub2 (device)/path syntax for boot resources. This change allows this syntax for general paths in grub2 scripts (for example, -f tests). This involves exposing grub2_lookup_device, to allow the script execution code to resolve pathnames. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: add support for grub2-style path specifiers in resourcesJeremy Kerr2019-11-294-37/+58
| | | | | | | | | | | | This change incorporates the grub2-style (device)/path specifiers in the grub2 parser's resource code. This allows the boot option paths to use device-specific references. Device names are looked-up using the UUID and kernel IDs, but with the lookup logic specific to a new function (grub2_lookup_device), so that can be extended in a future change. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Add parsing code for grub2 file specifiersJeremy Kerr2019-11-292-0/+42
| | | | | | | This change adds a (currently unused) function to parse (device)/path references from grub scripts. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: expose a struct for grub2 file referencesJeremy Kerr2019-11-292-15/+17
| | | | | | | | | | | | | | | | Currently, we have struct grub2_resource_info to keep references to boot payloads that may be returned in boot options, and be (conditionally) resolved by the parser. We'd also like to use the same semantics for other file references in the grub2 parser, for arbitrary usage in scripts - where files are also referenced by a path and an optional device. To do this, this change moves struct grub2_resource_info to grub2.h, and renames to struct grub2_file. Future changes will use this for script-internal file handling. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Add support for UUID and label for 'search' commandJeremy Kerr2019-11-291-3/+52
| | | | | | | | This change adds support for searching by UUID and filesystem label. We still fall back to passthrough if the UUID is not found, but we now resolve to device ID strings. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Use getopt for `search` argument parsingJeremy Kerr2019-11-291-5/+28
| | | | | | | | | | | | The search command will be extended to add the full set of grub2-style arguments, so switch to using getopt, rather than manual parsing. This means we now support `--set=foo` and `--set foo` style arguments, both of which appear in the docs and common grub configs. Also, add a small test for the search argument handling. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: 'search' set-variable defaults to rootJeremy Kerr2019-11-291-2/+2
| | | | | | | If no --set= argument is specified, default to the variable named 'root', as per current grub docs. 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-302-1/+6
| | | | Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* discover/grub2: Add support for initrd16 builtinShawn Anastasio2018-11-221-0/+4
| | | | | | | | | This commit adds support for the initrd16 builtin which compliments the existing linux16 support and improves usability on x86 platforms. Signed-off-by: Shawn Anastasio <shawn@anastas.io> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* discover/grub: Improve BLS grub environment variables expansionJavier Martinez Canillas2018-06-181-16/+69
| | | | | | | | | | | | | | | | | | | | | | | | | | The fields from a BootLoaderSpec file can contain environment variables, in GRUB 2 these are show verbatim and are evaluated later when an entry is selected. But on Petitboot these have to be expanded before creating the GRUB 2 resources and show in the UI the values after the evaluation. The current blscfg handler had a very limited support for variables, it only had support for the options field and also didn't take into account that variables could be mixed with literal values. So for example the following fields were not expanded correctly: linux $bootprefix/vmlinuz options $kernelopts foo=bar options foo=bar $kernelopts options $kernelopts $debugopts Also change some of the tests to cover mixing variables and literals. Signed-off-by: Javier Martinez Canillas <javierm@redhat.com> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* discover/grub: Use different paths to search for the BLS directoryJavier Martinez Canillas2018-06-181-3/+19
| | | | | | | | | | | | | | | | Currenlty the BLS fragments are only searched in the /loader/entries directory, but this assumes that there is a boot partition mounted in /boot. This may not always be the case, /boot may not be a mount point and just a directory inside the root partition. To cover this case, Petitboot tries to find a GRUB 2 config file in different paths. So let's do the same for the BLS files directory. Also change some of the unit tests to use /boot/loader/entries as a BLS directory instead of /loader/entries. Signed-off-by: Javier Martinez Canillas <javierm@redhat.com> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* discover/grub: Add cmdline signature support for BLS entriesBrett Grandbois2018-05-041-0/+6
| | | | | | | Follow along the way the linux builtin does it. Signed-off-by: Brett Grandbois <brett.grandbois@opengear.com> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* discover/grub: Allow to set a default index for BLS entriesJavier Martinez Canillas2018-04-181-4/+13
| | | | | | | | | | | | When the BLS support was added, the conclusion was that default indexes didn't apply for BLS snippets. But for GRUB 2 the indexes refers to the boot menu entries in memory, regardless of how these were generated. Since in GRUB 2 is valid to set a default index even for menu entries generated from BLS fragments, allow this to also be done in Petitboot. Signed-off-by: Javier Martinez Canillas <javierm@redhat.com> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* discover/grub: Don't add discover context boot options in blscfg handlerJavier Martinez Canillas2018-04-181-1/+2
| | | | | | | | | Instead of adding a boot option explicitly, just add it to the grub script boot option list and increment the number of options. That way BLS entries will be known by the grub script handler and can check if is a valid index. Signed-off-by: Javier Martinez Canillas <javierm@redhat.com> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* discover/grub: Reverse BLS entries sorting to match Petitboot's boot orderJavier Martinez Canillas2018-04-181-1/+1
| | | | | | | | | | | | The BLS entries were sorted so that the latest entry was at the top in the Petitboot UI, since it matches how menu entries are sorted in GRUB2 config and the GRUB2 UI. But in the Petitboot's UI, the latest entry is expected to be at the bottom and the older one at the top. Sort the BLS entries to match what's expected. Signed-off-by: Javier Martinez Canillas <javierm@redhat.com> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* discover/grub: Allow to choose a different BLS directoryJavier Martinez Canillas2018-03-291-2/+7
| | | | | | | | | | The default path to search for BootLoaderSpec configuration files is /loader/entries but in some setups a different directory may be used. So allow this to be chosen by using a blsdir GRUB environment variable. Signed-off-by: Javier Martinez Canillas <javierm@redhat.com> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* discover/grub: Add blscfg command support to parse BootLoaderSpec filesJavier Martinez Canillas2018-03-234-2/+251
| | | | | | | | | | | | | | | | | 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>
* grub2/grub2: add Yocto paths to default grub2 conf search pathsBrett Grandbois2018-02-081-0/+2
| | | | | Signed-off-by: Brett Grandbois <brett.grandbois@opengear.com> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* grub2/grub2-parser: accept no whitespace in grub menuentryBrett Grandbois2018-02-081-1/+1
| | | | | | | | | | The Yocto wic grub support will generate a grub.cfg with no whitespace between the ending quote of the menuentry label and the opening bracket. There doesn't seem to be anything in the specification that this is illegal so accept it here. Signed-off-by: Brett Grandbois <brett.grandbois@opengear.com> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* discover/status: Add parse status for GRUB2, yaboot & kboot parsersJeremy Kerr2016-12-201-0/+4
| | | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* Add support for GPG signature enforcement on bootedtpearson@raptorengineering.com2016-08-261-0/+8
| | | | | | | | | | | | | kernels and related blobs This can be used to implement a form of organization-controlled secure boot, whereby kernels may be loaded from a variety of sources but they will only boot if a valid signature file is found for each component, and only if the signature is listed in the /etc/pb-lockdown file. Signed-off-by: Timothy Pearson <tpearson@raptorengineering.com> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com> (Minor build fixes and gpgme.m4, comment on secure boot in gpg.c)
* 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>
* Allow evaluation of arbitrarily-positioned arguments in GRUB2 parserAlan Dunn2016-04-261-1/+2
| | | | | | | | | | | | | | | GRUB2 allows essentially arbitrary numbers of positional arguments, so ensure that they can be evaluated within scripts. GRUB2 also appears to support arbitrary numbers of leading 0's in positional parameters (i.e., $01 should evalute the same as $1), but this doesn't seem like a particularly important case to support. Tested: Modified test-grub2-pos-param to cover higher-numbered positional arguments. Signed-off-by: Alan Dunn <amdunn@google.com> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* discover/grub2: Ignore sign-compare warning for generated codeSamuel Mendoza-Jonas2016-04-011-1/+1
| | | | 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>
* Change parser interface to allow statAlan Dunn2016-03-151-9/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, the GRUB2 parser incorrectly reports "[ -f <path> ]" as false if the size of the file is above 1 MB. This patch changes the parser interface to allow stating files (with parser_stat_file). Then in the implementation of "[ -f <path> ]", we can use parser_stat_file instead of parser_request_file which has the size limitation. I eliminate parser_check_dir in lieu of this new interface, which has the side effect of making "[ -d <path> ]" work (the error code for stat was not checked correctly before). I add a basic test for the test file operations -f, -s, and -d (to show that my changes to test file operations do not break them) and minorly modify the test framework to ensure it has enough fidelity to cause the expected results. Unfortunately the test wouldn't have caught the issue with -d, since the test framework stubs out the parser interface itself. Nor can the test framework catch the initial problem with -f because the imposed limit is (transitively) in function parser_request_file. Note that -f and -d follow symlinks despite the fact that GRUB does not (see http://lists.gnu.org/archive/html/grub-devel/2016-02/msg00142.html discussing GRUB's behavior). This is not a change to Petitboot's behavior though. Tested: The test test-grub2-test-file-ops passes. I booted Petitboot against a GRUB snippet: status=success if [ ! -f /large_file -a $status = success ] then status=fail_large_file fi if [ ! -d /a_directory -a $status = success ] then status=fail_dir fi menuentry $status { linux /vmlinux } (after making /large_file a file of size > 1 MiB and /a_directory a directory) and the menuentry had title "success", as desired. Signed-off-by: Alan Dunn <amdunn@google.com> Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
* In GRUB2 parser save_env, treat unset variable value as emptyAlan Dunn2016-03-151-0/+4
| | | | | | | | | | | | | | It seems better to treat unset variable values as empty rather than crashing in save_env. While GRUB's behavior is actually to delete the variable from the environment block, it seems useful to at least not crash while later on someone can do further work to improve GRUB compatibility if desired. Tested: Modified test-grub2-save-env to cover this case. Signed-off-by: Alan Dunn <amdunn@google.com> Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
* discover/grub: Fix handling of empty stringsSam Mendoza-Jonas2016-02-091-0/+7
| | | | | | | | | | | If "" or '' are used in a statement to omit a word, we must still return a TOKEN_WORD for an empty string. In particular this fixes an issue where Petitboot would fail to parse the grub.cfg included in the Debian 8.2 install image, which includes a menuentry statement with an empty name. Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
* discover/grub2: Fix behavior of save_env -fAlan Dunn2016-02-081-3/+14
| | | | | | | | | | | | | | | Currently, "save_env -f" in the GRUB2 parser only works with three arguments, which means only commands of the form "save_env -f <path>" that save *no* environment variables are allowed. Allow "save_env -f <path> [<var>]*", making "save_env -f" useful. Tested: Unit test test-grub2-save-env-dash-f tests this change, and the remaining unit tests still pass. Signed-off-by: Alan Dunn <amdunn@google.com> Signed-off-by: Sam Mendoza-Jonas <sam@mendozajonas.com>
* discover: Initialise strtok_r saveptr to NULLSamuel Mendoza-Jonas2015-04-141-1/+1
| | | | | Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: Allow unset and invalid defaultsJeremy Kerr2014-12-112-1/+35
| | | | | | | | | | | | | | 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/grub2: improve handling of word & delimiter tokensJeremy Kerr2014-12-013-41/+57
| | | | | | | | | | | | | | | | | | | | | | | Currently, the delimiter token handling is a little fragile: we try to ignore non-inter-word delimiters in the lexer with a selective set of regexes on the possible delimiter characters. This means we don't need to handle potential delimiters in every grammar rule, but there are other situations (not regex-able) where we may see delimters, and this will cause a parse error. Instead of relying on the regex behaviour, we have an 'inter_word' flag, which is set when we see the first word token, and cleared when we see an end-of-line token. We only emit TOKEN_DELIM when this flag is set. This means that we only get the delim tokens when they're required - when we're looking for word separators (becuase WORD DELIM WORD is distinct from WORD WORD - eg "linux /vmlinux" and "x$var"). We add a few new tests for the "menuentry" and "if" syntax, with different delimiter configurations. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: fix incorrect prototype in yyerrorJeremy Kerr2014-12-012-5/+6
| | | | | | | Because we're using two parse-params, we need to add the scanner argument to yyerror. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* lib: Move generic file-handling code to lib/Jeremy Kerr2014-08-051-1/+1
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/grub2: distinguish parser.h from grub2/parser.hJeremy Kerr2014-08-053-18/+18
| | | | | | | | | | | | | 'make distcheck' will do a 'make all' srcdir == objdir, then later a 'make check' sith srcdir != objdir. Since gcc's cpp always assumes that a source file's directory is first in the include paths, we may see discover/parser.h included when we wanted the generated discover/grub2/parser.h. This change renames the grub2 lexer and parser files, to work-around this behaviour, and fix 'make distcheck'. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* automake: silence make outputJeremy Kerr2014-08-051-5/+2
| | | | | | | | | Currently, we get a lot of noise out of the build process; automake supports V={0,1}, which we can use to suppress the output a little. This needs a few cleanups for custom commands. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* autotools: Use non-recursive makeJeremy Kerr2014-08-012-28/+36
| | | | | | | | | | | | With the current testing infrastructure, we don't have a strictly hierarchical set of dependencies. This causes problems with a recursive make, and means we have to hack around some of the dependencies. This change generates a single, top-level makefile from all of the Makefile.am fragments. We still need the po/ directory as a separate SUBDIR, but all others can be converted to non-recursive. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* grub2: fix empty file handlingJeremy Kerr2014-06-051-0/+3
| | | | | | | | | | | Currently, we have a bug when parsing zero-length files: we subtract one from the length to exclude the trailing NUL (added by read_file), but a zero-length file will result in a length of -1. This change adds an explicit exit if we're attempting to parse an empty file. 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-303-0/+55
| | | | | | | | | 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: Add support for checking directories in parser APIJeremy Kerr2014-01-301-0/+14
| | | | | | | | | | | | | This change adds a function to the parser API: int parser_check_dir(struct discover_context *ctx, struct discover_device *dev, const char *dirname) - which allows parsers to check for the presence of a directory (path of 'dirname') on the device ('dev'). We use this in the GRUB2 parser to implement the `test -d` check. 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>
OpenPOWER on IntegriCloud