diff --git a/rpi3.mk b/rpi3.mk index fa9f41f04251b38a39d34321752c5b66f1278560..328878de5ff6ac39697816e0dc9d1e4f08a64981 100644 --- a/rpi3.mk +++ b/rpi3.mk @@ -41,7 +41,7 @@ U-BOOT_BIN ?= $(U-BOOT_PATH)/u-boot.bin U-BOOT_JTAG_BIN ?= $(U-BOOT_PATH)/u-boot-jtag.bin RPI3_FIRMWARE_PATH ?= $(BUILD_PATH)/rpi3/firmware -RPI3_HEAD_BIN ?= $(RPI3_FIRMWARE_PATH)/head.bin +RPI3_HEAD_BIN ?= $(ROOT)/out/head.bin RPI3_BOOT_CONFIG ?= $(RPI3_FIRMWARE_PATH)/config.txt RPI3_UBOOT_ENV ?= $(RPI3_FIRMWARE_PATH)/uboot.env RPI3_STOCK_FW_PATH ?= $(ROOT)/rpi3_firmware @@ -58,7 +58,7 @@ MODULE_OUTPUT ?= $(ROOT)/module_output all: rpi3-firmware arm-tf optee-os optee-client xtest u-boot \ linux update_rootfs all-clean: arm-tf-clean busybox-clean u-boot-clean optee-os-clean \ - optee-client-clean rpi3-firmware-clean + optee-client-clean rpi3-firmware-clean head-bin-clean -include toolchain.mk @@ -97,7 +97,7 @@ arm-tf-clean: U-BOOT_EXPORTS ?= CROSS_COMPILE=$(LEGACY_AARCH64_CROSS_COMPILE) ARCH=arm64 .PHONY: u-boot -u-boot: +u-boot: $(RPI3_HEAD_BIN) $(U-BOOT_EXPORTS) $(MAKE) -C $(U-BOOT_PATH) rpi_3_defconfig $(U-BOOT_EXPORTS) $(MAKE) -C $(U-BOOT_PATH) all cd $(U-BOOT_PATH) && cat $(RPI3_HEAD_BIN) $(U-BOOT_BIN) > $(U-BOOT_JTAG_BIN) @@ -105,6 +105,14 @@ u-boot: u-boot-clean: $(U-BOOT_EXPORTS) $(MAKE) -C $(U-BOOT_PATH) clean +$(RPI3_HEAD_BIN): $(RPI3_FIRMWARE_PATH)/head.S + mkdir -p $(ROOT)/out/ + $(AARCH64_CROSS_COMPILE)as $< -o $(ROOT)/out/head.o + $(AARCH64_CROSS_COMPILE)objcopy -O binary $(ROOT)/out/head.o $@ + +head-bin-clean: + rm -f $(RPI3_HEAD_BIN) $(ROOT)/out/head.o + ################################################################################ # Busybox ################################################################################ diff --git a/rpi3/firmware/head.S b/rpi3/firmware/head.S new file mode 100644 index 0000000000000000000000000000000000000000..ec155f9e13df75f45367377af1956ba5d88d3023 --- /dev/null +++ b/rpi3/firmware/head.S @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2016, Linaro Limited + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +/* + * Reverse-engineered from head.bin previously committed in the Git repository. + * Build with: + * aarch64-linux-gnu-as head.S -o head.o + * aarch64-linux-gnu-objcopy -O binary head.o head.bin + */ + mov x0, #0x40000000 + str wzr, [x0] + mov w1, #0x80000000 + str w1, [x0, #8] + + ldr x0, _19_2_MHz + msr cntfrq_el0, x0 + + msr cntvoff_el2, xzr + + mov x0, #0x33ff + msr cptr_el3, x0 + + mov x0, #0x5b0 + msr scr_el3, x0 + + mov x0, #0x40 + msr s3_1_c15_c2_1, x0 + + mrs x6, mpidr_el1 + and x6, x6, #0x3 + cbz x6, core0 + + adr x5, spin_table +spin: + wfe + ldr x4, [x5, x6, lsl #3] + cbz x4, spin + mov x0, #0x0 + b 1f +core0: + ldr x4, core0_init + ldr x0, core0_init_parm +1: + mov x1, #0x0 + mov x2, #0x0 + mov x3, #0x0 + br x4 + +_19_2_MHz: + .word 0x0124f800 + .rept 23 + .word 0x0 + .endr + .balign 8, 0 +core0_init: + .word 0x8000 + .balign 8, 0 +spin_table: + .rept 8 + .word 0x0 + .endr +core0_init_parm: + .word 0x100 + .p2align 15, 0 + diff --git a/rpi3/firmware/head.bin b/rpi3/firmware/head.bin deleted file mode 100644 index e8321c79d0f9859de2ef94aa96d636790e4b05d8..0000000000000000000000000000000000000000 Binary files a/rpi3/firmware/head.bin and /dev/null differ