public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
* [PATCH] wic: plugins: Improve rootfs-u-boot script_prepend passing
@ 2021-05-08 12:43 Jan Kiszka
  2021-06-08  6:47 ` Anton Mikanovich
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Kiszka @ 2021-05-08 12:43 UTC (permalink / raw)
  To: isar-users

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>
---
 meta/scripts/lib/wic/plugins/source/rootfs-u-boot.py | 7 +++++++
 1 file changed, 7 insertions(+)

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
-- 
2.26.2

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] wic: plugins: Improve rootfs-u-boot script_prepend passing
  2021-05-08 12:43 [PATCH] wic: plugins: Improve rootfs-u-boot script_prepend passing Jan Kiszka
@ 2021-06-08  6:47 ` Anton Mikanovich
  0 siblings, 0 replies; 2+ messages in thread
From: Anton Mikanovich @ 2021-06-08  6:47 UTC (permalink / raw)
  To: Jan Kiszka, isar-users

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.

-- 
Anton Mikanovich
Promwad Ltd.
External service provider of ilbers GmbH
Maria-Merian-Str. 8
85521 Ottobrunn, Germany
+49 (89) 122 67 24-0
Commercial register Munich, HRB 214197
General Manager: Baurzhan Ismagulov


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-06-08  6:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-08 12:43 [PATCH] wic: plugins: Improve rootfs-u-boot script_prepend passing Jan Kiszka
2021-06-08  6:47 ` Anton Mikanovich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox