GrabDuck

Convert to Lenny - shihsung

:

My IP Addresses:
    Gateway: 192.168.1.10
    VMWare Server host: 192.168.1.1
    openSUSE VM: 192.168.1.100
    HD-HLAN: 192.168.1.200

1. Install openSUSE 11.1 x86_64 KDE on VMWare Server 2.0 VM
    Remove beagle related packages
    Install gcc, ncurses-devel, automake, atftp, yast2-nfs-server
    Install and configure Samba and NFS servers
    Make a VM snapshot

2. Install ELDK 4.1 mips-2007-01-21.iso for mips_4KCle
    su
    cd /mnt
    mkdir nfs loop
    mount 192.168.1.1:/home/vm/iso nfs
    mount -o loop nfs/mips-2007-01-21.iso loop
loop/install -d /opt/eldk/mips-2007-01-21 mips_4KCle
NOTE: Some of the rpm packages on mips-2007-01-21.iso hang when installing. To continue, just find the processes with "ps aux | grep rpm" then terminate them with "kill -9 <pid>".
umount loop
umount nfs
exit

3. Find and download the source tarballs and patches
utelnetd-0.1.9.tar.gz
HD-HLAN_FW205_042005.zip
u-boot-2009.06.tar.bz2
linux-2.6.30.4.tar.bz2
busybox-1.14.2.tar.bz2
debootstrap_1.0.13_all.deb
e2fsprogs-1.41.6.tar.gz
u-boot-2009.06-hdhlan.patch
linux-2.6.30.4-0.2-hdhlan.patch

4. Setup servers on openSUSE VM
Disable firewall with yast2
su
mkdir -p /tftpboot/busybox /tftpboot/HD-HLAN_FW205
chown -R noboby.nogroup /tftpboot
chmod -R a+wt /tftpboot
mkdir /home/share
chown nobody.nogroup /home/share
chmod a+wt /home/share
vi /etc/exports
/tftpboot -rw,no_root_squash,subtree_check 192.168.*
/home/share 192.168.*(ro,subtree_check)
service nfsserver start
service atftpd start
setup smb to share /home/share as "share" with yast2
smbpasswd -a shihsung
service smb start
exit

5. Setup build environment
export ARCH=mips
export PATH=/opt/eldk/mips-2007-01-21/usr/bin:$PATH
export CROSS_COMPILE=mips_4KCle-

6. Build utelnetd
tar xvfz utelnetd-0.1.9.tar.gz
cd utelnetd-0.1.9
make CROSS=mips_4KCle- LDFLAGS=-static

7. Inject utelnetd into HD-HLAN_FW205 firmware
unzip HD-HLAN_FW205_042005.zip
cd HD-HLAN_FW205
unzip image.dat
NOTE: Search http://buffalo.nas-central.org for the password.
su
cd /tftpboot/HD-HLAN_FW205
tar xvfz /home/shihsung/HD-HLAN_FW205/tmpimage.tgz
cp /home/shihsung/utelnet-0.1.9/utelnetd sbin
Add "/sbin/utelnetd -l /bin/sh &" to the end of the start function in etc/init.d/networking
tar cvfz /home/shihsung/HD-HLAN_FW205/tmpimage.tgz .
exit
zip -e image.dat tmpimage.tgz
vi linkstation_version.txt
VERSION=2.06
cp firmimg.bin "HD-HLAN FWUpdate.exe" linkstation_version.txt image.dat /home/share

8. Upgrade HD-HLAN firmware from Live XP ISO running on a VMWare Server 2.0 VM
Build Live XP ISO image
NOTE: Refer to http://winbuilder.net for details.
Boot Live XP ISO image from a VMWare Server 2.0 VM
Map network drive \\192.168.1.100\share to x:
Run x:\"HD-HLAN FWUpdate.exe"
Click "Renew Firmware"

9. Build U-Boot and ncb
tar xvfj u-boot-2009.06.tar.bz2
cd u-boot-2009.06
patch -p1 -i ../u-boot-2009.06-hdhlan.patch
make distclean
make hdhlan_config
make
cp u-boot /tftpboot/u-boot-hdhlan.elf
cp u-boot.bin /tftpboot/u-boot-hdhlan.bin

10. Setup nc
cp tools/ncb ~/bin
vi ~/bin/nc
#!/bin/sh
[ $# = 1] || { echo "Usage: $0 target-ip" >&2; exit 1; }
stty -icanon -echo intr ^T
ncb &
netcat -u $1 6666
stty icanon echo intr ^C
kill 0
chmod +x ~/bin/nc

11. Flash U-Boot and verify
NOTE: DON'T CONTINUE IF YOU ARE NOT CONFIDENT YOU CAN REVIVE YOUR HD-HLAN WITH JTAG IN CASE SOMETHING GOES WRONG!!!
su
ifconfig eth2 192.168.11.100 netmask 255.255.255.0 broadcast 192.168.11.255
exit
telnet 192.168.11.150
cd /mnt/hda/share
dd if=/dev/mtd0 of=mtd0 bs=1k
exit
ftp 192.168.11.150
cd share
put /tftpboot/u-boot-hdhlan.bin
get mtd0
exit
telnet 192.168.11.150
cd /mnt/hda/share
eraseall /dev/mtd0
dd if=u-boot-hdhlan.bin of=/dev/mtd0 bs=1k
ls -l u-boot-hdhlan.bin
dd if=/dev/mtd0 of=verify bs=<u-boot-hdhlan.bin size> count=1
exit
ftp 192.168.11.150
get share/verify
exit
diff /tftpboot/u-boot-hdhlan.bin verify
cmp -b -l /tftpboot/u-boot-hdhlan.bin verify
NOTE: Repeat U-Boot flash if diff or cmp fails.

12. Test U-Boot just flashed
Press and hold HD-HLAN power button to shut it down
su
ifconfig eth2 192.168.1.100
exit
nc 192.168.1.200
Press HD-HLAN power button to power it up
You should see U-Boot prompt "HD-HLAN#" now.
NOTE: Prepare for JTAG revival if you don't see U-Boot prompt. Refer to "Unbrick with JTAG" for details.

13. Build Linux-2.6.30.4 kernel
tar xvfj linux-2.6.30.4.tar.bz2
cd linux-2.6.30.4
patch -p1 -i ../linux-2.6.30.4-0.2-hdhlan.patch
make mrproper
make hdhlan_defconfig
NOTE: My default configuration uses the new ATA driver instead of the old IDE dirver.
make vmlinux.bin
gzip -9vf arch/mips/boot/vmlinux.bin
mips_4KCle-readelf -l vmlinux
mkimage -A mips -O linux -T kernel -C gzip -a <virtAddr> -e <Entry point> -n "HD-HLAN Linux-2.6.30.4-0.2" -d arch/mips/boot/vmlinux.bin.gz vmlinux.uboot
cp vmlinux.uboot /tftpboot/vmlinux-2.6.30.4-0.2.uboot

14. Build Busyxob-1.14.2
tar xvfj busybox-1.14.2.tar.bz2
cd busybox-1.14.2
make defconfig
make menuconfig
SELECT "Busybox Setting->Build Options->static library"
DESELECT "Miscellaneous Utilities->ionice"
make CONFIG_PREFIX=/tftpboot/busybox install
su
chown root.root /tftpboot/busybox/bin/busybox
chmod u+s,g+s /tftpboot/busybox/bin/busybox
exit

15. Build e2fsprogs-1.41.6
tar xvfz e2fsprogs-1.41.6.tar.gz
cd e2fsprogs-1.41.6
mkdir mips_4KCle
cd mips_4KCle
../configure --host=mipsel-linux CC=mips_4KCle-gcc LDFLAGS=-static
make
mips_4KCle-strip misc/mke2fs misc/tune2fs
cp misc/mke2fs misc/tune2fs /tftpboot/busybox/sbin

16. Setup Busybox root FS
cd /tftpboot/busybox
mkdir -p dev etc lib proc sys tmp usr var mnt
mkdir -p usr/bin usr/sbin usr/lib
mkdir -p etc/init.d
chmod a+wt tmp
su
mknod -m 0600 dev/console c 5 1
exit
vi etc/profile
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
vi etc/inittab
::sysinit:/etc/init.d/rcS
ttyS0::respawn:-/bin/sh
vi etc/init.d/rcS
#!/bin/sh
/bin/busybox mount -t proc proc /proc
mount -n -o remount,rw /dev/root /
mount -t sysfs sysfs /sys
mount -t tmpfs tmpfs /dev
echo /sbin/mdev > /proc/sys/kernel/hotplug
mkdir /dev/pts
mount -t devpts devpts /dev/pts
mdev -s
mount -t tmpfs tmpfs /var
for d in lib lock log run tmp; do mkdir -p /var/$d; done
chmod a+wt /var/tmp
telnetd -l /bin/sh
chmod +x etc/init.d/rcS

17. Build Busybox initrd
NOTE: Optional, if you want to try booting with initrd.
su
dd if=/dev/zero of=initrd bs=1024 count=8192
mke2fs -Fm0 initrd
mount -o loop initrd /mnt
cp -a /tftpboot/busybox/* /mnt
umount /mnt
gzip -9vf initrd
mkimage -A mips -O linux -T ramdisk -C none -a 0x80800000 -e 0 -d initrd.gz -n "HD-HLAN Busybox-1.14.2" initrd.uboot
cp initrd.uboot /tftpboot/initrd-busybox-1.14.2.uboot
exit

18. Start debootstrap to install Lenny
cd /tftpboot/busybox
su
ar p /home/shihsung/debootstrap_1.0.13_all.deb data.tar.gz | tar xz
DEBOOTSTRAP_DIR=usr/share/debootstrap usr/sbin/debootstrap --foreign --arch mipsel lenny lenny
exit

19. Boot Linux-2.6.30.4 with Busybox-1.14.2 root FS over NFS
tftp 81000000 192.168.1.100:vmlinux-2.6.30.4-0.2.uboot
set bootargs root=/dev/nfs nfsroot=192.168.1.100:/tftpboot/busybox ip=192.168.1.200:192.168.1.100:192.168.1.10:255.255.255.0:lenny:eth0:none netconsole=6666@192.168.1.200/,@192.168.1.100/
NOTE: Linux kernel command line limit for MIPS architecture is 256 bytes. You need to redefine it if you need more than that.
To support MTD, add "mtdparts=physmap-flash.0:0x40000(u-boot),0x350000(kernel),0x10000(mac0),0x10000(mac1),0x10000(param),0x40000(config),0x400000@0(all)"
To enable KGDB, add "kgdboc=ttyS0,115200 kgdbwait" besides reconfigure the kernel with KGDB support.
boom

    NOTE: To boot with initrd:
tftp 81000000 192.168.1.100:vmlinux-2.6.30.4-0.2.uboot
tftp 807fffc0 192.168.1.100:initrd-busybox-1.14.2.uboot
set bootargs root=/dev/ram0 ip=192.168.1.200 netconsole=6666@192.168.1.200/,@192.168.1.100/
bootm 81000000 807fffc0

20. Complete Lenny installation
telnet 192.168.1.200
dd if=/dev/zero of=/dev/sda count=1
NOTE: THIS WILL WIPE OUT THE PARTITION TABLE!!!
fdisk /dev/sda
n    p    1    <ENTR>    +4096M
n    p    2    <ENTR>    +512M    t    2    82
n    p    3    <ENTR>    <ENTR>
w
touch /etc/mtab
mke2fs -j /dev/sda1
mke2fs -j /dev/sda3
tune2fs -c0 -i0 /dev/sda1
tune2fs -c0 -i0 /dev/sda3
mkswap /dev/sda2
swapon /dev/sda2
mount /dev/sda1 /mnt
mkdir /mnt/home
mount /dev/sda3 /mnt/home
cp -a /lenny/* /mnt
LANG=C chroot /mnt /bin/bash
debootstrap/debootstrap --second-stage

21. Configure and update Lenny
vi /etc/fstab
/dev/sda1    /    ext3    defaults    0    1
/dev/sda3    /home    ext3    rw,nosuid,nodev    0    2
/dev/sda2    none    swap    sw    0    0
proc    /proc    proc    defaults    0    0
sysfs    /sys    sysfs    defaults    0    0
devpts    /dev/pts    devpts    mode=0620,gid=5    0    0
mount /proc
mount /sys
mount /dev/pts
vi /etc/default/rcS
UTC=no
dpkg-reconfigure tzdata
vi /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.1.200
network 192.168.1.0
netmask 255.255.255.0
broadcast 192.168.1.255
gateway 192.168.1.10
vi /etc/resolv.conf
nameserver xxx.xxx.xxx.xxx
nameserver yyy.yyy.yyy.yyy
echo lenny > /etc/hostname
vi /etc/hosts
127.0.0.1    localhost lenny
vi /etc/apt/sources.list
deb http://mirrors.kernel.org/debian lenny main
deb-src http://mirrors.kernel.org/debian lenny main
deb http://security.debian.org/ lenny/updates main
deb-src http://security.debian.org/ lenny/updates main
deb http://mirrors.kernel.org/debian sid main
vi /etc/apt/preferences
Package: *
Pin: release a=stable
Pin-Priority: 990
mkdir /lib/modules/$(uname -r)
touch /lib/modules/$(uname -r)/modules.dep
apt-get update
apt-get dist-upgrade
aptitude install locales
dpkg-reconfigure locales
en_US.UTF-8
passwd
tasksel install standard
opt-get install ssh samba nfs-kernel-server udev avr-evtd ntp
aptitude clean
vi /etc/exports
/home    192.168.*(sync,rw,subtree_check)
vi /etc/samba/smb.conf
[homes]
read-only = no
addgroup shihsung
adduser --ingroup shihsung shihsung
smbpasswd -a shihsung
vi /etc/defaults/avr-evtd
DEBUG=OFF
vi /etc/init.d/avr-evtd
daemonoptions="-d /dev/ttyS0"
NOTE: Add the above line right before launching the daemon.
date MMDDhhmmYYYY
hwclock -w
vi /etc/inittab
#1:2345:respawn:/sbin/getty 38400 tty1
#2:23:respawn:/sbin/getty 38400 tty2
#3:23:respawn:/sbin/getty 38400 tty3
#4:23:respawn:/sbin/getty 38400 tty4
#5:23:respawn:/sbin/getty 38400 tty5
#6:23:respawn:/sbin/getty 38400 tty6
NOTE: Comment out the above lines to prevent respawning getty repeated on non-existent virtual terminals.
for f in samba nfs-kernel-server nfs-common ssh portmap atd exim4 cron ntp; do /etc/init.d/$f stop; done
umount /proc/fs/nfsd
umount /proc
umount /sys
umount /dev/pts
exit
sync
umount /mnt/home
umount /mnt
reboot

22. Verify Lenny installation and copy the kernel
tftp 81000000 192.168.1.100:vmlinux-2.6.30.4-0.2.uboot
set bootargs root=/dev/sda1 ip=192.168.1.200 netconsole=6666@192.168.1.200/,@192.168.1.100/
bootm
ssh 192.168.1.200
mount 192.168.1.100:/tftpboot /mnt
cp -a /mnt/vmlinux-2.6.30.4-0.2.uboot /mnt/initrd-busybox-1.14.2.uboot /boot
ln -sf vmlinux-2.6.30.4-0.2.uboot /boot/vmlinux.uboot
reboot

22.Setup auto-boot and silence nc
set bootargs root=/dev/sda1
set bootcmd ext2load ide 0 81000000 /boot/vmlinux.uboot\; bootm
set stdout nulldev; set stderr nulldev; save; reset

23. To interact with U-Boot again after enabling auto-boot and silencing nc
su
arp -s 192.168.1.200 ff:ff:ff:ff:ff:ff
NOTE: You can replace ff:ff:ff:ff:ff:ff with the MAC address of your LinkStation if you want.
nc 192.168.1.200
press and hold <ENTR> while powering up for 3 second
set stdout nc

LICENSE: All the additions and changes from the pristine source, except the one mentioned in the CREDIT section, are my own creation and licensed under the GPLv2.

CREDIT: My u-boot-2009.06-hdhlan.patch includes the EXT2 filesystem dynamic inode size support patch by Ryan Chen.

CHANGE LOG:
vmlinux-2.6.30.4-hdhlan.uboot built from linux-2.6.30.4-hdhlan.patch
issue: network lock up problem
vmlinux-2.6.30.4-0.2-hdhlan.uboot built from linux-2.6.30.4-0.2-hdhlan.patch
change: fixed network lock up problem
vmlinux-2.6.30.5-0.1-hdhlan.uboot built from linux-2.6.30.5-0.1-hdhlan.patch
change: improved Ethernet performance and built-in NLS codepage 437, character sets ISO 8859-1, and UTF-8 support
    Version 2 of u-boot-2009.06-hdhlan-ram.elf and u-boot-2009.06-hdhlan.bin built from u-boot-2009.06-hdhlan.patch
        change: fixed 25 seconds timeout/shutdown problem when "silent=1" not in the U-Boot environment setting