tools/mtd-utils: avoid linking libm statically
[openwrt/openwrt.git] / scripts / om-fwupgradecfg-gen.sh
1 #/bin/sh
2 #
3 # Copyright (C) 2011 OpenWrt.org
4 #
5 # This is free software, licensed under the GNU General Public License v2.
6 # See /LICENSE for more information.
7 #
8
9 usage() {
10 echo "Usage: $0 <OM2P|OM5P|MR600|MR900|MR1750> <out file path> <kernel path> <rootfs path>"
11 rm -f $CFG_OUT
12 exit 1
13 }
14
15 [ "$#" -lt 4 ] && usage
16
17 CE_TYPE=$1
18 CFG_OUT=$2
19 KERNEL_PATH=$3
20 ROOTFS_PATH=$4
21
22 case $CE_TYPE in
23 OM2P)
24 MAX_PART_SIZE=7168
25 KERNEL_FLASH_ADDR=0x1c0000
26 FLASH_BS=262144
27 MD5_SKIP_BLOCKS=1
28 ;;
29 OM5P|MR600|MR900|MR1750)
30 MAX_PART_SIZE=7808
31 KERNEL_FLASH_ADDR=0xb0000
32 FLASH_BS=65536
33 MD5_SKIP_BLOCKS=4
34 ;;
35 *)
36 echo "Error - unsupported ce type: $CE_TYPE"
37 exit 1
38 ;;
39 esac
40
41 CHECK_BS=65536
42
43 KERNEL_SIZE=$(stat -c%s "$KERNEL_PATH")
44 KERNEL_MD5=$(md5=$(md5sum $KERNEL_PATH); echo ${md5%% *})
45 KERNEL_PART_SIZE=$(size=$(($KERNEL_SIZE / $FLASH_BS)); [ $(($size * $FLASH_BS)) -lt $KERNEL_SIZE ] && size=$(($size + 1)); echo $(($size * $FLASH_BS / 1024)))
46
47 ROOTFS_FLASH_ADDR=$(addr=$(($KERNEL_FLASH_ADDR + ($KERNEL_PART_SIZE * 1024))); printf "0x%x" $addr)
48 ROOTFS_SIZE=$(stat -c%s "$ROOTFS_PATH")
49 ROOTFS_CHECK_BLOCKS=$((($ROOTFS_SIZE / $CHECK_BS) - $MD5_SKIP_BLOCKS))
50 ROOTFS_MD5=$(md5=$(dd if=$ROOTFS_PATH bs=$CHECK_BS count=$ROOTFS_CHECK_BLOCKS 2>&- | md5sum); echo ${md5%% *})
51 ROOTFS_MD5_FULL=$(md5=$(md5sum $ROOTFS_PATH); echo ${md5%% *})
52 ROOTFS_CHECK_SIZE=$(printf '0x%x' $(($ROOTFS_CHECK_BLOCKS * $CHECK_BS)))
53 ROOTFS_PART_SIZE=$(($MAX_PART_SIZE - $KERNEL_PART_SIZE))
54
55 cat << EOF > $CFG_OUT
56 [vmlinux]
57 filename=kernel
58 md5sum=$KERNEL_MD5
59 filemd5sum=$KERNEL_MD5
60 flashaddr=$KERNEL_FLASH_ADDR
61 checksize=0x0
62 cmd_success=setenv bootseq 1,2; setenv kernel_size_1 $KERNEL_PART_SIZE; saveenv
63 cmd_fail=reset
64
65 [rootfs]
66 filename=rootfs
67 md5sum=$ROOTFS_MD5
68 filemd5sum=$ROOTFS_MD5_FULL
69 flashaddr=$ROOTFS_FLASH_ADDR
70 checksize=$ROOTFS_CHECK_SIZE
71 cmd_success=setenv bootseq 1,2; setenv kernel_size_1 $KERNEL_PART_SIZE; setenv rootfs_size_1 $ROOTFS_PART_SIZE; saveenv
72 cmd_fail=reset
73 EOF