Another reorganization of the 'experiemntal' folder. Added musl with toybox (doesn't work at the moment).

This commit is contained in:
Ivan Davidov 2015-09-19 21:54:31 +03:00
parent 130ffa2cec
commit 9797b843d1
43 changed files with 389 additions and 6 deletions

16
.gitignore vendored
View File

@ -6,11 +6,15 @@
/src/work/** /src/work/**
/src/*.iso /src/*.iso
/src/experimental/toybox/source/** /src/experimental/glibc-toybox/source/**
/src/experimental/toybox/work/** /src/experimental/glibc-toybox/work/**
/src/experimental/toybox/*.iso /src/experimental/glibc-toybox/*.iso
/src/experimental/musl/source/** /src/experimental/musl-busybox/source/**
/src/experimental/musl/work/** /src/experimental/musl-busybox/work/**
/src/experimental/musl/*.iso /src/experimental/musl-busybox/*.iso
/src/experimental/musl-toybox/source/**
/src/experimental/musl-toybox/work/**
/src/experimental/musl-toybox/*.iso

View File

@ -0,0 +1,18 @@
# You can find the latest Linux kernel source bundles here:
#
# http://kernel.org
#
KERNEL_SOURCE_URL=https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.1.6.tar.xz
# You can find the latest Musl source bundles here:
#
# http://musl-libc.org
#
MUSL_SOURCE_URL=http://musl-libc.org/releases/musl-1.1.11.tar.gz
# You can find the latest ToyBox source bundles here:
#
# http://landley.net/toybox
#
TOYBOX_SOURCE_URL=http://landley.net/toybox/downloads/toybox-0.6.0.tar.gz

View File

@ -0,0 +1,8 @@
#!/bin/sh
rm -rf work
mkdir work
# -p stops errors if the directory already exists.
mkdir -p source

View File

@ -0,0 +1,24 @@
#!/bin/sh
# Grab everything after the '=' character.
DOWNLOAD_URL=$(grep -i KERNEL_SOURCE_URL .config | cut -f2 -d'=')
# Grab everything after the last '/' character.
ARCHIVE_FILE=${DOWNLOAD_URL##*/}
cd source
# Downloading kernel file.
# -c option allows the download to resume.
wget -c $DOWNLOAD_URL
# Delete folder with previously extracted kernel.
rm -rf ../work/kernel
mkdir ../work/kernel
# Extract kernel to folder 'work/kernel'.
# Full path will be something like 'work/kernel/linux-4.1.6'.
tar -xvf $ARCHIVE_FILE -C ../work/kernel
cd ..

View File

@ -0,0 +1,23 @@
#!/bin/sh
cd work/kernel
# Change to the first directory ls finds, e.g. 'linux-3.18.6'.
cd $(ls -d *)
# Cleans up the kernel sources, including configuration files.
make mrproper
# Create a default configuration file for the kernel.
make defconfig
# Changes the name of the system.
sed -i "s/.*CONFIG_DEFAULT_HOSTNAME.*/CONFIG_DEFAULT_HOSTNAME=\"minimal\"/" .config
# Compile the kernel with optimization for "parallel jobs" = "number of processors".
# Good explanation of the different kernels:
# http://unix.stackexchange.com/questions/5518/what-is-the-difference-between-the-following-kernel-makefile-terms-vmlinux-vmlinux
make bzImage -j $(grep ^processor /proc/cpuinfo | wc -l)
cd ../../..

View File

@ -0,0 +1,24 @@
#!/bin/sh
# Grab everything after the '=' character
DOWNLOAD_URL=$(grep -i MUSL_SOURCE_URL .config | cut -f2 -d'=')
# Grab everything after the last '/' character
ARCHIVE_FILE=${DOWNLOAD_URL##*/}
cd source
# Downloading musl file
# -c option allows the download to resume
wget -c $DOWNLOAD_URL
# Delete folder with previously extracted musl
rm -rf ../work/musl
mkdir ../work/musl
# Extract musl to folder 'work/musl'
# Full path will be something like 'work/musl/musl-1.1.11'
tar -xvf $ARCHIVE_FILE -C ../work/musl
cd ..

View File

@ -0,0 +1,18 @@
#!/bin/sh
cd work/musl
# Change to the first directory ls finds, e.g. 'musl-1.1.11'
cd $(ls -d *)
make distclean
mkdir musl-installed
./configure --prefix=$(pwd)/musl-installed
make -j $(grep ^processor /proc/cpuinfo | wc -l)
make install -j $(grep ^processor /proc/cpuinfo | wc -l)
cd ../../..

View File

@ -0,0 +1,65 @@
#!/bin/sh
cd work/kernel
cd $(ls -d *)
WORK_KERNEL_DIR=$(pwd)
cd ../../..
cd work/musl
# Change to the first directory ls finds, e.g. 'musl-1.1.11'
cd $(ls -d *)
cd musl-installed/bin
unlink musl-cc
ln -s musl-gcc musl-cc
unlink musl-ar
ln -s `which ar` musl-ar
unlink musl-strip
ln -s `which strip` musl-strip
cd ../include
#
# Should work with headers from the newly downloaded kernel
# but it diesn't work. Damn!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#
#unlink linux
#ln -s $WORK_KERNEL_DIR/include/linux linux
#
#unlink mtd
#ln -s $WORK_KERNEL_DIR/include/linux/mtd mtd
#
#unlink asm
#ln -s $WORK_KERNEL_DIR/include/uapi/asm-generic asm
#
#unlink asm-generic
#ln -s $WORK_KERNEL_DIR/include/uapi/asm-generic asm-generic
#
#unlink uapi
#ln -s $WORK_KERNEL_DIR/include/uapi uapi
#
#unlink uapi
#ln -s $WORK_KERNEL_DIR/include/uapi uapi
unlink linux
ln -s /usr/include/linux linux
unlink mtd
ln -s /usr/include/mtd mtd
if [ -d /usr/include/asm ]
then
unlink asm
ln -s /usr/include/asm asm
else
unlink asm
ln -s /usr/include/asm-generic asm
fi
unlink asm-generic
ln -s /usr/include/asm-generic asm-generic

View File

@ -0,0 +1,24 @@
#!/bin/sh
# Grab everything after the '=' character.
DOWNLOAD_URL=$(grep -i TOYBOX_SOURCE_URL .config | cut -f2 -d'=')
# Grab everything after the last '/' character.
ARCHIVE_FILE=${DOWNLOAD_URL##*/}
cd source
# Downloading ToyBox source.
# -c option allows the download to resume.
wget -c $DOWNLOAD_URL
# Delete folder with previously extracted ToyBox.
rm -rf ../work/toybox
mkdir ../work/toybox
# Extract toybox to folder 'toybox'.
# Full path will be something like 'work/toybox/toybox-0.6.0'.
tar -xvf $ARCHIVE_FILE -C ../work/toybox
cd ..

View File

@ -0,0 +1,54 @@
#!/bin/sh
cd work/musl
cd $(ls -d *)
cd musl-installed
cd bin
MUSL_BIN_DIR=$(pwd)
cd ../../../../..
cd work/toybox
# Change to the first directory ls finds, e.g. 'toybox-0.6.0'
cd $(ls -d *)
PATH_BACKUP=$PATH
PATH=$MUSL_BIN_DIR:$PATH
# Remove previously generated artefacts.
make distclean
# Create a configuration file with all possible selections.
#make allyesconfig
make defconfig
sed -i "s/.*CONFIG_DHCP.is.*/CONFIG_DHCP=y/" .config
# Static linking and cross compiling.
export CFLAGS="-std=c99"
export LDFLAGS="--static"
export CROSS_COMPILE="musl-"
# Compile ToyBox with optimization for "parallel jobs" = "number of processors".
make toybox -j $(grep ^processor /proc/cpuinfo | wc -l)
# We no longer need flags for static linking and cross compiling.
unset CFLAGS
unset LDFLAGS
unset CROSS_COMPILE
rm -rf rootfs
mkdir rootfs
# Directory where ToyBox binary and symlink will be instaled.
export PREFIX=rootfs
# Create the symlinks for toybox in single folder.
make install_flat
# We no longer need this environment variable.
unset PREFIX
PATH=$PATH_BACKUP
cd ../../..

View File

@ -0,0 +1,70 @@
#!/bin/sh
cd work
rm -rf rootfs
mkdir rootfs
cd toybox
cd $(ls -d *)
# Copy all toybox generated stuff to the location of our "initramfs/bin" folder.
cp -R rootfs ../../rootfs/bin
cd ../../rootfs
# Create root FS folders
mkdir dev
mkdir etc
mkdir proc
mkdir root
mkdir src
mkdir sys
mkdir tmp
# "1" means that only the owner of a file/directory (or root) can remove it.
chmod 1777 tmp
cd etc
# The file "/etc/welcome.txt" is displayed on every boot.
cat > welcome.txt << EOF
#####################################
# #
# Welcome to "Minimal Linux Live" #
# #
#####################################
EOF
cd ..
# For now we have simple console.
cat > init << EOF
#!/bin/sh
dmesg -n 1
mount -t devtmpfs none /dev
mount -t proc none /proc
mount -t sysfs none /sys
ifconfig eth0 up
dhcp -i eth0
cat /etc/welcome.txt
sh
poweroff
EOF
chmod +rx init
# Copy all source files to "/src". Note that the scripts won't work there.
cp ../../*.sh src
cp ../../.config src
chmod +r src/*.sh
chmod +r src/.config
cd ../..

View File

@ -0,0 +1,14 @@
#!/bin/sh
cd work
# Remove the old initramfs archive if it exists.
rm -f rootfs.cpio.gz
cd rootfs
# Packs the current folder structure in "cpio.gz" archive.
find . | cpio -H newc -o | gzip > ../rootfs.cpio.gz
cd ../..

View File

@ -0,0 +1,19 @@
#!/bin/sh
rm -f minimal_linux_live.iso
cd work/kernel
cd $(ls -d *)
# Edit Makefile to look for genisoimage instead of mkisofs. This was added as a
# workaround for some "Debian" and "Arch Linux" distributions. In general this
# fix should be harmless.
sed -i 's/mkisofs/genisoimage/g' arch/x86/boot/Makefile
# Generate the ISO image with optimization for "parallel jobs" = "number of processors"
make isoimage FDINITRD=../../rootfs.cpio.gz -j $(grep ^processor /proc/cpuinfo | wc -l)
cp arch/x86/boot/image.iso ../../../minimal_linux_live.iso
cd ../../..

View File

@ -0,0 +1,10 @@
#!/bin/sh
sh 0_prepare.sh
sh 1_get_kernel.sh
sh 2_build_kernel.sh
sh 3_get_toybox.sh
sh 4_build_toybox.sh
sh 5_generate_rootfs.sh
sh 6_pack_rootfs.sh
sh 7_generate_iso.sh

View File

@ -0,0 +1,4 @@
#!/bin/sh
qemu-system-i386 -cdrom minimal_linux_live.iso

View File

@ -0,0 +1,4 @@
#!/bin/sh
qemu-system-x86_64 -cdrom minimal_linux_live.iso