forked from NVIDIA/tegra-rootfs-scripts
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprepare-rootfs
executable file
·103 lines (85 loc) · 3.62 KB
/
prepare-rootfs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env bash
set -e
. scripts/env.sh
sudo_write()
{
echo $1 |sudo tee $2 >/dev/null
}
# Run a command into the chrooted target FS using qemu, by adding a binfmt_misc
run_in_qemu()
{
# Do we have binfmt_misc support?
if [ ! -f /proc/sys/fs/binfmt_misc/status ]; then
# Nope, try to mount it maybe?
sudo mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
if [ ! -f /proc/sys/fs/binfmt_misc/status ]; then
error "This script requires binfmt_misc support to run ARM binaries under qemu"
fi
fi
# Save current active status and enable
local curstatus=0
if [ $(cat /proc/sys/fs/binfmt_misc/status) = "enabled" ]; then
curstatus=1
fi
sudo_write 1 /proc/sys/fs/binfmt_misc/status
# Add new rule to run ARM binaries using our installed qemu
if [ ! -f /proc/sys/fs/binfmt_misc/arm-qemu-build-rootfs-tmp ]; then
sudo_write ':arm-qemu-build-rootfs-tmp:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-arm-static:' /proc/sys/fs/binfmt_misc/register
fi
# Run the command
sudo chroot $SYSROOT /usr/bin/env -i PATH="/sbin:/usr/sbin:/bin:/usr/bin" TERM="$TERM" $*
# Remove rule, restore status
sudo_write -1 /proc/sys/fs/binfmt_misc/arm-qemu-build-rootfs-tmp
sudo_write $curstatus /proc/sys/fs/binfmt_misc/status
}
if [ ! -e $SYSROOT ]; then
error "Directory $SYSROOT does not exist. Either link to your $DISTRO root FS, or run ./scripts/download-rootfs to download a fresh image."
exit 1
fi
if [ ! -f "$SYSROOT/usr/bin/qemu-arm-static" ]; then
status "Installing qemu-arm-static binary into target FS..."
QEMUDEB=$(mktemp)
wget http://snapshot.debian.org/archive/debian/20141030T220503Z/pool/main/q/qemu/qemu-user-static_2.1%2Bdfsg-5%2Bb1_i386.deb -O $QEMUDEB
${CROSS_COMPILE}ar p $QEMUDEB data.tar.xz|sudo tar xJf - -C $SYSROOT ./usr/bin/qemu-arm-static
rm -f $QEMUDEB
fi
# Fix target's resolv.conf so we can download packages
if [ ! -f "$SYSROOT/etc/resolv.conf.rootfs-nvbackup" ]; then
sudo mv $SYSROOT/etc/resolv.conf $SYSROOT/etc/resolv.conf.rootfs-nvbackup
fi
sudo cp /etc/resolv.conf $SYSROOT/etc/resolv.conf
. scripts/distro/prepare-$DISTRO
# Restore target's resolv.conf now that packages are installed"
sudo rm -f $SYSROOT/etc/resolv.conf
sudo mv $SYSROOT/etc/resolv.conf.rootfs-nvbackup $SYSROOT/etc/resolv.conf
if [ ! -d $SYSROOT/$NV_PREFIX ]; then
status "Creating $NV_PREFIX"
sudo mkdir $SYSROOT/$NV_PREFIX
sudo chown -R $USER $SYSROOT/$NV_PREFIX
fi
status "Fixing permissions in /boot, /lib/modules and /lib/firmware"
sudo mkdir -p $SYSROOT/boot
sudo chown -R $USER $SYSROOT/boot
sudo mkdir -p $SYSROOT/lib/modules
sudo chown -R $USER $SYSROOT/lib/modules
sudo mkdir -p $SYSROOT/lib/firmware
sudo chown -R $USER $SYSROOT/lib/firmware
status "Adding environment to /etc/profile.d/nouveau.sh"
cat <<EOF |sudo tee $SYSROOT/etc/profile.d/nouveau.sh >/dev/null
NV_PREFIX="$NV_PREFIX"
export PATH="\$NV_PREFIX/bin:\$PATH"
export LD_LIBRARY_PATH="\$NV_PREFIX/lib:\$LD_LIBRARY_PATH"
export PKG_CONFIG_PATH="\$NV_PREFIX/lib/pkgconfig:\$PKG_CONFIG_PATH"
EOF
status "Adding a serial console service..."
cat <<EOF |sudo tee $SYSROOT/etc/init/ttyS0.conf >/dev/null
description "Get a getty on ttyS0"
start on stopped rc RUNLEVEL=[2345] and (
not-container or
container CONTAINER=lxc or
container CONTAINER=lxc-libvirt)
stop on runlevel [!2345]
respawn
exec /sbin/getty -a ubuntu -L 115200 ttyS0
EOF
status "Target FS ready to compile the open graphics stack!"