[otbn] Simple linker script and wrapper for otbn
Signed-off-by: Rupert Swarbrick <rswarbrick@lowrisc.org>
diff --git a/hw/ip/otbn/data/otbn.ld b/hw/ip/otbn/data/otbn.ld
new file mode 100644
index 0000000..cdd9021
--- /dev/null
+++ b/hw/ip/otbn/data/otbn.ld
@@ -0,0 +1,37 @@
+/* Copyright lowRISC contributors. */
+/* Licensed under the Apache License, Version 2.0, see LICENSE for details. */
+/* SPDX-License-Identifier: Apache-2.0 */
+/*
+
+ OTBN has a pure Harvard architecture, with instruction and data
+ memory both starting at address 0.
+
+ We give each 1MiB of space: too much for the eventual chip - let's
+ come back to this once we know how much space we'll have or (harder)
+ auto-generate it from the address map.
+
+*/
+MEMORY
+{
+ imem (x) : ORIGIN = 0, LENGTH = 1M
+ dmem (rw) : ORIGIN = 0, LENGTH = 1M
+
+ /* LMA addresses (for VMAs in imem/dmem, respectively) */
+ imem_load (rw) : ORIGIN = 1M, LENGTH = 1M
+ dmem_load (rw) : ORIGIN = 1M, LENGTH = 1M
+}
+
+SECTIONS
+{
+ .text ALIGN(4) :
+ {
+ *(.text*)
+ } >imem AT >imem_load
+
+ .data ALIGN(32) :
+ {
+ *(.data*)
+ . = ALIGN(32);
+ *(.bss*)
+ } >dmem AT >dmem_load
+}
diff --git a/hw/ip/otbn/util/Makefile b/hw/ip/otbn/util/Makefile
index 42f6f52..f5078c2 100644
--- a/hw/ip/otbn/util/Makefile
+++ b/hw/ip/otbn/util/Makefile
@@ -2,8 +2,15 @@
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
-pyfiles := insn_yaml.py yaml_to_doc.py otbn-as
+pylibs := insn_yaml.py
+pyscripts := yaml_to_doc.py otbn-as otbn-ld
-.PHONY: lint
-lint: $(pyfiles)
- mypy --strict $(pyfiles)
+.PHONY: all
+all: lint
+
+lint-targets := $(addprefix lint-,$(pyscripts))
+.PHONY: lint $(lint-targets)
+lint: $(lint-targets)
+
+$(lint-targets): lint-%:
+ mypy --strict $*
diff --git a/hw/ip/otbn/util/otbn-ld b/hw/ip/otbn/util/otbn-ld
new file mode 100755
index 0000000..cdde8d7
--- /dev/null
+++ b/hw/ip/otbn/util/otbn-ld
@@ -0,0 +1,35 @@
+#!/usr/bin/env python3
+# Copyright lowRISC contributors.
+# Licensed under the Apache License, Version 2.0, see LICENSE for details.
+# SPDX-License-Identifier: Apache-2.0
+
+'''A wrapper around riscv32-unknown-elf-ld for OTBN
+
+This just adds the OTBN linker script and calls the underlying
+linker.'''
+
+import os
+import subprocess
+import sys
+
+
+def main() -> int:
+ ld_script = os.path.normpath(os.path.join(os.path.dirname(__file__),
+ '..', 'data', 'otbn.ld'))
+ if not os.path.exists(ld_script):
+ sys.stderr.write('Default linker script ({!r}) does not exist.'
+ .format(ld_script))
+
+ try:
+ ld_name = 'riscv32-unknown-elf-ld'
+ cmd = [ld_name, '--script={}'.format(ld_script)] + sys.argv[1:]
+ return subprocess.run(cmd).returncode
+ except FileNotFoundError:
+ sys.stderr.write('Unknown command: {!r}. '
+ '(is it installed and on your PATH?)\n'
+ .format(ld_name))
+ return 127
+
+
+if __name__ == '__main__':
+ sys.exit(main())