-
Notifications
You must be signed in to change notification settings - Fork 11
/
remote_flash.sh
executable file
·172 lines (157 loc) · 5.6 KB
/
remote_flash.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
#!/bin/bash
# We use a public/private keypair to authenticate.
# Surgeon uses the 169.254.8.X subnet to differentiate itself from
# a fully booted system for safety purposes.
SSH="ssh root@169.254.8.1"
show_warning () {
echo "Leapster flash utility - installs a custom OS on your leapster!"
echo
echo "WARNING! This utility will ERASE the stock leapster OS and any other"
echo "data on the device. The device can be restored to stock settings using"
echo "the LeapFrog Connect app. Note that flashing your device will likely"
echo "VOID YOUR WARRANTY! Proceed at your own risk."
echo
echo "Please power off your leapster, hold the L + R shoulder buttons (LeapsterGS), "
echo "or right arrow + home buttons (LeapPad2), and then press power."
echo "You should see a screen with a green background."
read -p "Press enter when you're ready to continue."
}
show_machinelist () {
echo "----------------------------------------------------------------"
echo "What type of system would you like to flash?"
echo
echo "1. LF1000-Didj (Didj with EmeraldBoot)"
echo "2. LF1000 (Leapster Explorer)"
echo "3. LF2000 (Leapster GS, LeapPad 2, LeapPad Ultra XDI)"
echo "4. [EXPERIMENTAL] LF2000 w/ RT+OC Kernel (Leapster GS, LeapPad 2, LeapPad Ultra XDI)"
echo "5. LF3000 (LeapPad 3, LeapPad Platinum)"
}
boot_surgeon () {
surgeon_path=$1
memloc=$2
echo "Booting the Surgeon environment..."
python2 make_cbf.py $memloc $surgeon_path surgeon_tmp.cbf
sudo python2 boot_surgeon.py surgeon_tmp.cbf
echo -n "Done! Waiting for Surgeon to come up..."
rm surgeon_tmp.cbf
sleep 15
echo "Done!"
}
nand_part_detect () {
# Probe for filesystem partition locations, they can vary based on kernel version + presence of NOR flash drivers.
# TODO: Make the escaping less yucky...
KERNEL_PARTITION=`${SSH} "awk -e '\\$4 ~ /\"Kernel\"/ {print \"/dev/\" substr(\\$1, 1, length(\\$1)-1)}' /proc/mtd"`
RFS_PARTITION=`${SSH} "awk -e '\\$4 ~ /\"RFS\"/ {print \"/dev/\" substr(\\$1, 1, length(\\$1)-1)}' /proc/mtd"`
echo "Detected Kernel partition=$KERNEL_PARTITION RFS Partition=$RFS_PARTITION"
}
nand_flash_kernel () {
kernel_path=$1
echo -n "Flashing the kernel..."
${SSH} "/usr/sbin/flash_erase $KERNEL_PARTITION 0 0"
cat $kernel_path | ${SSH} "/usr/sbin/nandwrite -p $KERNEL_PARTITION -"
echo "Done flashing the kernel!"
}
nand_flash_rfs () {
rfs_path=$1
echo -n "Flashing the root filesystem..."
${SSH} "/usr/sbin/ubiformat -y $RFS_PARTITION"
${SSH} "/usr/sbin/ubiattach -p $RFS_PARTITION"
sleep 1
${SSH} "/usr/sbin/ubimkvol /dev/ubi0 -N RFS -m"
sleep 1
${SSH} "mount -t ubifs /dev/ubi0_0 /mnt/root"
# Note: We used to use a ubifs image here, but now use a .tar.gz.
# This removes the need to care about PEB/LEB sizes at build time,
# which is important as some LF2000 models (Ultra XDi) have differing sizes.
echo "Writing rootfs image..."
cat $rfs_path | ${SSH} "gunzip -c | tar x -f '-' -C /mnt/root"
${SSH} "umount /mnt/root"
${SSH} '/usr/sbin/ubidetach -d 0'
sleep 3
echo "Done flashing the root filesystem!"
}
nand_maybe_wipe_roms () {
read -p "Do you want to format the roms partition? (You should do this on the first flash of retroleap) (y/n)" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
${SSH} /usr/sbin/ubiformat /dev/mtd3
${SSH} /usr/sbin/ubiattach -p /dev/mtd3
${SSH} /usr/sbin/ubimkvol /dev/ubi0 -m -N roms
fi
}
flash_nand () {
prefix=$1
if [[ $prefix == lf1000_* ]]; then
memloc="high"
kernel="zImage_tmp.cbf"
python2 make_cbf.py $memloc ${prefix}zImage $kernel
else
memloc="superhigh"
kernel=${prefix}uImage
fi
boot_surgeon ${prefix}surgeon_zImage $memloc
# For the first ssh command, skip hostkey checking to avoid prompting the user.
${SSH} -o "StrictHostKeyChecking no" 'test'
nand_part_detect
nand_flash_kernel $kernel
nand_flash_rfs ${prefix}rootfs.tar.gz
nand_maybe_wipe_roms
echo "Done! Rebooting the host."
${SSH} '/sbin/reboot'
}
mmc_flash_kernel () {
kernel_path=$1
echo -n "Flashing the kernel..."
# TODO: This directory structure should be included in surgeon images.
${SSH} "mkdir /mnt/boot"
# TODO: This assumes a specific partition layout - not sure if this is the case for all devices?
${SSH} "mount /dev/mmcblk0p2 /mnt/boot"
cat $kernel_path | ${SSH} "cat - > /mnt/boot/uImage"
${SSH} "umount /dev/mmcblk0p2"
echo "Done flashing the kernel!"
}
mmc_flash_rfs () {
rfs_path=$1
# Size of the rootfs to be flashed, in bytes.
echo -n "Flashing the root filesystem..."
${SSH} "/sbin/mkfs.ext4 -F -L RFS -O ^metadata_csum /dev/mmcblk0p3"
# TODO: This directory structure should be included in surgeon images.
${SSH} "mkdir /mnt/root"
${SSH} "mount -t ext4 /dev/mmcblk0p3 /mnt/root"
echo "Writing rootfs image..."
cat $rfs_path | ${SSH} "gunzip -c | tar x -f '-' -C /mnt/root"
${SSH} "umount /mnt/root"
echo "Done flashing the root filesystem!"
}
flash_mmc () {
prefix=$1
boot_surgeon ${prefix}surgeon_zImage superhigh
# For the first ssh command, skip hostkey checking to avoid prompting the user.
${SSH} -o "StrictHostKeyChecking no" 'test'
mmc_flash_kernel ${prefix}uImage
mmc_flash_rfs ${prefix}rootfs.tar.gz
echo "Done! Rebooting the host."
sleep 3
${SSH} '/sbin/reboot'
}
show_warning
prefix=$1
if [ -z "$prefix" ]
then
show_machinelist
read -p "Enter choice (1 - 5)" choice
case $choice in
1) prefix="lf1000_didj_" ;;
2) prefix="lf1000_" ;;
3) prefix="lf2000_" ;;
4) prefix="lf2000_rt_" ;;
5) prefix="lf3000_" ;;
*) echo -e "Unknown choice!" && sleep 2
esac
fi
if [ $prefix == "lf3000_" ]; then
flash_mmc $prefix
else
flash_nand $prefix
fi