| Message ID | 185f97a0-6755-1344-43cd-7df51040ba65@siemens.com |
|---|---|
| State | Accepted, archived |
| Headers | show |
| Series | wic: plugins: Improve rootfs-u-boot script_prepend passing | expand |
08.05.2021 15:43, Jan Kiszka wrote: > From: Jan Kiszka <jan.kiszka@siemens.com> > > Passing a script_prepend value down to the generated boot.scr currently > requires double escaping: once for the wks file when being parsed by > wic and a second time for /etc/default/u-boot-script when being parsed > by the u-boot-script tool. > > This removes the need for double escaping by detecting if the " or $ > characters are already escaped after the wic parsing step. If not, the > plugin injects the required escape character. > > In addition, this provides a way to avoid the wic warning about an > unknown (bitbake) variable when injecting ${some_var} into the script: > > do_wic_image: WARNING: cannot expand variable some_var > > The user can now simply escape the curly braces as well: $\{some_var\}. > The plugin will remove these escapes before generating the u-boot-script > configuration file. This also resolves the more theoretical case of a > naming clash between a WICVAR and a U-Boot script variable. > > Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Applied to next, thanks.
diff --git a/meta/scripts/lib/wic/plugins/source/rootfs-u-boot.py b/meta/scripts/lib/wic/plugins/source/rootfs-u-boot.py index 3ac0aa0..15acb57 100644 --- a/meta/scripts/lib/wic/plugins/source/rootfs-u-boot.py +++ b/meta/scripts/lib/wic/plugins/source/rootfs-u-boot.py @@ -14,6 +14,7 @@ import glob import logging +import re import os from wic import WicError @@ -75,6 +76,12 @@ class RootfsUBootPlugin(RootfsPlugin): overlays = source_params.get('overlays') or '' cfg.write('OVERLAYS="%s"\n' % overlays) script_prepend = source_params.get('script_prepend') or '' + # remove escapes from $\{var\} that are needed to avoid expansion by wic + script_prepend = re.sub(r'\$\\{([^\\]+)\\}', r'${\1}', script_prepend) + # escape any quotes that aren't escaped yet + script_prepend = re.sub(r'([^\\])"', r'\1\\"', script_prepend) + # escape any dollars that aren't escaped yet + script_prepend = re.sub(r'([^\\])\$', r'\1\\$', script_prepend) cfg.write('SCRIPT_PREPEND="%s"\n' % script_prepend) # Run update-u-boot-script in the target rootfs