OK try this code on as many kirkwood devices as possible, it just prints out what to set things to
$this->bbcode_second_pass_code('', '
#!/bin/bash
mac=$(tr 'a-z' 'A-Z' < /sys/class/net/eth0/address)
lastendoffset=0
mtdparts="mtdparts=orion_nand:"
for mtd in /sys/class/mtd/mtd*;
do
if [ "${mtd: -2:2}" != "ro" ]; then
read offset < ${mtd}/offset
printf -v offsethex "0x%X" ${offset}
read size < ${mtd}/size
printf -v sizehex "0x%X" ${size}
read name < ${mtd}/name
read flags < ${mtd}/flags
endoffset=$((${offset}+${size}))
# echo $mtd $offset $size $endoffset $name
if [ ${lastendoffset} -gt 0 ]; then
mtdparts="${mtdparts},"
fi
if [ $offset -eq $lastendoffset ]; then
mtdparts="${mtdparts}${sizehex}(${name})"
else
mtdparts="${mtdparts}${sizehex}@${offset}(${name})"
fi
# partion starts right place, big enough, and writeable
if [ $offset -eq 0 -a $endoffset -ge 524288 -a $(( ${flags} & 0x400 )) -ne 0 ]; then
# this assumes that the /dev name is the same as /sys
# its would be better to work from major minor numbers
ubootpart=/dev/${mtd#/sys/class/mtd/}
read ubooterase < ${mtd}/erasesize
fi
# partition starts before where we want, finishes after, and is writeable
if [ $offset -le 786432 -a $endoffset -ge 917504 -a $(( ${flags} & 0x400)) -ne 0 ]; then
ubootenvpart=/dev/${mtd#/sys/class/mtd/}
ubootenvoffset=$((786432-${offset}))
printf -v ubootenvoffsethex "0x%X" ${ubootenvoffset}
read ubootenverase < ${mtd}/erasesize
printf -v ubootenverasehex "0x%X" ${ubootenverase}
fi
lastendoffset=${endoffset}
fi
done
echo mtdparts=${mtdparts}
echo uboot ${ubootpart}
echo fw_env.config ${ubootenvpart} ${ubootenvoffsethex} 0x20000 ${ubootenverasehex}
echo ethernet mac ${mac}
if [ $ubooterase -eq 131072 ] ; then
echo clear uboot flash_erase ${ubootpart} 0 4
echo write uboot nandwrite ${ubootpart} /boot/uboot-nsa325.kwb
fi
if [ $ubootenverase -eq 131072 ] ; then
echo clear uboot env flash_erase ${ubootenvpart} ${ubootenvoffsethex} 1
echo write uboot env nandwrite -s ${ubootenvoffsethex} ${ubootenvpart} /boot/uboot-nsa325.env
fi
')
Granted it far more verbose than the current install.
It takes parameters from /sys
Tries to keep the mtd partitions the same as currently, and sets up fw_env.config for the current partitions.
Its reasonably robust (but some minor things like the mtd name been the same in /dev and /sys/class/mtd - really should check major and minor numbers). Also assumes that the ethernet card is eth0 - so systemd isn't doing any renaming ....
Interesting tried to see what it would do with the standard install:
http://de3.mirror.archlinuxarm.org/os/n ... arm.tar.gzwhere usb_key_func.sh.2 still uses mtdparts=nand_mtd:
Now that mtdparts is totally ignored when kernel boots, it uses another version, that is reasonable for the nsa325. Can't work out where it comes from, but suspect its in the flattened device tree.
Anyway conisder code above RFC - what do others think?
On my NSA325 it gives:
$this->bbcode_second_pass_code('', '
mtdparts=mtdparts=orion_nand:0xC0000(uboot),0x40000(uboot_env),0x80000(old_uboot_env),0x80000(key_store),0x80000(info),0xA00000(etc),0xA00000(kernel_1),0x2FC0000(rootfs1),0xA00000(kernel_2),0x2FC0000(rootfs2)
uboot /dev/mtd0
fw_env.config /dev/mtd1 0x0 0x20000 0x20000
ethernet mac XX:XX:XX:XX:XX:XX
clear uboot flash_erase /dev/mtd0 0 4
write uboot nandwrite /dev/mtd0 /boot/uboot-nsa325.kwb
clear uboot env flash_erase /dev/mtd1 0x0 1
write uboot env nandwrite -s 0x0 /dev/mtd1 /boot/uboot-nsa325.env
')