Skip to content
Snippets Groups Projects
Commit 437bacbc authored by dam1n19's avatar dam1n19
Browse files

SOC1-167: Removed compiled files from repo and created python-based bootrom...

SOC1-167: Removed compiled files from repo and created python-based bootrom generation script to allow for compilation of new bootrom before simulation
parent 77ce3e16
Branches
Tags
No related merge requests found
Showing
with 141 additions and 10496 deletions
......@@ -8,11 +8,11 @@
/software/*/*.o
# Compile Test Code Removal
/system/testcodes/*/*.elf
/system/testcodes/*/*.ELF
/system/testcodes/*/*.hex
/system/testcodes/*/*.lst
/system/testcodes/*/*.o
system/testcodes/*/*.elf
system/testcodes/*/*.ELF
system/testcodes/*/*.hex
system/testcodes/*/*.lst
system/testcodes/*/*.o
# Bootrom removal
/system/src/bootrom/verilog/*
......
......@@ -32,7 +32,7 @@
CPU_PRODUCT = CORTEX_M0
# Shared software directory
SOFTWARE_DIR = ../../../../software
SOFTWARE_DIR = $(NANOSOC_TECH_DIR)/software
CMSIS_DIR = $(SOFTWARE_DIR)/cmsis
CORE_DIR = $(CMSIS_DIR)/CMSIS/Include
......
......@@ -80,6 +80,10 @@ else
MEM_INIT :=
endif
# Bootrom Parameters:
BOOTROM_ADDRW ?= 8
BOOTROM_HEX ?= $(NANOSOC_TECH_DIR)/system/testcodes/bootloader/bootloader.hex
ADP_PATH := $(shell realpath $(ADP_FILE))
ADP_OPTIONS := -define ADP_FILE=\"$(ADP_PATH)\"
......@@ -191,22 +195,10 @@ run_xm : code compile_xm
@if [ ! -d $(SIM_DIR)/logs ] ; then \
mkdir $(SIM_DIR)/logs; \
fi
# Bootrom generation
ifneq ($(BOOTROM_GEN),)
# Create directories for bootrom for this simulation
mkdir -p $(SIM_DIR)/bootrom/hex/
mkdir -p $(SIM_DIR)/bootrom/verilog/
mkdir -p $(SIM_DIR)/bootrom/bintxt/
# Copy bootrom hex to simulaiton directory
cp $(TESTCODES_DIR)/bootloader/bootloader.hex $(SIM_DIR)/bootrom/hex/
endif
@echo run > $(SIM_DIR)/run.tcl.tmp
@echo exit >> $(SIM_DIR)/run.tcl.tmp
@mv $(SIM_DIR)/run.tcl.tmp $(SIM_DIR)/run.tcl
cd $(SIM_DIR); xmsim $(XMSIM_OPTIONS) -input run.tcl | tee logs/run_$(TESTNAME).log ;
ifneq ($(BOOTROM_GEN),)
cp -r $(SIM_DIR)/bootrom $(PROJ_SYS_DIR)
endif
# @make verify
# Run simulation in interactive mode
......@@ -308,6 +300,9 @@ bootrom:
fi ;\
fi ;\
cp $(BOOTLOADER).hex $(SIM_DIR)/$(BOOTLOADER).hex ;\
mkdir -p $(PROJ_SYS_DIR)/bootrom/verilog/ ;\
mkdir -p $(PROJ_SYS_DIR)/bootrom/bintxt/ ;\
python3 bootrom_gen.py -a $(BOOTROM_ADDRW) -i $(BOOTLOADER).hex -v $(PROJ_SYS_DIR)/bootrom/verilog/bootrom.v -b $(PROJ_SYS_DIR)/bootrom/bintxt/bootrom.bintxt ;\
cd $(SIM_DIR) )
# Compile test code
......
......@@ -32,7 +32,7 @@
CPU_PRODUCT = CORTEX_M0PLUS
# Shared software directory
SOFTWARE_DIR = ../../../../software
SOFTWARE_DIR = $(NANOSOC_TECH_DIR)/software
CMSIS_DIR = $(SOFTWARE_DIR)/cmsis
CORE_DIR = $(CMSIS_DIR)/CMSIS/Include
......
File deleted
68
03
00
30
35
03
00
10
3D
03
00
10
3F
03
00
10
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
00
41
03
00
10
00
00
00
00
00
00
00
00
43
03
00
10
45
03
00
10
47
03
00
10
47
03
00
10
47
03
00
10
47
03
00
10
47
03
00
10
47
03
00
10
47
03
00
10
47
03
00
10
47
03
00
10
47
03
00
10
47
03
00
10
47
03
00
10
47
03
00
10
47
03
00
10
47
03
00
10
47
03
00
10
47
03
00
10
47
03
00
10
47
03
00
10
47
03
00
10
47
03
00
10
47
03
00
10
47
03
00
10
47
03
00
10
47
03
00
10
47
03
00
10
47
03
00
10
47
03
00
10
47
03
00
10
47
03
00
10
47
03
00
10
47
03
00
10
00
F0
02
F8
00
F0
3E
F8
0C
A0
30
C8
08
38
24
18
2D
18
A2
46
67
1E
AB
46
54
46
5D
46
AC
42
01
D1
00
F0
30
F8
7E
46
0F
3E
0F
CC
B6
46
01
26
33
42
00
D0
FB
1A
A2
46
AB
46
33
43
18
47
DC
02
00
00
FC
02
00
00
10
3A
02
D3
78
C8
78
C1
FA
D8
52
07
01
D3
30
C8
30
C1
01
D5
04
68
0C
60
70
47
00
00
00
23
00
24
00
25
00
26
10
3A
01
D3
78
C1
FB
D8
52
07
00
D3
30
C1
00
D5
0B
60
70
47
1F
B5
1F
BD
10
B5
10
BD
00
F0
15
F9
11
46
FF
F7
F7
FF
00
F0
68
F8
00
F0
2D
F9
03
B4
FF
F7
F2
FF
03
BC
00
F0
33
F9
00
00
00
20
01
68
8D
46
41
68
08
47
00
00
41
21
53
48
49
01
01
61
01
21
81
60
51
48
81
60
51
49
20
20
88
61
70
47
4E
49
4A
68
D2
07
FC
D1
4A
68
D2
07
00
D1
08
60
70
47
4A
49
03
78
00
2B
09
D0
4A
68
D2
07
FC
D1
4A
68
D2
07
00
D1
0B
60
40
1C
00
2B
F2
D1
70
47
10
B5
44
4C
21
68
41
48
00
29
0A
D0
42
A3
1A
78
00
2A
21
D0
41
68
C9
07
FC
D1
41
68
C9
07
17
D0
17
E0
41
A3
1A
78
00
2A
09
D0
41
68
C9
07
FC
D1
41
68
C9
07
00
D1
02
60
5B
1C
00
2A
F2
D1
04
22
41
68
C9
07
FC
D1
41
68
C9
07
00
D1
02
60
FE
E7
02
60
5B
1C
00
2A
DA
D1
00
20
20
60
BF
F3
4F
8F
BF
F3
6F
8F
FF
F7
A2
FF
10
BD
10
B5
41
21
26
48
49
01
01
61
01
21
81
60
24
48
81
60
24
4A
20
21
91
61
2F
A3
1A
78
00
2A
09
D0
41
68
C9
07
FC
D1
41
68
C9
07
00
D1
02
60
5B
1C
00
2A
F2
D1
1D
4C
21
68
00
29
0A
D0
1C
A3
1A
78
00
2A
21
D0
41
68
C9
07
FC
D1
41
68
C9
07
17
D0
17
E0
1A
A3
1A
78
00
2A
09
D0
41
68
C9
07
FC
D1
41
68
C9
07
00
D1
02
60
5B
1C
00
2A
F2
D1
04
22
41
68
C9
07
FC
D1
41
68
C9
07
00
D1
02
60
FE
E7
02
60
5B
1C
00
2A
DA
D1
00
20
20
60
BF
F3
4F
8F
BF
F3
6F
8F
FF
F7
55
FF
00
20
10
BD
00
00
00
60
00
40
00
E0
00
40
00
10
01
40
00
F0
01
40
2A
2A
20
52
65
6D
61
70
2D
3E
52
41
4D
32
0A
00
40
45
72
72
6F
72
3A
20
52
45
4D
41
50
20
63
6C
65
61
72
65
64
0A
00
00
0A
0A
0A
53
4F
43
4C
41
42
53
3A
20
41
52
4D
20
43
6F
72
74
65
78
2D
4D
30
20
6E
61
6E
6F
73
6F
63
0A
00
00
04
49
03
48
08
60
70
47
02
49
01
48
08
60
70
47
00
E1
F5
05
00
00
00
30
07
48
80
47
07
48
00
47
FE
E7
FE
E7
FE
E7
FE
E7
FE
E7
FE
E7
04
48
05
49
05
4A
06
4B
70
47
00
00
25
03
00
10
C1
00
00
10
68
00
00
30
68
03
00
30
68
01
00
30
68
01
00
30
70
47
70
47
70
47
75
46
00
F0
24
F8
AE
46
05
00
69
46
53
46
C0
08
C0
00
85
46
18
B0
20
B5
FF
F7
DD
FF
60
BC
00
27
49
08
B6
46
00
26
C0
C5
C0
C5
C0
C5
C0
C5
C0
C5
C0
C5
C0
C5
C0
C5
40
3D
49
00
8D
46
70
47
10
B5
04
46
C0
46
C0
46
20
46
FF
F7
CC
FE
10
BD
00
48
70
47
04
00
00
30
01
49
18
20
AB
BE
FE
E7
26
00
02
00
70
47
00
00
F8
03
00
10
00
00
00
30
04
00
00
00
04
01
00
10
FC
03
00
10
04
00
00
30
64
03
00
00
20
01
00
10
00
E1
F5
05
This diff is collapsed.
File deleted
#!/usr/bin/env python3
#------------------------------------------------------------------------------------
# Verilog and Binary Bootrom Generation Script
# A joint work commissioned on behalf of SoC Labs, under Arm Academic Access license.
#
# Contributors
#
# David Mapstone (d.a.mapstone@soton.ac.uk)
# Copyright (c) 2023, SoC Labs (www.soclabs.org)
#------------------------------------------------------------------------------------
import argparse
import math
from string import Template
from datetime import datetime
v_template_head = f"""//------------------------------------------------------------------------------------
// Auto-generated synthesizable Bootrom
//
// Generated from bootrom_gen.py
//
// A joint work commissioned on behalf of SoC Labs, under Arm Academic Access license.
//
// Contributors
//
// David Flynn (d.w.flynn@soton.ac.uk)
// Date: $date
// Copyright (c) 2021-3, SoC Labs (www.soclabs.org)
//------------------------------------------------------------------------------------
module bootrom (
input wire CLK,
input wire EN,
input wire [$address_width:2] ADDR,
output reg [31:0] RDATA );
reg [$address_width:2] addr_r;
always @(posedge CLK) if (EN) addr_r <= ADDR;
always @(addr_r)
case(addr_r[$address_width:2])
"""
v_template_foot = """ default : RDATA <=32'h0;
endcase
endmodule"""
def bootrom_gen(args):
# Extract Data from Parsed Arguments
input_hex = args.input_hex
address_width = args.address_width
output_verilog = args.verilog_output
output_binary = args.binary_output
# Create Binary and Verilog Outputs
print(f"Generating Bootrom {input_hex}")
bootrom_verilog, bootrom_binary = output_construct(input_hex, address_width)
# Write Out Verilog File
f_verilog = open(output_verilog, "w")
f_verilog.write(bootrom_verilog)
f_verilog.close()
# Write Out Binary File
f_binary = open(output_binary, "w")
f_binary.write(bootrom_binary)
f_binary.close()
def output_construct(input_hex, address_width):
# Read in Hex File
f = open(input_hex, "r")
hex_bytes = f.readlines()
f.close()
# Number of bytes expected depending on address_width
address_bytes = 1 << (address_width + 2)
# Fill hex_bytes with zeros for addresses than aren't in the hex file
while (len(hex_bytes) < address_bytes): hex_bytes.append("00")
hex_words = math.ceil(len(hex_bytes)/4)
hex_data = []
# Combine bytes into words
for i in range(hex_words):
temp_hex_word= f"{hex_bytes[i*4+3].rstrip()}{hex_bytes[(i*4)+2].rstrip()}{hex_bytes[(i*4)+1].rstrip()}{hex_bytes[(i*4)].rstrip()}"
hex_data.append(int(temp_hex_word, 16))
# Get Date and Time to put in Generated Header
date_str = datetime.today().strftime('%Y-%m-%d %H:%M:%S')
# Generate Verilog Header from Template
temp_bootrom_obj = Template(v_template_head)
temp_verilog = temp_bootrom_obj.substitute(
address_width=address_width+1,
date=date_str
)
bootrom_verilog = temp_verilog
bootrom_binary = ""
# Append Hex Data to File
for i, word in enumerate(hex_data):
if address_width > 8:
temp_verilog = f""" {address_width:d}'h{i:03x} : RDATA <= 32'h{word:08x}; // 0x{i*4:04x}\n"""
else:
temp_verilog = f""" {address_width:d}'h{i:02x} : RDATA <= 32'h{word:08x}; // 0x{i*4:04x}\n"""
temp_binary = f"""{word:032b}\n"""
bootrom_verilog += temp_verilog
bootrom_binary += temp_binary
# Append footer to Verilog file
bootrom_verilog += v_template_foot
return bootrom_verilog, bootrom_binary
if __name__ == "__main__":
# Capture Arguments from Command Line
parser = argparse.ArgumentParser(description='Generates NanoSoC CPU Bootrom File')
parser.add_argument("-i", "--input_hex", type=str, help="Input Hex File to Generate Bootrom from")
parser.add_argument("-a", "--address_width", type=int, help="Address Width (In 32bit Words) of Bootrom")
parser.add_argument("-v", "--verilog_output", type=str, help="Output Bootrom verilog file")
parser.add_argument("-b", "--binary_output", type=str, help="Output Bootrom binary file")
args = parser.parse_args()
bootrom_gen(args)
\ No newline at end of file
......@@ -6,7 +6,7 @@
#//
#// David Flynn (d.w.flynn@soton.ac.uk)
#//
#// Copyright 2021-3, SoC Labs (www.soclabs.org)
#// Copyright 2021-3, SoC Labs (www.soclabs.org)
#//-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
......@@ -43,7 +43,7 @@
CPU_PRODUCT = CORTEX_M0
# Shared software directory
SOFTWARE_DIR = ../../../../software
SOFTWARE_DIR = $(NANOSOC_TECH_DIR)/software
CMSIS_DIR = $(SOFTWARE_DIR)/cmsis
CORE_DIR = $(CMSIS_DIR)/CMSIS/Include
......
File deleted
File deleted
......@@ -32,7 +32,7 @@
CPU_PRODUCT = CORTEX_M0
# Shared software directory
SOFTWARE_DIR = ../../../../software
SOFTWARE_DIR = $(NANOSOC_TECH_DIR)/software
CMSIS_DIR = $(SOFTWARE_DIR)/cmsis
CORE_DIR = $(CMSIS_DIR)/CMSIS/Include
GENERIC_DIR = ../generic
......
......@@ -32,7 +32,7 @@ CPU_PRODUCT = CORTEX_M0PLUS
# Shared software directory
# Shared software directory
SOFTWARE_DIR = ../../../../software
SOFTWARE_DIR = $(NANOSOC_TECH_DIR)/software
CMSIS_DIR = $(SOFTWARE_DIR)/cmsis
CORE_DIR = $(CMSIS_DIR)/CMSIS/Include
......
File deleted
This diff is collapsed.
This diff is collapsed.
File deleted
File deleted
......@@ -32,7 +32,7 @@ CPU_PRODUCT = CORTEX_M0PLUS
# Shared software directory
# Shared software directory
SOFTWARE_DIR = ../../../../software
SOFTWARE_DIR = $(NANOSOC_TECH_DIR)/software
CMSIS_DIR = $(SOFTWARE_DIR)/cmsis
CORE_DIR = $(CMSIS_DIR)/CMSIS/Include
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment