-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathcreate_disk.sh
executable file
·87 lines (66 loc) · 2.12 KB
/
create_disk.sh
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
#!/bin/bash
# Copyright 2020 Google LLC
#
# 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.
if [[ ${EUID} -ne 0 ]]; then
echo "This script must be run as root."
exit 1
fi
sdcard_file=${1}
working_dir=${2}
if [ -z ${sdcard_file} ]; then
echo "Needs name of sdcard file."
exit 2
fi
if [ -z ${working_dir} ]; then
echo "Working directory path not specified."
exit 3
fi
dd if=/dev/zero of=${sdcard_file} bs=1G count=1
lodev=$(losetup --show -f ${sdcard_file})
echo "Loopback device: ${lodev}"
sfdisk ${lodev} < sdcard_template
partprobe ${lodev}
# SPL with U-Boot.
echo "==== Writing spl with u-boot. ===="
dd if=${working_dir}/u-boot/u-boot-with-spl.sfp of=${lodev}p3 bs=64k seek=0
echo "==== Done writing spl ===="
echo "Making fat system."
mkfs -t vfat ${lodev}p1
echo "Making ext4 system."
mkfs.ext4 ${lodev}p2
echo "Mounting file systems."
mkdir -p fat ext4
mount ${lodev}p1 fat
mount ${lodev}p2 ext4
echo "Copying rootfs."
cd ext4
tar -xf ${working_dir}/rootfs.tar.bz2
cd ..
echo "Copying kernel."
cp ${working_dir}/linux/arch/arm/boot/zImage fat/
echo "Copying device tree."
cp ${working_dir}/u-boot/arch/arm/dts/socfpga_cyclone5_de10_nano.dtb fat/
echo "Creating extlinux."
mkdir -p fat/extlinux
echo "LABEL Linux Default" > fat/extlinux/extlinux.conf
echo " KERNEL ../zImage" >> fat/extlinux/extlinux.conf
echo " FDT ../socfpga_cyclone5_de10_nano.dtb" >> fat/extlinux/extlinux.conf
echo " APPEND root=/dev/mmcblk0p2 rw rootwait earlyprintk console=ttyS0,115200n8" >> fat/extlinux/extlinux.conf
echo "Unmounting filesystems."
umount fat
umount ext4
rmdir fat
rmdir ext4
echo "Deleting loopback device ${lodev}"
losetup -d ${lodev}