xref: /openbmc/linux/arch/mips/tools/generic-board-config.sh (revision 75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37)
127e0d4b0SPaul Burton#!/bin/sh
2*2874c5fdSThomas Gleixner# SPDX-License-Identifier: GPL-2.0-or-later
327e0d4b0SPaul Burton#
427e0d4b0SPaul Burton# Copyright (C) 2017 Imagination Technologies
5fb615d61SPaul Burton# Author: Paul Burton <paul.burton@mips.com>
627e0d4b0SPaul Burton#
727e0d4b0SPaul Burton# This script merges configuration fragments for boards supported by the
827e0d4b0SPaul Burton# generic MIPS kernel. It checks each for requirements specified using
927e0d4b0SPaul Burton# formatted comments, and then calls merge_config.sh to merge those
1027e0d4b0SPaul Burton# fragments which have no unmet requirements.
1127e0d4b0SPaul Burton#
1227e0d4b0SPaul Burton# An example of requirements in your board config fragment might be:
1327e0d4b0SPaul Burton#
1427e0d4b0SPaul Burton# # require CONFIG_CPU_MIPS32_R2=y
1527e0d4b0SPaul Burton# # require CONFIG_CPU_LITTLE_ENDIAN=y
1627e0d4b0SPaul Burton#
1727e0d4b0SPaul Burton# This would mean that your board is only included in kernels which are
1827e0d4b0SPaul Burton# configured for little endian MIPS32r2 CPUs, and not for example in kernels
1927e0d4b0SPaul Burton# configured for 64 bit or big endian systems.
2027e0d4b0SPaul Burton#
2127e0d4b0SPaul Burton
2227e0d4b0SPaul Burtonsrctree="$1"
2327e0d4b0SPaul Burtonobjtree="$2"
2427e0d4b0SPaul Burtonref_cfg="$3"
2527e0d4b0SPaul Burtoncfg="$4"
2627e0d4b0SPaul Burtonboards_origin="$5"
2727e0d4b0SPaul Burtonshift 5
2827e0d4b0SPaul Burton
2927e0d4b0SPaul Burton# Only print Skipping... lines if the user explicitly specified BOARDS=. In the
3027e0d4b0SPaul Burton# general case it only serves to obscure the useful output about what actually
3127e0d4b0SPaul Burton# was included.
3227e0d4b0SPaul Burtoncase ${boards_origin} in
3327e0d4b0SPaul Burton"command line")
3427e0d4b0SPaul Burton	print_skipped=1
3527e0d4b0SPaul Burton	;;
3627e0d4b0SPaul Burtonenvironment*)
3727e0d4b0SPaul Burton	print_skipped=1
3827e0d4b0SPaul Burton	;;
3927e0d4b0SPaul Burton*)
4027e0d4b0SPaul Burton	print_skipped=0
4127e0d4b0SPaul Burton	;;
4227e0d4b0SPaul Burtonesac
4327e0d4b0SPaul Burton
4427e0d4b0SPaul Burtonfor board in $@; do
45e1270575SPaul Burton	board_cfg="${srctree}/arch/mips/configs/generic/board-${board}.config"
4627e0d4b0SPaul Burton	if [ ! -f "${board_cfg}" ]; then
4727e0d4b0SPaul Burton		echo "WARNING: Board config '${board_cfg}' not found"
4827e0d4b0SPaul Burton		continue
4927e0d4b0SPaul Burton	fi
5027e0d4b0SPaul Burton
5127e0d4b0SPaul Burton	# For each line beginning with # require, cut out the field following
5227e0d4b0SPaul Burton	# it & search for that in the reference config file. If the requirement
5327e0d4b0SPaul Burton	# is not found then the subshell will exit with code 1, and we'll
5427e0d4b0SPaul Burton	# continue on to the next board.
5527e0d4b0SPaul Burton	grep -E '^# require ' "${board_cfg}" | \
5627e0d4b0SPaul Burton	    cut -d' ' -f 3- | \
5727e0d4b0SPaul Burton	    while read req; do
5827e0d4b0SPaul Burton		case ${req} in
5927e0d4b0SPaul Burton		*=y)
6027e0d4b0SPaul Burton			# If we require something =y then we check that a line
6127e0d4b0SPaul Burton			# containing it is present in the reference config.
6227e0d4b0SPaul Burton			grep -Eq "^${req}\$" "${ref_cfg}" && continue
6327e0d4b0SPaul Burton			;;
6427e0d4b0SPaul Burton		*=n)
6527e0d4b0SPaul Burton			# If we require something =n then we just invert that
6627e0d4b0SPaul Burton			# check, considering the requirement met if there isn't
6727e0d4b0SPaul Burton			# a line containing the value =y in the reference
6827e0d4b0SPaul Burton			# config.
6927e0d4b0SPaul Burton			grep -Eq "^${req/%=n/=y}\$" "${ref_cfg}" || continue
7027e0d4b0SPaul Burton			;;
7127e0d4b0SPaul Burton		*)
7227e0d4b0SPaul Burton			echo "WARNING: Unhandled requirement '${req}'"
7327e0d4b0SPaul Burton			;;
7427e0d4b0SPaul Burton		esac
7527e0d4b0SPaul Burton
7627e0d4b0SPaul Burton		[ ${print_skipped} -eq 1 ] && echo "Skipping ${board_cfg}"
7727e0d4b0SPaul Burton		exit 1
7827e0d4b0SPaul Burton	done || continue
7927e0d4b0SPaul Burton
8027e0d4b0SPaul Burton	# Merge this board config fragment into our final config file
81e1270575SPaul Burton	${srctree}/scripts/kconfig/merge_config.sh \
8227e0d4b0SPaul Burton		-m -O ${objtree} ${cfg} ${board_cfg} \
8327e0d4b0SPaul Burton		| grep -Ev '^(#|Using)'
8427e0d4b0SPaul Burtondone
85