#!/bin/sh
# new image size
# block size -> 64k
bs=65536
fimage=tplink3.bin
flash_size=$(ls -l $fimage | cut -d\  -f 5)
num_blocks=$(($flash_size/$bs))
# 64 blocks, 64kilobyte each
dd if=$fimage of=data.bin bs=$bs count=1 skip=1
dd if=$fimage of=art.bin bs=$bs count=1 skip=$(($num_blocks-1))

new_image_size=$((16777216/$bs - 3))
dd if=/dev/zero ibs=$bs count=$new_image_size | tr "\000" "\377" >FFs.bin

# build pepe2k bootloader at first: see https://github.com/pepe2k/u-boot_mod
cat uboot_for_tp-link_tl-wr703n.bin \
    data.bin FFs.bin art.bin > wr703_bootloader_data_empty_art.bin

