PROLEAD
A Probing-Based Leakage Detection Tool for Hardware and Software
Loading...
Searching...
No Matches
compile_sw.py
Go to the documentation of this file.
1from asyncio import subprocess
2import subprocess as sub
3import os
4import sys
5import shutil
6
7from pkg_resources import BINARY_DIST
8
9dir = os.getcwd()
10sys.path.append(dir)
11
12from pathlib import Path
13path = Path(dir)
14sys.path.append(str(path.parent.absolute()))
15
16BINARY_PATH = "../../binary"
17
18
19# check if directory exists
20if not os.path.exists(BINARY_PATH):
21 os.mkdir(BINARY_PATH)
22elif not os.path.isdir(BINARY_PATH):
23 raise FileExistsError("'{}' is not a directory.".format(BINARY_PATH))
24
25if(sys.argv[-1] == '0'):
26
27 LINKER_PATH = sys.argv[1]
28
29 #generate source file list for gcc call
30 source_file_args = ""
31 for arg_idx in range(2, len(sys.argv[:-1]) - 1):
32 source_file_args += (sys.argv[arg_idx])
33 source_file_args += " "
34
35 compiler_flags = sys.argv[len(sys.argv) - 2]
36 # build the ARM binary
37 sub.run(
38 f"arm-none-eabi-gcc {compiler_flags} -Wl,-T{LINKER_PATH} -Wl,-Map,{BINARY_PATH}/binary.map -o {BINARY_PATH}/binary.elf {source_file_args}",
39 shell=True,
40 check=True,
41 )
42else:
43 map_path = sys.argv[-3]
44 disassembled_path = sys.argv[-2]
45 elf_path = sys.argv[-4]
46
47 map_name = map_path.rsplit("/", 1)[-1]
48 disassembled_name = disassembled_path.rsplit("/", 1)[-1]
49 elf_name = elf_path.rsplit("/", 1)[-1]
50 #copy to binary directory
51 try:
52 shutil.copyfile(map_path, "../../binary/binary.map")
53 shutil.copyfile(disassembled_path, "../../binary/disassembled.txt")
54 shutil.copyfile(elf_path, "../../binary/binary.elf")
55 except OSError as e:
56 raise FileExistsError("File or directory to program file not found") from e
57
58
59# create disassembly for looking up armory results later
60with open(BINARY_PATH + "/disassembled.txt", "w") as dis_file:
61 sub.run(
62 ["arm-none-eabi-objdump", BINARY_PATH + "/binary.elf", "-d"],
63 stdout=dis_file,
64 check=True,
65 )
66