code:
#!/bin/bash

# Copyright (C) 2016 Paul Kocialkowski <contact@paulk.fr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

PROJECT_ACTIONS_GENERIC="usage download extract update build install release clean"
PROJECT_ACTIONS_HELPERS="arguments"
PROJECT_FUNCTIONS=$( for action in $PROJECT_ACTIONS_GENERIC ; do echo "$action" "$action""_check" ; done ; echo "$PROJECT_ACTIONS_HELPERS" )

INSTALL_REGEX="\([^:]*\):\(.*\)"

project_include() {
	local project=$1

	local project_path=$( project_path "$project" )

	unset -f $PROJECT_FUNCTIONS

	. "$project_path/$project"

	project_helper_include "$project"
}

project_helper_include() {
	local project=$1

	local project_path=$( project_path "$project" )
	local include="$project_path/$project-helper"

	if [ -f "$include" ]
	then
		. "$include"
	fi
}

project_check() {
	local project=$1

	local project_path=$( project_path "$project" )

	if ! [ -f "$project_path/$project" ]
	then
		return 1
	fi

	return 0
}

project_function_check() {
	local project=$1
	local function=$2

	project_include "$project"

	if ! function_check "$function"
	then
		return 1
	fi

	return 0
}

project_action() {
	local action=$1
	shift
	local project=$1
	shift
	local arguments=$@

	(
		set +e

		if ! project_check "$project"
		then
			printf "Project $project check failed\n" >&2
			return 1
		fi

		project_action_check "$action" "$project" "$@"

		if [ $? -eq 0 ]
		then
			return 0
		fi

		project_include "$project"

		if ! function_check "$action"
		then
			return 0
		fi

		printf "Project $project $action (with ${arguments:-no argument})\n" >&2

		(
			set -e
			"$action" "$@"
		)

		if [ $? -ne 0 ]
		then
			printf "\nProject $project $action (with ${arguments:-no argument}) failed\n" >&2
			return 1
		else
			printf "\nProject $project $action (with ${arguments:-no argument}) completed\n" >&2
		fi
	)
}

project_action_check() {
	local action=$1
	shift
	local project=$1
	shift

	(
		set +e

		if ! project_check "$project"
		then
			printf "Project $project check failed\n" >&2
			return 1
		fi

		project_include "$project"

		if ! function_check "$action""_check"
		then
			return 1
		fi

		for project_force in $PROJECTS_FORCE
		do
			if [ "$project_force" = "$project" ]
			then
				return 1
			fi
		done

		(
			set -e
			"$action""_check" "$@"
		)
	)
}

project_action_helper() {
	local helper=$1
	shift
	local project=$1
	shift

	(
		set +e

		if ! project_check "$project"
		then
			printf "Project $project check failed\n" >&2
			return 1
		fi

		project_include "$project"

		if ! function_check "$helper"
		then
			return 0
		fi

		(
			set -e
			"$helper" "$@"
		)
	)
}

project_action_arguments() {
	local action=$1
	shift
	local project=$1
	shift

	project_action_arguments_verify_recursive "$action" "$project" "$@"
	project_action_arguments_recursive "$action" "$project" "$@"
}

project_action_arguments_verify_recursive() {
	local action=$1
	shift
	local project=$1
	shift

	local action_helper_arguments

	# Store final argument.
	local argument=${@:$#}

	local test

	if [ $# -gt 1 ]
	then
		# Set previous arguments.
		set "${@:1:$#-1}"
	elif [ $# -eq 1 ]
	then
		shift
	else
		return 0
	fi

	action_helper_arguments=$( project_action_helper "arguments" "$project" "$@" )

	if ! [ -z "$action_helper_arguments" ]
	then
		test=$( echo "$action_helper_arguments" | grep -P "^$argument$" || true )

		if [ -z "$test" ]
		then
			printf "Invalid argument $argument for project $project action $action\n" >&2
			return 1
		fi
	fi

	project_action_arguments_verify_recursive "$action" "$project" "$@"
}

project_action_arguments_recursive() {
	local action=$1
	shift
	local project=$1
	shift

	local action_helper_arguments
	local argument
	local ifs_save

	action_helper_arguments=$( project_action_helper "arguments" "$project" "$@" )

	if [ $? -ne 0 ] || [ -z "$action_helper_arguments" ]
	then
		project_action "$action" "$project" "$@"
	else
		# This it to allow space characters in arguments.
		ifs_save=$IFS
		IFS=$'\n'

		for argument in $( echo "$action_helper_arguments" )
		do
			(
				IFS=$ifs_save

				# Only a single argument at a time is returned by the helper.
				project_action_arguments_recursive "$action" "$project" "$@" "$argument"
			)
		done

		IFS=$ifs_save
	fi
}

project_action_projects() {
	local action=$1
	shift
	local project=$1
	shift

	local project_path=$( project_path "$project" )
	local project_projects_path="$project_path/$CONFIGS/$PROJECTS"
	local project_projects_action_path="$project_path/$CONFIGS/$PROJECTS-$action"
	local arguments
	local path

	if [ -f "$project_projects_action_path" ]
	then
		path=$project_projects_action_path
	else
		path=$project_projects_path
	fi

	# Multiple arguments can be read from the file.
	while read arguments
	do
		eval "project_action_arguments "$action" $arguments"
	done < "$path"
}

project_path() {
	local project=$1

	local project_path="$root/$PROJECTS/$project"

	echo "$project_path"
}

project_sources_path() {
	local project=$1
	shift
	local repository=$1
	shift

	local sources_path
	local argument
	local path

	# Check downloaded and extracted sources first, using "$project."
	path="$root/$SOURCES/$project"

	for argument in "" "$@"
	do
		if ! [ -z "$argument" ]
		then
			path="$path-$argument"
		fi

		if ! directory_filled_check "$path"
		then
			continue
		fi

		sources_path=$path
	done

	if ! [ -z "$sources_path" ]
	then
		echo "$sources_path"
		return
	fi

	# Check downloaded sources then, using "$repository."
	path="$root/$SOURCES/$repository"

	if directory_filled_check "$path"
	then
		echo "$path"
		return
	fi

	# Check project sources finally, using "$project."
	path="$root/$PROJECTS/$project/$SOURCES"

	for argument in "" "$@"
	do
		if ! [ -z "$argument" ]
		then
			path="$path/$argument"
		fi

		if ! directory_filled_check "$path"
		then
			continue
		fi

		sources_path=$path
	done

	if ! [ -z "$sources_path" ]
	then
		echo "$sources_path"
		return
	fi
}

project_sources_directory_filled_check() {
	local project=$1
	shift

	local sources_path=$( project_sources_path "$project" "$@" )

	test ! -z "$sources_path"
}

project_sources_directory_filled_error() {
	local project=$1
	shift
	local arguments=$@

	local sources_path=$( project_sources_path "$project" "$@" )

	if ! [ -z "$sources_path" ]
	then
		printf "Sources directory for project $project (with ${arguments:-no argument}) already exists\n" >&2
		return 1
	else
		return 0
	fi
}

project_sources_directory_missing_empty_error() {
	local project=$1
	shift
	local arguments=$@

	local sources_path=$( project_sources_path "$project" "$@" )

	if [ -z "$sources_path" ]
	then
		printf "Sources directory for project $project (with ${arguments:-no argument}) missing or empty\n" >&2
		return 1
	else
		return 0
	fi
}

project_sources_archive() {
	local project=$1
	shift

	local sources_archive
	local argument
	local path="$root/$SOURCES/$project"

	for argument in "" "$@"
	do
		if ! [ -z "$argument" ]
		then
			path="$path-$argument"
		fi

		local archive="$path.$TAR_XZ"

		if ! [ -f "$archive" ]
		then
			continue
		fi

		sources_archive=$archive
	done

	if ! [ -z "$sources_archive" ]
	then
		echo "$sources_archive"
	fi
}

project_sources_archive_extract() {
	local project=$1
	shift
	local arguments=$@

	local archive=$( project_sources_archive "$project" "$@" )
	local destination=$( dirname "$archive" )

	printf "Extracting source archive for $project (with ${arguments:-no argument})\n"

	file_verification_check "$archive"
	archive_extract "$archive" "$destination"
}

project_sources_archive_update() {
	local project=$1
	shift
	local arguments=$@

	local repository=$project
	local sources_path=$( project_sources_path "$project" "$repository" "$@" )
	local archive=$( project_sources_archive "$project" "$@" )
	local destination=$( dirname "$archive" )

	if [ -d "$sources_path" ]
	then
		rm -rf "$sources_path"
	fi

	printf "Extracting source archive for $project (with ${arguments:-no argument})\n"

	file_verification_check "$archive"
	archive_extract "$archive" "$destination"
}

project_sources_archive_missing_error() {
	local project=$1
	shift
	local arguments=$@

	local archive=$( project_sources_archive "$project" "$@" )
	if [ -z "$archive" ] || ! [ -f "$archive" ]
	then
		printf "Missing sources archive for $project (with ${arguments:-no argument})\n" >&2
		return 1
	else
		return 0
	fi
}

project_sources_archive_missing_check() {
	local project=$1
	shift

	local archive=$( project_sources_archive "$project" "$@" )
	if [ -z "$archive" ] || ! [ -f "$archive" ]
	then
		return 0
	else
		return 1
	fi
}

project_blobs_path() {
	local project=$1
	shift

	local project_path=$( project_path "$project" )
	local configs_path="$project_path/$CONFIGS"
	local argument
	local path

	for argument in "" "$@"
	do
		if ! [ -z "$argument" ]
		then
			if [ -z "$path" ]
			then
				path="$argument"
			else
				path="$path/$argument"
			fi
		fi

		local blobs_path="$configs_path/$path/$BLOBS"

		if [ -f "$blobs_path" ]
		then
			echo "$blobs_path"
			return
		fi
	done

	echo "$blobs_path"
}

project_blobs_ignore_path() {
	local project=$1
	shift

	local project_path=$( project_path "$project" )
	local configs_path="$project_path/$CONFIGS"
	local argument
	local path

	for argument in "" "$@"
	do
		if ! [ -z "$argument" ]
		then
			if [ -z "$path" ]
			then
				path="$argument"
			else
				path="$path/$argument"
			fi
		fi

		blobs_ignore_path="$configs_path/$path/$BLOBS_IGNORE"

		if [ -f "$blobs_ignore_path" ]
		then
			echo "$blobs_ignore_path"
			return
		fi
	done
}

project_arguments_targets() {
	local project=$1
	shift

	local project_path=$( project_path "$project" )
	local targets_path="$project_path/$CONFIGS"
	local argument

	for argument in "$@"
	do
		targets_path="$targets_path/$argument"
	done

	targets_path="$targets_path/$TARGETS"

	if [ -f "$targets_path" ]
	then
		cat "$targets_path"
	fi
}

project_usage_actions() {
	local project=$1
	shift

	printf "\nGeneric actions:\n"

	for action in $PROJECT_ACTIONS_GENERIC
	do
		if function_check "$action"
		then
			printf "  $action\n"
		fi
	done

	if [ $# -gt 0 ]
	then
		printf "\nSpecific actions:\n"

		for action in "$@"
		do
			printf "  $action\n"
		done
	fi
}

project_usage_arguments() {
	local project=$1
	shift

	printf "\nArguments:\n"

	project_usage_arguments_recursive "$project" "  " "$@"
}

project_usage_arguments_recursive() {
	local project=$1
	shift
	local spacing=$1
	shift

	local action_helper_arguments
	local argument

	action_helper_arguments=$( project_action_helper "arguments" "$project" "$@" )

	if ! [ -z "$action_helper_arguments" ]
	then
		echo "$action_helper_arguments" | while read argument
		do
			printf "$spacing$argument\n"
			project_usage_arguments_recursive "$project" "  $spacing" "$@" "$argument"
		done
	fi
}

project_download_git() {
	local project=$1
	shift
	local repository=$1
	shift
	local urls=$1
	shift

	requirements "git"

	if ! git_project_check "$repository"
	then
		project_sources_directory_filled_error "$project" "$repository" "$@"

		git_project_clone "$repository" "$urls"
	fi

	git_project_prepare "$project" "$repository" "$@"
}

project_download_check_git() {
	local project=$1
	shift
	local repository=$1
	shift

	requirements "git"

	git_project_check "$repository"
	git_project_prepare_check "$project" "$repository" "$@"
}

project_extract() {
	local project=$1
	shift

	local repository=$project

	if ! project_sources_directory_filled_check "$project" "$repository" "$@"
	then
		project_sources_archive_missing_error "$project" "$@"
		project_sources_archive_extract "$project" "$@"
	fi
}

project_extract_check() {
	local project=$1
	shift

	local repository=$project

	project_sources_directory_filled_check "$project" "$repository" "$@"
}

project_update_git() {
	local project=$1
	shift
	local repository=$1
	shift

	requirements "git"

	project_sources_directory_missing_empty_error "$project" "$repository" "$@"

	if git_project_check "$repository"
	then
		git_project_update "$project" "$repository" "$@"
	else
		if ! project_sources_archive_missing_check "$project" "$@"
		then
			project_sources_archive_update "$project" "$@"
		fi
	fi
}

project_update_check_git() {
	local project=$1
	shift
	local repository=$1
	shift

	requirements "git"

	if git_project_check "$repository"
	then
		# Git repository should always be updated (even if upstream didn't progress).
		# For instance, this is useful for testing new versions of patches without changing revision.
		return 1
	else
		project_sources_archive_missing_check "$project" "$@"
	fi
}

project_build_check() {
	local project=$1
	shift

	local project_path=$( project_path "$project" )
	local build_path=$( project_build_path "$project" "$@" )
	local source_file_path
	local argument
	local rule
	local path

	for argument in "" "$@"
	do
		if ! [ -z "$argument" ]
		then
			if [ -z "$path" ]
			then
				path="$argument"
			else
				path="$path/$argument"
			fi
		fi

		configs_install_path="$project_path/$CONFIGS/$path/$INSTALL"

		if ! [ -f "$configs_install_path" ]
		then
			continue
		fi

		while read rule
		do
			source=$( echo "$rule" | sed "s/$INSTALL_REGEX/\1/g" )
			source_path="$build_path/$source"

			# Source may contain a wildcard.
			path_wildcard_expand "$source_path" | while read source_file_path
			do
				if ! [ -f "$source_file_path" ] && ! [ -d "$source_file_path" ]
				then
					false
				fi
			done
		done < "$configs_install_path"
	done
}

project_build_path() {
	local project=$1
	shift

	local build_path="$root/$BUILD/$project"
	local argument

	for argument in "$@"
	do
		build_path="$build_path-$argument"
	done

	echo "$build_path"
}

project_build_directory_missing_empty_error() {
	local project=$1
	shift
	local arguments=$@

	local build_path=$( project_build_path "$project" "$@" )

	if ! directory_filled_check "$build_path"
	then
		printf "Build directory for project $project (with ${arguments:-no argument}) missing or empty\n" >&2
		return 1
	else
		return 0
	fi
}

project_install() {
	local project=$1
	shift

	local project_path=$( project_path "$project" )
	local build_path=$( project_build_path "$project" "$@" )
	local install_path=$( project_install_path "$project" "$@" )
	local source_file_path
	local argument
	local rule
	local path

	# Install built files first.
	for argument in "" "$@"
	do
		if ! [ -z "$argument" ]
		then
			if [ -z "$path" ]
			then
				path="$argument"
			else
				path="$path/$argument"
			fi
		fi

		configs_install_path="$project_path/$CONFIGS/$path/$INSTALL"

		if ! [ -f "$configs_install_path" ]
		then
			continue
		fi

		project_build_directory_missing_empty_error "$project" "$@"

		while read rule
		do
			source=$( echo "$rule" | sed "s/$INSTALL_REGEX/\1/g" )
			source_path="$build_path/$source"

			destination=$( echo "$rule" | sed "s/$INSTALL_REGEX/\2/g" )
			destination_path="$install_path/$destination"
			destination_directory_path=$( dirname "$destination_path" )

			mkdir -p "$destination_directory_path"

			# Source may contain a wildcard.
			path_wildcard_expand "$source_path" | while read source_file_path
			do
				cp -rT "$source_file_path" "$destination_path"
			done
		done < "$configs_install_path"
	done

	path=""

	# Install install files then.
	for argument in "" "$@"
	do
		if ! [ -z "$argument" ]
		then
			if [ -z "$path" ]
			then
				path="$argument"
			else
				path="$path/$argument"
			fi
		fi

		install_install_path="$project_path/$INSTALL/$path/$INSTALL"

		if ! [ -f "$install_install_path" ]
		then
			continue
		fi

		while read rule
		do
			source=$( echo "$rule" | sed "s/$INSTALL_REGEX/\1/g" )
			source_path="$project_path/$INSTALL/$path/$source"

			destination=$( echo "$rule" | sed "s/$INSTALL_REGEX/\2/g" )
			destination_path="$install_path/$destination"
			destination_directory_path=$( dirname "$destination_path" )

			mkdir -p "$destination_directory_path"

			# Source may contain a wildcard.
			path_wildcard_expand "$source_path" | while read source_file_path
			do
				cp -rT "$source_file_path" "$destination_path"
			done
		done < "$install_install_path"
	done
}

project_install_check() {
	local project=$1
	shift

	local project_path=$( project_path "$project" )
	local build_path=$( project_build_path "$project" "$@" )
	local install_path=$( project_install_path "$project" "$@" )
	local argument
	local rule
	local path

	# Install built files first.
	for argument in "" "$@"
	do
		if ! [ -z "$argument" ]
		then
			if [ -z "$path" ]
			then
				path="$argument"
			else
				path="$path/$argument"
			fi
		fi

		configs_install_path="$project_path/$CONFIGS/$path/$INSTALL"

		if ! [ -f "$configs_install_path" ]
		then
			continue
		fi

		project_build_directory_missing_empty_error "$project" "$@"

		while read rule
		do
			destination=$( echo "$rule" | sed "s/$INSTALL_REGEX/\2/g" )
			destination_path="$install_path/$destination"

			if ! [ -f "$destination_path" ] && ! [ -d "$destination_path" ]
			then
				false
			fi
		done < "$configs_install_path"
	done

	path=""

	# Install install files then.
	for argument in "" "$@"
	do
		if ! [ -z "$argument" ]
		then
			if [ -z "$path" ]
			then
				path="$argument"
			else
				path="$path/$argument"
			fi
		fi

		install_install_path="$project_path/$INSTALL/$path/$INSTALL"

		if ! [ -f "$install_install_path" ]
		then
			continue
		fi

		while read rule
		do
			destination=$( echo "$rule" | sed "s/$INSTALL_REGEX/\2/g" )
			destination_path="$install_path/$destination"

			if ! [ -f "$destination_path" ] && ! [ -d "$destination_path" ]
			then
				false
			fi
		done < "$install_install_path"
	done
}

project_install_path() {
	local project=$1
	shift

	local install_path="$root/$INSTALL/$project"
	local argument

	for argument in "$@"
	do
		install_path="$install_path-$argument"
	done

	echo "$install_path"
}

project_install_directory_missing_empty_error() {
	local project=$1
	shift
	local arguments=$@

	local install_path=$( project_install_path "$project" "$@" )

	if ! directory_filled_check "$install_path"
	then
		printf "Install directory for project $project (with ${arguments:-no argument}) missing or empty\n" >&2
		return 1
	else
		return 0
	fi
}

project_release_path() {
	local project=$1
	shift
	local prefix=$1

	local release_path="$root/$RELEASE/$prefix"

	# Special care for tools and systems, that depend on the host arch.
	if [ "$prefix" = "$SYSTEMS" ] || [ "$prefix" = "$TOOLS" ]
	then
		local machine=$( uname -m )

		release_path="$release_path/$machine/$project"
	else
		release_path="$release_path/$project"
	fi

	echo "$release_path"
}

project_release_archive_path() {
	local project=$1
	shift
	local prefix=$1
	shift

	local release_path=$( project_release_path "$project" "$prefix" )
	local argument
	local path="$project"

	for argument in "$@"
	do
		path="$path-$argument"
	done

	local archive_path="$release_path/$path.$TAR_XZ"

	echo "$archive_path"
}

project_release_rootfs_path() {
	local project=$1
	shift
	local prefix=$1
	shift

	local release_path=$( project_release_path "$project" "$prefix" )
	local argument
	local path="$project"

	for argument in "$@"
	do
		path="$path-$argument"
	done

	local rootfs_path="$release_path/$path.$TAR_XZ"

	echo "$rootfs_path"
}

project_release_sources_archive_path() {
	local project=$1
	shift

	local sources_path="$root/$SOURCES/"
	local release_path
	local argument
	local path="$project"

	for argument in "" "$@"
	do
		if ! [ -z "$argument" ]
		then
			path="$path-$argument"
		fi

		local directory_path="$sources_path/$path"

		if ! directory_filled_check "$directory_path"
		then
			continue
		fi

		release_path=$path
	done

	if ! [ -z "$release_path" ]
	then
		local archive_path="$root/$RELEASE/$SOURCES/$project/$release_path.$TAR_XZ"

		echo "$archive_path"
	fi
}

project_release_sources_archive_create() {
	local project=$1
	shift
	local arguments=$@

	local repository=$project
	local archive_path=$( project_release_sources_archive_path "$project" "$@" )
	local sources_path=$( project_sources_path "$project" "$repository" "$@" )

	printf "Releasing sources archive for $project (with ${arguments:-no argument})\n"

	archive_create "$archive_path" "$sources_path"
	file_verification_create "$archive_path"
}

project_release_sources_archive_exists_check() {
	local project=$1
	shift

	local archive_path=$( project_release_sources_archive_path "$project" "$@" )
	if [ -z "$archive_path" ] || ! [ -f "$archive_path" ]
	then
		return 1
	else
		return 0
	fi
}

project_release_sources_git() {
	local project=$1
	shift
	local repository=$1
	shift

	requirements "git"

	project_sources_directory_missing_empty_error "$project" "$repository" "$@"

	if git_project_check "$repository"
	then
		if ! git_project_release_check "$project" "$repository" "$@"
		then
			git_project_release "$project" "$repository" "$@"
		fi
	else
		if ! project_release_sources_archive_exists_check "$project" "$@"
		then
			project_release_sources_archive_create "$project" "$@"
		fi
	fi
}

project_release_check_sources_git() {
	local project=$1
	shift
	local repository=$1
	shift

	requirements "git"

	if git_project_check "$repository"
	then
		git_project_release_check "$project" "$repository" "$@"
	else
		project_release_sources_archive_exists_check "$project" "$@"
	fi
}

project_release_install() {
	local project=$1
	shift
	local prefix=$1
	shift

	local install_path=$( project_install_path "$project" "$@" )
	local release_path=$( project_release_path "$project" "$prefix" )
	local directory_path
	local path

	project_install_directory_missing_empty_error "$project" "$@"

	local files=$( cd "$install_path" && find -type f || true )
	local file

	echo "$files" | while read file
	do
		path="$release_path/$file"
		directory_path=$( dirname "$path" )

		mkdir -p "$directory_path"

		cp "$install_path/$file" "$path"
		file_verification_create "$path"
	done
}

project_release_install_check() {
	local project=$1
	shift
	local prefix=$1
	shift

	local install_path=$( project_install_path "$project" "$@" )
	local release_path=$( project_release_path "$project" "$prefix" )
	local path

	project_install_directory_missing_empty_error "$project" "$@"

	local files=$( cd "$install_path" && find -type f || true )
	local file

	echo "$files" | while read file
	do
		path="$release_path/$file"

		file_exists_check "$path"
	done
}

project_release_install_archive() {
	local project=$1
	shift
	local prefix=$1
	shift

	project_install_directory_missing_empty_error "$project" "$@"

	project_release_install_archive_create "$project" "$prefix" "$@"
}

project_release_install_archive_check() {
	local project=$1
	shift

	project_release_install_archive_exists_check "$project" "$@"
}

project_release_install_archive_create() {
	local project=$1
	shift
	local prefix=$1
	shift
	local arguments=$@

	local install_path=$( project_install_path "$project" "$@" )
	local archive_path=$( project_release_archive_path "$project" "$prefix" "$@" )

	printf "Releasing $prefix archive for $project (with ${arguments:-no argument})\n"

	archive_create "$archive_path" "$install_path"
	file_verification_create "$archive_path"
}

project_release_install_archive_exists_check() {
	local project=$1
	shift
	local prefix=$1
	shift

	local archive_path=$( project_release_archive_path "$project" "$prefix" "$@" )

	file_exists_check "$archive_path"
}

project_release_install_rootfs() {
	local project=$1
	shift
	local prefix=$1
	shift

	project_install_directory_missing_empty_error "$project" "$@"

	if ! project_release_install_rootfs_exists_check "$project" "$prefix" "$@"
	then
		project_release_install_rootfs_create "$project" "$prefix" "$@"
	fi
}

project_release_install_rootfs_check() {
	local project=$1
	shift

	project_release_install_rootfs_exists_check "$project" "$@"
}

project_release_install_rootfs_create() {
	local project=$1
	shift
	local prefix=$1
	shift
	local arguments=$@

	local install_path=$( project_install_path "$project" "$@" )
	local rootfs_path=$( project_release_rootfs_path "$project" "$prefix" "$@" )

	printf "Releasing $prefix rootfs for $project (with ${arguments:-no argument})\n"

	rootfs_create "$rootfs_path" "$install_path"
	file_verification_create "$rootfs_path"
}

project_release_install_rootfs_exists_check() {
	local project=$1
	shift
	local prefix=$1
	shift

	local rootfs_path=$( project_release_rootfs_path "$project" "$prefix" "$@" )

	file_exists_check "$rootfs_path"
}

project_clean() {
	local project=$1
	shift

	project_clean_build "$project" "$@"
	project_clean_install "$project" "$@"
	project_clean_release "$project" "$@"
}

project_clean_build() {
	local project=$1
	shift

	local build_path=$( project_build_path "$project" "$@" )

	rm -rf "$build_path"
}

project_clean_install() {
	local project=$1
	shift

	local install_path=$( project_install_path "$project" "$@" )

	rm -rf "$install_path"
}

project_clean_release() {
	local project=$1
	shift

	local prefix

	for prefix in "$SOURCES" "$SYSTEMS" "$IMAGES" "$TOOLS" "$DOCS"
	do
		local release_path=$( project_release_path "$project" "$prefix" )

		rm -rf "$release_path"
	done
}

project_clean_rootfs() {
	local project=$1
	shift

	project_clean_build "$project" "$@"
	project_clean_rootfs_install "$project" "$@"
	project_clean_release "$project" "$@"

}

project_clean_rootfs_install() {
	local project=$1
	shift

	local install_path=$( project_install_path "$project" "$@" )

	execute_root rm -rf "$install_path"

}

project_file_path() {
	local project=$1
	shift
	local directory=$1
	shift
	local file=$1
	shift

	local project_path=$( project_path "$project" )
	local path="$project_path/$directory"
	local argument
	local file_path

	for argument in "" "$@"
	do
		if ! [ -z "$argument" ]
		then
			path="$path/$argument"
		fi

		if ! [ -f "$path/$file" ]
		then
			continue
		fi

		file_path="$path/$file"
	done

	if [ -z "$file_path" ]
	then
		return 1
	fi

	echo "$file_path"
}

project_file_test() {
	local file_path=$( project_file_path "$@" )

	test -f "$file_path"
}

project_file_contents() {
	local file_path=$( project_file_path "$@" )

	if [ -f "$file_path" ]
	then
		cat "$file_path"
	fi
}

project_file_contents_herit() {
	local project=$1
	shift
	local directory=$1
	shift
	local file=$1
	shift

	local project_path=$( project_path "$project" )
	local path="$project_path/$directory"
	local argument
	local file_path

	for argument in "" "$@"
	do
		if ! [ -z "$argument" ]
		then
			path="$path/$argument"
		fi

		file_path="$path/$file"

		if ! [ -f "$file_path" ]
		then
			continue
		fi

		cat "$file_path"
	done
}

path: libs/project


code:
#!/bin/bash

# Copyright (C) 2016 Paul Kocialkowski <contact@paulk.fr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

TOOL_ACTIONS_GENERIC="usage update execute"
TOOL_ACTIONS_HELPERS="arguments"
TOOL_FUNCTIONS=$( for action in $TOOL_ACTIONS_GENERIC ; do echo "$action" "$action""_check" ; done ; echo "$TOOL_ACTIONS_HELPERS" )

tool_include() {
	local tool=$1

	local tool_path=$( tool_path "$tool" )

	unset -f $TOOL_FUNCTIONS

	. "$tool_path/$tool"

	tool_helper_include "$tool"
}

tool_helper_include() {
	local tool=$1

	local tool_path=$( tool_path "$tool" )
	local include="$tool_path/$tool-helper"

	if [ -f "$include" ]
	then
		. "$include"
	fi
}

tool_check() {
	local tool=$1

	local tool_path=$( tool_path "$tool" )

	if ! [ -f "$tool_path/$tool" ]
	then
		return 1
	fi

	return 0
}

tool_function_check() {
	local tool=$1
	local function=$2

	tool_include "$tool"

	if ! function_check "$function"
	then
		return 1
	fi

	return 0
}

tool_action() {
	local action=$1
	shift
	local tool=$1
	shift
	local arguments=$@

	(
		set +e

		if ! tool_check "$tool"
		then
			printf "Tool $tool check failed\n" >&2
			return 1
		fi

		tool_action_check "$action" "$tool" "$@"

		if [ $? -eq 0 ]
		then
			return 0
		fi

		tool_include "$tool"

		if ! function_check "$action"
		then
			return 0
		fi

		printf "Tool $tool $action (with ${arguments:-no argument})\n" >&2

		(
			set -e
			"$action" "$@"
		)

		if [ $? -ne 0 ]
		then
			printf "\nTool $tool $action (with ${arguments:-no argument}) failed\n" >&2
			return 1
		else
			printf "\nTool $tool $action (with ${arguments:-no argument}) completed\n" >&2
		fi
	)
}

tool_action_check() {
	local action=$1
	shift
	local tool=$1
	shift

	(
		set +e

		if ! tool_check "$tool"
		then
			printf "Tool $tool check failed\n" >&2
			return 1
		fi

		tool_include "$tool"

		if ! function_check "$action""_check"
		then
			return 1
		fi

		for tool_force in $TOOLS_FORCE
		do
			if [ "$tool_force" = "$tool" ]
			then
				return 1
			fi
		done

		(
			set -e
			"$action""_check" "$@"
		)
	)
}

tool_action_helper() {
	local helper=$1
	shift
	local tool=$1
	shift

	(
		set +e

		if ! tool_check "$tool"
		then
			printf "Tool $tool check failed\n" >&2
			return 1
		fi

		tool_include "$tool"

		if ! function_check "$helper"
		then
			return 0
		fi

		(
			set -e
			"$helper" "$@"
		)
	)
}

tool_action_arguments_recursive() {
	local action=$1
	shift
	local tool=$1
	shift

	local action_helper_arguments=$( tool_action_helper "arguments" "$tool" "$@" )
	local argument

	if [ $? -ne 0 ] || [ -z "$action_helper_arguments" ]
	then
		tool_action "$action" "$tool" "$@"
	else
		echo "$action_helper_arguments" | while read argument
		do
			tool_action_arguments_recursive "$action" "$tool" "$@" "$argument"
		done
	fi
}

tool_path() {
	local tool=$1

	local tool_path="$root/$TOOLS/$tool"

	echo "$tool_path"
}

tool_sources_path() {
	local tool=$1
	shift

	local path="$root/$TOOLS/$tool/$SOURCES"
	local argument

	for argument in "" "$@"
	do
		if ! [ -z "$argument" ]
		then
			path="$path/$argument"
		fi

		if directory_filled_check "$path"
		then
			echo "$path"
			return
		fi
	done
}

tool_usage_actions() {
	local tool=$1
	shift

	printf "\nGeneric actions:\n"

	for action in $TOOL_ACTIONS_GENERIC
	do
		if function_check "$action"
		then
			printf "  $action\n"
		fi
	done

	if [ $# -gt 0 ]
	then
		printf "\nSpecific actions:\n"

		for action in "$@"
		do
			printf "  $action\n"
		done
	fi
}

tool_usage_arguments() {
	local tool=$1
	shift

	printf "\nArguments:\n"

	tool_usage_arguments_recursive "$tool" "  " "$@"
}

tool_usage_arguments_recursive() {
	local tool=$1
	shift
	local spacing=$1
	shift

	local action_helper_arguments=$( tool_action_helper "arguments" "$tool" "$@" )
	local argument

	if ! [ -z "$action_helper_arguments" ]
	then
		echo "$action_helper_arguments" | while read argument
		do
			printf "$spacing$argument\n"
			tool_usage_arguments_recursive "$tool" "  $spacing" "$@" "$argument"
		done
	fi
}

tool_file_path() {
	local tool=$1
	shift
	local directory=$1
	shift
	local file=$1
	shift

	local tool_path=$( tool_path "$tool" )
	local path="$tool_path/$directory"
	local argument
	local file_path

	for argument in "" "$@"
	do
		if ! [ -z "$argument" ]
		then
			path="$path/$argument"
		fi

		if ! [ -f "$path/$file" ]
		then
			continue
		fi

		file_path="$path/$file"
	done

	if [ -z "$file_path" ]
	then
		return 1
	fi

	echo "$file_path"
}

tool_file_test() {
	local file_path=$( tool_file_path "$@" )

	test -f "$file_path"
}

tool_file_contents() {
	local file_path=$( tool_file_path "$@" )

	if [ -f "$file_path" ]
	then
		cat "$file_path"
	fi
}

tool_file_contents_herit() {
	local tool=$1
	shift
	local directory=$1
	shift
	local file=$1
	shift

	local tool_path=$( tool_path "$tool" )
	local path="$tool_path/$directory"
	local argument
	local file_path

	for argument in "" "$@"
	do
		if ! [ -z "$argument" ]
		then
			path="$path/$argument"
		fi

		file_path="$path/$file"

		if ! [ -f "$file_path" ]
		then
			continue
		fi

		cat "$file_path"
	done
}

repo_name: johnmh/libreboot

path: libs/tool

license: mit


code:
#!/bin/sh

#  generic build script, for building components (all of them)
#
#	Copyright (C) 2014, 2015 Leah Rowe <info@minifree.org>
#	Copyright (C) 2015 Patrick "P. J." McDermott <pj@pehjota.net>
#	Copyright (C) 2015, 2016 Klemens Nanni <contact@autoboot.org>
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

[ "x${DEBUG+set}" = 'xset' ] && set -v
set -u -e

build=./resources/scripts/helpers/build

listmodes() {
	for mode in "${build}"/*; do
		printf '%s\n' "${mode##*/}"
	done
}

# Takes exactly one mode as parameter
listoptions() {
	for option in "${build}"/"${1}"/*; do
		printf '%s\n' "${option##*/}"
	done
}

help() {
	cat <<- EOF
	USAGE:	./oldbuild <MODE> <OPTION>

	possible values for 'mode':
	$(listmodes)

	Example:	./oldbuild module all
	Example:	./oldbuild module flashrom [static]
	Example:	./oldbuild roms withgrub
	Example:	./oldbuild clean all

	Refer to the libreboot documentation for more information.
	EOF
}

die() {
	printf 'Error: %s\n' "${@}" 1>&2
	exit 1
}

if [ $# -lt 1 ]; then
	die "Wrong number of arguments specified. See './oldbuild help'."
fi

mode="${1}"

[ "${mode}" = help ] && help && exit 0

if [ $# -gt 1 ]; then

    option="${2}"
    shift 2

    case "${option}" in
    	list)
    		printf "Available options for mode '%s':\n\n" "${mode}"
    		listoptions "${mode}"
    		;;
    	all)
    		for option in $(listoptions "${mode}"); do
    			"${build}"/"${mode}"/"${option}" $@
    		done
    		;;
    	*)
    		if [ -d "${build}"/"${mode}"/ ]; then
    			if [ -f "${build}"/"${mode}"/"${option}" ]; then
    				"${build}"/"${mode}"/"${option}" $@
    			else
                    help
    				die "Invalid option for '${mode}'. See './oldbuild ${mode} list'."
    			fi
    		else
                help
    			die "Invalid mode '${mode}'. See './oldbuild help'."
    		fi
    esac
else
    help
    exit 0
fi

path: oldbuild


code:
#!/bin/bash

# Copyright (C) 2016 Paul Kocialkowski <contact@paulk.fr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

download() {
	local repository="coreboot"

	git_project_prepare "$project" "$repository" "$@"
}

download_check() {
	local repository="coreboot"

	git_project_prepare_check "$project" "$repository" "$@"
}

extract() {
	local repository="coreboot"

	project_extract "$project" "$@"
}

extract_check() {
	local repository="coreboot"

	project_extract_check "$project" "$@"
}

update() {
	local repository="coreboot"

	project_update_git "$project" "$repository" "$@"
}

update_check() {
	local repository="coreboot"

	project_update_check_git "$project" "$repository" "$@"
}

build() {
	local repository="coreboot"

	project_sources_directory_missing_empty_error "$project" "$repository" "$@"

	local coreboot_sources_path=$( project_sources_path "$project" "$repository" "$@" )
	local sources_path="$coreboot_sources_path/util/cbfstool/"
	local build_path=$( project_build_path "$project" "$@" )
	local build_util_path=$( dirname "$build_path" )

	local vboot_sources_path=$( project_sources_path "vboot" "vboot" "devices" )

	if git_project_check "$repository"
	then
		git_project_checkout "$project" "$repository" "$@"
	fi

	project_action "checkout" "vboot" "devices"

	mkdir -p "$build_path"

	make -C "$sources_path" objutil="$build_util_path" VBOOT_SOURCE="$vboot_sources_path" -j$TASKS
}

build_check() {
	project_build_check "$project" "$@"
}

install() {
	project_install "$project" "$@"
}

install_check() {
	project_install_check "$project" "$@"
}

release() {
	local repository="coreboot"

	project_release_install_archive "$project" "$TOOLS" "$@"

	project_release_sources_git "$project" "$repository" "$@"
}

release_check() {
	local repository="coreboot"

	project_release_install_archive_check "$project" "$TOOLS" "$@"

	project_release_check_sources_git "$project" "$repository" "$@"
}

clean() {
	project_clean "$project" "$@"
}

path: projects/cbfstool/cbfstool


code:
cbfstool:cbfstool
fmaptool:fmaptool

path: projects/cbfstool/configs/install


code:
#!/bin/bash

# Copyright (C) 2016 Paul Kocialkowski <contact@paulk.fr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

download() {
	local repository="coreboot"

	git_project_prepare "$project" "$repository" "$@"
}

download_check() {
	local repository="coreboot"

	git_project_prepare_check "$project" "$repository" "$@"
}

extract() {
	local repository="coreboot"

	project_extract "$project" "$@"
}

extract_check() {
	local repository="coreboot"

	project_extract_check "$project" "$@"
}

update() {
	local repository="coreboot"

	project_update_git "$project" "$repository" "$@"
}

update_check() {
	local repository="coreboot"

	project_update_check_git "$project" "$repository" "$@"
}

build() {
	local repository="coreboot"

	project_sources_directory_missing_empty_error "$project" "$repository" "$@"

	local coreboot_sources_path=$( project_sources_path "$project" "$repository" "$@" )
	local sources_path="$coreboot_sources_path/util/cbmem/"
	local build_path=$( project_build_path "$project" "$@" )

	if git_project_check "$repository"
	then
		git_project_checkout "$project" "$repository" "$@"
	fi

	mkdir -p "$build_path"

	make -C "$sources_path" -j$TASKS

	cp "$sources_path/cbmem" "$build_path"

	make -C "$sources_path" "clean"
}

build_check() {
	project_build_check "$project" "$@"
}

install() {
	project_install "$project" "$@"
}

install_check() {
	project_install_check "$project" "$@"
}

release() {
	local repository="coreboot"

	project_release_install_archive "$project" "$TOOLS" "$@"

	project_release_sources_git "$project" "$repository" "$@"
}

release_check() {
	local repository="coreboot"

	project_release_install_archive_check "$project" "$TOOLS" "$@"

	project_release_check_sources_git "$project" "$repository" "$@"
}

clean() {
	project_clean "$project" "$@"
}

path: projects/cbmem/cbmem


path: projects/cbmem/configs/install


path: projects/coreboot/configs/blobs


code:
Documentation/codeflow.svg
Documentation/CorebootBuildingGuide.tex
Documentation/hypertransport.svg
payloads/external/depthcharge/Kconfig
payloads/external/FILO/Kconfig
payloads/external/GRUB2/Kconfig
payloads/external/SeaBIOS/Kconfig
payloads/external/U-Boot/Kconfig
payloads/Kconfig
payloads/libpayload/curses/PDCurses-3.4/demos/worm.c
payloads/libpayload/curses/PDCurses-3.4/sdl1/deffont.h
payloads/libpayload/curses/PDCurses-3.4/sdl1/deficon.h
payloads/libpayload/curses/PDCurses-3.4/win32/pdckbd.c
payloads/libpayload/curses/PDCurses-3.4/x11/big_icon.xbm
payloads/libpayload/curses/PDCurses-3.4/x11/little_icon.xbm
payloads/libpayload/curses/pdcurses-backend/pdcdisp.c
payloads/libpayload/curses/PDCurses/demos/worm.c
payloads/libpayload/curses/PDCurses/sdl1/deffont.h
payloads/libpayload/curses/PDCurses/sdl1/deficon.h
payloads/libpayload/curses/PDCurses/win32/pdckbd.c
payloads/libpayload/curses/PDCurses/x11/big_icon.xbm
payloads/libpayload/curses/PDCurses/x11/little_icon.xbm
payloads/libpayload/curses/tinycurses.c
payloads/libpayload/drivers/keyboard.c
payloads/libpayload/drivers/usb/usbmsc.c
payloads/libpayload/tests/cbfs-x86-test.c
payloads/nvramcui/payload.sh
src/cpu/allwinner/a10/raminit.c
src/cpu/amd/family_10h-family_15h/init_cpus.c
src/cpu/amd/family_10h-family_15h/processor_name.c
src/cpu/amd/geode_gx2/Kconfig
src/cpu/amd/geode_lx/cpureginit.c
src/cpu/amd/geode_lx/Kconfig
src/cpu/amd/microcode/microcode.c
src/cpu/amd/model_10xxx/init_cpus.c
src/cpu/amd/model_10xxx/processor_name.c
src/cpu/amd/model_fxx/model_fxx_update_microcode.c
src/cpu/amd/model_fxx/powernow_acpi.c
src/cpu/intel/fsp_model_206ax/acpi.c
src/cpu/intel/fsp_model_406dx/acpi.c
src/cpu/intel/haswell/acpi.c
src/cpu/intel/microcode/microcode.c
src/cpu/intel/model_2065x/acpi.c
src/cpu/intel/model_206ax/acpi.c
src/cpu/Kconfig
src/cpu/samsung/exynos5250/update-bl1.sh
src/cpu/via/nano/update_ucode.c
src/device/dram/spd_cache.c
src/device/Kconfig
src/device/oprom/yabel/interrupt.c
src/drivers/aspeed/common/ast_dram_tables.h
src/drivers/aspeed/common/ast_tables.h
src/drivers/i2c/ww_ring/ww_ring_programs.c
src/drivers/intel/fsp1_1/car.c
src/drivers/intel/fsp1_1/fsp_gop.c
src/drivers/intel/fsp1_1/Kconfig
src/drivers/intel/fsp1_1/ramstage.c
src/drivers/intel/fsp2_0/graphics.c
src/drivers/intel/fsp2_0/Kconfig
src/drivers/pc80/mc146818rtc.c
src/drivers/pc80/rtc/mc146818rtc.c
src/drivers/pc80/vga/vga_palette.c
src/drivers/siemens/nc_fpga/nc_fpga.c
src/drivers/xgi/common/vb_setmode.c
src/drivers/xgi/common/vb_table.h
src/drivers/xgi/common/XGI_main.h
src/Kconfig
src/lib/coreboot_table.c
src/lib/jpeg.c
src/lib/tlcl_structures.h
src/lib/tpm2_tlcl.c
src/mainboard/adi/rcc-dff/Kconfig
src/mainboard/advansus/a785e-i/mptable.c
src/mainboard/amd/bettong/mptable.c
src/mainboard/amd/bimini_fam10/mptable.c
src/mainboard/amd/db-ft3b-lc/Memphis_MEM4G16D3EABG.spd.hex
src/mainboard/amd/dinar/buildOpts.c
src/mainboard/amd/dinar/Kconfig
src/mainboard/amd/gardenia/OemCustomize.c
src/mainboard/amd/inagua/Kconfig
src/mainboard/amd/lamar/Kconfig
src/mainboard/amd/olivehill/mptable.c
src/mainboard/amd/olivehillplus/mptable.c
src/mainboard/amd/parmer/mptable.c
src/mainboard/amd/persimmon/Kconfig
src/mainboard/amd/serengeti_cheetah_fam10/get_bus_conf.c
src/mainboard/amd/south_station/Kconfig
src/mainboard/amd/south_station/mptable.c
src/mainboard/amd/thatcher/mptable.c
src/mainboard/amd/torpedo/Kconfig
src/mainboard/amd/torpedo/mptable.c
src/mainboard/amd/union_station/Kconfig
src/mainboard/amd/union_station/mptable.c
src/mainboard/apple/macbookair4_2/early_southbridge.c
src/mainboard/asrock/e350m1/mptable.c
src/mainboard/asrock/imb-a180/mptable.c
src/mainboard/asus/f2a85-m/mptable.c
src/mainboard/asus/kfsn4-dre/get_bus_conf.c
src/mainboard/asus/m5a88-v/mptable.c
src/mainboard/avalue/eax-785e/mptable.c
src/mainboard/bap/ode_e20XX/BAP_Q7_1066.spd.hex
src/mainboard/bap/ode_e20XX/BAP_Q7_800.spd.hex
src/mainboard/bap/ode_e20XX/BAP_Q7.spd.hex
src/mainboard/bap/ode_e21XX/BAP_Q7_1066.spd.hex
src/mainboard/bap/ode_e21XX/BAP_Q7_1333.spd.hex
src/mainboard/bap/ode_e21XX/BAP_Q7_800.spd.hex
src/mainboard/bap/ode_e21XX/mptable.c
src/mainboard/digitallogic/adl855pc/irq_tables.c
src/mainboard/gigabyte/ga-b75m-d3h/romstage.c
src/mainboard/gigabyte/ga-b75m-d3v/romstage.c
src/mainboard/gizmosphere/gizmo2/Micron_MT41J128M16JT.spd.hex
src/mainboard/gizmosphere/gizmo/mptable.c
src/mainboard/google/auron_paine/spd/spd.c
src/mainboard/google/auron/spd/Elpida_EDJ4216EFBG.spd.hex
src/mainboard/google/auron/spd/empty.spd.hex
src/mainboard/google/auron/spd/Hynix_HMT425S6AFR6A.spd.hex
src/mainboard/google/auron/spd/Micron_4KTF25664HZ.spd.hex
src/mainboard/google/auron/spd/spd.c
src/mainboard/google/bolt/elpida_4Gb_1600_x16.spd.hex
src/mainboard/google/bolt/micron_4Gb_1600_1.35v_x16.spd.hex
src/mainboard/google/bolt/romstage.c
src/mainboard/google/bolt/samsung_4Gb_1600_1.35v_x16.spd.hex
src/mainboard/google/butterfly/hda_verb.c
src/mainboard/google/butterfly/mainboard.c
src/mainboard/google/chell/spd/empty.spd.hex
src/mainboard/google/chell/spd/hynix_dimm_H9CCNNN8GTMLAR.spd.hex
src/mainboard/google/chell/spd/hynix_dimm_H9CCNNNBJTMLAR.spd.hex
src/mainboard/google/chell/spd/hynix_dimm_H9CCNNNCLTMLAR.spd.hex
src/mainboard/google/chell/spd/samsung_dimm_K4E6E304EB-EGCF.spd.hex
src/mainboard/google/chell/spd/samsung_dimm_K4E6E304EE-EGCF.spd.hex
src/mainboard/google/chell/spd/samsung_dimm_K4E8E304EE-EGCF.spd.hex
src/mainboard/google/chell/spd/spd.c
src/mainboard/google/cyan/Kconfig
src/mainboard/google/cyan/spd/hynix_2GiB_dimm_H5TC4G63AFR-PBA.spd.hex
src/mainboard/google/cyan/spd/hynix_2GiB_dimm_HMT425S6CFR6A_H5TC4G63CFR.spd.hex
src/mainboard/google/cyan/spd/samsung_2GiB_dimm_K4B4G1646Q-HYK0.spd.hex
src/mainboard/google/cyan/spd/spd.c
src/mainboard/google/enguarde/spd/hynix_2GiB_dimm_H5TC4G63AFR-PBA.spd.hex
src/mainboard/google/enguarde/spd/samsung_1GiB_dimm_K4B2G1646Q-BYK0.spd.hex
src/mainboard/google/enguarde/spd/micron_1GiB_dimm_MT41K128M16JT-125.spd.hex
src/mainboard/google/enguarde/spd/samsung_2GiB_dimm_K4B4G1646Q-HYK0.spd.hex
src/mainboard/google/enguarde/spd/micron_2GiB_dimm_MT41K256M16HA-125.spd.hex
src/mainboard/google/enguarde/spd/hynix_1GiB_dimm_H5TC2G63FFR-PBA.spd.hex
src/mainboard/google/eve/spd/hynix_dimm_H9CCNNNBJTALAR.spd.hex
src/mainboard/google/eve/spd/hynix_dimm_H9CCNNNCLTMLAR.spd.hex
src/mainboard/google/eve/spd/samsung_dimm_K4E8E324EB.spd.hex
src/mainboard/google/eve/spd/empty.spd.hex
src/mainboard/google/eve/spd/samsung_dimm_K4E6E304EB.spd.hex
src/mainboard/google/eve/spd/samsung_dimm_K4EBE304EB.spd.hex
src/mainboard/google/eve/spd/hynix_dimm_H9CCNNN8GTALAR.spd.hex
src/mainboard/google/falco/Elpida_EDJ4216EFBG.spd.hex
src/mainboard/google/falco/Hynix_HMT425S6AFR6A.spd.hex
src/mainboard/google/falco/Micron_4KTF25664HZ.spd.hex
src/mainboard/google/falco/romstage.c
src/mainboard/google/falco/Samsung_M471B5674QH0.spd.hex
src/mainboard/google/glados/spd/empty.spd.hex
src/mainboard/google/glados/spd/hynix_dimm_H9CCNNN8JTBLAR.spd.hex
src/mainboard/google/glados/spd/hynix_dimm_H9CCNNNBLTALAR.spd.hex
src/mainboard/google/glados/spd/samsung_dimm_K4E6E304EE-EGCF.spd.hex
src/mainboard/google/glados/spd/spd.c
src/mainboard/google/guado/lan.c
src/mainboard/google/jecht/lan.c
src/mainboard/google/lars/spd/empty.spd.hex
src/mainboard/google/lars/spd/hynix_dimm_H9CCNNN8JTBLAR-NUD-1G-1866.spd.hex
src/mainboard/google/lars/spd/hynix_dimm_H9CCNNNBLTBLAR-NUD-2G-1866.spd.hex
src/mainboard/google/lars/spd/samsung_dimm_K4E6E304EB-EGCF-2G-1866.spd.hex
src/mainboard/google/lars/spd/samsung_dimm_K4E8E324EB-EGCF-1G-1866.spd.hex
src/mainboard/google/lars/spd/spd.c
src/mainboard/google/link/elpida_4Gb_1600_x16.spd.hex
src/mainboard/google/link/hda_verb.c
src/mainboard/google/link/i915.c
src/mainboard/google/link/micron_4Gb_1600_1.35v_x16.spd.hex
src/mainboard/google/link/romstage.c
src/mainboard/google/link/samsung_4Gb_1600_1.35v_x16.spd.hex
src/mainboard/google/ninja/lan.c
src/mainboard/google/ninja/romstage.c
src/mainboard/google/ninja/spd/hynix_1GiB_dimm_H5TC2G63FFR-PBA.spd.hex
src/mainboard/google/ninja/spd/hynix_2GiB_dimm_H5TC4G63AFR-PBA.spd.hex
src/mainboard/google/ninja/spd/hynix_2GiB_dimm_H5TC4G63CFR-PBA.spd.hex
src/mainboard/google/ninja/spd/micron_1GiB_dimm_MT41K128M16JT-125.spd.hex
src/mainboard/google/ninja/spd/micron_2GiB_dimm_MT41K256M16HA-125.spd.hex
src/mainboard/google/panther/lan.c
src/mainboard/google/peach_pit/mainboard.c
src/mainboard/google/peppy/Elpida_EDJ4216EFBG.spd.hex
src/mainboard/google/peppy/Hynix_HMT425S6AFR6A.spd.hex
src/mainboard/google/peppy/Micron_4KTF25664HZ.spd.hex
src/mainboard/google/peppy/romstage.c
src/mainboard/google/rambi/romstage.c
src/mainboard/google/rambi/spd/hynix_1GiB_dimm_H5TC2G63FFR-PBA.spd.hex
src/mainboard/google/rambi/spd/hynix_2GiB_dimm_H5TC4G63AFR-PBA.spd.hex
src/mainboard/google/rambi/spd/micron_1GiB_dimm_MT41K128M16JT-125.spd.hex
src/mainboard/google/rambi/spd/micron_2GiB_dimm_MT41K256M16HA-125.spd.hex
src/mainboard/google/rikku/lan.c
src/mainboard/google/rotor/dram_params.c
src/mainboard/google/samus/romstage.c
src/mainboard/google/samus/spd/elpida_16.spd.hex
src/mainboard/google/samus/spd/elpida_4.spd.hex
src/mainboard/google/samus/spd/elpida_8.spd.hex
src/mainboard/google/samus/spd/empty.spd.hex
src/mainboard/google/samus/spd/hynix_16.spd.hex
src/mainboard/google/samus/spd/hynix_4.spd.hex
src/mainboard/google/samus/spd/hynix_8.spd.hex
src/mainboard/google/samus/spd/samsung_4.spd.hex
src/mainboard/google/samus/spd/samsung_8.spd.hex
src/mainboard/google/samus/spd/spd.c
src/mainboard/google/slippy/Hynix_HMT425S6AFR6A.spd.hex
src/mainboard/google/slippy/Micron_4KTF25664HZ.spd.hex
src/mainboard/google/slippy/variants/peppy/spd/Micron_4KTF25664HZ.spd.hex
src/mainboard/google/slippy/variants/peppy/spd/Elpida_EDJ4216EFBG.spd.hex
src/mainboard/google/slippy/variants/peppy/spd/Hynix_HMT425S6AFR6A.spd.hex
src/mainboard/google/slippy/variants/falco/spd/Micron_4KTF25664HZ.spd.hex
src/mainboard/google/slippy/variants/falco/spd/Elpida_EDJ4216EFBG.spd.hex
src/mainboard/google/slippy/variants/falco/spd/Samsung_M471B5674QH0.spd.hex
src/mainboard/google/slippy/variants/falco/spd/Hynix_HMT425S6AFR6A.spd.hex
src/mainboard/google/slippy/variants/leon/spd/Micron_4KTF25664HZ.spd.hex
src/mainboard/google/slippy/variants/leon/spd/Hynix_HMT425S6AFR6A.spd.hex
src/mainboard/google/slippy/variants/leon/spd/Samsung_K4B4G1646Q.spd.hex
src/mainboard/google/slippy/variants/wolf/spd/Micron_4KTF25664HZ.spd.hex
src/mainboard/google/slippy/variants/wolf/spd/Samsung_K4B4G1646B.spd.hex
src/mainboard/google/slippy/variants/wolf/spd/Hynix_HMT425S6AFR6A.spd.hex
src/mainboard/google/slippy/romstage.c
src/mainboard/google/tidus/lan.c
src/mainboard/hp/abm/mptable.c
src/mainboard/hp/dl165_g6_fam10/get_bus_conf.c
src/mainboard/hp/pavilion_m6_1035dx/mptable.c
src/mainboard/ibase/mb899/cmos.layout
src/mainboard/ibase/mb899/superio_hwm.c
src/mainboard/intel/amenia/romstage.c
src/mainboard/intel/apollolake_rvp/romstage.c
src/mainboard/intel/cougar_canyon2/Kconfig
src/mainboard/intel/kblrvp/spd/hynix_dimm_H9CCNNNBJTMLAR.spd.hex
src/mainboard/intel/kblrvp/spd/empty.spd.hex
src/mainboard/intel/kblrvp/spd/rvp3.spd.hex
src/mainboard/intel/kunimitsu/spd/empty.spd.hex
src/mainboard/intel/kunimitsu/spd/hynix_dimm_H9CCNNN8JTALAR-NUD-1G-1866.spd.hex
src/mainboard/intel/kunimitsu/spd/hynix_dimm_H9CCNNN8JTBLAR-NUD-1G-1866.spd.hex
src/mainboard/intel/kunimitsu/spd/hynix_dimm_H9CCNNNBLTALAR-NUD-2G-1866.spd.hex
src/mainboard/intel/kunimitsu/spd/hynix_dimm_H9CCNNNBLTBLAR-NUD-2G-1866.spd.hex
src/mainboard/intel/kunimitsu/spd/mic_dimm_EDF8132A3MA-JD-F-1G-1866.spd.hex
src/mainboard/intel/kunimitsu/spd/samsung_dimm_K4E6E304EE-EGCF-2G-1866.spd.hex
src/mainboard/intel/kunimitsu/spd/samsung_dimm_K4E8E304EE-EGCE.spd.hex
src/mainboard/intel/kunimitsu/spd/samsung_dimm_K4E8E304EE-EGCF-1G-1866.spd.hex
src/mainboard/intel/kunimitsu/spd/spd.c
src/mainboard/intel/minnowmax/Kconfig
src/mainboard/intel/mohonpeak/Kconfig
src/mainboard/intel/sklrvp/spd/empty.spd.hex
src/mainboard/intel/sklrvp/spd/rvp3.spd.hex
src/mainboard/intel/sklrvp/spd/spd.c
src/mainboard/intel/strago/Kconfig
src/mainboard/intel/strago/spd/hynix_2GiB_dimm_H5TC4G63AFR-PBA.spd.hex
src/mainboard/intel/strago/spd/hynix_2GiB_dimm_HMT425S6CFR6A_H5TC4G63CFR.spd.hex
src/mainboard/intel/strago/spd/samsung_2GiB_dimm_K4B4G1646Q-HYK0.spd.hex
src/mainboard/intel/strago/spd/spd.c
src/mainboard/intel/wtm2/i915.c
src/mainboard/jetway/nf81-t56n-lf/Kconfig
src/mainboard/kontron/986lcd-m/cmos.layout
src/mainboard/kontron/986lcd-m/mainboard.c
src/mainboard/lenovo/g505s/mptable.c
src/mainboard/lippert/frontrunner-af/Kconfig
src/mainboard/lippert/frontrunner-af/mptable.c
src/mainboard/lippert/toucan-af/Kconfig
src/mainboard/lippert/toucan-af/mptable.c
src/mainboard/msi/ms7721/mptable.c
src/mainboard/msi/ms9652_fam10/get_bus_conf.c
src/mainboard/packardbell/ms2290/mainboard.c
src/mainboard/pcengines/apu1/Kconfig
src/mainboard/samsung/lumpy/romstage.c
src/mainboard/siemens/mc_bdx1/mainboard.c
src/mainboard/siemens/mc_tcu3/lcd_panel.c
src/mainboard/siemens/mc_tcu3/mainboard.c
src/mainboard/siemens/mc_tcu3/modhwinfo.c
src/mainboard/siemens/mc_tcu3/romstage.c
src/mainboard/siemens/sitemp_g1p1/cmos.layout
src/mainboard/supermicro/h8dmr_fam10/get_bus_conf.c
src/mainboard/supermicro/h8qgi/buildOpts.c
src/mainboard/supermicro/h8qme_fam10/get_bus_conf.c
src/mainboard/supermicro/h8scm/buildOpts.c
src/mainboard/tyan/s2912_fam10/get_bus_conf.c
src/mainboard/tyan/s4880/irq_tables.c
src/mainboard/tyan/s4882/irq_tables.c
src/mainboard/tyan/s8226/buildOpts.c
src/northbridge/amd/agesa/common/common.c
src/northbridge/amd/amdk8/acpi.c
src/northbridge/amd/amdk8/coherent_ht.c
src/northbridge/amd/amdk8/raminit_test.c
src/northbridge/amd/amdmct/mct_ddr3/mcttmrl.c
src/northbridge/amd/amdmct/mct/mctardk3.c
src/northbridge/amd/amdmct/mct/mctardk4.c
src/northbridge/amd/amdmct/mct/mcttmrl.c
src/northbridge/amd/gx2/pll_reset.c
src/northbridge/amd/pi/00630F01/Kconfig
src/northbridge/amd/pi/00660F01/Kconfig
src/northbridge/amd/pi/00730F01/Kconfig
src/northbridge/intel/fsp_rangeley/fsp/Kconfig
src/northbridge/intel/fsp_sandybridge/fsp/Kconfig
src/northbridge/intel/gm45/raminit_rcomp_calibration.c
src/northbridge/intel/gm45/raminit_read_write_training.c
src/northbridge/intel/haswell/Kconfig
src/northbridge/intel/haswell/raminit.c
src/northbridge/intel/i82830/vga.c
src/northbridge/intel/i945/raminit.c
src/northbridge/intel/nehalem/gma.c
src/northbridge/intel/nehalem/raminit.c
src/northbridge/intel/nehalem/raminit_tables.c
src/northbridge/intel/pineview/raminit.c
src/northbridge/intel/sandybridge/gma.c
src/northbridge/intel/sandybridge/Kconfig
src/northbridge/intel/sandybridge/raminit.c
src/northbridge/intel/sandybridge/raminit_mrc.c
src/northbridge/intel/sandybridge/raminit_patterns.h
src/northbridge/intel/x4x/raminit_ddr2.c
src/northbridge/via/cx700/raminit.c
src/northbridge/via/vx800/ide.c
src/northbridge/via/vx800/uma_ram_setting.c
src/northbridge/via/vx900/sata.c
src/soc/broadcom/cygnus/ddr_init.c
src/soc/broadcom/cygnus/ddr_init_table.c
src/soc/intel/apollolake/Kconfig
src/soc/intel/apollolake/nhlt.c
src/soc/intel/baytrail/acpi.c
src/soc/intel/baytrail/Kconfig
src/soc/intel/baytrail/romstage/raminit.c
src/soc/intel/braswell/acpi.c
src/soc/intel/braswell/gpio.c
src/soc/intel/braswell/Kconfig
src/soc/intel/broadwell/acpi.c
src/soc/intel/broadwell/Kconfig
src/soc/intel/broadwell/romstage/raminit.c
src/soc/intel/common/fsp_ramstage.c
src/soc/intel/common/mma.c
src/soc/intel/common/vbt.c
src/soc/intel/fsp_baytrail/acpi.c
src/soc/intel/fsp_baytrail/fsp/Kconfig
src/soc/intel/fsp_baytrail/Kconfig
src/soc/intel/fsp_broadwell_de/fsp/chipset_fsp_util.c
src/soc/intel/fsp_broadwell_de/fsp/Kconfig
src/soc/intel/quark/Kconfig
src/soc/intel/quark/romstage/romstage.c
src/soc/intel/sch/Kconfig
src/soc/intel/skylake/Kconfig
src/soc/intel/skylake/nhlt/dmic.c
src/soc/intel/skylake/nhlt/max98357.c
src/soc/intel/skylake/nhlt/nau88l25.c
src/soc/intel/skylake/nhlt/ssm4567.c
src/soc/nvidia/tegra210/Kconfig
src/soc/nvidia/tegra210/mtc.c
src/soc/qualcomm/ipq40xx/Kconfig
src/soc/qualcomm/ipq40xx/lcc.c
src/soc/qualcomm/ipq806x/Kconfig
src/soc/qualcomm/ipq806x/lcc.c
src/soc/samsung/exynos5250/clock.c
src/soc/samsung/exynos5420/clock.c
src/southbridge/amd/agesa/hudson/Kconfig
src/southbridge/amd/cimx/sb800/Kconfig
src/southbridge/amd/pi/hudson/Kconfig
src/southbridge/intel/bd82x6x/Kconfig
src/southbridge/intel/bd82x6x/lpc.c
src/southbridge/intel/common/firmware/Kconfig
src/southbridge/intel/i82801ix/dmi_setup.c
src/southbridge/intel/ibexpeak/Kconfig
src/southbridge/intel/lynxpoint/Kconfig
src/southbridge/intel/sch/Kconfig
src/southbridge/nvidia/ck804/early_setup_ss.h
src/southbridge/nvidia/mcp55/early_setup_ss.h
src/southbridge/sis/sis966/early_setup_ss.h
src/southbridge/sis/sis966/early_smbus.c
src/southbridge/sis/sis966/ide.c
src/southbridge/sis/sis966/sata.c
src/southbridge/sis/sis966/usb2.c
src/southbridge/sis/sis966/usb.c
src/superio/via/vt1211/vt1211.c
src/vendorcode/amd/agesa/f10/Proc/CPU/Family/0x10/cpuF10Dmi.c
src/vendorcode/amd/agesa/f10/Proc/CPU/Family/0x10/cpuF10WheaInitDataTables.c
src/vendorcode/amd/agesa/f10/Proc/Mem/Main/muc.c
src/vendorcode/amd/agesa/f12/Proc/CPU/Family/0x10/cpuF10Dmi.c
src/vendorcode/amd/agesa/f12/Proc/CPU/Family/0x10/cpuF10WheaInitDataTables.c
src/vendorcode/amd/agesa/f12/Proc/CPU/Family/0x12/cpuF12Dmi.c
src/vendorcode/amd/agesa/f12/Proc/CPU/Family/0x12/cpuF12WheaInitDataTables.c
src/vendorcode/amd/agesa/f12/Proc/Fch/Hwm/Family/Hudson2/Hudson2HwmLateService.c
src/vendorcode/amd/agesa/f12/Proc/GNB/Gfx/Family/LN/F12GfxServices.c
src/vendorcode/amd/agesa/f12/Proc/Mem/Main/muc.c
src/vendorcode/amd/agesa/f14/Proc/CPU/Family/0x10/cpuF10Dmi.c
src/vendorcode/amd/agesa/f14/Proc/CPU/Family/0x10/cpuF10WheaInitDataTables.c
src/vendorcode/amd/agesa/f14/Proc/Mem/Main/muc.c
src/vendorcode/amd/agesa/f15/Proc/CPU/Family/0x10/cpuF10Dmi.c
src/vendorcode/amd/agesa/f15/Proc/CPU/Family/0x10/cpuF10WheaInitDataTables.c
src/vendorcode/amd/agesa/f15/Proc/CPU/Family/0x15/cpuF15WheaInitDataTables.c
src/vendorcode/amd/agesa/f15/Proc/Mem/Main/muc.c
src/vendorcode/amd/agesa/f15/Proc/Mem/Ps/OR/mpor3.c
src/vendorcode/amd/agesa/f15/Proc/Mem/Tech/DDR3/mtlrdimm3.c
src/vendorcode/amd/agesa/f15tn/Proc/CPU/Family/0x15/cpuF15WheaInitDataTables.c
src/vendorcode/amd/agesa/f15tn/Proc/GNB/Modules/GnbInitTN/GfxIntegratedInfoTableTN.c
src/vendorcode/amd/agesa/f15tn/Proc/GNB/Modules/GnbInitTN/GfxLibTN.c
src/vendorcode/amd/agesa/f15tn/Proc/Mem/Main/muc.c
src/vendorcode/amd/agesa/f15tn/Proc/Mem/Ps/TN/mptn3.c
src/vendorcode/amd/agesa/f15tn/Proc/Mem/Tech/DDR3/mtlrdimm3.c
src/vendorcode/amd/agesa/f16kb/Proc/CPU/Family/0x16/cpuF16WheaInitDataTables.c
src/vendorcode/amd/agesa/f16kb/Proc/GNB/Modules/GnbGfxIntTableV3/GfxLibV3.c
src/vendorcode/amd/agesa/f16kb/Proc/GNB/Modules/GnbInitKB/GnbF1TableKB.c
src/vendorcode/amd/agesa/f16kb/Proc/Mem/Main/muc.c
src/vendorcode/amd/agesa/f16kb/Proc/Mem/Ps/KB/mpkb3.c
src/vendorcode/amd/cimx/sb800/SATA.c
src/vendorcode/amd/pi/Kconfig
src/vendorcode/google/chromeos/build-snow
util/amdtools/example_input/lspci-cb-48G-667MHz-18.2-20090909e
util/amdtools/example_input/lspci-prop-48G-667MHz-18.2
util/autoport/readme.md
util/bimgtool/bimgtool.c
util/cbfstool/fmd_parser.c_shipped
util/cbfstool/fmd_scanner.c_shipped
util/cbfstool/linux_trampoline.c
util/cbfstool/lz4/lib/lz4.c
util/crossgcc/patches/binutils-2.25_riscv.patch
util/crossgcc/patches/gcc-5.2.0_riscv.patch
util/ifdtool/ifdtool.c
util/intelmetool/intelmetool.c
util/ipqheader/createxbl.py
util/kconfig/zconf.hash.c_shipped
util/kconfig/zconf.lex.c_shipped
util/kconfig/zconf.tab.c_shipped
util/mma/mma_automated_test.sh
util/mtkheader/gen-bl-img.py
util/nvidia/cbootimage/src/aes_ref.c
util/nvramtool/accessors/layout-bin.c
util/riscvtools/make-spike-elf.sh
util/rockchip/make_idb.py
util/romcc/do_tests.sh
util/romcc/test.sh
util/romcc/tests/include/linux_console.h
util/romcc/tests/linux_console.h
util/romcc/tests/linux_test5.c
util/romcc/tests/raminit_test6.c
util/romcc/tests/raminit_test7.c
util/romcc/tests/simple_test14.c
util/romcc/tests/simple_test30.c
util/romcc/tests/simple_test38.c
util/romcc/tests/simple_test39.c
util/romcc/tests/simple_test54.c
util/romcc/tests/simple_test59.c
util/romcc/tests/simple_test72.c
util/romcc/tests/simple_test73.c
util/sconfig/lex.yy.c_shipped
util/sconfig/sconfig.tab.c_shipped
util/superiotool/fintek.c
util/superiotool/ite.c
util/superiotool/nuvoton.c
util/superiotool/smsc.c
util/superiotool/winbond.c
util/xcompile/xcompile

path: projects/coreboot/configs/blobs-ignore


code:
.spd.hex files - serial presence detect. These are not blobs
see JEDEC standard or https://en.wikipedia.org/wiki/Serial_presence_detect
These are added to the nonblobs file

src/northbridge/intel/nehalem/raminit_tables.c"
src/northbridge/intel/sandybridge/raminit_patterns.h
These are used by native raminit for the relevant platforms, and are not blobs

"src/southbridge/nvidia/mcp55/early_setup_ss.h" \
"src/southbridge/nvidia/ck804/early_setup_ss.h" \
"src/southbridge/sis/sis966/early_setup_ss.h"
not blobs

The text in this file is CC-BY-SA 4.0 or higher. All contributions to it must
be made under the same license.


code:
jerry
mickey
minnie
speedy


path: projects/coreboot/configs/install


path: projects/coreboot/configs/revision


code: depthcharge

path: projects/coreboot/configs/targets


code:
#!/bin/bash

# Copyright (C) 2016 Paul Kocialkowski <contact@paulk.fr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

arguments() {
	project_arguments_targets "$project" "$@"
}

usage() {
	project_usage_actions "$project"
	project_usage_arguments "$project" "$@"
}

download() {
	local repository=$project

	project_download_git "$project" "$repository" "https://review.coreboot.org/coreboot https://github.com/coreboot/coreboot.git" "$@"
}

download_check() {
	local repository=$project

	project_download_check_git "$project" "$repository" "$@"
}

extract() {
	project_extract "$project" "$@"
}

extract_check() {
	project_extract_check "$project" "$@"
}

update() {
	local repository=$project

	project_update_git "$project" "$repository" "$@"
}

update_check() {
	local repository=$project

	project_update_check_git "$project" "$repository" "$@"
}

build() {
	local payload=$1
	shift

	local repository=$project

	project_sources_directory_missing_empty_error "$project" "$repository" "$payload" "$@"

	local sources_path=$( project_sources_path "$project" "$repository" "$payload" "$@" )
	local build_path=$( project_build_path "$project" "$payload" "$@" )
	local config_path=$( coreboot_config_path "$payload" "$@" )

	local arch=$( coreboot_arch "$payload" "$@" )

	local crossgcc_build_path=$( project_build_path "crossgcc" "$arch" )
	local crossgcc_bin_path="$crossgcc_build_path/bin/"
	local vboot_sources_path=$( project_sources_path "vboot" "vboot" "devices" )

	project_action "build" "crossgcc" "$arch"

	if git_project_check "$repository"
	then
		git_project_checkout "$project" "$repository" "$payload" "$@"
	fi

	project_action "checkout" "vboot" "devices"

	project_action "build" "$payload" "$@"

	if coreboot_ec_check "$payload" "$@"
	then
		ec=$( coreboot_ec "$payload" "$@" )

		project_action "build" "$ec" "$@"
	fi

	rm -f "$sources_path/.xcompile"

	mkdir -p "$build_path"

	make -C "$sources_path" obj="$build_path" DOTCONFIG="$build_path/.config" XGCCPATH="$crossgcc_bin_path" BUILD_TIMELESS=1 KERNELVERSION="$VERSION" KBUILD_DEFCONFIG="$config_path" "defconfig"
	make -C "$sources_path" obj="$build_path" DOTCONFIG="$build_path/.config" XGCCPATH="$crossgcc_bin_path" BUILD_TIMELESS=1 KERNELVERSION="$VERSION" VBOOT_SOURCE="$vboot_sources_path" -j$TASKS

	rm -f "$sources_path/.xcompile"
}

build_check() {
	project_build_check "$project" "$@"
}

install() {
	project_install "$project" "$@"
}

install_check() {
	project_install_check "$project" "$@"
}

release() {
	local repository=$project

	project_release_install_archive "$project" "$IMAGES" "$@"

	project_release_sources_git "$project" "$repository" "$@"
}

release_check() {
	local repository=$project

	project_release_install_archive_check "$project" "$IMAGES" "$@"

	project_release_check_sources_git "$project" "$repository" "$@"
}

clean() {
	project_clean "$project" "$@"
}

path: projects/coreboot/coreboot


code:
#!/bin/bash

# Copyright (C) 2016 Paul Kocialkowski <contact@paulk.fr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

DEVICES="devices"
PAYLOADS="payloads"
CONFIG="config"
ARCH="arch"
EC="ec"

coreboot_arch() {
	project_file_contents "$project" "$CONFIGS" "$ARCH" "$@"
}

coreboot_config_path() {
	project_file_path "$project" "$CONFIGS" "$CONFIG" "$@"
}

coreboot_ec_check() {
	project_file_test "$project" "$CONFIGS" "$EC" "$@"
}

coreboot_ec() {
	project_file_contents "$project" "$CONFIGS" "$EC" "$@"
}

path: projects/coreboot/coreboot-helper


code:
From 6c534728fde6a9582915995a2742808764fe4783 Mon Sep 17 00:00:00 2001
From: Paul Kocialkowski <contact@paulk.fr>
Date: Wed, 20 Jul 2016 16:03:30 +0200
Subject: [PATCH 1/2] Avoid using git submodules for 3rdparty

This gets rid of git submodules entirely, to avoid the nuisance caused
by automatically checking them out.

Change-Id: I54de09656bd2dd9c308bd6c8dce554945aa8e535
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
---
 .gitmodules                   | 20 --------------------
 3rdparty/arm-trusted-firmware |  1 -
 3rdparty/blobs                |  1 -
 3rdparty/chromeec             |  1 -
 3rdparty/libgfxinit           |  1 -
 3rdparty/libhwbase            |  1 -
 3rdparty/vboot                |  1 -
 Makefile.inc                  | 11 -----------
 8 files changed, 37 deletions(-)
 delete mode 160000 3rdparty/arm-trusted-firmware
 delete mode 160000 3rdparty/blobs
 delete mode 160000 3rdparty/chromeec
 delete mode 160000 3rdparty/libgfxinit
 delete mode 160000 3rdparty/libhwbase
 delete mode 160000 3rdparty/vboot

diff --git a/.gitmodules b/.gitmodules
index c3270e6ae2..3a617c7dc5 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,23 +1,3 @@
-[submodule "3rdparty/blobs"]
-	path = 3rdparty/blobs
-	url = ../blobs.git
-	update = none
-	ignore = dirty
 [submodule "util/nvidia-cbootimage"]
 	path = util/nvidia/cbootimage
 	url = ../nvidia-cbootimage.git
-[submodule "vboot"]
-	path = 3rdparty/vboot
-	url = ../vboot.git
-[submodule "arm-trusted-firmware"]
-	path = 3rdparty/arm-trusted-firmware
-	url = ../arm-trusted-firmware.git
-[submodule "3rdparty/chromeec"]
-	path = 3rdparty/chromeec
-	url = ../chrome-ec.git
-[submodule "libhwbase"]
-	path = 3rdparty/libhwbase
-	url = ../libhwbase.git
-[submodule "libgfxinit"]
-	path = 3rdparty/libgfxinit
-	url = ../libgfxinit.git
diff --git a/3rdparty/arm-trusted-firmware b/3rdparty/arm-trusted-firmware
deleted file mode 160000
index 236c27d21f..0000000000
--- a/3rdparty/arm-trusted-firmware
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 236c27d21f52ad8f0a998e54774e3d8a4b59129d
diff --git a/3rdparty/blobs b/3rdparty/blobs
deleted file mode 160000
index 8090bdd598..0000000000
--- a/3rdparty/blobs
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 8090bdd59853599e469b7503ea473ca12e8c681b
diff --git a/3rdparty/chromeec b/3rdparty/chromeec
deleted file mode 160000
index bcffec7fdc..0000000000
--- a/3rdparty/chromeec
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit bcffec7fdc50e959cb298d094d8af472777dba75
diff --git a/3rdparty/libgfxinit b/3rdparty/libgfxinit
deleted file mode 160000
index 88a7f17b7d..0000000000
--- a/3rdparty/libgfxinit
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 88a7f17b7d7a4f8a4d25ef6b87c71236b0862f5d
diff --git a/3rdparty/libhwbase b/3rdparty/libhwbase
deleted file mode 160000
index aab715f166..0000000000
--- a/3rdparty/libhwbase
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit aab715f166bf1b54cfbd6982e8df49248ea544d8
diff --git a/3rdparty/vboot b/3rdparty/vboot
deleted file mode 160000
index adfafba793..0000000000
--- a/3rdparty/vboot
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit adfafba793684ed92965dfbd86b3fb3463975d8c
diff --git a/Makefile.inc b/Makefile.inc
index c5ce30f2b1..919a5d4ac1 100644
--- a/Makefile.inc
+++ b/Makefile.inc
@@ -183,17 +183,6 @@ ifeq ($(CONFIG_COVERAGE),y)
 ramstage-c-ccopts += -fprofile-arcs -ftest-coverage
 endif

-ifneq ($(UPDATED_SUBMODULES),1)
-# try to fetch non-optional submodules if the source is under git
-forgetthis:=$(if $(GIT),$(shell git submodule update --init))
-ifeq ($(CONFIG_USE_BLOBS),y)
-# this is necessary because 3rdparty/blobs is update=none, and so is ignored
-# unless explicitly requested and enabled through --checkout
-forgetthis:=$(if $(GIT),$(shell git submodule update --init --checkout 3rdparty/blobs))
-endif
-export UPDATED_SUBMODULES:=1
-endif
-
 ramstage-c-deps:=$$(OPTION_TABLE_H)
 romstage-c-deps:=$$(OPTION_TABLE_H)
 libverstage-c-deps:=$$(OPTION_TABLE_H)
--
2.11.0


code:
From 417866c23c193a44a84d686ce1c2ee3d43284e05 Mon Sep 17 00:00:00 2001
From: Paul Kocialkowski <contact@paulk.fr>
Date: Mon, 19 Dec 2016 20:23:44 +0100
Subject: [PATCH 2/2] libpayload: Enable USB HID in veyron configuration

This enables USB HID support in the veyron config, since it seems to
work correctly and is needed for interaction with depthcharge on devices
without an embedded keyboard (such as veyron_mickey).

Change-Id: Icae829e3a132005df17bcb6f7e6f8a190912576d
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
---
 payloads/libpayload/configs/config.veyron | 1 -
 1 file changed, 1 deletion(-)

diff --git a/payloads/libpayload/configs/config.veyron b/payloads/libpayload/configs/config.veyron
index e80535c63e..b643e92a48 100644
--- a/payloads/libpayload/configs/config.veyron
+++ b/payloads/libpayload/configs/config.veyron
@@ -4,4 +4,3 @@ CONFIG_LP_8250_SERIAL_CONSOLE=y
 CONFIG_LP_TIMER_RK3288=y
 CONFIG_LP_USB_EHCI=y
 CONFIG_LP_USB_DWC2=y
-# CONFIG_LP_USB_HID is not set
--
2.11.0


code:
ec.bin:ec.bin
ec.RW.bin:ec.RW.bin

path: projects/cros-ec/configs/nyan/install


path: projects/cros-ec/configs/nyan/revision


code:
big
blaze

path: projects/cros-ec/configs/nyan/targets


code:
nyan
tools
veyron

path: projects/cros-ec/configs/targets


code:
util/ectool:ectool
util/ec_uartd:ec_uartd
util/iteflash:iteflash
util/lbcc:lbcc
util/lbplay:lbplay
util/stm32mon:stm32mon

path: projects/cros-ec/configs/tools/install


path: projects/cros-ec/configs/tools/revision


path: projects/cros-ec/configs/veyron/install


code:
jerry
minnie
speedy

path: projects/cros-ec/configs/veyron/targets


code:
#!/bin/bash

# Copyright (C) 2016 Paul Kocialkowski <contact@paulk.fr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

arguments() {
	project_arguments_targets "$project" "$@"
}

usage() {
	project_usage_actions "$project"
	project_usage_arguments "$project" "$@"
}

download() {
	local repository=$project

	project_download_git "$project" "$repository" "https://chromium.googlesource.com/chromiumos/platform/ec https://review.coreboot.org/chrome-ec.git https://github.com/coreboot/chrome-ec.git" "$@"
}

download_check() {
	local repository=$project

	project_download_check_git "$project" "$repository" "$@"
}

extract() {
	project_extract "$project" "$@"
}

extract_check() {
	project_extract_check "$project" "$@"
}

update() {
	local repository=$project

	project_update_git "$project" "$repository" "$@"
}

update_check() {
	local repository=$project

	project_update_check_git "$project" "$repository" "$@"
}

build() {
	local target=$1

	local repository=$project

	project_sources_directory_missing_empty_error "$project" "$repository" "$@"

	local sources_path=$( project_sources_path "$project" "$repository" "$@" )
	local build_path=$( project_build_path "$project" "$@" )

	if git_project_check "$repository"
	then
		git_project_checkout "$project" "$repository" "$@"
	fi

	mkdir -p "$build_path"

	if [ "$target" = "tools" ]
	then
		make -C "$sources_path" out="$build_path" HOST_CROSS_COMPILE= -j$TASKS "utils"
	else
		local arch="arm"

		local config=$( cros_ec_config "$@" )

		local crossgcc_bin_prefix=$( project_action "prefix" "crossgcc" "$arch" )

		project_action "build" "crossgcc" "$arch"

		make -C "$sources_path" out="$build_path" CROSS_COMPILE="$crossgcc_bin_prefix" HOST_CROSS_COMPILE= BOARD="$config" -j$TASKS
	fi
}

build_check() {
	project_build_check "$project" "$@"
}

install() {
	project_install "$project" "$@"
}

install_check() {
	project_install_check "$project" "$@"
}

release() {
	local target=$1

	local repository=$project

	if [ "$target" = "tools" ]
	then
		project_release_install_archive "$project" "$TOOLS" "$@"
	else
		project_release_install_archive "$project" "$IMAGES" "$@"
	fi

	project_release_sources_git "$project" "$repository" "$@"
}

release_check() {
	local target=$1

	local repository=$project

	if [ "$target" = "tools" ]
	then
		project_release_install_archive_check "$project" "$TOOLS" "$@"
	else
		project_release_install_archive_check "$project" "$IMAGES" "$@"
	fi

	project_release_check_sources_git "$project" "$repository" "$@"
}

clean() {
	project_clean "$project" "$@"
}

path: projects/cros-ec/cros-ec


code:
#!/bin/bash

# Copyright (C) 2016 Paul Kocialkowski <contact@paulk.fr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

CONFIG="config"

cros_ec_config() {
	project_file_contents "$project" "$CONFIGS" "$CONFIG" "$@"
}

path: projects/cros-ec/cros-ec-helper


code:
From b98bd2808f4185970781bd4dcca141cbda9b03c6 Mon Sep 17 00:00:00 2001
From: Mike Frysinger <vapier@chromium.org>
Date: Mon, 7 Dec 2015 21:46:13 -0500
Subject: [PATCH 1/4] use _DEFAULT_SOURCE for newer glibc

Newer versions of glibc have moved to _DEFAULT_SOURCE and away from
_BSD_SOURCE.  Trying to use the BSD define by itself leads to warnings
which causes build failures.

BRANCH=none
BUG=None
TEST=precq still works

Signed-off-by: Mike Frysinger <vapier@chromium.org>
Change-Id: Ice24b84dc6a540695fc7b76e8f22a4c85c301976
Reviewed-on: https://chromium-review.googlesource.com/316730
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
---
 util/ec_uartd.c | 3 ++-
 util/stm32mon.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/util/ec_uartd.c b/util/ec_uartd.c
index fbf4a5e..bfd0642 100644
--- a/util/ec_uartd.c
+++ b/util/ec_uartd.c
@@ -11,7 +11,8 @@
  */

 /* Force header files to define grantpt(), posix_openpt(), cfmakeraw() */
-#define _BSD_SOURCE
+#define _DEFAULT_SOURCE /* Newer glibc */
+#define _BSD_SOURCE     /* Older glibc */
 #define _XOPEN_SOURCE 600
 /* Force header file to declare ptsname_r(), etc. */
 #ifndef _GNU_SOURCE
diff --git a/util/stm32mon.c b/util/stm32mon.c
index 2e73bcf..f65cd64 100644
--- a/util/stm32mon.c
+++ b/util/stm32mon.c
@@ -6,7 +6,8 @@
  */

 /* use cfmakeraw() */
-#define _BSD_SOURCE
+#define _DEFAULT_SOURCE /* Newer glibc */
+#define _BSD_SOURCE     /* Older glibc */

 #include <arpa/inet.h>
 #include <errno.h>
--
2.9.0


code:
From fd77232c8e9789f5556fc6cc3c694924c1546a41 Mon Sep 17 00:00:00 2001
From: Paul Kocialkowski <contact@paulk.fr>
Date: Wed, 20 Jul 2016 16:26:32 +0200
Subject: [PATCH 2/4] Enforce compilation without system headers

This is based on commit bc404c94b4ab1e6a62e607fd7ef034aa31d6388e
(Enforce compilation without system headers)
---
 Makefile.toolchain | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile.toolchain b/Makefile.toolchain
index dd0ebb2..47991e1 100644
--- a/Makefile.toolchain
+++ b/Makefile.toolchain
@@ -19,7 +19,7 @@ BUILDCC?=gcc
 HOSTCC?=$(HOST_CROSS_COMPILE)gcc

 CFLAGS_WARN=-Wall -Werror -Wundef -Wstrict-prototypes -Wno-trigraphs      \
-            -fno-strict-aliasing -fno-common                              \
+            -fno-strict-aliasing -fno-common -ffreestanding -fno-builtin  \
             -Werror-implicit-function-declaration -Wno-format-security    \
             -fno-delete-null-pointer-checks -Wdeclaration-after-statement \
             -Wno-pointer-sign -fno-strict-overflow -fconserve-stack
--
2.9.0


code:
From 9d747549141e710c324968636522e57fe4ba9445 Mon Sep 17 00:00:00 2001
From: Paul Kocialkowski <contact@paulk.fr>
Date: Wed, 20 Jul 2016 16:27:05 +0200
Subject: [PATCH 3/4] Don't declare functions inline that aren't always defined
 as such

This is based on commit 960cf45b3ffe88e842c27145e7e646d63a89c371
(Don't declare functions inline that aren't always defined as such)
---
 include/task.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/task.h b/include/task.h
index 00368fb..52827e9 100644
--- a/include/task.h
+++ b/include/task.h
@@ -47,7 +47,7 @@ void interrupt_enable(void);
 /**
  * Return true if we are in interrupt context.
  */
-inline int in_interrupt_context(void);
+int in_interrupt_context(void);

 /**
  * Set a task event.
--
2.9.0


code:
From f7d7b22a9e711783c99be55b2c1c437a6808f24d Mon Sep 17 00:00:00 2001
From: Paul Kocialkowski <contact@paulk.fr>
Date: Sat, 23 Jul 2016 15:51:58 +0200
Subject: [PATCH 4/4] cortex-m: Use assembly exception handler and routine for
 task switching

The way Cortex processors handle exceptions allows writing exception
routines directly in C, as return from exception is handled by providing
a special value for the link register.

However, it is not safe to do this when doing context switching. In
particular, C handlers may push some general-purpose registers that
are used by the handler and pop them later, even when context switch
has happened in the meantime. While the processor will restore {r0-r3}
from the stack when returning from an exception, the C handler code
may push, use and pop another register, clobbering the value resulting
from the context switch.

For this reason, it is safer to have assembly routines for exception
handlers that do context switching.

BUG=chromium:631514
BRANCH=None
TEST=Build and run big EC with a recent GCC version

Change-Id: Ia356321021731e6e372af152c962d8f01c065da5
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
---
 core/cortex-m/switch.S | 90 +++++++++++++++++++++++++++++++++++---------------
 core/cortex-m/task.c   | 28 ++++------------
 2 files changed, 69 insertions(+), 49 deletions(-)

diff --git a/core/cortex-m/switch.S b/core/cortex-m/switch.S
index 92c7e51..80a99c8 100644
--- a/core/cortex-m/switch.S
+++ b/core/cortex-m/switch.S
@@ -13,6 +13,48 @@
 .code 16

 /**
+ * Start the task scheduling.  r0 is a pointer to task_stack_ready, which is
+ * set to 1 after the task stack is set up.
+ */
+.global __task_start
+.thumb_func
+__task_start:
+  ldr r2,=scratchpad     @ area used as dummy thread stack for the first switch
+#ifdef CONFIG_FPU
+  mov r3, #6             @ use : priv. mode / thread stack / floating point on
+#else
+  mov r3, #2             @ use : priv. mode / thread stack / no floating point
+#endif
+  add r2, #17*4          @ put the pointer at the top of the stack
+  mov r1, #0             @ __Schedule parameter : re-schedule nothing
+  msr psp, r2            @ setup a thread stack up to the first context switch
+  mov r2, #1
+  isb                    @ ensure the write is done
+  msr control, r3
+  mov r3, r0
+  mov r0, #0             @ __Schedule parameter : de-schedule nothing
+  isb                    @ ensure the write is done
+  str r2, [r3]           @ Task scheduling is now active
+  bl __schedule          @ execute the task with the highest priority
+  /* we should never return here */
+  mov r0, #1             @ set to EC_ERROR_UNKNOWN
+  bx lr
+
+/**
+ * SVC exception handler
+ */
+.global svc_handler
+.thumb_func
+svc_handler:
+  push {lr}                  @ save link register
+  bl __svc_handler           @ call svc handler helper
+  ldr r3,=current_task       @ load the current task's address
+  ldr r1, [r3]               @ load the current task
+  cmp r0, r1                 @ compare with previous task returned by helper
+  beq svc_handler_return     @ return if they are the same
+  /* continue to __switchto to switch to the new task */
+
+/**
  * Task context switching
  *
  * Change the task scheduled after returning from the exception.
@@ -30,8 +72,6 @@
  *     r0, r1, r2, r3, r12, lr, pc, psr, r4, r5, r6, r7, r8, r9, r10, r11
  *       exception frame              <|> additional registers
  */
-.global __switchto
-.thumb_func
 __switchto:
   mrs r3, psp            @ get the task stack where the context has been saved
   ldr r2, [r1]           @ get the new scheduled task stack pointer
@@ -39,33 +79,29 @@ __switchto:
   ldmia r2!, {r4-r11}    @ restore r4-r11 for the next task context
   str r3, [r0]           @ save the task stack pointer in its context
   msr psp, r2            @ set the process stack pointer to exception context
-  bx lr                  @ return from exception
+
+svc_handler_return:
+  pop {pc}               @ return from exception or return to caller

 /**
- * Start the task scheduling.  r0 is a pointer to task_stack_ready, which is
- * set to 1 after the task stack is set up.
+ * Resched task if needed:
+ * Continue iff a rescheduling event happened or profiling is active,
+ * and we are not called from another exception.
  */
-.global __task_start
+.global task_resched_if_needed
 .thumb_func
-__task_start:
-  ldr r2,=scratchpad     @ area used as dummy thread stack for the first switch
-#ifdef CONFIG_FPU
-  mov r3, #6             @ use : priv. mode / thread stack / floating point on
-#else
-  mov r3, #2             @ use : priv. mode / thread stack / no floating point
-#endif
-  add r2, #17*4          @ put the pointer at the top of the stack
-  mov r1, #0             @ __Schedule parameter : re-schedule nothing
-  msr psp, r2            @ setup a thread stack up to the first context switch
-  mov r2, #1
-  isb                    @ ensure the write is done
-  msr control, r3
-  mov r3, r0
-  mov r0, #0             @ __Schedule parameter : de-schedule nothing
-  isb                    @ ensure the write is done
-  str r2, [r3]           @ Task scheduling is now active
-  bl __schedule          @ execute the task with the highest priority
-  /* we should never return here */
-  mov r0, #1             @ set to EC_ERROR_UNKNOWN
-  bx lr
+task_resched_if_needed:
+  push {lr}                                 @ save link register
+  ldr r3,=need_resched_or_profiling         @ load need's address
+  ldr r1, [r3]                              @ load need
+  cbz r1, task_resched_if_needed_return     @ return if there is no need
+  and r0, #0xf                              @ called from another exception
+  cmp r0, #1                                @ check bit
+  beq task_resched_if_needed_return         @ return if called from exception
+  movs r1, #0                               @ desched nothing
+  movs r0, #0                               @ resched nothing
+  bl svc_handler                            @ re-schedule the highest priority
+                                            @ task

+task_resched_if_needed_return:
+  pop {pc}                                  @ return to caller
diff --git a/core/cortex-m/task.c b/core/cortex-m/task.c
index bfb3a9b..9935a28 100644
--- a/core/cortex-m/task.c
+++ b/core/cortex-m/task.c
@@ -57,7 +57,6 @@ static uint32_t task_switches;   /* Number of times active task changed */
 static uint32_t irq_dist[CONFIG_IRQ_COUNT];  /* Distribution of IRQ calls */
 #endif

-extern void __switchto(task_ *from, task_ *to);
 extern int __task_start(int *task_stack_ready);

 #ifndef CONFIG_LOW_POWER_IDLE
@@ -124,7 +123,7 @@ uint32_t scratchpad[17+18];
 uint32_t scratchpad[17];
 #endif

-static task_ *current_task = (task_ *)scratchpad;
+task_ *current_task = (task_ *)scratchpad;

 /*
  * Should IRQs chain to svc_handler()?  This should be set if either of the
@@ -137,7 +136,7 @@ static task_ *current_task = (task_ *)scratchpad;
  * task unblocking.  After checking for a task switch, svc_handler() will clear
  * the flag (unless profiling is also enabled; then the flag remains set).
  */
-static int need_resched_or_profiling;
+int need_resched_or_profiling;

 /*
  * Bitmap of all tasks ready to be run.
@@ -197,7 +196,7 @@ int task_start_called(void)
 /**
  * Scheduling system call
  */
-void svc_handler(int desched, task_id_t resched)
+task_ *__svc_handler(int desched, task_id_t resched)
 {
 	task_ *current, *next;
 #ifdef CONFIG_TASK_PROFILING
@@ -264,16 +263,13 @@ void svc_handler(int desched, task_id_t resched)
 	need_resched_or_profiling = 0;
 #endif

-	/* Nothing to do */
-	if (next == current)
-		return;
-
 	/* Switch to new task */
 #ifdef CONFIG_TASK_PROFILING
-	task_switches++;
+	if (next != current)
+		task_switches++;
 #endif
 	current_task = next;
-	__switchto(current, next);
+	return current;
 }

 void __schedule(int desched, int resched)
@@ -313,18 +309,6 @@ void task_start_irq_handler(void *excep_return)
 }
 #endif

-void task_resched_if_needed(void *excep_return)
-{
-	/*
-	 * Continue iff a rescheduling event happened or profiling is active,
-	 * and we are not called from another exception.
-	 */
-	if (!need_resched_or_profiling || (((uint32_t)excep_return & 0xf) == 1))
-		return;
-
-	svc_handler(0, 0);
-}
-
 static uint32_t __wait_evt(int timeout_us, task_id_t resched)
 {
 	task_ *tsk = current_task;
--
2.9.0


code:
From 35987639080ef4293bffbc1ce21de4d8a35b41db Mon Sep 17 00:00:00 2001
From: Yunlian Jiang <yunlian@google.com>
Date: Mon, 20 Apr 2015 09:38:56 -0700
Subject: [PATCH 1/6] ec: fix a clang warning by use a unused variable.

This uses the variable 'usage' in an error message to fix a clang
warning.

BUG=chromium:475960
TEST=CC=x86_64-cros-linux-gnu-clang emerge-falco ec-devutils
BRANCH=none
Signed-off-by: yunlian@chromium.org

Change-Id: Ic5703636040805661c7b81b83fc182e127ceab8c
Reviewed-on: https://chromium-review.googlesource.com/266404
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Yunlian Jiang <yunlian@chromium.org>
Commit-Queue: Yunlian Jiang <yunlian@chromium.org>
---
 util/lbcc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util/lbcc.c b/util/lbcc.c
index b34b21e..953f422 100644
--- a/util/lbcc.c
+++ b/util/lbcc.c
@@ -630,7 +630,7 @@ int main(int argc, char *argv[])
 	}

 	if (errorcnt) {
-		fprintf(stderr, "\nUsage:  %s [options] ...\n\n", progname);
+		fprintf(stderr, usage, progname);
 		exit(1);
 	}

--
2.9.0


code:
From d2f946caf27adf4518cb657da39e296366d0b53f Mon Sep 17 00:00:00 2001
From: Mike Frysinger <vapier@chromium.org>
Date: Mon, 7 Dec 2015 21:46:13 -0500
Subject: [PATCH 2/6] use _DEFAULT_SOURCE for newer glibc

Newer versions of glibc have moved to _DEFAULT_SOURCE and away from
_BSD_SOURCE.  Trying to use the BSD define by itself leads to warnings
which causes build failures.

BRANCH=none
BUG=None
TEST=precq still works

Signed-off-by: Mike Frysinger <vapier@chromium.org>
Change-Id: Ice24b84dc6a540695fc7b76e8f22a4c85c301976
Reviewed-on: https://chromium-review.googlesource.com/316730
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
---
 util/ec_uartd.c | 3 ++-
 util/stm32mon.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/util/ec_uartd.c b/util/ec_uartd.c
index 82823c4..678932e 100644
--- a/util/ec_uartd.c
+++ b/util/ec_uartd.c
@@ -11,7 +11,8 @@
  */

 /* Force header files to define grantpt(), posix_openpt(), cfmakeraw() */
-#define _BSD_SOURCE
+#define _DEFAULT_SOURCE /* Newer glibc */
+#define _BSD_SOURCE     /* Older glibc */
 #define _XOPEN_SOURCE 600
 /* Force header file to declare ptsname_r(), etc. */
 #ifndef _GNU_SOURCE
diff --git a/util/stm32mon.c b/util/stm32mon.c
index 2de9400..ed1a7ee 100644
--- a/util/stm32mon.c
+++ b/util/stm32mon.c
@@ -13,7 +13,8 @@
  */

 /* use cfmakeraw() */
-#define _BSD_SOURCE
+#define _DEFAULT_SOURCE /* Newer glibc */
+#define _BSD_SOURCE     /* Older glibc */

 #include <arpa/inet.h>
 #include <errno.h>
--
2.9.0


code:
From 63bb6f6effbaae9864366588464a7b9354c9a623 Mon Sep 17 00:00:00 2001
From: Paul Kocialkowski <contact@paulk.fr>
Date: Wed, 20 Jul 2016 16:26:32 +0200
Subject: [PATCH 3/6] Enforce compilation without system headers

This is based on commit bc404c94b4ab1e6a62e607fd7ef034aa31d6388e
(Enforce compilation without system headers)
---
 Makefile           | 5 +++--
 Makefile.toolchain | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index 01581fb..195ea44 100644
--- a/Makefile
+++ b/Makefile
@@ -99,8 +99,9 @@ _rw_size_str:=$(shell echo "CONFIG_FW_RW_SIZE" | $(CPP) $(CPPFLAGS) -P \
 _rw_size:=$(shell echo "$$(($(_rw_size_str)))")

 # Get RSA key size from board defines
-_rsa_size:=$(shell echo "CONFIG_RSA_KEY_SIZE" | $(CPP) $(CPPFLAGS) -P \
-            -Ichip/$(CHIP) -Iboard/$(BOARD) -imacros include/rsa.h)
+_rsa_size:=$(shell echo "CONFIG_RSA_KEY_SIZE" | $(CPP) $(CPPFLAGS) \
+            $(CFLAGS_WARN) -P -Ichip/$(CHIP) -Iboard/$(BOARD) \
+            -imacros include/rsa.h)
 $(eval RSA_KEY_SIZE=$(_rsa_size))

 $(eval BOARD_$(UC_BOARD)=y)
diff --git a/Makefile.toolchain b/Makefile.toolchain
index 43f390c..898129c 100644
--- a/Makefile.toolchain
+++ b/Makefile.toolchain
@@ -19,7 +19,7 @@ BUILDCC?=gcc
 HOSTCC?=$(HOST_CROSS_COMPILE)gcc

 CFLAGS_WARN=-Wall -Werror -Wundef -Wstrict-prototypes -Wno-trigraphs      \
-            -fno-strict-aliasing -fno-common                              \
+            -fno-strict-aliasing -fno-common -ffreestanding -fno-builtin  \
             -Werror-implicit-function-declaration -Wno-format-security    \
             -fno-delete-null-pointer-checks -Wdeclaration-after-statement \
             -Wno-pointer-sign -fno-strict-overflow -fconserve-stack
--
2.9.0


code:
From 3515f1d744cbcdb37471e898277aa6b1ddd3d0ee Mon Sep 17 00:00:00 2001
From: Paul Kocialkowski <contact@paulk.fr>
Date: Wed, 20 Jul 2016 16:27:05 +0200
Subject: [PATCH 4/6] Don't declare functions inline that aren't always defined
 as such

This is based on commit 960cf45b3ffe88e842c27145e7e646d63a89c371
(Don't declare functions inline that aren't always defined as such)
---
 include/task.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/task.h b/include/task.h
index cb96281..85d5b00 100644
--- a/include/task.h
+++ b/include/task.h
@@ -47,7 +47,7 @@ void interrupt_enable(void);
 /**
  * Return true if we are in interrupt context.
  */
-inline int in_interrupt_context(void);
+int in_interrupt_context(void);

 /**
  * Set a task event.
--
2.9.0


code:
From 913b2f1265bd7f3ebe6cf4cba92c20c5a423a6c3 Mon Sep 17 00:00:00 2001
From: Paul Kocialkowski <contact@paulk.fr>
Date: Tue, 2 Aug 2016 12:05:55 +0200
Subject: [PATCH 5/6] Don't include missing and unnecessary math header

This removes the inclusion of an unnecessary math header that is neither
found nor necessary for non-cortex-m ECs.

Change-Id: I56a04178dadedb76f841504fa645e2d43900d25f
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
---
 common/math_util.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/common/math_util.c b/common/math_util.c
index 120d13d..34a267d 100644
--- a/common/math_util.c
+++ b/common/math_util.c
@@ -6,7 +6,6 @@
 /* Common math functions. */

 #include "common.h"
-#include "math.h"
 #include "math_util.h"
 #include "util.h"

--
2.9.0