soc/intel/cmn/cse: Deprecate CONFIG_SOC_INTEL_CSE_RW_VERSION
[coreboot2.git] / util / chromeos / update_ec_headers.sh
blobc3ee13e5f7541c98aacd628f6d42414c4e69ccff
1 #!/usr/bin/env bash
3 # SPDX-License-Identifier: GPL-2.0-only
6 # Imports ec_commands.h and ec_cmd_api.h from the cros EC repo
7 # and updates the copyright header for coreboot.
10 set -u
12 scratch_file=''
13 coreboot_top=''
14 pname=''
16 cleanup()
18 if [[ -n "${scratch_file}" ]]; then
19 rm -f -- "${scratch_file}"
20 scratch_file=''
24 trap cleanup EXIT
26 usage()
28 cat <<- __EOF
29 Usage: ${pname}: [top of cros EC repo]
31 Imports ec_commands.h and ec_cmd_api.h from the cros EC repo
32 and updates the copyright header for coreboot.
33 __EOF
37 # Remove the original ChromiumOS copyright so we can insert the SPDX
38 # license identifier. Preserve the original number of lines in the file
39 # so embedded #line directives are correct.
42 update_copyright()
44 local spdx='/* SPDX-License-Identifier: BSD-3-Clause */'
45 local f=$1
47 # replace existing copyright with empty lines
48 sed -i -e '/Copyright.*Chromium/,/^$/{s/^.*$//}' "${f}"
49 # now add the SPDX header
50 sed -i -e "1s@^\$@${spdx}@" "${f}"
53 get_file()
55 local ec_path="$1"
56 local ec_file="$2"
57 local dst_path="$3"
58 local log
60 if [[ ! -f "${ec_path}/${ec_file}" ]]; then
61 echo "${ec_path}/${ec_file} does not exist" 2>&1
62 return 1
65 scratch_file=$(mktemp)
67 cp "${ec_path}/${ec_file}" "${scratch_file}"
69 update_copyright "${scratch_file}"
70 cp "${scratch_file}" "${dst_path}"
72 rm -f "${scratch_file}"
73 scratch_file=''
75 log=$(git -C "${ec_path}" log --oneline -1 "${ec_file}")
76 echo "The original ${ec_file} version in the EC repo is:"
77 echo " ${log}"
80 main()
82 local dst_path
83 local ec_path
85 pname=$(basename "$0")
87 if [[ $# != 1 ]]; then
88 usage
89 exit 1
92 ec_path="$1"
93 if [[ ! -d "${ec_path}" ]]; then
94 echo "${pname}: could not find ${ec_path}" 1>&2
95 exit 1
98 coreboot_top=$(git rev-parse --show-toplevel)
99 if [[ ! -d "${coreboot_top}" ]]; then
100 echo "${pname}: could not determine coreboot top" 1>&2
101 exit 1
104 dst_path="${coreboot_top}/src/ec/google/chromeec"
106 cat <<- __EOF
107 Suggested commit message:
109 Generated using ${pname} [EC-DIR].
111 __EOF
113 get_file "${ec_path}" include/ec_commands.h "${dst_path}/ec_commands.h"
114 get_file "${ec_path}" include/ec_cmd_api.h "${dst_path}/ec_cmd_api.h"
115 echo
118 main "$@"