forked from CyanogenMod/android_device_bn_encore
-
Notifications
You must be signed in to change notification settings - Fork 7
/
ramdisk_tools.sh
executable file
·228 lines (201 loc) · 7.73 KB
/
ramdisk_tools.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
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
#!/bin/bash
# ramdisk_tools.sh
#
# (C) 2010-2011 fattire
# (C) 2011 Gerad Munsch <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# So what does this do? It creates an encore initramfs (ramdisk) from
# the files provided in ./root/. It automatically replaces the mount
# points in init.encore.rc, based on which argument is passed to the
# script. It supports creating ramdisks for internal, SD card, and
# alternate internal boot setups.
#
# Run this file script from $OUT -- (basically) the place you found it.
#
# Arguments:
# --internal : creates ramdisk.ub for use on standard internal
# emmc partitions
#
# --sdcard : creates ramdisk-sdcard.ub for use on SD card setups
#
# --alternate : create ramdisk-alternate.ub for use on the alternate
# internal emmc partitions (9,10,11)
#
# --recovery : creates a recovery image (ramdisk-recovery.ub)
#
# Place the resultant file in the appropriate /boot partition, with
# the appropriate name, reboot, and enjoy!
### CONSTANTS ###
# files
ROOT="root"
INIT="root/init.encore.rc"
INT_OUT="ramdisk.ub"
SD_OUT="ramdisk-sdcard.ub"
ALT_OUT="ramdisk-alternate.ub"
REC_OUT="ramdisk-recovery.ub"
REC_ROOT="recovery/root"
# partitions
INT_SYSTEM="mmcblk0p5"
INT_USERDATA="mmcblk0p6"
INT_CACHE="mmcblk0p7"
SD_SYSTEM="mmcblk1p2"
SD_USERDATA="mmcblk1p3"
SD_CACHE="mmcblk1p5"
ALT_SYSTEM="mmcblk0p9"
ALT_USERDATA="mmcblk0p10"
ALT_CACHE="mmcblk0p11"
# strings
INT_NAME_1="internal"
INT_NAME_2="emmc"
SD_NAME_1="SD"
SD_NAME_2="card"
ALT_NAME_1="alternate"
ALT_NAME_2="internal/emmc"
INT_BOOT="mmcblk0p1"
SD_BOOT="mmcblk1p1"
ALT_BOOT="mmcblk0p1"
INT_RAMDISK_NAME="uRamdisk"
SD_RAMDISK_NAME="uRamdisk"
ALT_RAMDISK_NAME="uAltRam"
REC_NAME_1="recovery"
REC_NAME_2="internal/emmc"
REC_BOOT="mmcblk0p1"
REC_RAMDISK_NAME="uRecRam"
### END CONSTANTS ###
### FUNCTION DEFINITIONS ###
## display help information
function display_help {
echo -e "\033[1m$0\033[0m\n"
echo -e "This is a combination script, used for building ramdisks for use with the Nook Color. It covers"
echo -e "use with standard emmc, alternate emmc, and SD card partition setups. It uses the ./root/ folder"
echo -e "for its input. The init file, \033[1minit.encore.rc\033[0m will automatically be modified to contain the"
echo -e "appropriate mount points.\n"
echo -e "\033[1mUSAGE:\033[0m"
echo -e "\033[1m$0 --internal\033[0m - rebuilds your ramdisk, setup for the default internal emmc partitions.\n Output: \033[1mramdisk.ub\033[0m"
echo -e "\033[1m$0 --sdcard\033[0m - rebuilds your ramdisk, setup for installations on MicroSD cards.\n Output: \033[1mramdisk-sdcard.ub\033[0m"
echo -e "\033[1m$0 --alternate\033[0m - rebuilds your ramdisk, setup for the alternate internal emmc partitions.\n Output: \033[1mramdisk-alternate.ub\033[0m"
return 0
} # end function 'help_info' #
## check for existance of mkimage
function check_mkimage {
which mkimage &> /dev/null
if [ $? -ne 0 ]; then
echo -e "\n\033[1mY U NO have mkimage??\033[0m\n"
echo -e "Please install mkimage from your distributions repositories, or elsewhere.\n"
echo -e "Older Debian/Ubuntu: \033[1m(sudo) apt-get install uboot-mkimage\033[0m"
echo -e "Newer Debian/Ubuntu: \033[1m(sudo) apt-get install u-boot-tools\033[0m\n"
echo -e "Mac users : Not available via ports. You'll need to compile it.\n"
echo -e "Please try again once mkimage is accessible from your path/shell, and try again."
return 1
else
echo -e "\n\033[1m* Found mkimage, proceeding.\033[0m"
return 0
fi
} # end function 'check_mkimage' #
## update init.encore.rc with proper partition names
function update_init {
sed -i 's/.*mount.*\/system.*/ mount ext4 \/dev\/block\/'$1' \/system wait ro barrier=1/' $INIT
sed -i 's/.*mount.*\/data.*/ mount ext4 \/dev\/block\/'$2' \/data wait noatime nosuid nodev barrier=1 noauto_da_alloc/' $INIT
sed -i 's/.*mount.*\/cache.*/ mount ext4 \/dev\/block\/'$3' \/cache wait noatime nosuid nodev barrier=1/' $INIT
} # end function 'update_init' #
## create new ramdisk from ./root/ folder
function create_ramdisk {
if [ ! -d "$ROOT" ]; then
echo "Whoops! The directory ./$ROOT, which is used to make the ramdisk, is missing. Are you running this script from the right place?"
exit 1
fi
# enter initramfs (ramdisk) root
cd $ROOT
# collect files to be added to initramfs (ramdisk), and add them
echo -e "\n\033[1m* Adding files:\033[0m"
find . -regex "./.*" | cpio -ov -H newc | gzip > ../repacked-ramdisk.cpio.gz
# create new initramfs (ramdisk) image using mkimage (u-boot-tools)
echo -e "\n\033[1m* Creating ramdisk:\033[0m"
mkimage -A ARM -T RAMDisk -n Image -d ../repacked-ramdisk.cpio.gz ../$1
} # end function 'create_ramdisk' #
## cleanup our mess
function cleanup_mess {
rm ../repacked-ramdisk.cpio.gz
} # end function 'cleanup_mess' #
## display helpful info
function output_info {
echo -e "\n\033[1m* Created ramdisk for $1 $2 boot. To install this ramdisk on your device, boot into your NC, then:\033[0m"
echo -e "adb shell"
echo -e "mount -o rw,remount /"
echo -e "mkdir -p /mnt/boot"
echo -e "mount -t vfat /dev/block/$3 /mnt/boot"
echo -e "exit"
echo -e "adb push $4 /mnt/boot/$5"
echo -e "adb shell sync"
echo -e "adb reboot"
} # end function 'output_info' #
## display extra info for alternate boot
function alt_boot_info {
echo -e "\n\033[1m* Please keep in mind, you need uAltImg in place as well.\033[0m"
echo "To set the default boot device to alternate eMMC partitions, do:"
echo "adb shell"
echo "mount -o rw,remount /rom"
echo "cd /rom"
echo "touch u-boot.altboot"
echo "echo 1 > u-boot.altboot"
echo "sync"
echo "mount -o ro,remount /rom"
echo -e "\n\033[1m* Your alternate boot image/ramdisk are now the default.\033[0m"
} # end function 'alt_boot_info' #
### END FUNCTION DEFINITIONS ###
### MAIN PROGRAM ###
# check for arguments -- if none exist, assume --internal
if [ $# -lt 1 ]; then
cmd="--internal"
else
cmd=$1
fi
case $cmd in
--internal|-internal|-int|-i)
# rebuild ramdisk for use on standard emmc partitions
check_mkimage
create_ramdisk $INT_OUT
cleanup_mess
output_info $INT_NAME_1 $INT_NAME_2 $INT_BOOT $INT_OUT $INT_RAMDISK_NAME
;; # end case '--internal' #
--sdcard|-sdcard|-s|-sd)
# rebuild ramdisk for use on SD card
check_mkimage
update_init $SD_SYSTEM $SD_USERDATA $SD_CACHE
create_ramdisk $SD_OUT
cleanup_mess
output_info $SD_NAME_1 $SD_NAME_2 $SD_BOOT $SD_OUT $SD_RAMDISK_NAME
;; # end case '--sdcard' #
--alternate|-alternate|-alt|-a)
# rebuild ramdisk for use on alternate emmc partitions
check_mkimage
update_init $ALT_SYSTEM $ALT_USERDATA $ALT_CACHE
create_ramdisk $ALT_OUT
cleanup_mess
output_info $ALT_NAME_1 $ALT_NAME_2 $ALT_BOOT $ALT_OUT $ALT_RAMDISK_NAME
alt_boot_info
;; # end case '--alternate' #
--recovery|-recovery|-rec|-r)
# rebuild recovery
check_mkimage
ROOT=$REC_ROOT
create_ramdisk $REC_OUT
cleanup_mess
mv ../${REC_OUT} ../../${REC_OUT}
output_info $REC_NAME_1 $REC_NAME_2 $REC_BOOT $REC_OUT $REC_RAMDISK_NAME
;; # end case '--recovery' #
--help|-help|-h)
# display help
display_help
;; # end case '--help' #
esac
### END MAIN PROGRAM ###