diff --git a/kernel/target/arm64/board/kirin970/boot-shim-config.h b/kernel/target/arm64/board/kirin970/boot-shim-config.h new file mode 100644 index 0000000000000000000000000000000000000000..9ff45b54d49b8fe48f10c6d29efab37110bf9301 --- /dev/null +++ b/kernel/target/arm64/board/kirin970/boot-shim-config.h @@ -0,0 +1,120 @@ +// Copyright 2018 The Fuchsia Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#define HAS_DEVICE_TREE 1 + +static const zbi_cpu_config_t cpu_config = { + .cluster_count = 2, + .clusters = { + { + .cpu_count = 4, + }, + { + .cpu_count = 4, + }, + }, +}; + +static const zbi_mem_range_t mem_config[] = { + { + //TODO: Cornel uses 4GB + .type = ZBI_MEM_RANGE_RAM, + .length = 0xc0000000, // 3GB + }, + { + .type = ZBI_MEM_RANGE_PERIPHERAL, + .paddr = 0xe8100000, + .length = 0x17f00000, + }, + { + // memory to reserve to avoid stomping on bootloader data + .type = ZBI_MEM_RANGE_RESERVED, + .paddr = 0x00000000, + .length = 0x00080000, + }, + { + // bl31 + .type = ZBI_MEM_RANGE_RESERVED, + .paddr = 0x1FE00000, + .length = 0x400000, + }, + { + // pstore + .type = ZBI_MEM_RANGE_RESERVED, + .paddr = 0x20a00000, + .length = 0x100000, + }, + { + // lpmx-core + .type = ZBI_MEM_RANGE_RESERVED, + .paddr = 0x8E100000, + .length = 0x100000, + }, + { + // lpmcu + .type = ZBI_MEM_RANGE_RESERVED, + .paddr = 0x8E200000, + .length = 0x40000, + }, +}; + +static const dcfg_simple_t uart_driver = { + .mmio_phys = 0xfff32000, + .irq = 111, +}; + +static const dcfg_arm_gicv2_driver_t gicv2_driver = { + .mmio_phys = 0xe82b0000, + .gicd_offset = 0x1000, + .gicc_offset = 0x2000, + .gich_offset = 0x4000, + .gicv_offset = 0x6000, + .ipi_base = 12, +}; + +static const dcfg_arm_psci_driver_t psci_driver = { + .use_hvc = false, +}; + +static const dcfg_arm_generic_timer_driver_t timer_driver = { + .irq_phys = 30, + .irq_virt = 27, +}; + +static const dcfg_hisilicon_power_driver_t power_driver = { + .sctrl_phys = 0xfff0a000, + .pmu_phys = 0xfff34000, +}; + +static const zbi_platform_id_t platform_id = { + .vid = PDEV_VID_HISILICON, + .pid = PDEV_PID_CORNEL, + .board_name = "COR_AL00_VD" +}; + +static void append_board_boot_item(zbi_header_t* bootdata) { + // add CPU configuration + append_boot_item(bootdata, ZBI_TYPE_CPU_CONFIG, 0, &cpu_config, + sizeof(zbi_cpu_config_t) + + sizeof(zbi_cpu_cluster_t) * cpu_config.cluster_count); + + // add memory configuration + append_boot_item(bootdata, ZBI_TYPE_MEM_CONFIG, 0, &mem_config, + sizeof(zbi_mem_range_t) * countof(mem_config)); + + // add kernel drivers + append_boot_item(bootdata, ZBI_TYPE_KERNEL_DRIVER, KDRV_PL011_UART, &uart_driver, + sizeof(uart_driver)); + append_boot_item(bootdata, ZBI_TYPE_KERNEL_DRIVER, KDRV_ARM_GIC_V2, &gicv2_driver, + sizeof(gicv2_driver)); + append_boot_item(bootdata, ZBI_TYPE_KERNEL_DRIVER, KDRV_ARM_PSCI, &psci_driver, + sizeof(psci_driver)); + append_boot_item(bootdata, ZBI_TYPE_KERNEL_DRIVER, KDRV_ARM_GENERIC_TIMER, &timer_driver, + sizeof(timer_driver)); + append_boot_item(bootdata, ZBI_TYPE_KERNEL_DRIVER, KDRV_HISILICON_POWER, &power_driver, + sizeof(power_driver)); + + // add platform ID + append_boot_item(bootdata, ZBI_TYPE_PLATFORM_ID, 0, &platform_id, sizeof(platform_id)); +} diff --git a/kernel/target/arm64/board/kirin970/rules.mk b/kernel/target/arm64/board/kirin970/rules.mk new file mode 100644 index 0000000000000000000000000000000000000000..e000831f6c500a07a72b718686aa4d62d493508c --- /dev/null +++ b/kernel/target/arm64/board/kirin970/rules.mk @@ -0,0 +1,13 @@ +# Copyright 2018 The Fuchsia Authors +# +# Use of this source code is governed by a MIT-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/MIT + +LOCAL_DIR := $(GET_LOCAL_DIR) + +PLATFORM_BOARD_NAME := kirin970 +PLATFORM_USE_SHIM := true +PLATFORM_USE_GZIP := true + +include make/board.mk diff --git a/kernel/target/arm64/boot-shim/kirin970-uart.c b/kernel/target/arm64/boot-shim/kirin970-uart.c new file mode 100644 index 0000000000000000000000000000000000000000..072d7f4c60a7ad7d86f0a5305d0ea0ca3ed12ae3 --- /dev/null +++ b/kernel/target/arm64/boot-shim/kirin970-uart.c @@ -0,0 +1,17 @@ +// Copyright 2018 The Fuchsia Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include <stdint.h> +#include "debug.h" + +static volatile uint32_t* uart_fifo_dr = (uint32_t *)0xfff32000; +static volatile uint32_t* uart_fifo_fr = (uint32_t *)0xfff32018; + +void uart_pputc(char c) +{ + /* spin while fifo is full */ + while (*uart_fifo_fr & (1<<5)) + ; + *uart_fifo_dr = c; +} diff --git a/scripts/flash-kirin970 b/scripts/flash-kirin970 new file mode 100755 index 0000000000000000000000000000000000000000..3d49d3b9ca0a23d2c18e0068e7dac929e3e64059 --- /dev/null +++ b/scripts/flash-kirin970 @@ -0,0 +1,93 @@ +#!/usr/bin/env bash + +# Copyright 2017 The Fuchsia Authors +# +# Use of this source code is governed by a MIT-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/MIT + +MEMBASE=0x00000000 +KERNEL_OFFSET=0x00080000 +RAMDISK_OFFSET=0x07c00000 +DT_OFFSET=0x07a00000 + +CMDLINE= + +SCRIPTS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +ZIRCON_DIR="${SCRIPTS_DIR}/.." + +MKBOOTIMG="${ZIRCON_DIR}/third_party/tools/android/mkbootimg" +MKDTIMG="${ZIRCON_DIR}/third_party/tools/android/mkdtimg" + +help() { + echo "usage: ${0} [options]" + echo " -b [build-dir] Use specified build directory." + echo " Defaults to build-kirin970/." + echo " -d [ramdisk] Use specified ramdisk file." + echo " Defaults to BUILD_DIR/bootdata.bin." + echo " -f Download and flash firmware." + echo " -m Add mexec option to kernel command line to enable netboot." + echo " -h Show this help message." + exit 1 +} + +help_fastboot() { + echo + echo "Check that the device is in fastboot mode:" + echo " Auto Power up(Switch 1) closed/ON" + echo " Recovery(Switch 2) open/OFF" + echo " Fastboot(Switch 3) closed/ON" + + read -p "Proceed (y|n)? " -n 1 -r + echo + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + exit 1 + fi +} + +git_clone() { + git clone --depth 1 $@ +} + +flash_kernel() { + "${MKBOOTIMG}" \ + --kernel $KERNEL \ + --kernel_offset $KERNEL_OFFSET \ + --base $MEMBASE \ + --ramdisk_offset $RAMDISK_OFFSET \ + --ramdisk "${RAMDISK}" \ + --tags_offset $DT_OFFSET \ + --cmdline "${CMDLINE}" \ + -o $OUT_IMAGE + + fastboot flash boot $OUT_IMAGE + # Can't guarantee that the target has written image to flash before the + # fastboot command completes, so short delay here before reboot. + sleep 1 + fastboot reboot +} + +while getopts "b:d:fmnp:ruh" FLAG; do + case $FLAG in + b) BUILD_DIR="${OPTARG}";; + d) RAMDISK="${OPTARG}";; + f) FLAG_FIRMWARE=true;; + m) CMDLINE+=" netsvc.netboot=true";; + *) help;; + esac +done +shift $((OPTIND-1)) + +BUILD_DIR="${BUILD_DIR:-build-arm64}" +RAMDISK="${RAMDISK:-${BUILD_DIR}/kirin970-bootdata.bin}" +OUT_IMAGE="${BUILD_DIR}/boot.img" + +BOARD=kirin970 +BOOTDATA_BIN="${BUILD_DIR}/${BOARD}-zircon-bootimage.bin" +ZBOOTDATA_BIN="${BUILD_DIR}/z${BOARD}-zircon-bootimage.bin" +gzip -c ${BOOTDATA_BIN} > ${ZBOOTDATA_BIN} +KERNEL=${ZBOOTDATA_BIN} +RAMDISK="${BUILD_DIR}/dummy-ramdisk.bin" +dd if=/dev/zero of=${RAMDISK} bs=4096 count=1 + +flash_kernel diff --git a/system/ulib/ddk/include/ddk/platform-defs.h b/system/ulib/ddk/include/ddk/platform-defs.h index 2480f95a58c5d360f8b67a558c597cfa9394ca88..16475969a9c165e7be85b9912b1394a0d820db28 100644 --- a/system/ulib/ddk/include/ddk/platform-defs.h +++ b/system/ulib/ddk/include/ddk/platform-defs.h @@ -149,4 +149,8 @@ __BEGIN_CDECLS; #define PDEV_VID_SONY 14 #define PDEV_PID_SONY_IMX227 1 +// Hisilicon +#define PDEV_VID_HISILICON 15 +#define PDEV_PID_CORNEL 1 + __END_CDECLS;