diff --git a/config/sources/families/rk322x.conf b/config/sources/families/rk322x.conf index 7efbbe5553..403d458039 100644 --- a/config/sources/families/rk322x.conf +++ b/config/sources/families/rk322x.conf @@ -37,8 +37,65 @@ GOVERNOR="ondemand" write_uboot_platform() { + + # Extract the Command Rate bit from existing loader. + # Some DDR memories have issues with different Command Rate, so we + # restore the same value after installing the new loader. + # Note: this has to be done only on live installations (DIR variable + # is present only during boot loader upgrade on running system) + # while loop is only for convenient break syntax + while [[ -n $DIR ]]; do + + # Find the signature "a7866565" in the first 128k of the stored running image + SIGNATURE_OFFSET=$(dd if=$2 bs=128k count=1 2>/dev/null | od -A o -w4 -tx4 | grep 'a7866565' | cut -d " " -f 1) + + # Some command failed, skip the rest + [[ $? -ne 0 ]] && break; + + # No signature found, skip the rest + [[ -z $SIGNATURE_OFFSET ]] && break; + + # Command rate bit is 16 bytes before signature + CMD_RATE_OFFSET=$(($SIGNATURE_OFFSET - 16)) + CR_BYTE=$(od -A n -t dI -j $CMD_RATE_OFFSET -N 1 $2) + + # No command rate byte for some reason, skip the rest + [[ -z $CR_BYTE ]] && break; + + # Invalid command rate byte (should be 0 or 1), skip the rest + [[ "$CR_BYTE" -ne 0 && "$CR_BYTE" -ne 1 ]] && break; + + # Proceed patching u-boot-rk322x-with-spl.bin, do find the + # cr bit there too to verify that the position of the CR bit is right + SIGNATURE_OFFSET=$(dd if=$1/u-boot-rk322x-with-spl.bin bs=128k count=1 2>/dev/null | od -A o -w4 -tx4 | grep 'a7866565' | cut -d " " -f 1) + + # Some command failed, skip the rest + [[ $? -ne 0 ]] && break; + + # No signature found, skip the rest + [[ -z $SIGNATURE_OFFSET ]] && break + + # Command rate bit is 16 bytes before signature + CMD_RATE_OFFSET=$(($SIGNATURE_OFFSET - 16)) + DST_BYTE=$(od -A n -t dI -j $CMD_RATE_OFFSET -N 1 $1/u-boot-rk322x-with-spl.bin) + + # Verify command rate byte is 0 or 1 + [[ "$DST_BYTE" -ne 0 && "$DST_BYTE" -ne 1 ]] && break; + + # Patch the file + [[ "$CR_BYTE" -eq 0 ]] && HEX_CR="\x00" + [[ "$CR_BYTE" -eq 1 ]] && HEX_CR="\x01" + + echo -e $HEX_CR | dd of=$1/u-boot-rk322x-with-spl.bin bs=1 seek=$CMD_RATE_OFFSET count=1 conv=notrunc >/dev/null 2>&1 + + # always break the while loop + break + + done + dd if=/dev/zero of=$2 bs=1k count=1023 seek=1 status=noxfer > /dev/null 2>&1 - dd if=$1/u-boot-rk322x-with-spl.bin of=$2 seek=64 conv=notrunc > /dev/null 2>&1 + dd if=$1/u-boot-rk322x-with-spl.bin of=$2 bs=32k seek=1 conv=notrunc > /dev/null 2>&1 + } uboot_custom_postprocess() @@ -56,7 +113,7 @@ uboot_custom_postprocess() # tools/mkimage -n rk322x -T rksd -d tpl/u-boot-tpl.bin u-boot-rk322x-with-spl.bin # - tools/mkimage -n rk322x -T rksd -d $SRC/packages/blobs/rockchip/rk322x_ddr_330MHz_v1.10_no2t.bin u-boot-rk322x-with-spl.bin + tools/mkimage -n rk322x -T rksd -d $SRC/packages/blobs/rockchip/rk322x_ddr_330MHz_v1.10_2t.bin u-boot-rk322x-with-spl.bin cat spl/u-boot-spl.bin >> u-boot-rk322x-with-spl.bin dd if=u-boot.itb of=u-boot-rk322x-with-spl.bin seek=$((0x200 - 0x40)) conv=notrunc diff --git a/packages/blobs/rockchip/rk322x_ddr_330MHz_v1.10_no2t.bin b/packages/blobs/rockchip/rk322x_ddr_330MHz_v1.10_2t.bin similarity index 98% rename from packages/blobs/rockchip/rk322x_ddr_330MHz_v1.10_no2t.bin rename to packages/blobs/rockchip/rk322x_ddr_330MHz_v1.10_2t.bin index 65d1f0cf24..f4fd573957 100755 Binary files a/packages/blobs/rockchip/rk322x_ddr_330MHz_v1.10_no2t.bin and b/packages/blobs/rockchip/rk322x_ddr_330MHz_v1.10_2t.bin differ