Category: OpenWrt

  • LEDE 19.07 on the Ubiquity ER-lite3

    The Ubiquity EdgeRouter Lite is my new favorite OpenWrt device. It is fast and inexpensive ($150 new) and the os is on a USB Stick. Stock Photo

    Pros

    • 3 independent Gigabit network ports.
    • Serial Console
    • Cheap and still supported.
    • Stock Edge-os would work for most tasks.
    • OS on a USB-stick easiest backup and install EVER.
    • 512 K of memory.

    Cons (some assembly required)

    • Because the stock usb stick and (unused) flash is only 4K LEDE considers it a 4K and are threatening to stop producing stock images after 19.07.
    • Third party usb sticks take longer to start up than the on board bootloader (U-boot) expects. So a pause and usb reset need to be configured.

    How do I get set up?

    Building 19.07 for the device

    • Getting the source. See LEDE documentation for dependencies.
    feurig@vasily:~$ git clone https://git.openwrt.org/openwrt/openwrt.git
    
    • Building for the target
    feurig@vasily:~$ cd openwrt/
    feurig@vasily:~/openwrt$ make clean
    feurig@vasily:~/openwrt$ git pull . v19.07.3
    feurig@vasily:~/openwrt$ ./scripts/feeds update -a
    feurig@vasily:~/openwrt$ ./scripts/feeds install -a
    feurig@vasily:~/openwrt$ make menuconfig
    
        Target System (Cavium Networks Octeon)  --->
        Target Profile (Ubiquiti EdgeRouter Lite)  --->                                                                                   
        Target Images --------->
           [*] ramdisk  --->
           ***   Root filesystem archives ***
           [ ] cpio.gz
           [*] tar.gz
           ***   Root filesystem images ***
           [*] ext4  --->
           [ ] squashfs  ---- 
           [*] GZip images
               *** Image Options *** 
           (104) Root filesystem partition size (in MB) 
    feurig@vasily:~/openwrt$ make -j8 download world
    feurig@vasily:~/openwrt$ mv bin/targets/octeon/generic/openwrt-octeon-erlite-ext4-sysupgrade.tar.gz ~/firmware/
    feurig@vasily:~/openwrt$ ./scripts/diffconfig.sh > ../firmware/openwrt-octeon-erlite-ext4-sysupgrade.diffconfig
    

    Deploying the image

    • download the image from the build server to a local linux box.
    feurig@colbert:~ $ scp feurig@wrt.suspectdevices.com:firmware/openwrt-octeon-erlite-ext4-sysupgrade.tar.gz .
    
    • Format the stick with 2 partitions (142M dos and the lemaining linux)
    root@colbert:~ # fdisk -l
    ... On our machine, this is our disk ...
    Disk /dev/sda: 7.6 GiB, 8166703104 bytes, 15950592 sectors
    ...
    root@colbert:~ # fdisk /dev/sda
    ... Partition disk here ...
    root@colbert:~ # fdisk -l
    ...
    Disk /dev/sda: 7.6 GiB, 8166703104 bytes, 15950592 sectors
    Disk model: USB 2.0 FD      
    ...
    Device     Boot  Start     End Sectors  Size Id Type
    /dev/sda1         2048  292863  290816  142M  c W95 FAT32 (LBA)
    /dev/sda2       292864 3710975 3418112  1.6G 83 Linux
    ...
    root@colbert:/home/feurig# mkfs.vfat /dev/sda1
    root@colbert:/home/feurig# mkfs.ext4 /dev/sda2
    
    • copy firmware to usb stick
    root@colbert:~ # mkdir scratch
    root@colbert:~ # cd scratch/
    root@colbert:~ # tar -xf ../openwrt-octeon-erlite-ext4-sysupgrade.tar.gz 
    root@colbert:~ # mkdir root oroot kernel
    root@colbert:~ # mount /dev/sda1 kernel/
    root@colbert:~ # mount /dev/sda2 root/
    root@colbert:~ # mount sysupgrade-erlite/root oroot -o loop
    root@colbert:~ # cp sysupgrade-erlite/kernel kernel/vmlinux.64
    root@colbert:~ # md5sum sysupgrade-erlite/kernel | cut -d' ' -f 1 > kernel/vmlinux.64.md5
    root@colbert:~ # rsync -aHAX oroot/* root/
    root@colbert:~ # umount kernel root oroot
    root@colbert:~ # sync
    

    Fixing the bootloader for standard USB Sticks.

    • If the usb stick used takes longer than the stock one to initialize the boot will fail.
    don$ screen /dev/tty.usbserial 115200
    ...
    U-Boot 1.1.1 (UBNT Build ID: 4670715-gbd7e2d7) (Build time: May 27 2014 - 11:16:22)
    .
    BIST check passed.
    UBNT_E100 r1:2, r2:18, f:4/71, serial #: 802AA84CE978
    MPR 13-00318-18
    Core clock: 500 MHz, DDR clock: 266 MHz (532 Mhz data rate)
    DRAM:  512 MB
    Clearing DRAM....... done
    Flash:  4 MB
    Net:   octeth0, octeth1, octeth2
    .
    USB:   (port 0) scanning bus for devices... 
          USB device not responding, giving up (status=0)
    1 USB Devices found
           scanning bus for storage devices...
    No device found. Not initialized?                                                                                                                  0 
    
    • Getting the stock boot command
    Octeon ubnt_e100# printenv               
    bootdelay=0
    baudrate=115200
    download_baudrate=115200
    nuke_env=protect off $(env_addr) +$(env_size);erase $(env_addr) +$(env_size)
    autoload=n
    ethact=octeth0
    bootcmd=fatload usb 0 $loadaddr vmlinux.64;bootoctlinux $loadaddr coremask=0x3 root=/dev/sda2 rootdelay=15 rw rootsqimg=squashfs.img rootsqwdir=w mtd
    ...
    
    • Copy the bootcmd from the existing environment and add a delay and usb reset
    Octeon ubnt_e100# setenv bootcmd 'sleep 10;usb reset;fatload usb 0 $loadaddr vmlinux.64;bootoctlinux $loadaddr coremask=0x3 root=/dev/sda2 rootdelay=15 rw rootsqimg=squashfs.img rootsqwdir=w mtd'
    Octeon ubnt_e100# saveenv
    Octeon ubnt_e100# reset
    

    Adding Initial Configuration to build

    In our deployment the router is maintained externally. For this reason direct login to the router as root is disabled and sudo enabled accounts are installed. These accounts connect using ssh keys and escallate privilages with their passwords. The root account is locked and ssh access is allowed from the wan port. The process for this is documented here

    Once this is done the configuration can be saved to a tarball and added to the build under the files directory. These files are copied into the root filesystem of the target. The box then comes up pre configured and pre-hardened. One kludge used here is to add an rc.local which changes the users home directorys to be owned by them. Otherwise the ssh keys will not have the correct permissions.

    Also /etc/sudoers, /etc/rc.local, and /home should be added to /etc/sysupgrade.conf. This way the configuration changes will be preserved while doing a sysupgrade

    Rebuilding using a repo.

    Now that we have a working pre-hardened build for our router we can adjust and repeat the build. (this example assumes that the build server has access to the repo)

    feurig@vasily:~$ cd openwrt
    feurig@vasily:~/openwrt$ git pull . v19.07.3
    feurig@vasily:~/openwrt$ mv files /tmp/
    feurig@vasily:~/openwrt$ git clone git@bitbucket.org:houselan/config.git files
    Cloning into 'files'...
    feurig@vasily:~/openwrt$ cp files/openwrt-octeon-erlite-ext4-sysupgrade.diffconfig .config
    feurig@vasily:~/openwrt$ make defconfig
    #
    # configuration written to .config
    #
    feurig@vasily:~/openwrt$ ./scripts/feeds update -a
    ...
    feurig@vasily:~/openwrt$ ./scripts/feeds install -a
    ...
    feurig@vasily:~/openwrt$ make -j8 download world
    feurig@vasily:~/openwrt$ mv bin/targets/octeon/generic/openwrt-octeon-erlite-ext4-sysupgrade.tar.gz ~/firmware/
    feurig@vasily:~/openwrt$ ./scripts/diffconfig.sh > ../firmware/openwrt-octeon-erlite-ext4-sysupgrade.diffconfig 
    

    References

    Primary

  • Transit Tracker Rebuild: Making Due With What You Have.

    Most of this week has been devoted to finishing the house network setting up a workspace in the garage and using it. One of the things I have been trying to get off of my plate was to rebuild the transit tracker that we use to tell us when the next max is going downtown. In order to network from the house to the garage I have to navigate a super creepy crawl space and not get spider bitten or set up a wireless bridge. One of the OpwnWrt devices we bought to evaluate seemed perfect. The TP-Link TP-WR740.

     

    Getting the OpenWrt operating system on the router is pretty much a matter of uploading the new firmare ( http://downloads.openwrt.org/attitude_adjustment/12.09-beta/ar71xx/generic/openwrt-ar71xx-generic-tl-wr740n-v4-squashfs-factory.bin) using the routers web based interface. Accessing the serial port required some surgery.

     

    Once the serial was connected to the 4 pin connector I tested it with my ftdi.3.3v serial cable. Then I tried to see if the 3.3v tx signal was strong enough to be read by a sparkfun 5v serial lcd board I had on the bench. It wasn’t. If i had the parts for the 3.3v-5v boards i had fabbed last month (in particular the 74ahc125) then I would be done. So I looked around for what I could find. One of the documents I found on this was an app note from microchip called “3V Tips and Tricks” (http://ww1.microchip.com/downloads/en/DeviceDoc/chapter%208.pdf). As I was looking through it I went out to the garage and tried to see what I had that I could use. In a box labeled “chips and dips” I found a bunch of lm393 comparators that I had been packing around for over 10 years.

    So I soldered an lm7805 to the dc coming in and the ground-plain started breadboarding.

    I got no love from the resistor values provided by microchip so I put a pot in place opened a minicom connection to the serial on the router, held my hand on the g key, and rotated the pot until I got ggg’s on the lcd. Then I continued until I stopped getting characters. Then I centered the pot in between those places pulled it out and measured it with a multimeter. Which gave me the circuit below which I wired up bug style and embedded in hot glue.

     

    There was still a little work to do. The OpenWrt luci system takes up a lot of space but makes trying things very easy. The command line tools aren’t bad but luci comes with most of the stock images which is ok. The thing that forced me to build a custom image was that the fact that the serial port starts up at 115200 baud rate and my lcd module didn’t support that. To make matters worse sending the boot messeges at 115200 created serial sequences that would corrupt the lcd module.

    To get the baud rate to 9600 required me to:

    • Upload the OpenWrt-ImageBuilder-ar71xx_generic-for-linux-i486.tar.bz2 to one of my linux machines.
    • Find and replace parts of the Makefile where the console baud rate was hard coded. (target/linux/ar71xx/image/Makefile)
    • “make image” with the correct target and any packages I wanted installed.

    I also commented out the install luci part in the .config file at the top of the tree and added the trimet.lua script to a /scripts directory and which was magically added to my custom image (though not were I expected it to be).

    make image PROFILE=TLWR740 PACKAGES="nano coreutils-stty coreutils-nohup monit lua luasocket" FILES="myscripts"

    This created several images including one called bin/ar71xx/openwrt-ar71xx-generic-tl-wr740n-v4-squashfs-sysupgrade.bin
    to install it i scp’d it to the /tmp/ partition of the router sshd into it and as root ran the command.

    root@fatlink:~# sysupgrade -v openwrt-ar71xx-generic-tl-wr740n-v4-squashfs-sysupgrade.bin

    where as the router flashed the image and rebooted.
    A little tweeking on the startup scripts and we were done.

    IMG_1545

    The transit tracker code from my previous post runs while the router is still doing its job as a hub and a wireless router.

    Not bad for 20 bucks and what we had on hand.

    References: