Manish Pandey | 3f90ad7 | 2020-01-14 11:52:05 +0000 | [diff] [blame] | 1 | #!/usr/bin/python3 |
| 2 | # Copyright (c) 2020, Arm Limited. All rights reserved. |
| 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | |
| 6 | """ |
| 7 | This script is invoked by Make system and generates secure partition makefile. |
| 8 | It expects platform provided secure partition layout file which contains list |
| 9 | of Secure Partition Images and Partition manifests(PM). |
| 10 | Layout file can exist outside of TF-A tree and the paths of Image and PM files |
| 11 | must be relative to it. |
| 12 | |
| 13 | This script parses the layout file and generates a make file which updates |
| 14 | FDT_SOURCES, FIP_ARGS and SPTOOL_ARGS which are used in later build steps. |
| 15 | This script also gets SP "uuid" from parsing its PM and converting it to a |
| 16 | standard format. |
| 17 | |
| 18 | param1: Generated mk file "sp_gen.mk" |
| 19 | param2: "SP_LAYOUT_FILE", json file containing platform provided information |
| 20 | param3: plat out directory |
| 21 | |
| 22 | Generated "sp_gen.mk" file contains triplet of following information for each |
| 23 | Secure Partition entry |
| 24 | FDT_SOURCES += sp1.dts |
| 25 | SPTOOL_ARGS += -i sp1.bin:sp1.dtb -o sp1.pkg |
| 26 | FIP_ARGS += --blob uuid=XXXXX-XXX...,file=sp1.pkg |
| 27 | |
| 28 | A typical SP_LAYOUT_FILE file will look like |
| 29 | { |
| 30 | "SP1" : { |
| 31 | "image": "sp1.bin", |
| 32 | "pm": "test/sp1.dts" |
| 33 | }, |
| 34 | |
| 35 | "SP2" : { |
| 36 | "image": "sp2.bin", |
| 37 | "pm": "test/sp2.dts" |
| 38 | } |
| 39 | |
| 40 | ... |
| 41 | } |
| 42 | |
| 43 | """ |
| 44 | |
| 45 | import getopt |
| 46 | import json |
| 47 | import os |
| 48 | import re |
| 49 | import sys |
| 50 | import uuid |
| 51 | |
| 52 | with open(sys.argv[2],'r') as in_file: |
| 53 | data = json.load(in_file) |
| 54 | json_file = os.path.abspath(sys.argv[2]) |
| 55 | json_dir = os.path.dirname(json_file) |
| 56 | gen_file = sys.argv[1] |
| 57 | out_dir = sys.argv[3][2:] |
| 58 | dtb_dir = out_dir + "/fdts/" |
| 59 | print(dtb_dir) |
| 60 | |
| 61 | with open(gen_file, 'w') as out_file: |
| 62 | for key in data.keys(): |
| 63 | |
| 64 | """ |
| 65 | Append FDT_SOURCES |
| 66 | """ |
| 67 | dts = os.path.join(json_dir, data[key]['pm']) |
| 68 | dtb = dtb_dir + os.path.basename(data[key]['pm'][:-1] + "b") |
| 69 | out_file.write("FDT_SOURCES += " + dts + "\n") |
| 70 | |
| 71 | """ |
| 72 | Update SPTOOL_ARGS |
| 73 | """ |
| 74 | dst = out_dir + "/" + key + ".pkg" |
| 75 | src = [ json_dir + "/" + data[key]['image'] , dtb ] |
| 76 | out_file.write("SPTOOL_ARGS += -i " + ":".join(src) + " -o " + dst + "\n") |
| 77 | |
| 78 | """ |
| 79 | Extract uuid from partition manifest |
| 80 | """ |
| 81 | pm_file = open(dts) |
| 82 | key = "uuid" |
| 83 | |
| 84 | for line in pm_file: |
| 85 | if key in line: |
| 86 | uuid_hex = re.findall(r'\<(.+?)\>', line)[0]; |
| 87 | |
| 88 | # PM has uuid in format 0xABC... 0x... 0x... 0x... |
| 89 | # Get rid of '0x' and spaces and convert to string of hex digits |
| 90 | uuid_hex = uuid_hex.replace('0x','').replace(' ','') |
| 91 | # make UUID from a string of hex digits |
| 92 | uuid_std = uuid.UUID(uuid_hex) |
| 93 | # convert UUID to a string of hex digits in standard form |
| 94 | uuid_std = str(uuid_std) |
| 95 | |
| 96 | """ |
| 97 | Append FIP_ARGS |
| 98 | """ |
| 99 | out_file.write("FIP_ARGS += --blob uuid=" + uuid_std + ",file=" + dst + "\n") |
| 100 | out_file.write("\n") |