1 # The U-Boot loader of the OM2P requires image sizes and checksums to be
2 # provided in the U-Boot environment.
3 # The OM2P comes with 2 main partitions - while one is active sysupgrade
4 # will flash the other. The boot order is changed to boot the newly
5 # flashed partition. If the new partition can't be booted due to upgrade
6 # failures the previously used partition is loaded.
16 local section
=$2 our_section
=0
17 local param
=$3 our_param
=
21 [ "$cfg_opt" = "[$section]" ] && our_section
=1 && continue
22 [ "$our_section" = "1" ] ||
continue
24 our_param
=$
(echo ${cfg_opt%%=*})
25 [ "$param" = "$our_param" ] && echo ${cfg_opt##*=} && break
29 # make sure we got uboot-envtools and fw_env.config copied over to the ramfs
30 platform_add_ramfs_ubootenv
()
32 [ -e /usr
/sbin
/fw_printenv
] && install_bin
/usr
/sbin
/fw_printenv
/usr
/sbin
/fw_setenv
33 [ -e /etc
/fw_env.config
] && install_file
/etc
/fw_env.config
35 append sysupgrade_pre_upgrade platform_add_ramfs_ubootenv
37 platform_check_image_om2p
()
41 local fw_printenv
=/usr
/sbin
/fw_printenv
42 local img_board_target
= img_num_files
= i
=0
43 local cfg_name
= kernel_name
= rootfs_name
=
46 # Combined Extended Image v1
48 img_board_target
=$
(trim $
(dd if="$img_path" bs
=4 skip
=1 count
=8 2>/dev
/null
))
49 img_num_files
=$
(trim $
(dd if="$img_path" bs
=2 skip
=18 count
=1 2>/dev
/null
))
52 echo "Invalid image ($img_magic). Use combined extended images on this platform"
57 case "$img_board_target" in
61 echo "Invalid board target ($img_board_target). Use the correct image for this platform"
66 [ $img_num_files -ne 3 ] && {
67 echo "Invalid number of embedded images ($img_num_files). Use the correct image for this platform"
71 cfg_name
=$
(trim $
(dd if="$img_path" bs
=2 skip
=19 count
=16 2>/dev
/null
))
73 [ "$cfg_name" != "fwupgrade.cfg" ] && {
74 echo "Invalid embedded config file ($cfg_name). Use the correct image for this platform"
78 kernel_name
=$
(trim $
(dd if="$img_path" bs
=2 skip
=55 count
=16 2>/dev
/null
))
80 [ "$kernel_name" != "kernel" ] && {
81 echo "Invalid embedded kernel file ($kernel_name). Use the correct image for this platform"
85 rootfs_name
=$
(trim $
(dd if="$img_path" bs
=2 skip
=91 count
=16 2>/dev
/null
))
87 [ "$rootfs_name" != "rootfs" ] && {
88 echo "Invalid embedded kernel file ($rootfs_name). Use the correct image for this platform"
92 [ ! -x "$fw_printenv" ] && {
93 echo "Please install uboot-envtools!"
97 [ ! -r "/etc/fw_env.config" ] && {
98 echo "/etc/fw_env.config is missing"
105 platform_do_upgrade_om2p
()
108 local kernel_start_addr
= kernel_size
= kernel_md5
=
109 local rootfs_size
= rootfs_checksize
= rootfs_md5
=
110 local kernel_bsize
= total_size
=7340032
111 local data_offset
=$
((64 * 1024)) block_size
=$
((256 * 1024)) offset
=
112 local uboot_env_upgrade
="/tmp/fw_env_upgrade"
113 local cfg_size
= kernel_size
= rootfs_size
=
116 [ -f "$CONF_TAR" -a "$SAVE_CONFIG" -eq 1 ] && append
="-j $CONF_TAR"
118 cfg_size
=$
(dd if="$img_path" bs
=2 skip
=35 count
=4 2>/dev
/null
)
119 kernel_size
=$
(dd if="$img_path" bs
=2 skip
=71 count
=4 2>/dev
/null
)
120 rootfs_size
=$
(dd if="$img_path" bs
=2 skip
=107 count
=4 2>/dev
/null
)
122 cfg_content
=$
(dd if="$img_path" bs
=1 skip
=$data_offset count
=$
(echo $
((0x
$cfg_size))) 2>/dev
/null
)
124 kernel_md5
=$
(cfg_value_get
"$cfg_content" "vmlinux" "md5sum")
125 rootfs_md5
=$
(cfg_value_get
"$cfg_content" "rootfs" "md5sum")
126 rootfs_checksize
=$
(cfg_value_get
"$cfg_content" "rootfs" "checksize")
128 if [ "$((0x$kernel_size % $block_size))" = "0" ]
130 kernel_bsize
=$
(echo $
((0x
$kernel_size)))
132 kernel_bsize
=$
((0x
$kernel_size + ($block_size - (0x
$kernel_size % $block_size))))
135 mtd
-q erase inactive
137 offset
=$
(echo $
(($data_offset + 0x
$cfg_size + 0x
$kernel_size)))
138 dd if="$img_path" bs
=1 skip
=$offset count
=$
(echo $
((0x
$rootfs_size))) 2>&- | mtd
-n -p $kernel_bsize $append write - "inactive"
140 offset
=$
(echo $
(($data_offset + 0x
$cfg_size)))
141 dd if="$img_path" bs
=1 skip
=$offset count
=$
(echo $
((0x
$kernel_size))) 2>&- | mtd
-n write - "inactive"
143 rm $uboot_env_upgrade 2>&-
145 if [ "$(grep 'mtd3:.*inactive' /proc/mtd)" ]
147 printf "kernel_size_1 %u\n" $
(($kernel_bsize / 1024)) >> $uboot_env_upgrade
148 printf "rootfs_size_1 %u\n" $
((($total_size - $kernel_bsize) / 1024)) >> $uboot_env_upgrade
149 printf "bootseq 1,2\n" >> $uboot_env_upgrade
150 kernel_start_addr
=0x9f1c0000
152 printf "kernel_size_2 %u\n" $
(($kernel_bsize / 1024)) >> $uboot_env_upgrade
153 printf "rootfs_size_2 %u\n" $
((($total_size - $kernel_bsize) / 1024)) >> $uboot_env_upgrade
154 printf "bootseq 2,1\n" >> $uboot_env_upgrade
155 kernel_start_addr
=0x9f8c0000
158 printf "vmlinux_start_addr %s\n" $kernel_start_addr >> $uboot_env_upgrade
159 printf "vmlinux_size 0x%s\n" $kernel_size >> $uboot_env_upgrade
160 printf "vmlinux_checksum %s\n" $kernel_md5 >> $uboot_env_upgrade
161 printf "rootfs_start_addr 0x%x\n" $
(($kernel_start_addr + $kernel_bsize)) >> $uboot_env_upgrade
162 printf "rootfs_size %s\n" $rootfs_checksize >> $uboot_env_upgrade
163 printf "rootfs_checksum %s\n" $rootfs_md5 >> $uboot_env_upgrade
165 fw_setenv
-s $uboot_env_upgrade ||
{
166 echo "failed to update U-Boot environment"