February 7, 2022

Orange Pi 4 (Rockchip 3399) USB download and rkflashtool

This thing called rkflashtool is a cute little 237 line bit of C code. It is lean on instructions and it has become clear to me that it does not talk to the bootrom (aka "maskrom") on the chip.

What I am looking to do is to build a small standalone executable and have some tool to load it into SRAM and run it.

Rkflashtool is not what I am looking for.
It has two strikes against it. It is not clear what it is supposed to talk to, and it never downloaded and ran executables anyway.

The usage message from rkflashtool shows:

	rkflashtool b                   	reboot device
	rkflashtool e offset size       	erase flash (fill with 0xff)
	rkflashtool r offset size >file 	read flash
	rkflashtool w offset size 

Nothing about loading and running executables.



rkflashtool is command line, rkflashkit is gui (python and gtk3).
The Readme for rkflashkit indicates it is derived from rkflashtool.

Note that Galland states that his rkflashtool is based on work by Omegamoon.
He describes a tool "flash_mk808_omegamoon" that he used to send his linux kernel
to the RK3606.  This is a script that runs his "rkflashtool".

A look at rkflashtool reveal that it is a tidy little 237 line piece of C code!!
Let's try to build it.

git clone https://github.com/Galland/rkflashtool_rk3066.git
cd rkflashtool_rk3066
ln -s GNUmakefile Makefile
make
This code has been unchanged for 9 years (since 2013) which is fine by me. It supports the RK3066 and RK3188. The RK3066 was a dual Corex-A9 used in cheap tablets. The RK3188 was a quad core Cortex-A9.

I get a deprecation warning from libusb, but I recall that libusb is one of those things that is forever changing and causing trouble of this sort. I also remember that there is libusb and libusbx and that both exist and there is confusion about which is better, current, recommended that I just don't recall details about. But this code is libusb based, compiles with a bit of work, so we leave that issue for now. Actually a bit of searching lays that to rest. libusb was a "hostile fork" of libusb, but apparently the rancor has died down and libusb has generally replaced libusbx in almost all cases.

gcc -O2 -W -Wall rkflashtool.c -o rkflashtool -s -lusb-1.0
make
warning: ‘libusb_set_debug’ is deprecated: Use libusb_set_option
I make the following change and get a clean build:
    // libusb_set_debug(c, 3);
    libusb_set_option(c, LIBUSB_OPTION_LOG_LEVEL, 3);


Have any comments? Questions? Drop me a line!

Tom's electronics pages / [email protected]