Last active
December 22, 2015 21:29
-
-
Save aperezdc/6533546 to your computer and use it in GitHub Desktop.
Edits the the Nook Color initial ramdisk of Android 4.3-based ROMs (e.g. CyanogenMod 10.2) to mount the internal eMMC data partition to be used as an “SD card”. You need to run this script from an Unix system (e.g. GNU/Linux) with your device connected. The tools “adb” and “mkimage” (from u-Boot) must be installed.
This file contains hidden or 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
#! /bin/bash | |
# | |
# android-4.3-encore-sdswap-ramdisk | |
# Copyright (C) 2013 Adrian Perez <[email protected]> | |
# | |
# Distributed under terms of the MIT license. | |
# | |
set -e | |
devices=$(adb devices | sed -e 1d -e '/^[:space:]$/d') | |
if [[ -z ${devices} ]] ; then | |
cat 1>&2 <<-EOF | |
No devices connected. Make sure your Nook Color is connected and | |
that ADB can access its contents. | |
EOF | |
exit 1 | |
fi | |
# Should be random enough as to not have clashes with other directories. | |
tempdir="sdswap-$(uuidgen)" | |
# Cleanup will be called on user interruption or end the of the script. | |
cleanup () { | |
adb shell sync | |
adb shell umount "/data/local/tmp/${tempdir}" | |
adb shell rm -rf "/data/local/tmp/${tempdir}" | |
cd /tmp | |
rm -rf "/tmp/${tempdir}" | |
} | |
trap cleanup INT EXIT | |
# A local temporary directory is used to unpack and edit the ramdisk. | |
mkdir -p "/tmp/${tempdir}/scratch" | |
cd "/tmp/${tempdir}" | |
# Mount the /boot partition of the Nook in a temporary random directory. | |
adb shell mkdir "/data/local/tmp/${tempdir}" | |
adb shell mount -t vfat /dev/block/mmcblk0p1 "/data/local/tmp/${tempdir}" | |
adb pull "/data/local/tmp/${tempdir}/uRamdisk" . | |
cd scratch | |
dd if=../uRamdisk bs=64 skip=1 | gunzip -c | cpio -i | |
# Edit the fstab.encore file. Note that replacements are only made | |
# for the sdcard and emmc lines. The way the edit is done allows to | |
# run the command several times on the same file and always get the | |
# same result. | |
mv fstab.encore .. | |
sed -e '/voldmanaged=sdcard/y:sdcard1:sdcard0:' \ | |
-e '/voldmanaged=emmc/y:sdcard0:sdcard1:' \ | |
../fstab.encore > fstab.encore | |
diff -u ../fstab.encore fstab.encore || true | |
# Re-pack the ramdisk. The old uRamdisk is deleted first to avoid | |
# including it in the new one. | |
find . -regex './.*' | cpio -o -H newc | gzip -9c > ../ramdisk.gz | |
cd .. | |
mkimage -A ARM -T RAMDisk -n Image -d ramdisk.gz uRamdisk.new | |
adb push uRamdisk.new "/data/local/tmp/${tempdir}/uRamdisk.new" | |
adb shell mv "/data/local/tmp/${tempdir}/uRamdisk.new" \ | |
"/data/local/tmp/${tempdir}/uRamdisk" | |
# NOTE: Cleanup is done on exit using the cleanup() function above |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment