
svn co svn://svn.openwrt.org/openwrt/trunk openwrt-dev
cd openwrt-dev
./scripts/feeds update
./scripts/feeds install -a

# Last stable Linux 2.6.39.4 revisions
# trunk: 31744
# packages: 31800

# Last stable Linux 3.10 revisions
# trunk: 40774
# packages: 40750

# Last stable Linux 3.12 revisions
# trunk: 40842
# packages: 40817

# Last stable Linux 3.14 revisions
# trunk: 40774
# packages: 40750

cd openwrt-dev
svn up -r <trunk revision>
cd feeds/packages
svn up -r <packages revision>

PATCHES_DIR=$HOME/git/ps3openwrt/patches.git
CONFIGS_DIR=$HOME/git/ps3openwrt/configs.git
KMAP_DIR=$HOME/git/ps3openwrt/kmap.git
KERNEL_PATCHES_DIR=$HOME/git/ps3linux
SCRIPTS_DIR=$HOME/git/ps3otheros/scripts.git

# Restore PS3 target
# This patch is necessary since trunk revision 34765

patch -p0 < $PATCHES_DIR/add-ps3-target.patch
chmod 755 target/linux/ps3/petitboot/base-files/sbin/initrun
chmod 755 target/linux/ps3/petitboot/base-files/sbin/ps3-bl-option
chmod 755 target/linux/ps3/petitboot/base-files/bin/login

# Fix broken target

patch -p0 < $PATCHES_DIR/target-broken-fix.patch

# Create non-zipped target image

patch -p0 < $PATCHES_DIR/create-non-zipped-target-image.patch

# dropbear patches

patch -p0 < $PATCHES_DIR/dropbear-no-empty-host-keys.patch
mkdir target/linux/ps3/petitboot/base-files/etc/dropbear
cp $PATCHES_DIR/dropbear_dss_host_key target/linux/ps3/petitboot/base-files/etc/dropbear
cp $PATCHES_DIR/dropbear_rsa_host_key target/linux/ps3/petitboot/base-files/etc/dropbear

# package patches

patch -p0 < $PATCHES_DIR/parted-package.patch
patch -p0 < $PATCHES_DIR/sg3-utils.patch
patch -p0 < $PATCHES_DIR/kbd-package.patch
patch -p0 < $PATCHES_DIR/kmod-hid-special.patch
patch -p0 < $PATCHES_DIR/fix-ps3_gelic-path.patch
patch -p0 < $PATCHES_DIR/fix-ps3_gelic-load.patch
patch -p0 < $PATCHES_DIR/kernel-module-packages.patch
patch -p0 < $PATCHES_DIR/ps3vuart-tools-package.patch
patch -p0 < $PATCHES_DIR/ps3sed-package.patch
patch -p0 < $PATCHES_DIR/ps3lv1call-tools-package.patch
patch -p0 < $PATCHES_DIR/ps3lv1write-package.patch

# petitboot patches

patch -p0 < $PATCHES_DIR/petitboot-install-artwork.patch

cp $PATCHES_DIR/030-petitboot-udevadm-action-fix.diff package/feeds/packages/petitboot/patches
cp $PATCHES_DIR/040-petitboot-mount-ufs2.diff package/feeds/packages/petitboot/patches
cp $PATCHES_DIR/050-petitboot-udev-change-event.diff package/feeds/packages/petitboot/patches
cp $PATCHES_DIR/060-petitboot-kexec-shutdown-fix.diff package/feeds/packages/petitboot/patches

mkdir -p target/linux/ps3/petitboot/base-files/etc/init.d/
cp $PATCHES_DIR/umount target/linux/ps3/petitboot/base-files/etc/init.d/
cp $PATCHES_DIR/kexec target/linux/ps3/petitboot/base-files/etc/init.d/
cp $PATCHES_DIR/udev target/linux/ps3/petitboot/base-files/etc/init.d/

# udev patches

mkdir -p target/linux/ps3/petitboot/base-files/etc/udev/rules.d
cp $PATCHES_DIR/70-persistent-ps3flash.rules target/linux/ps3/petitboot/base-files/etc/udev/rules.d

# sysctl patches

patch -p0 < $PATCHES_DIR/increase-unix-socket-qlen.patch
patch -p0 < $PATCHES_DIR/disable-tcp-ecn.patch
cp $PATCHES_DIR/sysctl target/linux/ps3/petitboot/base-files/etc/init.d

# kexec-tools patches

cp $PATCHES_DIR/0100-kexec-tools-disable-endless-verify-loop.patch package/boot/kexec-tools/patches/
cp $PATCHES_DIR/0150-kexec-tools-purgatory-print-sha256-regions.patch package/boot/kexec-tools/patches/
cp $PATCHES_DIR/0200-kexec-tools-add-ps3-console.patch package/boot/kexec-tools/patches/
cp $PATCHES_DIR/0300-kexec-tools-print-sha256-digest.patch package/boot/kexec-tools/patches/

# console keymaps
# select your kmap in console file
# default kmap is us.kmap

cp $PATCHES_DIR/console target/linux/ps3/petitboot/base-files/etc/init.d
mkdir -p target/linux/ps3/petitboot/base-files/usr/share/keymaps
cp $KMAP_DIR/*.kmap target/linux/ps3/petitboot/base-files/usr/share/keymaps/

# BD drive authentication

cp $PATCHES_DIR/bd_drive_auth target/linux/ps3/petitboot/base-files/etc/init.d

# Enable SCSI polling in kernel

cp $PATCHES_DIR/rc.local target/linux/ps3/petitboot/base-files/etc/

# WLAN patches
# set your ssid and psk in target/linux/ps3/petitboot/base-files/etc/config/wireless

mkdir -p target/linux/ps3/petitboot/base-files/lib/wifi
cp $PATCHES_DIR/wext.sh target/linux/ps3/petitboot/base-files/lib/wifi/
patch -p0 < $PATCHES_DIR/wlan-config.patch

# Set root password to 'root' which disables telnet login and enables SSH login

cp $PATCHES_DIR/shadow target/linux/ps3/petitboot/base-files/etc

# Install OtherOS++ script(s)

cp $SCRIPTS_DIR/create_hdd_region.sh target/linux/ps3/petitboot/base-files/sbin/
cp $SCRIPTS_DIR/dispmngr_access.sh target/linux/ps3/petitboot/base-files/sbin/
cp $SCRIPTS_DIR/gpu_4kb_iopage.sh target/linux/ps3/petitboot/base-files/sbin/
cp $SCRIPTS_DIR/dump_lv1_console.sh target/linux/ps3/petitboot/base-files/sbin/

# Linux kernel patches
# Remove any overlayfs patches.

cp -r $KERNEL_PATCHES_DIR/kernel-patches-26-39.git target/linux/ps3/patches-2.6.39
cp -r $KERNEL_PATCHES_DIR/kernel-patches-310.git target/linux/ps3/patches-3.10
cp -r $KERNEL_PATCHES_DIR/kernel-patches-312.git target/linux/ps3/patches-3.12
cp -r $KERNEL_PATCHES_DIR/kernel-patches-314.git target/linux/ps3/patches-3.14

# Linux kernel configs

cp $CONFIGS_DIR/kernel-config-2.6.39 target/linux/ps3/config-2.6.39
cp $CONFIGS_DIR/kernel-config-3.10 target/linux/ps3/config-3.10
cp $CONFIGS_DIR/kernel-config-3.12 target/linux/ps3/config-3.12
cp $CONFIGS_DIR/kernel-config-3.14 target/linux/ps3/config-3.14

# Linux kernel version
# choose only one

patch -p0 < $PATCHES_DIR/kernel-version-2.6.39.4.patch
patch -p0 < $PATCHES_DIR/kernel-version-3.10.patch
patch -p0 < $PATCHES_DIR/kernel-version-3.12.patch
patch -p0 < $PATCHES_DIR/kernel-version-3.14.patch

# Build

cp $CONFIGS_DIR/config-huge .config
make V=99 menuconfig
make V=99 kernel_menuconfig
make -j4 V=99

# Images

ls -l bin/ps3/openwrt-ps3-petitboot-vmlinux-initramfs.elf
ls -l bin/ps3/otheros.bin


ps3sed and problem with missing ps3strgmngr.h
----------------------------------------------

cp build_dir/target-powerpc_uClibc-0.9.33.2/linux-ps3_petitboot/linux-3.12.20/arch/powerpc/include/asm/ps3strgmngr.h \
	staging_dir/toolchain-powerpc_gcc-4.8-linaro_uClibc-0.9.33.2/include/asm/

Debugging
----------

Kernel hacking -> Early debugging -> PS3 gelic udbg (LV1 console udbg, Flash udbg)

Disable PS3 gelic device driver if you are going to use gelic udbg.
Disable PS3 flash device driver if you are going to use flash udbg.

kexec -l /root/openwrt-ps3-petitboot-vmlinux-initramfs.elf  --command-line="udbg-immortal initcall_debug keep_bootcon"

socat - udp4-listen:18194,reuseaddr

strings /dev/ps3flashg
dd if=/dev/zero of=/dev/ps3flashg
