Skip to content

Building and Running OpenWRT for ARC

Yuriy Kolerov edited this page Aug 1, 2023 · 1 revision

Introduction

OpenWrt is an embedded Linux distribution that is typically meant to be used on wireless routers. This article describes how to build and run OpenWrt for execution on ARC AXS10x and HSDK Development Platforms.

The ARC SDP has no built-in wireless interfaces however it's possible to attach an external USB Wi-Fi dongle and use the ARC SDP as a wireless access point. Compared to AXS platfrom HSDK has on-board Wi-Fi module but as of today it couldn't be used together with micro-SD card and so for time being we'll revert to the same setup as with AXS - we'll use external USB Wi-Fi module.

Unfortunately not all USB Wi-Fi dongles may work in access point mode (most are supposed to be used only as wireless clients) and not all wireless chipsets are supported in recent versions of Linux kernel. Best options are USB Wi-Fi dongles based on Atheros so-called ath9k_htc chips: AR7010 (list of known devices with that chipset - https://wikidevi.com/wiki/Atheros_AR7010) or AR9271 (list of known devices with that chipset - https://wikidevi.com/wiki/Atheros_AR9271).

One widely available dongle is the TP-Link TL-WN722N (https://wikidevi.com/wiki/TP-LINK_TL-WN722N) and we use it as a reference device for OpenWrt on ARC SDP.

Additionally it's possible to build and run OpenWrt in the ARC nSIM simulator environment. This is useful for debugging purposes and simple smoke-testing to verify image booting, etc.

This articles describes two types of images: 1) Images for ARC SDP Platform as well as 2) Images for the ARC nSIM simulator.

Prerequisites

Software

OpenWrt can only be built on a Linux development host, so either a real Linux host or a virtual machine with Linux installed in the client should be used.

Before building OpenWrt it's important to make sure the build machine has all required packages installed. Please refer to OpenWRT Wiki where examples for different host Linux distributions are provided: https://wiki.openwrt.org/doc/howto/buildroot.exigence#examples_of_package_installations

For example for Fedora 22 it will be:

dnf install -y subversion binutils bzip2 gcc gcc-c++ gawk gettext git-core \
flex ncurses-devel zlib-devel zlib-static make patch unzip \
perl-ExtUtils-MakeMaker glibc glibc-devel glibc-static quilt sed sdcc \
intltool sharutils bison wget openssl-devel

Hardware

  • Upon initial start, OpenWrt on ARC boards will have wireless disabled and wired interface won't accept connections from outside. Because of this, it is required to have ARC board connected to development host via "data-port". Serial port terminal should be available on that machine. Any terminal emulator program like Hyperterminal, minicom, cutecom, putty will work. Terminal must be set for baud-rate 115200 with 8 data bits, no parity, and 1 stop bit.

  • The ARC board must be connected to existing Ethernet network in order for it to operate as a router. The ARC board also requires access to a working DHCP server on the network in order to get its wired (Ethernet) network settings.

Building

ARC AXS101 and AXS103 boards are supported in the most recent release of Lede (former OpenWrt fork). SD-card images for those boards are available by the links below:

HSDK board was introduced much later and SD-card images for it are only available from snapshots here: https://downloads.openwrt.org/snapshots/targets/archs38/generic/openwrt-archs38-generic-Default-sdcard-vfat-ext4.img.gz

The rest of this article uses method of building from a local git (clone) repo.

  • Clone OpenWrt git repository git clone https://git.openwrt.org/openwrt/openwrt.git

  • Go into folder with local repository: cd openwrt

  • Run configuration utility: make menuconfig

  • Select "Synopsys DesignWare ARC 770D" or "Synopsys DesignWare ARC HS38" as a target system, save configuration and exit from configuration utility. Note built images will be universal. SD-card image built with "Synopsys DesignWare ARC 770D" configuration will work on AXS101 while SD-card image built with "Synopsys DesignWare ARC HS38" works equally well on both AXS103 and HSDK.

  • By default OpenWrt has no WebUI, so the only way to communicate with the board is through a serial console. It is possible to build and enable a LUA-based WebUI (so-called LuCI) for OpenWrt. If this is desired, users should enable LuCI packages like this:

    scripts/feeds update
    scripts/feeds install luci
    

And then select LuCI in configuration. Run make menuconfig and enable luci in "LuCI -> Collections".

  • Run build procedure:

    make
    

It is possible to build in a multithreaded way:

make -j X

(where X is number of jobs (commands) to run simultaneously)

Once build process is complete, final images will be located in "bin" folder.

If "Synopsys DesignWare ARC 770D" target system was selected, the following files will be produced:

  • bin/targets/arc770/generic-uClibc/openwrt-arc770-generic-Default-sdcard-vfat-ext4.img.gz - compressed SD-card image for use with U-Boot bootloader on AXS101
  • bin/targets/arc770/generic-uClibc/openwrt-arc770-generic-nsim-initramfs.elf – ELF file is for use with nSIM for ARC 700

If "Synopsys DesignWare ARC HS38" target system was selected, the following files will be produced:

  • bin/targets/archs38/generic-uClibc/openwrt-archs38-generic-Default-sdcard-vfat-ext4.img.gz - compressed SD-card image for use with U-Boot bootloader on AXS103 and HSDK
  • bin/targets/archs38/generic-uClibc/openwrt-archs38-generic-nsim_hs-initramfs.elf – ELF file is for use with nSIM for ARC HS38

Running

Running in simulation

The simplest way to see how and if at all OpenWrt works on ARC is to run it in simulation environment. For that one may use one of existing simulator engines for ARC - nSIM. This indeed will only allow interested user to see boot console and interact with OpenWrt via virtual serial console in terminal window because there's no other peripherals in nSIM other than serial. Still that helps to see that at least OpenWrt's kernel is up and basic stuff works. Good application for that is a simple smoke testing of development snapshots etc.

So first the ARC nSIM simulator must be installed on your development machine. Note even Free nSIM (https://www.synopsys.com/cgi-bin/dwarcnsim/req1.cgi) could be used to run vmlinux for ARC770.

Then use the following command-line to launch OpenWrt on ARC770 in [Free] nSIM:

nsimdrv -prop=nsim_isa_family=a700 -prop=nsim_isa_atomic_option=1 -prop=nsim_mmu=3 -prop=icache=32768,32,2,0 -prop=dcache=32768,32,4,0 -prop=nsim_isa_dpfp=none -prop=nsim_isa_shift_option=2 -prop=nsim_isa_swap_option=1 -prop=nsim_isa_bitscan_option=1 -prop=nsim_isa_sat=1 -prop=nsim_isa_mpy32=1 -prop=nsim_isa_enable_timer_0=1 -prop=nsim_isa_enable_timer_1=1 -prop=nsim_mem-dev=uart0 bin/targets/arc770/generic-uClibc/openwrt-arc770-generic-nsim-initramfs.elf

Note: the cache line length for aRC770 in nSIM is set to 32 bytes. This value matches cache line length of AXS101 board and so base kernel binary (without built-in device tree blob) is built only once both both AXS101 and ARC nSIM.

To run Lede's vmlinux on ARC HS38 in nSIM you'll need proprietary MetaWare tools installed because images for ARC HS38 are only built for multi-core (AKA SMP) configurations and nsimdrv cannot instantiate multi-core simulation as of today. Now if you have Metaware Debugger (AKA mdb) installed that's the command line which could be used to fire-up simulation:

export NSIM_MULTICORE=1
mdb -pset=1 -psetname=core0 -prop=ident=0x00000050 -cmpd=soc -nsim -av2hs -core1 -prop=nsim_mem-dev=uart0,base=0xc0fc1000,irq=0,use_connect=1 -profile -Xrtc -Xtimer0 -Xtimer1 -Xlib -Xll64 -Xatomic -Xunaligned -Xmacd -mmuv4 -prop=mmu_pagesize=8192 -prop=mmu_super_pagesize=32768 -prop=mmu_stlb_entries=16 -prop=mmu_ntlb_ways=4 -prop=mmu_ntlb_sets=128 -icache=16384,64,2,o -dcache=16384,64,4,o -on=nsim_print-sys-arch -prop=nsim_isa_num_actionpoints=4 -prop=nsim_isa_aps_feature=1 -prop=nsim_connect=2 -prop=nsim_connect_idu=1 -prop=nsim_connect_gfrc=1 -prop=nsim_connect_ici=1 bin/targets/archs38/generic-uClibc/openwrt-archs38-generic-nsim_hs-initramfs.elf
mdb -pset=2 -psetname=core1 -prop=ident=0x00000150 -cmpd=soc -nsim -av2hs -core1 -prop=nsim_mem-dev=uart0,base=0xc0fc1000,irq=0,use_connect=1 -profile -Xrtc -Xtimer0 -Xtimer1 -Xlib -Xll64 -Xatomic -Xunaligned -Xmacd -mmuv4 -prop=mmu_pagesize=8192 -prop=mmu_super_pagesize=32768 -prop=mmu_stlb_entries=16 -prop=mmu_ntlb_ways=4 -prop=mmu_ntlb_sets=128 -icache=16384,64,2,o -dcache=16384,64,4,o -on=nsim_print-sys-arch -prop=nsim_isa_num_actionpoints=4 -prop=nsim_isa_aps_feature=1 -prop=nsim_connect=2 -prop=nsim_connect_idu=1 -prop=nsim_connect_gfrc=1 -prop=nsim_connect_ici=1 bin/targets/archs38/generic-uClibc/openwrt-archs38-generic-nsim_hs-initramfs.elf
mdb -multifiles=core0,core1 -cmpd=soc -run -cl

Running on ARC SDP systems (AXS10x) and HSDK

Preparing SD-card with system image

On platforms which have access to storage medias and moreover have U-Boot bootloader installed (that's the case for ARC SDP) it's possible to load built image of OpenWrt from either SD-card, TFTP server or USB mass-storage device and then run it in U-Boot.

The most convenient approach here is SD-card usage because SD-card is tiny and barely extends size of the development board, could be easily replaced and sure everybody else out there use SD-cards for system images.

And that's what we generate for ARC SDP boards these days. You may either build your own image as described above or simply grab the latest snapshot image from OpenWrt's autobuilder:

Once image is available on the local machine you need to extract it on SD-card you'll be using to boot ARC SDP or HSDK. On Linux host that's as simple as:

wget https://downloads.openwrt.org/snapshots/targets/archs38/generic/openwrt-archs38-generic-Default-sdcard-vfat-ext4.img.gz
gunzip --stdout openwrt-archs38-generic-Default-sdcard-vfat-ext4.img.gz | sudo dd of=/dev/mmcblk0 bs=1M

On Windows you may use a special Win32 Disk Imager utility from here https://sourceforge.net/projects/win32diskimager/, note you'll need to extract gzip archive first before passing image to Win32 Disk Imager. For example that might be done with 7zip archive manager or probably any other decompression utility for Windows.

When ready insert this prepared SD-card in ARC SDP or HSDK (we essentially assume that different images are required for AXS101 and AXS103/HSDK boards so please be careful when matching an image you're writing on SD-card with the board you're going to use it with).

Setting up U-Boot bootloader

On ARC SDP boards U-Boot bootloader is usually programmed in SPI-flash on the base-board and could be auto-started on power-on. For that it're required to set some dip-switches on the base-board in the following positions:

SW2501:
 1 - OFF
 2 - ON
 3 - OFF
 4-6 - ON
 7 - OFF

SW2503: all ON

SW2502:
 1-4 - OFF
 5 - ON
 6 - OFF
 7 - ON

U-Boot (as well as later Linux kernel) use so-called Data-port (USB Type B female connector) for serial console. There's FTDI's USB-to-RS232 IC installed on the SDP's base-board so don't be surprised USB-cable is used instead of common RS-232 cable. But that requires FTDI drivers to be installed on the host. In most of modern Linux distributions FTDI drivers are usually already built into the kernel but to access /dev/ttyUSB user must be in dialout group. To add your user in the group execute as an administrator:

sudo usermod -a -G dialout $USERNAME

In case of Windows machine FTDI drivers must be installed separately (if not already installed), please find drivers and instructions how to choose and install one here: http://www.ftdichip.com/Drivers/VCP.htm

When finally serial port is available (on Linux host it most probably will be /dev/ttyUSB0, on Windows COMx) use terminal application of your choice, point it to the newly created serial port and set it to 115200 8n1.

Now power-up the SDP board and you should see some information printed in the serial console. In case of AXS101 pre-bootloader outputs data to another serial port and so only U-Boot header and prompt should appear like that:

U-Boot 2016.03-dirty (Apr 20 2016 - 21:03:39 +0300)

I2C:   ready
DRAM:  512 MiB
NAND:  512 MiB
MMC:   Synopsys Mobile storage: 0
In:    serial0@e0022000
Out:   serial0@e0022000
Err:   serial0@e0022000
Net:   
Warning: ethernet@e0018000 (eth0) using random MAC address - f2:c8:23:e1:b6:67
eth0: ethernet@e0018000
Hit any key to stop autoboot:  0

In case of AXS103 pre-bootloader prints its information in the same serial port so a bit more data will appear:

** PREBOOT **
Apr 18 2016
17:07:42
ARCHS38
52
CPU-FPGA-VERSION:
2132016
2330
MB-FPGA-VERSION:
2562015
00
MB-CPLD-VERSION:
20102014
935
FLASH SPEED: 50MHz
FLASH READ MODE: FAST
FLASH ADDR MODE: 3byte
READ INFO FROM FLASH:
UPDATE FLASH
IMAGE: SPIFLASH
VALID IMAGE FOUND IN:
00
100000
** HEADER **
ARCID:
52
SIZE:
4CA4C
CRC:
B8
COPYTO:
80FFFFFC
LOAD
VRF:
 OK
JUMP


U-Boot 2016.03-00003-g9a6dd15 (Apr 25 2016 - 15:54:28 +0300)

I2C:   ready
DRAM:  512 MiB
NAND:  512 MiB
MMC:   Synopsys Mobile storage: 0
In:    serial0@e0022000
Out:   serial0@e0022000
Err:   serial0@e0022000
Net:   
Warning: ethernet@e0018000 (eth0) using random MAC address - a2:1e:dc:c6:03:ab
eth0: ethernet@e0018000
Hit any key to stop autoboot:  0

If still no U-Boot prompt as above appear you check:

  1. If so-called "Tunnel LEDs" near the fan on the base-board are Green (LED0) and Red (LED1)
  2. LED1505 displays 4 for AXS101 and 3 for AXS103, LED1506 displays '0'

If above conditions were not met please check SDP's manual on:

  1. How to make sure ARC core gets auto-started on power-on
  2. How to program U-Boot in SPI-flash

Hopefully U-Boot's prompt is there so press any key to stop U-Boot from execution of default boot sequence (which is most probably loading of uImage from SD-card and subsequent execution of it). We'll need to override default boot command so U-Boot properly loads OpenWrt's image from SD-card. For that we need:

  • Specify device tree blob to be used
  • For AXS101 we need axs101.dtb:
setenv dts axs101.dtb
  • For AXS103 we need axs103_idu.dtb:
setenv dts axs103_idu.dtb
  • Specify bootcmd that loads not only uImage but also passes device tree blob to the kernel, we do it that way (note that's exactly the same line for both board flavors):
setenv bootcmd fatload mmc 0 \$(loadaddr) boot.scr\; source \$(loadaddr)

When all that setup is done save U-Boot's environment in non-volatile memory with saveenv so next time you reset or even power-toggle the board it remembers all the settings that were done and will contnue to boot automatically in OpenWrt.

And now really press reset button or say boot in U-Boot's command prompt. You should see how OpenWrt gets started.

On HSDK board there is no need to do anything with u-boot. Just plug SD-card in board, power it up and wait until system loads. Note DIP-switch BIM should be in 1:off, 2:on state while both BMC and BCS should be in 1: on, 2:on state.

First boot setup of OpenWrt

If you are lucky enough and OpenWrt distribution started fine (and Linux kernel boots to the user-space and all init scripts were executed successfully) you'll see an invitation like that in the serial console

Please press Enter to activate this console.

And pressing Enter will bring you to:

BusyBox v1.27.2 () built-in shell (ash)

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 OpenWrt SNAPSHOT, unknown
 -----------------------------------------------------
=== WARNING! =====================================
There is no root password defined on this device!
Use the "passwd" command to set up a new password
in order to prevent unauthorized SSH logins.
--------------------------------------------------
root@OpenWrt:/# 

Cool that means basic OpenWrt system is up and running. But that basic system is indeed has only bare minimum of software packages installed and as well as wireless interface is not configured. That means we need to do some first-time settings but since we're running off of SD-card all our settings will be kept between reboots.

Installing extra software packages

Serial console is very powerful thing but not so nice and convenient for not very experienced user. Luckily OpenWrt has really awesome Web-UI called LuCI (which stands for Lua-based Unified Configuration Interface). To install it just execute:

opkg update
opkg install luci

The same way it's possible to install many other packages, but given Web-UI is up and runing by that time why bother with command-line if the same could be done from Web-UI (see System -> Software).

Just in case to access OpenWrt's Web-UI you need to know IP-address of the board. That might captured from ifconfig output:

# ifconfig 
br-lan    Link encap:Ethernet  HWaddr A2:1E:DC:C6:03:AB  
          inet addr:10.42.0.163  Bcast:10.42.0.255  Mask:255.255.255.0
          inet6 addr: fe80::a01e:dcff:fec6:3ab/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:684 errors:0 dropped:0 overruns:0 frame:0
          TX packets:742 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1101345 (1.0 MiB)  TX bytes:60638 (59.2 KiB)

In my case board's IP-address is 10.42.0.163, so open web-browser of choice and direct it to http://10.42.0.163. Just press Login button (since there's no password set yet) and enjoy LuCI.

Enabling wireless interface

By default on the first boot no wireless interface is configured in OpenWrt that means if there's plan to attach USB Wi-Fi dongle with an AXS board we need to make sure OpenWrt knows there's a wireless inetrface and we do want to enable and use it. That could be achieved with the following command once USB Wi-Fi dongle is inserted and recognized by the Linux kernel:

wifi config

Now in WebUI go to Network -> Wireless and press 'Enable', at this point new (open, i.e. with no encryption) Wi-Fi network "OpenWrt" will appear and users will be able to connect to it.

Other method is using serial console. Just open /etc/config/wireless file and remove line:

option disabled '1'

Then run:

wifi restart

Useful links

  1. Development FAQ (OpenWRT Wiki)
  2. OpenWrt build system – Installation (OpenWRT Wiki)
  3. Compiling OpenWrt from source (ljdelight.com)
  4. How to debug Linux kernel with MetaWare Debugger

Known issues

On ARC AXS101 the following known issue have been observed when trying to run OpenWrt with TP-Link TL-WN722N USB Wi-fi dongle.

  • TL-WN722N USB Wi-Fi adapter silently dies on heavy load (STAR 9000979181)

    There is no work-around for this issue yet (except disabling EHCI support in Linux kernel for AXS101 because in USB 1.1 mode AKA OHCI all works fine but slower <= 5Mbit/sec compared to up-up 20 in USB 2.0 mode). Normal browsing works properly however higher throughput applications such Speedtest app on smartphone cause the wireless interface to eventually fail. As this is outside to core ARC port these issues have not been debugged further.

    If the wireless network OpenWrt silently disappears as described above just reboot the board.

Clone this wiki locally