-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimage_from_dir
More file actions
executable file
·500 lines (431 loc) · 13.3 KB
/
image_from_dir
File metadata and controls
executable file
·500 lines (431 loc) · 13.3 KB
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
#!/bin/bash
# **********************************************
# Creates odroid C1 image from local directory *
# created with "create_odroid_image *
# **********************************************
if [ "$(id -u)" != "0" ]; then
echo "Script must be run as root !"
exit 0
fi
echo ""
date
echo "Creating Ubuntu/Debian SD Card image for Odroid-C1"
echo "=================================================="
echo ""
_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
cd $_DIR
idir=$1
sdcard="$1.img"
_boot_on_ext4="$2"
if [ "${_boot_on_ext4}" = "" ]; then
_boot_on_ext4="no"
fi
# ===================================================
if [ "${1}" = "" ]; then
echo "Directory not specified."
echo "USAGE: image_from_dir <directory> [yes|no]"
echo " yes|no - create or not ext4 only system"
exit 0
fi
if [ ! -d $idir ]; then
echo "Directory not found."
echo "USAGE: image_from_dir <directory> [yes|no]"
echo " yes|no - create or not ext4 only system"
exit 0
fi
# ===================================================
# =====================================================
# ==== P A R A M E T E R S ============================
# =====================================================
# *****************************************************
# Set FAT partition size *
# *****************************************************
fatsize=32
# *****************************************************
# Linux partition size IS CALCULATED *
_ext4size=`du -s $1 | awk '{print $1}'`
ext4sizeMB=$(expr $_ext4size / 1024)
ext4size=$(expr $ext4sizeMB / 2 + $ext4sizeMB)
# *****************************************************
# ******************************************************
# Linux partition will be formated as btrfs filesystem *
# if _btrfs="yes", otherwyse as ext4 *
# ******************************************************
_btrfs="no"
# *****************************************************
# Set path to odroid u-boot files *
# *****************************************************
BL1="uboot/bl1.bin.hardkernel"
UBOOT="uboot/u-boot.bin"
# *****************************************************
# If you want to xz compress image and make md5sum *
# set _compress="yes" *
# *****************************************************
_compress="no"
# ^^^^ P A R A M E T E R S ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
if [ ! -f $BL1 ]; then
echo "Error: $BL1 is not exist."
exit 1
fi
if [ ! -f $UBOOT ]; then
echo "Error: $UBOOT is not exist."
exit 1
fi
if [ "${_btrfs}" = "yes" ]; then
_boot_on_ext4="no"
fi
odir="_extdir"
bootdir="_fatdir"
# === Show info ===============
echo " from: $idir"
echo " to: $sdcard"
echo "ext4boot: $_boot_on_ext4"
echo " btrfs: $_btrfs"
echo "dir size: $ext4sizeMB"
echo "img size: $ext4size"
echo ""
# ==============================================
# PREPARE SD CARD IMAGE FOR ODROID - UBUNTU BOOT
# ==============================================
# remove old image files
rm ${sdcard} > /dev/null 2>&1
rm ${sdcard}1 > /dev/null 2>&1
rm ${sdcard}2 > /dev/null 2>&1
rm ${sdcard}u > /dev/null 2>&1
if [ "${_compress}" = "yes" ]; then
rm ${sdcard}.md5sum > /dev/null 2>&1
rm ${sdcard}.xz > /dev/null 2>&1
rm ${sdcard}.xz.md5sum > /dev/null 2>&1
fi
if [ "${_boot_on_ext4}" = "yes" ] ; then
_ersz=$(expr $ext4size + 2)
else
_ersz=$(expr $fatsize + $ext4size + 2)
fi
echo "Creating bootable SD card image $sdcard, please wait ..."
echo ""
dd if=/dev/zero of=${sdcard} bs=1M count=$_ersz > /dev/null 2>&1
echo "Creating partition images, please wait ..."
if [ "${_boot_on_ext4}" = "yes" ] ; then
dd if=/dev/zero of=${sdcard}1 bs=1M count=$ext4size > /dev/null 2>&1
else
dd if=/dev/zero of=${sdcard}1 bs=1M count=$fatsize > /dev/null 2>&1
dd if=/dev/zero of=${sdcard}2 bs=1M count=$ext4size > /dev/null 2>&1
fi
sync
sleep 2
# Create msdos partition table
echo ""
echo "Creating new filesystem on $sdcard..."
echo -e "o\nw" | fdisk ${sdcard} > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR."
exit 0
fi
sync
echo " New filesystem created on SD card."
echo ""
echo "Partitioning SD card $sdcard..."
if [ "${_boot_on_ext4}" = "yes" ] ; then
echo " Creating linux partition"
sext4=3072
if [ $ext4size == 0 ]; then
eext4=""
else
eext4=$(expr $ext4size \* 1024 \* 1024 / 512 + $sext4 - 1)
fi
echo -e "n\np\n1\n$sext4\n$eext4\nt\n83\nw" | fdisk ${sdcard} > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR."
exit 0
fi
else
sfat=3072
efat=$(expr $fatsize \* 1024 \* 1024 / 512 + $sfat - 1)
echo " Creating fat & linux partitions"
sext4=$(expr $efat + 1)
if [ $ext4size == 0 ]; then
eext4=""
else
eext4=$(expr $ext4size \* 1024 \* 1024 / 512 + $sext4 - 1)
fi
echo -e "n\np\n1\n$sfat\n$efat\nn\np\n2\n$sext4\n$eext4\nt\n1\n6\nt\n2\n83\nw" | fdisk ${sdcard} > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR."
exit 0
fi
fi
echo " OK."
sync
sleep 2
#echo -e "p\nq\n" | fdisk ${sdcard}
_mntopt=""
echo ""
if [ ! "${_boot_on_ext4}" = "yes" ] ; then
echo "Formating fat partition ..."
mkfs -t vfat -n BOOT ${sdcard}1 > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR formating fat partition."
exit 1
fi
echo " fat partition formated."
vfatuuid=`blkid -s UUID -o value ${sdcard}1`
echo "Formating linux partition, please wait ..."
if [ "${_btrfs}" = "yes" ] ; then
# format as btrfs
mkfs.btrfs -f -L linux_b ${sdcard}2 > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR formating btrfs linux partition."
exit 1
fi
_mntopt="-o compress-force=lzo"
else
mkfs -F -t ext4 -L linux ${sdcard}2 > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR formating ext4 partition."
exit 1
fi
#tune2fs -o journal_data_writeback ${sdcard}2 > /dev/null 2>&1
#if [ $? -ne 0 ]; then
# echo "ERROR tuning ext4 partition."
# exit 1
#fi
#tune2fs -O ^has_journal ${sdcard}2 > /dev/null 2>&1
#f [ $? -ne 0 ]; then
# echo "ERROR tuning ext4 partition."
# exit 1
#fi
fi
ext4uuid=`blkid -s UUID -o value ${sdcard}2`
else
echo "Formating linux partition, please wait ..."
if [ "${_btrfs}" = "yes" ] ; then
# format as btrfs
mkfs.btrfs -f -L linux_b ${sdcard}1 > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR formating btrfs linux partition."
exit 1
fi
_mntopt="-o compress-force=lzo"
else
mkfs -F -t ext4 -L linux ${sdcard}1 > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR formating linux partition."
exit 1
fi
#tune2fs -o journal_data_writeback ${sdcard}1 > /dev/null 2>&1
#if [ $? -ne 0 ]; then
# echo "ERROR tuning ext4 partition."
# exit 1
#fi
#tune2fs -O ^has_journal ${sdcard}1 > /dev/null 2>&1
#if [ $? -ne 0 ]; then
# echo "ERROR tuning ext4 partition."
# exit 1
#fi
fi
ext4uuid=`blkid -s UUID -o value ${sdcard}1`
fi
echo " linux partition formated."
echo ""
echo "Instaling u-boot to $sdcard ..."
dd if=$BL1 of=${sdcard} bs=1 count=442 conv=notrunc > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR installing u-boot."
exit 0
fi
dd if=$BL1 of=${sdcard} bs=512 skip=1 seek=1 conv=notrunc > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR installing u-boot."
exit 0
fi
dd if=$UBOOT of=${sdcard} bs=512 seek=64 conv=notrunc > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "ERROR installing u-boot."
exit 0
fi
sync
dd if=${sdcard} of=${sdcard}u bs=512 count=3072 > /dev/null 2>&1
rm ${sdcard}
echo "U-boot installed to $sdcard."
# -------------------------------------------------------------------
# -------------------------------------------------------------------
if [ ! "${_boot_on_ext4}" = "yes" ] ; then
if [ ! -d $bootdir ]; then
mkdir -p $bootdir
fi
rm $bootdir/* > /dev/null 2>&1
sync
umount $bootdir > /dev/null 2>&1
fi
if [ ! -d $odir ]; then
mkdir -p $odir
fi
rm -rf $odir/* > /dev/null 2>&1
sync
umount $odir > /dev/null 2>&1
sleep 1
# ================
# MOUNT PARTITIONS
# ================
echo ""
echo "Mounting SD Card partitions..."
if [ ! "${_boot_on_ext4}" = "yes" ] ; then
if ! mount ${sdcard}1 $bootdir; then
echo "ERROR mounting fat partitions..."
exit 1
fi
if ! mount ${_mntopt} ${sdcard}2 $odir; then
echo "ERROR mounting linux partitions..."
umount $bootdir
exit 1
fi
echo "FAT partitions mounted to $odir & $bootdir"
else
if ! mount ${_mntopt} ${sdcard}1 $odir; then
echo "ERROR mounting linux partitions..."
exit 1
fi
fi
echo "linux partition mounted to $odir"
#-----------------------------------------------------------------------------------------------
echo ""
echo "Copying files to image ..."
if [ ! "${_boot_on_ext4}" = "yes" ] ; then
cp $idir/boot/* $bootdir
fi
rsync -r -t -p -o -g -x --delete -l -H -D --numeric-ids -s --stats $PWD/$idir/ $PWD/$odir/
echo ""
if [ ! "${_boot_on_ext4}" = "yes" ] ; then
mkdir -p $odir/media/boot
fi
sync
# ***************
# Create fstab
# ***************
echo "Creating \"fstab\""
echo "# Odroid fstab" > $odir/etc/fstab
echo "" >> $odir/etc/fstab
if [ "${_btrfs}" = "yes" ] ; then
echo "UUID=$ext4uuid / btrfs noatime,nodiratime,compress=lzo 0 1" >> $odir/etc/fstab
else
# echo "#UUID=$ext4uuid / ext4 errors=remount-ro,noatime,nodiratime,data=writeback 0 1" >> $odir/etc/fstab
echo "UUID=$ext4uuid / ext4 errors=remount-ro,noatime,nodiratime 0 1" >> $odir/etc/fstab
fi
if [ ! "${_boot_on_ext4}" = "yes" ] ; then
echo "UUID=${vfatuuid} /media/boot vfat defaults,rw,owner,flush,umask=000 0 0" >> $odir/etc/fstab
fi
echo "tmpfs /tmp tmpfs nodev,nosuid,mode=1777 0 0" >> $odir/etc/fstab
#-----------------------------------------------------------------------------------------------
# ******************************
# CREATE Odroid-C1 boot.ini file
# You can modify parameters
# ******************************
if [ "${_boot_on_ext4}" = "yes" ] ; then
_ul1="ext4load mmc 0:1 0x21000000 boot/uImage"
_ul2="ext4load mmc 0:1 0x22000000 boot/uInitrd"
_ul3="ext4load mmc 0:1 0x21800000 boot/meson8b_odroidc.dtb"
_bootd="$odir/boot/boot.ini"
else
_ul1="fatload mmc 0:1 0x21000000 uImage"
_ul2="fatload mmc 0:1 0x22000000 uInitrd"
_ul3="fatload mmc 0:1 0x21800000 meson8b_odroidc.dtb"
_bootd="$bootdir/boot.ini"
fi
echo "Creating \"boot.ini\""
cat > $_bootd << _EOF_
ODROIDC-UBOOT-CONFIG
# Possible screen resolutions
# Uncomment only a single Line! The line with setenv written.
# At least one mode must be selected.
# setenv m "vga" # 640x480
# setenv m "480p" # 720x480
# setenv m "576p" # 720x576
# setenv m "800x480p60hz" # 800x480
# setenv m "800x600p60hz" # 800x600
# setenv m "1024x600p60hz" # 1024x600
# setenv m "1024x768p60hz" # 1024x768
# setenv m "1360x768p60hz" # 1360x768
# setenv m "1366x768p60hz" # 1366x768
# setenv m "1440x900p60hz" # 1440x900
# setenv m "1600x900p60hz" # 1600x900
# setenv m "1680x1050p60hz" # 1680x1050
# setenv m "720p" # 720p 1280x720
# setenv m "800p" # 1280x800
# setenv m "sxga" # 1280x1024
setenv m "1080p" # 1080P 1920x1080
# setenv m "1920x1200" # 1920x1200
# HDMI DVI Mode Configuration
setenv vout_mode "hdmi"
# setenv vout_mode "dvi"
# HDMI BPP Mode
setenv m_bpp "32"
# setenv m_bpp "24"
# setenv m_bpp "16"
# UHS Card Configuration
# Uncomment the line below to __DISABLE__ UHS-1 MicroSD support
# This might break boot for some brand models of cards.
#setenv disableuhs "disableuhs"
# Disable VPU (Video decoding engine, Saves RAM!!!)
# 0 = disabled
# 1 = enabled
setenv vpu "1"
# Disable HDMI Output (Again, saves ram!)
# 0 = disabled
# 1 = enabled
setenv hdmioutput "1"
# Default Console Device Setting
# setenv condev "console=ttyS0,115200n8" # on serial port
setenv condev "console=tty0" # on display (HDMI)
# setenv condev "console=ttyS0,115200n8 console=tty0" # on both
# Set Linux partition UUID
setenv linuuid "$ext4uuid"
# Boot Arguments
setenv bootargs "root=UUID=\${linuuid} rootwait ro \${condev} no_console_suspend vdaccfg=0xa000 logo=osd1,loaded,0x7900000,720p,full dmfc=3 cvbsmode=576cvbs hdmimode=\${m} m_bpp=\${m_bpp} vout=\${vout_mode} \${disableuhs}"
# Booting
$_ul1
$_ul2
$_ul3
fdt addr 21800000
if test "\${vpu}" = "0"; then fdt rm /mesonstream; fdt rm /vdec; fdt rm /ppmgr; fi
if test "\${hdmioutput}" = "0"; then fdt rm /mesonfb; fi
bootm 0x21000000 0x22000000 0x21800000
_EOF_
if [ ! "${_boot_on_ext4}" = "yes" ] ; then
if ! umount $bootdir; then
echo "ERROR unmounting fat partition."
exit 0
fi
rm -rf $bootdir/* > /dev/null 2>&1
rmdir $bootdir > /dev/null 2>&1
fi
if ! umount $odir; then
echo "ERROR unmounting linux partitions."
exit 0
fi
rm -rf $odir/* > /dev/null 2>&1
rmdir $odir > /dev/null 2>&1
sync
echo "Creating SDCard image..."
dd if=${sdcard}u of=${sdcard} > /dev/null 2>&1
if [ -f ${sdcard}1 ]; then
dd if=${sdcard}1 of=${sdcard} bs=1M conv=notrunc oflag=append > /dev/null 2>&1
fi
if [ -f ${sdcard}2 ]; then
dd if=${sdcard}2 of=${sdcard} bs=1M conv=notrunc oflag=append > /dev/null 2>&1
fi
if [ "${_compress}" = "yes" ]; then
echo "Compressing image..."
xz -z -k -9 -f -v $sdcard
md5sum $sdcard > $sdcard.md5sum
md5sum $sdcard.xz > $sdcard.xz.md5sum
fi
echo ""
date
echo ""
echo "*********************"
echo "SDCard image created."
echo "*********************"
echo ""
exit 0