iw: update to version 4.14
[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|OM5PAC|MR600|MR900|MR1750|A60|A42> <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 SIZE_FACTOR=1
29 SIZE_FORMAT="%d"
30 ;;
31 OM5P|OM5PAC|MR600|MR900|MR1750|A60)
32 MAX_PART_SIZE=7808
33 KERNEL_FLASH_ADDR=0xb0000
34 FLASH_BS=65536
35 MD5_SKIP_BLOCKS=4
36 SIZE_FACTOR=1
37 SIZE_FORMAT="%d"
38 ;;
39 A42)
40 MAX_PART_SIZE=15616
41 KERNEL_FLASH_ADDR=0x180000
42 FLASH_BS=65536
43 MD5_SKIP_BLOCKS=4
44 SIZE_FACTOR=1024
45 SIZE_FORMAT="0x%08x"
46 ;;
47 *)
48 echo "Error - unsupported ce type: $CE_TYPE"
49 exit 1
50 ;;
51 esac
52
53 CHECK_BS=65536
54
55 KERNEL_SIZE=$(stat -c%s "$KERNEL_PATH")
56 KERNEL_MD5=$(mkhash md5 $KERNEL_PATH)
57 KERNEL_SHA256=$(mkhash sha256 $KERNEL_PATH)
58 KERNEL_PART_SIZE_KB=$(size=$(($KERNEL_SIZE / $FLASH_BS)); [ $(($size * $FLASH_BS)) -lt $KERNEL_SIZE ] && size=$(($size + 1)); echo $(($size * $FLASH_BS / 1024)))
59 KERNEL_PART_SIZE=$(printf $SIZE_FORMAT $(($KERNEL_PART_SIZE_KB * $SIZE_FACTOR)))
60
61 ROOTFS_FLASH_ADDR=$(addr=$(($KERNEL_FLASH_ADDR + ($KERNEL_PART_SIZE_KB * 1024))); printf "0x%x" $addr)
62 ROOTFS_SIZE=$(stat -c%s "$ROOTFS_PATH")
63 ROOTFS_CHECK_BLOCKS=$((($ROOTFS_SIZE / $CHECK_BS) - $MD5_SKIP_BLOCKS))
64 ROOTFS_MD5=$(dd if=$ROOTFS_PATH bs=$CHECK_BS count=$ROOTFS_CHECK_BLOCKS 2>&- | mkhash md5)
65 ROOTFS_MD5_FULL=$(mkhash md5 $ROOTFS_PATH)
66 ROOTFS_SHA256_FULL=$(mkhash sha256 $ROOTFS_PATH)
67 ROOTFS_CHECK_SIZE=$(printf '0x%x' $(($ROOTFS_CHECK_BLOCKS * $CHECK_BS)))
68 ROOTFS_PART_SIZE_KB=$(($MAX_PART_SIZE - $KERNEL_PART_SIZE_KB))
69 ROOTFS_PART_SIZE=$(printf $SIZE_FORMAT $(($ROOTFS_PART_SIZE_KB * $SIZE_FACTOR)))
70
71 cat << EOF > $CFG_OUT
72 [vmlinux]
73 filename=kernel
74 md5sum=$KERNEL_MD5
75 filemd5sum=$KERNEL_MD5
76 filesha256sum=$KERNEL_SHA256
77 flashaddr=$KERNEL_FLASH_ADDR
78 checksize=0x0
79 cmd_success=setenv bootseq 1,2; setenv kernel_size_1 $KERNEL_PART_SIZE; saveenv
80 cmd_fail=reset
81
82 [rootfs]
83 filename=rootfs
84 md5sum=$ROOTFS_MD5
85 filemd5sum=$ROOTFS_MD5_FULL
86 filesha256sum=$ROOTFS_SHA256_FULL
87 flashaddr=$ROOTFS_FLASH_ADDR
88 checksize=$ROOTFS_CHECK_SIZE
89 cmd_success=setenv bootseq 1,2; setenv kernel_size_1 $KERNEL_PART_SIZE; setenv rootfs_size_1 $ROOTFS_PART_SIZE; saveenv
90 cmd_fail=reset
91 EOF