code:
#!/usr/bin/env 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/>.

DOTGIT=".git"
HEAD="HEAD"
ORIGIN_HEAD="origin/HEAD"
WILDDOTPATCH="*.patch"
GIT_NAME="Libreboot"
GIT_EMAIL="libreboot@libreboot.org"

git_check() {
	local repository_path=$1

	directory_filled_check "$repository_path/$DOTGIT"
}

git_clone() {
	local repository_path=$1
	local url=$2

	git clone "$url" "$repository_path"
}

git_submodule_update() {
	local repository_path=$1

	(
		cd "$repository_path"
		git submodule update --init
	)
}

git_merge() {
	local repository_path=$1
	local revision=$2

	(
		cd "$repository_path"
		git merge "$revision"
	)
}

git_branch_create() {
	local repository_path=$1
	local branch=$2
	local revision=$3

	(
		cd "$repository_path"
		git checkout -B "$branch"

		if [[ -n "$revision" ]]
		then
			git reset --hard "$revision"
		fi
	)
}

git_branch_delete() {
	local repository_path=$1
	local branch=$2

	(
		cd "$repository_path"
		git branch -D "$branch"
	)
}

git_branch_checkout() {
	local repository_path=$1
	local branch=$2

	(
		cd "$repository_path"
		git checkout "$branch" > /dev/null
	)
}

git_branch_check() {
	local repository_path=$1
	local branch=$2

	(
		cd "$repository_path" 2> /dev/null > /dev/null
		if [[ $? -ne 0 ]]
		then
			return 1
		fi

		git rev-parse --verify "$branch" 2> /dev/null > /dev/null
		if [[ $? -ne 0 ]]
		then
			return 1
		fi
	)
}

git_fetch() {
	local repository_path=$1

	(
		cd "$repository_path"
		git fetch origin
	)
}

git_fetch_check() {
	local repository_path=$1

	(
		cd "$repository_path" 2> /dev/null > /dev/null
		if [[ $? -ne 0 ]]
		then
			return 1
		fi

		local output=$(git fetch --dry-run origin 2>&1)
		if [[ -n "$output" ]]
		then
			return 1
		fi
	)
}

git_clean() {
	local repository_path=$1

	(
		cd "$repository_path"
		git clean -df
	)
}

git_remove() {
	local repository_path=$1
	local path=$2

	(
		cd "$repository_path"
		git rm -rf "$path"
	)
}

git_commit() {
	local repository_path=$1
	local message=$2

	(
		export GIT_COMMITTER_NAME=$GIT_NAME
		export GIT_COMMITTER_EMAIL=$GIT_EMAIL

		cd "$repository_path"
		git commit --author="$GIT_NAME <$GIT_EMAIL>" -m "$message"
	)
}

git_patch() {
	local repository_path=$1
	local branch=$2
	local patch=$3

	(
		export GIT_COMMITTER_NAME=$GIT_NAME
		export GIT_COMMITTER_EMAIL=$GIT_EMAIL

		cd "$repository_path"
		git checkout "$branch" 2> /dev/null > /dev/null
		git am "$patch"
	)
}

git_revision() {
	local repository_path=$1

	(
		cd "$repository_path"
		git rev-parse "$HEAD"
	)
}

git_describe() {
	local repository_path=$1

	(
		cd "$repository_path"
		git describe --tags
	)
}

git_files() {
	local repository_path="$1"

	(
		cd "$repository_path"
		# Reproducible sorting.
		git ls-files -z | env LC_ALL='C.UTF-8' sort -z
	)
}

git_project_repository_path() {
	local repository=$1

	printf '%s\n' "$root/$SOURCES/$repository"
}

git_project_check() {
	local repository=$1

	local repository_path=$(git_project_repository_path "$repository")

	git_check "$repository_path"
}

git_project_patch_recursive() {
	local project="$1"
	local repository="$2"
	local branch="$3"
	local path="${4:-.}"

	local repository_path="$(git_project_repository_path "$repository")"
	local project_path="$(project_path "$project")"
	local patches_path="$project_path/$PATCHES/$path"

	if ! [[ -d "$patches_path" ]]; then
		return
	fi

	if [[ "$path" != "." ]]; then
		git_project_patch_recursive "$project" "$repository" "$branch" "$(dirname "$path")"
	fi

	for patch in "$patches_path"/[!.]*.@(patch|diff); do
		if [[ "${patch##*.}" == "patch" ]]; then
			git_patch "$repository_path" "$branch" "$patch"
		else
			diff_patch_file "$repository_path" "$patch"
		fi
	done
}

git_project_clone() {
	local repository=$1
	shift
	local urls=$@

	local repository_path=$(git_project_repository_path "$repository")
	local directory_path=$(dirname "$repository_path")
	local url

	mkdir -p "$directory_path"

	(
		set +e

		for url in $urls
		do
			git_clone "$repository_path" "$url"

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

		return 1
	)
}

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

	git_project_prepare_revision "$project" "$repository" "$@"
	git_project_prepare_blobs "$project" "$repository" "$@"
	git_project_prepare_patch "$project" "$repository" "$@"
}

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

	local repository_path=$(git_project_repository_path "$repository")
	local blobs_path=$(project_blobs_path "$project" "$@")
	local blob

	if ! [[ -f "$blobs_path" ]]
	then
		return
	fi

	while read blob
	do
		git_remove "$repository_path" "$blob"
	done < "$blobs_path"

	git_commit "$repository_path" "Removed blobs"
}

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

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

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

			branch="$branch-$argument"
		fi

		local revision_path="$configs_path/$path/$REVISION"

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

		prepare_branch=$branch
		prepare_path=$path
	done

	if [[ -n "$prepare_branch" ]]
	then
		git_project_patch_recursive "$project" "$repository" "$prepare_branch" "$prepare_path"
	fi
}

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

	local repository_path=$(git_project_repository_path "$repository")
	local project_path=$(project_path "$project")
	local configs_path="$project_path/$CONFIGS"
	local prepare_branch
	local prepare_revision
	local branch=$project
	local argument
	local path

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

			branch="$branch-$argument"
		fi

		local revision_path="$configs_path/$path/$REVISION"

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

		prepare_branch=$branch
		prepare_revision=$(cat "$revision_path")
	done

	if [[ -n "$prepare_branch" ]]
	then
		git_branch_create "$repository_path" "$prepare_branch" "$prepare_revision"
	fi
}

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

	local repository_path=$(git_project_repository_path "$repository")
	local project_path=$(project_path "$project")
	local configs_path="$project_path/$CONFIGS"
	local prepare_branch
	local branch=$project
	local argument
	local path

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

			branch="$branch-$argument"
		fi

		local revision_path="$configs_path/$path/$REVISION"

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

		prepare_branch=$branch
	done

	if [[ -n "$prepare_branch" ]]
	then
		git_branch_check "$repository_path" "$prepare_branch"
	fi
}

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

	local repository_path=$(git_project_repository_path "$repository")
	local prepare_branch
	local branch=$project
	local argument

	for argument in "" "$@"
	do
		if [[ -n "$argument" ]]
		then
			branch="$branch-$argument"
		fi

		if ! git_branch_check "$repository_path" "$branch"
		then
			continue
		fi

		prepare_branch=$branch
	done

	if [[ -n "$prepare_branch" ]]
	then
		# Let's not worry about missing branches.
		(
			set +e

			git_branch_delete "$repository_path" "$prepare_branch"

			if [[ $? -ne 0 ]]
			then
				return 0
			fi
		)
	fi
}

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

	local repository_path=$(git_project_repository_path "$repository")
	local checkout_branch
	local branch=$project
	local argument

	for argument in "" "$@"
	do
		if [[ -n "$argument" ]]
		then
			branch="$branch-$argument"
		fi

		if ! git_branch_check "$repository_path" "$branch"
		then
			continue
		fi

		checkout_branch=$branch
	done

	if [[ -n "$checkout_branch" ]]
	then
		git_branch_checkout "$repository_path" "$checkout_branch"
		git_submodule_update "$repository_path"
	fi
}

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

	local repository_path=$(git_project_repository_path "$repository")

	git_fetch "$repository_path"
	git_branch_checkout "$repository_path" "$ORIGIN_HEAD"

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

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

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

	git_fetch_check "$repository_path"
}

git_project_release() {
	local project=$1
	shift
	local repository=$1
	shift
	local arguments=$@

	local repository_path=$(git_project_repository_path "$repository")
	local release_branch
	local branch=$project
	local argument

	for argument in "" "$@"
	do
		if [[ -n "$argument" ]]
		then
			branch="$branch-$argument"
		fi

		if ! git_branch_check "$repository_path" "$branch"
		then
			continue
		fi

		release_branch=$branch
	done

	if [[ -n "$release_branch" ]]
	then
		local archive_path="$root/$RELEASE/$SOURCES/$project/$release_branch.$ARCHIVE"
		local sources_path="$root/$SOURCES/$repository"

		printf '%s\n' "Releasing sources archive for $project (with ${arguments:-no argument}) from "$repository" git"

		git_branch_checkout "$repository_path" "$release_branch"
		git_submodule_update "$repository_path"
		git_clean "$repository_path"
		archive_create "$archive_path" "$sources_path" "$release_branch"
		file_verification_create "$archive_path"
	fi
}

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

	local repository_path=$(git_project_repository_path "$repository")
	local release_branch
	local branch=$project
	local argument

	for argument in "" "$@"
	do
		if [[ -n "$argument" ]]
		then
			branch="$branch-$argument"
		fi

		if ! git_branch_check "$repository_path" "$branch"
		then
			continue
		fi

		release_branch=$branch
	done

	if [[ -n "$release_branch" ]]
	then
		local archive_path="$root/$RELEASE/$SOURCES/$project/$release_branch.$ARCHIVE"

		file_exists_check "$archive_path"

		if [[ $? -ne 0 ]]
		then
			return 1
		else
			return 0
		fi
	fi
}

path: libs/git


code:
#!/usr/bin/env 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_GENERIC_IGNORE_CHECK=(usage clean)
PROJECT_ACTIONS_HELPERS=(arguments)

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

project_include() {
	local project=$1

	local project_path=$(project_path "$project")

	unset -f "${PROJECT_ACTIONS[@]}"

	source "$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
		source "$include"
	fi
}

project_check() {
	local project="${1##*/}"

	local project_path="$(project_path "$project")"

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

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

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

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

		if "$action" "$@"; then
			printf 1>&2 '\n%s\n' "Project $project $action (with ${arguments:-no argument}) completed"
		else
			printf 1>&2 '\n%s\n' "Project $project $action (with ${arguments:-no argument}) failed"
			return 1
		fi
	)
}

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

	(
		set +e

		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

	if ! function_check "$helper"; then
		return 0
	fi

	"$helper" "$@"
}

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

	project_include "$project"

	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 [[ -n "$action_helper_arguments" ]]; then
		test="$(printf '%s\n' "$action_helper_arguments" | grep -e "^$argument\$" || true)"

		if [[ -z "$test" ]]; then
			printf 1>&2 '%s\n' "Invalid argument $argument for project $project action $action"
			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

	action_helper_arguments="$(project_action_helper 'arguments' "$project" "$@" || true)"

	if [[ -z "$action_helper_arguments" ]]; then
		project_action "$action" "$project" "$@"
	else
		# This is to allow space characters in arguments.
		local ifs_save="$IFS"
		local IFS=$'\n'

		for argument in $(printf '%s\n' "$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
	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 -r arguments; do
		eval "project_action_arguments $action $arguments"
	done < "$path"
}

project_path() {
	local project=$1

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

	printf '%s\n' "$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 [[ -n "$argument" ]]
		then
			path="$path-$argument"
		fi

		if ! directory_filled_check "$path"
		then
			continue
		fi

		sources_path=$path
	done

	if [[ -n "$sources_path" ]]
	then
		printf '%s\n' "$sources_path"
		return
	fi

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

	if directory_filled_check "$path"
	then
		printf '%s\n' "$path"
		return
	fi

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

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

		if ! directory_filled_check "$path"
		then
			continue
		fi

		sources_path=$path
	done

	if [[ -n "$sources_path" ]]
	then
		printf '%s\n' "$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 [[ -n "$sources_path" ]]
	then
		printf 1>&2 '%s\n' "Sources directory for project $project (with ${arguments:-no argument}) already exists"
		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 1>&2 '%s\n' "Sources directory for project $project (with ${arguments:-no argument}) missing or empty"
		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 [[ -n "$argument" ]]
		then
			path="$path-$argument"
		fi

		local archive="$path.$ARCHIVE"

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

		sources_archive=$archive
	done

	if [[ -n "$sources_archive" ]]
	then
		printf '%s\n' "$sources_archive"
	fi
}

project_sources_archive_extract() {
	local project=$1
	shift
	local arguments="$*"

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

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

	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 '%s\n' "Extracting source archive for $project (with ${arguments:-no argument})"

	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 1>&2 '%s\n' "Missing sources archive for $project (with ${arguments:-no argument})"
		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_sources_prepare() {
	local project="$1"
	local sources_path="$2"

	# Not implemented yet / May end up not being needed
	#project_sources_prepare_blobs
	project_sources_prepare_patch "$project" "$sources_path" "$@"
}

project_sources_prepare_patch() {
	local project="$1"
	local sources_path="$2"

	local project_path="$(project_path "$project")"
	local patches_path="$project_path/$PATCHES"

	for patch in "$patches_path"/[!.]*.@(patch|diff); do
		diff_patch_file "$sources_path" "$patch"
	done
}

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 [[ -n "$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
			printf '%s\n' "$blobs_path"
			return
		fi
	done

	printf '%s\n' "$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 [[ -n "$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
			printf '%s\n' "$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 '\n%s\n' 'Generic actions:'

	(
		for action in "${PROJECT_ACTIONS_GENERIC[@]}"; do
			if function_check "$action"; then
				printf '%s\n' "  $action"
			fi
		done
	)

	if [[ "$#" -gt 0 ]]; then
		printf '\n%s\n' 'Specific actions:'

		(
			for action in "$@"; do
				printf '%s\n' "  $action"
			done
		)
	fi
}

project_usage_arguments() {
	local project="$1"
	shift

	printf '\n%s\n' 'Arguments:'

	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 [[ -n "$action_helper_arguments" ]]; then
		for argument in $action_helper_arguments; do
			printf '%s\n' "$spacing$argument"
			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_download_archive() {
	local project="$1"
	shift
	local archive_uri="$1"
	shift
	local archive_dsig_uri="$1"

	local archive="${archive_uri##*/}"
	local compress_fmt="${archive##*.tar}"

	local directory_prefix="$root/$SOURCES"
	local archive_path="$root/$SOURCES/$archive"
	local sources_path="$root/$SOURCES/$project"

	if [[ "${compress_fmt#*.}" != "${ARCHIVE#*.}" ]]; then
		ARCHIVE="tar$compress_fmt"
	fi

	# TODO: Split this code block into separate functions
	# Archive verification will be included at that point in time
	if ! project_sources_directory_filled_check "$project"; then
		download_wrapper "$directory_prefix" "$archive_uri" "$archive_dsig_uri"
		archive_extract "$archive_path" "$directory_prefix"

		mv "${archive_path%.tar*}" "$sources_path"
	fi

	# Patch the source, if necessary
	project_sources_prepare "$project" "$sources_path"
}

project_download_check_archive() {
	local project="$1"
	local sources_path="$2"

	# TODO: Write the following function
	#project_sources_archive_extract_check "$project" "$sources_path"
}

project_extract() {
	local project=$1
	shift

	local repository=$project

	if ! project_sources_directory_filled_check "$project" "$repository" "$@"
	then
		project_sources_archive_missing_error "$project" "$@" || return 1
		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 [[ -n "$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 -r rule
		do
			source=$(printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\1/g")
			source_path="$build_path/$source"

			# Source may contain a wildcard.
			path_wildcard_expand "$source_path" | while read -r 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

	printf '%s\n' "$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 1>&2 '%s\n' "Build directory for project $project (with ${arguments:-no argument}) missing or empty"
		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 [[ -n "$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 -r rule
		do
			source=$(printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\1/g")
			source_path="$build_path/$source"

			destination=$(printf '%s\n' "$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 -r 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 [[ -n "$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 -r rule
		do
			source=$(printf '%s\n' "$rule" | sed "s/$INSTALL_REGEX/\\1/g")
			source_path="$project_path/$INSTALL/$path/$source"

			destination=$(printf '%s\n' "$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 -r 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 [[ -n "$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 -r rule
		do
			destination=$(printf '%s\n' "$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 [[ -n "$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 -r rule
		do
			destination=$(printf '%s\n' "$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

	printf '%s\n' "$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 1>&2 '%s\n' "Install directory for project $project (with ${arguments:-no argument}) missing or empty"
		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

	printf '%s\n' "$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.$ARCHIVE"

	printf '%s\n' "$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.$ARCHIVE"

	printf '%s\n' "$rootfs_path"
}

project_release_sources_archive_path() {
	local project=$1
	shift

	local repository="$project"
	local sources_path="$(project_sources_path "$project" "$repository" "$@")"
	local archive_path="$root/$RELEASE/$SOURCES/$project/${sources_path##*/}.$ARCHIVE"

	printf '%s\n' "$archive_path"
}

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 '%s\n' "Releasing sources archive for $project (with ${arguments:-no argument})"

	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=$(find "$install_path" -type f || true)
	local file

	printf '%s\n' "$files" | while read -r 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=$(find "$install_path" -type f || true)
	local file

	printf '%s\n' "$files" | while read -r 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 '%s\n' "Releasing $prefix archive for $project (with ${arguments:-no argument})"

	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 '%s\n' "Releasing $prefix rootfs for $project (with ${arguments:-no argument})"

	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 [[ -n "$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

	printf '%s\n' "$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 [[ -n "$argument" ]]
		then
			path="$path/$argument"
		fi

		file_path="$path/$file"

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

		cat "$file_path"
	done
}

repo_name: ShalokShalom/libreboot

path: libs/project

license: mit


code:
#!/usr/bin/env 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_GENERIC_IGNORE_CHECK=(usage update)
TOOL_ACTIONS_HELPERS=(arguments)

tool_include() {
	local tool=$1

	local tool_path=$(tool_path "$tool")

	unset -f "${TOOL_ACTIONS[@]}"

	source "$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
		source "$include"
	fi
}

tool_check() {
	local tool="${1##*/}"

	local tool_path="$(tool_path "$tool")"

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

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 1>&2 '%s\n' "Tool $tool check failed"
			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 1>&2 '%s\n' "Tool $tool $action (with ${arguments:-no argument})"

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

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

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

	(
		set +e

		if ! tool_check "$tool"
		then
			printf 1>&2 '%s\n' "Tool $tool check failed"
			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 1>&2 '%s\n' "Tool $tool check failed"
			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
		printf '%s\n' "$action_helper_arguments" | while read argument
		do
			tool_action_arguments_recursive "$action" "$tool" "$@" "$argument"
		done
	fi
}

tool_arguments_targets() {
	local tool="$1"
	shift

	local tool_path="$(tool_path "$tool")"
	local targets_path="$tool_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
}

tool_path() {
	local tool=$1

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

	printf '%s\n' "$tool_path"
}

tool_sources_path() {
	local tool=$1
	shift

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

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

		if directory_filled_check "$path"
		then
			printf '%s\n' "$path"
			return
		fi
	done
}

tool_usage_actions() {
	local tool=$1
	shift

	printf '\n%s\n' 'Generic actions:'

	for action in "${TOOL_ACTIONS_GENERIC[@]}"
	do
		if function_check "$action"
		then
			printf '%s\n' "  $action"
		fi
	done

	if [[ $# -gt 0 ]]
	then
		printf '\n%s\n' 'Specific actions:'

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

tool_usage_arguments() {
	local tool=$1
	shift

	printf '\n%s\n' 'Arguments:'

	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 [[ -n "$action_helper_arguments" ]]
	then
		printf '%s\n' "$action_helper_arguments" | while read argument
		do
			printf '%s\n' "$spacing$argument"
			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 [[ -n "$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

	printf '%s\n' "$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 [[ -n "$argument" ]]
		then
			path="$path/$argument"
		fi

		file_path="$path/$file"

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

		cat "$file_path"
	done
}

path: libs/tool


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:
#!/usr/bin/env 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" "$@"
}

extract() {
	local repository="$project"

	project_extract "$project" "$@"
}

extract_check() {
	local repository="$project"

	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 repository="$project"

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

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

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

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

	mkdir -p "$build_path"
	make -C "$sources_path" -j"$TASKS"
	cp "$sources_path/bucts" "$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="$project"

	project_release_install_archive "$project" "$TOOLS" "$@"
	project_release_sources_archive_create "$project" "$@"
}

release_check() {
	local repository="bucts"

	project_release_install_archive_check "$project" "$TOOLS" "$@"
	project_release_sources_archive_exists_check "$project" "$@"
}

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

path: projects/bucts/bucts


path: projects/bucts/configs/install


path: projects/bucts/configs/revision


code:
CC:=gcc
OBJ:=bucts.o
VERSION:=withoutgit

ifeq ($(shell uname), FreeBSD)
	CFLAGS = -I/usr/local/include
	LDFLAGS = -L/usr/local/lib
endif

all: bucts

bucts: $(OBJ)
	$(CC) -o $@ $(OBJ) $(LDFLAGS) -lpci

%.o: %.c
	$(CC) $(CFLAGS) -DVERSION='"$(VERSION)"' -c $<

.PHONY: clean
clean:
	rm -f bucts $(OBJ)

path: projects/bucts/sources/Makefile


code:
/* compile: gcc -s -o bucts bucts.c -lpci  or:  make
 * run as root: ./bucts [0|1]
 */
/*
 * Copyright (C) 2011 Peter Stuge <peter@stuge.se>
 *
 * 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; version 2 of the License.
 *
 * 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, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 */

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/mman.h>
#if defined(__GLIBC__)
#include <sys/io.h>
#endif
#include <pci/pci.h>

#if defined (__sun) && (defined(__i386) || defined(__amd64))
#define MEM_DEV "/dev/xsvc"
#else
#define MEM_DEV "/dev/mem"
#endif

static int fd_mem=-1;

static void *sys_physmap(unsigned long phys_addr, size_t len) {
  void *virt_addr = mmap(0, len, PROT_WRITE|PROT_READ, MAP_SHARED, fd_mem, (off_t)phys_addr);
  return MAP_FAILED == virt_addr ? NULL : virt_addr;
}

static void physunmap(void *virt_addr, size_t len) {
  if (!len) {
    printf("Not unmapping zero size at %p\n", virt_addr);
    return;
  }
  munmap(virt_addr, len);
}

static void *physmap(const char *descr, unsigned long phys_addr, size_t len) {
  void *virt_addr;

  if (!descr)
    descr = "memory";

  if (!len) {
    printf("Not mapping %s, zero size at 0x%08lx.\n", descr, phys_addr);
    return NULL;
  }

  if ((getpagesize() - 1) & len)
    fprintf(stderr, "Unaligned size 0x%lx for %s at 0x%08lx!\n", (unsigned long)len, descr, phys_addr);

  if ((getpagesize() - 1) & phys_addr)
    fprintf(stderr, "Unaligned address 0x%08lx for %s!\n", phys_addr, descr);

  virt_addr = sys_physmap(phys_addr, len);
  if (!virt_addr) {
    fprintf(stderr, "Error accessing 0x%lx bytes %s at 0x%08lx!\n", (unsigned long)len, descr, phys_addr);
    perror("mmap(" MEM_DEV ")");
    if (EINVAL == errno) {
      fprintf(stderr, "\n");
      fprintf(stderr, "In Linux this error can be caused by the CONFIG_NONPROMISC_DEVMEM (<2.6.27),\n");
      fprintf(stderr, "CONFIG_STRICT_DEVMEM (>=2.6.27) and CONFIG_X86_PAT kernel options.\n");
      fprintf(stderr, "Please check if either is enabled in your kernel before reporting a failure.\n");
      fprintf(stderr, "You can override CONFIG_X86_PAT at boot with the nopat kernel parameter but\n");
      fprintf(stderr, "disabling the other option unfortunately requires a kernel recompile. Sorry!\n");
    }
  }

  return virt_addr;
}

int bucts(struct pci_dev *sb, int8_t newts) {
  uint8_t buc, ts;
  uint32_t rcba_addr;
  volatile uint8_t *rcba;
  const char *str[2]={
    "128kb address range 0xFFFE0000-0xFFFFFFFF is untranslated",
    "64kb address ranges at 0xFFFE0000 and 0xFFFF0000 are swapped"
  };

  switch (sb->device_id) {
  case 0x27b9:
    rcba_addr = pci_read_long(sb, 0xf0) & ~1;
    break;
  default:
    fprintf(stderr, "Unsupported LPC bridge. Sorry.\n");
    return 1;
  }

  rcba = physmap("RCBA", rcba_addr, 0x4000);
  if (!rcba)
    return 1;

  buc = rcba[0x3414];
  ts = buc & 1;
  printf("Current BUC.TS=%d - %s\n", ts, str[ts]);

  if (0 == newts || 1 == newts) {
    if (ts == newts) {
      printf("Not writing BUC register since TS is already correct.\n");
      goto unmap;
    }
    buc &= ~1;
    buc |= newts;
    rcba[0x3414] = buc;
    buc = rcba[0x3414];
    ts = buc & 1;
    printf("Updated BUC.TS=%d - %s\n", ts, str[ts]);
  }

unmap:
  physunmap((void *)rcba, 0x4000);
  return 0;
}

int main(int argc, const char *argv[], const char *envp[]) {
  int ret;
  char *endp;
  int8_t newts = -1;
  struct pci_access *pacc;
  struct pci_dev *dev, *sb = NULL;
#if defined(__FreeBSD__)
  int io_fd;
#endif

  printf("bucts utility version '" VERSION "'\n");

#if defined(__FreeBSD__)
  if ((io_fd = open("/dev/io", O_RDWR)) < 0) {
    perror("open(/dev/io)");
#else
  if (iopl(3)) {
    perror("iopl");
#endif
    printf("You need to be root.\n");
    return 1;
  }

  if (-1 == (fd_mem = open(MEM_DEV, O_RDWR|O_SYNC))) {
    perror("Error: open(" MEM_DEV ")");
    return 1;
  }

  pacc=pci_alloc();
  pci_init(pacc);
  pci_scan_bus(pacc);
  for (dev=pacc->devices; dev && !sb; dev=dev->next) {
    pci_fill_info(dev, PCI_FILL_IDENT|PCI_FILL_CLASS);
    if (dev->vendor_id != 0x8086 || dev->device_class != 0x0601)
      continue;
    sb = dev;
  }
  if (!sb) {
    fprintf(stderr, "Error: LPC bridge not found!\n");
    return 1;
  }

  printf("Using LPC bridge %04x:%04x at %02x%02x:%02x.%02x\n", sb->vendor_id, sb->device_id, sb->domain, sb->bus, sb->dev, sb->func);

  if (argc > 1) {
    newts = strtoul(argv[1], &endp, 10);
    if (endp == argv[1]) {
      fprintf(stderr, "Invalid new TS value '%s', please specify 0 or 1.\n", argv[1]);
      newts = -1;
    }
  }

  ret = bucts(sb, newts);

  close(fd_mem);
  return ret;
}


code:
#!/usr/bin/env 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_arguments "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:
#!/usr/bin/env 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