Browse Source

Cleaned target/share/initramfs/build.sh, and introduced target/share/initramfs.in library for reusable functions

karasz/new-early
Alejandro Mery 17 years ago
parent
commit
a8719e9fab
2 changed files with 100 additions and 27 deletions
  1. +76
    -0
      target/share/initramfs.in
  2. +24
    -27
      target/share/initramfs/build.sh

+ 76
- 0
target/share/initramfs.in

@ -0,0 +1,76 @@
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: target/share/initramfs.in
# Copyright (C) 2007 The OpenSDE Project
#
# More information can be found in the files COPYING and README.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. A copy of the
# GNU General Public License can be found in the file COPYING.
# --- SDE-COPYRIGHT-NOTE-END ---
# functions
#
# list the packages active for stage 1
initramfs_list_stage1() {
grep '^X .1' $base/config/$config/packages | cut -d' ' -f5
}
# install a package based on the flist and a given filter
initramfs_install_flist() {
local pkg_name="$1" sandbox="$2" rootfs="$3"
local flist="$sandbox/var/adm/flists/$pkg_name"
shift 3
sed -e '/ var\/adm/ d;' "$@" "$flist" | cut -f2- -d' ' |
tar -C "$sandbox/" -cf- --no-recursion --files-from=- |
tar -C "$rootfs" -xf-
}
# apply an overlay
initramfs_install_overlay() {
local overlaydir="$1" rootfs="$2"
local file= source= target= ext= mode=
for file in $overlaydir/*; do
source="${file##*/}"
ext="${file##*.}"
case "$ext" in
sh|exec|txt|patch)
case "$ext" in
sh|exec) mode='exec' ;;
*) mode="$ext" ;;
esac
target="$( echo ${source%.$ext} | tr '_%' '/_' )"
;;
*) continue ;;
esac
case "$mode" in
exec|txt)
echo_status "injecting $target ($mode)"
cp -f "$file" "$rootfs/$target"
[ "$mode" != "exec" ] || chmod +x "$rootfs/$target"
;;
patch)
echo_status "$(patch -p1 -d "${rootfs}" 2>&1 < $file )"
;;
esac
done
}
# weak functions
#
# should this package be extracted by flist or not?
# initramfs_install <pkg_name> <sandbox> <rootfs>
initramfs_install() { true; }
# what arguments should it pass to sed to filter the flist?
# initramfs_install_pattern <pkg_name> <default_patterns>
initramfs_install_pattern() { shift; echo "$@"; }

+ 24
- 27
target/share/initramfs/build.sh

@ -19,53 +19,49 @@ initrddir="$build_toolchain/initrd"
rm -rf "$initrddir" rm -rf "$initrddir"
mkdir -p "$initrddir" mkdir -p "$initrddir"
INITRD_POSTFLIST_HOOK=
# Hooks
#
INITRAMFS_POSTINSTALL_HOOK=
INITRAMFS_POSTOVERLAY_HOOK=
INITRD_FLIST_PACKAGES=
INITRD_FLIST_PATTERN="-e '/\.\(h\|o\|a\|a\..*\|la\|pc\)$/d;' -e '/ usr\/share\/\(doc\|info\|man\)\//d;'"
INITRD_EMPTY_PATTERN="-e '/\.\/lib\/udev\/devices\//d;'"
# Lists
#
INITRAMFS_INSTALL_PACKAGES=
INITRAMFS_INSTALL_PATTERN="-e '/\.\(h\|o\|a\|a\..*\|la\|pc\)$/d;' -e '/ usr\/share\/\(doc\|info\|man\)\//d;'"
# weak function, should this package be extracted by flist or not?
initrd_flist_install_filter() { true; }
INITRAMFS_EMPTY_PATTERN="-e '/\.\/lib\/udev\/devices\//d;'"
# source target specific code
# source library, and the target specific overlay
# #
. "target/share/initramfs.in"
if [ -f target/$target/build-initramfs.in ]; then if [ -f target/$target/build-initramfs.in ]; then
. target/$target/build-initramfs.in . target/$target/build-initramfs.in
fi fi
# install what was flisted for stage 1 packages, use $INITRD_FLIST_PATTERN to skip files
# install what was flisted for stage 1 packages, use $INITRAMFS_INSTALL_PATTERN to skip files
# #
if [ -z "$INITRD_FLIST_PACKAGES" ]; then
INITRD_FLIST_PACKAGES=$( grep '^X .1' $base/config/$config/packages | cut -d' ' -f5 | tr '\n' ' ' )
fi
[ -n "$INITRAMFS_INSTALL_PACKAGES" ] || INITRAMFS_INSTALL_PACKAGES=$( initramfs_list_stage1 )
echo_status "Populating ${initrddir#$base/} ..." echo_status "Populating ${initrddir#$base/} ..."
for pkg_name in $INITRD_FLIST_PACKAGES; do
if initrd_flist_install_filter $pkg_name; then
for pkg_name in $INITRAMFS_INSTALL_PACKAGES; do
if initramfs_install "$pkg_name" "build/$SDECFG_ID" "$initrddir"; then
echo_status "- $pkg_name" echo_status "- $pkg_name"
flist="build/${SDECFG_ID}/var/adm/flists/$pkg_name"
eval "sed -e '/ var\/adm/ d;' $INITRD_FLIST_PATTERN '$flist'" | cut -f2- -d' ' |
tar -C "build/${SDECFG_ID}/" -cf- --no-recursion --files-from=- |
tar -C "$initrddir" -xf-
eval "initramfs_install_flist '$pkg_name' 'build/$SDECFG_ID' '$initrddir' $( initramfs_install_pattern "$pkg_name" "$INITRAMFS_INSTALL_PATTERN" )"
fi fi
done done
# hook
# hook $INITRAMFS_POSTINSTALL_HOOK
# #
[ -z "$INITRD_POSTFLIST_HOOK" ] || eval "$INITRD_POSTFLIST_HOOK"
[ -z "$INITRAMFS_POSTINSTALL_HOOK" ] || eval "$INITRD_POSTINSTALL_HOOK"
if [ -r "target/$target/init.sh" ]; then
echo_status "Copying target's /init script."
cp "target/$target/init.sh" "${initrddir}/init"
chmod +x "${initrddir}/init"
fi
# Apply overlay
[ ! -d "target/$target/initramfs" ] || initramfs_install_overlay "target/$target/initramfs" "$initrddir"
# remove empty folder, use $INITRD_EMPTY_PATTERN to skip folders
# remove empty folder, use $INITRAMFS_EMPTY_PATTERN to skip folders
# #
echo_status "Removing empty folders ..." echo_status "Removing empty folders ..."
( cd "$initrddir"; find . -type d ) | tac | eval "sed -e '/\.\/\(dev\|sys\|proc\|mnt\|tmp\)\$/d;' $INITRD_EMPTY_PATTERN" | while read folder; do
( cd "$initrddir"; find . -type d ) | tac | eval "sed -e '/\.\/\(dev\|sys\|proc\|mnt\|tmp\)\$/d;' $INITRAMFS_EMPTY_PATTERN" | while read folder; do
count=$( find "${initrddir}/$folder" | wc -l ) count=$( find "${initrddir}/$folder" | wc -l )
if [ $count -eq 1 ]; then if [ $count -eq 1 ]; then
@ -74,7 +70,8 @@ echo_status "Removing empty folders ..."
fi fi
done done
# sanity check
# sanity checks
#
[ -x "${initrddir}/init" ] || echo_warning "This image is missing an /init file, it wont run." [ -x "${initrddir}/init" ] || echo_warning "This image is missing an /init file, it wont run."
for x in ${initrddir}/{,usr/}{sbin,bin}/* ${initrddir}/init ${initrddir}/lib/udev/*; do for x in ${initrddir}/{,usr/}{sbin,bin}/* ${initrddir}/init ${initrddir}/lib/udev/*; do
[ -e "$x" ] || continue [ -e "$x" ] || continue

Loading…
Cancel
Save