This time we will build modified version of D-Link DNS-323 firmware.
Flashing modified firmware binary image can brick your device voiding warranty. Use at own risk
As an example we will modify security mode in Samba configuration file and put it in "defaults" section of firmware.
First lets cd in directory which will hold our new firmware and unpack current firmware (we will experiment on version 1.04).
$ cd ~/devel/1.04custom/
$ parseFirmware.py ~/DNS323.1.04
Kernel offset: 64
Kernel length: 1426484
Ramdisk offset: 1426548
Ramdisk length: 6426240
Defaults offset: 7852788
Defaults length: 7448
Kernel checksum: 56548743
Ramsdisk checksum: 3413102303
Defaults checksum: 3639957044
There are three new files in the current directory now.
$ ls
default.tar.gz Ramdisk.gz uImage
default.tar.gz and uImage can be safely ignored. We will place them in new firmware binary unmodified.
Create directory to mount ramdisk image.
$ mkdir ramdisk
Unpack Ramdisk.gz and mount it on newly created directory.
$ gunzip ./Ramdisk.gz
$ sudo mount -o loop Ramdisk ./ramdisk
If we look in the ramdisk directory we'll see a image.cfs file. This file contains default parameters for the device (among other things).
$ ls ./ramdisk
bin etc image.cfs lost+found proc sbin
tmp var welcome.msg dev home lib
mnt root sys usr web
Now we need to mount image.cfs somewhere and copy its contents to start modifications.
$ sudo mount -o loop ramdisk/image.cfs /mnt
$ mkdir tmpcramfs
$ cp -R /mnt/* ./tmpcramfs
$ sudo umount /mnt
We need to modify file smb.default located at tmpcramfs/default directory. Open this file in your favorite editor and change this line:
security = SHARE
to look like this:
security = USER
Save the file.
Next we must create new cramfs image with our modifications and put it back at ramdisk image.
To create cramfs image and put it back at ramdisk image issue these commands:
$ sudo mkcramfs tmpcramfs image.cfs
$ sudo cp image.cfs ramdisk/
If we just umount ramdisk filesystem and gzip an image file we won't get original compression rate as some dirty inodes of ramdisk filesystem contain remnants of old image.cfs.
So we create new ramdisk filesystem image and copy contents of modified ramdisk there.
$ sudo dd if=/dev/zero of=new-ramdisk.img bs=1k count=8k
$ sudo mkfs.ext2 -F new-ramdisk.img
$ sudo mount -o loop new-ramdisk.img /mnt
$ sudo cp -R ramdisk/* /mnt/
$ sudo umount ramdisk
$ sudo umount /mnt
Next we should gzip new ramdisk filesystem image and use it to create u-boot ramdisk image.
$ gzip new-ramdisk.img
$ mkimage -a 0x800000 -e 0x800000 -n 'boot ramdisk' -A arm \
-O linux -T ramdisk -C gzip -d new-ramdisk.img.gz uRamdisk
Copy goahead/LINUX/custom.h file here (available at firmware sources from D-Link).
At this time we should have four files in our 1.04custom directory
One last step remains to build binary firmware image. Run the merge-FrodoII utility.
$ merge-FrodoII
size of structure = 64
Product ID = 7
Custom ID = 1
Model ID = 1
Sub ID = 1
CH off 1 = 64
CH len 1 = 1426484
CH off 2 = 1426548
CH len 2 = 6370700
CH off 3 = 7797248
CH len 3 = 7448
CH checksum 1 = 35EDD87
CH checksum 2 = CA36C95B
CH checksum 3 = D8F55634
Next_offset = 0x00000000
Firmware binary image will be named FrodoII-firmware.