kernel: Create recommended configs file

We've started to have more and more "recommended" but not "required"
kernel configs (i.e. hardware-specific, etc). Instead of confusingly
requiring them or forcing them into defconfig files, split these out
into a single file that can be overridden on a per-product basis.

Additionally fixes a bug with the PSTORE config (which needed the
MISC_FILESYSTEMS config too), simplifies the prebuilt check, and
documents some missing target variables.

Bug: 27774946

Change-Id: Ic867aeec8450749c2a471eff1959f544dcaaf804
diff --git a/kconfig/common.config b/kconfig/common.config
index 1a10d6c..24df799 100644
--- a/kconfig/common.config
+++ b/kconfig/common.config
@@ -113,11 +113,8 @@
 CONFIG_DEBUG_INFO=y
 
 # Enable pstore to allow kernel panic crash collection.
+CONFIG_MISC_FILESYSTEMS=y
 CONFIG_PSTORE=y
 CONFIG_PSTORE_CONSOLE=y
 CONFIG_PSTORE_FTRACE=y
 CONFIG_PSTORE_RAM=y
-
-# Enable the FTDI driver.
-CONFIG_USB_SERIAL_FTDI_SIO=y
-CONFIG_USB_SERIAL=y
diff --git a/kconfig/recommended.config b/kconfig/recommended.config
new file mode 100644
index 0000000..4fb43e8
--- /dev/null
+++ b/kconfig/recommended.config
@@ -0,0 +1,23 @@
+#
+# Copyright 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#
+# This file contains the Brillo kernel configurations that are recommended
+# (though not strictly required) for all kernel builds.
+#
+
+# It's extremely handy to have a serial port available for debugging.
+CONFIG_USB_SERIAL_FTDI_SIO=y
+CONFIG_USB_SERIAL=y
diff --git a/kernel.mk b/kernel.mk
index ceafd6c..3e85c74 100644
--- a/kernel.mk
+++ b/kernel.mk
@@ -15,17 +15,23 @@
 #
 
 # Targets for builing kernels
-# The following must be set before including this file.
+#
+# The following must be set before including this file:
 # TARGET_KERNEL_SRC must be set the base of a kernel tree.
 # TARGET_KERNEL_DEFCONFIG must name a base kernel config.
 # TARGET_KERNEL_ARCH must be set to match kernel arch.
+#
+# The following maybe set:
+# TARGET_KERNEL_CROSS_COMPILE_PREFIX to override toolchain.
+# TARGET_KERNEL_CONFIGS to specify a set of additional kernel configs.
+# TARGET_KERNEL_DTB to define a DTB to build.
+# TARGET_KERNEL_DTB_APPEND to append the built DTB to the kernel.
 
-# The following maybe set.
-# TARGET_KERNEL_CROSS_COMPILE_PREFIX to override toolchain
-# TARGET_PREBUILT_KERNEL to use a pre-built kernel
 
-# Only build kernel if caller has not defined a prebuild
-ifeq ($(TARGET_PREBUILT_KERNEL),)
+# Brillo does not support prebuilt kernels.
+ifneq ($(TARGET_PREBUILT_KERNEL),)
+$(error TARGET_PREBUILT_KERNEL defined but Brillo kernels build from source)
+endif
 
 ifeq ($(TARGET_KERNEL_SRC),)
 $(error TARGET_KERNEL_SRC not defined)
@@ -108,6 +114,7 @@
 KERNEL_CONFIGS_ARCH := $(KERNEL_CONFIGS_DIR)/$(KERNEL_ARCH).config
 KERNEL_CONFIGS_VER := $(KERNEL_CONFIGS_DIR)/$(KERNEL_VERSION)/common.config
 KERNEL_CONFIGS_VER_ARCH := $(KERNEL_CONFIGS_DIR)/$(KERNEL_VERSION)/$(KERNEL_ARCH).config
+KERNEL_CONFIGS_RECOMMENDED := $(KERNEL_CONFIGS_DIR)/recommended.config
 
 KERNEL_MERGE_CONFIG := device/generic/brillo/mergeconfig.sh
 KERNEL_HEADERS_INSTALL := $(KERNEL_OUT)/usr
@@ -147,7 +154,12 @@
 
 # Merge the final target kernel config.
 $(KERNEL_CONFIG): $(KERNEL_OUT) $(KERNEL_CONFIG_REQUIRED)
-	$(KERNEL_MERGE_CONFIG) $(TARGET_KERNEL_SRC) $(realpath $(KERNEL_OUT)) $(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) arch/$(KERNEL_SRC_ARCH)/configs/$(TARGET_KERNEL_DEFCONFIG) $(TARGET_KERNEL_CONFIGS) $(realpath $(KERNEL_CONFIG_REQUIRED))
+	$(KERNEL_MERGE_CONFIG) $(TARGET_KERNEL_SRC) $(realpath $(KERNEL_OUT)) \
+		$(KERNEL_ARCH) $(KERNEL_CROSS_COMPILE) \
+		arch/$(KERNEL_SRC_ARCH)/configs/$(TARGET_KERNEL_DEFCONFIG) \
+		$(realpath $(KERNEL_CONFIGS_RECOMMENDED)) \
+		$(TARGET_KERNEL_CONFIGS) \
+		$(realpath $(KERNEL_CONFIG_REQUIRED))
 
 $(KERNEL_BIN): $(KERNEL_OUT) $(KERNEL_CONFIG)
 	$(hide) echo "Building $(KERNEL_ARCH) $(KERNEL_VERSION) kernel..."
@@ -186,6 +198,3 @@
 $(PRODUCT_OUT)/kernel: $(KERNEL_BIN) $(KERNEL_BIN).vdso $(KERNEL_HEADERS_INSTALL) | $(ACP)
 	$(ACP) -fp $< $@
 endif
-
-endif
-