Commit 235a02df authored by Guido Gunther's avatar Guido Gunther Committed by Guido Gunther
Browse files

librem5-flash-image: Detect board type via argv[0]

Closes: #30
parent 55ed68f5
......@@ -29,6 +29,8 @@ from urllib.parse import urljoin
JENKINS = 'https://arm01.puri.sm'
BOARD_TYPE = 'librem5r4'
VALID_PHONE_BOARD_TYPES = ['librem5r2', 'librem5r3', 'librem5r4']
VALID_DEVKIT_BOARD_TYPES = ['devkit']
BOARD_VARIANT = 'plain'
DIST = 'amber-phone'
IMAGE = '{}.img'
......@@ -256,6 +258,42 @@ def flash_image(uuu_target, debug):
subprocess.check_call(['uuu', uuu_target])
def get_board(path):
"""
Get board type from script name.
In case of doubt return the default board.
>>> get_board("/a/b/librem5-devkit-flash-image")
'devkit'
>>> get_board("/a/b/librem5r2-flash-image")
'librem5r2'
>>> get_board("/a/b/librem5r3-flash-image")
'librem5r3'
>>> get_board("/a/b/librem5r4-flash-image")
'librem5r4'
>>> get_board("/a/b/schwobel")
'librem5r4'
"""
name = os.path.split(path)[-1]
parts = name.split('-')
if len(parts) < 3 or len(parts) > 4:
return BOARD_TYPE
if parts[-2:] != ['flash', 'image']:
return BOARD_TYPE
parts = parts[:-2]
if len(parts) == 1 and parts[0] in VALID_PHONE_BOARD_TYPES:
return parts[0]
if parts[0] == 'librem5' and parts[1] in VALID_DEVKIT_BOARD_TYPES:
return parts[1]
# People do odd things so use default in this case
return BOARD_TYPE
def main():
uuu_mods = ''
parser = argparse.ArgumentParser(description='Flash a Librem 5 or Librem 5 Devkit.')
......@@ -273,9 +311,9 @@ def main():
parser.add_argument('--variant', choices=['legacy', 'current', 'next', 'plain'], default=BOARD_VARIANT,
help="Variant of the board to download ( legacy, current, next ), "
"default is '{}'".format(BOARD_VARIANT))
parser.add_argument('--board', choices=['devkit', 'librem5r2', 'librem5r3', 'librem5r4'], default=BOARD_TYPE,
parser.add_argument('--board', choices=VALID_DEVKIT_BOARD_TYPES + VALID_PHONE_BOARD_TYPES, default=None,
help="Type of the board to download ( devkit, librem5r2, librem5r3, librem5r4 ) "
"default is '{}'".format(BOARD_TYPE))
"default is 'auto'")
group = parser.add_argument_group(title='Testing and debugging options')
group.add_argument('--debug', action="store_true", default=False,
......@@ -292,9 +330,11 @@ def main():
else:
logging.basicConfig(level=level, format='%(asctime)s %(levelname)s %(message)s')
board = args.board if args.board else get_board(sys.argv[0])
# Check available downloads upfront so it's less likely we fail
# later:
image_ref = find_image(args.image_job, args.board, args.variant, args.dist)
image_ref = find_image(args.image_job, board, args.variant, args.dist)
if image_ref:
image_ref['ts'] = datetime.datetime.fromtimestamp(image_ref['timestamp'] / 1000).strftime('%c')
logging.info("Found disk image Build {id} '{description}' from {ts}".format(**image_ref))
......@@ -304,10 +344,10 @@ def main():
if args.uboot_job:
uboot_ref = find_uboot(args.uboot_job)
uboot_board = args.board
uboot_board = board
else:
# uboot builds don't carry board revisions (yet?)
uboot_board = args.board[:-2] if re.match('librem5r[0-9]$', args.board) else args.board
uboot_board = board[:-2] if re.match('librem5r[0-9]$', board) else board
uboot_ref = find_uboot(UBOOT_JOB_NAME.format(uboot_board))
if uboot_ref:
......@@ -317,7 +357,7 @@ def main():
logging.error("No matching uboot found")
return 1
if args.board in ["librem5r3", 'librem5r4']:
if board in ["librem5r3", 'librem5r4']:
uuu_mods = "CFG: SDP: -chip MX8MQ -compatible MX8MQ -vid 0x316d -pid 0x4c05"
outdir = args.dir if args.dir is not None else tempfile.mkdtemp(prefix='devkit_image_', dir='.')
......@@ -326,11 +366,11 @@ def main():
if args.dir == outdir:
os.makedirs(args.dir, exist_ok=True)
image_target = os.path.join(outdir, IMAGE.format(args.board))
image_target = os.path.join(outdir, IMAGE.format(board))
uboot_target = os.path.join(outdir, UBOOT.format(uboot_board))
uuu_target = os.path.join(outdir, UUU_SCRIPT.format(args.board))
uuu_target = os.path.join(outdir, UUU_SCRIPT.format(board))
download_image(urljoin(image_ref['url'], 'artifact/{}.xz').format(IMAGE.format(args.board)),
download_image(urljoin(image_ref['url'], 'artifact/{}.xz').format(IMAGE.format(board)),
image_target, args.download_attempts)
download_uboot(urljoin(uboot_ref['url'],
'artifact/output/uboot-{}/{}'.format(uboot_board, UBOOT.format(uboot_board))),
......
librem5-flash-image
\ No newline at end of file
librem5-flash-image
\ No newline at end of file
librem5-flash-image
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment