Commit 55d7a9b2 authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

1. initramfs 2. parallel make for initramfs

parent 7a705d48
# Simple initramfs image. Mostly used for live images.
DESCRIPTION = "Small image capable of booting a device. The kernel includes \
the Minimal RAM-based Initial Root Filesystem (initramfs), which finds the \
first 'init' program more efficiently."
PACKAGE_INSTALL = "initramfs-live-boot ${VIRTUAL-RUNTIME_base-utils} udev base-passwd ${ROOTFS_BOOTSTRAP_INSTALL}"
# Do not pollute the initrd image with rootfs features
IMAGE_FEATURES = ""
export IMAGE_BASENAME = "core-image-elphel393-initramfs"
IMAGE_LINGUAS = ""
LICENSE = "MIT"
IMAGE_FSTYPES = "${INITRAMFS_FSTYPES}"
inherit core-image
IMAGE_ROOTFS_SIZE = "8192"
BAD_RECOMMENDATIONS += "busybox-syslog"
...@@ -8,6 +8,7 @@ IMAGE_INSTALL = "packagegroup-core-boot ${ROOTFS_PKGMANAGE_BOOTSTRAP} ${CORE_IMA ...@@ -8,6 +8,7 @@ IMAGE_INSTALL = "packagegroup-core-boot ${ROOTFS_PKGMANAGE_BOOTSTRAP} ${CORE_IMA
IMAGE_INSTALL_append = "u-boot-ezynq" IMAGE_INSTALL_append = "u-boot-ezynq"
IMAGE_INSTALL_append += " \ IMAGE_INSTALL_append += " \
sudo \ sudo \
gcc \
python-core \ python-core \
python-numpy \ python-numpy \
python-argparse \ python-argparse \
......
#!/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
ROOT_MOUNT="/rootfs"
ROOT_IMAGE="rootfs.img"
MOUNT="/bin/mount"
UMOUNT="/bin/umount"
ISOLINUX=""
ROOT_DISK=""
# Copied from initramfs-framework. The core of this script probably should be
# turned into initramfs-framework modules to reduce duplication.
udev_daemon() {
OPTIONS="/sbin/udev/udevd /sbin/udevd /lib/udev/udevd /lib/systemd/systemd-udevd"
for o in $OPTIONS; do
if [ -x "$o" ]; then
echo $o
return 0
fi
done
return 1
}
_UDEV_DAEMON=`udev_daemon`
early_setup() {
mkdir -p /proc
mkdir -p /sys
mount -t proc proc /proc
mount -t sysfs sysfs /sys
mount -t devtmpfs none /dev
# support modular kernel
modprobe isofs 2> /dev/null
mkdir -p /run
mkdir -p /var/run
$_UDEV_DAEMON --daemon
udevadm trigger --action=add
}
read_args() {
[ -z "$CMDLINE" ] && CMDLINE=`cat /proc/cmdline`
for arg in $CMDLINE; do
optarg=`expr "x$arg" : 'x[^=]*=\(.*\)'`
case $arg in
root=*)
ROOT_DEVICE=$optarg ;;
rootimage=*)
ROOT_IMAGE=$optarg ;;
rootfstype=*)
ROOT_FSTYPE=$optarg
modprobe $optarg 2> /dev/null ;;
# ubi.mtd=*)
# optarg_arr=${optarg//,/ }
# ROOT_UBIVOL=$optarg_arr[0]
# ;;
LABEL=*)
label=$optarg ;;
video=*)
video_mode=$arg ;;
vga=*)
vga_mode=$arg ;;
console=*)
if [ -z "${console_params}" ]; then
console_params=$arg
else
console_params="$console_params $arg"
fi ;;
debugshell*)
if [ -z "$optarg" ]; then
shelltimeout=30
else
shelltimeout=$optarg
fi
esac
done
}
boot_live_root() {
# Watches the udev event queue, and exits if all current events are handled
udevadm settle --timeout=3 --quiet
killall "${_UDEV_DAEMON##*/}" 2>/dev/null
# # Allow for identification of the real root even after boot
# mkdir -p ${ROOT_MOUNT}/media/realroot
# mount -n --move "/run/media/${ROOT_DISK}" ${ROOT_MOUNT}/media/realroot
# # Move the mount points of some filesystems over to
# # the corresponding directories under the real root filesystem.
# for dir in `awk '/\/dev.* \/run\/media/{print $2}' /proc/mounts`; do
# mkdir -p ${ROOT_MOUNT}/media/${dir##*/}
# mount -n --move $dir ${ROOT_MOUNT}/media/${dir##*/}
# done
mount -n --move /proc ${ROOT_MOUNT}/proc
mount -n --move /sys ${ROOT_MOUNT}/sys
mount -n --move /dev ${ROOT_MOUNT}/dev
cd $ROOT_MOUNT
# busybox switch_root supports -c option
exec switch_root -c /dev/console $ROOT_MOUNT /sbin/init $CMDLINE ||
fatal "Couldn't switch_root, dropping to shell"
}
fatal() {
echo $1 >$CONSOLE
echo >$CONSOLE
exec sh
}
early_setup
[ -z "$CONSOLE" ] && CONSOLE="/dev/console"
read_args
#echo "Not waiting for removable media..."
# C=0
# while true
# do
# echo "testing C= $C"
# echo "break immediately"
# break
# for i in `ls /run/media 2>/dev/null`; do
# if [ -f /run/media/$i/$ROOT_IMAGE ] ; then
# found="yes"
# ROOT_DISK="$i"
# break
# elif [ -f /run/media/$i/isolinux/$ROOT_IMAGE ]; then
# found="yes"
# ISOLINUX="isolinux"
# ROOT_DISK="$i"
# break
# fi
# done
# if [ "$found" = "yes" ]; then
# break;
# fi
# # don't wait for more than $shelltimeout seconds, if it's set
# if [ -n "$shelltimeout" ]; then
# echo -n " " $(( $shelltimeout - $C ))
# if [ $C -ge $shelltimeout ]; then
# echo "..."
# echo "Mounted filesystems"
# mount | grep media
# echo "Available block devices"
# cat /proc/partitions
# fatal "Cannot find $ROOT_IMAGE file in /run/media/* , dropping to a shell "
# fi
# C=$(( C + 1 ))
# fi
# sleep 1
# done
# Try to mount the root image read-write and then boot it up.
# This function distinguishes between a read-only image and a read-write image.
# In the former case (typically an iso), it tries to make a union mount if possible.
# In the latter case, the root image could be mounted and then directly booted up.
mount_and_boot() {
mkdir $ROOT_MOUNT
#mknod /dev/loop0 b 7 0 2>/dev/null
#if [ "$ROOT_FSTYPE" = "ubifs" ]; then
#unlock flash ? - driver should have taken care of this
# ubiattach won't be found and there's no need because kernel already knows
#ubiattach /dev/ubi_ctrl -m $ROOT_UBIVOL
#fi
if ! mount -t $ROOT_FSTYPE -o rw,noatime $ROOT_DEVICE $ROOT_MOUNT ; then
fatal "Could not mount rootfs device (not $ROOT_FSTYPE?)"
fi
# always 'overlay'
TMP=/var/volatile/tmp
mkdir -p /var/volatile
mount -t tmpfs tmpfs /var/volatile
mkdir -p $TMP/rootfs.ro $TMP/rootfs.rw
if ! mount -n --move $ROOT_MOUNT $TMP/rootfs.ro; then
rm -rf $TMP/rootfs.ro $TMP/rootfs.rw
fatal "Could not move rootfs mount point"
else
mount -t tmpfs -o rw,noatime,mode=755 tmpfs $TMP/rootfs.rw
mkdir -p $TMP/rootfs.rw/upperdir $TMP/rootfs.rw/work
mount -t overlay overlay -o "lowerdir=$TMP/rootfs.ro,upperdir=$TMP/rootfs.rw/upperdir,workdir=$TMP/rootfs.rw/work" $ROOT_MOUNT
# Assuming $ROOT_MOUNT/var/volatile exists
mount --move /var/volatile $ROOT_MOUNT/var/volatile
# Everything is already moved with /var/volatile
#mkdir -p $ROOT_MOUNT/rootfs.ro $ROOT_MOUNT/rootfs.rw
#mount --move /rootfs.ro $ROOT_MOUNT/rootfs.ro
#mount --move /rootfs.rw $ROOT_MOUNT/rootfs.rw
fi
boot_live_root
#commenting out old lines
# mkdir $ROOT_MOUNT
# mknod /dev/loop0 b 7 0 2>/dev/null
#
# if ! mount -o rw,loop,noatime,nodiratime /run/media/$ROOT_DISK/$ISOLINUX/$ROOT_IMAGE $ROOT_MOUNT ; then
# fatal "Could not mount rootfs image"
# fi
#
# if touch $ROOT_MOUNT/bin 2>/dev/null; then
# # The root image is read-write, directly boot it up.
# boot_live_root
# fi
#
# # determine which unification filesystem to use
# union_fs_type=""
# if grep -q -w "overlay" /proc/filesystems; then
# union_fs_type="overlay"
# elif grep -q -w "aufs" /proc/filesystems; then
# union_fs_type="aufs"
# else
# union_fs_type=""
# fi
#
# # make a union mount if possible
# case $union_fs_type in
# "overlay")
# mkdir -p /rootfs.ro /rootfs.rw
# if ! mount -n --move $ROOT_MOUNT /rootfs.ro; then
# rm -rf /rootfs.ro /rootfs.rw
# fatal "Could not move rootfs mount point"
# else
# mount -t tmpfs -o rw,noatime,mode=755 tmpfs /rootfs.rw
# mkdir -p /rootfs.rw/upperdir /rootfs.rw/work
# mount -t overlay overlay -o "lowerdir=/rootfs.ro,upperdir=/rootfs.rw/upperdir,workdir=/rootfs.rw/work" $ROOT_MOUNT
# mkdir -p $ROOT_MOUNT/rootfs.ro $ROOT_MOUNT/rootfs.rw
# mount --move /rootfs.ro $ROOT_MOUNT/rootfs.ro
# mount --move /rootfs.rw $ROOT_MOUNT/rootfs.rw
# fi
# ;;
# "aufs")
# mkdir -p /rootfs.ro /rootfs.rw
# if ! mount -n --move $ROOT_MOUNT /rootfs.ro; then
# rm -rf /rootfs.ro /rootfs.rw
# fatal "Could not move rootfs mount point"
# else
# mount -t tmpfs -o rw,noatime,mode=755 tmpfs /rootfs.rw
# mount -t aufs -o "dirs=/rootfs.rw=rw:/rootfs.ro=ro" aufs $ROOT_MOUNT
# mkdir -p $ROOT_MOUNT/rootfs.ro $ROOT_MOUNT/rootfs.rw
# mount --move /rootfs.ro $ROOT_MOUNT/rootfs.ro
# mount --move /rootfs.rw $ROOT_MOUNT/rootfs.rw
# fi
# ;;
# "")
# mount -t tmpfs -o rw,noatime,mode=755 tmpfs $ROOT_MOUNT/media
# ;;
# esac
#
# # boot the image
# boot_live_root
}
# if [ "$label" != "boot" -a -f $label.sh ] ; then
# if [ -f /run/media/$i/$ISOLINUX/$ROOT_IMAGE ] ; then
# ./$label.sh $i/$ISOLINUX $ROOT_IMAGE $video_mode $vga_mode $console_params
# else
# fatal "Could not find $label script"
# fi
#
# # If we're getting here, we failed...
# fatal "Target $label failed"
# fi
mount_and_boot
FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
...@@ -28,6 +28,10 @@ export _MAKEFLAGS="-s -w -B KCFLAGS='-v'" ...@@ -28,6 +28,10 @@ export _MAKEFLAGS="-s -w -B KCFLAGS='-v'"
export BB_ENV_EXTRAWHITE="$BB_ENV_EXTRAWHITE _MAKEFLAGS" export BB_ENV_EXTRAWHITE="$BB_ENV_EXTRAWHITE _MAKEFLAGS"
EXTRA_OEMAKE = "${_MAKEFLAGS}" EXTRA_OEMAKE = "${_MAKEFLAGS}"
INITRAMFS_IMAGE = "core-image-elphel393-initramfs"
INITRAMFS_IMAGE_BUNDLE = "1"
#IMAGE_FSTYPES = "cpio.gz"
do_fetch_append() { do_fetch_append() {
if os.path.isdir("${DEV_DIR}"): if os.path.isdir("${DEV_DIR}"):
print("Found DEV_DIR, skipping cloning") print("Found DEV_DIR, skipping cloning")
...@@ -78,5 +82,36 @@ do_deploy_append(){ ...@@ -78,5 +82,36 @@ do_deploy_append(){
else else
echo "NOT 3 FOUND!" echo "NOT 3 FOUND!"
fi fi
#copy initramfs image over initramfsless image
if [ -f ${DEPLOYDIR}/${INITRAMFS_BASE_NAME}.bin ]; then
if [ -f ${DEPLOY_DIR_IMAGE}/${RLOC}/${PRODUCTION_KERNEL} ]; then
rm ${DEPLOY_DIR_IMAGE}/${RLOC}/${PRODUCTION_KERNEL}
fi
cp ${DEPLOYDIR}/${INITRAMFS_BASE_NAME}.bin ${DEPLOY_DIR_IMAGE}/${RLOC}/${PRODUCTION_KERNEL}
fi
done done
} }
# Override kernel_do_compile used by do_bundle_initramfs in kernel.bbclass
# Added ${PARALLEL_MAKE} only
kernel_do_compile() {
unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
# The $use_alternate_initrd is only set from
# do_bundle_initramfs() This variable is specifically for the
# case where we are making a second pass at the kernel
# compilation and we want to force the kernel build to use a
# different initramfs image. The way to do that in the kernel
# is to specify:
# make ...args... CONFIG_INITRAMFS_SOURCE=some_other_initramfs.cpio
if [ "$use_alternate_initrd" = "" ] && [ "${INITRAMFS_TASK}" != "" ] ; then
# The old style way of copying an prebuilt image and building it
# is turned on via INTIRAMFS_TASK != ""
copy_initramfs
use_alternate_initrd=CONFIG_INITRAMFS_SOURCE=${B}/usr/${INITRAMFS_IMAGE}-${MACHINE}.cpio
fi
oe_runmake ${KERNEL_IMAGETYPE_FOR_MAKE} ${PARALLEL_MAKE} ${KERNEL_ALT_IMAGETYPE} CC="${KERNEL_CC}" LD="${KERNEL_LD}" ${KERNEL_EXTRA_ARGS} $use_alternate_initrd
if test "${KERNEL_IMAGETYPE_FOR_MAKE}.gz" = "${KERNEL_IMAGETYPE}"; then
gzip -9c < "${KERNEL_IMAGETYPE_FOR_MAKE}" > "${KERNEL_OUTPUT}"
fi
}
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