Porting OpenWRT to a new device using the ASUS DSL N12U as an example
- Tutorial
In this article, I will talk about the process of porting firmware as a whole and about my experience in porting OpenWRT to ASUS DSL N12U.
First you need to determine how much this will actually be done. To do this, find out the configuration of your router. There are many options for the development of events, for example, my router showed all the necessary parameters in the log at boot time and in dmesg. Here you should precisely determine the RAM, ROM volumes, partition addresses in mtd, and of course, on the basis of which chip the router itself is made.
An example of a full download log in my case is here .
I will note the most important lines for us:
M25P128(20 20180000) (16384 Kbytes)
mtd .name = raspi, .size = 0x01000000 (16M) .erasesize = 0x00040000 (256K) .numeraseregions = 0
Creating 5 MTD partitions on "raspi":
0x00000000-0x01000000 : "ALL"
0x00000000-0x00040000 : "Bootloader"
0x00040000-0x00080000 : "Config"
0x00080000-0x000c0000 : "Factory"
0x000c0000-0x00800000 : "Kernel"There are partitions addresses, there is a volume and type of ROM memory. Hurrah.
There is also a amount of memory and a specific platform is indicated:
ASIC 3052F (DSL-N12U) (Port5<->None)
Total memory: 32 MBytesNow you need to try to find in the table of compatible devices the most similar to your router (the main thing is the platform), if there is nothing like that, then this instruction will not help you.
My router showed all the necessary information in dmesg and in the console on the port. But other options and directions for the search for this and other useful information are possible. The main ones are the GPL firmware release (if any) and the router firmware dump.
We also need to connect to the UART or Serial port of the router, the probability of success of the venture without this connection tends to zero. As USB -> UART, you can use Arduino, but you need to remember that in Arduino the signal level is 5V (and most of these devices have 3.3V). And you need to take examples to solve this problem (at least add a resistor to the RX router).
How to detect the Serial port is the topic of a separate article, but usually almost any router or device with Linux inside has it, in my case it was just Google.
Now let's move on to the firmware assembly.
At least the packages for building the toolchain must be installed on the system:
sudo apt-get install subversion git build-essentialI built on Debian 7, but in general there should be no problems at this point.
Clone the repository:
svn co svn://svn.openwrt.org/openwrt/trunk wrtWe launch a recursive update of the firmware and toolchain components:
cd ~/wrt
./scripts/feeds update -a
./scripts/feeds install -aPutting the toolchain:
make prereqNext, configure the firmware for the most similar supported router model
make menuconfigHere we are interested in the fields:
Target System (Ralink RT288x/RT3xxx) --->
Subtarget (RT3x5x/RT5350 based boards) --->
Target Profile (Asus RT-N13U) ---> I chose the ASUS RT-N13U as the most similar to my router. In fact, this choice is not very important, since the difference in specific profiles is minimal, and we will correct most of the differences, the main thing is to correctly guess the platform.
More in menuconfig you do not need to change anything.
At the first assembly, you also need to collect the toolchain and utilities once:
make tools/install -j9 V=-1 && make toolchain/install -j9 V=-1The assembly itself will take place using
make -j9 V=-1The result will lie in bin / ramips
Ramips to describe the device uses DTS which lie in target / linux / ramips / dts. The original DTS for ASUS DSL RT-N13U lies here .
Here we will completely replace the cfi @ 1f000000 block with our new one. Obviously, this is not what is suitable for our ROM chip. A quick search of neighboring dts revealed that the configuration example should look something like this (this is again a block for DTS):
palmbus@10000000 {
spi@b00 {
status = "okay";
m25p80@0 {
#address-cells = <1>;
#size-cells = <1>;
compatible = "m25p128";
reg = <0 0>;
linux,modalias = "m25p80", "m25p128";
spi-max-frequency = <10000000>;
partition@0 {
label = "u-boot";
reg = <0x0 0x30000>;
read-only;
};
partition@30000 {
label = "u-boot-env";
reg = <0x30000 0x10000>;
read-only;
};
factory: partition@40000 {
label = "factory";
reg = <0x40000 0x10000>;
read-only;
};
partition@50000 {
label = "firmware";
reg = <0x50000 0xfb0000>;
};
};
};
};
Hoping for a successful outcome with a minimum of work, I assembled the firmware for ASUS RT-N13U with the changes made and tried to fill it in through recovery mode, but the router refused to accept it with the
wrong product id error .
At the moment, I could not find out which id he was checking, so installing the firmware without access to the Serial port is impossible.
But the router flashed without problems in 2 uboot mode
2: System Load Linux Kernel then write to Flash via TFTP.
Warning!! Erase Linux in Flash then burn new one. Are you sure?(Y/N)
Please Input new ones /or Ctrl-C to discard
Input device IP (192.168.1.1) ==:192.168.0.2
Input server IP (192.168.1.20) ==:192.168.0.20
Input Linux Kernel filename () ==:fw.binIt does not use a TFTP server, as in recovery from ASUS, but the router itself goes to the specified server and downloads the specified file.
On the first attempt, the router did not start due to the inability to mount /, but the boot log showed that there were problems with ROM
[ 0.550000] m25p80 spi32766.0: found mr25h256, expected w25q128
[ 0.560000] m25p80 spi32766.0: mr25h256 (32 Kbytes)
[ 0.570000] 4 ofpart partitions found on MTD device spi32766.0
[ 0.580000] Creating 4 MTD partitions on "spi32766.0":
[ 0.590000] 0x000000000000-0x000000030000 : "u-boot"
[ 0.600000] mtd: partition "u-boot" extends beyond the end of device "spi32766.0" -- size truncated to 0x8000
[ 0.620000] 0x000000030000-0x000000040000 : "u-boot-env"
[ 0.640000] mtd: partition "u-boot-env" is out of reach -- disabled
[ 0.650000] 0x000000040000-0x000000050000 : "factory"
[ 0.660000] mtd: partition "factory" is out of reach -- disabled
[ 0.670000] 0x000000050000-0x000001000000 : "firmware"
[ 0.680000] mtd: partition "firmware" is out of reach -- disabledA quick look at the m25p80 driver combined with a suspicious error
[ 0.470000] rt2880-pinmux pinctrl: pin io3 already requested by pinctrl; cannot claim for 10000b00.spi
[ 0.490000] rt2880-pinmux pinctrl: pin-3 (10000b00.spi) status -22
[ 0.500000] rt2880-pinmux pinctrl: could not request pin 3 (io3) from group spi on device rt2880-pinmuxmade it clear that the problem is in some pinctr and it seems that the driver cannot access the chip (he defined it as the most primitive with id 0). As it turned out, it was enough to erase the line with spi from the pinctrl section in the DTS, it was it that prevented the m25p80 driver from gaining access to spi.
At the next attempt to boot the device, it became clear that the ROM was detected correctly, and the only thing left was to set the correct mtd partition addresses.
It ended up like this:
palmbus@10000000 {
spi@b00 {
status = "okay";
m25p80@0 {
#address-cells = <1>;
#size-cells = <1>;
compatible = "m25p128";
reg = <0 0>;
linux,modalias = "m25p80", "m25p128";
spi-max-frequency = <10000000>;
partition@0 {
label = "u-boot";
reg = <0x0 0x40000>;
read-only;
};
partition@40000 {
label = "u-boot-env";
reg = <0x40000 0x40000>;
read-only;
};
factory: partition@80000 {
label = "factory";
reg = <0x80000 0x40000>;
read-only;
};
partition@c0000 {
label = "firmware";
reg = <0xc0000 0x740000>;
};
};
};
};
Firmware, and suddenly everything is loaded, Hurray!
Log of successful device boot.
As a result, that’s all: the router made money on OpenWRT without any problems and failures. Naturally, DSL does not work, but everything else works better than on the original firmware. Even the indication on the case worked correctly.
This article is written to show that running OpenWRT on a new device (provided that the platform is supported) is very simple, I hope it helps someone make the OpenWRT port on their device as well.