2023-01-22 18:11:10 +00:00
|
|
|
# Copyright 2023 Oliver Smith
|
2020-02-20 20:07:28 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2017-11-19 14:35:23 +00:00
|
|
|
import sys
|
|
|
|
import pytest
|
|
|
|
|
2020-02-20 19:14:38 +00:00
|
|
|
import pmb_test
|
|
|
|
import pmb_test.const
|
2017-11-19 14:35:23 +00:00
|
|
|
import pmb.chroot.apk_static
|
|
|
|
import pmb.parse.apkindex
|
|
|
|
import pmb.helpers.logging
|
|
|
|
import pmb.parse.bootimg
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def args(request):
|
|
|
|
import pmb.parse
|
|
|
|
sys.argv = ["pmbootstrap.py", "chroot"]
|
|
|
|
args = pmb.parse.arguments()
|
|
|
|
args.log = args.work + "/log_testsuite.txt"
|
|
|
|
pmb.helpers.logging.init(args)
|
2021-09-20 10:00:13 +00:00
|
|
|
request.addfinalizer(pmb.helpers.logging.logfd.close)
|
2017-11-19 14:35:23 +00:00
|
|
|
return args
|
|
|
|
|
|
|
|
|
|
|
|
def test_bootimg_invalid_path(args):
|
|
|
|
with pytest.raises(RuntimeError) as e:
|
|
|
|
pmb.parse.bootimg(args, "/invalid-path")
|
|
|
|
assert "Could not find file" in str(e.value)
|
|
|
|
|
|
|
|
|
|
|
|
def test_bootimg_kernel(args):
|
2020-02-20 19:14:38 +00:00
|
|
|
path = pmb_test.const.testdata + "/bootimg/kernel-boot.img"
|
2017-11-19 14:35:23 +00:00
|
|
|
with pytest.raises(RuntimeError) as e:
|
|
|
|
pmb.parse.bootimg(args, path)
|
|
|
|
assert "heimdall-isorec" in str(e.value)
|
|
|
|
|
|
|
|
|
|
|
|
def test_bootimg_invalid_file(args):
|
|
|
|
with pytest.raises(RuntimeError) as e:
|
|
|
|
pmb.parse.bootimg(args, __file__)
|
2018-07-06 19:57:18 +00:00
|
|
|
assert "File is not an Android boot.img" in str(e.value)
|
2017-11-19 14:35:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_bootimg_normal(args):
|
2020-02-20 19:14:38 +00:00
|
|
|
path = pmb_test.const.testdata + "/bootimg/normal-boot.img"
|
2022-07-15 14:10:04 +00:00
|
|
|
output = {"header_version": "0",
|
|
|
|
"base": "0x80000000",
|
2017-11-19 14:35:23 +00:00
|
|
|
"kernel_offset": "0x00008000",
|
|
|
|
"ramdisk_offset": "0x04000000",
|
|
|
|
"second_offset": "0x00f00000",
|
|
|
|
"tags_offset": "0x0e000000",
|
|
|
|
"pagesize": "2048",
|
|
|
|
"cmdline": "bootopt=64S3,32S1,32S1",
|
2019-10-25 15:07:08 +00:00
|
|
|
"qcdt": "false",
|
2020-07-05 19:42:54 +00:00
|
|
|
"mtk_mkimage": "false",
|
2019-10-25 15:07:08 +00:00
|
|
|
"dtb_second": "false"}
|
2017-11-19 14:35:23 +00:00
|
|
|
assert pmb.parse.bootimg(args, path) == output
|
|
|
|
|
|
|
|
|
|
|
|
def test_bootimg_qcdt(args):
|
2020-02-20 19:14:38 +00:00
|
|
|
path = pmb_test.const.testdata + "/bootimg/qcdt-boot.img"
|
2017-11-19 14:35:23 +00:00
|
|
|
output = {"base": "0x80000000",
|
|
|
|
"kernel_offset": "0x00008000",
|
|
|
|
"ramdisk_offset": "0x04000000",
|
|
|
|
"second_offset": "0x00f00000",
|
|
|
|
"tags_offset": "0x0e000000",
|
|
|
|
"pagesize": "2048",
|
|
|
|
"cmdline": "bootopt=64S3,32S1,32S1",
|
2019-10-25 15:07:08 +00:00
|
|
|
"qcdt": "true",
|
2020-07-05 19:42:54 +00:00
|
|
|
"mtk_mkimage": "false",
|
|
|
|
"dtb_second": "false"}
|
|
|
|
assert pmb.parse.bootimg(args, path) == output
|
|
|
|
|
|
|
|
|
|
|
|
def test_bootimg_mtk_mkimage(args):
|
|
|
|
path = pmb_test.const.testdata + "/bootimg/mtk_mkimage-boot.img"
|
2022-07-15 14:10:04 +00:00
|
|
|
output = {"header_version": "0",
|
|
|
|
"base": "0x10000000",
|
2020-07-05 19:42:54 +00:00
|
|
|
"kernel_offset": "0x00008000",
|
2021-09-12 19:43:01 +00:00
|
|
|
"ramdisk_offset": "0x01000000",
|
2020-07-05 19:42:54 +00:00
|
|
|
"second_offset": "0x00f00000",
|
2021-09-12 19:43:01 +00:00
|
|
|
"tags_offset": "0x00000100",
|
2020-07-05 19:42:54 +00:00
|
|
|
"pagesize": "2048",
|
2021-09-12 19:43:01 +00:00
|
|
|
"cmdline": "",
|
2020-07-05 19:42:54 +00:00
|
|
|
"qcdt": "false",
|
|
|
|
"mtk_mkimage": "true",
|
2021-09-12 19:55:32 +00:00
|
|
|
"dtb_second": "false"}
|
|
|
|
assert pmb.parse.bootimg(args, path) == output
|
|
|
|
|
|
|
|
|
|
|
|
def test_bootimg_mtk_mkimage_recovery(args):
|
|
|
|
path = pmb_test.const.testdata + "/bootimg/mtk_mkimage-boot-recovery.img"
|
2022-07-15 14:10:04 +00:00
|
|
|
output = {"header_version": "0",
|
|
|
|
"base": "0x80000000",
|
2021-09-12 19:55:32 +00:00
|
|
|
"kernel_offset": "0x00008000",
|
|
|
|
"ramdisk_offset": "0x04000000",
|
|
|
|
"second_offset": "0x00f00000",
|
|
|
|
"tags_offset": "0x00000100",
|
|
|
|
"pagesize": "2048",
|
|
|
|
"cmdline": "",
|
|
|
|
"qcdt": "false",
|
|
|
|
"mtk_mkimage": "true",
|
2019-10-25 15:07:08 +00:00
|
|
|
"dtb_second": "false"}
|
|
|
|
assert pmb.parse.bootimg(args, path) == output
|
|
|
|
|
|
|
|
|
|
|
|
def test_bootimg_dtb_second(args):
|
2020-02-20 19:14:38 +00:00
|
|
|
path = pmb_test.const.testdata + "/bootimg/dtb-second-boot.img"
|
2022-07-15 14:10:04 +00:00
|
|
|
output = {"header_version": "0",
|
|
|
|
"base": "0x00000000",
|
2019-10-25 15:07:08 +00:00
|
|
|
"kernel_offset": "0x00008000",
|
|
|
|
"ramdisk_offset": "0x02000000",
|
|
|
|
"second_offset": "0x00f00000",
|
|
|
|
"tags_offset": "0x00000100",
|
|
|
|
"pagesize": "2048",
|
|
|
|
"cmdline": "bootopt=64S3,32S1,32S1",
|
|
|
|
"qcdt": "false",
|
2020-07-05 19:42:54 +00:00
|
|
|
"mtk_mkimage": "false",
|
2019-10-25 15:07:08 +00:00
|
|
|
"dtb_second": "true"}
|
2017-11-19 14:35:23 +00:00
|
|
|
assert pmb.parse.bootimg(args, path) == output
|
2021-06-19 15:50:27 +00:00
|
|
|
|
|
|
|
|
2022-07-15 15:28:53 +00:00
|
|
|
def test_bootimg_v2(args):
|
|
|
|
path = pmb_test.const.testdata + "/bootimg/boot-header-v2.img"
|
|
|
|
output = {"header_version": "2",
|
|
|
|
"base": "0x40078000",
|
|
|
|
"kernel_offset": "0x00008000",
|
|
|
|
"ramdisk_offset": "0x07c08000",
|
|
|
|
"second_offset": "0x00e10000",
|
|
|
|
"tags_offset": "0x0bc08000",
|
|
|
|
"pagesize": "2048",
|
|
|
|
"dtb_offset": "0x0bc08000",
|
|
|
|
"cmdline": "bootopt=64S3,32N2,64N2 systempart=/dev/mapper/system",
|
|
|
|
"qcdt": "false",
|
|
|
|
"mtk_mkimage": "false",
|
|
|
|
"dtb_second": "false"}
|
|
|
|
assert pmb.parse.bootimg(args, path) == output
|
|
|
|
|
|
|
|
|
2021-06-19 15:50:27 +00:00
|
|
|
def test_bootimg_v3(args):
|
|
|
|
path = pmb_test.const.testdata + "/bootimg/boot-header-v3.img"
|
|
|
|
output = {"header_version": "3",
|
|
|
|
"pagesize": "4096",
|
|
|
|
"cmdline": "twrpfastboot=1",
|
|
|
|
"qcdt": "false",
|
|
|
|
"mtk_mkimage": "false",
|
|
|
|
"dtb_second": "false"}
|
|
|
|
assert pmb.parse.bootimg(args, path) == output
|