Updating memory drawer.

This commit is contained in:
Jonathan Herrewijnen 2024-09-14 16:40:44 +02:00
parent 13f080e111
commit 2e7700c54c
3 changed files with 140 additions and 80 deletions

View File

@ -4,6 +4,16 @@ import random, argparse
import numpy as np import numpy as np
import pandas as pd import pandas as pd
"""
This script reads a CSV file with the following columns: start,end,name,order,comment,X0,LR
- name: Name of the function or location (Required)
- start: Start address of the function or location (Required)
- end: End address of the function or location (Required)
Then it generates a memory map of the regions, and outputs an HTML file with the memory map.
"""
def read_data(input_file): def read_data(input_file):
data = pd.read_csv(input_file) data = pd.read_csv(input_file)
@ -20,8 +30,8 @@ def read_data(input_file):
data['end'] = data['end'].apply(convert_to_int) data['end'] = data['end'].apply(convert_to_int)
data['size'] = data['end'] - data['start'] data['size'] = data['end'] - data['start']
data.sort_values(by=['size'], inplace=True, ascending=False) #data.sort_values(by=['size'], inplace=True, ascending=False)
data.sort_values(by=['start'], inplace=True) data.sort_values(by=['start', 'size'], inplace=True, ascending=True)
# Inverse the order of the data # Inverse the order of the data
data.reset_index(drop=True, inplace=True) data.reset_index(drop=True, inplace=True)
@ -30,15 +40,32 @@ def read_data(input_file):
data['index'] = data.index data['index'] = data.index
for i, row in data.iterrows(): for i, row in data.iterrows():
# Annotate rows that overlap with each other
temp = data.loc[(data['start'] <= row['start']) & (data['end'] >= row['end'])]
data.at[i, 'overlap'] = False data.at[i, 'overlap'] = False
data.at[i, 'partial_overlap'] = False
# Annotate rows that fully overlap the current row
temp = data.loc[(data['start'] <= row['start']) & (data['end'] >= row['end'])]
if temp.shape[0] > 1: if temp.shape[0] > 1:
data.at[i, 'overlap'] = True data.at[i, 'overlap'] = True
# Increment the overlap_with column, with the value of of the column 'index' of the row, and allow multiple overlaps data.at[i, 'overlapped_by'] = ','.join(temp['index'].astype(str).to_list())
data.at[i, 'overlap_with'] = ','.join(temp['index'].astype(str).to_list())
data.at[i, 'overlap_with'] = True # Annotate rows that partially overlap the current row (from start, but not to end)
temp = data.loc[(data['start'] <= row['start']) & (data['end'] < row['end']) & (data['end'] >= row['start'])]
if temp.shape[0] > 1:
data.at[i, 'partial_overlap'] = "Bottom"
data.at[i, 'partial_overlapped_by'] = ','.join(temp['index'].astype(str).to_list())
# Annotate rows that partially overlap the current row (from end, but not to start)
temp = data.loc[(data['start'] > row['start']) & (data['end'] >= row['end']) & (data['start'] <= row['end'])]
if temp.shape[0] > 1:
data.at[i, 'partial_overlap'] = "Top"
data.at[i, 'partial_overlapped_by'] = ','.join(temp['index'].astype(str).to_list())
# Also annotate which regions this row is overlapping
temp = data.loc[(data['start'] >= row['start']) & (data['end'] <= row['end'])]
if temp.shape[0] > 1:
data.at[i, 'overlap'] = True
data.at[i, 'overlapping'] = ','.join(temp['index'].astype(str).to_list())
# Send warnings if sizes are negative # Send warnings if sizes are negative
if (data['size'] < 0).any(): if (data['size'] < 0).any():
@ -47,48 +74,55 @@ def read_data(input_file):
return data return data
def draw_diagram(data): def draw_diagram(data, vertical_gap_percentage=0.08, horizontal_gap=0.1):
tickpointers = [] tickpointers = []
vertical_len = len(data['overlap_with'].unique())
vertical_gap_percentage = 0.08
horizontal_gap = 0.1
labels = pd.DataFrame() labels = pd.DataFrame()
def random_color(): def random_color():
return f'#{random.randint(0, 0xFFFFFF):06x}' return f'#{random.randint(0, 0xFFFFFF):06x}'
fig = go.Figure() fig = go.Figure()
fig.update_layout(font=dict(family="Courier New, monospace"))
fig.update_layout(
plot_bgcolor='#FFFFFF',
)
for i, d in data.iterrows(): for i, d in data.iterrows():
fillcolor = random_color() fillcolor = random_color()
data.at[i, 'fillcolor'] = fillcolor data.at[i, 'fillcolor'] = fillcolor
# Set base x values. Width of the rectangle.
x0 = 1 x0 = 1
x1=4 x1 = 6
if d['overlap'] == False: # Set base y values. Height of the rectangle.
y0=d['overlap_with'] y0 = d['index']
y1=d['overlap_with']+1 y1 = d['index']+1
elif d['overlap'] == True:
overlaps = data.loc[data['overlap_with'] == d['overlap_with']].shape[0]
# Calculate relative size of the overlap if d['overlap'] == True:
overlap_sizes = data.loc[data['overlap_with'] == d['overlap_with']].iloc[1:]['size'].sum() # Row is overlapping the current row
if pd.notna(d['overlapping']):
y0 = sorted(map(int, d['overlapping'].split(',')))[0]
y1 = sorted(map(int, d['overlapping'].split(',')))[-1] + 1
if d['overlap_with'] == i: if pd.notna(d['overlapped_by']):
y0=i y0 = y0 + vertical_gap_percentage
y1=overlaps+i y1 = y1 - vertical_gap_percentage
if i != data.shape[0]+1: x0 = x0 + horizontal_gap
if d['end'] > data.iloc[i+1].start and d['end'] < data.iloc[i+1].end: x1 = x1 - horizontal_gap
y1=overlaps+i-0.5
x0=x0-horizontal_gap if d['partial_overlap'] == "Bottom":
x1=x1+horizontal_gap if pd.notna(d['partial_overlapped_by']):
else: y0 = y0 + 0.25 + (0.6**len(d['partial_overlapped_by'].split(',')))
y0=0.02+i #x0 = x0 + horizontal_gap
y1=0.87+i #x1 = x1 - horizontal_gap
else:
print(f'Something went wrong with {d}. Skipping') if d['partial_overlap'] == "Top":
continue if pd.notna(d['partial_overlapped_by']):
y1 = y1 - (0.6**len(d['partial_overlapped_by'].split(',')))
#x0 = x0 + horizontal_gap
#x1 = x1 - horizontal_gap
fig.add_shape( fig.add_shape(
type="rect", type="rect",
@ -96,17 +130,17 @@ def draw_diagram(data):
x1=x1, x1=x1,
y0=y0+vertical_gap_percentage, y0=y0+vertical_gap_percentage,
y1=y1-vertical_gap_percentage, y1=y1-vertical_gap_percentage,
line=dict(width=2), line=dict(width=1),
fillcolor=fillcolor, fillcolor=fillcolor,
opacity=0.5, opacity=0.4,
layer="below", layer="below",
) )
# Add middle text ### Add middle text
fig.add_trace(go.Scatter fig.add_trace(go.Scatter
( (
x=[(x0+x1)/2], x=[(x0+x1)/2],
y=[y0+0.5], y=[i+0.5],
text=d['name'], text=d['name'],
mode="text", mode="text",
textposition="middle center", textposition="middle center",
@ -116,7 +150,36 @@ def draw_diagram(data):
), ),
)) ))
# Add top-left text with d['end'] ### Add top-left text with d['end']
# Overlapped to the right, to make it more readable
if pd.notna(d['overlapped_by']):
fig.add_trace(go.Scatter
(
x=[(x1-0.24+horizontal_gap)],
y=[y1-0.16],
text=hex(d['end']),
mode="text",
textposition="middle center",
marker=dict(
color=fillcolor,
),
showlegend=False,
))
# Add bottom-left text with d['end']
fig.add_trace(go.Scatter
(
x=[(x1-0.24+horizontal_gap)],
y=[y0+0.14],
text=hex(d['start']),
mode="text",
textposition="middle center",
marker=dict(
color=fillcolor,
),
showlegend=False,
))
else:
fig.add_trace(go.Scatter fig.add_trace(go.Scatter
( (
x=[(x0+0.14+horizontal_gap)], x=[(x0+0.14+horizontal_gap)],
@ -130,7 +193,7 @@ def draw_diagram(data):
showlegend=False, showlegend=False,
)) ))
# Add bottom-left text with d['end'] ### Add bottom-left text with d['end']
fig.add_trace(go.Scatter fig.add_trace(go.Scatter
( (
x=[(x0+0.14+horizontal_gap)], x=[(x0+0.14+horizontal_gap)],
@ -145,8 +208,8 @@ def draw_diagram(data):
)) ))
fig.update_xaxes( fig.update_xaxes(
range=[0, 5], range=[0, 7],
tickvals=[0, 1, 2, 3, 4, 5], tickvals=[0, 1, 2, 3, 4, 5, 6, 7],
) )
start_values = data['start'].sort_values() start_values = data['start'].sort_values()
@ -167,12 +230,12 @@ def draw_diagram(data):
fig.update_yaxes( fig.update_yaxes(
# tickvals=[i for i in range(len(data)+1)], # tickvals=[i for i in range(len(data)+1)],
tickvals = tickpointers, tickvals = tickpointers,
# ticktext= labels, #ticktext= labels, # Adds labels to the left-hand side of the graph
griddash="longdashdot", griddash="longdashdot",
gridwidth=0, gridwidth=0,
gridcolor="black", gridcolor="black",
showgrid=False, showgrid=False,
showticklabels=True, showticklabels=False,
autorange='reversed', autorange='reversed',
) )
@ -189,7 +252,6 @@ def draw_diagram(data):
font=dict( font=dict(
size=18, size=18,
), ),
# Legend being the name of the function
legend_title_text="Function/Locations", legend_title_text="Function/Locations",
) )

File diff suppressed because one or more lines are too long

View File

@ -5,18 +5,16 @@ start,end,name,order,comment,X0,LR
0x000064e0,0x0000658c,_boot_usb,,,, 0x000064e0,0x0000658c,_boot_usb,,,,
0x020c0000,0x020c0004,_frederic_dest_ptr,,,, 0x020c0000,0x020c0004,_frederic_dest_ptr,,,,
0x000002c0,0x000002c4,_jump_bl1,,,, 0x000002c0,0x000002c4,_jump_bl1,,,,
0x02022000,0x02024000,BL1,,,, 0x02022000,0x02023fff,BL1,,,,
0x02024000,0x02048000,BL31,,,, 0x02024000,0x02047fff,BL31,,,,
0x02048000,0x0206ed10,BL2,,,, 0x02048000,0x0206ed10,BL2,,,,
0x02069000,0x0206f000,Debugger,,,, 0x02069000,0x0206f000,Debugger,,,,
0x020c0000,0x020c7000,Debugger relocated,,,, 0x020c0000,0x020c7000,Debugger relocated,,,,
0x02048000,0x0204daf0,BL2 empty space?,,,, 0x02048000,0x0204daf0,BL2 empty space?,,,,
0x0204eb00,0x0204eb00,BL2 copy start/source,,,, 0x020c2000,0x020e8d10,BL2 loaded to this address,,,,
0x020c2000,0x020e8d10,BL2 load address?,,,, 0x0206ed10,0x02070000,Open space. Has pointers written to.,,,,
0x0206ed10,0x02070000,End/Start peripheral space?,,,,
0x02019e5c,0x02020e5c,Tried debugger space,,,,
0x020C7800,0x020C8000,modem_interface,,,, 0x020C7800,0x020C8000,modem_interface,,,,
0x14AC0000,0x14ac5000,mali@14AC0000,,,, 0x14AC0000,0x14ac5000,mali@14AC0000,,,,
0x02035600,0x02035608,TTBR0_EL3 address ptr,,,, 0x02035600,0x02035608,TTBR0_EL3,,,,
0x11207010,0x11207010,memread/write space,,,, 0x11200000,0x11207000,Last relocated debugger,,,,
0xa0000000,0xa0013fff,Parts of BL2,,,, 0xa0000000,0xa0013fff,Parts of BL2 in IMEM,,,,
1 start end name order comment X0 LR
5 0x000064e0 0x0000658c _boot_usb
6 0x020c0000 0x020c0004 _frederic_dest_ptr
7 0x000002c0 0x000002c4 _jump_bl1
8 0x02022000 0x02024000 0x02023fff BL1
9 0x02024000 0x02048000 0x02047fff BL31
10 0x02048000 0x0206ed10 BL2
11 0x02069000 0x0206f000 Debugger
12 0x020c0000 0x020c7000 Debugger relocated
13 0x02048000 0x0204daf0 BL2 empty space?
14 0x0204eb00 0x020c2000 0x0204eb00 0x020e8d10 BL2 copy start/source BL2 loaded to this address
15 0x020c2000 0x0206ed10 0x020e8d10 0x02070000 BL2 load address? Open space. Has pointers written to.
0x0206ed10 0x02070000 End/Start peripheral space?
0x02019e5c 0x02020e5c Tried debugger space
16 0x020C7800 0x020C8000 modem_interface
17 0x14AC0000 0x14ac5000 mali@14AC0000
18 0x02035600 0x02035608 TTBR0_EL3 address ptr TTBR0_EL3
19 0x11207010 0x11200000 0x11207010 0x11207000 memread/write space Last relocated debugger
20 0xa0000000 0xa0013fff Parts of BL2 Parts of BL2 in IMEM