1#!/usr/bin/python3 2# Copyright (c) 2020, Arm Limited. All rights reserved. 3# 4# SPDX-License-Identifier: BSD-3-Clause 5 6""" 7This script is invoked by Make system and generates secure partition makefile. 8It expects platform provided secure partition layout file which contains list 9of Secure Partition Images and Partition manifests(PM). 10Layout file can exist outside of TF-A tree and the paths of Image and PM files 11must be relative to it. 12 13This script parses the layout file and generates a make file which updates 14FDT_SOURCES, FIP_ARGS and SPTOOL_ARGS which are used in later build steps. 15This script also gets SP "uuid" from parsing its PM and converting it to a 16standard format. 17 18param1: Generated mk file "sp_gen.mk" 19param2: "SP_LAYOUT_FILE", json file containing platform provided information 20param3: plat out directory 21 22Generated "sp_gen.mk" file contains triplet of following information for each 23Secure 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 28A 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 45import getopt 46import json 47import os 48import re 49import sys 50import uuid 51 52with open(sys.argv[2],'r') as in_file: 53 data = json.load(in_file) 54json_file = os.path.abspath(sys.argv[2]) 55json_dir = os.path.dirname(json_file) 56gen_file = sys.argv[1] 57out_dir = sys.argv[3][2:] 58dtb_dir = out_dir + "/fdts/" 59print(dtb_dir) 60 61with 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") 101