Skip to content

Commit

Permalink
Finish adding UF2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
vkottler committed Oct 27, 2023
1 parent 85fe259 commit 8c26d8d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 15 deletions.
2 changes: 2 additions & 0 deletions tests/data/valid/scenarios/native/yambs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ variants:

debug:
suffix: &gcc_version "-13"
targets: [apps, lib, uf2s]

opt:
suffix: *gcc_version

Expand Down
1 change: 1 addition & 0 deletions yambs/data/schemas/Native.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ properties:

uf2_family:
type: string
default: ""
4 changes: 3 additions & 1 deletion yambs/data/templates/native_rules.ninja.j2
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ rule hex

rule dump
command = ${toolchain_prefix}objdump -D $in > $out
{% if uf2_family %}

rule uf2
command = mbs uf2conv $uf2conv_args -o $out $in
command = mbs uf2conv -f {{uf2_family}} -o $out $in
{% endif %}

rule ar
command = ar rcs $out $in
Expand Down
63 changes: 49 additions & 14 deletions yambs/environment/native.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,36 @@ def write_static_library_rule(

return lib

def _write_app_phony_targets(
self, stream: TextIO, elfs: Dict[Path, Path], uf2_family: str = None
) -> None:
"""Write phony targets for all variants."""

elfs_list = list(elfs.values())

if elfs_list:
line = "build ${variant}_apps: phony "
offset = " " * len(line)

stream.write(line + str(elfs_list[0]))
for elf in elfs_list[1:]:
write_continuation(stream, offset)
stream.write(str(elf))
stream.write(linesep)

if uf2_family:
# Create uf2 phony.
line = "build ${variant}_uf2s: phony "
offset = " " * len(line)

uf2s = [x.with_suffix(".uf2") for x in elfs_list]

stream.write(line + str(uf2s[0]))
for elf in uf2s[1:]:
write_continuation(stream, offset)
stream.write(str(elf))
stream.write(linesep)

def write_app_rules(
self, stream: TextIO, outputs: Set[Path], uf2_family: str = None
) -> Dict[Path, Path]:
Expand Down Expand Up @@ -168,6 +198,24 @@ def write_app_rules(

stream.write(linesep + linesep)

# Write rules for other kinds of outputs.
for output in ["bin", "hex", "dump"]:
stream.write(
f"build {elf.with_suffix('.' + output)}: {output} {elf}"
)
stream.write(linesep)

if uf2_family:
stream.write(
(
f"build {elf.with_suffix('.uf2')}: "
f"uf2 {elf.with_suffix('.hex')}"
)
)
stream.write(linesep)

stream.write(linesep)

# Add a phony target for creating a static library.
if outputs:
stream.write(
Expand All @@ -177,20 +225,7 @@ def write_app_rules(
+ linesep
)

line = "build ${variant}_apps: phony "
offset = " " * len(line)

elfs_list = list(elfs.values())
if elfs_list:
stream.write(line + str(elfs_list[0]))
for elf in elfs_list[1:]:
write_continuation(stream, offset)
stream.write(str(elf))
stream.write(linesep)

# need to actually handle this
if uf2_family is not None:
print(uf2_family)
self._write_app_phony_targets(stream, elfs, uf2_family=uf2_family)

return elfs

Expand Down

0 comments on commit 8c26d8d

Please sign in to comment.