From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6959899212283641856 X-Received: by 2002:a17:906:6ace:: with SMTP id q14mr16068037ejs.79.1620477813456; Sat, 08 May 2021 05:43:33 -0700 (PDT) X-BeenThere: isar-users@googlegroups.com Received: by 2002:aa7:cdcb:: with SMTP id h11ls1121103edw.2.gmail; Sat, 08 May 2021 05:43:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz5uuxmTVgVDGIg2whDYnWeC0i5q0mJQG3vjIyffwKE0i7jB7p1ANiMoElH2Y6mUpV9mqwM X-Received: by 2002:aa7:d917:: with SMTP id a23mr17307176edr.260.1620477812460; Sat, 08 May 2021 05:43:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620477812; cv=none; d=google.com; s=arc-20160816; b=m7CMStrXEYpIE3me9J4QWRxjQMMHnsf6mueb2dI4LDh/fz/T4ytT9CGzho1pKnEFaJ +KwJGIHEonbLgvMYIgizaVQtN1IxXa4KtEU1+g+Be4djyao7RI0chtH6K4cfXixUCHCr Lc66sBwA1GgkVu+5W23VG05trH29RWrcZKOlNtxkPCicl6pCrIKATkQ/Onvz3Ya1GFmR aIxMzxedr7nv9y/UWuFsCo1vuRRxjyhUm0L7gS9fZKpOl7uniSVgRpFJ3iECBBi5YkIW CwJ9cQROpnbZSshWCirFBn5DzdJmp3tRAU/15RdkIs1EPE/iieSNhjS8tZ7Yv5QuzRwq /1jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:mime-version:user-agent :date:message-id:to:subject:from; bh=fGVbltvC85ijlbEojc87o65pKjEOLpvqD01d+xKcLWE=; b=hidHWVktrLOGrgNo+v/+7fj+D6VPWAA9ZTqgKECNnT+b4kGP6N3vprLTA/fgfvDzdA RD77mivdtVZp5mud3cqobp/Uk2iNb7QWTzYH2n70P9UEaKHd4eZ5ERhYatc+z+QoD/Kq IL69e99e436snhiKKbz/veZ4dVx5ACNa46N4FcUr8dR1LsUBNDXLsGk31XotzgbeR+fi o/J+wIbHfTMOPgwdbCoRge7+4n1zkTidmj4U3WPFPrFOsYs8g23/PQzpuYsdQl3cBw2O hvVUjJjz5cCKvD7I8IOT+KvYIjyK+B5lnEdtWwTuK8wi9jmEVTk6mD+Ewfooo8Umrva6 Ow4g== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of jan.kiszka@siemens.com designates 194.138.37.39 as permitted sender) smtp.mailfrom=jan.kiszka@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Return-Path: Received: from lizzard.sbs.de (lizzard.sbs.de. [194.138.37.39]) by gmr-mx.google.com with ESMTPS id di23si246861edb.0.2021.05.08.05.43.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 08 May 2021 05:43:32 -0700 (PDT) Received-SPF: pass (google.com: domain of jan.kiszka@siemens.com designates 194.138.37.39 as permitted sender) client-ip=194.138.37.39; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of jan.kiszka@siemens.com designates 194.138.37.39 as permitted sender) smtp.mailfrom=jan.kiszka@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Received: from mail2.sbs.de (mail2.sbs.de [192.129.41.66]) by lizzard.sbs.de (8.15.2/8.15.2) with ESMTPS id 148ChV5t010126 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Sat, 8 May 2021 14:43:32 +0200 Received: from [167.87.32.109] ([167.87.32.109]) by mail2.sbs.de (8.15.2/8.15.2) with ESMTP id 148ChVfD026273 for ; Sat, 8 May 2021 14:43:31 +0200 From: Jan Kiszka Subject: [PATCH] wic: plugins: Improve rootfs-u-boot script_prepend passing To: isar-users Message-ID: <185f97a0-6755-1344-43cd-7df51040ba65@siemens.com> Date: Sat, 8 May 2021 14:43:31 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-TUID: RaTi6AfrjAWl From: Jan Kiszka 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 --- 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