#!/sbin/sh
/tmp/echo "performance" > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
/tmp/echo "1" > /sys/devices/system/cpu/cpu0/online
/tmp/echo "1" > /sys/devices/system/cpu/cpu1/online
/tmp/echo "1" > /sys/devices/system/cpu/cpu2/online
/tmp/echo "1" > /sys/devices/system/cpu/cpu3/online
/tmp/echo "1024" > /sys/block/mmcblk0/bdi/read_ahead_kb
/tmp/echo "row" > /sys/block/mmcblk0/queue/scheduler
if [ ! -e /tmp/ramdisk ] ; then /tmp/mkdir /tmp/ramdisk; fi
cd /tmp/ramdisk
/tmp/rm -rf /tmp/extract.prop /tmp/notgzip.prop /tmp/boot*
/tmp/dd if=/dev/block/platform/dw_mmc/by-name/BOOT of=/tmp/boot.img
/tmp/unpackbootimg -i /tmp/boot.img -o /tmp/ || /tmp/echo unable=1 > /tmp/extract.prop
if [ -f /tmp/extract.prop ] ; then
	exit 1
fi
/tmp/echo unable=0 > /tmp/extract.prop
/tmp/gzip -l ../boot.img-ramdisk.gz || /tmp/echo notgzip=1 > /tmp/notgzip.prop
if [ -f /tmp/notgzip.prop ] ; then
	exit 1
fi
/tmp/echo notgzip=0 > /tmp/notgzip.prop
CPIO=/tmp/cpio
/tmp/cpio --version || CPIO="busybox cpio"
/tmp/gzip -dc ../boot.img-ramdisk.gz | $CPIO -i
/tmp/find . -type f -exec /tmp/grep -l "smdk" {} + | while read file; do /tmp/file -m /tmp/magic.mgc $file | /tmp/grep ASCII | /tmp/cut -d: -f1 | while read file2; do /tmp/sed -i -e 's/smdk4x12/SHW-M440S/g' -e 's/smdk4412/SHW-M440S/g' $file2; done; done
/tmp/find . -name '*smdk*' -type f | while read file; do /tmp/mv -f "$file" "$(/tmp/echo $file | /tmp/sed -e 's/smdk4x12/SHW-M440S/g' -e 's/smdk4412/SHW-M440S/g')"; done
/tmp/echo > /tmp/ramdisk/made_by_gal3_arter97
/tmp/find . -name "init" -exec chmod 755 {} \;
/tmp/find . -name "*.SHW-M440S" -exec chmod 644 {} \;
/tmp/find . -name "fstab*" -exec chmod 64 {} \;
/tmp/find . -name "*.rc" -exec chmod 644 {} \;
/tmp/find . -name "init.SHW-M440S*rc*" -exec chmod 775 {} \;
/tmp/find . -name "init.SHW-M440S*rc" -exec chmod 644 {} \;
/tmp/find . -name "*.prop" -exec chmod 644 {} \;
/tmp/find . -name "lib" -exec chmod -R 755 {} \;
/tmp/find . | $CPIO -o -H newc | /tmp/gzip -1 > ../boot.img-ramdisk-gal3-arter97.gz
cd ..
echo exceeds=0 > /tmp/exceeds.prop
/tmp/mkbootimg --kernel /tmp/boot.img-zImage --ramdisk /tmp/boot.img-ramdisk-gal3-arter97.gz --base 0x$(/tmp/cat /tmp/boot.img-base) --cmdline "$(/tmp/cat /tmp/boot.img-cmdline)" --pagesize $(/tmp/cat /tmp/boot.img-pagesize) --output /tmp/newboot.img
if [ "$(/tmp/stat -c%s /tmp/newboot.img)" -gt "8388608" ] ; then
	cd /tmp/ramdisk
	/tmp/rm ../boot.img-ramdisk-gal3-arter97.gz
	/tmp/find . | $CPIO -o -H newc | /tmp/gzip -9 > ../boot.img-ramdisk-gal3-arter97.gz
	cd ..
	/tmp/mkbootimg --kernel /tmp/boot.img-zImage --ramdisk /tmp/boot.img-ramdisk-gal3-arter97.gz --base 0x$(/tmp/cat /tmp/boot.img-base) --cmdline "$(/tmp/cat /tmp/boot.img-cmdline)" --pagesize $(/tmp/cat /tmp/boot.img-pagesize) --output /tmp/newboot.img
	if [ "$(/tmp/stat -c%s /tmp/newboot.img)" -le "8388608" ] ; then
	        /tmp/dd if=/dev/zero of=/dev/block/platform/dw_mmc/by-name/BOOT
	        /tmp/dd if=/tmp/newboot.img of=/dev/block/platform/dw_mmc/by-name/BOOT
	else
		echo exceeds=1 > /tmp/exceeds.prop
		exit 1
	fi
else
	/tmp/dd if=/dev/zero of=/dev/block/platform/dw_mmc/by-name/BOOT
	/tmp/dd if=/tmp/newboot.img of=/dev/block/platform/dw_mmc/by-name/BOOT
fi
