Parcourir la source

wic: plugins: Improve rootfs-u-boot script_prepend passing

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>
Jan Kiszka il y a 4 ans
Parent
commit
3000f28721
1 fichiers modifiés avec 7 ajouts et 0 suppressions
  1. 7 0
      meta/scripts/lib/wic/plugins/source/rootfs-u-boot.py

+ 7 - 0
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