Skip to content
Snippets Groups Projects
boundary_insert 2.29 KiB
Newer Older
#!/bin/bash
# syntax ./boundary_insert CONFIG_1 CONFIG_2 ... CONFIG_n

insert_configs=$*;
boards=`ls -d board/boundary/* | sed 's.board/boundary/..'`;

numboards=0;
numsuccess=0;
numfailures=0;
skipped=0;
for board in ${boards} ; do
	update_cnt=0;
	already_there=0;
	if [ -e board/boundary/${board}/Kconfig ] ; then
		target=`grep TARGET_ board/boundary/${board}/Kconfig | sed 's.if ..'`;
		defconfigs=`git grep -w CONFIG_${target} configs/ | sed 's.configs/..'| sed 's/_defconfig:.*$//'`;
	else
		defconfigs="";
	fi
	board_cfgs=":"
	for defconfig in ${defconfigs} ; do
		cfgs=""
		for insert_config in ${insert_configs} ; do
			cnt=`sed -n "/${insert_config}=/=" configs/${defconfig}_defconfig`
			if [ "${cnt}" != "" ] ; then
				already_there=`expr $already_there + 1`;
			else
				cfgs="${cfgs} ${insert_config}"
			fi
		done

		if [ "${cfgs}" != "" ] ; then
			make ${defconfig}_defconfig;
			for insert_config in ${cfgs} ; do
				echo "${insert_config}=y" >>.config;
			done
			make savedefconfig;
			diff -q defconfig configs/${defconfig}_defconfig;
			if [ $? -eq 0 ] ; then
				already_there=`expr $already_there + 1`;
			else
				if [ $? -eq 1 ] ; then
					cp defconfig configs/${defconfig}_defconfig;
					echo updated ${defconfig}_defconfig;
					git update-index configs/${defconfig}_defconfig;
					update_cnt=`expr $update_cnt + 1`;
					for insert_config in ${cfgs} ; do
						if [ `expr "${board_cfgs}" : "[A-Z0-9_:]*:${insert_config}:"` -eq 0 ] ; then
							cnt=`sed -n "/${insert_config}=/=" configs/${defconfig}_defconfig`
							if [ "${cnt}" != "" ] ; then
								board_cfgs="${board_cfgs}:${insert_config}:"
							fi
						fi
					done
				else
					numfailures=`expr $numfailures + 1`;
					echo -e "\n\n\n!!!!!!!! insert failure for ${defconfig}_defconfig !!!!!!!!!!!!\n\n";
					read line;
				fi
			fi
		fi
	done
	if [ ${update_cnt} != "0" ] ; then
		echo "${board}: ${update_cnt} defconfigs updated, ${already_there} already there";
		numsuccess=`expr $numsuccess + 1`;
		if [ ${board_cfgs} != ":" ] ; then
			git c -m"${board}: add ${board_cfgs//::/ } to defconfigs";
		else
			git c -m"${board}: reorder defconfigs";
		fi
	else
		skipped=`expr $skipped + 1`;
	fi
	numboards=`expr $numboards + 1`;
done
echo "\n\ninsert for ${numboards} boards. ${numsuccess} succeeded and ${numfailures} failed, ${skipped} skipped";