bootloaders: Load bootloader manifests from XMLs

* HisiBootloaders repo uses XML instead of JSON

Change-Id: I54d8dc3d78ef29133304cb631d6710313e768848
Signed-off-by: Woomymy <woomy@woomy.be>
This commit is contained in:
Woomymy 2023-11-01 16:38:40 +01:00 committed by Andrey Smirnoff
parent fddf3f6329
commit 9e9f437c76
2 changed files with 11 additions and 8 deletions

View file

@ -1,5 +1,4 @@
adb==1.3.0 adb==1.3.0
lxml==4.4.1
pychalk==2.0.1 pychalk==2.0.1
pyserial==3.4 pyserial==3.4
inquirerpy==0.3.4 inquirerpy==0.3.4

View file

@ -1,8 +1,8 @@
import sys import sys
import chalk import chalk
import argparse import argparse
import json
import hashlib import hashlib
import xml.etree.ElementTree as ET
from os import path from os import path
from glob import glob from glob import glob
from . import ui from . import ui
@ -34,7 +34,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
'type': 'list', 'type': 'list',
'name': 'bootloader', 'name': 'bootloader',
'message': 'Select bootloader:', 'message': 'Select bootloader:',
'choices': list(map(lambda x: path.split(x)[-1], glob('bootloaders/*'))) 'choices': list(map(lambda x: path.basename(path.split(x)[-2]), glob('bootloaders/*/manifest.xml')))
})['bootloader'] })['bootloader']
if not args.key: if not args.key:
@ -45,7 +45,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
'validate': lambda val: len(val) == 16 or 'Excepted 16 symbols' 'validate': lambda val: len(val) == 16 or 'Excepted 16 symbols'
})['key'] })['key']
args.manifest = "./bootloaders/%s/manifest.json".format(args.bootloader) args.manifest = f"./bootloaders/{args.bootloader}/manifest.xml"
if len(args.key) != 16: if len(args.key) != 16:
ui.error("Invalid key length!", critical=True) ui.error("Invalid key length!", critical=True)
@ -62,7 +62,7 @@ def flash_images(data: dict):
for image in data["images"]: for image in data["images"]:
ui.progress(title="Flashing {}".format(image['role'])) ui.progress(title="Flashing {}".format(image['role']))
flasher.download_from_disk("./bootloaders/{}/{}" flasher.download_from_disk("./bootloaders/{}/{}"
.format(data['name'], image['filename']), int(image['address'], 16)) .format(data['name'], image['path']), int(image['address'], 16))
ui.success("Bootloader uploaded.") ui.success("Bootloader uploaded.")
@ -82,8 +82,12 @@ def write_nvme(key: str):
def main(): def main():
args = setup() args = setup()
if not args.skip_bootloader: if not args.skip_bootloader:
with open(args.manifest) as json_file: xmltree = ET.parse(args.manifest)
data = json.load(json_file) bootloader = xmltree.getroot()
data = bootloader.attrib
data["images"] = list(map(lambda img: img.attrib, bootloader.findall('image')))
data["name"] = args.bootloader data["name"] = args.bootloader
flash_images(data) flash_images(data)
write_nvme(args.key) write_nvme(args.key)