flasher stuff
authorGrazvydas Ignotas <notasas@gmail.com>
Tue, 18 May 2010 11:30:44 +0000 (14:30 +0300)
committerGrazvydas Ignotas <notasas@gmail.com>
Tue, 18 May 2010 11:30:44 +0000 (14:30 +0300)
flasher/doit.sh [new file with mode: 0755]
flasher/rootfs/etc/init.d/rc [new file with mode: 0755]
flasher/rootfs/etc/init.d/rcS [new file with mode: 0755]
flasher/rootfs/etc/updater.sh [new file with mode: 0755]
flasher/rootfs/etc/updater_funcs.sh [new file with mode: 0644]
flasher/script.txt [new file with mode: 0644]

diff --git a/flasher/doit.sh b/flasher/doit.sh
new file mode 100755 (executable)
index 0000000..a45cc95
--- /dev/null
@@ -0,0 +1,75 @@
+#!/bin/sh
+#
+# Firmware flasher creator for Pandora
+# Copyright (c) 2010, Gražvydas Ignotas
+
+set -e
+
+out_dir="out/"
+out_opt_dir="out_opt/"
+sysf_in="in/"
+rd_input="rootfs"
+rdfile=`mktemp`
+rdfile_out="tmp/rd-ext2.bin"
+boot_scr_tmp=`mktemp`
+boot_scr_tmp2=`mktemp`
+boot_scr_tmp_scr=`mktemp`
+zipfile="pandora_flasher_v.zip"
+
+if test '!' '(' -d $rd_input -a -f ${sysf_in}x-load.bin.ift -a -f ${sysf_in}u-boot.bin \
+       -a -f ${sysf_in}uImage -a -f ${sysf_in}uImage_updater ')'
+then
+       echo "missing input files"
+       exit 1
+fi
+
+rm -rf $out_dir $out_opt_dir
+mkdir $out_dir 2>/dev/null && mkdir $out_opt_dir 2>/dev/null || true
+
+
+# files for SD boot
+cp ${sysf_in}x-load.bin.ift ${out_opt_dir}MLO
+cp ${sysf_in}u-boot.bin_updater ${out_opt_dir}u-boot.bin
+
+
+# sysf.tgz
+cd $sysf_in
+tar czvf sysf.tgz u-boot.bin uImage
+cd ..
+mv -f ${sysf_in}sysf.tgz ${out_dir}
+
+
+# rootfs
+dd if=/dev/zero of=$rdfile bs=1M count=8
+mkfs.ext2 -F $rdfile 
+sudo mount -o loop $rdfile /mnt/tmp
+sudo cp -r $rd_input/* /mnt/tmp/
+sudo umount /mnt/tmp
+cat $rdfile | gzip -9 > $rdfile_out
+rm $rdfile
+
+
+# boot.scr
+dd if=/dev/zero of=$boot_scr_tmp_scr bs=1 count=4020
+dd if=/dev/zero of=$boot_scr_tmp bs=4K count=800
+
+# 000000 - 000fff: u-boot header, the script
+dd if=script.txt of=$boot_scr_tmp_scr conv=notrunc bs=1
+# 001000 - 020fff: x-load
+dd if=$rd_input/usr/local/erasednandblk of=$boot_scr_tmp conv=notrunc bs=4K
+dd if=${sysf_in}x-load.bin.ift of=$boot_scr_tmp conv=notrunc bs=4K
+# 021000 - 320fff: uImage
+dd if=${sysf_in}uImage_updater of=$boot_scr_tmp conv=notrunc bs=4K seek=32
+# 321000 - end:    ramdisk
+cat $boot_scr_tmp $rdfile_out > $boot_scr_tmp2
+# adjust for u-boot header
+#dd if=$boot_scr_tmp2 of=$boot_scr_tmp bs=72 skip=1
+tmp/mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n "script" \
+       -d $boot_scr_tmp_scr:$boot_scr_tmp2 ${out_dir}boot.scr
+rm $boot_scr_tmp $boot_scr_tmp2 $boot_scr_tmp_scr
+
+# release zip
+cd ${out_dir}
+zip -9 $zipfile sysf.tgz boot.scr
+mv -f $zipfile ../tmp/
+cd ..
diff --git a/flasher/rootfs/etc/init.d/rc b/flasher/rootfs/etc/init.d/rc
new file mode 100755 (executable)
index 0000000..f4e5ebf
--- /dev/null
@@ -0,0 +1,45 @@
+#!/bin/sh
+
+. /etc/updater_funcs.sh
+
+chvt $LOG_TTY
+log "Starting updater. Press Alt+right for verbose output.."
+log ""
+
+# wait a bit for things to settle..
+sleep 2
+
+echo running update script..
+
+{ /etc/updater.sh 2>&1; echo $? > /tmp/update.result; } | tee /tmp/update.log
+if [ `cat /tmp/update.result` = "0" ]
+then
+       log "---------------------------------------------"
+       log "Update FINISHED"
+       log "---------------------------------------------"
+else
+       log "---------------------------------------------"
+       log "Update FAILED"
+       log "---------------------------------------------"
+       mkdir -p /mnt/log 2> /dev/null
+       if mount /dev/mmcblk0p1 /mnt/log
+       then
+               if touch /mnt/log/update.log
+               then
+                       dmesg > /mnt/log/update.log
+                       echo "----------" >> /mnt/log/update.log
+                       cat /tmp/update.log >> /mnt/log/update.log
+                       log "update.log saved to SD."
+               fi
+               umount /mnt/log
+       fi
+fi
+echo "press Enter to power off" > $LOG_DEVICE
+sync
+read a < $LOG_DEVICE
+if [ "$a" != "n" ]
+then
+       sync
+       echo poweroff
+       poweroff -f
+fi
diff --git a/flasher/rootfs/etc/init.d/rcS b/flasher/rootfs/etc/init.d/rcS
new file mode 100755 (executable)
index 0000000..d342a14
--- /dev/null
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+echo -n "Starting up."
+
+export PATH=/bin:/sbin:/usr/bin:/usr/sbin
+export HOSTNAME=pandora
+hostname $HOSTNAME
+
+mount -n -t proc none /proc
+mount -n -t sysfs none /sys
+mount -n -t tmpfs none /dev
+
+mkdir /dev/input
+mkdir /dev/pts
+mkdir /dev/snd
+
+mdev -s
+echo "/sbin/mdev" > /proc/sys/kernel/hotplug
+mount -a
+
+setlogcons 1
+ifconfig lo up
+
+echo "."
+
+/sbin/syslogd
diff --git a/flasher/rootfs/etc/updater.sh b/flasher/rootfs/etc/updater.sh
new file mode 100755 (executable)
index 0000000..67dcc42
--- /dev/null
@@ -0,0 +1,170 @@
+#/bin/sh
+#
+# on-target updater script for Pandora
+# Copyright (c) 2010, Gražvydas Ignotas
+
+set -e
+
+. /etc/updater_funcs.sh
+
+status_uboot="missing"
+status_uboot_env="already empty"
+status_uimage="missing"
+status_rootfs="missing"
+
+mkdir /mnt/ubifs 2> /dev/null || true
+
+if [ ! -e /dev/mmcblk0p1 ]
+then
+       # hmh what's up with the SD card?
+       log "Can't access SD card, please reinsert and press enter"
+       read a < /dev/tty3
+       test -e /dev/mmcblk0p1
+fi
+
+mdevs="/dev/mmcblk0p1 /dev/mmcblk0p2"
+
+cd /tmp
+
+for md in $mdevs
+do
+       mpoint="/mnt/`basename $md`"
+       keep_mpoint="no"
+       mkdir $mpoint 2> /dev/null || true
+       if ! mount $md $mpoint
+       then
+               continue;
+       fi
+
+       if [ -e $mpoint/sysf.tgz ]
+       then
+               tar xzvf $mpoint/sysf.tgz
+       fi
+
+       if [ -x $mpoint/finalize.sh ]
+       then
+               finalize_mpoint=$mpoint
+               keep_mpoint="yes"
+       fi
+
+       if [ -e $mpoint/rootfs.img -a -e $mpoint/rootfs.md5 -a -z "$rootfs_file" ]
+       then
+               rootfs_file=$mpoint/rootfs.img
+               rootfs_md5=`head -n 1 $mpoint/rootfs.md5 | cut -c 1-32`
+               rootfs_mpoint=$mpoint
+               keep_mpoint="yes"
+       fi
+
+       if [ "$keep_mpoint" != "yes" ]
+       then
+               umount $mpoint
+       fi
+done
+
+if [ -e u-boot.bin ]
+then
+       size=`stat -c %s u-boot.bin`
+       dd if=/dev/mtdblock1 of=u-boot.bin.flashed bs=$size count=1
+       if ! cmp u-boot.bin u-boot.bin.flashed
+       then
+               flash_eraseall /dev/mtd1
+               nandwrite -p /dev/mtd1 u-boot.bin
+               log "u-boot.bin flashed."
+               status_uboot="flashed"
+       else
+               log "u-boot.bin already flashed, skipped."
+               status_uboot="already there"
+       fi
+else
+       log "u-boot is missing, skipped."
+fi
+
+if ! cmp /dev/mtdblock2 /usr/local/erasednandblk
+then
+       flash_eraseall /dev/mtd2
+       status_uboot_env="cleared"
+       log "u-boot environment cleared."
+fi
+
+if [ -e uImage ]
+then
+       # attempt to mount and check
+       ubiattach /dev/ubi_ctrl -m 3 || true
+       mount -t ubifs ubi0:boot /mnt/ubifs  2> /dev/null || true
+       if ! cmp uImage /mnt/ubifs/uImage  2> /dev/null
+       then
+               log "flashing uImage.."
+               umount /mnt/ubifs  2> /dev/null || true
+               ubidetach /dev/ubi_ctrl -d 0  2> /dev/null || true
+               # format just in case, should be harmless even it's formated already
+               ubiformat /dev/mtd3 -s 512 -y
+               ubiattach /dev/ubi_ctrl -m 3
+               ubimkvol /dev/ubi0 -m -N boot
+               mount -t ubifs ubi0:boot /mnt/ubifs
+               cp uImage /mnt/ubifs/uImage
+               status_uimage="flashed"
+               log "done"
+       else
+               log "uImage already flashed, skipped."
+               status_uimage="already there"
+       fi
+       umount /mnt/ubifs
+       ubidetach /dev/ubi_ctrl -d 0
+else
+       log "uImage is missing, skipped."
+fi
+
+if [ -n "$rootfs_file" ]
+then
+       log "Calculating checksum, this might take a few minutes.."
+       real_md5=`md5sum $rootfs_file | cut -c 1-32`
+       if [ "$real_md5" = "$rootfs_md5" ]
+       then
+               log $real_md5
+       else
+               log "INCORRECT"
+               false
+       fi
+
+       # be destructive here, too hard to validate rootfs to bother
+       log "formatting.."
+       ubiformat /dev/mtd4 -s 512 -y
+       ubiattach /dev/ubi_ctrl -m 4
+       ubimkvol /dev/ubi0 -m -N rootfs
+       log "done."
+       log "Writing rootfs, please wait. This may take up to 15 minutes.."
+       ubiupdatevol /dev/ubi0_0 $rootfs_file
+       ubidetach /dev/ubi_ctrl -d 0
+       status_rootfs="flashed"
+       log "done."
+else
+       log "root filesystem is missing, skipped."
+fi
+
+if [ -n "$finalize_mpoint" ]
+then
+       log "running finalize script.."
+       cd $finalize_mpoint
+       if ! ./finalize.sh
+       then
+               log "finalize.sh failed."
+               false
+       fi
+       log "done."
+       cd /tmp
+       umount $finalize_mpoint
+fi
+
+if [ -n "$rootfs_mpoint" ]
+then
+       umount $rootfs_mpoint 2> /dev/null || true
+fi
+
+log "======================="
+log "results:"
+log "u-boot:     $status_uboot"
+log "u-boot-env: $status_uboot_env"
+log "kernel:     $status_uimage"
+log "rootfs:     $status_rootfs $rootfs_file"
+
+exit 0
diff --git a/flasher/rootfs/etc/updater_funcs.sh b/flasher/rootfs/etc/updater_funcs.sh
new file mode 100644 (file)
index 0000000..a13fe4b
--- /dev/null
@@ -0,0 +1,9 @@
+LOG_TTY=3
+LOG_DEVICE="/dev/tty$LOG_TTY"
+
+log()
+{
+       echo "$@"
+       echo "$@" > $LOG_DEVICE
+}
+
diff --git a/flasher/script.txt b/flasher/script.txt
new file mode 100644 (file)
index 0000000..180d5a0
--- /dev/null
@@ -0,0 +1,28 @@
+setenv stdout lcd
+mw.l 83000000 40200800
+if cmp.l 82001004 83000000 1
+then
+  nandecc hw
+  nand read 83000000 0 20000
+  if cmp.b 82001000 83000000 20000
+  then
+    echo
+    echo >>> x-load already flashed, skipped.
+    echo
+  else
+    nand erase 0 80000
+    nand write 82001000 0 20000
+    nand write 82001000 20000 20000
+    nand write 82001000 40000 20000
+    nand write 82001000 60000 20000
+    echo
+    echo >>> finished flashing new x-load
+    echo
+  fi
+  setenv bootargs console=tty1 ramdisk_size=8192 root=/dev/ram0 rw rootfstype=ext2 initrd=0x82321000,8M vram=6272K omapfb.vram=0:3000K
+  bootm 0x82021000
+fi
+
+echo
+echo Data corruption detected.
+echo