| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | # |
| 3 | # SPDX-License-Identifier: GPL-2.0-only |
| 4 | |
| 5 | # |
| 6 | # Imports ec_commands.h and ec_cmd_api.h from the cros EC repo |
| 7 | # and updates the copyright header for coreboot. |
| 8 | # |
| 9 | |
| 10 | set -u |
| 11 | |
| 12 | scratch_file='' |
| 13 | coreboot_top='' |
| 14 | pname='' |
| 15 | SPDX_ID_STRING="SPDX-License-Identifier" |
| 16 | |
| 17 | cleanupscip-shell shell coreboot 25.09+dfsg-1 cleanup().() |
| 18 | { |
| 19 | if [[ -n "${scratch_file}" ]]; then |
| 20 | rmscip-shell system . . rm. -f -- "${scratch_file}" |
| 21 | scratch_file='' |
| 22 | fi |
| 23 | } |
| 24 | |
| 25 | trap cleanup EXIT |
| 26 | |
| 27 | usagescip-shell shell coreboot 25.09+dfsg-1 usage().() |
| 28 | { |
| 29 | catscip-shell system . . cat. <<- __EOF |
| 30 | Usage: ${pname}: [top of cros EC repo] |
| 31 | |
| 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 |
| 35 | } |
| 36 | |
| 37 | # |
| 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. |
| 41 | # |
| 42 | |
| 43 | update_copyrightscip-shell shell coreboot 25.09+dfsg-1 update_copyright().() |
| 44 | { |
| 45 | local spdx="/* ${SPDX_ID_STRING}: BSD-3-Clause */" |
| 46 | local f=$1 |
| 47 | |
| 48 | # replace existing copyright with empty lines |
| 49 | sedscip-shell system . . sed. -i -e '/Copyright.*Chromium/,/^$/{s/^.*$//}scip-shell filesystem . . `/Copyright.*Chromium/,/^$/{s/^.*$//}`.' "${f}" |
| 50 | # now add the SPDX header |
| 51 | sedscip-shell system . . sed. -i -e "1s@^\$@${spdx}@" "${f}" |
| 52 | } |
| 53 | |
| 54 | get_filescip-shell shell coreboot 25.09+dfsg-1 get_file().() |
| 55 | { |
| 56 | local ec_path="$1" |
| 57 | local ec_file="$2" |
| 58 | local dst_path="$3" |
| 59 | local log |
| 60 | |
| 61 | if [[ ! -f "${ec_path}/${ec_file}" ]]; then |
| 62 | echoscip-shell system . . echo. "${ec_path}/${ec_file} does not exist" 2>&1 |
| 63 | return 1 |
| 64 | fi |
| 65 | |
| 66 | scratch_file=$(mktempscip-shell system . . mktemp.) |
| 67 | |
| 68 | cpscip-shell system . . cp. "${ec_path}/${ec_file}" "${scratch_file}" |
| 69 | |
| 70 | update_copyrightscip-shell shell coreboot 25.09+dfsg-1 update_copyright(). "${scratch_file}" |
| 71 | cpscip-shell system . . cp. "${scratch_file}" "${dst_path}" |
| 72 | |
| 73 | rmscip-shell system . . rm. -f "${scratch_file}" |
| 74 | scratch_file='' |
| 75 | |
| 76 | log=$(gitscip-shell system . . git. -C "${ec_path}" log --oneline -1 "${ec_file}") |
| 77 | echoscip-shell system . . echo. "The original ${ec_file} version in the EC repo is:" |
| 78 | echoscip-shell system . . echo. " ${log}" |
| 79 | } |
| 80 | |
| 81 | mainscip-shell shell coreboot 25.09+dfsg-1 main().() |
| 82 | { |
| 83 | local dst_path |
| 84 | local ec_path |
| 85 | |
| 86 | pname=$(basenamescip-shell system . . basename. "$0") |
| 87 | |
| 88 | if [[ $# != 1 ]]; then |
| 89 | usagescip-shell shell coreboot 25.09+dfsg-1 usage(). |
| 90 | exit 1 |
| 91 | fi |
| 92 | |
| 93 | ec_path="$1" |
| 94 | if [[ ! -d "${ec_path}" ]]; then |
| 95 | echoscip-shell system . . echo. "${pname}: could not find ${ec_path}" 1>&2 |
| 96 | exit 1 |
| 97 | fi |
| 98 | |
| 99 | coreboot_top=$(gitscip-shell system . . git. rev-parse --show-toplevel) |
| 100 | if [[ ! -d "${coreboot_top}" ]]; then |
| 101 | echoscip-shell system . . echo. "${pname}: could not determine coreboot top" 1>&2 |
| 102 | exit 1 |
| 103 | fi |
| 104 | |
| 105 | dst_path="${coreboot_top}/src/ec/google/chromeec" |
| 106 | |
| 107 | catscip-shell system . . cat. <<- __EOF |
| 108 | Suggested commit message: |
| 109 | |
| 110 | Generated using ${pname} [EC-DIR]. |
| 111 | |
| 112 | __EOF |
| 113 | |
| 114 | get_filescip-shell shell coreboot 25.09+dfsg-1 get_file(). "${ec_path}" include/ec_commands.h "${dst_path}/ec_commands.h" |
| 115 | get_filescip-shell shell coreboot 25.09+dfsg-1 get_file(). "${ec_path}" include/ec_cmd_api.h "${dst_path}/ec_cmd_api.h" |
| 116 | echoscip-shell system . . echo. |
| 117 | } |
| 118 | |
| 119 | mainscip-shell shell coreboot 25.09+dfsg-1 main(). "$@" |