on a 2 mb dsl modem/router managed to create a small extra mtd5 partion to use with led.conf file
need to format it to "minix" and mount it
however, 2 mb firmware does not come with "makemtd.sh" script
can somebody post content of "makemtd.sh" , so I can do it manually ?
thanks
minix + makemtd.sh + mtd5
- thechief
- RouterTech Team
- Posts: 12067
- Joined: Wed Feb 01, 2006 10:22 pm
- Location: England, the Centre of Africa
- Contact:
Re: minix + makemtd.sh + mtd5
jenom wrote: ↑Sat May 05, 2018 5:10 pmon a 2 mb dsl modem/router managed to create a small extra mtd5 partion to use with led.conf file
need to format it to "minix" and mount it
however, 2 mb firmware does not come with "makemtd.sh" script
can somebody post content of "makemtd.sh" , so I can do it manually ?
thanks
Code: Select all
#!/bin/sh
#
# RouterTech script to create a new MTD partition
# It starts at the bottom of the mtd table, and works backwards, always taking away from mtd4
# USE WITH GREAT CARE. IF YOU TRASH YOUR ROUTER, THEN DON'T LOOK HERE!
# (c)2007-2011, RouterTech
# Author: TheChief
# Last amended: 11 October 2011
#
. /usr/local/bin/rt_utils.sh
# only certain values are valid
isvalid()
{
RES=0
case $1 in
64) RES=1;;
128) RES=2;;
192) RES=3;;
256) RES=4;;
320) RES=5;;
384) RES=6;;
448) RES=7;;
512) RES=8;;
576) RES=9;;
640) RES=10;;
704) RES=11;;
768) RES=12;;
832) RES=13;;
896) RES=14;;
esac
echo "$RES"
}
# is the flash big enough?
[ $BIGMEM -eq 0 ] && {
echo "Your flash memory is too small for creating minix partitions."
echo "You are advised to stop now!"
# exit 1
}
res=$(has_substr "$RT_ARGS" "--help")
if [ $res -eq 1 ] || [ -z "$2" ]; then
echo "Create a brand new mtd partition, and resize mtd0 and mtd4 to do so. USE WITH GREAT CARE!!!"
echo "Syntax = $ARGV0 <newMTD> <size> [auto_minix]"
echo "\"auto_minix\" means create a minix filesystem automatically on the new mtd partition."
echo "\"size\" must be a multiple of 64kb - e.g.,"
echo " 64; 128; 192; 256; 320; 384; 448; 512; 576; 640; 704; 768; 832; 896"
echo "Make sure that the partition is not too big, or you WILL trash your firmware!"
echo "So, you'd better get the size parameter right!"
echo "For a wireless router, you should NEVER exceed 448kb."
echo "Example: $ARGV0 mtd5 192 auto_minix"
exit 1
fi
SZ=$(KBytes $2)
res=$(isvalid $2)
if [ -z "$SZ" ] || [ $SZ -lt 65536 ] || [ $res -lt 1 ]; then
echo "Invalid size parameter \"$2\". The partition size must be within this range:"
echo "64, 128, 192, 256, 320, 384, 448, 512, 576, 640, 704, 768, 832, 896"
echo "Quitting ..."
exit 1
fi
echo ""
# refuse to cooperate if the partition already exists
if grep "$1" /proc/mtd > /dev/null ; then
echo "The $1 partition already exists. Quitting ..."
exit 1
fi
# get mtd0 and mtd4 - we want to adjust their ends
mtd_0=`getenv mtd0`
mtd_4=$(getenv mtd4)
# test for empty values
if [ -z "$mtd_0" ]; then
echo "The mtd0 partition does not exist. Quitting ..."
exit 1
fi
if [ -z "$mtd_4" ]; then
echo "The mtd4 partition does not exist. Quitting ..."
exit 1
fi
echo "Trying to create new partition: $1, of size: $SZ ..."
# get the substrings (start and end )
mtd_0_start=`expr substr "$mtd_0" 1 10`
mtd_0_end=`expr substr "$mtd_0" 12 10`
mtd_4_start=`expr substr "$mtd_4" 1 10`
mtd_4_end=`expr substr "$mtd_4" 12 10`
# convert to decimals for mathematical operations
end0=$(hex2int $mtd_0_end)
end4=$(hex2int $mtd_4_end)
if [ "$end0" != "$end4" ]; then
echo "The mtd0 and mtd4 partitions end at different offsets. Quitting ..."
exit 2
fi
# reduce the current ends by the size parameter
tmp=`maths $end0 $SZ`
# convert the result to hexadecimal
res2=$(int2hex $tmp)
# display,results
echo "Old end:$end0 : `int2hex $end0`"
echo "New end:$tmp : `int2hex $tmp`"
echo "New end for mtd0 and mtd4=$res2"
# now do the job!
saved=/var/mtds.sav
getenv | grep ^mtd > $saved
echo ""
echo " ----- This is how to restore the original MTD values: -----"
echo "unsetenv $1"
echo "setenv mtd0 \"$mtd_0_start,$mtd_0_end\""
echo "setenv mtd4 \"$mtd_4_start,$mtd_4_end\""
# write to file
oldF="/var/remove_"$1.sh
echo "A script to delete the new $1 partition is stored in: $oldF."
echo "You'd better save and backup that file!!!"
echo "#!/bin/sh" > $oldF
echo "# A script to delete the new $1 partition, $SZ byte(s) in size" >> $oldF
echo "# Created on $(date)" >> $oldF
echo "unsetenv $1" >> $oldF
echo "setenv mtd0 \"$mtd_0_start,$mtd_0_end\"" >> $oldF
echo "setenv mtd4 \"$mtd_4_start,$mtd_4_end\"" >> $oldF
echo "echo \"New mtd partition table:\"" >> $oldF
echo "getenv | grep ^mtd" >> $oldF
echo "exit 0" >> $oldF
echo "# This is the backup information of original mtd partition table:" >> $oldF
cat $saved >> $oldF
echo "# New MTD partition $1 of $SZ size was created on $(date)" >> $oldF
chmod a+x $oldF
echo ""
# just do echoes at the moment - nothing actually created
echo " --- You need to run these commands to create the new partition: RUN THEM AT YOUR OWN RISK!!! ---"
echo "setenv mtd0 \"$mtd_0_start,$res2\""
echo "setenv mtd4 \"$mtd_4_start,$res2\""
echo "setenv $1 \"$res2,$mtd_4_end\""
# write to file
newF="/var/create_"$1.sh
echo "A script to create the new $1 partition is stored in: $newF"
echo "#!/bin/sh" > $newF
echo "# A script to create a new $1 partition, $SZ byte(s) in size" >> $newF
echo "# Created on $(date)" >> $newF
echo "setenv mtd0 \"$mtd_0_start,$res2\"" >> $newF
echo "setenv mtd4 \"$mtd_4_start,$res2\"" >> $newF
echo "setenv $1 \"$res2,$mtd_4_end\"" >> $newF
echo "echo \"New mtd partition table:\"" >> $newF
echo "getenv | grep ^mtd" >> $newF
echo "exit 0" >> $newF
echo "# New MTD partition $1 of $SZ size was created on $(date)" >> $newF
echo "# This is the original mtd partition table:" >> $newF
cat $saved >> $newF
chmod a+x $newF
# exit 0
echo ""
echo "*****************************************************************************************"
echo "The commands to create your \"$1\" partition are in: \"$newF\""
echo "The commands to restore your mtd partitions and remove the new \"$1\" partition are in: \"$oldF\""
echo "FINAL WARNING. RUN THESE COMMANDS ENTIRELY AT YOUR OWN RISK. YOU HAVE BEEN WARNED!!!!"
echo "*****************************************************************************************"
echo ""
echo "This is your LAST CHANCE to back out of this process!!!"
echo -n "I can create the \"$1\" partition for you now. Should I do it now? (Y/N): "
read ans
case $ans in
y*|Y*) echo "You answered \"Yes\". I will now proceed to execute \"$newF\"";;
n*|N*|*) echo "You answered \"No\". Abandoning the process."; echo ""; exit 1;;
esac
echo ""
echo "Working ...."
$newF
### automate the rest of the stuff ?
if [ "$3" = "auto_minix" ]; then
td=0
case $1 in
mtd5) td=5;;
mtd6) td=6;;
mtd7) td=7;;
mtd8) td=8;;
mtd9) td=9;;
esac
# e.g., setenv "auto_minix.sh" "262144 5"
if [ $td -gt 0 ]; then
setenv "auto_minix.sh" "$SZ $td"
echo "Finished. The router will now reboot to complete the process."
echo -n "Rebooting in 8 seconds. Press CTRL-C to abort ..."
sleep 8
/sbin/reboot
sleep 2
fi
else
echo ""
echo "Finished. You need to reboot your router for the changes to take effect. Run \"/sbin/reboot\""
echo "But first of all, backup these files: \"$oldF\", and \"$newF\""
echo ""
fi
The Chief: Be sure to read the Firmware FAQ and do a Forum Search before posting!
No support via PM. Ask all questions on the open forum.
No support via PM. Ask all questions on the open forum.