Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/bin/bash | ||
|
||
function pt_error() | ||
{ | ||
echo -e "\033[1;31mERROR: $*\033[0m" | ||
} | ||
|
||
function pt_warn() | ||
{ | ||
echo -e "\033[1;31mWARN: $*\033[0m" | ||
} | ||
|
||
function pt_info() | ||
{ | ||
echo -e "\033[1;32mINFO: $*\033[0m" | ||
} | ||
|
||
function pt_ok() | ||
{ | ||
echo -e "\033[1;33mOK: $*\033[0m" | ||
} | ||
|
||
|
||
|
||
SDCARD="$1" | ||
|
||
if [ -z "$SDCARD" ]; then | ||
pt_error "Usage: $0 <SD card> (SD CARD: /dev/sdX where X is your sd card number or /dev/mmcblkX where X is a letter)" | ||
exit 1 | ||
fi | ||
|
||
if [ $UID -ne 0 ] | ||
then | ||
pt_error "Please run as root." | ||
exit | ||
fi | ||
|
||
|
||
pt_info "Umounting $out, please wait..." | ||
umount ${SDCARD}* >/dev/null 2>&1 | ||
sleep 1 | ||
sync | ||
|
||
set -e | ||
|
||
pt_warn "Flashing $SDCARD...." | ||
dd if=./boot0.bin conv=notrunc bs=1k seek=8 of=${SDCARD} | ||
dd if=./ub-nanopi-a64.bin conv=notrunc bs=1k seek=19096 of=${SDCARD} | ||
|
||
mkdir -p erootfs | ||
mount $SDCARD"2" erootfs | ||
tar -xvpzf rootfs_nanopia64_rc1.tar.gz -C ./erootfs --numeric-ow | ||
sync | ||
umount erootfs | ||
rm -fR erootfs | ||
|
||
set +e | ||
mkdir eboot | ||
mount $SDCARD"1" eboot | ||
tar -xvpzf boot_nanopia64_rc1.tar.gz -C ./eboot --numeric-ow | ||
sync | ||
umount eboot | ||
rm -fR eboot | ||
|
||
pt_ok "Finished flashing $SDCARD!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#!/bin/bash | ||
|
||
function pt_error() | ||
{ | ||
echo -e "\033[1;31mERROR: $*\033[0m" | ||
} | ||
|
||
function pt_warn() | ||
{ | ||
echo -e "\033[1;31mWARN: $*\033[0m" | ||
} | ||
|
||
function pt_info() | ||
{ | ||
echo -e "\033[1;32mINFO: $*\033[0m" | ||
} | ||
|
||
function pt_ok() | ||
{ | ||
echo -e "\033[1;33mOK: $*\033[0m" | ||
} | ||
|
||
|
||
|
||
out="$1" | ||
|
||
if [ -z "$out" ]; then | ||
pt_error "Usage: $0 <SD card> (SD CARD: /dev/sdX where X is your SD CARD letter or /dev/mmcblkX where X is your sd card number)" | ||
exit 1 | ||
fi | ||
|
||
if [ $UID -ne 0 ] | ||
then | ||
pt_error "Please run as root." | ||
exit | ||
fi | ||
|
||
|
||
pt_info "Umounting $out, please wait..." | ||
sync | ||
umount ${out}* >/dev/null 2>&1 | ||
sleep 1 | ||
sync | ||
|
||
set -e | ||
pt_info "Formating sd card $out ..." | ||
|
||
part_position=20480 # KiB | ||
boot_size=80 # MiB | ||
# Create beginning of disk | ||
pt_info "Zeroing mbr on $out ..." | ||
dd if=/dev/zero bs=1M count=$((part_position/1024)) of="$out" | ||
sync | ||
|
||
pt_info "Creating partition on $out ..." | ||
# Add partition table | ||
cat <<EOF | fdisk "$out" | ||
o | ||
n | ||
p | ||
1 | ||
$((part_position*2)) | ||
+${boot_size}M | ||
t | ||
c | ||
n | ||
p | ||
2 | ||
$((part_position*2 + boot_size*1024*2)) | ||
t | ||
2 | ||
83 | ||
w | ||
EOF | ||
|
||
sleep 1 | ||
sync | ||
partprobe -s ${out} | ||
sync | ||
|
||
pt_warn "Formating $out ..." | ||
# Create boot file system (VFAT) | ||
dd if=/dev/zero bs=1M count=${boot_size} of=${out}1 | ||
mkfs.vfat -n boot -I ${out}1 | ||
|
||
# Create ext4 file system for rootfs | ||
mkfs.ext4 -F -b 4096 -E stride=2,stripe-width=1024 -L rootfs ${out}2 | ||
sync | ||
sudo tune2fs -O ^has_journal ${out}2 | ||
sync | ||
|
||
pt_ok "Done - Geometry created and sd card '$out' formatted, now flash the image with ./flash_sd.sh" | ||
|