There's another way to create images for flashing a kernel to a different kernel mtd definition by just using standard linux commands.
So, from my point of view I would not "complicate" the usage of the wrt350nv2-webbuilder for this.
Note that all sizes for dd have to be stated in decimal values, this is automatically done by the builtin bash command 'declare' and its option -i.
The latest version of the my script "create_images_orion.sh" is always available at http://ftp.maddes.net/openwrt/.
Either create a build yourself or download it from the OpenWrt snapshots as mentioned here:
BOARD='orion'
BUILDTYPE='snapshot'
FSTYPE='squashfs'
mkdir bin || rm bin/*
cd bin
# get latest uImage for router and pad it
wget http://downloads.openwrt.org/snapshots/trunk/orion/openwrt-wrt350nv2-uImage
dd if=openwrt-wrt350nv2-uImage of=openwrt-wrt350nv2-uImage.${BUILDTYPE}.${FSTYPE}.padded bs=1024k conv=sync
# get latest openwrt-orion-squashfs.img
wget http://downloads.openwrt.org/snapshots/trunk/orion/openwrt-orion-${FSTYPE}.img
# extract general uImage (padded to 1024k) from openwrt-orion-squashfs.img
#dd if=openwrt-orion-${FSTYPE}.img of=uImage.padded bs=1024k count=1
# extract root.squashfs (padded to 128k) from openwrt-orion-squashfs.img
dd if=openwrt-orion-${FSTYPE}.img of=root.${FSTYPE}.${BOARD}.${BUILDTYPE} bs=128k skip=8
# create combined flash image (uImage + padding + rootfs)
cat openwrt-wrt350nv2-uImage.${BUILDTYPE}.${FSTYPE}.padded root.${FSTYPE}.${BOARD}.${BUILDTYPE} >openwrt-wrt350nv2-${FSTYPE}.${BUILDTYPE}.img
cd ..
# create further images if wanted
~/create_images_orion.sh "${BUILDTYPE}" "${FSTYPE}"
~/create_images_orion.sh (to copy configs and create images directly after a build, also works with above mentioned downloads)
#!/bin/bash
#
# Intended Usage:
#
# BOARD='orion'
#
# BUILDTYPE='tun'
# - or -
# BUILDTYPE='all'
#
# FSTYPE='squashfs'
# - or -
# FSTYPE='ramdisk'
#
# mkdir bin || rm bin/*
# LOGFILE="bin/compilelog.${BOARD}.${BUILDTYPE}.${FSTYPE}.`svnversion`.`date +%Y%m%d_%H%M%S`.log"
# script -f -c 'make V=99 IGNORE_ERRORS=m' "${LOGFILE}" ; bzip2 "${LOGFILE}" ; ~/create_images_orion.sh "${BUILDTYPE}" "${FSTYPE}" ; echo -e '\a'
#
# ToDo:
# - check sizes of existing files, if mismatch then error message so user can react on it
# - check md5sum of existing files, if mismatch then error message so user can react on it
#
# check parameters
rc=0
#
if [ -z "$1" ]
then
echo 'build type not stated (e.g. tun or all)'
rc=1
fi
#
if [ -z "$2" ]
then
echo 'filesystem type not stated (squashfs or ramdisk)'
rc=1
fi
#
[ "${rc}" -ne 0 ] && exit "${rc}"
# define mtd and erase sizes
KERNELMTDSIZE='0x00100000'
declare -i ROOTFSMTDSIZE=0x00750000-"${KERNELMTDSIZE}"
# define kernel file names
KERNELORG='openwrt-wrt350nv2-uImage'
KERNEL="${KERNELORG}.$1.$2"
KERNELPAD="${KERNEL}.padded"
# define rootfs file names
FSIMGORG='openwrt-orion-squashfs.img'
FSIMG="openwrt-orion-squashfs.$1.img"
#
ROOTFSORG='root.squashfs'
ROOTFS="${ROOTFSORG}.orion.$1"
ROOTFSPAD="${ROOTFS}.padded"
# define kernel+rootfs merge file names
MERGE="${KERNELPAD}+${ROOTFSORG}"
MERGEPAD="${MERGE}.padded"
# define misc file names
MD5SUMS="md5sums.orion.$1.$2"
SPLITFILE="${MERGEPAD}"
# define integer variables for dd
declare -i SIZE1
declare -i SIZE2
# switch to bin folder
cd bin ; rc=$?
[ "${rc}" -ne 0 ] && exit "${rc}"
# create md5sums file
[ ! -f "${MD5SUMS}" ] && touch "${MD5SUMS}"
# copy general config
CONFIG="config.orion.$1.$2"
[ ! -f "${CONFIG}" ] && cp ../.config "${CONFIG}"
grep -e "${CONFIG}" "${MD5SUMS}" >/dev/null || md5sum --text "${CONFIG}" >>"${MD5SUMS}"
# copy kernel config
CONFIG="kconfig-orion.$1.$2"
[ ! -f "${CONFIG}" ] && cp ../tmp/.kconfig-orion "${CONFIG}"
grep -e "${CONFIG}" "${MD5SUMS}" >/dev/null || md5sum --text "${CONFIG}" >>"${MD5SUMS}"
# checksum compilelog
grep -e "compilelog.orion.$1.$2.*.*.log.bz2" "${MD5SUMS}" >/dev/null || md5sum --binary compilelog.orion.$1.$2.*.*.log.bz2 >>"${MD5SUMS}"
# rename kernel image
[ ! -f "${KERNEL}" ] && mv "${KERNELORG}" "${KERNEL}"
grep -e "${KERNEL}" "${MD5SUMS}" >/dev/null || md5sum --binary "${KERNEL}" >>"${MD5SUMS}"
## --- squashfs build only begin ---
if [ "$2" == "squashfs" ]
then
# rename squashfs image
[ ! -f "${FSIMG}" ] && mv "${FSIMGORG}" "${FSIMG}"
grep -e "${FSIMG}" "${MD5SUMS}" >/dev/null || md5sum --binary "${FSIMG}" >>"${MD5SUMS}"
# get latest rootfs
[ ! -f "${ROOTFS}" ] && dd if="../build_dir/linux-orion_generic/${ROOTFSORG}" of="${ROOTFS}" bs=128k conv=sync
grep -e "${ROOTFS}" "${MD5SUMS}" >/dev/null || md5sum --binary "${ROOTFS}" >>"${MD5SUMS}"
# create a padded kernel image
SIZE1="${KERNELMTDSIZE}"
[ ! -f "${KERNELPAD}" ] && {
echo "Creating ${KERNELPAD}..."
dd if="${KERNEL}" of="${KERNELPAD}" bs="${SIZE1}" conv=sync
}
SIZE2=`stat -c %s "${KERNELPAD}"`
[ "${SIZE2}" -ne "${SIZE1}" ] && { echo "STOP!!! Kernel too big!!!"; exit 1 ; }
grep -e "${KERNELPAD}" "${MD5SUMS}" >/dev/null || md5sum --binary "${KERNELPAD}" >>"${MD5SUMS}"
# create a concatenated image (for split and flashing in U-Boot)
[ ! -f "${MERGE}" ] && cat "${KERNELPAD}" "${ROOTFS}" >"${MERGE}"
grep -e "${MERGE}" "${MD5SUMS}" >/dev/null || md5sum --binary "${MERGE}" >>"${MD5SUMS}"
# create a padded rootfs image
SIZE1="${ROOTFSMTDSIZE}"
[ ! -f "${ROOTFSPAD}" ] && {
echo "Creating ${ROOTFSPAD}..."
dd if="${ROOTFS}" of="${ROOTFSPAD}" bs="${SIZE1}" conv=sync
}
SIZE2=`stat -c %s "${ROOTFSPAD}"`
[ "${SIZE2}" -ne "${SIZE1}" ] && { echo "STOP!!! rootfs too big!!!"; exit 1 ; }
grep -e "${ROOTFSPAD}" "${MD5SUMS}" >/dev/null || md5sum --binary "${ROOTFSPAD}" >>"${MD5SUMS}"
# create a concatenated padded image
[ ! -f "${MERGEPAD}" ] && cat "${KERNELPAD}" "${ROOTFSPAD}" >"${MERGEPAD}"
grep -e "${MERGEPAD}" "${MD5SUMS}" >/dev/null || md5sum --binary "${MERGEPAD}" >>"${MD5SUMS}"
### split for flashing in Linux with different mtd sizes
echo "Splitting '${SPLITFILE}' with kernel mtd size of ${KERNELMTDSIZE} in..."
for OTHERSIZE in '0x00100000' '0x00120000' '0x001A0000'
do
[ "${OTHERSIZE}" == "${KERNELMTDSIZE}" ] && continue
#
SIZE1="${OTHERSIZE}"
#
IMGFILE="img.wrt350nv2.$1.$2.${OTHERSIZE}.mtd0"
[ ! -f "${IMGFILE}" ] && {
echo "...mtd0 for kernel mtd size ${OTHERSIZE}"
dd if="${SPLITFILE}" of="${IMGFILE}" bs="${SIZE1}" count=1
}
grep -e "${IMGFILE}" "${MD5SUMS}" >/dev/null || md5sum --binary "${IMGFILE}" >>"${MD5SUMS}"
#
IMGFILE="img.wrt350nv2.$1.$2.${OTHERSIZE}.mtd1"
[ ! -f "${IMGFILE}" ] && {
echo "...mtd1 for kernel mtd size ${OTHERSIZE}"
dd if="${SPLITFILE}" of="${IMGFILE}" bs="${SIZE1}" skip=1
}
grep -e "${IMGFILE}" "${MD5SUMS}" >/dev/null || md5sum --binary "${IMGFILE}" >>"${MD5SUMS}"
done
fi
# --- squashfs build only end ---
# go back up
cd ..
Flashing in U-Boot:
# temporary change network settings to fit your network
setenv ipaddr 10.0.0.99
setenv serverip 10.0.0.1
# erase and unprotect flash for writing
erase 0xff800000 0xfff4ffff
protect off 0xff800000 0xfff4ffff
# flash kernel + rootfs
tftpboot 0x400000 "openwrt-wrt350nv2-uImage.snapshot.squashfs.padded+root.squashfs"
# recognize the download size in its output, it will be used in the next command
cp.b 0x400000 0xff800000 <transferred bytes in hex/0x>
reset
Flashing in Linux:
Copy files via SFTP to /tmp or get them with wget over http or ftp.
To copy a new kernel and rootfs to the router via SCP/SFTP checkout this wiki page
Flashing with same kernel mtd size:
# check mtd sizes
cat /proc/mtd
ls -la /dev/mtdblock*
dd if=/tmp/openwrt-wrt350nv2-uImage.snapshot.squashfs.padded of=/dev/mtdblock0 ; echo -e '\a' #ring the bell when done
sync ; dd if=/tmp/root.squashfs of=/dev/mtdblock1 ; rc=$? ; \
[ ${rc} -eq 0 ] && reboot ; echo -e '\a' # reboot immediately so the new rootfs is not destroyed by any action (and force you to use U-Boot to reflash)
Flashing with different kernel mtd sizes (here 0x00120000):
# check mtd sizes
cat /proc/mtd
ls -la /dev/mtdblock*
sync ; dd if=/tmp/img.wrt350nv2.snapshot.squashfs.0x00120000.mtd0 of=/dev/mtdblock0 ; rc=$? ; \
[ ${rc} -eq 0 ] && { dd if=/tmp/img.wrt350nv2.snapshot.squashfs.0x00120000.mtd1 of=/dev/mtdblock1 ; rc=$? ; } ; \
[ ${rc} -eq 0 ] && reboot ; echo -e '\a' # reboot immediately so the new rootfs is not destroyed by any action (and force you to use U-Boot to reflash)
Flashing on stock firmware:
# check mtd sizes
cat /proc/mtd
ls -la /dev/mtdblock*
sync ; dd if=/tmp/openwrt-wrt350nv2-uImage.padded+root.squashfs.padded of=/dev/mtdblock0 ; rc=$? ; \
[ ${rc} -eq 0 ] && reboot ; echo -e '\a' # reboot immediately so the new rootfs is not destroyed by any action (and force you to use U-Boot to reflash)
Update:
Even faster (less dd action) and simpler way by calculating the correct pad size via bash's 'declare' and standard stat command.
Update 2:
Flashing information
Update 3:
Updated to padded images to reduce risk of destroyed rootfs.
Splitting for different mtd sizes is now done in a second.
Update 4:
Added sync command to reduce risk of destroyed rootfs mtd partition.
Update 5:
With sync and immediate reboot I never had any flashing issues again.
Outcommented all lines with padded rootfs.
Updated flashing commands to check for errors and not rebooting if anything failed.
Update 6:
Had another flashing despite using sync and immediate reboot.
Difference was that the kernel mtd size was downsized from 0x00120000 to 0x00100000.
Further tests showed that upsizing works with unpadded images, but downsizing needs padded images.
Hence reverted back to padded images for different mtd sizes.
Update 7:
New script, works with own compiled builds and snapshot downloads.
(Last edited by maddes.b on 3 Apr 2010, 16:59)