mirror of
https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git
synced 2025-07-13 19:39:51 +03:00
pmb: add -f (force) parameter to bootimg_analyze
We are analyzing the `boot.img` with `file` before we send it to `unpackbootimg`. File does not recognize all kinds of `boot.img` files, which `unpackbootimg` can extract, so we need a way to skip this check. Details: * Add `-f` parameter, continues extraction with a warning if the file seems to be invalid * Tell the user that `-f` can be used if the `boot.img` is invalid and it's not specified * Consistent spelling of `boot.img` instead of `bootimg` in messages Fixes #1608
This commit is contained in:
parent
0aa125e45c
commit
d4f4ea8488
3 changed files with 19 additions and 6 deletions
|
@ -437,6 +437,9 @@ def arguments():
|
||||||
bootimg_analyze = sub.add_parser("bootimg_analyze", help="Extract all the"
|
bootimg_analyze = sub.add_parser("bootimg_analyze", help="Extract all the"
|
||||||
" information from an existing boot.img")
|
" information from an existing boot.img")
|
||||||
bootimg_analyze.add_argument("path", help="path to the boot.img")
|
bootimg_analyze.add_argument("path", help="path to the boot.img")
|
||||||
|
bootimg_analyze.add_argument("-f", dest="force", action="store_true",
|
||||||
|
help="force even if the file seems to be"
|
||||||
|
" invalid")
|
||||||
|
|
||||||
# Use defaults from the user's config file
|
# Use defaults from the user's config file
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
|
@ -38,12 +38,22 @@ def bootimg(args, path):
|
||||||
file_output = pmb.chroot.user(args, ["file", "-b", "boot.img"], working_dir=temp_path,
|
file_output = pmb.chroot.user(args, ["file", "-b", "boot.img"], working_dir=temp_path,
|
||||||
return_stdout=True).rstrip()
|
return_stdout=True).rstrip()
|
||||||
if "android bootimg" not in file_output.lower():
|
if "android bootimg" not in file_output.lower():
|
||||||
if "linux kernel" in file_output.lower():
|
if "force" in args and args.force:
|
||||||
raise RuntimeError("File is a Kernel image, you might need the 'heimdall-isorec'"
|
logging.warning("WARNING: boot.img file seems to be invalid, but"
|
||||||
" flash method. See also: "
|
" proceeding anyway (-f specified)")
|
||||||
"<https://wiki.postmarketos.org/wiki/Deviceinfo_flash_methods>")
|
|
||||||
else:
|
else:
|
||||||
raise RuntimeError("File is not an Android bootimg. (" + file_output + ")")
|
logging.info("NOTE: If you are sure that your file is a valid"
|
||||||
|
" boot.img file, you could force the analysis"
|
||||||
|
" with: 'pmbootstrap bootimg_analyze " + path +
|
||||||
|
" -f'")
|
||||||
|
if "linux kernel" in file_output.lower():
|
||||||
|
raise RuntimeError("File is a Kernel image, you might need the"
|
||||||
|
" 'heimdall-isorec' flash method. See also:"
|
||||||
|
" <https://wiki.postmarketos.org/wiki/"
|
||||||
|
"Deviceinfo_flash_methods>")
|
||||||
|
else:
|
||||||
|
raise RuntimeError("File is not an Android boot.img. (" +
|
||||||
|
file_output + ")")
|
||||||
|
|
||||||
# Extract all the files
|
# Extract all the files
|
||||||
pmb.chroot.user(args, ["unpackbootimg", "-i", "boot.img"], working_dir=temp_path)
|
pmb.chroot.user(args, ["unpackbootimg", "-i", "boot.img"], working_dir=temp_path)
|
||||||
|
|
|
@ -56,7 +56,7 @@ def test_bootimg_kernel(args):
|
||||||
def test_bootimg_invalid_file(args):
|
def test_bootimg_invalid_file(args):
|
||||||
with pytest.raises(RuntimeError) as e:
|
with pytest.raises(RuntimeError) as e:
|
||||||
pmb.parse.bootimg(args, __file__)
|
pmb.parse.bootimg(args, __file__)
|
||||||
assert "File is not an Android bootimg" in str(e.value)
|
assert "File is not an Android boot.img" in str(e.value)
|
||||||
|
|
||||||
|
|
||||||
def test_bootimg_normal(args):
|
def test_bootimg_normal(args):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue