blob: c0cbb6f43647b40e29612418a2f0e84914cfc701 [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
10import os
11import sys
12from datetime import datetime
Timothy Chenc1b009e2019-09-19 18:07:11 -070013from io import StringIO
14from pathlib import Path
15
16
Miguel Young de la Sotab2ef4832019-11-22 12:55:46 -060017header_template = r"""
Timothy Chenc1b009e2019-09-19 18:07:11 -070018// 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ölfelee06edc2019-09-24 12:06:34 +020022// --------- 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 -070023
24#ifndef _F_CHIPINFO_H__
25#define _F_CHIPINFO_H__
26
27static const char chip_info[128] __attribute__((section(".chip_info"))) =
Miguel Young de la Sotab2ef4832019-11-22 12:55:46 -060028 "Version: {%version%}\r\n"
Timothy Chenc1b009e2019-09-19 18:07:11 -070029 "Build Date: {%build_date%}\r\n";
30
Miguel Young de la Sotab2ef4832019-11-22 12:55:46 -060031#endif // _F_CHIPINFO_H__
Timothy Chenc1b009e2019-09-19 18:07:11 -070032
33"""
34def 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 Sotab2ef4832019-11-22 12:55:46 -060041 parser.add_argument('--ot_version',
42 required=True,
43 help='OpenTitan Version'
44 )
Timothy Chenc1b009e2019-09-19 18:07:11 -070045
46 log.basicConfig(format="%(levelname)s: %(message)s")
47 args = parser.parse_args()
48
49 if not args.outdir:
Miguel Young de la Sotab2ef4832019-11-22 12:55:46 -060050 log.error("Missing --outdir.")
Timothy Chenc1b009e2019-09-19 18:07:11 -070051 raise SystemExit(sys.exc_info()[1])
Miguel Young de la Sotab2ef4832019-11-22 12:55:46 -060052 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 Chenc1b009e2019-09-19 18:07:11 -070058
Miguel Young de la Sota3fbb28a2019-10-16 15:15:07 -050059 outdir.mkdir(parents=True, exist_ok=True)
Timothy Chenc1b009e2019-09-19 18:07:11 -070060 out_path = outdir / "chip_info.h"
61
Timothy Chenc1b009e2019-09-19 18:07:11 -070062 now = datetime.now()
63 wall_time = now.strftime("%Y-%m-%d, %H:%M:%S")
64
Miguel Young de la Sotab2ef4832019-11-22 12:55:46 -060065 log.info("Version: %s" % (version,))
66 log.info("Build Date: %s" % (wall_time,))
Timothy Chenc1b009e2019-09-19 18:07:11 -070067
Miguel Young de la Sotab2ef4832019-11-22 12:55:46 -060068 output = header_template
69 output = output.replace('{%version%}', version, 1)
Timothy Chenc1b009e2019-09-19 18:07:11 -070070 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
76if __name__ == "__main__":
77 main()