small blocks in blocks memory map update

This commit is contained in:
Jonathan Herrewijnen 2024-08-25 20:00:07 +02:00
parent 3039e1dbc7
commit df71d537ec
2 changed files with 264 additions and 281 deletions

View File

@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 50,
"execution_count": 180,
"metadata": {},
"outputs": [],
"source": [
@ -20,41 +20,7 @@
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"data = pd.read_csv('stack_and_functions.csv')\n",
"\n",
"def convert_to_int(value):\n",
" try:\n",
" if isinstance(value, str) and value.startswith('0x'):\n",
" return int(value, 16)\n",
" else:\n",
" return int(value)\n",
" except ValueError:\n",
" return value \n",
"\n",
"data.sort_values(by=['start'], inplace=True)\n",
"data['start'] = data['start'].apply(convert_to_int)\n",
"data['end'] = data['end'].apply(convert_to_int)\n",
"\n",
"# Check for overlapping ranges, annotatie row with overlap\n",
"data['overlap'] = False\n",
"for i, row in data.iterrows():\n",
" for j, row2 in data.iterrows():\n",
" if i == j:\n",
" continue\n",
" if row['start'] < row2['end'] and row['end'] > row2['start']:\n",
" data.at[i, 'overlap'] = True\n",
" data.at[j, 'overlap'] = True\n",
" data.at[i, 'overlap_with'] = j"
]
},
{
"cell_type": "code",
"execution_count": 52,
"execution_count": 197,
"metadata": {},
"outputs": [
{
@ -85,6 +51,7 @@
" <th>comment</th>\n",
" <th>overlap</th>\n",
" <th>overlap_with</th>\n",
" <th>size</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
@ -96,7 +63,8 @@
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>True</td>\n",
" <td>4.0</td>\n",
" <td>0.0</td>\n",
" <td>131072</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
@ -107,6 +75,7 @@
" <td>NaN</td>\n",
" <td>True</td>\n",
" <td>0.0</td>\n",
" <td>20480</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
@ -117,6 +86,7 @@
" <td>NaN</td>\n",
" <td>True</td>\n",
" <td>0.0</td>\n",
" <td>20480</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
@ -127,6 +97,7 @@
" <td>NaN</td>\n",
" <td>True</td>\n",
" <td>0.0</td>\n",
" <td>20480</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
@ -137,6 +108,7 @@
" <td>NaN</td>\n",
" <td>True</td>\n",
" <td>0.0</td>\n",
" <td>20480</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
@ -146,7 +118,8 @@
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>False</td>\n",
" <td>NaN</td>\n",
" <td>5.0</td>\n",
" <td>20480</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
@ -156,7 +129,8 @@
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>False</td>\n",
" <td>NaN</td>\n",
" <td>6.0</td>\n",
" <td>8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
@ -165,38 +139,31 @@
" <td>Event buffer pointer</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>True</td>\n",
" <td>8.0</td>\n",
" <td>False</td>\n",
" <td>7.0</td>\n",
" <td>20480</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>33691648</td>\n",
" <td>33712128</td>\n",
" <td>BL1 pointer</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>True</td>\n",
" <td>7.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>33984512</td>\n",
" <td>34004992</td>\n",
" <td>First debugger location</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>True</td>\n",
" <td>10.0</td>\n",
" <td>9.0</td>\n",
" <td>20480</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <th>9</th>\n",
" <td>33992704</td>\n",
" <td>34013184</td>\n",
" <td>End of memory stack</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>True</td>\n",
" <td>9.0</td>\n",
" <td>8.0</td>\n",
" <td>20480</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
@ -212,45 +179,118 @@
"5 2146304 2166784 Frederic Destination pointer NaN NaN \n",
"6 33689440 33689448 Boot USB return address NaN NaN \n",
"7 33691000 33711480 Event buffer pointer NaN NaN \n",
"8 33691648 33712128 BL1 pointer NaN NaN \n",
"9 33984512 34004992 First debugger location NaN NaN \n",
"10 33992704 34013184 End of memory stack NaN NaN \n",
"8 33984512 34004992 First debugger location NaN NaN \n",
"9 33992704 34013184 End of memory stack NaN NaN \n",
"\n",
" overlap overlap_with \n",
"0 True 4.0 \n",
"1 True 0.0 \n",
"2 True 0.0 \n",
"3 True 0.0 \n",
"4 True 0.0 \n",
"5 False NaN \n",
"6 False NaN \n",
"7 True 8.0 \n",
"8 True 7.0 \n",
"9 True 10.0 \n",
"10 True 9.0 "
" overlap overlap_with size \n",
"0 True 0.0 131072 \n",
"1 True 0.0 20480 \n",
"2 True 0.0 20480 \n",
"3 True 0.0 20480 \n",
"4 True 0.0 20480 \n",
"5 False 5.0 20480 \n",
"6 False 6.0 8 \n",
"7 False 7.0 20480 \n",
"8 True 9.0 20480 \n",
"9 True 8.0 20480 "
]
},
"execution_count": 52,
"execution_count": 197,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"data = pd.read_csv('stack_and_functions.csv')\n",
"\n",
"def convert_to_int(value):\n",
" try:\n",
" if isinstance(value, str) and value.startswith('0x'):\n",
" return int(value, 16)\n",
" else:\n",
" return int(value)\n",
" except ValueError:\n",
" return value \n",
"\n",
"data.sort_values(by=['start'], inplace=True)\n",
"data['start'] = data['start'].apply(convert_to_int)\n",
"data['end'] = data['end'].apply(convert_to_int)\n",
"data['overlap'] = False\n",
"\n",
"for i, row in data.iterrows():\n",
" for j, row2 in data.iterrows():\n",
" if i == j:\n",
" continue\n",
" if row['start'] < row2['end'] and row['end'] > row2['start']:\n",
" if row['end'] - row['start'] > row2['end'] - row2['start']:\n",
" continue\n",
" data.at[i, 'overlap'] = True\n",
" data.at[j, 'overlap'] = True\n",
" data.at[i, 'overlap_with'] = j\n",
"\n",
"data['overlap_with'] = data['overlap_with'].fillna(data.index.to_series())\n",
"data['overlap_with'] = data['overlap_with'].astype(float)\n",
"data['size'] = data['end'] - data['start']\n",
"\n",
"data"
]
},
{
"cell_type": "code",
"execution_count": 239,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"np.int64(34013184)"
]
},
"execution_count": 239,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data['end'].iloc[-1]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create stacked block diagram"
"Inherent stacked block diagram"
]
},
{
"cell_type": "code",
"execution_count": 53,
"execution_count": 242,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"8.0\n",
"1.25\n",
"1.25\n",
"1.25\n",
"1.25\n",
"inf\n",
"inf\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/tmp/ipykernel_16763/1983735317.py:29: RuntimeWarning:\n",
"\n",
"divide by zero encountered in scalar divide\n",
"\n"
]
},
{
"data": {
"application/vnd.plotly.v1+json": {
@ -260,7 +300,7 @@
"data": [
{
"marker": {
"color": "#2b5c62"
"color": "#ce2c3c"
},
"mode": "text",
"name": "BootROM",
@ -268,15 +308,15 @@
"textposition": "middle center",
"type": "scatter",
"x": [
1.5
2
],
"y": [
2.2856563094483198
0.5
]
},
{
"marker": {
"color": "#c3bb78"
"color": "#ee6511"
},
"mode": "text",
"name": "BL1 boot entry point",
@ -284,15 +324,15 @@
"textposition": "middle center",
"type": "scatter",
"x": [
0.5
2
],
"y": [
4.928446417247939
1.52
]
},
{
"marker": {
"color": "#086666"
"color": "#157424"
},
"mode": "text",
"name": "Boot USB function",
@ -300,15 +340,15 @@
"textposition": "middle center",
"type": "scatter",
"x": [
1.5
2
],
"y": [
5.64271401395054
2.52
]
},
{
"marker": {
"color": "#9744a8"
"color": "#879ab3"
},
"mode": "text",
"name": "bootrom authentication function",
@ -316,15 +356,15 @@
"textposition": "middle center",
"type": "scatter",
"x": [
1.5
2
],
"y": [
6.356981610653138
3.52
]
},
{
"marker": {
"color": "#331fdf"
"color": "#a4cd2c"
},
"mode": "text",
"name": "BL1 boot function",
@ -332,15 +372,15 @@
"textposition": "middle center",
"type": "scatter",
"x": [
1.5
2
],
"y": [
7.07124920735574
4.52
]
},
{
"marker": {
"color": "#972c60"
"color": "#1b44e8"
},
"mode": "text",
"name": "Frederic Destination pointer",
@ -348,15 +388,15 @@
"textposition": "middle center",
"type": "scatter",
"x": [
1.5
2
],
"y": [
7.7855168040583385
5.5
]
},
{
"marker": {
"color": "#2c2ca0"
"color": "#8be123"
},
"mode": "text",
"name": "Boot USB return address",
@ -364,15 +404,15 @@
"textposition": "middle center",
"type": "scatter",
"x": [
1.5
2
],
"y": [
8.14279010779962
6.5
]
},
{
"marker": {
"color": "#d1058f"
"color": "#d82002"
},
"mode": "text",
"name": "Event buffer pointer",
@ -380,31 +420,15 @@
"textposition": "middle center",
"type": "scatter",
"x": [
1.5
2
],
"y": [
8.500063411540902
7.5
]
},
{
"marker": {
"color": "#7d4052"
},
"mode": "text",
"name": "BL1 pointer",
"text": "BL1 pointer",
"textposition": "middle center",
"type": "scatter",
"x": [
1.5
],
"y": [
9.2143310082435
]
},
{
"marker": {
"color": "#e8bcfa"
"color": "#b60e34"
},
"mode": "text",
"name": "First debugger location",
@ -412,15 +436,15 @@
"textposition": "middle center",
"type": "scatter",
"x": [
1.5
2
],
"y": [
9.928598604946101
8.52
]
},
{
"marker": {
"color": "#81a246"
"color": "#4c0da0"
},
"mode": "text",
"name": "End of memory stack",
@ -428,10 +452,10 @@
"textposition": "middle center",
"type": "scatter",
"x": [
1.5
2
],
"y": [
10.6428662016487
9.52
]
}
],
@ -454,7 +478,20 @@
},
"shapes": [
{
"fillcolor": "#2b5c62",
"fillcolor": "#ce2c3c",
"layer": "below",
"line": {
"width": 2
},
"opacity": 0.5,
"type": "rect",
"x0": 0.9,
"x1": 3.1,
"y0": 0.05,
"y1": 4.95
},
{
"fillcolor": "#ee6511",
"layer": "below",
"line": {
"width": 2
@ -462,25 +499,12 @@
"opacity": 0.5,
"type": "rect",
"x0": 1,
"x1": 2,
"y0": 0,
"y1": 4.5713126188966395
"x1": 3,
"y0": 1.07,
"y1": 1.92
},
{
"fillcolor": "#c3bb78",
"layer": "below",
"line": {
"width": 2
},
"opacity": 0.5,
"type": "rect",
"x0": 0,
"x1": 1,
"y0": 4.5713126188966395,
"y1": 5.285580215599239
},
{
"fillcolor": "#086666",
"fillcolor": "#157424",
"layer": "below",
"line": {
"width": 2
@ -488,12 +512,12 @@
"opacity": 0.5,
"type": "rect",
"x0": 1,
"x1": 2,
"y0": 5.285580215599239,
"y1": 5.999847812301839
"x1": 3,
"y0": 2.07,
"y1": 2.92
},
{
"fillcolor": "#9744a8",
"fillcolor": "#879ab3",
"layer": "below",
"line": {
"width": 2
@ -501,12 +525,12 @@
"opacity": 0.5,
"type": "rect",
"x0": 1,
"x1": 2,
"y0": 5.999847812301839,
"y1": 6.714115409004439
"x1": 3,
"y0": 3.07,
"y1": 3.92
},
{
"fillcolor": "#331fdf",
"fillcolor": "#a4cd2c",
"layer": "below",
"line": {
"width": 2
@ -514,12 +538,12 @@
"opacity": 0.5,
"type": "rect",
"x0": 1,
"x1": 2,
"y0": 6.714115409004439,
"y1": 7.428383005707039
"x1": 3,
"y0": 4.069999999999999,
"y1": 4.92
},
{
"fillcolor": "#972c60",
"fillcolor": "#1b44e8",
"layer": "below",
"line": {
"width": 2
@ -527,12 +551,12 @@
"opacity": 0.5,
"type": "rect",
"x0": 1,
"x1": 2,
"y0": 7.428383005707039,
"y1": 8.142650602409638
"x1": 3,
"y0": 5.05,
"y1": 5.95
},
{
"fillcolor": "#2c2ca0",
"fillcolor": "#8be123",
"layer": "below",
"line": {
"width": 2
@ -540,12 +564,12 @@
"opacity": 0.5,
"type": "rect",
"x0": 1,
"x1": 2,
"y0": 8.142650602409638,
"y1": 8.142929613189601
"x1": 3,
"y0": 6.05,
"y1": 6.95
},
{
"fillcolor": "#d1058f",
"fillcolor": "#d82002",
"layer": "below",
"line": {
"width": 2
@ -553,12 +577,12 @@
"opacity": 0.5,
"type": "rect",
"x0": 1,
"x1": 2,
"y0": 8.142929613189601,
"y1": 8.8571972098922
"x1": 3,
"y0": 7.05,
"y1": 7.95
},
{
"fillcolor": "#7d4052",
"fillcolor": "#b60e34",
"layer": "below",
"line": {
"width": 2
@ -566,12 +590,12 @@
"opacity": 0.5,
"type": "rect",
"x0": 1,
"x1": 2,
"y0": 8.8571972098922,
"y1": 9.5714648065948
"x1": 3,
"y0": 8.07,
"y1": 8.92
},
{
"fillcolor": "#e8bcfa",
"fillcolor": "#4c0da0",
"layer": "below",
"line": {
"width": 2
@ -579,22 +603,9 @@
"opacity": 0.5,
"type": "rect",
"x0": 1,
"x1": 2,
"y0": 9.5714648065948,
"y1": 10.2857324032974
},
{
"fillcolor": "#81a246",
"layer": "below",
"line": {
"width": 2
},
"opacity": 0.5,
"type": "rect",
"x0": 1,
"x1": 2,
"y0": 10.2857324032974,
"y1": 11
"x1": 3,
"y0": 9.07,
"y1": 9.92
}
],
"template": {
@ -1413,18 +1424,20 @@
}
}
},
"width": 1600,
"width": 1200,
"xaxis": {
"range": [
0,
3
4
],
"showgrid": false,
"showticklabels": false,
"tickvals": [
0,
1,
2,
3
3,
4
]
},
"yaxis": {
@ -1432,8 +1445,9 @@
"griddash": "longdashdot",
"gridwidth": 0,
"showgrid": false,
"showticklabels": true,
"ticktext": [
"0x0",
"0x20000<br>0x0",
"0x52c0<br>0x2c0",
"0xb4e0<br>0x64e0",
"0x17848<br>0x12848",
@ -1441,46 +1455,20 @@
"0x211000<br>0x20c000",
"0x2020f68<br>0x2020f60",
"0x2026578<br>0x2021578",
"0x2026800<br>0x2021800",
"0x206e000<br>0x2069000",
"0x2070000<br>0x206b000",
[
"0x0",
"0x20000",
"0x2c0",
"0x52c0",
"0x64e0",
"0xb4e0",
"0x12848",
"0x17848",
"0x19310",
"0x1e310",
"0x20c000",
"0x211000",
"0x2020f60",
"0x2020f68",
"0x2021578",
"0x2026578",
"0x2021800",
"0x2026800",
"0x2069000",
"0x206e000",
"0x206b000",
"0x2070000"
]
"0x2070000<br>0x206b000"
],
"tickvals": [
0,
4.5713126188966395,
5.285580215599239,
5.999847812301839,
6.714115409004439,
7.428383005707039,
8.142650602409638,
8.142929613189601,
8.8571972098922,
9.5714648065948,
10.2857324032974
1,
2,
3,
4,
5,
6,
7,
8,
9
]
}
}
@ -1494,105 +1482,101 @@
"import plotly.graph_objects as go\n",
"import random\n",
"\n",
"data = data.to_dict(orient='records')\n",
"\n",
"# If there is no end, set it to start + 0x1000\n",
"for d in data:\n",
" if 'end' not in d:\n",
" d['end'] = d['start'] + 0x5000\n",
"\n",
"# If there is no start, set it to end - 0x1000\n",
"for d in data:\n",
" if 'start' not in d:\n",
" d['start'] = d['end'] - 0x5000\n",
"\n",
"# Sort the data by start\n",
"data = sorted(data, key=lambda x: x['start'])\n",
"total_used_len = sum([d['end']-d['start'] for d in data]) # Length of all blocks described\n",
"tickpointers = []\n",
"vertical_len = len(data['overlap_with'].unique())\n",
"vertical_gap_percentage = 0.05\n",
"horizontal_gap = 0.1\n",
"\n",
"def random_color():\n",
" return f'#{random.randint(0, 0xFFFFFF):06x}'\n",
"\n",
"# Create a square for each index\n",
"fig = go.Figure()\n",
"for i, d in enumerate(data):\n",
" if i == 0:\n",
" prev_y = 0\n",
" max_y = (prev_y + ((d['end'] - d['start']) / total_used_len))\n",
" fillcolor = random_color()\n",
"\n",
" if d['order'] == \"ENTRY\":\n",
" x0 = 0\n",
" else:\n",
"for i, d in data.iterrows():\n",
" fillcolor = random_color()\n",
" data.at[i, 'fillcolor'] = fillcolor\n",
" \n",
" x0=1\n",
" x1=3\n",
"\n",
" if d['overlap'] == False:\n",
" y0=d['overlap_with']\n",
" y1=d['overlap_with']+1\n",
" elif d['overlap'] == True:\n",
" overlaps = data.loc[data['overlap_with'] == d['overlap_with']].shape[0]\n",
"\n",
" # Calculate relative size of the overlap\n",
" overlap_sizes = data.loc[data['overlap_with'] == d['overlap_with']].iloc[1:]['size'].sum()\n",
" print((d['size']/overlap_sizes)*overlaps)\n",
"\n",
" if d['overlap'] == i+1:\n",
" y0=i\n",
" y1=overlaps+i\n",
" if y1 == vertical_len:\n",
" y1 = vertical_len + vertical_gap_percentage\n",
" x0=x0-horizontal_gap\n",
" x1=x1+horizontal_gap\n",
" else:\n",
" y0=0.02+i\n",
" y1=0.97+i\n",
" else:\n",
" print(f'Something went wrong with {d}. Skipping')\n",
" continue\n",
"\n",
" fig.add_shape(\n",
" type=\"rect\",\n",
" x0=x0,\n",
" y0=prev_y * len(data),\n",
" x1=x0 + 1,\n",
" y1=max_y * len(data),\n",
" x1=x1,\n",
" y0=y0+gap_percentage,\n",
" y1=y1-gap_percentage,\n",
" line=dict(width=2),\n",
" fillcolor=fillcolor,\n",
" opacity=0.5,\n",
" layer=\"below\",\n",
" )\n",
"\n",
" tickpoint = [(prev_y + (max_y - prev_y) / 2) * len(data)]\n",
" tickpointers.extend([prev_y * len(data)])\n",
"\n",
" fig.add_trace(go.Scatter\n",
" (\n",
" x=[x0+0.5],\n",
" y=tickpoint,\n",
" x=[(x0+x1)/2],\n",
" y=[y0+0.5],\n",
" text=d['name'],\n",
" mode=\"text\",\n",
" textposition=\"middle center\",\n",
" name=d['name'],\n",
" # Set color to\n",
" marker=dict(\n",
" color=fillcolor,\n",
" ),\n",
" ))\n",
"\n",
" prev_y = max_y\n",
"\n",
"fig.update_xaxes(\n",
" range=[0, 3],\n",
" tickvals=[0, 1, 2, 3],\n",
" range=[0, 4],\n",
" tickvals=[0, 1, 2, 3, 4],\n",
")\n",
"\n",
"labels = [hex(value) for d in data for value in (d.get('start'), d['end']) if 'end' in d]\n",
"labels = []\n",
"for i, j in zip(data['start'], data['end']):\n",
" labels.append(f'{hex(j)}<br>{hex(i)}')\n",
"\n",
"# If label is not the first in labels or the last entry, merge the label with the next label\n",
"labelset = []\n",
"for i in range(0, len(labels), 2):\n",
" if i == 0:\n",
" labelset.append(labels[i])\n",
" elif i == len(labels) - 1:\n",
" labelset.append(labels[i])\n",
" else:\n",
" labelset.append(f\"{labels[i+1]}<br>{labels[i]}\")\n",
"labelset.append(labels)\n",
"tickpointers = [i for i in range(len(data))]\n",
"\n",
"fig.update_yaxes(\n",
" # tickvals=[i for i in range(len(data)+1)], \n",
" tickvals = tickpointers,\n",
" ticktext=labelset,\n",
" ticktext= labels,\n",
" griddash=\"longdashdot\",\n",
" gridwidth=0,\n",
" gridcolor=\"black\",\n",
" showgrid=False,\n",
" showticklabels=True,\n",
")\n",
"\n",
"fig.update_xaxes(\n",
" # Disable ticks\n",
" showgrid=False,\n",
" showticklabels=False,\n",
")\n",
"\n",
"fig.update_layout(\n",
" width=1600,\n",
" width=1200,\n",
" height=1200,\n",
" autosize=True,\n",
" margin=dict(l=200, r=20, t=20, b=20),\n",

View File

@ -7,6 +7,5 @@ start,end,name,order,comment
2146304,2166784,Frederic Destination pointer,,
33689440,33689448,Boot USB return address,,
33691000,33711480,Event buffer pointer,,
33691648,33712128,BL1 pointer,,
33984512,34004992,First debugger location,,
33992704,34013184,End of memory stack,,

1 start end name order comment
7 2146304 2166784 Frederic Destination pointer
8 33689440 33689448 Boot USB return address
9 33691000 33711480 Event buffer pointer
33691648 33712128 BL1 pointer
10 33984512 34004992 First debugger location
11 33992704 34013184 End of memory stack