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