blob: 2153a5651657edf624a6aefca1f211eaa1060ce9 [file] [log] [blame]
Manish Pandey3f90ad72020-01-14 11:52:05 +00001#!/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
Manish Pandeyaaaeb312020-05-26 23:59:36 +010014FDT_SOURCES, FIP_ARGS, CRT_ARGS and SPTOOL_ARGS which are used in later build
15steps.
Manish Pandey3f90ad72020-01-14 11:52:05 +000016This script also gets SP "uuid" from parsing its PM and converting it to a
17standard format.
18
19param1: Generated mk file "sp_gen.mk"
20param2: "SP_LAYOUT_FILE", json file containing platform provided information
21param3: plat out directory
22
23Generated "sp_gen.mk" file contains triplet of following information for each
24Secure Partition entry
25 FDT_SOURCES += sp1.dts
26 SPTOOL_ARGS += -i sp1.bin:sp1.dtb -o sp1.pkg
27 FIP_ARGS += --blob uuid=XXXXX-XXX...,file=sp1.pkg
Manish Pandeyaaaeb312020-05-26 23:59:36 +010028 CRT_ARGS += --sp-pkg1 sp1.pkg
Manish Pandey3f90ad72020-01-14 11:52:05 +000029
30A typical SP_LAYOUT_FILE file will look like
31{
32 "SP1" : {
33 "image": "sp1.bin",
34 "pm": "test/sp1.dts"
35 },
36
37 "SP2" : {
38 "image": "sp2.bin",
39 "pm": "test/sp2.dts"
40 }
41
42 ...
43}
44
45"""
46
47import getopt
48import json
49import os
50import re
51import sys
52import uuid
53
54with open(sys.argv[2],'r') as in_file:
55 data = json.load(in_file)
56json_file = os.path.abspath(sys.argv[2])
57json_dir = os.path.dirname(json_file)
Grant Likely388248a2020-07-30 08:50:10 +010058gen_file = os.path.abspath(sys.argv[1])
59out_dir = os.path.abspath(sys.argv[3])
Manish Pandey3f90ad72020-01-14 11:52:05 +000060dtb_dir = out_dir + "/fdts/"
61print(dtb_dir)
62
63with open(gen_file, 'w') as out_file:
Manish Pandeyaaaeb312020-05-26 23:59:36 +010064 for idx, key in enumerate(data.keys()):
Manish Pandey3f90ad72020-01-14 11:52:05 +000065
66 """
67 Append FDT_SOURCES
68 """
69 dts = os.path.join(json_dir, data[key]['pm'])
70 dtb = dtb_dir + os.path.basename(data[key]['pm'][:-1] + "b")
71 out_file.write("FDT_SOURCES += " + dts + "\n")
72
73 """
74 Update SPTOOL_ARGS
75 """
76 dst = out_dir + "/" + key + ".pkg"
77 src = [ json_dir + "/" + data[key]['image'] , dtb ]
78 out_file.write("SPTOOL_ARGS += -i " + ":".join(src) + " -o " + dst + "\n")
79
80 """
81 Extract uuid from partition manifest
82 """
83 pm_file = open(dts)
84 key = "uuid"
85
86 for line in pm_file:
87 if key in line:
88 uuid_hex = re.findall(r'\<(.+?)\>', line)[0];
89
90 # PM has uuid in format 0xABC... 0x... 0x... 0x...
91 # Get rid of '0x' and spaces and convert to string of hex digits
92 uuid_hex = uuid_hex.replace('0x','').replace(' ','')
93 # make UUID from a string of hex digits
94 uuid_std = uuid.UUID(uuid_hex)
95 # convert UUID to a string of hex digits in standard form
96 uuid_std = str(uuid_std)
97
98 """
99 Append FIP_ARGS
100 """
101 out_file.write("FIP_ARGS += --blob uuid=" + uuid_std + ",file=" + dst + "\n")
Manish Pandeyaaaeb312020-05-26 23:59:36 +0100102
103 """
104 Append CRT_ARGS
105 """
106 out_file.write("CRT_ARGS += --sp-pkg" + str(idx + 1) + " " + dst + "\n")
Manish Pandey3f90ad72020-01-14 11:52:05 +0000107 out_file.write("\n")