blob: baa1b69111cb04a48bda0e2b00e15359a0deaac8 [file] [log] [blame]
Timothy Chenc1b009e2019-09-19 18:07:11 -07001#!/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
5r"""Generates chip_info.h for ROM build
6"""
7
8import argparse
9import logging as log
Timothy Chenc1b009e2019-09-19 18:07:11 -070010import sys
11from datetime import datetime
Timothy Chenc1b009e2019-09-19 18:07:11 -070012from pathlib import Path
13
Miguel Young de la Sotab2ef4832019-11-22 12:55:46 -060014header_template = r"""
Timothy Chenc1b009e2019-09-19 18:07:11 -070015// Copyright lowRISC contributors.
16// Licensed under the Apache License, Version 2.0, see LICENSE for details.
17// SPDX-License-Identifier: Apache-2.0
18//
Tobias Wölfelee06edc2019-09-24 12:06:34 +020019// --------- 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 Chenc1b009e2019-09-19 18:07:11 -070020
21#ifndef _F_CHIPINFO_H__
22#define _F_CHIPINFO_H__
23
24static const char chip_info[128] __attribute__((section(".chip_info"))) =
Alphan Ulusoy022b1812022-06-13 10:49:20 -040025 "Version: {%version%}, Build Date: {%build_date%}";
Timothy Chenc1b009e2019-09-19 18:07:11 -070026
Miguel Young de la Sotab2ef4832019-11-22 12:55:46 -060027#endif // _F_CHIPINFO_H__
Timothy Chenc1b009e2019-09-19 18:07:11 -070028
29"""
Timothy Trippel4a903632022-04-15 15:04:39 -070030
31
Timothy Chenc1b009e2019-09-19 18:07:11 -070032def main():
33 parser = argparse.ArgumentParser(prog="rom_chip_info")
34 parser.add_argument('--outdir',
35 '-o',
36 required=True,
Timothy Trippel4a903632022-04-15 15:04:39 -070037 help='Output Directory')
Miguel Young de la Sotab2ef4832019-11-22 12:55:46 -060038 parser.add_argument('--ot_version',
Drew Macrae399af402021-11-01 18:15:09 +000039 required=False,
Timothy Trippel4a903632022-04-15 15:04:39 -070040 help='OpenTitan Version')
Drew Macrae399af402021-11-01 18:15:09 +000041 parser.add_argument('--ot_version_file',
42 required=False,
Timothy Trippel4a903632022-04-15 15:04:39 -070043 help='Path to a file with the OpenTitan Version')
Timothy Chenc1b009e2019-09-19 18:07:11 -070044
45 log.basicConfig(format="%(levelname)s: %(message)s")
46 args = parser.parse_args()
47
48 if not args.outdir:
Miguel Young de la Sotab2ef4832019-11-22 12:55:46 -060049 log.error("Missing --outdir.")
Timothy Chenc1b009e2019-09-19 18:07:11 -070050 raise SystemExit(sys.exc_info()[1])
Drew Macrae399af402021-11-01 18:15:09 +000051
52 if args.ot_version:
53 version = args.ot_version
54 elif args.ot_version_file:
55 version = open(args.ot_version_file, "rt").read().strip()
56 else:
57 log.error(
Timothy Trippel4a903632022-04-15 15:04:39 -070058 "Missing ot_version, provide --ot_version or --ot_version_file.")
Miguel Young de la Sotab2ef4832019-11-22 12:55:46 -060059 raise SystemExit(sys.exc_info()[1])
60
61 outdir = Path(args.outdir)
Timothy Chenc1b009e2019-09-19 18:07:11 -070062
Miguel Young de la Sota3fbb28a2019-10-16 15:15:07 -050063 outdir.mkdir(parents=True, exist_ok=True)
Timothy Chenc1b009e2019-09-19 18:07:11 -070064 out_path = outdir / "chip_info.h"
65
Timothy Chenc1b009e2019-09-19 18:07:11 -070066 now = datetime.now()
Alphan Ulusoy022b1812022-06-13 10:49:20 -040067 wall_time = now.strftime("%Y-%m-%d %H:%M:%S")
Timothy Chenc1b009e2019-09-19 18:07:11 -070068
Timothy Trippel4a903632022-04-15 15:04:39 -070069 log.info("Version: %s" % (version, ))
70 log.info("Build Date: %s" % (wall_time, ))
Timothy Chenc1b009e2019-09-19 18:07:11 -070071
Miguel Young de la Sotab2ef4832019-11-22 12:55:46 -060072 output = header_template
73 output = output.replace('{%version%}', version, 1)
Timothy Chenc1b009e2019-09-19 18:07:11 -070074 output = output.replace('{%build_date%}', wall_time, 1)
75
76 with out_path.open(mode='w', encoding='UTF-8') as fout:
77 fout.write(output + "\n")
78
79
80if __name__ == "__main__":
81 main()