#!/bin/bash

echo "Replacing ramdisk with $1"

# Extract the Kernel from firmware image
dd if=C61200-WX-2.00.01-61002-A0.img bs=13376 skip=1 of=kernel.gz
cp C61200-WX-2.00.01-61002-A0.img C61200-WX-custom.img
gunzip kernel.gz
# Overwrite the existing ramdisk with our new one
dd if=/dev/zero of=kernel bs=1 seek=2031616 conv=notrunc count=1929216
dd if=$1 of=kernel bs=2031616 seek=1 conv=notrunc
gzip kernel -v9

# Clear a space for our image.
dd if=/dev/zero of=C61200-WX-custom.img bs=13376 seek=1 conv=notrunc count=192

# Put it back into the firmware image.
dd if=kernel.gz of=C61200-WX-custom.img bs=13376 seek=1 conv=notrunc
rm kernel.gz

# Create a tftp compatible image
dd if=C61200-WX-custom.img of=C61200-WX-custom.raw bs=112 skip=1
./create_header C61200-WX-custom.raw

rm C61200-WX-custom.raw

