Initial commit; kernel source import

This commit is contained in:
Nathan
2025-04-06 23:50:55 -05:00
commit 25c6d769f4
45093 changed files with 18199410 additions and 0 deletions

2
chromeos/scripts/README Normal file
View File

@@ -0,0 +1,2 @@
For details on how to use these scripts, please see:
http://dev.chromium.org/chromium-os/how-tos-and-troubleshooting/kernel-configuration

190
chromeos/scripts/kernelconfig Executable file
View File

@@ -0,0 +1,190 @@
#!/bin/bash
# Script to merge all configs and run 'make oldconfig' on it to wade out bad juju.
# Then split the configs into distro-commmon and flavour-specific parts
#
# See this page for more details:
# http://dev.chromium.org/chromium-os/how-tos-and-troubleshooting/kernel-configuration
error() {
printf 'error: %b\n' "$*" >&2
}
die() {
error "$@"
exit 1
}
usage() {
cat <<-EOF
Usage: ${0##*/} [options] <oldconfig|olddefconfig|editconfig|genconfig>
Options:
-h This screen.
EOF
if [[ $# -gt 0 ]]; then
echo
die "$@"
else
exit 0
fi
}
build_one() {
local arch=$1
local kernarch
# Map debian archs to kernel archs.
case "${arch}" in
armel) kernarch="arm" ;;
*) kernarch="${arch}" ;;
esac
echo ""
echo "***************************************"
echo "* Processing ${arch} (${kernarch}) ... "
local O="$(pwd)/build/${arch}"
mkdir -p "${O}"
local config
local archconfdir="${confdir}/${arch}"
local flavourconfigs=( $(cd "${archconfdir}" && echo *.flavour.config) )
# Merge configs
# We merge base.config + common.config + <flavour>.flavour.config
for config in "${flavourconfigs[@]}"; do
cat \
"${base_conf}" \
"${archconfdir}/common.config" \
"${archconfdir}/${config}" \
> "${O}/.config"
# Call oldconfig or menuconfig
case ${mode} in
oldconfig|olddefconfig)
# Weed out incorrect config parameters
echo "* Run ${mode} on ${arch}/${config} ..."
make -j O="${O}" ARCH=${kernarch} "${mode}"
;;
editconfig)
# Interactively edit config parameters
echo "* ${arch}/${config}: press <Enter> to edit, S to skip"
read -s -n 1
case ${REPLY} in
s|S)
echo "* Skip: running oldconfig"
make -j O="${O}" ARCH=${kernarch} oldconfig
;;
*)
echo "* Running menuconfig"
make -j O="${O}" ARCH=${kernarch} menuconfig
;;
esac
;;
*) # Bad!
die "invalid mode ${mode}"
;;
esac
cat "${O}/.config" > "${archconfdir}/${config}"
if [[ "${keep}" == "1" ]]; then
# oldconfig is probably redundant because .config is
# likely formatted already at this point, however
# this only take a split-second and could flag some
# issues.
make -j O="${O}" ARCH=${kernarch} oldconfig
make -j O="${O}" ARCH=${kernarch} savedefconfig
mv "${O}"/.config "CONFIGS/${arch}-${config}"
mv "${O}"/defconfig "CONFIGS/${arch}-${config}.def"
fi
done
echo "Running splitconfig for ${arch}"
echo
# Can we make this more robust by avoiding $tmpdir completely?
# This approach was used for now because I didn't want to change
# splitconfig
pushd "${archconfdir}" >/dev/null
rm common.config
"${bindir}/splitconfig"
mv common.config "${tmpdir}/${arch}.config"
popd >/dev/null
}
cleanup() {
rm -rf "${tmpdir}"
}
cd_kerneldir() {
# We have to be in the top level kernel source directory.
if [[ ! -f MAINTAINERS || ! -f Makefile ]]; then
# See if we can find it automatically first.
local d=$(realpath "${0%/*}/../..")
cd "${d}"
if [[ ! -f MAINTAINERS || ! -f Makefile ]]; then
die "This does not appear to be the kernel source directory."
else
echo "Using top kernel dir: ${d}"
fi
fi
}
main() {
# Process use flags first (so -h works nicely).
local opt
while getopts "h" opt; do
case ${opt} in
h) usage ;;
*) usage "Invalid option ${opt}" ;;
esac
done
shift $(( OPTIND - 1 ))
# Process the remaining args.
local mode=$1
case ${mode} in
oldconfig|olddefconfig) ;; # All is good
editconfig) ;; # All is good
genconfig) ;; # All is good
*) usage "invalid/missing mode: ${mode}" ;;
esac
# Then make sure we're in the right directory.
cd_kerneldir
# Set up variables the build func expects.
local kerneldir=$(pwd)
local confdir="${kerneldir}/chromeos/config"
local archs=( x86_64 armel )
local bindir="${kerneldir}/chromeos/scripts"
local base_conf="${confdir}/base.config"
export tmpdir=$(mktemp -d)
trap cleanup EXIT
local keep=0
if [[ "${mode}" == "genconfig" ]]; then
keep=1
mode="oldconfig"
mkdir -p CONFIGS
fi
mkdir -p build
echo "running ${mode} for ${archs[*]}"
echo ""
for arch in "${archs[@]}"; do
build_one "${arch}"
done
# Now run splitconfig on all the <arch>.common.config copied to $tmpdir.
pushd "${tmpdir}" >/dev/null
"${bindir}/splitconfig"
mv "common.config" "${base_conf}"
for arch in "${archs[@]}"; do
mv "${arch}.config" "${confdir}/${arch}/common.config"
done
}
main "$@"

22
chromeos/scripts/prepareconfig Executable file
View File

@@ -0,0 +1,22 @@
#!/bin/bash
# See this page for more details:
# http://dev.chromium.org/chromium-os/how-tos-and-troubleshooting/kernel-configuration
family=chromeos
flavourconf=$(find ${family}/config -name $1.flavour.config)
if [ ! -f "${flavourconf}" ]; then
echo "Found no flavour configuration for '$1'." 1>&2
exit 1
fi
outputfile="${2:-.config}"
archconfdir=$(dirname ${flavourconf})
arch=$(basename ${archconfdir})
# Generate .config
cat "${family}/config/base.config" \
"${archconfdir}/common.config" \
"${flavourconf}" > "${outputfile}"

52
chromeos/scripts/splitconfig Executable file
View File

@@ -0,0 +1,52 @@
#!/usr/bin/env python3
"""See this page for more details:
http://dev.chromium.org/chromium-os/how-tos-and-troubleshooting/kernel-configuration
"""
from __future__ import print_function
import os
import re
import sys
allconfigs = {}
# Parse config files
for config in os.listdir("."):
# Only config.*
if not config.endswith(".config"):
continue
allconfigs[config] = set()
for line in open(config):
m = re.match("#*\s*CONFIG_(\w+)[\s=](.*)$", line)
if not m:
continue
option, value = m.groups()
allconfigs[config].add((option, value))
# Split out common config options
common = None
for config in allconfigs:
if common is None:
common = allconfigs[config].copy()
else:
common &= allconfigs[config]
for config in allconfigs:
allconfigs[config] -= common
allconfigs["common.config"] = common
# Generate new splitconfigs
for config in allconfigs:
f = open(config, "w")
command = os.path.basename(sys.argv[0])
print("#\n# Config options generated by %s\n#" % command, file=f)
for option, value in sorted(list(allconfigs[config])):
if value == "is not set":
print("# CONFIG_%s %s" % (option, value), file=f)
else:
print("CONFIG_%s=%s" % (option, value), file=f)
f.close()

View File

@@ -0,0 +1,91 @@
#! /bin/bash
#
# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
# Distributed under the terms of the GNU General Public License v2
# Print help if no args provided, or if the user is requesting help.
if [[ $# -eq 0 || $1 == "--help" || $1 == "-h" ]]; then
name=$(basename $0)
cat <<-EOF
USAGE: ./${name} [list of boards]
e.g. ./${name} x86-generic amd64-generic daisy
This command will build kernel for the following boards:
- x86-generic
- amd64-generic
- daisy
It will then generate a file containing all smatch errors not already
in the known errors whitelist. Duplicates will be listed only once.
If chromeos-kernel is not cros_workon'd for a board, that board will
be skipped.
EOF
exit
fi
# Put board name arguments into a list.
BOARDS=()
SKIPPED_BOARDS=()
while [[ $# -gt 0 ]]; do
board=$1
# If kernel is not cros-workon'd, then skip this board.
if cros_workon-${board} list | grep -q chromeos-kernel; then
BOARDS+=( "${board}" )
else
SKIPPED_BOARDS+=( "${board}" )
fi
shift
done
datestamp() {
date +%Y%m%d%H%M%s
}
# We want to ignore smatch test errors when building kernel, so that we can
# collect those errors for updating the whitelist.
export FEATURES='test test-fail-continue'
export USE="smatch ignore_test_errors"
LOG_FILES=()
for board in "${BOARDS[@]}"; do
LOG_FILE=/tmp/${board}-kernel-$(datestamp).log
emerge-${board} chromeos-kernel |& tee "${LOG_FILE}"
pipestatus=${PIPESTATUS[*]}
if [[ ${pipestatus// } -ne 0 ]]; then
echo "Error building kernel for ${board}" >&2
exit 1
fi
grep "Non-whitelisted error found:" "${LOG_FILE}" | cut -f 2- -d: | \
sed -e 's/"$//g' | cut -f 2- -d '"' | \
sort > "${LOG_FILE}.new_errors"
LOG_FILES+=( "${LOG_FILE}.new_errors" )
done
# Create a new log file to contain all errors, overwriting it if it already
# exists. For each board's new errors, add to this log file the errors that
# haven't already been added. This creates the union of all new errors.
NEW_ERRORS_FILE=/tmp/smatch_new_errors-$(datestamp).log
for log_file in "${LOG_FILES[@]}"; do
while read line; do
fgrep -q "${line}" "${NEW_ERRORS_FILE}" && continue
echo "${line}"
done < "${log_file}"
done > "${NEW_ERRORS_FILE}"
# Rename the new errors file to reflect the new boards, and move it to the
# current working directory.
BOARDS_NO_SPACES=$(printf -- -%s "${BOARDS[@]}")
NEW_ERRORS_FILE_FINAL=smatch_new_errors${BOARDS_NO_SPACES}.log
if [[ $(wc -l < "${NEW_ERRORS_FILE}") -ne 0 ]]; then
mv "${NEW_ERRORS_FILE}" "${NEW_ERRORS_FILE_FINAL}" || exit
fi
echo "*****************************************************"
echo "Done building kernel for these boards: ${BOARDS[*]}"
[[ ${#SKIPPED_BOARDS[@]} -gt 0 ]] && \
echo "Skipped these boards because kernel was not cros_workon'd:" \
"${SKIPPED_BOARDS[*]}"
if [[ -e ${NEW_ERRORS_FILE_FINAL} ]]; then
echo "New smatch errors are in ${NEW_ERRORS_FILE_FINAL}"
else
echo "No new smatch errors found."
fi