#!/bin/bash # Copyright (c) 2014-2015, NVIDIA CORPORATION. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # * Neither the name of NVIDIA CORPORATION nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY # OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. DATE="`date +\"%T\"`" build_date=`date`; initrd_dir=/mnt/initrd; dhclient_flag="true"; count=0; echo "[ $DATE ] L4T initrd starts from here....."; #Mount procfs, devfs and sysfs mount -t proc proc /proc if [ $? -ne 0 ]; then echo "ERROR: mounting proc fail..."; exec /bin/bash; fi; mount -t devtmpfs none /dev if [ $? -ne 0 ]; then echo "ERROR: mounting dev fail..."; exec /bin/bash; fi; mount -t sysfs sysfs /sys if [ $? -ne 0 ]; then echo "ERROR: mounting sys fail..."; exec /bin/bash; fi; echo "[ $DATE ] L4T-INITRD BINGO Build DATE: $build_date"; rootdev=`cat /proc/cmdline | sed -e 's/.*root=\/dev\/\([abcdefklmnps012]*\).*/\1/'`; echo "[ $DATE ] Root device found: $rootdev"; if [[ "${rootdev}" == mmcblk0p* || "${rootdev}" == mmcblk1p* ]]; then if [ ! -e "/dev/${rootdev}" ]; then count=0; while [ ${count} -lt 50 ] do sleep 0.2; count=`expr $count + 1`; if [ -e "/dev/${rootdev}" ]; then break; fi done fi if [ -e "/dev/${rootdev}" ]; then echo "Rootdevice found: /dev/${rootdev}"; else echo "ERROR: ${rootdev} not found"; exec /bin/bash; fi mount /dev/${rootdev} /mnt/; if [ $? -ne 0 ]; then echo "ERROR: ${rootdev} mount fail..."; exec /bin/bash; fi; elif [[ "${rootdev}" == sd* ]]; then if [ ! -e "/dev/${rootdev}" ]; then while [ ${count} -lt 50 ] do sleep 0.2; count=`expr $count + 1`; if [ -e "/dev/${rootdev}" ]; then break; fi done fi if [ -e "/dev/${rootdev}" ]; then echo "Rootdevice found: /dev/${rootdev}"; else echo "ERROR: ${rootdev} not found"; exec /bin/bash; fi mount /dev/${rootdev} /mnt/; if [ $? -ne 0 ]; then echo "ERROR: ${rootdev} mount fail..."; exec /bin/bash; fi; elif [[ "${rootdev}" == "nfs" ]]; then eth_interface=`ifconfig -a | grep eth | awk '{print $1}'`; echo "[ $DATE ] Ethernet interfaces: $eth_interface"; for eth in ${eth_interface} do ipaddr=`ifconfig "$eth" | grep -A1 "$eth" | grep "inet addr" | sed 's/.*addr:\([0-9\.]*\) .*/\1/'`; echo "[ $DATE ] eth_interface is pointing to $eth and ipaddr: $ipaddr" if [[ "$ipaddr" =~ [0-9]*.[0-9]*.[0-9]*.[0-9]* ]]; then echo "[ $DATE ]: static ipaddr found: $ipaddr"; dhclient_flag="false"; break; fi while [ ${count} -lt 50 ] do sleep 0.2; ipaddr=`ifconfig "$eth" | grep -A1 "$eth" | grep "inet addr" | sed 's/.*addr:\([0-9\.]*\) .*/\1/'`; echo "[ $DATE ] eth_interface is pointing to $eth and ipaddr: $ipaddr" if [[ "$ipaddr" =~ [0-9]*.[0-9]*.[0-9]*.[0-9]* ]]; then echo "[ $DATE ]: static ipaddr found: $ipaddr"; dhclient_flag="false"; break; fi count=`expr $count + 1`; done if [ "$dhclient_flag" == "false" ]; then break; fi done if [ "$dhclient_flag" == "true" ]; then for eth in ${eth_interface} do echo "[ $DATE ] eth_interface is pointing to $eth"; timeout 8s /sbin/dhclient $eth; if [ $? -eq 0 ]; then break; fi; done if [ $? -ne 0 ]; then echo "[ $DATE ] ERROR: dhclient fail..."; exec /bin/bash; fi; fi; nfsroot_path=`cat /proc/cmdline | sed -e 's/.*nfsroot=\([^ ]*\) .*/\1 /'`; # JCK: mount -t nfs -o nolock $nfsroot_path /mnt/; mount -t nfs -v -o nolock $nfsroot_path /mnt/; if [ $? -ne 0 ]; then echo "ERROR: NFS mount fail..."; exec /bin/bash; fi; else echo "[ $DATE ] No root-device: Mount failed" exec /bin/bash; fi echo "[ $DATE ] Rootfs mounted over ${rootdev}"; mount -o bind /proc /mnt/proc; mount -o bind /sys /mnt/sys; mount -o bind /dev/ /mnt/dev; cd /mnt; cp /etc/resolv.conf etc/resolv.conf echo "[ $DATE ] Switching from initrd to actual rootfs"; exec chroot . /sbin/init 2;