Installing OpenWrt on ALFA AP120C - Success!

I'm going to install the latest available OpenWRT on my ALFA AP120C (Not the AP120C-AC !) I found a forum post from @rosenbj who was doing the same thing with a LEDE firmware back in 2017. Pretty much nothing has changed, honestly, but I wanted to write down how I successfully installed OpenWRT on my ALFA AP120C in case it helps someone else do the same. I left in my mistakes, because sometimes watching others make a mistake is a great way of learning to avoid making them yourself:

This firmware needs to be installed exclusively through the serial terminal during the Uboot phase of boot up using a tftp transfer from the host pc. So we need a serial terminal client that we can send and receive on. And we need an tftp server running on the computer, and the computers IP has to be set correctly to match the what the router is expecting.

Download the latest firmware from the techdata page, there are usually some important links there, you might want to read them.

I first installed the ftp server. My computer is using Ubuntu. If your not there are instructions for other OS's here: Installing OpenWrt via TFTP

anon@computer:$ sudo apt install atftpd

> [sudo] password for anon: 
> Reading package lists... Done
> Building dependency tree  
> Reading state information... Done
> The following additional packages will be installed:
>   inetutils-inetd tcpd
> The following NEW packages will be installed:
>   atftpd inetutils-inetd tcpd
> 0 upgraded, 3 newly installed, 0 to remove and 10 not upgraded.
> Need to get 130 kB of archives.
> After this operation, 617 kB of additional disk space will be used.
> Do you want to continue? [Y/n] Y
> *************[snip *******************
> Processing triggers for systemd (245.4-4ubuntu3.15) ...

anon@computer:/$ mkdir /srv/tftp

> mkdir: cannot create directory ‘/srv/tftp’: File exists

anon@computer:/$ cd /srv/tftp
anon@computer:/srv/tftp$ sudo cp "/home/anon/Projects/AP120C/openwrt-18.06.9-ar71xx-generic-alfa-ap120c-squashfs-sysupgrade.bin" .
anon@computer:/srv/tftp$ sudo mv openwrt-18.06.9-ar71xx-generic-alfa-ap120c-squashfs-sysupgrade.bin sysupgrade.bin
anon@computer:/srv/tftp$ ls

sysupgrade.bin

anon@computer:/srv/tftp$ sha256sum sysupgrade.bin

9c33d869ab4ebc5f3f5e0d6084d1f074ea744d4a500e8e910f1795ae41a07bea  sysupgrade.bin

The correct sha256sum is listed on the download page index, make sure it matches, mine is correct for the file I got.

(If that's not the right index for you, just take the link for the firmware you downloaded and remove the last bit to get to the file index.
Change this:
https://downloads.openwrt.org/releases/18.06.9/targets/ar71xx/generic/openwrt-18.06.9-ar71xx-generic-alfa-ap120c-squashfs-sysupgrade.bin
Into this:
https://downloads.openwrt.org/releases/18.06.9/targets/ar71xx/generic/
and put that into your browser.)

Now I'm going to test the tftp server now to make sure it's working.

anon@computer:/srv/tftp$ tftp localhost

Command 'tftp' not found, but can be installed with:

sudo apt install tftp-hpa  # version 5.2+20150808-1ubuntu4, or
sudo apt install tftp      # version 0.17-22ubuntu2 

anon@computer:/srv/tftp$ sudo apt install tftp-hpa

[sudo] password for anon: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
tftp-hpa
0 upgraded, 1 newly installed, 0 to remove and 10 not upgraded.
Need to get 19.0 kB of archives.
After this operation, 63.5 kB of additional disk space will be used.
****************** [snip]**************************
Setting up tftp-hpa (5.2+20150808-1ubuntu4) ...
Processing triggers for man-db (2.9.1-1) ...

anon@computer:/srv/tftp$ tftp localhost

tftp> get sysupgrade.bin
tftp: sysupgrade.bin: Permission denied
tftp> quit

Doe! I forgot to change file permissions...

anon@computer:/srv/tftp$ sudo chmod 777 sysupgrade.bin
anon@computer:/srv/tftp$ tftp localhost

tftp> get sysupgrade.bin
tftp> quit

A successful tftp in this test will result in nothing but a new "tftp>" prompt. So that's working. Time to move on to working with the AP120C over a serial connection.

There is good information about serial Consoles here, and serial Cables here.

For the ALFA AP120C it has an RJ45 type serial console cable connector, the serial connection is 5v, it uses very standard connection settings of 8-N-1, and operates at a speed of 115200.

There isn't much I can do over the internet to get you connected beyond that. I pushed the easy button, I bought a console cable, and a USB to serial adapter, and just plugged them in. Also I am using the "Serial Monitor" from the Arduino IDE

If your serial connection is good when you power up the device you will see something like my boot up log. Besides this being a good test of your serial connection there is an important bit of information in there:

***********************[SNIP]**********************
Current Image was A 
In:    serial
Out:   serial
Err:   serial
Net:   ag934x_enet_initialize...
No valid address in Flash. Using fixed address
 wasp  reset mask:10c03300 
WASP  ----> F1 PHY *
: cfg1 0x80000000 cfg2 0x7114
eth0: 00:03:7f:09:0b:ad
F1Phy reg init 
ATHR_AUTONEG_ADVERT:1DE1
ATHR_1000BASET_CONTROL:200
ATHR_PHY_CONTROL:3100
ATHRSF1_PHY: Port 5, Neg Success
ATHRSF1_PHY: unit 0 phy addr 5 eth0 up
eth0
Hit any key to stop autoboot:  4  3  2  1  0 
## Booting image at 9fd50000 ...
***********************[SNIP]**********************

The

"Current Image was A"

and

"## Booting image at 9fd50000 ..."

are important.
If it says "Current Image was B" you need to go in to the web interface (For me the default IP was 192.168.1.2/24) and change it to give the "A" image priority, I don't know what to do if it says it's booting "Image A" and the memory address is different than "9fd50000" - Maybe just change the commands you have to issue later to match? Maybe ask on the OpenWRT forum. But it should be "9fd50000".

Next lets interrupt the bootup to get to the Uboot software. We can check for the IP address that the router is expecting the tftp server to be on, change our computer to match, and then flash the firmware.

To interrupt the boot process you have to be quick. Get your serial terminal running. I plugged in the PoE cable to the AP120C's PoE/Lan port and immediately switched to the serial terminal and started pressing "f" and "ENTER" repeatedly. I was successful at interrupting the boot process and I got a "EAP9112A>" prompt - We are now connected to the device and the Uboot software is waiting for us. I issued the command "printenv serverip" to find the IP address the AP120C is expecting our tftp server to have.

It looked like this on the serial monitor:

U-Boot 1.1.4 (Apr 24 2013 - 09:58:53)

Subversion r1.8

U-boot DB120
DRAM:  
sri
Wasp 1.2
wasp_ddr_initial_config(255): (32bit) ddr2 init
Setting 0xb8116290 to 0x38702d0f
128 MB

cpu_pll_cfg: 0x21354
cpu_pll_dither: 0x3c153f
CFG_PLL_FREQ: 0x1f
CFG_HZ      : 266500000

CPU Clock: 533MHz    DDR Clock: 400MHz

Top of RAM usable for U-Boot at: 88000000
Reserving 231k for U-Boot at: 87fc4000
Reserving 192k for malloc() at: 87f94000
Reserving 44 Bytes for Board Info at: 87f93fd4
Reserving 44 Bytes for Global Data at: 87f93fa8
Reserving 128k for boot params() at: 87f73fa8
Stack Pointer at: 87f73f88
Now running in RAM - U-Boot at: 87fc4000
manufacturerId 0xc2, deviceId0 0x20, deviceId1 0x18
flash size 16MB, sector count = 256
flash-2 size 16MB, sector count = 256
Flash: 16 MB
pci_init_board: PCIe PLL not set for 40MHz refclk
BOARD IS NOT CALIBRATED!!!
pci_init_board: PCI DeviceID=33
[eapsw_watchdog::status] cold start
[eapsw_watchdog::status] boot normally 
[eapsw_watchdog::status] autoswitch enabled=On , times=None 
Current Image was A 
In:    serial
Out:   serial
Err:   serial
Net:   ag934x_enet_initialize...
No valid address in Flash. Using fixed address
 wasp  reset mask:10c03300 
WASP  ----> F1 PHY *
: cfg1 0x80000000 cfg2 0x7114
eth0: 00:03:7f:09:0b:ad
F1Phy reg init 
ATHR_AUTONEG_ADVERT:1DE1
ATHR_1000BASET_CONTROL:200
ATHR_PHY_CONTROL:3100
ATHRSF1_PHY: Port 5, Neg Success
ATHRSF1_PHY: unit 0 phy addr 5 eth0 up
eth0
Hit any key to stop autoboot:  4  3  2  0 
EAP9112A> f



Bank # 1: The hell do you want flinfo for??

Bank # 2: The hell do you want flinfo for??
EAP9112A> f



Bank # 1: The hell do you want flinfo for??

Bank # 2: The hell do you want flinfo for??
EAP9112A> printenv serverip


serverip=192.168.100.11
EAP9112A>

Ok, so I just left this there and went back to the computer to change my IP address:

anon@grayghost:/srv/tftp$ nmcli dev status

DEVICE           TYPE      STATE        CONNECTION         
enx00249b5b5e95  ethernet  connected    Wired connection 1 
enx9cebe890fa3b  ethernet  unavailable  --                 
wlp2s0           wifi      unavailable  --                 
lo               loopback  unmanaged    --

anon@grayghost:/srv/tftp$ nmcli con mod "Wired connection 1" ipv4.addresses 192.168.100.11/24

Then I unplugged and re-plugged in my network cable to the switch. It didn't work for me the first time. If it doesn't try issuing the command again while the cable is unplugged, or use your computers GUI network tools. Eventually it worked:

anon@grayghost:/srv/tftp$ ip addr

*******[snip]********
5: enx00249b5b5e95: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:24:9b:5b:5e:95 brd ff:ff:ff:ff:ff:ff
    inet 192.168.100.11/24 brd 192.168.100.255 scope global noprefixroute 
********[snip]********

I also had Wireshark running and I started to see packets with the new IP in it:

134354 32831.168131069 ActionSt_5b:5e:95 Broadcast ARP 42 Who has 192.168.0.1? Tell 192.168.100.11

Then I went back to the serial console/terminal/monitor thing and issued the scary commands! (Could brick your WiFi router!) I actually messed up at fist. I include that below in case it helps some one. The "sysupgrade.bin" needs to match the name of the file on your tftp server. These are the correct commands:

tftp 0x80060000 sysupgrade.bin
erase 0x9f050000 +0xe80000
cp.b 0x80060000 0x9f050000 $filesize
reset

Hooo Boy! So yeah; I almost messed it up. Somehow my sysupgrade.bin file was ZERO bytes! But I just copied it again on the computer and changed it's permissions again, and verified that it was the correct size - Those commands aren't shown here, but I retroactively added the sha256sum check above so it won't happen to you. Here is what I saw and did on the serial terminal:

EAP9112A> tftp 0x80060000 sysupgrade.bin


Trying eth0
dup 1 speed 1000
Using eth0 device
TFTP from server 192.168.100.11; our IP address is 192.168.100.46
Filename 'sysupgrade.bin'.
Load address: 0x80060000
Loading: *#
done
EAP9112A> erase 0x9f050000 +0xe80000


Erase Flash from 0x9f050000 to 0x9fecffff in Bank # 1 erase flash#0

First 0x5 last 0xec sector size 0x10000
   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
Erased 232 sectors
EAP9112A> echo $filesize


d00000
EAP9112A> tftp 0x80060000 sysupgrade.bin


Trying eth0
Using eth0 device
TFTP from server 192.168.100.11; our IP address is 192.168.100.46
Filename 'sysupgrade.bin'.
Load address: 0x80060000
Loading: *#################################################################
	 #################################################################
	 **************** [Sniped 42 more lines] ****************
	 #################################################################
	 #########
done
Bytes transferred = 15018558 (e52a3e hex)
EAP9112A> cp.b 0x80060000 0x9f050000 $filesize


Copy to Flash... write flash#0
write addr: 50000
done
EAP9112A> reset

The AP120C rebooted, I changed my computers IP back to 192.168.1.8, plugged and un-plugged the cord, and opened
http://192.168.1.1 in my browser.

Victory!! I had sucessfully installed OpenWRT - Although I couldn't log in! I forgot to find out the default password for the new firmware before installing it! Using the serial console I can change the password using "passwd" then entering the password twice. But that also isn't working.... Ok looking it up on my phone the default password is supposed to be blank, but that wouldn't work.

I went back and flashed it again, without my error, and it seemed to work again. However I also used the "clear data" function on my browser to get rid of stored passwords and cookies and stuff before I tried to login to the newly flashed AP120C and that might have been what really did it. Or maybe changing the password on the serial console was messing things up. But either way I successfully logged in, and I have another OpenWRT router!

I hope this helps someone. Huge thank you to everyone who made this possible!!