Timothy Chen | c1b009e | 2019-09-19 18:07:11 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # Copyright lowRISC contributors. |
| 3 | # Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| 4 | # SPDX-License-Identifier: Apache-2.0 |
| 5 | r"""Generates chip_info.h for ROM build |
| 6 | """ |
| 7 | |
| 8 | import argparse |
| 9 | import logging as log |
| 10 | import os |
| 11 | import sys |
| 12 | from datetime import datetime |
Timothy Chen | c1b009e | 2019-09-19 18:07:11 -0700 | [diff] [blame] | 13 | from io import StringIO |
| 14 | from pathlib import Path |
| 15 | |
| 16 | |
Miguel Young de la Sota | b2ef483 | 2019-11-22 12:55:46 -0600 | [diff] [blame] | 17 | header_template = r""" |
Timothy Chen | c1b009e | 2019-09-19 18:07:11 -0700 | [diff] [blame] | 18 | // Copyright lowRISC contributors. |
| 19 | // Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| 20 | // SPDX-License-Identifier: Apache-2.0 |
| 21 | // |
Tobias Wölfel | ee06edc | 2019-09-24 12:06:34 +0200 | [diff] [blame] | 22 | // --------- W A R N I N G: A U T O - G E N E R A T E D C O D E !! ---------// |
Timothy Chen | c1b009e | 2019-09-19 18:07:11 -0700 | [diff] [blame] | 23 | |
| 24 | #ifndef _F_CHIPINFO_H__ |
| 25 | #define _F_CHIPINFO_H__ |
| 26 | |
| 27 | static const char chip_info[128] __attribute__((section(".chip_info"))) = |
Miguel Young de la Sota | b2ef483 | 2019-11-22 12:55:46 -0600 | [diff] [blame] | 28 | "Version: {%version%}\r\n" |
Timothy Chen | c1b009e | 2019-09-19 18:07:11 -0700 | [diff] [blame] | 29 | "Build Date: {%build_date%}\r\n"; |
| 30 | |
Miguel Young de la Sota | b2ef483 | 2019-11-22 12:55:46 -0600 | [diff] [blame] | 31 | #endif // _F_CHIPINFO_H__ |
Timothy Chen | c1b009e | 2019-09-19 18:07:11 -0700 | [diff] [blame] | 32 | |
| 33 | """ |
| 34 | def main(): |
| 35 | parser = argparse.ArgumentParser(prog="rom_chip_info") |
| 36 | parser.add_argument('--outdir', |
| 37 | '-o', |
| 38 | required=True, |
| 39 | help='Output Directory' |
| 40 | ) |
Miguel Young de la Sota | b2ef483 | 2019-11-22 12:55:46 -0600 | [diff] [blame] | 41 | parser.add_argument('--ot_version', |
| 42 | required=True, |
| 43 | help='OpenTitan Version' |
| 44 | ) |
Timothy Chen | c1b009e | 2019-09-19 18:07:11 -0700 | [diff] [blame] | 45 | |
| 46 | log.basicConfig(format="%(levelname)s: %(message)s") |
| 47 | args = parser.parse_args() |
| 48 | |
| 49 | if not args.outdir: |
Miguel Young de la Sota | b2ef483 | 2019-11-22 12:55:46 -0600 | [diff] [blame] | 50 | log.error("Missing --outdir.") |
Timothy Chen | c1b009e | 2019-09-19 18:07:11 -0700 | [diff] [blame] | 51 | raise SystemExit(sys.exc_info()[1]) |
Miguel Young de la Sota | b2ef483 | 2019-11-22 12:55:46 -0600 | [diff] [blame] | 52 | if not args.ot_version: |
| 53 | log.error("Missing --ot_version.") |
| 54 | raise SystemExit(sys.exc_info()[1]) |
| 55 | |
| 56 | outdir = Path(args.outdir) |
| 57 | version = args.ot_version |
Timothy Chen | c1b009e | 2019-09-19 18:07:11 -0700 | [diff] [blame] | 58 | |
Miguel Young de la Sota | 3fbb28a | 2019-10-16 15:15:07 -0500 | [diff] [blame] | 59 | outdir.mkdir(parents=True, exist_ok=True) |
Timothy Chen | c1b009e | 2019-09-19 18:07:11 -0700 | [diff] [blame] | 60 | out_path = outdir / "chip_info.h" |
| 61 | |
Timothy Chen | c1b009e | 2019-09-19 18:07:11 -0700 | [diff] [blame] | 62 | now = datetime.now() |
| 63 | wall_time = now.strftime("%Y-%m-%d, %H:%M:%S") |
| 64 | |
Miguel Young de la Sota | b2ef483 | 2019-11-22 12:55:46 -0600 | [diff] [blame] | 65 | log.info("Version: %s" % (version,)) |
| 66 | log.info("Build Date: %s" % (wall_time,)) |
Timothy Chen | c1b009e | 2019-09-19 18:07:11 -0700 | [diff] [blame] | 67 | |
Miguel Young de la Sota | b2ef483 | 2019-11-22 12:55:46 -0600 | [diff] [blame] | 68 | output = header_template |
| 69 | output = output.replace('{%version%}', version, 1) |
Timothy Chen | c1b009e | 2019-09-19 18:07:11 -0700 | [diff] [blame] | 70 | output = output.replace('{%build_date%}', wall_time, 1) |
| 71 | |
| 72 | with out_path.open(mode='w', encoding='UTF-8') as fout: |
| 73 | fout.write(output + "\n") |
| 74 | |
| 75 | |
| 76 | if __name__ == "__main__": |
| 77 | main() |