2012-12-11 09:14:19 +00:00
|
|
|
# Copyright 2012 Hewlett-Packard Development Company, L.P.
|
|
|
|
# Copyright (c) 2012 NTT DOCOMO, INC.
|
|
|
|
#
|
|
|
|
# All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License. You may obtain
|
|
|
|
# a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
|
2012-11-09 18:18:08 +00:00
|
|
|
function fullpath() {
|
|
|
|
local f=$1
|
|
|
|
if [ "${f#/}" = "$f" ]; then
|
|
|
|
echo `pwd`/"$f"
|
|
|
|
else
|
|
|
|
echo "$f"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function cleanup () {
|
|
|
|
rm -rf "$TMP_BUILD_DIR"
|
|
|
|
}
|
|
|
|
|
|
|
|
function ensure_binaries() {
|
|
|
|
BINARY_DEPS="${BUSYBOX}"
|
2012-11-30 20:47:57 +00:00
|
|
|
for _FLVR in ${RAMDISK_ELEMENT} ; do
|
|
|
|
_FILE="${ELEMENTS_DIR}/${_FLVR}/binary-deps"
|
2012-11-09 18:18:08 +00:00
|
|
|
if [ -a $_FILE ]; then
|
|
|
|
for _LINE in $(cat $_FILE) ; do
|
|
|
|
BINARY_DEPS="${BINARY_DEPS} $_LINE"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
for _BIN in $BINARY_DEPS ; do
|
2013-02-12 07:40:26 +00:00
|
|
|
_LOCATION=$(which "$_BIN" || echo "")
|
2012-11-09 18:18:08 +00:00
|
|
|
if [ -z "$_LOCATION" ]; then
|
|
|
|
echo "$_BIN is not found in your PATH" 1>&2
|
|
|
|
echo "Please install it on your system"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
export BINARY_DEPS
|
|
|
|
}
|
|
|
|
|
|
|
|
function create_base () {
|
|
|
|
echo "Creating base system"
|
|
|
|
|
|
|
|
mkdir -p "$TMP_MOUNT_PATH/bin"
|
|
|
|
ln -s bin "$TMP_MOUNT_PATH/sbin"
|
|
|
|
mkdir -p "$TMP_MOUNT_PATH/lib"
|
|
|
|
ln -s lib "$TMP_MOUNT_PATH/lib64"
|
|
|
|
mkdir -p "$TMP_MOUNT_PATH/lib/modules"
|
|
|
|
mkdir -p "$TMP_MOUNT_PATH/etc"
|
|
|
|
mkdir -p "$TMP_MOUNT_PATH/etc/udev"
|
2012-11-20 22:04:40 +00:00
|
|
|
# cjk adding for discovery support
|
|
|
|
mkdir -p "$TMP_MOUNT_PATH/var/lib/dhcp"
|
|
|
|
mkdir -p "$TMP_MOUNT_PATH/var/run"
|
|
|
|
|
2012-11-29 03:28:14 +00:00
|
|
|
mkdir -p "$TMP_MOUNT_PATH/lib/udev/rules.d"
|
|
|
|
cp -a "$LIB_UDEV/rules.d/50-firmware.rules" "$TMP_MOUNT_PATH/lib/udev/rules.d"
|
|
|
|
cp -a "$LIB_UDEV/rules.d/80-drivers.rules" "$TMP_MOUNT_PATH/lib/udev/rules.d"
|
|
|
|
cp -a "$LIB_UDEV/firmware" "$TMP_MOUNT_PATH/lib/udev"
|
2012-11-20 22:04:40 +00:00
|
|
|
# cjk adding for hwdiscovery support
|
|
|
|
cp "/sbin/dhclient-script" "$TMP_MOUNT_PATH/sbin"
|
2012-11-09 18:18:08 +00:00
|
|
|
|
|
|
|
mkdir -p "$TMP_MOUNT_PATH/etc/modprobe.d"
|
|
|
|
echo "blacklist evbug" > "$TMP_MOUNT_PATH/etc/modprobe.d/blacklist.conf"
|
|
|
|
|
2012-11-20 22:04:40 +00:00
|
|
|
# cjk adding for hwdiscovery support
|
|
|
|
touch "$TMP_MOUNT_PATH/etc/fstab"
|
|
|
|
|
2012-11-09 18:18:08 +00:00
|
|
|
mkdir -p "$TMP_MOUNT_PATH/etc/udev"
|
|
|
|
cat >"$TMP_MOUNT_PATH/etc/udev/udev.conf" <<EOF
|
2012-11-20 22:04:40 +00:00
|
|
|
|
2012-11-09 18:18:08 +00:00
|
|
|
udev_root="/dev"
|
|
|
|
udev_rules="/lib/udev/rules.d"
|
|
|
|
udev_log="no"
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
function populate_lib () {
|
|
|
|
echo "Populating /lib"
|
|
|
|
|
|
|
|
libs=
|
2012-11-29 03:28:14 +00:00
|
|
|
for i in "$BUSYBOX" "$LIB_UDEV/firmware" bash lsmod modprobe udevd udevadm wget reboot shutdown $BINARY_DEPS ; do
|
2012-11-09 18:18:08 +00:00
|
|
|
if "$BUSYBOX" --list | grep "^$i\$" >/dev/null; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
path=`which $i 2>/dev/null` || path=$i
|
|
|
|
if ! [ -x "$path" ]; then
|
|
|
|
echo "$i is not found in PATH" 2>&1
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
cp -L "$path" "$TMP_MOUNT_PATH/bin/"
|
|
|
|
if l=`ldd "$path"`; then
|
|
|
|
l=$( echo "$l" | grep '/' | tr "\t" " " )
|
|
|
|
l=$( echo "$l" | sed 's/^.* => \([^ ]*\).*$/\1/' )
|
|
|
|
l=$( echo "$l" | sed 's/^ *\([^ ]*\) *(0x[0-9a-f]*)/\1/' )
|
|
|
|
l=$( echo "$l" | tr " " "\n" )
|
|
|
|
libs=$( printf "%s\n%s\n" "$l" "$libs" | sort | uniq )
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
cp $libs "$TMP_MOUNT_PATH/lib/"
|
|
|
|
|
|
|
|
cp -a "$MODULE_DIR" "$TMP_MOUNT_PATH/lib/modules/$KERNEL_VERSION"
|
|
|
|
cp -a "$FIRMWARE_DIR" "$TMP_MOUNT_PATH/lib/firmware"
|
|
|
|
}
|
|
|
|
|
|
|
|
function populate_busybox () {
|
|
|
|
echo "Creating symlinks for busybox binaries"
|
|
|
|
|
|
|
|
for i in $( "$BUSYBOX" --list ); do
|
|
|
|
if [ -f "$TMP_MOUNT_PATH/bin/$i" ]; then
|
|
|
|
echo "skip $i"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
ln -s busybox "$TMP_MOUNT_PATH/bin/$i"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
function populate_init () {
|
|
|
|
echo "Installing init"
|
|
|
|
cp "$INIT" "$TMP_MOUNT_PATH/init"
|
|
|
|
chmod +x $TMP_MOUNT_PATH/init
|
|
|
|
for F in "$FUNCTIONS_D"/* ; do
|
|
|
|
cp "$F" "$TMP_MOUNT_PATH"
|
|
|
|
done
|
2012-11-09 21:48:41 +00:00
|
|
|
|
2012-11-30 20:47:57 +00:00
|
|
|
# Append /init with any element fragments that are present
|
|
|
|
for _FLVR in ${RAMDISK_ELEMENT} ; do
|
|
|
|
_FILE="${ELEMENTS_DIR}/${_FLVR}/init"
|
2012-11-09 21:48:41 +00:00
|
|
|
if [ -a $_FILE ]; then
|
|
|
|
cat >>$TMP_MOUNT_PATH/init <<EOF
|
|
|
|
|
|
|
|
# init fragment from ${_FLVR}
|
|
|
|
EOF
|
|
|
|
cat <$_FILE >>$TMP_MOUNT_PATH/init
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# Add our final steps to /init
|
|
|
|
cat <${INIT}-end >>$TMP_MOUNT_PATH/init
|
2012-11-09 18:18:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function finalise_image () {
|
|
|
|
echo "Finalising image"
|
|
|
|
(cd "$TMP_MOUNT_PATH"; find . | cpio -o -H newc | gzip > "$TMP_IMAGE_PATH" )
|
|
|
|
}
|
|
|
|
|
2012-11-12 16:56:08 +00:00
|
|
|
function populate_udev () {
|
|
|
|
echo "Installing udev rules"
|
|
|
|
|
2012-11-30 20:47:57 +00:00
|
|
|
for _FLVR in ${RAMDISK_ELEMENT} ; do
|
|
|
|
_DIR="${ELEMENTS_DIR}/${_FLVR}/udev"
|
2012-11-12 16:56:08 +00:00
|
|
|
if [ -d $_DIR ]; then
|
|
|
|
find $_DIR -type f -exec cp -v {} $TMP_MOUNT_PATH/lib/udev/rules.d/ \;
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
|