Commit 2ac86991 authored by Alessandro Rubini's avatar Alessandro Rubini

build: Initial version, more or less working

This compiles only buildroot, at91boot and u-boot. Other steps are still
missing. However, the documentation is consistent with the code, and the
overall structure is going to remain this one. Time for a release.
parent 2fbdd2d9
This diff is collapsed.
# -*-shell-script-*-
# This file lists files we need to download. It is read by the shell,
# so it is organized by lines. Each line has 4 fields:
# filename md5sum upstream-location white-rabbit-svn-location
# note that backslashes are allowed to make continuation lines
#
AT91Bootstrap1.11.zip 547fe261cb0bfefdd57936e000ca7750 \
ftp://www.at91.com/pub/at91bootstrap/AT91Bootstrap1.11.zip \
pkg/AT91Bootstrap1.11.zip
u-boot-1.3.4.tar.bz2 ca12b805b4f2bdcf15733be3fe22e896 \
ftp://ftp.denx.de/pub/u-boot/u-boot-1.3.4.tar.bz2 \
pkg/u-boot-1.3.4.tar.bz2
buildroot-2009.11.tar.bz2 f742c4dc5e7f811464d9da789ff275d0 \
http://buildroot.uclibc.org/downloads/buildroot-2009.11.tar.bz2 \
pkg/buildroot-2009.11.tar.bz2
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#!/bin/bash
# check variables, like all scripts herein do
WRS_SCRIPT_NAME=$(basename $0)
if [ -z "$WRS_BASE_DIR" ]; then
echo "$0: Plesae set WRS_BASE_DIR" >& 2
exit 1
fi
. ${WRS_BASE_DIR}/scripts/wrs_functions
wrs_check_vars WRS_OUTPUT_DIR WRS_DOWNLOAD_DIR WRS_WR_REPOSITORY CROSS_COMPILE
wrs_echo "--- AT91Boot"
zipname="AT91Bootstrap1.11.zip"
wrs_download $zipname
mkdir -p $WRS_OUTPUT_DIR/build || wrs_die "mkdir build"
mkdir -p $WRS_OUTPUT_DIR/images || wrs_die "mkdir images"
# go to the build dir and compile it
cd $WRS_OUTPUT_DIR/build
dirname="Bootstrap-v1.11"; #stupid zip: content doesn't match the container
rm -rf $dirname
unzip -q ${WRS_DOWNLOAD_DIR}/$zipname || wrs_die "unzip $zipname"
wrs_echo "Patching AT91Boot"
patch -t -p2 -d $dirname < \
$WRS_BASE_DIR/patches/at91boot/AT91Bootstrap1.11-patch-wr \
|| wrs_die "patching at91boot"
wrs_echo "Building AT91Boot"; # stupid makefiles, I must force CROSS_COMPILE
make -C $dirname/board/whiterabbit-mch/dataflash CROSS_COMPILE=$CROSS_COMPILE \
|| wrs_die "compiling at91boot"
cp $dirname/board/whiterabbit-mch/dataflash/dataflash_whiterabbit-mch.bin \
$WRS_OUTPUT_DIR/images \
|| wrs_die "copying at91boot image"
exit 0
\ No newline at end of file
#!/bin/bash
# check variables, like all scripts herein do
WRS_SCRIPT_NAME=$(basename $0)
if [ -z "$WRS_BASE_DIR" ]; then
echo "$0: Plesae set WRS_BASE_DIR" >& 2
exit 1
fi
. ${WRS_BASE_DIR}/scripts/wrs_functions
wrs_check_vars WRS_OUTPUT_DIR WRS_DOWNLOAD_DIR WRS_WR_REPOSITORY
wrs_echo "--- Buildroot compiler and filesystem"
zipname="buildroot-2009.11.tar.bz2"
wrs_download $zipname
mkdir -p $WRS_OUTPUT_DIR/build || wrs_die "mkdir build"
mkdir -p $WRS_OUTPUT_DIR/images || wrs_die "mkdir images"
# go to the build dir and compile it, using our configuration
cd $WRS_OUTPUT_DIR/build
dirname="buildroot-2009.11"
rm -rf $dirname
tar xjf ${WRS_DOWNLOAD_DIR}/$zipname || wrs_die "untar $zipname"
# copy the config and replace "-j" level. First remove it in case it's left in
cd $dirname
cp $WRS_BASE_DIR/patches/buildroot/buildroot-config-wrswitch .config
sed -i /^BR2_JLEVEL/d .config
echo "BR2_JLEVEL=$WRS_MAKE_J_NUMBER" >> .config
# now, if CROSS_COMPILE is already set and is not ours, change the config
if [ "x$CROSS_COMPILE" != "x" ]; then
wrs_echo "Changing config for external compiler"
wrs_unset_config BR2_TOOLCHAIN_BUILDROOT
wrs_unset_config BR2_TOOLCHAIN_SOURCE
wrs_set_config BR2_TOOLCHAIN_EXTERNAL
echo BR2_TOOLCHAIN_EXTERNAL_PATH=\"$(dirname $(dirname $CROSS_COMPILE))\" \
>> .config
echo BR2_TOOLCHAIN_EXTERNAL_PREFIX="\"\$(ARCH)-linux\"" >> .config
echo '# BR2_TOOLCHAIN_EXTERNAL_UCLIBC is not set' >> .config
echo BR2_TOOLCHAIN_EXTERNAL_GLIBC=y >> .config
echo BR2_TOOLCHAIN_EXTERNAL_STRIP=y >> .config
fi
# re-digest the config we built
make oldconfig || wrs_die "buildroot config"
buildrootdir=$(/bin/pwd)
### currently, we get the packages from a local checkout or ohwr remote repo
mkdir -p $WRS_DOWNLOAD_DIR/buildroot-pkg || die "mkdir within downloads"
cd $WRS_DOWNLOAD_DIR/buildroot-pkg
repodir=$(echo $WRS_WR_REPOSITORY | sed 's-^file:/*-/-')
repodir=$repodir/trunk/pkg/buildroot-pkg
if [ -d $repodir ]; then
if ln $repodir/* . 2> /dev/null; then
wrs_echo "Hardlinked packages from $repodir"
else
cp -a $repodir/* . || wrs_die "copying"
wrs_echo "Copied packages from $repodir"
fi
else
# The repository is remote, then try wget
wrs_echo "Dowloading packages from $WRS_WR_REPOSITORY"
wget -nd -np -nc -nv -r $WRS_WR_REPOSITORY/pkg/buildroot-pkg/
fi
# buildroot wants its own guest source packages to be within its own dir..
# so "cd" to the place we saved, and copy stuff here as well
cd $buildrootdir
mkdir dl
if ln $WRS_DOWNLOAD_DIR/buildroot-pkg/* dl 2> /dev/null; then
wrs_echo "Hardlinked packages from downloads to build place"
else
cp -a $WRS_DOWNLOAD_DIR/buildroot-pkg/* dl || wrs_die "copying"
wrs_echo "Copied packages from downloads to build place"
fi
# We don't want CC to be pre-set at this point (some of us do :)
unset CC
make || wrs_die "buildroot compilation"
#!/bin/bash
# check variables, like all scripts herein do
WRS_SCRIPT_NAME=$(basename $0)
if [ -z "$WRS_BASE_DIR" ]; then
echo "$0: Plesae set WRS_BASE_DIR" >& 2
exit 1
fi
. ${WRS_BASE_DIR}/scripts/wrs_functions
wrs_check_vars WRS_OUTPUT_DIR WRS_DOWNLOAD_DIR WRS_WR_REPOSITORY CROSS_COMPILE
wrs_echo "--- U-Boot"
zipname="u-boot-1.3.4.tar.bz2"
wrs_download $zipname
mkdir -p $WRS_OUTPUT_DIR/build || wrs_die "mkdir build"
mkdir -p $WRS_OUTPUT_DIR/images || wrs_die "mkdir images"
# go to the build dir and compile it
cd $WRS_OUTPUT_DIR/build
dirname="u-boot-1.3.4"
rm -rf $dirname
tar xjf ${WRS_DOWNLOAD_DIR}/$zipname || wrs_die "untar $zipname"
wrs_echo "Patching U-Boot"
patch -t -p2 -d $dirname < \
$WRS_BASE_DIR/patches/u-boot/u-boot-1.3.4-wr-patch \
|| wrs_die "patching u-boot"
wrs_echo "Building U-Boot"
cd $dirname
make whiterabbit_mch || wrs_die "configure u-boot"
make -s $WRS_MAKE_J || wrs_die "compile u-boot"
cp u-boot u-boot.bin $WRS_OUTPUT_DIR/images \
|| wrs_die "copying u-boot image"
exit 0
\ No newline at end of file
# -*-shell-script-*-
# This file is loaded by the main build script and possibly
# sub scripts. It defines common utilities used at build time.
# All functions are prefixed with "wrs_" so they can be easily identified
# as local code within the scripts.
function wrs_echo {
# actually, this echo is to stderr, for diagnostics
echo -n "$(date "+%Y-%m-%d %H:%M:%S"): " >&2
echo $* >&2
}
function wrs_warn {
echo -n "$(date "+%Y-%m-%d %H:%M:%S"): " >& 2
echo "Warning: $*" >& 2
}
function wrs_err {
echo -n "$(date "+%Y-%m-%d %H:%M:%S"): " >& 2
echo "Error: $*" >& 2
}
function wrs_die {
if [ -n "$*" ]; then wrs_err $*; fi
exit 1
}
# Set a default variable without typing the name twice as in VAR=${VAR:-val}
function wrs_setenv_default {
name=$1
value=$2
if [ -z "$(eval echo \$$name)" ]; then
eval ${name}="$value"
fi
export $name
}
# Show current variables to make the user confident things are fine
function wrs_show_vars {
echo ""; echo "Building with the following parameters: "
for n in $*; do
val=$(env | grep "^$n=" | sed 's/^.*=//')
# we may show optional variables (e.g.: CROSS_COMPILE)
if [ "x$val" != "x" ]; then
printf "%-20s = %s\n" $n "$val"
fi
done
# If the shell's stdout is a tty (not redirected), allow a delay
stty -F /proc/$$/fd/1 2> /dev/null > /dev/null
if [ $? -ne 0 ]; then return; fi
echo -n "You may now ctrl-C for 3 seconds"
for n in 1 2 3; do
echo -n .; sleep 1
done
echo ""
}
function wrs_check_tools {
local error=false
for f in $*; do
if [ -z "$(type -p $f)" ]; then
wrs_err "Can't find \"$f\" in your current PATH" >& 2
error=true
fi
done
if $error; then
wrs_die "Please install missing tools"
fi
}
# While the function above is called once for all, the one below is called
# by each sub-script with a different list of required variables
function wrs_check_vars {
local error=false
for n in $*; do
env | grep -q "^$n=" && continue
wrs_echo "${WRS_SCRIPT_NAME}: Environment variable $n is not set" >&2
error=true
done
if $error; then
wrs_die
fi
}
# Set and unset a variable in a config file. Used for buildroot/kernel stuff
# Activate and deactivate a configuration option
function wrs_set_config {
local config
if [ "x$2" = "x" ]; then config=".config"; else config="$2"; fi
sed -i "s/# $1 is not set/$1=y/" $config
}
function wrs_unset_config {
local config
if [ "x$2" = "x" ]; then config=".config"; else config="$2"; fi
sed -i "s/$1=y/# $1 is not set/" $config
}
# We'll need to set CROSS_COMPILE to the buildroot one, if unset
function wrs_default_compiler {
dirname=$WRS_OUTPUT_DIR/build/buildroot-2009.11/output/staging/usr/bin
if [ -e $dirname/arm-linux-gcc ]; then
wrs_setenv_default CROSS_COMPILE $dirname/arm-linux-
fi
}
# See documentation about use of the download-info file. Unfortunately,
# a loop in a pipe is run in a sub-shell, so variables can't be just set.
# Therefore, we use a temporary file here
function wrs_download {
file=$1
DLLIST=${WRS_BASE_DIR}/download-info
wrs_echo "Looking for file $file"
T=$(mktemp /tmp/wrs-download-XXXXXX)
grep -v '^#' $DLLIST | grep -v '^[ ]*$' | \
while read name md5 upstream svnname; do
#echo "md5 $md5 name $name u $upstream s $svnname"
if [ "$name" != "$file" ]; then continue; fi
echo md5=\"$md5\" > $T
echo upstream=\"$upstream\" >> $T
echo svnname=\"$svnname\" >> $T
break
done
. $T
mkdir -p ${WRS_DOWNLOAD_DIR} || wrs_die "mkdir ${WRS_DOWNLOAD_DIR}"
# If it exists, we are done
output=${WRS_DOWNLOAD_DIR}/$file
if [ -f $output ]; then
ourmd5=$(cat $output | md5sum | sed 's/ .*$//')
if [ "$ourmd5" = "$md5" ]; then
wrs_echo "Skip download of $file"
return
else
wrs_warn "File $file is corrupted, re-downloading"
rm $output
fi
fi
# Check if svn is local and the file exists
repodir=$(echo $WRS_WR_REPOSITORY | sed 's-^file:/*-/-')
repofile=$repodir/trunk/$svnname
if [ -f $repofile ]; then
cp $repofile $output
wrs_echo "Copied $file from local svn repo"
return
fi
# Download from upstream
wget $upstream -nv $upstream -O $output
if [ -f $output ]; then
wrs_echo "Copied $file from upstream"
return
fi
# Finally, get from ohwr.org
wget $upstream -nv $WRS_WR_REPOSITORY/trunk/$svnname \
-O $output
if [ -f $output ]; then
wrs_echo "Retrieved $file from ohwr.org"
return
fi
wrs_error "Cannot download $file"
}
# The following builds one step if needed: if file $1 exists, then the
# step has already been acoomplished
function wrs_build_step {
markerfile=$WRS_DONE_DIR/$1
script=$2
wrs_check_vars WRS_DONE_DIR
if [ -f $markerfile ]; then return; fi
# The step is build in a sub-process, so we can continue with the next
# Note that
sh $WRS_SH_OPTIONS
}
# Every time wrs_functions is loaded, re-set WRS_MAKE_J
export WRS_MAKE_J_NUMBER=$(expr $(grep ^processor /proc/cpuinfo | wc -l) + 1)
export WRS_MAKE_J=-j$WRS_MAKE_J_NUMBER
#!/bin/bash
# This is the main build script. It must build all the environment
# variables for sub-scripts.
# Base dir is forcibly the dirname of this script, as an absolute pathname
dir=$(dirname $0)
if echo $dir | grep -q '^/'; then
WRS_BASE_DIR="$dir";
else
WRS_BASE_DIR="$(echo $(/bin/pwd)/$dir | sed 's-/.$--')";
fi
export WRS_BASE_DIR
. ${WRS_BASE_DIR}/scripts/wrs_functions
# See documentation for the meaning of these variables
wrs_setenv_default WRS_OUTPUT_DIR $(/bin/pwd)
wrs_setenv_default WRS_DOWNLOAD_DIR ${WRS_OUTPUT_DIR}/downloads
wrs_setenv_default WRS_WR_REPOSITORY http://svn.ohwr.org/white-rabbit
# Refuse to build within the directory itself
if [ "$WRS_OUTPUT_DIR" = "$WRS_BASE_DIR" ]; then
wrs_die "Please run $(basename $0) from a different directory"
fi
# Check the tools
# FIXME: is the list of tools correct?
WRS_TOOLS="curl svn git gcc g++ ar as m4 libtool gettext md5sum make"
WRS_TOOLS="$WRS_TOOLS awk unzip patch bison flex ncursesw5-config"
WRS_TOOLS="$WRS_TOOLS lua fakeroot"
wrs_check_tools $WRS_TOOLS
# Create the directory for the "done" markers, as wrs_build_step needs it
export WRS_DONE_DIR=${WRS_OUTPUT_DIR}/build/_done
if ! [ -d "${WRS_DONE_DIR}" ]; then
mkdir -p ${WRS_DONE_DIR} || wrs_die "mkdir failed"
fi
export WRS_SCRIPTS_DIR=${WRS_BASE_DIR}/scripts
wrs_show_vars WRS_BASE_DIR WRS_OUTPUT_DIR WRS_DOWNLOAD_DIR WRS_WR_REPOSITORY \
WRS_SCRIPTS_DIR WRS_DONE_DIR CROSS_COMPILE
# The function builds one step if needed: if the marker file exists, then the
# step has already been acoomplished and nothing is run this time
function wrs_build_step {
markerfile="$WRS_DONE_DIR/$1"
script="$WRS_SCRIPTS_DIR/$2"
if [ -f $markerfile ]; then
wrs_echo "Marker $markerfile exists:"
wrs_echo " not running $script"
return
fi
# Run another shell, so we can continue with the next step if it exits
# I sometimes set WRS_SH_OPTIONS to "-x" to help me in debugging
bash $WRS_SH_OPTIONS $script
if [ $? -ne 0 ];
then failed_step=true;
else touch $markerfile
fi
}
failed_step=false; # this is set to "true" but the wrs_build_step function
# Now build the stuff one step at a time, only if not already done.
# done-marker script name
wrs_build_step 00-buildroot wrs_build_buildroot
wrs_default_compiler
wrs_build_step 01-at91boot wrs_build_at91boot
wrs_build_step 02-u-boot wrs_build_u-boot
#wrs_build_step 03-kernel wrs_build_kernel
#wrs_build_step 04-filesystem wrs_build_buildroot-fs
#wrs_build_step 05-wrs-tools wrs_build_tools
#wrs_build_step 06-wrs-addon wrs_build_addon
#wrs_build_step 07-wrap-rootfs wrs_build_finalrootfs
#wrs_build_step 08-host-tftpd wrs_build_tftpd
if $failed_step; then
wrs_die "One or more build steps failed"
fi
wrs_echo "Complete build succeeded, apparently"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment