flasher stuff
[pandora-misc.git] / flasher / doit.sh
1 #!/bin/sh
2 #
3 # Firmware flasher creator for Pandora
4 # Copyright (c) 2010, GraÅžvydas Ignotas
5
6 set -e
7
8 out_dir="out/"
9 out_opt_dir="out_opt/"
10 sysf_in="in/"
11 rd_input="rootfs"
12 rdfile=`mktemp`
13 rdfile_out="tmp/rd-ext2.bin"
14 boot_scr_tmp=`mktemp`
15 boot_scr_tmp2=`mktemp`
16 boot_scr_tmp_scr=`mktemp`
17 zipfile="pandora_flasher_v.zip"
18
19 if test '!' '(' -d $rd_input -a -f ${sysf_in}x-load.bin.ift -a -f ${sysf_in}u-boot.bin \
20         -a -f ${sysf_in}uImage -a -f ${sysf_in}uImage_updater ')'
21 then
22         echo "missing input files"
23         exit 1
24 fi
25
26 rm -rf $out_dir $out_opt_dir
27 mkdir $out_dir 2>/dev/null && mkdir $out_opt_dir 2>/dev/null || true
28
29
30 # files for SD boot
31 cp ${sysf_in}x-load.bin.ift ${out_opt_dir}MLO
32 cp ${sysf_in}u-boot.bin_updater ${out_opt_dir}u-boot.bin
33
34
35 # sysf.tgz
36 cd $sysf_in
37 tar czvf sysf.tgz u-boot.bin uImage
38 cd ..
39 mv -f ${sysf_in}sysf.tgz ${out_dir}
40
41
42 # rootfs
43 dd if=/dev/zero of=$rdfile bs=1M count=8
44 mkfs.ext2 -F $rdfile 
45 sudo mount -o loop $rdfile /mnt/tmp
46 sudo cp -r $rd_input/* /mnt/tmp/
47 sudo umount /mnt/tmp
48 cat $rdfile | gzip -9 > $rdfile_out
49 rm $rdfile
50
51
52 # boot.scr
53 dd if=/dev/zero of=$boot_scr_tmp_scr bs=1 count=4020
54 dd if=/dev/zero of=$boot_scr_tmp bs=4K count=800
55
56 # 000000 - 000fff: u-boot header, the script
57 dd if=script.txt of=$boot_scr_tmp_scr conv=notrunc bs=1
58 # 001000 - 020fff: x-load
59 dd if=$rd_input/usr/local/erasednandblk of=$boot_scr_tmp conv=notrunc bs=4K
60 dd if=${sysf_in}x-load.bin.ift of=$boot_scr_tmp conv=notrunc bs=4K
61 # 021000 - 320fff: uImage
62 dd if=${sysf_in}uImage_updater of=$boot_scr_tmp conv=notrunc bs=4K seek=32
63 # 321000 - end:    ramdisk
64 cat $boot_scr_tmp $rdfile_out > $boot_scr_tmp2
65 # adjust for u-boot header
66 #dd if=$boot_scr_tmp2 of=$boot_scr_tmp bs=72 skip=1
67 tmp/mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n "script" \
68         -d $boot_scr_tmp_scr:$boot_scr_tmp2 ${out_dir}boot.scr
69 rm $boot_scr_tmp $boot_scr_tmp2 $boot_scr_tmp_scr
70
71 # release zip
72 cd ${out_dir}
73 zip -9 $zipfile sysf.tgz boot.scr
74 mv -f $zipfile ../tmp/
75 cd ..