Skip to content

Commit

Permalink
Always rewrite EEPROM data and MAC addresses
Browse files Browse the repository at this point in the history
Commit openwrt/openwrt@050621a introduced a new SPI-NAND driver for
MediaTek SoCs to Linux. It's the same driver we have already been
using in U-Boot and TF-A, so will be less maintainance work in future.

However, it turns out the new driver is particularly picky when it
comes to read data with broken OOB/ECC information, such as everything
written using the old driver **or even the stock factory partition**.

Hence, in order to run OpenWrt after commit openwrt/openwrt@050621a,
we need to read and write back the factory partition using the new
driver in order to make calibration data available again, as rewriting
fixes ECC errors left behind by previous firmware.
  • Loading branch information
dangowrt committed Aug 28, 2021
1 parent d8ce5cf commit 6674ead
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions files/installer/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,8 @@ install_fix_factory() {
exit 1
fi

echo -n "found factory partition at offset $(printf %08x $((off))), "
if [ $((off)) -eq 0 ]; then
echo "ok."
return
fi
echo -n "found factory partition at offset $(printf %08x $((off))), rewriting..."

echo "fixing..."
dd if=$mtddev bs=$ebs skip=$skip count=1 of=/tmp/factory-fixed
mtd write /tmp/factory-fixed $mtddev
local magic="$(hexdump -v -n 2 -e '"%02x"' $mtddev)"
Expand Down Expand Up @@ -90,9 +85,9 @@ install_fix_macpart() {
exit 1
fi

[ $((blockoff)) -eq $((destoff)) ] && return
[ $((blockoff)) -eq $((destoff)) ] ||
echo "mac addresses block shifted by 0x$(printf %08x $((blockoff - destoff))), fixing."

echo "mac addresses block shifted by 0x$(printf %08x $((blockoff - destoff))), fixing."
dd if=$mtddev bs=$ebs skip=$skip count=1 of=/tmp/macs-fixed
mtd -p $destoff -l $ebs write /tmp/macs-fixed $mtddev
}
Expand Down Expand Up @@ -140,10 +135,10 @@ install_prepare_ubi() {
# backup mtd0...mtd2
install_prepare_backup 2

# make sure two mac addresses are store at correct offset in factory
# rewrite two mac addresses are stored at correct offset in factory partition
install_fix_macpart /dev/mtd2 0x60000 0x1fff4

# make sure wifi eeprom starts at correct offset
# make sure wifi eeprom starts at correct offset and rewrite to fix ECC
install_fix_factory /dev/mtd2 "7622"

echo "redundantly write bl2 into the first 4 blocks"
Expand Down

0 comments on commit 6674ead

Please sign in to comment.