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