xref: /OK3568_Linux_fs/kernel/arch/mips/tools/generic-board-config.sh (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun#!/bin/sh
2*4882a593Smuzhiyun# SPDX-License-Identifier: GPL-2.0-or-later
3*4882a593Smuzhiyun#
4*4882a593Smuzhiyun# Copyright (C) 2017 Imagination Technologies
5*4882a593Smuzhiyun# Author: Paul Burton <paul.burton@mips.com>
6*4882a593Smuzhiyun#
7*4882a593Smuzhiyun# This script merges configuration fragments for boards supported by the
8*4882a593Smuzhiyun# generic MIPS kernel. It checks each for requirements specified using
9*4882a593Smuzhiyun# formatted comments, and then calls merge_config.sh to merge those
10*4882a593Smuzhiyun# fragments which have no unmet requirements.
11*4882a593Smuzhiyun#
12*4882a593Smuzhiyun# An example of requirements in your board config fragment might be:
13*4882a593Smuzhiyun#
14*4882a593Smuzhiyun# # require CONFIG_CPU_MIPS32_R2=y
15*4882a593Smuzhiyun# # require CONFIG_CPU_LITTLE_ENDIAN=y
16*4882a593Smuzhiyun#
17*4882a593Smuzhiyun# This would mean that your board is only included in kernels which are
18*4882a593Smuzhiyun# configured for little endian MIPS32r2 CPUs, and not for example in kernels
19*4882a593Smuzhiyun# configured for 64 bit or big endian systems.
20*4882a593Smuzhiyun#
21*4882a593Smuzhiyun
22*4882a593Smuzhiyunsrctree="$1"
23*4882a593Smuzhiyunobjtree="$2"
24*4882a593Smuzhiyunref_cfg="$3"
25*4882a593Smuzhiyuncfg="$4"
26*4882a593Smuzhiyunboards_origin="$5"
27*4882a593Smuzhiyunshift 5
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun# Only print Skipping... lines if the user explicitly specified BOARDS=. In the
30*4882a593Smuzhiyun# general case it only serves to obscure the useful output about what actually
31*4882a593Smuzhiyun# was included.
32*4882a593Smuzhiyuncase ${boards_origin} in
33*4882a593Smuzhiyun"command line")
34*4882a593Smuzhiyun	print_skipped=1
35*4882a593Smuzhiyun	;;
36*4882a593Smuzhiyunenvironment*)
37*4882a593Smuzhiyun	print_skipped=1
38*4882a593Smuzhiyun	;;
39*4882a593Smuzhiyun*)
40*4882a593Smuzhiyun	print_skipped=0
41*4882a593Smuzhiyun	;;
42*4882a593Smuzhiyunesac
43*4882a593Smuzhiyun
44*4882a593Smuzhiyunfor board in $@; do
45*4882a593Smuzhiyun	board_cfg="${srctree}/arch/mips/configs/generic/board-${board}.config"
46*4882a593Smuzhiyun	if [ ! -f "${board_cfg}" ]; then
47*4882a593Smuzhiyun		echo "WARNING: Board config '${board_cfg}' not found"
48*4882a593Smuzhiyun		continue
49*4882a593Smuzhiyun	fi
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun	# For each line beginning with # require, cut out the field following
52*4882a593Smuzhiyun	# it & search for that in the reference config file. If the requirement
53*4882a593Smuzhiyun	# is not found then the subshell will exit with code 1, and we'll
54*4882a593Smuzhiyun	# continue on to the next board.
55*4882a593Smuzhiyun	grep -E '^# require ' "${board_cfg}" | \
56*4882a593Smuzhiyun	    cut -d' ' -f 3- | \
57*4882a593Smuzhiyun	    while read req; do
58*4882a593Smuzhiyun		case ${req} in
59*4882a593Smuzhiyun		*=y)
60*4882a593Smuzhiyun			# If we require something =y then we check that a line
61*4882a593Smuzhiyun			# containing it is present in the reference config.
62*4882a593Smuzhiyun			grep -Eq "^${req}\$" "${ref_cfg}" && continue
63*4882a593Smuzhiyun			;;
64*4882a593Smuzhiyun		*=n)
65*4882a593Smuzhiyun			# If we require something =n then we just invert that
66*4882a593Smuzhiyun			# check, considering the requirement met if there isn't
67*4882a593Smuzhiyun			# a line containing the value =y in the reference
68*4882a593Smuzhiyun			# config.
69*4882a593Smuzhiyun			grep -Eq "^${req/%=n/=y}\$" "${ref_cfg}" || continue
70*4882a593Smuzhiyun			;;
71*4882a593Smuzhiyun		*)
72*4882a593Smuzhiyun			echo "WARNING: Unhandled requirement '${req}'"
73*4882a593Smuzhiyun			;;
74*4882a593Smuzhiyun		esac
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun		[ ${print_skipped} -eq 1 ] && echo "Skipping ${board_cfg}"
77*4882a593Smuzhiyun		exit 1
78*4882a593Smuzhiyun	done || continue
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun	# Merge this board config fragment into our final config file
81*4882a593Smuzhiyun	${srctree}/scripts/kconfig/merge_config.sh \
82*4882a593Smuzhiyun		-m -O ${objtree} ${cfg} ${board_cfg} \
83*4882a593Smuzhiyun		| grep -Ev '^(#|Using)'
84*4882a593Smuzhiyundone
85