Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ when W110 puts the regions in zooms of their own, their groups get a note instea
## Recipes
- Show sizes: view.defaults.labels.size: true
- Boundary + prev end: view.defaults.labels.address: both
- Hide addresses: view.defaults.labels.address: none
- Zoom into a region: view.expand: [region_id]
- Title a column: view.columns: [{ id: a, root: flash, title: Flash }]
- Title a zoom: view.expand: [{ region: flash, title: Flash }]
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ scripts and agents.
| [nrf52840_boot_chain.yaml](examples/nrf52840_boot_chain.yaml) | Chained zooms, column `range`, per-column labels and scale, `start_of_next` |
| [riscv64_soc.yaml](examples/riscv64_soc.yaml) | 64-bit addresses, `collapse_reserved_over`, relative heights, style options |
| [rtos_mpu_ram.yaml](examples/rtos_mpu_ram.yaml) | `check_alignment`, `fill_gaps: none`, `depth`, two columns of one memory |
| [ota_package_format.yaml](examples/ota_package_format.yaml) | A file format instead of memory: `address: none`, byte sizes, a zoom to the left |

To render them all into `build/`:

Expand Down
42 changes: 42 additions & 0 deletions examples/ota_package_format.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# File format, not memory: an OTA update package as it is sent to the device.
# Only the order and size of the fields matter, so the addresses (file offsets) are hidden.
version: 1
figure: { title: "OTA update package format", legend: true }

memory:
regions:
- id: package
name: Update package
start: 0
size: 256K
children: # placed sequentially from offset 0
- id: header
name: Header
size: 64
color: "#e07a5f"
children:
- { id: magic, name: Magic "OTA1", size: 4 }
- { id: fmt_version, name: Format version, size: 2 }
- { id: flags, name: Flags, size: 2 }
- { id: img_version, name: Image version, size: 4 }
- { id: payload_size, name: Payload size, size: 4 }
- { id: payload_hash, name: Payload SHA-256, size: 32 }
- { id: header_crc, name: Header CRC32, size: 4 }
- { id: hdr_reserved, name: Reserved, size: auto }
- { id: manifest, name: Manifest, size: 448, color: "#f2cc8f", note: "CBOR, padded" }
- { id: signature, name: Signature, size: 512, color: "#9fb3c8", note: "RSA-4096 over header + manifest" }
- { id: payload, name: Payload, size: auto, color: "#81b29a", note: "LZ4-compressed image" }

view:
defaults:
labels:
address: none # offsets do not matter here, only order and size
size: true
scale: { mode: weighted, min_height: 30 }
columns: # zoom on the left, as the notes take the right
- { id: header_col, root: header, title: Header fields, lane: 0, offset: 40 }
- { id: package_col, root: package, title: Package, lane: 1 }
expand:
- { region: header, from: package_col, to: header_col }

style: { palette: color }
9 changes: 7 additions & 2 deletions memmap/layout/labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ def build_labels(
blocks: list[Block], band_starts: set[int], mode: str, address_bits: int
) -> list[AddressLabel]:
"""All address labels of one column, bottom to top. In a column with bands only the band
boundaries, the column ends and overridden edges are labelled."""
boundaries, the column ends and overridden edges are labelled. With mode `none` only the
overridden edges are."""
labels: list[AddressLabel] = []
last_address = 2**address_bits - 1
hidden = mode == "none"

def add(values: list[tuple[int, str, str]], edge: int, region: str) -> None:
"""Turn (value, role, placement) entries into labels on `edge`."""
Expand All @@ -65,13 +67,16 @@ def add(values: list[tuple[int, str, str]], edge: int, region: str) -> None:

if not blocks:
return labels
add([(blocks[0].start, "start", "center")], 0, blocks[0].node.id)
if not hidden:
add([(blocks[0].start, "start", "center")], 0, blocks[0].node.id)

for index, lower in enumerate(blocks):
upper = blocks[index + 1] if index + 1 < len(blocks) else None
top_of_space = upper is None and lower.end == last_address
if lower.top_label is not None:
values = _override_values(lower, upper, lower.top_label, top_of_space)
elif hidden:
values = []
elif upper is None:
values = [(lower.end, "end", "center")]
elif band_starts and upper.start not in band_starts:
Expand Down
5 changes: 3 additions & 2 deletions memmap/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,12 @@ class Memory(Model):
class Labels(Model):
"""Address and size labels."""

address: Literal["start", "both"] = Field(
address: Literal["start", "both", "none"] = Field(
default="start",
description=(
"What an internal edge prints: the boundary, or boundary and previous end. An edge "
"with unfilled space at it always prints both."
"with unfilled space at it always prints both. none prints no addresses, except on "
"edges with a top_label override."
),
examples=["both"],
)
Expand Down
48 changes: 48 additions & 0 deletions tests/golden/example_ota_package.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ def test_group_help_points_to_the_guide():
[
["view.defaults.labels.size=true"],
["view.defaults.labels.address=both"],
["view.defaults.labels.address=none"],
["view.columns[0]={id: a, root: /}", "view.expand=[flash]"],
["view.columns[0]={id: a, root: flash, title: Flash}"],
["view.columns[0]={id: a, root: /}", "view.expand=[{region: flash, title: Flash}]"],
Expand Down
1 change: 1 addition & 0 deletions tests/test_golden.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"example_nrf52840": (ROOT / "examples" / "nrf52840_boot_chain.yaml", []),
"example_riscv64": (ROOT / "examples" / "riscv64_soc.yaml", []),
"example_rtos_mpu": (ROOT / "examples" / "rtos_mpu_ram.yaml", []),
"example_ota_package": (ROOT / "examples" / "ota_package_format.yaml", []),
"column_titles": (
EXPANDED,
["view.columns[1].title=Peripherals", "view.columns[2].title=Code area"],
Expand Down
17 changes: 17 additions & 0 deletions tests/test_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def address_labels(result, column=None):
"0x0000 4400", "0x0000 43FF",
"0x0000 4FFF",
],
"none": [],
} # fmt: skip


Expand Down Expand Up @@ -90,6 +91,22 @@ def test_top_label_override(top_label, strings):
assert labels == expected


def test_none_keeps_only_overridden_edges():
sets = ["view.defaults.labels.address=none", "view.overrides=[{region: b, top_label: end}]"]
assert address_labels(run(MODES, sets)) == ["0x0000 3FFF"]


def test_none_leaves_no_room_for_addresses():
layout = drawn(run(MODES, ["view.defaults.labels.address=none"])).columns[0]
assert layout.left_gutter == 0


def test_none_hides_addresses_in_one_column_only():
result = run(ROOT / "examples" / "stm32f303_fig8.yaml", ["view.columns[2].labels.address=none"])
assert address_labels(result, "code_detail") == []
assert address_labels(result, "periph_detail")


def test_override_forces_a_label_on_an_edge_bands_would_skip():
sets = ["view.columns[0].bands=16K", "view.overrides=[{region: b, top_label: end}]"]
assert address_labels(run(MODES, sets)) == ["0x0000 1000", "0x0000 3FFF", "0x0000 4FFF"]
Expand Down
Loading