Welcome! Log In Create A New Profile

Advanced

HowTo: OpenWrt on Kirkwood boxes

Posted by chessplayer 
HowTo: OpenWrt on Kirkwood boxes
June 06, 2019 03:22PM
How to install OpenWrt on Kirkwood boxes

This thread is a new version of one started by joerg_999 since I did run into a few problems with that one and I wanted to suggest a way which seems slightly easier to me and is also more general, since it is not restricted to Pogo E02. Also, I believe Jörg's post is missing a crucial step in connection with bodhi's uBoot. But, a big "Thank you!" goes to Jörg for his original post.

The procedure described in this thread is confirmed to work for Dockstar, GoFlexNet, and Pogo E02, so I am confident it will also work for the other boxes OpenWrt/LEDE provides images for ;-)

Assumptions

I assume that the box in question has the latest uBoot and is able to boot a USB device with the latest kernel and rootfs according to the first two links in section Kirkwood plugs of the wiki.

Remark: The procedure described below also seems to work with older uBoots in connection with older kernels and rootfs, which I tested with a GoFlexNet.

However, it will be absolutely necessary to be able to reach the box via netconsole or serial console.

The plan

We now want to install OpenWrt (LEDE is now OpenWrt again ...) on our box. The steps we will need to take are
  1. Boot into debian and do some modifications to the uBoot environment variables
  2. Download, rename and copy to a FAT32 USB drive an OpenWrt Image
  3. Reboot the box without a USB device but with netconsole to interact with it <- this is crucial
  4. Use netconsole to boot OpenWrt/LEDE image from the USB drive created before
  5. SSH into OpenWrt/LEDE and make sure the uBoot environment is found <- this is crucial
  6. Install to NAND via sysupgrade OpenWrt/LEDE
  7. Boot from NAND and SSH into OpenWrt/LEDE and make sure the uBoot environment is always found
  8. Enjoy!

Implementation
So, let us look at these steps in more detail.

1. Modify uBoot variables

First, we need to boot the box to debian, log in and then do the following:
fw_setenv mtdparts 'mtdparts=orion_nand:0x100000@0x0(u-boot),-@0x100000(ubi)'
fw_setenv partition 'nand0,0'
fw_setenv set_bootargs_lede 'setenv bootargs console=ttyS0,115200 $mtdparts'
fw_setenv bootcmd_lede 'run set_bootargs_lede; ubi part ubi; ubi read 0x800000 kernel; bootm 0x800000'

All the other variables can stay the way they were before, but we have to add the OpenWrt/LEDE boot option to the bootcmd. If we still have bodhi's environment variables as they came, this would be:
fw_setenv bootcmd 'run bootcmd_uenv; run scan_disk; run set_bootargs; run bootcmd_exec; run bootcmd_lede'

The important part is to add 'run bootcmd_lede' to the bootcmd you are currently using. So, if you changed something, e.g. to be able to boot with a separate boot partition or from SATA or anything like that, just append the OpenWrt/LEDE boot option to the one you are using.

2. Download an OpenWrt/LEDE image

Next, we need the appropriate image. Start on the release page of OpenWrt and choose the one you like best and then navigate to
targets/kirkwood/generic
Then, download the uImage appropriate for your box. Rename it to uImage and place it in the root of a FAT32 formatted USD device.

Hint: It makes sense to keep the browser tab open for the final step 6.

3. Reboot to NAND with (net)console

Then, we need to reboot the box without the debian USB device, but with a way of interacting with it, preferably via netconsole. The latter needs to be started on the server beforehand with
nc -l -u -p 6666
Wait until after a few error messages you see the prompt, e.g.
Dockstar>
in the console window.

4. Reboot with OpenWrt/LEDE image

Insert the drive you created in step 2 into the box and boot it by issuing the following command at the (net)console prompt:
usb reset; fatload usb 0 0x800000 uImage; bootm 0x800000
This should end with
Starting kernel ...
in the console output, meaning that OpenWrt/LEDE is now running in RAM.

5. Log in to OpenWrt/LEDE

Find the IP address of your box and ssh into it (user root without password). The following step is absolutely crucial (according to bodhi; see the first reply) in connection with bodhi's environment from the uBoot post, as I can tell from experience, since without it, I ran into problems when I first tried the procedure from Jörgs original post on a Dockstar (see my description there of how to remedy the issue if things have gone awry).

Temporarily generate or modify /etc/fw_env.config
Check whether the file /etc/fw_env.config has the following contents:
# MTD device name       Device offset   Env. size       Flash sector size       Number of sectors
/dev/mtd0 0xc0000 0x20000 0x20000
If not, modify it accordingly (e.g., using vim, which is available in OpenWrt/LEDE). If the file does not exist at all, the easiest way to generate it is
echo '/dev/mtd0 0xc0000 0x20000 0x20000' > /etc/fw_env.config
(which you can also do after removing the original file, if you would rather not fiddle around with vim ...)

Afterwards, check that the uBoot environment is found by printing the variables to screen using
fw_printenv

Remark: Since OpenWrt/LEDE only runs in RAM at the moment, this is a temporary change. If you want to be able to access the uBoot environment from the OpenWrt/LEDE rescue system later on, this step will most likely have to be repeated (see step 7 below).

6. Install to NAND

Finally, we can perform a sysupgrade of OpenWrt/LEDE either using the WIF (Web Interface) or the command line. Since we are already logged in via ssh, I only describe the latter option, while the former may be found, e.g., in step 4.b of Jörg's original post. We must do:
opkg update
opkg install ca-bundle ca-certificates libustream-openssl ubi-utils
cd /tmp
wget <URL of our desired sysupgrade file>
sysupgrade <name of our desired sysupgrade file>
The desired upgrade file may be found the same way as we found the image in step 2 above starting from the release page (but, ideally, you kept the browser tab open in step 2). There you can just copy the link address to the sysupgrade file (tar or bin depending on the release) and paste it into the ssh window.

The upgrade process will result in an automatic reboot (during which I removed the USB stick, but that may not be necessary).

7. Boot from NAND and log in to OpenWrt/LEDE

There is, unfortunately, a very good chance that OpenWrt/LEDE in NAND also cannot find the uBoot environment (as before in the case of the image loaded into RAM). Therefore, you have to repeat step 5. above in order to be able to modify the uBoot environment. This time, it will be a permanent modification of /etc/fw_env.config allowing you to make changes to the uBoot environment using your new rescue system.

8. Enjoy

---
Standart ist der Standardfehler



Edited 4 time(s). Last edit at 06/12/2019 04:48AM by chessplayer.
Re: HowTo: OpenWrt on Kirkwood boxes
June 07, 2019 01:07AM
Quote

Find the IP address of your box and ssh into it (user root without password). I am not entirely sure whether the next part is strictly necessary, but I believe so, since without it, I ran into problems when I first tried the procedure on a Dockstar.

Generate or modify /etc/fw_env.config
Check whether the file /etc/fw_env.config has the following contents:
# MTD device name Device offset Env. size Flash sector size Number of sectors
/dev/mtd0 0xc0000 0x20000 0x20000
If not, modify it accordingly (e.g., using vim, which is available in OpenWrt/LEDE).

It is a requirement of the new Kirkwood u-boot to do this (see instruction):
Generate or modify /etc/fw_env.config 
Check whether the file /etc/fw_env.config has the following contents: 
# MTD device name       Device offset   Env. size       Flash sector size       Number of sectors
/dev/mtd0 0xc0000 0x20000 0x20000

Good writeup chessplayer :) will add this as an additional tutorial for the same topic.

-bodhi
===========================
Forum Wiki
bodhi's corner
Re: HowTo: OpenWrt on Kirkwood boxes
June 07, 2019 03:46AM
bodhi,

thanks for the clarification. I updated my original post to make it quite clear that this is essential.

Cheers,

chesspalyer

---
Standart ist der Standardfehler
Re: HowTo: OpenWrt on Kirkwood boxes
June 08, 2019 08:57PM
Tried to install on a dockstar, used tftp boot,

openwrt_dockstar_uImage is https://downloads.openwrt.org/releases/18.06.2/targets/kirkwood/generic/openwrt-18.06.2-kirkwood-seagate_dockstar-initramfs-uImage


Dockstar>tftp 0x800000 openwrt_dockstar_uImage

Dockstar>bootm 0x800000




root login to openwrt ok, tried to install the packages to the initial file system, openwrt complains no space on /overlay


root@OpenWrt:/tmp# opkg install ca-bundle ca-certificates libustream-openssl ubi
-utils
Installing ca-bundle (20190110-1) to root...
Installing ca-certificates (20190110-1) to root...
Installing libustream-openssl (2018-07-30-23a3f283-1) to root...
Package ubi-utils (2.0.2-1) installed in root is up to date.
Collected errors:
 * verify_pkg_installable: Only have 0kb available on filesystem /overlay, pkg ca-bundle needs 113
 * opkg_install_cmd: Cannot install package ca-bundle.
 * verify_pkg_installable: Only have 0kb available on filesystem /overlay, pkg ca-certificates needs 122
 * opkg_install_cmd: Cannot install package ca-certificates.
 * verify_pkg_installable: Only have 0kb available on filesystem /overlay, pkg libustream-openssl needs 4
 * opkg_install_cmd: Cannot install package libustream-openssl.

root@OpenWrt:/tmp# df -h
Filesystem                Size      Used Available Use% Mounted on
tmpfs                    60.2M    668.0K     59.5M   1% /tmp
tmpfs                   512.0K         0    512.0K   0% /dev



Edited 1 time(s). Last edit at 06/08/2019 09:05PM by daviddyer.
Re: HowTo: OpenWrt on Kirkwood boxes
June 08, 2019 09:14PM
Just found a typo in

echo '/dev/mtd0 0xc0000 0x20000 0x20000' > /etc/fw_envs.config

should be

echo '/dev/mtd0 0xc0000 0x20000 0x20000' > /etc/fw_env.config
Re: HowTo: OpenWrt on Kirkwood boxes
June 08, 2019 09:44PM
Finally used a nasty method and solved it. Download the upgrade file to my http server, then we don't need opkg install those things. Just download from the http server (not https server), run upgrade, yeah!

After that, just do the opkg update and install. :-)
Re: HowTo: OpenWrt on Kirkwood boxes
June 10, 2019 04:21PM
@chessplayer
you can do it like i discribed in the "Lede on Pogo E02" but for step4 your choice should be "4b. LEDE-WIF upgrade" afterwards you should do step5, otherwise you cant get access to your envs. (4a is outdated and not longer working - runnig out of memory - with the newer Lede or openwrt)
I tested this on Pogo E02 and with the suitable files also on GoflexNet.
Also very important is the very long line in the uboot-envs:
setenv bootcmd_exec 'if run load_uimage; then; if run load_initrd; then if run load_dtb; then bootm $load_uimage_addr $load_initrd_addr $load_dtb_addr; else bootm $load_uimage_addr $load_initrd_addr; fi; else if run load_dtb; then bootm $load_uimage_addr - $load_dtb_addr; else bootm $load_uimage_addr; fi; fi; fi'
its only an extension of bodhis original and is required for correct warm booting either Lede/openwrt from nand or debian from stick.
Tried this procedure also with the new openwrt 18.06.2 and works well on both machines.



Edited 5 time(s). Last edit at 06/11/2019 02:33AM by joerg_999.
Re: HowTo: OpenWrt on Kirkwood boxes
June 11, 2019 02:17AM
joerg_999,

I tried that and it did not work. Maybe I did something wrong somewhere.

Anyway, the method I am describing did work on Dockstar, PogoE02 and also GoFlex Net, in the latter case even with an older uBoot and customised uBoot environment. Thus, I thought I would share. I does seem to me that being able to find the environment variables by having the correct /etc/fw_env.config is necessary, as also mentioned by bodhi.

But thanks for your original post, which did all the heavy lifting!

Cheers,

chessplayer

---
Standart ist der Standardfehler
Re: HowTo: OpenWrt on Kirkwood boxes
June 11, 2019 02:22AM
daviddyer Wrote:
-------------------------------------------------------
> Just found a typo in
>
> echo '/dev/mtd0 0xc0000 0x20000 0x20000' >
> /etc/fw_envs.config
>
> should be
>
> echo '/dev/mtd0 0xc0000 0x20000 0x20000' >
> /etc/fw_env.config

Thanks for pointing this out. I corrected it in the original post.

Cheers,

chessplayer

---
Standart ist der Standardfehler
Re: HowTo: OpenWrt on Kirkwood boxes
June 11, 2019 09:02AM
Yes what joerg said is absolutely correct, the modified bootcmd_exec is required to boot with Debian on USB and fall back to OpenWrt, when the USB rootfs is either corrupted or absent. Without this change, the rescue system will not work as intended.

setenv bootcmd_exec 'if run load_uimage; then; if run load_initrd; then if run load_dtb; then bootm $load_uimage_addr $load_initrd_addr $load_dtb_addr; else bootm $load_uimage_addr $load_initrd_addr; fi; else if run load_dtb; then bootm $load_uimage_addr - $load_dtb_addr; else bootm $load_uimage_addr; fi; fi; fi'

This bootcmd_exec version is what I will have as default in the next u-boot release (I actually had this on all my boxes for a couple years, but did not thtink it is important to make an update). It is not important to do this if you ony boot with Debian. However, it is a change I have planned for a while to make it more robust anyway.

Thanks for pointing that out joerg :)

-bodhi
===========================
Forum Wiki
bodhi's corner



Edited 1 time(s). Last edit at 06/11/2019 09:13AM by bodhi.
Re: HowTo: OpenWrt on Kirkwood boxes
June 12, 2019 04:33AM
bodhi Wrote:
-------------------------------------------------------
> Yes what joerg said is absolutely correct, the
> modified bootcmd_exec is required to boot with
> Debian on USB and fall back to OpenWrt, when the
> USB rootfs is either corrupted or absent. Without
> this change, the rescue system will not work as
> intended.
>
>
> setenv bootcmd_exec 'if run load_uimage; then; if
> run load_initrd; then if run load_dtb; then bootm
> $load_uimage_addr $load_initrd_addr
> $load_dtb_addr; else bootm $load_uimage_addr
> $load_initrd_addr; fi; else if run load_dtb; then
> bootm $load_uimage_addr - $load_dtb_addr; else
> bootm $load_uimage_addr; fi; fi; fi'
>
>
> This bootcmd_exec version is what I will have as
> default in the next u-boot release (I actually had
> this on all my boxes for a couple years, but did
> not thtink it is important to make an update). It
> is not important to do this if you ony boot with
> Debian. However, it is a change I have planned for
> a while to make it more robust anyway.
>
> Thanks for pointing that out joerg :)

Ok, I have one less level of conditions and I think that is what is contained in your default environment (i.e. I have
bootcmd_exec=run load_uimage; if run load_initrd; then if run load_dtb; then bootm $load_uimage_addr $load_initrd_addr $load_dtb_addr; else bootm $load_uimage_addr $load_initrd_addr; fi; else if run load_dtb; then bootm $load_uimage_addr - $load_dtb_addr; else bootm $load_uimage_addr; fi; fi
)

Just tested with an empty ext4-USB drive labeled rootfs and it did boot OpenWrt as a result (also, obviously, without any external drives). So: how does the extra if-statement make a difference? Changing it to Jörg's bootcmd_exec yielded the exact same bahavior. Another test with my old stick (which uses a separate boot partition) was the same in both cases as well - it booted the kernel image, but did not obtain an IP address, since it could not find the rootfs, I guess.

But I just realized something else: after flashing OpenWrt to NAND, the problem with etc/fw_env.config persists. Therefore, that has to be checked and corrected once more with the system booted from NAND in order to be able to modify the environment variables if necessary. I will add this step to my instructions in the first post.

Cheers,

chessplayer

---
Standart ist der Standardfehler
Re: HowTo: OpenWrt on Kirkwood boxes
June 12, 2019 05:57AM
chessplayer,

I recall I tested the new boocmd_exec env quite a bit (I wrote it myself) before posting it for joerg to try in the Pogo E02 thread. So you would need to trust me, no need to explain:)

-bodhi
===========================
Forum Wiki
bodhi's corner
Re: HowTo: OpenWrt on Kirkwood boxes
June 12, 2019 06:26AM
Found that post:
https://forum.doozan.com/read.php?4,45989,46039#msg-46039

So look back a few posts, I think joerg showed that it did not fallback to OpenWrt correctly with the original env.

-bodhi
===========================
Forum Wiki
bodhi's corner
Re: HowTo: OpenWrt on Kirkwood boxes
June 12, 2019 08:26AM
@chessplayer

A Maybe you need to add "nand erase.part ubi" in 3 or 4.
B It's not necessary to do "echo '/dev/mtd0 0xc0000 0x20000 0x20000' > /etc/fw_env.config" in step 5 since it won't be saved to NAND. It is necessary to do "echo '/dev/mtd0 0xc0000 0x20000 0x20000' > /etc/fw_env.config" in step 7 after openwrt is flashed to NAND.
C "LEDE/openwrt-WIF upgrade" should be useful when openwrt system (in ram) complains "no space on /overlay" .
Re: HowTo: OpenWrt on Kirkwood boxes
June 12, 2019 09:19AM
daviddyer Wrote:
-------------------------------------------------------
> @chessplayer
>
> A Maybe you need to add "nand erase.part ubi"
> in 3 or 4.

Don't know about that, since I went through this process on 2 Dockstars, 3 Pogo E02 and a GoFlex Net (I know, I overdid it a bit with these boxes way back when ...) and did not need this.

> B It's not necessary to do "echo '/dev/mtd0
> 0xc0000 0x20000 0x20000' > /etc/fw_env.config" in
> step 5 since it won't be saved to NAND. It is
> necessary to do "echo '/dev/mtd0 0xc0000 0x20000
> 0x20000' > /etc/fw_env.config" in step 7 after
> openwrt is flashed to NAND.

As I said, for some reason, when I left that out when trying for the first time, something went wrong. Maybe, however, I made some other foolish mistake. All I know is that it certainly does not hurt.

> C "LEDE/openwrt-WIF upgrade" should be useful
> when openwrt system (in ram) complains "no space
> on /overlay" .

Again, I do not know about that, as this did not occur in my cases. But I guess you are right about this and I am pointing people to this possibility in the above instructions should they see the need.

Maybe your points will become relevant for me when I update my NSA320 and GoFlex Home .... If so, I will be sure to report back.

---
Standart ist der Standardfehler
Re: HowTo: OpenWrt on Kirkwood boxes
June 13, 2019 11:14AM
Well, sysupgrade can do the mtd format / etc when needed, but it is always a good idea to format the new mtd when the mtd is changed / created.
Re: HowTo: OpenWrt on Kirkwood boxes
June 13, 2019 06:04PM
Well actually, what joerg did was quite important.

Quote
https://forum.doozan.com/read.php?4,42279

# when you change/add a new partition layout you always need to erase the ubi nand first before new install:
nand erase.part ubi

This will make it work the same way in the subsequent steps in different environment (stock OS, Debian,....).

If you skip the erase, it might work in Debian, but most likely it will fail in stock OS.

-bodhi
===========================
Forum Wiki
bodhi's corner



Edited 1 time(s). Last edit at 06/14/2019 02:03AM by bodhi.
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: