drivers/wifi: Remove unnecessary data structure copy
[coreboot2.git] / util / chromeos / update_ec_headers.sh
blob23b6418983f71b4b3f9f9cf0ea2a7fe662551023
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=''
15 SPDX_ID_STRING="SPDX-License-Identifier"
17 cleanup()
19 if [[ -n "${scratch_file}" ]]; then
20 rm -f -- "${scratch_file}"
21 scratch_file=''
25 trap cleanup EXIT
27 usage()
29 cat <<- __EOF
30 Usage: ${pname}: [top of cros EC repo]
32 Imports ec_commands.h and ec_cmd_api.h from the cros EC repo
33 and updates the copyright header for coreboot.
34 __EOF
38 # Remove the original ChromiumOS copyright so we can insert the SPDX
39 # license identifier. Preserve the original number of lines in the file
40 # so embedded #line directives are correct.
43 update_copyright()
45 local spdx="/* ${SPDX_ID_STRING}: BSD-3-Clause */"
46 local f=$1
48 # replace existing copyright with empty lines
49 sed -i -e '/Copyright.*Chromium/,/^$/{s/^.*$//}' "${f}"
50 # now add the SPDX header
51 sed -i -e "1s@^\$@${spdx}@" "${f}"
54 get_file()
56 local ec_path="$1"
57 local ec_file="$2"
58 local dst_path="$3"
59 local log
61 if [[ ! -f "${ec_path}/${ec_file}" ]]; then
62 echo "${ec_path}/${ec_file} does not exist" 2>&1
63 return 1
66 scratch_file=$(mktemp)
68 cp "${ec_path}/${ec_file}" "${scratch_file}"
70 update_copyright "${scratch_file}"
71 cp "${scratch_file}" "${dst_path}"
73 rm -f "${scratch_file}"
74 scratch_file=''
76 log=$(git -C "${ec_path}" log --oneline -1 "${ec_file}")
77 echo "The original ${ec_file} version in the EC repo is:"
78 echo " ${log}"
81 main()
83 local dst_path
84 local ec_path
86 pname=$(basename "$0")
88 if [[ $# != 1 ]]; then
89 usage
90 exit 1
93 ec_path="$1"
94 if [[ ! -d "${ec_path}" ]]; then
95 echo "${pname}: could not find ${ec_path}" 1>&2
96 exit 1
99 coreboot_top=$(git rev-parse --show-toplevel)
100 if [[ ! -d "${coreboot_top}" ]]; then
101 echo "${pname}: could not determine coreboot top" 1>&2
102 exit 1
105 dst_path="${coreboot_top}/src/ec/google/chromeec"
107 cat <<- __EOF
108 Suggested commit message:
110 Generated using ${pname} [EC-DIR].
112 __EOF
114 get_file "${ec_path}" include/ec_commands.h "${dst_path}/ec_commands.h"
115 get_file "${ec_path}" include/ec_cmd_api.h "${dst_path}/ec_cmd_api.h"
116 echo
119 main "$@"