From fbabc04d040cdad57eda0a4bf597cccf56d4c530 Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Tue, 8 Sep 2015 10:12:09 +0200 Subject: [PATCH] Add "copy" keyword to novaboot script syntax --- README.pod | 6 ++++++ contrib/novaboot-mode.el | 8 ++++---- novaboot | 31 ++++++++++++++++++++++--------- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/README.pod b/README.pod index a309c5f..6b6a68c 100644 --- a/README.pod +++ b/README.pod @@ -703,6 +703,12 @@ that line. The SRCDIR variable in CMD's environment is set to the absolute path of the directory containing the interpreted novaboot script. +Lines starting with C keyword are similar to C lines. The +file mentioned there is copied to the same place as in case of C +(e.g. tftp server), but the file is not used in the bootloader +configuration. Such a file can be used by the target for other +purposed than booting, e.g. at OS runtime or for firmware update. + Lines starting with C keyword contain shell commands that are run during file generation phase. This is the same as the "< CMD" syntax for C keyboard except that the command's output is not diff --git a/contrib/novaboot-mode.el b/contrib/novaboot-mode.el index e3b5e40..e3e680f 100644 --- a/contrib/novaboot-mode.el +++ b/contrib/novaboot-mode.el @@ -1,6 +1,6 @@ ;;; novaboot-mode.el --- Major mode for novaboot scripts -;; Copyright (C) 2014 Michal Sojka +;; Copyright (C) 2014, 2015 Michal Sojka ;; Author: Michal Sojka ;; Keywords: languages, tools, files @@ -41,14 +41,14 @@ (defvar novaboot-mode-font-lock-keywords) (setq novaboot-mode-font-lock-keywords `(("^#.*" . font-lock-comment-face) - ("^load\\>.*\\(<.*\\(<.*?< \\(.*\\)" + ("^\\(?:load\\|copy\\)\\>.*?< \\(.*\\)" (1 font-lock-string-face)) ("^\\(run\\|uboot\\)\\>" . font-lock-keyword-face) ("^\\([A-Z_]+\\)=" (1 font-lock-variable-name-face)) diff --git a/novaboot b/novaboot index dc1640c..0118649 100755 --- a/novaboot +++ b/novaboot @@ -296,7 +296,7 @@ my @scripts; my $file; my $EOF; my $last_fn = ''; -my ($modules, $variables, $generated, $continuation) = ([], {}, []); +my ($modules, $variables, $generated, $copy, $continuation) = ([], {}, [], []); my $skip_reading = defined($on_opt) || defined($off_opt); while (!$skip_reading && ($_ = <>)) { if ($ARGV ne $last_fn) { # New script @@ -306,7 +306,9 @@ while (!$skip_reading && ($_ = <>)) { push @scripts, { 'filename' => $ARGV, 'modules' => $modules = [], 'variables' => $variables = {}, - 'generated' => $generated = []}; + 'generated' => $generated = [], + 'copy' => $copy = [], + }; } chomp(); @@ -339,21 +341,26 @@ while (!$skip_reading && ($_ = <>)) { push(@exiton, $2) if ($1 eq "EXITON"); next; } - if (s/^load *//) { # Load line + sub process_load_copy($) { die("novaboot: '$last_fn' line $.: Missing file name\n") unless /^[^ <]+/; if (/^([^ ]*)(.*?)[[:space:]]*<<([^ ]*)$/) { # Heredoc start - push @$modules, "$1$2"; $file = []; push @$generated, {filename => $1, content => $file}; $EOF = $3; - next; + return "$1$2"; } if (/^([^ ]*)(.*?)[[:space:]]*< ?(.*)$/) { # Command substitution - push @$modules, "$1$2"; push @$generated, {filename => $1, command => $3}; - next; + return "$1$2"; } - push @$modules, $_; + return $_; + } + if (s/^load *//) { # Load line + push @$modules, process_load_copy($_); + next; + } + if (s/^copy *//) { # Copy line + push @$copy, process_load_copy($_); next; } if (/^run (.*)/) { # run line @@ -874,7 +881,7 @@ foreach my $script (@scripts) { $path = $hostname; $hostname = ""; } - my $files = join(" ", map({ ($file) = m/([^ ]*)/; $file; } ( @$modules, @bootloader_configs))); + my $files = join(" ", map({ ($file) = m/([^ ]*)/; $file; } ( @$modules, @bootloader_configs, @$copy))); map({ my $file = (split)[0]; die "$file: $!" if ! -f $file; } @$modules); my $istty = -t STDOUT && ($ENV{'TERM'} || 'dumb') ne 'dumb'; my $progress = $istty ? "--progress" : ""; @@ -1902,6 +1909,12 @@ that line. The SRCDIR variable in CMD's environment is set to the absolute path of the directory containing the interpreted novaboot script. +Lines starting with C keyword are similar to C lines. The +file mentioned there is copied to the same place as in case of C +(e.g. tftp server), but the file is not used in the bootloader +configuration. Such a file can be used by the target for other +purposed than booting, e.g. at OS runtime or for firmware update. + Lines starting with C keyword contain shell commands that are run during file generation phase. This is the same as the "< CMD" syntax for C keyboard except that the command's output is not -- 2.39.2