From 4dcbba98cee2260e4c4f680f6a7fda5a98fdc7d5 Mon Sep 17 00:00:00 2001 From: Charlie Bareham Date: Thu, 20 Jun 2024 12:11:53 +0100 Subject: [PATCH] feat: add option to input attr as string of flag names Change-Id: I56f0364ef43c9d415a335474e15b68e79db37f5d Signed-off-by: Charlie Bareham --- docs/tools/transfer-list-compiler.rst | 27 +++++++++++++++++++++ tools/tlc/tests/test_cli.py | 23 ++++++++++++++++++ tools/tlc/tlc/tl.py | 34 ++++++++++++++++++++++++++- 3 files changed, 83 insertions(+), 1 deletion(-) diff --git a/docs/tools/transfer-list-compiler.rst b/docs/tools/transfer-list-compiler.rst index 8ecbab529..fa660dc6b 100644 --- a/docs/tools/transfer-list-compiler.rst +++ b/docs/tools/transfer-list-compiler.rst @@ -275,6 +275,33 @@ You can give the name of the tag instead of the tag id number. The valid tag nam * hob_block * hob_list +You can input the attr field of entry_point_info as a string of flag +names separated by `|`. The names are taken from ep_info_exp.h in TF-A. +For example: + +.. code:: + + has_checksum: true + max_size: 4096 + entries: + - tag_id: 0x102 + ep_info: + args: + - 67112976 + - 67112960 + - 0 + - 0 + - 0 + - 0 + - 0 + - 0 + h: + attr: EP_NON_SECURE | EP_ST_ENABLE + type: 1 + version: 2 + pc: 67239936 + spsr: 965 + -------------- *Copyright (c) 2024, Arm Limited. All rights reserved.* diff --git a/tools/tlc/tests/test_cli.py b/tools/tlc/tests/test_cli.py index 6d50ab7cd..99b5816b7 100644 --- a/tools/tlc/tests/test_cli.py +++ b/tools/tlc/tests/test_cli.py @@ -320,6 +320,29 @@ def test_create_from_yaml_check_sum_bytes(tlcrunner, tmpyamlconfig, tmptlstr, en "0x00000000 0x00000000" ), ), + ( + { + "tag_id": 0x102, + "ep_info": { + "h": { + "type": 0x01, + "version": 0x02, + "attr": "EP_NON_SECURE | EP_ST_ENABLE", + }, + "pc": 67239936, + "spsr": 965, + "args": [67112976, 67112960, 0, 0, 0, 0, 0, 0], + }, + }, + ( + "0x00580201 0x00000005 0x04020000 0x00000000 " + "0x000003C5 0x00000000 0x04001010 0x00000000 " + "0x04001000 0x00000000 0x00000000 0x00000000 " + "0x00000000 0x00000000 0x00000000 0x00000000 " + "0x00000000 0x00000000 0x00000000 0x00000000 " + "0x00000000 0x00000000" + ), + ), ], ) def test_create_from_yaml_check_exact_data( diff --git a/tools/tlc/tlc/tl.py b/tools/tlc/tlc/tl.py index eec5db08e..3f0065d05 100644 --- a/tools/tlc/tlc/tl.py +++ b/tools/tlc/tlc/tl.py @@ -13,6 +13,7 @@ import typing import math import struct from dataclasses import dataclass +from functools import reduce from pathlib import Path from tlc.te import TransferEntry @@ -236,13 +237,44 @@ class TransferList: # size of the entry_point_info struct entry_point_size = 88 + attr = header["attr"] + if type(attr) is str: + # convert string of flags names to an integer + + # bit number | 0 | 1 | + # ------------|-----------------------|----------------------| + # 0 | secure | non-secure | + # 1 | little endian | big-endian | + # 2 | disable secure timer | enable secure timer | + # 3 | executable | non-executable | + # 4 | first exe | not first exe | + # + # Bit 5 and bit 0 are used to determine the security state. + + flag_names = { + "EP_SECURE": 0x0, + "EP_NON_SECURE": 0x1, + "EP_REALM": 0x21, + "EP_EE_LITTLE": 0x0, + "EP_EE_BIG": 0x2, + "EP_ST_DISABLE": 0x0, + "EP_ST_ENABLE": 0x4, + "EP_NON_EXECUTABLE": 0x0, + "EP_EXECUTABLE": 0x8, + "EP_FIRST_EXE": 0x10, + } + + # create list of integer flags, then bitwise-or them together + flags = [flag_names[f.strip()] for f in attr.split("|")] + attr = reduce(lambda x, y: x | y, flags) + return self.add_transfer_entry_from_struct_format( 0x102, transfer_entry_formats[0x102]["format"], header["type"], header["version"], entry_point_size, - header["attr"], + attr, ep_info["pc"], ep_info["spsr"], *ep_info["args"],