Bardzo szybki start

Skrypt nie wymaga praw administratora. Budowane jest jądro z dołączonym systemem bazowym. Do katalogu /lib trafiają wszystkie biblioteki znalezione w katalogu toolchaina, a nie tylko te wykorzystywane przez programy (busybox) - pozostawia to pole do dalszej optymalizacji.

quickstart.sh
#!/bin/bash
#Distro builder.
#Copyright 2010-2011 Marcin Bis <marcin@at@bis.org.pl>
 
#<Configuration>
#Toolchain prefix (Without ending -).
#TARGET=arm-none-linux-uclibcgnueabi
TARGET=arm-none-linux-gnueabi
 
#Directory, the cross-toolchain's sysroot is placed (needs to have "lib" directory, containing target libraries).
SYSROOT=/opt/tools
#Crosstool-NG example
#SYSROOT=$HOME/x-tools/$TARGET/$TARGET/sysroot
 
#Directory in which the tollchain is installed (assumming executables are in "bin" subdirectory)
TOOLS=/opt/tools/cross-tools
#Crosstool-NG example
#TOOLS=$HOME/x-tools/$TARGET
 
#Number of jobs to run simultanously (saves a lot of time on multi-core systems)
JOBS=4
 
#Password for root account in target system:
PASSPHRASE=toor
 
#</Configuration>
 
export SYSROOT TARGET
export PATH=$TOOLS/bin:$PATH
 
function get_all () {
wget -c http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.39.1.tar.bz2
wget -c http://busybox.net/downloads/busybox-1.18.5.tar.bz2
}
 
#This depends on versions of downloaded software.
function clean_sources() {
	rm -rf \
		linux-1.6.39.1/ \
		busybox-1.18.5/
}
 
function run() {
	echo "Press ENTER to execute wirtual system."
	echo "While it is running: Ctrl-a x to quit."
	read
	exec qemu-system-arm -M versatilepb -kernel zImage -nographic -append "console=ttyAMA0"
}
 
if [ "$1" == "--clean" ]; then
	clean_sources
	exit $?
elif [ "$1" == "--build" ]; then
	#do nothing, just go to first build command
	true
elif [ "$1" == "--get" ]; then
	get_all
	exit $?
elif [ "$1" == "--run" ]; then
	run
	exit $?
else
	cat << EOF
"Usage: $0 <--get|--build|--clean|--run>"
 
$0 --get       #Fetch all the sources to the current directory (from they original locations).
$0 --build     #Build simple system.
$0 --clean     #Removes all build directories (safe after successfull build).
$0 --run       #Run simple system in emulator.
 
See script source for more information.
EOF
	exit 1
fi
 
#Make bash show every command before execution.
set -x
 
#Make staging dir
STAGDIR=$(mktemp -d /tmp/$0.XXXXXX)
 
#================================== Kernel config & modules ====================
tar -xf linux-2.6.39.1.tar.bz2
cd linux-2.6.39.1/
make ARCH=arm CROSS_COMPILE=$TARGET- versatile_defconfig
#Selects EABI and initramfs settings in some cryptic way.
sed -i  \
	-e "s/# CONFIG_AEABI is not set/CONFIG_AEABI=y\nCONFIG_OABI_COMPAT=y\nCONFIG_ARM_UNWIND=y/" \
	-e "s/CONFIG_INITRAMFS_SOURCE=\"\"/CONFIG_INITRAMFS_SOURCE=\"rootfs-spec.txt\"\nCONFIG_INITRAMFS_ROOT_UID=0\nCONFIG_INITRAMFS_ROOT_GID=0\nCONFIG_INITRAMFS_COMPRESSION_NONE=y\n# CONFIG_INITRAMFS_COMPRESSION_GZIP is not set\n# CONFIG_INITRAMFS_COMPRESSION_BZIP2 is not set\n# CONFIG_INITRAMFS_COMPRESSION_LZMA is not set\n# CONFIG_INITRAMFS_COMPRESSION_XZ is not set\n# CONFIG_INITRAMFS_COMPRESSION_LZO is not set/" \
	.config
 
make ARCH=arm CROSS_COMPILE=$TARGET- oldconfig
make -j$JOBS ARCH=arm CROSS_COMPILE=$TARGET- modules
make ARCH=arm CROSS_COMPILE=$TARGET- INSTALL_MOD_PATH=$STAGDIR modules_install
 
cd ..
#================================== Busybox ====================================
tar -xf busybox-1.18.5.tar.bz2
cd busybox-1.18.5
 
make ARCH=arm defconfig
 
sed -i -e "s/CONFIG_FEATURE_IPV6=y/# CONFIG_FEATURE_IPV6 is not set/" .config 
make -j$JOBS ARCH=arm CROSS_COMPILE=$TARGET-
make ARCH=arm CROSS_COMPILE=$TARGET- install
 
BBDIR=$(pwd)/_install
 
cd ..
 
#================================== Config files ===============================
 
mkdir $STAGDIR/etc
 
cat > $STAGDIR/etc/inittab << EOF
null::sysinit:/etc/init.d/rcS
ttyAMA0::askfirst:/sbin/getty 115200 ttyAMA0
tty0::askfirst:/sbin/getty 38400 tty0
#ttyS0::askfirst:/sbin/getty 115200 ttyS0
#ttyS2::askfirst:/sbin/getty 115200 ttyS2
EOF
 
mkdir $STAGDIR/etc/init.d
 
cat >> $STAGDIR/etc/init.d/rcS << EOF
#!/bin/ash
/bin/mount -t proc proc /proc
/bin/mount -t sysfs sys /sys
/bin/mount -t devpts devpts /dev/pts
echo "embedded1" > /proc/sys/kernel/hostname
echo /sbin/mdev > /proc/sys/kernel/hotplug
/bin/ip link set lo up
/sbin/mdev -s
EOF
 
cat >> $STAGDIR/etc/passwd << EOF
root:x:0:0:root:/:/bin/ash
EOF
 
CPASS=$(echo "$PASSPHRASE" | openssl passwd -1 -stdin)
cat >> $STAGDIR/etc/shadow << EOF
root:$CPASS:14778:0:99999:7:::
EOF
 
#================================== Kernel final ===============================
cd linux-2.6.39.1/
 
#Standard files
cat > rootfs-spec.txt << EOF
dir /dev 755 0 0
dir /dev/pts 755 0 0
dir /etc 755 0 0
dir /etc/init.d 755 0 0
nod /dev/console 644 0 0 c 5 1
nod /dev/null 644 0 0 c 1 3
dir /bin 755 0 0
dir /lib 755 0 0
dir /sbin 755 0 0
dir /proc 755 0 0
dir /sys 755 0 0
dir /mnt 755 0 0
dir /usr 755 0 0
dir /usr/bin 755 0 0
dir /usr/sbin 755 0 0
file /etc/inittab $STAGDIR/etc/inittab 644 0 0
file /etc/init.d/rcS $STAGDIR/etc/init.d/rcS 755 0 0
file /etc/passwd $STAGDIR/etc/passwd 644 0 0
file /etc/shadow $STAGDIR/etc/shadow 600 0 0
file /bin/busybox $BBDIR/bin/busybox 755 0 0
slink /init bin/busybox 777 0 0
EOF
 
#Busybox
for file in $(find $BBDIR -type l); do
	F=$(echo $file | sed -e "s%$BBDIR%%")
	L=$(readlink $file)
	echo "slink $F $L 777 0 0"
done >> rootfs-spec.txt
 
#Libraries
LIBDIR=$SYSROOT/lib
for file in $(find $LIBDIR -type f -name '*.so*'); do
	F=$(echo $file | sed -e "s%$LIBDIR%%")
	echo "file /lib$F $file 755 0 0"
done >> rootfs-spec.txt
 
for file in $(find $LIBDIR -type l); do
	F=$(echo $file | sed -e "s%$LIBDIR%%")
	L=$(readlink $file)
	echo "slink /lib$F $L 777 0 0"
done >> rootfs-spec.txt
 
#Modules
MODDIR=$STAGDIR/lib/modules
 
for file in $(find $MODDIR -type d); do
	F=$(echo $file | sed -e "s%$MODDIR%%")
	echo "dir /lib/modules$F 755 0 0"
done >> rootfs-spec.txt
 
for file in $(find $MODDIR -type f -name '*.ko'); do
	F=$(echo $file | sed -e "s%$MODDIR%%")
	echo "file /lib/modules$F $file 755 0 0"
done >> rootfs-spec.txt
 
#Build kernel with embedded ramdisk
make -j$JOBS ARCH=arm CROSS_COMPILE=$TARGET- zImage
cp arch/arm/boot/zImage ../
 
#================================== Clean ======================================
rm -rf $STAGDIR

System bazowy

Wynikiem działania skryptu jest plik zImage, gotowy do uruchomienia w emulatorze. Przykładowy plik wynikowy znajduje się tu: http://bis.org.pl/static/zImage. Użytkownik: root, hasło: toor.

System bazowy do debugowania

Zmodyfikowana wersja opisanego powyżej skryptu, została wykorzystana do zbudowania systemu bazowego umożliwiającego zdalne debugowanie aplikacji z poziomu Eclipse IDE. System bazowy do debugowania.

ostatnio zmienione: 2011/07/18 13:09