Skip to content

Commit

Permalink
[POWERPC] PS3: Bootwrapper support.
Browse files Browse the repository at this point in the history
Add support to build the PS3 flash rom image and remove some unneeded
lmb calls.

The PS3's lv1 loader supports loading gzipped binary images from flash
rom to addr zero. The loader enters the image at addr 0x100.

In this implementation a bootwrapper overlay is use to arrange for the
kernel to be loaded to addr zero and to have a suitable bootwrapper
entry at 0x100.  To construct the rom image, 0x100 bytes from offset
0x100 in the kernel is copied to the bootwrapper symbol
__system_reset_kernel.  The 0x100 bytes at the bootwrapper symbol
__system_reset_overlay is then copied to offset 0x100.  At runtime the
bootwrapper program copies the 0x100 bytes at __system_reset_kernel to
addr 0x100.

zImage.ps3 is a wrapped image that contains a flat device tree, an lv1
compatible entry point, and an optional initrd.  otheros.bld is the gzip
compresed rom image built from zImage.ps3.  otheros.bld is suitable for
programming into the PS3 boot flash memory.

Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
  • Loading branch information
Geoff Levand authored and Paul Mackerras committed Jul 10, 2007
1 parent 76a5b8b commit bafdb64
Show file tree
Hide file tree
Showing 7 changed files with 542 additions and 11 deletions.
21 changes: 12 additions & 9 deletions arch/powerpc/boot/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ src-wlib := string.S crt0.S stdio.c main.c flatdevtree.c flatdevtree_misc.c \
gunzip_util.c elf_util.c $(zlib) devtree.c oflib.c ofconsole.c \
44x.c ebony.c mv64x60.c mpsc.c mv64x60_i2c.c cuboot.c
src-plat := of.c cuboot-83xx.c cuboot-85xx.c holly.c \
cuboot-ebony.c treeboot-ebony.c prpmc2800.c
cuboot-ebony.c treeboot-ebony.c prpmc2800.c \
ps3-head.S ps3-hvcall.S ps3.c
src-boot := $(src-wlib) $(src-plat) empty.c

src-boot := $(addprefix $(obj)/, $(src-boot))
Expand Down Expand Up @@ -75,11 +76,11 @@ $(addprefix $(obj)/,$(zliblinuxheader)): $(obj)/%: $(srctree)/include/linux/%
$(obj)/empty.c:
@touch $@

$(obj)/zImage.lds $(obj)/zImage.coff.lds: $(obj)/%: $(srctree)/$(src)/%.S
$(obj)/zImage.lds $(obj)/zImage.coff.lds $(obj)/zImage.ps3.lds: $(obj)/%: $(srctree)/$(src)/%.S
@cp $< $@

clean-files := $(zlib) $(zlibheader) $(zliblinuxheader) \
empty.c zImage.coff.lds zImage.lds
empty.c zImage zImage.coff.lds zImage.ps3.lds zImage.lds

quiet_cmd_bootcc = BOOTCC $@
cmd_bootcc = $(CROSS32CC) -Wp,-MD,$(depfile) $(BOOTCFLAGS) -c -o $@ $<
Expand All @@ -102,7 +103,7 @@ hostprogs-y := addnote addRamDisk hack-coff mktree

targets += $(patsubst $(obj)/%,%,$(obj-boot) wrapper.a)
extra-y := $(obj)/wrapper.a $(obj-plat) $(obj)/empty.o \
$(obj)/zImage.lds $(obj)/zImage.coff.lds
$(obj)/zImage.lds $(obj)/zImage.coff.lds $(obj)/zImage.ps3.lds

wrapper :=$(srctree)/$(src)/wrapper
wrapperbits := $(extra-y) $(addprefix $(obj)/,addnote hack-coff mktree) \
Expand Down Expand Up @@ -179,11 +180,12 @@ $(obj)/zImage.%: vmlinux $(wrapperbits) $(dts)
$(obj)/zImage.iseries: vmlinux
$(STRIP) -s -R .comment $< -o $@

$(obj)/zImage.ps3: vmlinux
$(STRIP) -s -R .comment $< -o $@
$(obj)/zImage.ps3: vmlinux $(wrapper) $(wrapperbits) $(srctree)/$(src)/dts/ps3.dts
$(STRIP) -s -R .comment $< -o vmlinux.strip
$(call cmd,wrap,ps3,$(srctree)/$(src)/dts/ps3.dts,,)

$(obj)/zImage.initrd.ps3: vmlinux
@echo " WARNING zImage.initrd.ps3 not supported (yet)"
$(obj)/zImage.initrd.ps3: vmlinux $(wrapper) $(wrapperbits) $(srctree)/$(src)/dts/ps3.dts $(obj)/ramdisk.image.gz
$(call cmd,wrap,ps3,$(srctree)/$(src)/dts/ps3.dts,,$(obj)/ramdisk.image.gz)

$(obj)/uImage: vmlinux $(wrapperbits)
$(call if_changed,wrap,uboot)
Expand All @@ -206,7 +208,8 @@ install: $(CONFIGURE) $(addprefix $(obj)/, $(image-y))
sh -x $(srctree)/$(src)/install.sh "$(KERNELRELEASE)" vmlinux System.map "$(INSTALL_PATH)" $<

# anything not in $(targets)
clean-files += $(image-) $(initrd-) zImage zImage.initrd cuImage.* treeImage.*
clean-files += $(image-) $(initrd-) zImage zImage.initrd cuImage.* treeImage.* \
otheros.bld

# clean up files cached by wrapper
clean-kernel := vmlinux.strip vmlinux.bin
Expand Down
80 changes: 80 additions & 0 deletions arch/powerpc/boot/ps3-head.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* PS3 bootwrapper entry.
*
* Copyright (C) 2007 Sony Computer Entertainment Inc.
* Copyright 2007 Sony Corp.
*
* 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; version 2 of the License.
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include "ppc_asm.h"

.text

/*
* __system_reset_overlay - The PS3 first stage entry.
*
* The bootwraper build script copies the 0x100 bytes at symbol
* __system_reset_overlay to offset 0x100 of the rom image.
*
* The PS3 has a single processor with two threads.
*/

.globl __system_reset_overlay
__system_reset_overlay:

/* Switch to 32-bit mode. */

mfmsr r9
clrldi r9,r9,1
mtmsrd r9
nop

/* Get thread number in r3 and branch. */

mfspr r3, 0x88
cntlzw. r3, r3
li r4, 0
li r5, 0
beq 1f

/* Secondary goes to __secondary_hold in kernel. */

li r4, 0x60
mtctr r4
bctr

/* Primary delays then goes to _zimage_start in wrapper. */
1:
or 31, 31, 31 /* db16cyc */
or 31, 31, 31 /* db16cyc */

lis r4, _zimage_start@ha
addi r4, r4, _zimage_start@l
mtctr r4
bctr

/*
* __system_reset_kernel - Place holder for the kernel reset vector.
*
* The bootwrapper build script copies 0x100 bytes from offset 0x100
* of the rom image to the symbol __system_reset_kernel. At runtime
* the bootwrapper program copies the 0x100 bytes at __system_reset_kernel
* to ram address 0x100. This symbol must occupy 0x100 bytes.
*/

.globl __system_reset_kernel
__system_reset_kernel:

. = __system_reset_kernel + 0x100
184 changes: 184 additions & 0 deletions arch/powerpc/boot/ps3-hvcall.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
/*
* PS3 bootwrapper hvcalls.
*
* Copyright (C) 2007 Sony Computer Entertainment Inc.
* Copyright 2007 Sony Corp.
*
* 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; version 2 of the License.
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include "ppc_asm.h"

/*
* The PS3 hypervisor uses a 64 bit "C" language calling convention.
* The routines here marshal arguments between the 32 bit wrapper
* program and the 64 bit hvcalls.
*
* wrapper lv1
* 32-bit (h,l) 64-bit
*
* 1: r3,r4 <-> r3
* 2: r5,r6 <-> r4
* 3: r7,r8 <-> r5
* 4: r9,r10 <-> r6
* 5: 8(r1),12(r1) <-> r7
* 6: 16(r1),20(r1) <-> r8
* 7: 24(r1),28(r1) <-> r9
* 8: 32(r1),36(r1) <-> r10
*
*/

.macro GLOBAL name
.section ".text"
.balign 4
.globl \name
\name:
.endm

.macro NO_SUPPORT name
GLOBAL \name
b ps3_no_support
.endm

.macro HVCALL num
li r11, \num
.long 0x44000022
extsw r3, r3
.endm

.macro SAVE_LR offset=4
mflr r0
stw r0, \offset(r1)
.endm

.macro LOAD_LR offset=4
lwz r0, \offset(r1)
mtlr r0
.endm

.macro LOAD_64_REG target,high,low
sldi r11, \high, 32
or \target, r11, \low
.endm

.macro LOAD_64_STACK target,offset
ld \target, \offset(r1)
.endm

.macro LOAD_R3
LOAD_64_REG r3,r3,r4
.endm

.macro LOAD_R4
LOAD_64_REG r4,r5,r6
.endm

.macro LOAD_R5
LOAD_64_REG r5,r7,r8
.endm

.macro LOAD_R6
LOAD_64_REG r6,r9,r10
.endm

.macro LOAD_R7
LOAD_64_STACK r7,8
.endm

.macro LOAD_R8
LOAD_64_STACK r8,16
.endm

.macro LOAD_R9
LOAD_64_STACK r9,24
.endm

.macro LOAD_R10
LOAD_64_STACK r10,32
.endm

.macro LOAD_REGS_0
stwu 1,-16(1)
stw 3, 8(1)
.endm

.macro LOAD_REGS_5
LOAD_R3
LOAD_R4
LOAD_R5
LOAD_R6
LOAD_R7
.endm

.macro LOAD_REGS_6
LOAD_REGS_5
LOAD_R8
.endm

.macro LOAD_REGS_8
LOAD_REGS_6
LOAD_R9
LOAD_R10
.endm

.macro STORE_REGS_0_1
lwz r11, 8(r1)
std r4, 0(r11)
mr r4, r3
li r3, 0
addi r1,r1,16
.endm

.macro STORE_REGS_5_2
lwz r11, 16(r1)
std r4, 0(r11)
lwz r11, 24(r1)
std r5, 0(r11)
.endm

.macro STORE_REGS_6_1
lwz r11, 24(r1)
std r4, 0(r11)
.endm

GLOBAL lv1_get_logical_ppe_id
SAVE_LR
LOAD_REGS_0
HVCALL 69
STORE_REGS_0_1
LOAD_LR
blr

GLOBAL lv1_get_logical_partition_id
SAVE_LR
LOAD_REGS_0
HVCALL 74
STORE_REGS_0_1
LOAD_LR
blr

GLOBAL lv1_get_repository_node_value
SAVE_LR
LOAD_REGS_5
HVCALL 91
STORE_REGS_5_2
LOAD_LR
blr

GLOBAL lv1_panic
SAVE_LR
LOAD_REGS_8
HVCALL 255
LOAD_LR
blr
Loading

0 comments on commit bafdb64

Please sign in to comment.