<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Gagan Deep</title>
    <description>The latest articles on DEV Community by Gagan Deep (@pandafy).</description>
    <link>https://dev.to/pandafy</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F269977%2F08f25a23-3821-4a37-a18a-12f5aeef9acd.jpeg</url>
      <title>DEV Community: Gagan Deep</title>
      <link>https://dev.to/pandafy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pandafy"/>
    <language>en</language>
    <item>
      <title>Flashing OpenWrt on TP-Link Archer C50</title>
      <dc:creator>Gagan Deep</dc:creator>
      <pubDate>Sun, 24 Jan 2021 13:39:42 +0000</pubDate>
      <link>https://dev.to/pandafy/flashing-openwrt-on-tp-link-archer-c50-4jm3</link>
      <guid>https://dev.to/pandafy/flashing-openwrt-on-tp-link-archer-c50-4jm3</guid>
      <description>&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: The router referenced in this blog is an EU variant of the router, i.e. TP-Link Archer C50 V4. It is recommended that you reference both OEM and OpenWrt documentation for your router before following these steps.&lt;/p&gt;

&lt;p&gt;⚠️ &lt;strong&gt;Disclaimer:&lt;/strong&gt; Failing to properly follow mentioned steps may end up in a bricked router. The goal of this blog is to share knowledge and document everything in one place. Proceed with caution at your own risk.&lt;/p&gt;

&lt;h3&gt;
  
  
  Prologue
&lt;/h3&gt;

&lt;p&gt;I have been contributing to  &lt;a href="https://openwisp.org/"&gt;OpenWISP&lt;/a&gt; for over a year now. OpenWISP is a network management software that can be used to manage network devices primarily running OpenWrt. I have been using a virtual machine to suffice for a networking device. But, after getting comfortable with VM, I wanted to get my hands dirtier with a real router.&lt;/p&gt;




&lt;p&gt;I chose  &lt;a href="https://www.tp-link.com/in/home-networking/wifi-router/archer-c50/"&gt;TP-Link Archer C50&lt;/a&gt;  after thorough research for OpenWrt compatible router in my local market. It comes with 8MB Flash storage and 64MB RAM. More hardware information can be found at  &lt;a href="https://openwrt.org/toh/tp-link/archer-c50"&gt;OpenWrt's device page for TP-Link Archer C50&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;While there are pre-built OpenWrt images available from the community, I chose to build the image on my own. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; If you want to use the pre-built images, you can reference the  &lt;a href="https://openwrt.org/toh/tp-link/archer-c50#v4_installation_instructions"&gt;concerned section in OpenWrt's documentation&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Building Firmware Image
&lt;/h2&gt;

&lt;p&gt;Building the firmware image on your own is simple as well. You'll have just followed these steps:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1&lt;/strong&gt;: Download the firmware for the router from &lt;a href="https://www.tp-link.com/en/support/download/archer-c50/v4/"&gt;TP-Link's download center&lt;/a&gt;. The link will download an archive. Extract the contents of the archive and rename the firmware file(it will be with &lt;code&gt;.bin&lt;/code&gt; extension) to &lt;code&gt;tpl.bin&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Download the OpenWrt sysupgrade for this router from  &lt;a href="http://downloads.openwrt.org/releases/19.07.5/targets/ramips/mt76x8/openwrt-19.07.5-ramips-mt76x8-tplink_c50-v4-squashfs-sysupgrade.bin"&gt;OpenWrt's website&lt;/a&gt;. Rename this file to &lt;code&gt;owrt.bin&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Move these files under the same directory for your ease. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Open the terminal in the said directory, and execute the following commands. These commands will build the required firmware image for your router&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;dd &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/dev/zero &lt;span class="nv"&gt;of&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;tp_recovery.bin &lt;span class="nv"&gt;bs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;196608 &lt;span class="nv"&gt;count&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1
&lt;span class="nb"&gt;dd &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;tpl.bin &lt;span class="nv"&gt;of&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;tmp.bin &lt;span class="nv"&gt;bs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;131584 &lt;span class="nv"&gt;count&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1
&lt;span class="nb"&gt;dd &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;tmp.bin &lt;span class="nv"&gt;of&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;boot.bin &lt;span class="nv"&gt;bs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;512 &lt;span class="nv"&gt;skip&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1
&lt;span class="nb"&gt;cat &lt;/span&gt;boot.bin &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; tp_recovery.bin
&lt;span class="nb"&gt;cat &lt;/span&gt;owrt.bin &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; tp_recovery.bin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Setting up a TFTP Server
&lt;/h2&gt;

&lt;p&gt;TFTP - Trivial File Transfer Protocol - is a very simple protocol, such that it can be implemented in small boot loaders like a router. &lt;/p&gt;

&lt;p&gt;While booting, the bootloader listens to TFTP requests for transferring a flash image. This characteristic of the bootloader, allows us to flash the router using TFTP Server. &lt;/p&gt;

&lt;p&gt;A router can either have a TFTP client or server. The bootloader of TP-Link Archer C50 integrates a TFTP client. This means that we will have to run a TFTP server. &lt;/p&gt;

&lt;p&gt;You will need to follow these steps, to properly configure a TFTP server:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Install &lt;code&gt;aftpd&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;aftpd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Create a directory from where you want to serve the image file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; ~/srv/tftp/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Put the &lt;code&gt;tp_recovery.bin&lt;/code&gt; image file in the &lt;code&gt;tftp&lt;/code&gt; directory&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Change the ownership of the folder and the file in it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo chown &lt;/span&gt;nobody:nogroup &lt;span class="nt"&gt;-R&lt;/span&gt; /srv/tftp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; Run TFTP server&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;atftpd &lt;span class="nt"&gt;--daemon&lt;/span&gt; &lt;span class="nt"&gt;--no-fork&lt;/span&gt; &lt;span class="nt"&gt;--logfile&lt;/span&gt; - ~/srv/tftp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;code&gt;atftpd&lt;/code&gt; might not be able to bind to the &lt;code&gt;69&lt;/code&gt; port number. On Ubuntu, a service named &lt;code&gt;inet&lt;/code&gt; already keeps the hold of port &lt;code&gt;69&lt;/code&gt;. You can stop that service using &lt;code&gt;systemctl&lt;/code&gt;. If the system keep complaining, use &lt;code&gt;fuser&lt;/code&gt; to kill the process as follows&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;fuser &lt;span class="nt"&gt;-k&lt;/span&gt; 69/udp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 6:&lt;/strong&gt; Check if your TFTP server is listening&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;netstat &lt;span class="nt"&gt;-lunp&lt;/span&gt; | &lt;span class="nb"&gt;grep &lt;/span&gt;69
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Testing TFTP Server
&lt;/h2&gt;

&lt;p&gt;Before jumping right into the flashing your router using the TFTP server, it is generally a good practice to check whether the server is able to serve &lt;code&gt;tpl_recovery.bin&lt;/code&gt; file or not. &lt;/p&gt;

&lt;p&gt;It is preferred to use another computer to test the TFTP server, but you can also test it from the same machine. You'll just need to follow these steps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt;  Install &lt;code&gt;tftp&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo install &lt;/span&gt;tftp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Connect to the TFTP server using the IP address of the computer running the server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;tftp X.X.X.X
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Substitute X.X.X.X with the IP address of the computer running TFTP server&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; If you are testing from the same computer, use &lt;code&gt;0.0.0.0&lt;/code&gt; for the IP address.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Fetch &lt;code&gt;tp_recovery.bin&lt;/code&gt; file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;get tp_recovery.bin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should get a message like following on the client.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Received &amp;lt;size of the file&amp;gt; bytes &lt;span class="k"&gt;in&lt;/span&gt; &amp;lt;&lt;span class="nb"&gt;time &lt;/span&gt;taken to &lt;span class="nb"&gt;complete &lt;/span&gt;the transfer&amp;gt; seconds
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On the server, you will get a message like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&amp;lt;Date and &lt;span class="nb"&gt;time&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &amp;lt;host system name&amp;gt; atftpd[&amp;lt;some numbers I don&lt;span class="s1"&gt;'t understand 😅&amp;gt;]: Serving tp_recovery.bin to &amp;lt;IP address and port number of client&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you see messages like above, and the &lt;code&gt;tpl_recovery.bin&lt;/code&gt; is present on the client computer, then you are good to go. If not, it might be possible that you messed up something while setting up the TFTP server. Take a step back and check every step.&lt;/p&gt;

&lt;h3&gt;
  
  
  Let's Flash
&lt;/h3&gt;

&lt;p&gt;With everything set, we are good to go and flash the TP-Link Archer C50 V4 with OpenWrt. &lt;/p&gt;

&lt;p&gt;Don't get overwhelmed, just follow these steps:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1:&lt;/strong&gt; Reset your router. &lt;br&gt;
&lt;em&gt;You will not find it in the OpenWrt's documentation because it might not be needed but I like to start fresh.&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Plug the power cable into the router, but don't turn it on yet. &lt;br&gt;
&lt;em&gt;I prefer to use the power switch on the back of the router to control power.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3:&lt;/strong&gt; Connect the ethernet interface of your computer to the LAN 1 port of the router. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 4:&lt;/strong&gt; Make sure your computer is not connected to any other network. (&lt;em&gt;Turn off WiFi&lt;/em&gt;). And manually set the IP address of your wired ethernet interface to &lt;code&gt;192.168.0.66&lt;/code&gt;. &lt;strong&gt;This is important.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5:&lt;/strong&gt; After making all the configurations, press and hold the &lt;strong&gt;reset&lt;/strong&gt; button and power on the router simultaneously. &lt;/p&gt;

&lt;p&gt;⚠️ &lt;strong&gt;Don't let go of the reset button yet&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After 10 seconds the router will start downloading the firmware image from the TFTP server.  The WPS LED will also light up during this time.&lt;/p&gt;

&lt;p&gt;You will see a message as below on your TFTP server&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&amp;lt;Date and Time&amp;gt; &amp;lt;name of host system&amp;gt; atftpd[&amp;lt;Some numbers I don&lt;span class="s1"&gt;'t understand  😅&amp;gt;]: Serving tp_recovery.bin to 192.168.0.2:3026
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Voila! The router has started downloading the firmware image At this moment, you can let go of the reset button. &lt;/p&gt;

&lt;p&gt;The router will then reboot(indicated by all LEDs turning off and on). After this, only the power LED will stay on and will keep blinking.&lt;/p&gt;

&lt;p&gt;After about a minute, the router will reboot once again and you will be able to login to OpenWrt.  But, before that, you will need to follow this one last step.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 6:&lt;/strong&gt; Either configure the ethernet interface of your system to configure its IP address automatically(using DHCP) or manually set it to &lt;code&gt;192.168.1.X&lt;/code&gt; (replace &lt;em&gt;X&lt;/em&gt; with a desired number less than 255).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 7:&lt;/strong&gt; Log in to the OpenWrt dashboard by visiting &lt;code&gt;192.168.1.1&lt;/code&gt; on your browser. &lt;/p&gt;

&lt;p&gt;By default, no password is set. The username field should be already populated with &lt;code&gt;root&lt;/code&gt;. Leave the password field blank and click on &lt;code&gt;Login&lt;/code&gt;. Make sure you set a password later. &lt;/p&gt;

&lt;p&gt;You can now play with OpenWrt installed on your &lt;strong&gt;TP-Link Archer C50 V4&lt;/strong&gt; 🎉&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mXwvio7v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1609583794065/RDn2KeL0V.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mXwvio7v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1609583794065/RDn2KeL0V.png" alt="LuCI web interface of OpenWrt installed on TP-Link Archer C50 V4"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;This write-up was an attempt to document everything in one place in a beginner-friendly manner. While it includes personal experiences, it would have not been possible without the awesome work of the OpenWrt community.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://git.openwrt.org/?p=openwrt/openwrt.git;a=commit;h=01dcd574a24864c10a9c4df4304a3ce0da5c11a9"&gt;Commit adding support for TP-Link Archer C50&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://openwrt.org/toh/tp-link/archer-c50"&gt;Device page of TP-Linker Archer C50 in OpenWrt's documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://openwrt.org/docs/guide-user/installation/generic.flashing.tftp"&gt;Installing OpenWrt via TFTP guide in OpenWrt's documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>openwrt</category>
      <category>network</category>
      <category>router</category>
    </item>
  </channel>
</rss>
