Welcome! Log In Create A New Profile

Advanced

[TOOL] Finding address of stock envs of fw_printenv

Posted by bobafetthotmail 
[TOOL] Finding address of stock envs of fw_printenv
January 23, 2017 05:01AM
I made this simple script that will run fw_printenv sequentially on all possible flash sectors in the first two mtd partitions, to identify where are stock uboot envs even if you are not using stock firmware anymore.

To be run on different devices it might need some adjustments (it currently checks only 1 MiB of flash sectors per partition, and checks only the first two partitions, which should be enough as uboot partition is 1MiB and the uboot_env partition is 0.5MiB).

I've left in the loop I used to generate the hex values, it's commented out but will work as long as you have installed bc in your system.

#!/bin/sh

# MTD device name	Device offset	Env. size	Flash sector size	Number of sectors
#/dev/mtd0		0xc0000		0x20000		0x20000

#backing up current config
mv /etc/fw_env.config /etc/fw_env.config.backup

#list of block addresses
#128k = 131072 bytes -> 0x20000 in hexadecimal and we sum 0x20000 to it to get our addresses.

# address=180000
#
# while [ "$address" != "0" ] ; do
#
# address=$( echo "obase=16;ibase=16;$address-20000" | bc )
# echo $address
#
# done


# addresses for mtd0
# E0000
# C0000
# A0000
# 80000
# 60000
# 40000
# 20000
# 0

# addresses for mtd1
# same as above, it restarts from 0 in each mtd

#zyxel nsa310 new mtdparts, kinda
#mtdparts=orion_nand:0x100000(uboot),0x80000(uboot_env),0x100000(second_stage_uboot),0x7b80000(ubi)

for address in e0000 c0000 a0000 80000 60000 40000 20000 0; do

echo "/dev/mtd0		0x$address		0x20000		0x20000" > /etc/fw_env.config
cat /etc/fw_env.config
echo "stuff found at mtd0 $address"
fw_printenv
echo -----------------------------

done

for address in e0000 c0000 a0000 80000 60000 40000 20000 0; do

echo "/dev/mtd1		0x$address		0x20000		0x20000" > /etc/fw_env.config

echo "stuff found at mtd1 $address"
fw_printenv
echo -----------------------------

done

#restoring current config
mv /etc/fw_env.config.backup /etc/fw_env.config
Re: [TOOL] Finding address of stock envs of fw_printenv
January 23, 2017 08:10AM
Nice and thank you for sharing the scripts. I am sure it will come handy.
Re: [TOOL] Finding address of stock envs of fw_printenv
January 23, 2017 02:31PM
bobafetthotmail,

Nice script :) I've added it to the Wiki thread.

-bodhi
===========================
Wiki
latest Kirkwood kernel builds and rootfs
latest u-boot-kirkwood builds
latest Oxnas kernel builds and rootfs
latest u-boot-oxnas builds
latest MVEBU Armada kernel builds and rootfs
U-Boot & Kernel Booting process
bodhi's u-boot GitHub
bodhi's corner



Edited 1 time(s). Last edit at 01/23/2017 02:39PM by bodhi.
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: