summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorGwendal Grignou <gwendal@chromium.org>2019-04-08 14:52:34 -0700
committerchrome-bot <chrome-bot@chromium.org>2019-04-26 00:17:31 -0700
commit5c931074f53de0bcac655d60e5867b3eb0959864 (patch)
tree2acb81ac19cad47cbd174ec8eb39789035951ecf /util
parentd3ce30103e55fb8296259bd7d22f7d8c8d8e7a0c (diff)
downloadchrome-ec-5c931074f53de0bcac655d60e5867b3eb0959864.tar.gz
util: Add tool to generate cros_ec_commands.h
Add a rule to generate a new cros_ec_commands.h when ec_commands.h is modified. The rule is checked when buildall is invoked. At Presubmit stage, check a cros_ec_commands.h exists if ec_commands.h is modified. The CL author is responsible to upstream that file. BUG=chromium:945948 BRANCH=none Cq-Depend: chromium:1558853 TEST=Check manually cros_ec_commands.h is generated with make build_cros_ec_commands Check no bread crumbs are left-over when the rule fails. Check checkpatch triggers when it finds an invalid syntax in the output file. Check ../../repohooks/pre-upload.py returns a meaningful error when cros_ec_commands.h file is not present. Change-Id: Ibc8ed7165914d39b5f0bd41643932a8514768925 Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1559380 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Reviewed-by: Brian Norris <briannorris@chromium.org>
Diffstat (limited to 'util')
-rwxr-xr-xutil/linux_ec_commands_h_check.sh25
-rwxr-xr-xutil/make_linux_ec_commands_h.sh70
2 files changed, 95 insertions, 0 deletions
diff --git a/util/linux_ec_commands_h_check.sh b/util/linux_ec_commands_h_check.sh
new file mode 100755
index 0000000000..4c55faca0a
--- /dev/null
+++ b/util/linux_ec_commands_h_check.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+#
+# Copyright 2019 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+set -e
+
+ec_commands_file_in="include/ec_commands.h"
+ec_commands_file_out="build/kernel/include/linux/mfd/cros_ec_commands.h"
+
+# Check if ec_commands.h has changed.
+echo ${PRESUBMIT_FILES} | grep -q "${ec_commands_file_in}" || exit 0
+
+if [ ! -f "${ec_commands_file_out}" ]; then
+ echo "A new cros_ec_commands.h must be generated."
+ echo 'Please run "make buildall" or "make build_cros_ec_commands"'.
+ exit 1
+fi
+
+if [ "${ec_commands_file_out}" -ot "${ec_commands_file_in}" ]; then
+ echo "cros_ec_commands.h is out of date."
+ echo 'Please run "make buildall" or "make build_cros_ec_commands"'.
+ exit 1
+fi
diff --git a/util/make_linux_ec_commands_h.sh b/util/make_linux_ec_commands_h.sh
new file mode 100755
index 0000000000..5de8017f4e
--- /dev/null
+++ b/util/make_linux_ec_commands_h.sh
@@ -0,0 +1,70 @@
+#!/bin/bash
+#
+# Copyright 2019 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# Generate a kernel include file from ec_commands.h.
+
+usage() {
+ cat << EOF
+Generate an ec_commands.h file suitable for upstreaming to kernel.org.
+Syntax:
+$0 source_ec_commands.h target_cros_ec_commands.h
+
+source_ec_commands.h: source file, usually include/ec_commands.h
+target_cros_ec_commands.h: target file that will be upstreamed.
+EOF
+}
+
+set -e
+
+in="$1"
+out="$2"
+
+if [ $# -ne 2 ]; then
+ usage
+ exit 1
+fi
+
+out_dir="$(dirname "${out}")"
+mkdir -p "${out_dir}"
+tmp="$(mktemp -p "${out_dir}" cros_ec_XXX.h)"
+cp "${in}" "${tmp}"
+
+cleanup() {
+ rm -f "${tmp}"*
+}
+
+trap cleanup EXIT
+
+# Replace license
+patch "${tmp}" << EOF
+@@ -1,6 +1,11 @@
+-/* Copyright (c) 2014 The Chromium OS Authors. All rights reserved.
+- * Use of this source code is governed by a BSD-style license that can be
+- * found in the LICENSE file.
++/* SPDX-License-Identifier: GPL-2.0 */
++/*
++ * Host communication command constants for ChromeOS EC
++ *
++ * Copyright (C) 2012 Google, Inc
++ *
++ * NOTE: This file is auto-generated from ChromeOS EC Open Source code from
++ * https://chromium.googlesource.com/chromiumos/platform/ec/+/master/include/ec_commands.h
+ */
+
+ /* Host communication command constants for Chrome EC */
+EOF
+
+# Change header guards
+sed -i "s/__CROS_EC_EC_COMMANDS_H/__CROS_EC_COMMANDS_H/" "${tmp}"
+
+# Remove non kernel code to prevent checkpatch warnings and simplify the .h.
+unifdef -x2 -m -UCONFIG_HOSTCMD_ALIGNED -U__ACPI__ -D__KERNEL__ -U__cplusplus \
+ -UCHROMIUM_EC "${tmp}"
+
+# Check kernel checkpatch passes.
+"${CROS_WORKON_SRCROOT}/src/repohooks/checkpatch.pl" -f "${tmp}"
+
+cp "${tmp}" "${out}"