scripts/wic: fix calling wic ls|cp|rm|write hung in bitbake task

While calling wic ls/cp/rm/write in bitbake task along with do_image_wic,
it hung without return.

Due to commit [2255f28b57 wic: add WIC_SECTOR_SIZE variable][1] applied,
It calls get_bitbake_var in `wic ls|cp|rm|write' to define sector size.
By default, get_bitbake_var starts a `bitbake -e' to get variables which
triggers nested bitbake in this situation

Refer `wic create', adds option --vars and --image-name to support to
read bitbake variables from <image>.env files

NOTE: This commit does not add -e for `wic write' to avoid confliction
with existed option -e/--expand

[1] 2255f28b57

(From OE-Core rev: 793732a6ac2b3788d6c6635e5a496b117bd60584)

Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Hongxu Jia 2025-06-16 16:12:45 +08:00 committed by Richard Purdie
parent 3bef3d2ee1
commit e2e709d85e

View File

@ -237,6 +237,13 @@ def wic_ls_subcommand(args, usage_str):
Command-line handling for list content of images. Command-line handling for list content of images.
The real work is done by engine.wic_ls() The real work is done by engine.wic_ls()
""" """
if args.image_name:
BB_VARS.default_image = args.image_name
if args.vars_dir:
BB_VARS.vars_dir = args.vars_dir
engine.wic_ls(args, args.native_sysroot) engine.wic_ls(args, args.native_sysroot)
def wic_cp_subcommand(args, usage_str): def wic_cp_subcommand(args, usage_str):
@ -244,6 +251,12 @@ def wic_cp_subcommand(args, usage_str):
Command-line handling for copying files/dirs to images. Command-line handling for copying files/dirs to images.
The real work is done by engine.wic_cp() The real work is done by engine.wic_cp()
""" """
if args.image_name:
BB_VARS.default_image = args.image_name
if args.vars_dir:
BB_VARS.vars_dir = args.vars_dir
engine.wic_cp(args, args.native_sysroot) engine.wic_cp(args, args.native_sysroot)
def wic_rm_subcommand(args, usage_str): def wic_rm_subcommand(args, usage_str):
@ -251,6 +264,12 @@ def wic_rm_subcommand(args, usage_str):
Command-line handling for removing files/dirs from images. Command-line handling for removing files/dirs from images.
The real work is done by engine.wic_rm() The real work is done by engine.wic_rm()
""" """
if args.image_name:
BB_VARS.default_image = args.image_name
if args.vars_dir:
BB_VARS.vars_dir = args.vars_dir
engine.wic_rm(args, args.native_sysroot) engine.wic_rm(args, args.native_sysroot)
def wic_write_subcommand(args, usage_str): def wic_write_subcommand(args, usage_str):
@ -258,6 +277,12 @@ def wic_write_subcommand(args, usage_str):
Command-line handling for writing images. Command-line handling for writing images.
The real work is done by engine.wic_write() The real work is done by engine.wic_write()
""" """
if args.image_name:
BB_VARS.default_image = args.image_name
if args.vars_dir:
BB_VARS.vars_dir = args.vars_dir
engine.wic_write(args, args.native_sysroot) engine.wic_write(args, args.native_sysroot)
def wic_help_subcommand(args, usage_str): def wic_help_subcommand(args, usage_str):
@ -390,6 +415,12 @@ def wic_init_parser_ls(subparser):
help="image spec: <image>[:<vfat partition>[<path>]]") help="image spec: <image>[:<vfat partition>[<path>]]")
subparser.add_argument("-n", "--native-sysroot", subparser.add_argument("-n", "--native-sysroot",
help="path to the native sysroot containing the tools") help="path to the native sysroot containing the tools")
subparser.add_argument("-e", "--image-name", dest="image_name",
help="name of the image to use the artifacts from "
"e.g. core-image-sato")
subparser.add_argument("-v", "--vars", dest='vars_dir',
help="directory with <image>.env files that store "
"bitbake variables")
def imgpathtype(arg): def imgpathtype(arg):
img = imgtype(arg) img = imgtype(arg)
@ -404,6 +435,12 @@ def wic_init_parser_cp(subparser):
help="image spec: <image>:<vfat partition>[<path>] or <file>") help="image spec: <image>:<vfat partition>[<path>] or <file>")
subparser.add_argument("-n", "--native-sysroot", subparser.add_argument("-n", "--native-sysroot",
help="path to the native sysroot containing the tools") help="path to the native sysroot containing the tools")
subparser.add_argument("-e", "--image-name", dest="image_name",
help="name of the image to use the artifacts from "
"e.g. core-image-sato")
subparser.add_argument("-v", "--vars", dest='vars_dir',
help="directory with <image>.env files that store "
"bitbake variables")
def wic_init_parser_rm(subparser): def wic_init_parser_rm(subparser):
subparser.add_argument("path", type=imgpathtype, subparser.add_argument("path", type=imgpathtype,
@ -413,6 +450,12 @@ def wic_init_parser_rm(subparser):
subparser.add_argument("-r", dest="recursive_delete", action="store_true", default=False, subparser.add_argument("-r", dest="recursive_delete", action="store_true", default=False,
help="remove directories and their contents recursively, " help="remove directories and their contents recursively, "
" this only applies to ext* partition") " this only applies to ext* partition")
subparser.add_argument("-e", "--image-name", dest="image_name",
help="name of the image to use the artifacts from "
"e.g. core-image-sato")
subparser.add_argument("-v", "--vars", dest='vars_dir',
help="directory with <image>.env files that store "
"bitbake variables")
def expandtype(rules): def expandtype(rules):
""" """
@ -454,6 +497,12 @@ def wic_init_parser_write(subparser):
help="expand rules: auto or <partition>:<size>[,<partition>:<size>]") help="expand rules: auto or <partition>:<size>[,<partition>:<size>]")
subparser.add_argument("-n", "--native-sysroot", subparser.add_argument("-n", "--native-sysroot",
help="path to the native sysroot containing the tools") help="path to the native sysroot containing the tools")
subparser.add_argument("--image-name", dest="image_name",
help="name of the image to use the artifacts from "
"e.g. core-image-sato")
subparser.add_argument("-v", "--vars", dest='vars_dir',
help="directory with <image>.env files that store "
"bitbake variables")
def wic_init_parser_help(subparser): def wic_init_parser_help(subparser):
helpparsers = subparser.add_subparsers(dest='help_topic', help=hlp.wic_usage) helpparsers = subparser.add_subparsers(dest='help_topic', help=hlp.wic_usage)