-
Notifications
You must be signed in to change notification settings - Fork 12
/
create-wic.sh
executable file
·175 lines (134 loc) · 4.88 KB
/
create-wic.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash
#!/bin/bash
# Authors:
# Sai Sree Kartheek Adivi <[email protected]>
# LT Thomas <[email protected]>
# Chase Maupin
# Franklin Cooper Jr.
#
# create-img.sh v0.1
# This distribution contains contributions or derivatives under copyright
# as follows:
#
# Copyright (c) 2024, Texas Instruments Incorporated
# 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 Texas Instruments 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 AND CONTRIBUTORS
# "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 HOLDER 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.
# Force locale language to be set to English. This avoids issues when doing
# text and string processing.
export LANG=C
# Determine the absolute path to the executable
# EXE will have the PWD removed so we can concatenate with the PWD safely
PWD=`pwd`
EXE=`echo $0 | sed s=$PWD==`
EXEPATH="$PWD"/"$EXE"
clear
export topdir=$(git rev-parse --show-toplevel)
BUILD=$1
BUILDPATH=${topdir}/build/
cat << EOM
################################################################################
This script will create a flashable/bootable SD card image from the built
binaries.
The script must be run with root permissions and from the bin directory of
the SDK
Usage:
$ sudo ./create-wic.sh <build-id>
################################################################################
EOM
AMIROOT=`whoami | awk {'print $1'}`
if [ "$AMIROOT" != "root" ] ; then
echo " **** Error *** must run script with sudo"
echo ""
exit
fi
source ${topdir}/scripts/common.sh
validate_section "Build" ${BUILD} "${topdir}/builds.toml"
distro_codename=($(read_build_config ${BUILD} distro_codename))
bsp_version=($(read_bsp_config ${distro_codename} bsp_version))
if [ ! -f ${topdir}/build/${BUILD}/tisdk-debian-${BUILD}-${bsp_version}-boot.tar.xz ]; then
echo "Error: Boot partition tarball not found for ${BUILD}."
exit -1
fi
if [ ! -f ${topdir}/build/${BUILD}/tisdk-debian-${BUILD}-${bsp_version}-rootfs.tar.xz ]; then
echo "Error: RootFS partition tarball not found for ${BUILD}."
exit -1
fi
IMAGE=tisdk-debian-${BUILD}-${bsp_version}.wic
echo "Creating an empty image"
dd if=/dev/zero of=${BUILDPATH}/${BUILD}/${IMAGE} count=10485760 status=progress
sync ; sync
cat << END | fdisk ${BUILDPATH}/${BUILD}/${IMAGE}
o
n
p
+128M
t
c
a
n
p
w
END
echo "Mount the image"
LOOPDEV=$(losetup -fP ${BUILDPATH}/${BUILD}/${IMAGE} --show)
echo "Partitioning Boot"
mkfs.fat -F32 -a -v -I -n "BOOT" ${LOOPDEV}p1
echo "Partitioning RootFS"
mkfs.ext3 -F -L "rootfs" ${LOOPDEV}p2
echo "Mounting Boot Paritition"
mkdir -p ${BUILDPATH}/${BUILD}/temp/ ; cd ${BUILDPATH}/${BUILD}/temp/
mkdir img_boot
mount ${LOOPDEV}p1 ./img_boot
echo "Copy Boot Partition files"
cd ./img_boot
tar -xf ${BUILDPATH}/${BUILD}/tisdk-debian-${BUILD}-${bsp_version}-boot.tar.xz
mv tisdk-debian-${BUILD}-${bsp_version}-boot/* ./
rmdir tisdk-debian-${BUILD}-${bsp_version}-boot
echo "Sync and Unmount Boot Partition"
cd ${BUILDPATH}/${BUILD}/temp/
sync ; sync
umount ./img_boot ; rmdir ./img_boot
echo "Mounting RootFS Paritition"
mkdir -p ${BUILDPATH}/${BUILD}/temp/ ; cd ${BUILDPATH}/${BUILD}/temp/
mkdir img_rootfs
mount ${LOOPDEV}p2 ./img_rootfs
echo "Copy RootFS Partition files"
cd ./img_rootfs
tar -xf ${BUILDPATH}/${BUILD}/tisdk-debian-${BUILD}-${bsp_version}-rootfs.tar.xz
mv tisdk-debian-${BUILD}-${bsp_version}-rootfs/* ./
rmdir tisdk-debian-${BUILD}-${bsp_version}-rootfs
echo "Sync and Unmount RootFS Partition"
cd ${BUILDPATH}/${BUILD}/temp/
sync ; sync
umount ./img_rootfs ; rmdir ./img_rootfs
echo "Unmount the image"
losetup -d ${LOOPDEV}
echo "Compress the image"
cd ${BUILDPATH}/${BUILD}/
xz -T 0 ${IMAGE}
echo "Cleanup"
rm -rf ${BUILDPATH}/${BUILD}/temp
echo "Done"