Welcome! Log In Create A New Profile

Advanced

Howto: Roll your own u-boot for GoFlexHome

Posted by majic79 
Howto: Roll your own u-boot for GoFlexHome
August 09, 2013 05:19PM
Well, I thought I'd share my experiences of building u-boot for the GoFlexHome

This has been an interesting course of development for the past few weeks - involving bricking and then recovering my device(s). I have two GoFlexHomes (as they were cheap) one of which is to be used for work, the other as personal storage.

u-boot-2013.07 has support for the GoFlexHome, however it's got a couple of issues, and I wanted the default environment to permit booting from USB, SATA(IDE) and UBIFS

I'm assuming that (as I) you will be building this on a Debian Wheezy platform (it's a nice base, pretty new and does everything I want to out of the box) - there may be some dependencies I've missed (I do a lot of development on this machine and I've already got everything required aside from the codesourcery cross compiler)

First, grab build-essentials and the codesourcery-arm cross compile suite (see instructions at http://www.nas-central.org/wiki/Setting_up_the_codesourcery_toolchain_for_X86_to_ARM9_cross_compiling - tweak the script to install just the arm-2011.03 toolchain)

Download u-boot-2013.07.tar.bz2 from ftp://ftp.denx.de/pub/u-boot/

$ tar xf u-boot-2013.07.tar.bz2
$ cd u-boot-2013.07
$ make goflexhome_config

Now, we need to tweak the config for the GFH, this is found in u-boot-2013.07/include/configs/goflexhome.h

/*
 * Copyright (C) 2013 Suriyan Ramasami <suriyan.r@gmail.com>
 *
 * Based on dockstar.h originally written by
 * Copyright (C) 2010  Eric C. Cooper <ecc@cmu.edu>
 *
 * Based on sheevaplug.h originally written by
 * Prafulla Wadaskar <prafulla@marvell.com>
 * (C) Copyright 2009
 * Marvell Semiconductor <www.marvell.com>
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301 USA
 */

#ifndef _CONFIG_GOFLEXHOME_H
#define _CONFIG_GOFLEXHOME_H

/*
 * Version number information
 */
#define CONFIG_IDENT_STRING	"\nSeagate GoFlex Home"

/*
 * High Level Configuration Options (easy to change)
 */
#define CONFIG_FEROCEON_88FR131	1	/* CPU Core subversion */
#define CONFIG_KIRKWOOD		1	/* SOC Family Name */
#define CONFIG_KW88F6281	1	/* SOC Name */
#define CONFIG_MACH_TYPE	MACH_TYPE_GOFLEXHOME		/* Machine type */
#define CONFIG_SKIP_LOWLEVEL_INIT	/* disable board lowlevel_init */

/*
 * Default GPIO configuration and LED status
 */
#define GOFLEXHOME_OE_LOW               (~(0))
#define GOFLEXHOME_OE_HIGH              (~(0))
#define GOFLEXHOME_OE_VAL_LOW           (1 << 29)       /* USB_PWEN low */
#define GOFLEXHOME_OE_VAL_HIGH          (1 << 17)       /* LED pin high */

/* PHY related */
#define MV88E1116_LED_FCTRL_REG         10
#define MV88E1116_CPRSP_CR3_REG         21
#define MV88E1116_MAC_CTRL_REG          21
#define MV88E1116_PGADR_REG             22
#define MV88E1116_RGMII_TXTM_CTRL       (1 << 4)
#define MV88E1116_RGMII_RXTM_CTRL       (1 << 5)

/*
 * Commands configuration
 */
#define CONFIG_SYS_NO_FLASH		/* Declare no flash (NOR/SPI) */
#define CONFIG_CONSOLE_MUX
#define CONFIG_SYS_CONSOLE_IS_IN_ENV
#define CONFIG_SYS_HUSH_PARSER	1	/* use the "Hush" shell */

#include <config_cmd_default.h>
#define CONFIG_CMD_DHCP
#define CONFIG_CMD_ENV
#define CONFIG_CMD_MII
#define CONFIG_CMD_NAND
#define CONFIG_CMD_PING
#define CONFIG_CMD_USB
#define CONFIG_CMD_IDE
#define CONFIG_CMD_DATE
#define CONFIG_CMD_EXT4
#define CONFIG_SYS_MVFS         /* Picks up Filesystem from mv-common.h */

/*
 * mv-common.h should be defined after CMD configs since it used them
 * to enable certain macros
 */
#include "mv-common.h"

/*
#define	CONFIG_SYS_TEXT_BASE	0x00060000
*/

#define CONFIG_JFFS2_NAND
#define CONFIG_JFFS2_LZO

#undef CONFIG_SYS_PROMPT	/* previously defined in mv-common.h */
#define CONFIG_SYS_PROMPT	"GFH >> "	/* Command Prompt */

/*
 *  Environment variables configurations
 */
#ifdef CONFIG_CMD_NAND
#define CONFIG_ENV_IS_IN_NAND		1
#define CONFIG_ENV_SECT_SIZE		0x20000	/* 128K */
#else
#define CONFIG_ENV_IS_NOWHERE		1	/* if env in SDRAM */
#endif
/*
 * max 4k env size is enough, but in case of nand
 * it has to be rounded to sector size
 */
#define CONFIG_ENV_SIZE			0x20000 /* 128k */
#define CONFIG_ENV_ADDR			0xA0000
#define CONFIG_ENV_OFFSET		0xA0000	/* env starts here */

#define CONFIG_CMDLINE_TAG	1
#define CONFIG_INITRD_TAG	1
#define CONFIG_SETUP_MEMORY_TAGS	1

/*
 * Default environment variables
 */
/*
#define CONFIG_BOOTCOMMAND \
	"setenv bootargs console=${console} ${mtdparts} ${bootargs_root}; " \
	"ubi part root; " \
	"ubifsmount ubi:root; " \
	"ubifsload 0x800000 ${kernel}; " \
	"bootm 0x800000"
*/
#define CONFIG_BOOTCOMMAND \
	"mw 0x800000 0 1;" \
	"run setdevice_usb;" \
	"run bootcmd_device;" \
	"run setdevice_ide;" \
	"run bootcmd_device;" \
	"run bootcmd_ubifs;" \
	"reset"


#define CONFIG_MTDPARTS \
	"mtdparts=orion_nand:1M(u-boot),6M(uImage),-(root)\0"

#define CONFIG_LOADS_ECHO	0
#define CONFIG_ETHPRIME		"egiga0"
#define CONFIG_AUTOLOAD		"no"
#define CONFIG_ROOTPATH		"/boot/uImage"
#define CONFIG_LOADADDR		0x02000000

/* Defaults taken from original u-boot defaults from device */

#define CONFIG_ETHADDR		00:50:43:f8:1b:1c
#define CONFIG_IPADDR		169.254.254.253
#define CONFIG_SERVERIP		169.254.254.254

#define CONFIG_EXTRA_ENV_SETTINGS \
	"console=ttyS0,115200\0" \
	"mtdids=nand0=orion_nand\0" \
	"mtdparts=" CONFIG_MTDPARTS \
	"bootcmd_device=run device_setup; if ext2load ${device_interface} ${device_part} 0x800000 ${rootpath}; then run device_bootargs; run device_boot; fi\0" \
	"bootcmd_ubifs=run setdevice_ubi; ubi part root 2048; ubifsmount ubi0:rootfs; run device_bootargs; setenv bootargs ubi.mtd=2,2048 ${bootargs}; nand read 0x800000 0x100000 0x600000; bootm 0x800000\0" \
	"device_setup=$device_interface reset\0" \
	"device_part=0:1\0" \
	"device_bootargs=setenv bootargs console=${console} mtdparts=${mtdparts} root=${device_root} rootdelay=${device_rootdelay} rootfstype=${device_rootfs}\0" \
	"device_boot=if ext2load ${device_interface} ${device_part} 0x1100000 /boot/uInitrd; then bootm 0x800000 0x1100000;else bootm 0x800000;fi\0" \
	"setdevice_usb=setenv device_interface usb; setenv device_root LABEL=rootfs; setenv device_rootdelay 5; setenv device_rootfs ext2;\0" \
	"setdevice_ide=setenv device_interface ide; setenv device_root /dev/sda1; setenv device_rootdelay 1; setenv device_rootfs ext3;\0" \
	"setdevice_ubi=setenv device_root ubi:rootfs; setenv device_rootdelay 1; setenv device_rootfs ubifs;\0"


/*
 * Ethernet Driver configuration
 */
#ifdef CONFIG_CMD_NET
#define CONFIG_MVGBE_PORTS	{1, 0}	/* enable port 0 only */
#define CONFIG_PHY_BASE_ADR	0
#endif /* CONFIG_CMD_NET */

/*
 *  * SATA Driver configuration
 *   */
#ifdef CONFIG_MVSATA_IDE
#define CONFIG_SYS_ATA_IDE0_OFFSET      MV_SATA_PORT0_OFFSET
#endif /*CONFIG_MVSATA_IDE*/

/*
 *  * RTC driver configuration
 *   */
#ifdef CONFIG_CMD_DATE
#define CONFIG_RTC_MV
#endif /* CONFIG_CMD_DATE */

#endif /* _CONFIG_GOFLEXHOME_H */

#define CONFIG_MACH_TYPE MACH_TYPE_GOFLEXHOME is a key part - it saves us having to provide a machid/arcNumber environment variable override (I'll be adding another writeup to add support to the longterm kernel for the GoFlexHome)

#define CONFIG_ENV_OFFSET 0xA0000 is another key part - although there's nothing preventing you putting it at 0xC0000, 0xA0000 is where the environment is stored out of the factory (I verified it by loading that part of nand into memory and then checking it with "mr" from within u-boot)

The rest of my modifications are the configuration of environment variables to suit the intended use - I've gone for boot from USB (look for /boot/uImage on USB partition 1 - only works if the USB stick is called "rootfs") if that fails, boot from IDE (SATA port, look for /boot/uImage on Sata partition 1, passes root=/dev/sda1 if it works) or if that fails, boot from UBIFS. This does work, but not with the standard kernel (it just hangs there - not sure why as yet) I've focussed on the "longterm" kernel releases and 3.2.49 and 3.4.56 both work fine, once support for the goflexhome is compiled in.

build and prepare the image for use:

codesourcery-arm-2011.03.sh
export CONCURRENCY_LEVEL=2
make u-boot.kwb
exit

If you have a superfast machine, then you may want to increase the CONCURRENCY_LEVEL - there's lots of arguments for what's a good figure (number of cores, doubled if it can hyperthread etc), but whatever the machine is capable of delivering threadwise is a good start. I'm using a quadcore machine and using a value of 4 it takes less than 5 minutes to compile.

now pad the file out to 512K page size:

dd if=u-boot.kwb of=uboot.mtd0.kwb bs=512K conv=sync

Boot up your device with stock system and login via ssh
grab blparam/flase_erase/nanddump/nandwrite/fw_printenv from jeffs tutorial on uboot http://projects.doozan.com/uboot/ and copy them into /usr/sbin, then they are always available (standard firmware uses UBIFS, and is read/write, so they stay there)

cat /dev/mtd0 0xA0000 0x20000 0x20000 > /etc/fw_env.config
cp blparam /usr/sbin
cp flash_erase /usr/sbin
cp nanddump /usr/sbin
cp nandwrite /usr/sbin
cp fw_printenv /usr/sbin
ln -s /usr/sbin/fw_printenv /usr/sbin/fw_saveenv
export PATH=/usr/sbin:/sbin:$PATH
fw_printenv > envbackup.txt
nanddump -nof uboot.mtd0.bak -l 0x100000 /dev/mtd0
nanddump -nof uImage.mtd1.bak -l 0x600000 /dev/mtd1
nanddump -nof rootfs.mtd2.bak -l 0xf900000 /dev/mtd2

Then using any appropriate method (network transfer, load it onto a USB stick and plug it into the USB port on the device, tftp from within u-boot environment), transfer the file to the device and flash it to NAND

!Warning - doing this without also flashing a replacement kernel into MTD1 will cause you problems!

nandwrite uboot.mtd0.kwb /dev/mtd0
nandwrite uImage.mtd1.kwb /dev/mtd1

This is largely speculation - I had serial access and tested via UART boot first, then flashed it to memory. I also did my flashing within the u-boot environment, so I have not yet tested from within a Linux environment. I would recommend that uboot and uImage (see next writeup) are created and flashed together for the best reliability, unless you have a successful netconsole or serial link working (sadly, not tested the netconsole output yet)



Edited 2 time(s). Last edit at 08/09/2013 06:29PM by majic79.
Clément
Re: Howto: Roll your own u-boot for GoFlexHome
September 21, 2013 07:28AM
Hi,

I'm trying to rebuild u-boot for a GoFlexHome following your instructions and Jeff's ones at http://projects.doozan.com/uboot/build_uboot.htm but the resulting binary is not booting.

I've taken the 2013.07 version, taken your goflexhome.h and compiled it with the arm-linux-gnueabi toolchain.

At the end of the compilation, I get this:

Preparing kirkwood boot image to boot from nand
Nand ECC mode = default
Nand page size = 0x800
Image Type:   Kirkwood Boot from NAND Flash Image
Data Size:    396648 Bytes = 387.35 kB = 0.38 MB
Load Address: 00600000
Entry Point:  00600000


I then created the uboot.mtd0.kwb and loaded in my goflexhome, using tftp.
tftp 0x800000 uboot.mtd0.kwb
go 0x800200


After this, I get:
## Starting application at 0x00800200 ...

on the serial console and nothing more. Nothing on the eth0 interface either.

I was wondering what I missed: is the 0x200 offset still valid for the GoFlexHome? Should I start from 0x600000 as suggested by the message at the end of the compilation? Is the arm-gnueabi toolchain not working to compile uboot?
Clément
Re: Howto: Roll your own u-boot for GoFlexHome
September 22, 2013 05:48AM
I found a way to get out of blindness using kwboot as described here: http://forum.doozan.com/read.php?3,7852,7852
:-)
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: