nx: build bootstack for l4t-loader

We are migrating from coreboot to an ATF loader
built into hekate-ipl. This will load sc7 bins etc. along
with ATF (bl31) and U-Boot (bl33), which will chainload
kernel (as is currently the case). This also migrates to new
R2P method/driver as the new loader/ATF will stash a
copy of the bootloader in RAM so we do not have to
load a hekate payload.

Change-Id: I11e4a1810829ab3ac4c8830fd03afd6054e40bad
This commit is contained in:
tmakin authored and Nolen Johnson committed 2024-01-25 15:54:02 -05:00
1 parent ef6a02e5f6
commit 8bb5bf7347
9 files changed
+121 -233

No files matched your search

+10 -2
View File
@@ -45,12 +45,20 @@ endif
# Charger
WITH_LINEAGE_CHARGER := false
# Kernel
# Kernel Toolchain (>= GCC 6.x needed for U-Boot)
KERNEL_TOOLCHAIN := $(shell pwd)/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-gnu-6.4.1/bin
KERNEL_TOOLCHAIN_PREFIX := aarch64-linux-gnu-
# Kernel Source
TARGET_KERNEL_SOURCE := kernel/nvidia/kernel-$(TARGET_TEGRA_KERNEL)
TARGET_KERNEL_CONFIG := tegra_android_defconfig
BOARD_KERNEL_IMAGE_NAME := Image.gz
TARGET_KERNEL_ADDITIONAL_FLAGS := "NV_BUILD_KERNEL_OPTIONS=$(TARGET_TEGRA_KERNEL)"
# Kernel Image Parameters
BOARD_KERNEL_IMAGE_NAME := Image.gz
BOARD_KERNEL_LOAD_BASE := 0x88000000
BOARD_MKBOOTIMG_ARGS := --base $(BOARD_KERNEL_LOAD_BASE)
# Recovery
TARGET_RECOVERY_DENSITY := hdpi
TARGET_RECOVERY_FSTAB := device/nintendo/nx/initfiles/fstab.nx
+1 -1
View File
@@ -1 +1 @@
require version-bootloader=2020.04-03753-g53ff5d2195-rev6
require version-bootloader=2022.10-g4f111ee6dc
+6 -2
View File
@@ -1,5 +1,9 @@
[LineageOS]
payload=switchroot/android/coreboot.rom
[LineageOS 18.1]
l4t=1
boot_prefixes=switchroot/android/
id=SWANDR
icon=switchroot/android/icon_android_hue.bmp
logopath=switchroot/android/bootlogo_android.bmp
r2p_action=self
; USB3 is disabled by default as in stock due to Wi-Fi/BT interference
; usb3_enable=1
-13
View File
@@ -26,19 +26,6 @@ LOCAL_MODULE_PATH := $(PRODUCT_OUT)
include $(BUILD_PREBUILT)
INSTALLED_RADIOIMAGE_TARGET += $(PRODUCT_OUT)/00-android.ini
include $(CLEAR_VARS)
LOCAL_MODULE := boot.scr
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_PATH := $(PRODUCT_OUT)
_uscript_input := $(abspath device/nintendo/nx/bootfiles/android_boot.txt)
_uscript_intermediates := $(call intermediates-dir-for,$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE))
_uscript_archive := $(_uscript_intermediates)/$(LOCAL_MODULE)$(LOCAL_MODULE_SUFFIX)
$(_uscript_archive):
@mkdir -p $(dir $@)
$(LINEAGE_TOOLS_PATH)/mkimage -A arm -T script -O linux -d $(_uscript_input) $(_uscript_intermediates)/boot.scr
include $(BUILD_SYSTEM)/base_rules.mk
INSTALLED_RADIOIMAGE_TARGET += $(PRODUCT_OUT)/boot.scr
include $(CLEAR_VARS)
LOCAL_MODULE := bootlogo_android
LOCAL_MODULE_SUFFIX := .bmp
-211
View File
@@ -1,211 +0,0 @@
scrrev=6
# SD is always bootfile mmc
setenv sdmmc_idx 1
# Load uenv.txt
if fatload mmc ${sdmmc_idx}:1 0x8f000000 switchroot/android/uenv.txt; then
env import -t 0x8f000000 ${filesize};
echo Successfully imported uenv.txt...
fi
setenv mmc_idx 1
# Check if eMMC boot is enabled
if test -n ${emmc}; then
setenv mmc_idx 0
echo eMMC boot enabled!
else
echo SD boot enabled!
fi
mmc dev $mmc_idx
# fastboot setup for our GPT layout
setenv fastboot_partition_alias_boot LNX
setenv fastboot_partition_alias_system APP
setenv fastboot_partition_alias_userdata UDA
setenv fastboot_partition_alias_cache CAC
setenv fastboot_partition_alias_recovery SOS
setenv fastboot_partition_alias_dtb DTB
# load fastboot first so 'fastboot continue' works
gpio input 191 || fastboot 0
# store main MMC serial number to use as device serial
mmc info serial#
# generate a uboot version we can assert against in recovery
setexpr ver_simple gsub "U-Boot (.*) \\(.*\\)" "\\1-rev$scrrev" "$ver"
# find root partition and convert to decimal
part number mmc $mmc_idx APP app_part_num
setexpr app_part_num_dec gsub "^0x1$" 1 $app_part_num
setexpr app_part_num_dec gsub "^0x2$" 2 $app_part_num
setexpr app_part_num_dec gsub "^0x3$" 3 $app_part_num
setexpr app_part_num_dec gsub "^0x4$" 4 $app_part_num
setexpr app_part_num_dec gsub "^0x5$" 5 $app_part_num
setexpr app_part_num_dec gsub "^0x6$" 6 $app_part_num
setexpr app_part_num_dec gsub "^0x7$" 7 $app_part_num
setexpr app_part_num_dec gsub "^0x8$" 8 $app_part_num
setexpr app_part_num_dec gsub "^0x9$" 9 $app_part_num
setexpr app_part_num_dec gsub "^0xa$" 10 $app_part_num
setexpr app_part_num_dec gsub "^0xb$" 11 $app_part_num
setexpr app_part_num_dec gsub "^0xc$" 12 $app_part_num
setexpr app_part_num_dec gsub "^0xd$" 13 $app_part_num
setexpr app_part_num_dec gsub "^0xe$" 14 $app_part_num
setexpr app_part_num_dec gsub "^0xf$" 15 $app_part_num
setexpr app_part_num_dec gsub "^0x10$" 16 $app_part_num
host_mac_addr=0xff
# load mac address info file
if fatload mmc ${sdmmc_idx}:1 0x90000000 switchroot/joycon_mac.bin; then
if itest.b *0x90000000 == 0x01; then
echo Left JoyCon is available
host_mac_addr=0x90000007
else
echo \\e Left JoyCon pairing info is not available!
fi
if itest.b *0x9000001d == 0x02; then
echo Right JoyCon is available
host_mac_addr=0x90000024
else
echo \\e Right JoyCon pairing info is not available!
fi
fi
if itest $host_mac_addr == 0xff; then
echo No JoyCons available
# write to a known good location
mw.q 0x90000000 ${serial#} 1
# write crc32 of value at offset 0x3
crc32 0x90000000 8 0x90000003
# write nintendo prefix
mw.b 0x90000000 0x98 1
mw.b 0x90000001 0xE8 1
mw.b 0x90000002 0xFA 1
# use this to generate mac
host_mac_addr=0x90000000
fi
bt_mac=""
sep=""
for i in 0 1 2 3 4 5 ; do
setexpr x $host_mac_addr + $i
setexpr.b b *$x
if itest $b <= f; then
# There is no way to have leading zeros, so do this hack
bt_mac="$bt_mac${sep}0$b"
else
bt_mac="$bt_mac$sep$b"
fi
sep=":"
done
# FIXME after hekate gets wifi mac reading
setexpr.b last_byte *0x90000005
if itest $last_byte == 0xFF; then
# wrap around case
setexpr wifi_mac gsub "(.*:.*:.*:.*:.*:).*" "\\100" $bt_mac
else
setexpr.b wb $last_byte + 1
if itest $wb <= f; then
setexpr wifi_mac gsub "(.*:.*:.*:.*:.*:).*" "\\10$wb" $bt_mac
else
setexpr wifi_mac gsub "(.*:.*:.*:.*:.*:).*" "\\1$wb" $bt_mac
fi
fi
# Set extra bootargs to kill console and set default loglevel
setenv bootargs_extra "console=null loglevel=5"
# load dtb
part start mmc $mmc_idx DTB dtb_part_start
part size mmc $mmc_idx DTB dtb_part_size
mmc read $fdt_addr_r $dtb_part_start $dtb_part_size
fdt addr $fdt_addr_r
# Load overlays based on uenv.txt
if test -n ${overlays}; then
for ov in ${overlays}; do
echo overlaying ${ov}...
fdt resize 8192
if fatload mmc ${sdmmc_idx}:1 0x8f000000 switchroot/overlays/${ov}.dtbo && fdt apply 0x8f000000; then
echo Successfully loaded ${ov}.dtbo...
if test "${ov}" = "tegra210-UART-B-overlay"; then
# Override bootargs_extra for extra logging with UART overlay
setenv bootargs_extra "no_console_suspend androidboot.console=ttyS1 console=ttyS1,115200,8n1 loglevel=8"
fi
else
# Error on failure to apply
echo \\e failed to overlay ${ov}!; sleep 5; reset
fi
done
fi
# Patch DT on eMMC boot
if test -n ${emmc}; then
fdt set /sdhci@700b0600 status okay
setenv bootargs_extra "${bootargs_extra} androidboot.boot_devices=sdhci-tegra.3"
else
setenv bootargs_extra "${bootargs_extra} androidboot.boot_devices=sdhci-tegra.0"
fi
# insert mac address dtb node
fdt set /chosen nvidia,wifi-mac ${wifi_mac}
fdt set /chosen nvidia,bluetooth-mac ${bt_mac}
# Prepare display panel id from Nyx.
cp.b 0xED838002 0xED838001 0x1
mw.b 0xED838002 0x0 0x1
# Get display panel handle.
if itest.w *0xED838000 == 0xf20; then echo Display is INNO; fdt get value DHANDLE /host1x@50000000/dsi/panel-i-720p-6-2 phandle
elif itest.w *0xED838000 == 0xf30; then echo Display is AUO; fdt get value DHANDLE /host1x@50000000/dsi/panel-a-720p-6-2 phandle
elif itest.b *0xED838000 == 0x10; then echo Display is JDI; fdt get value DHANDLE /host1x@50000000/dsi/panel-j-720p-6-2 phandle
else Display is Unknown; fi
# Set new active display panel handle.
if test -n ${DHANDLE}; then echo Setting Display panel; fdt resize 8192; fdt set /host1x@50000000/dsi nvidia,active-panel <$DHANDLE>; fi
# Set common bootargs
setenv bootargs_path "init=/init nvdec_enabled=0 usbcore.autosuspend=-1 log_buf_len=4M androidboot.bootloader=${ver_simple} androidboot.hardware=nx androidboot.hardware.sku=icosa androidboot.selinux=permissive androidboot.serialno=${serial#} androidboot.modem=none pcie_aspm=off vpr_resize pmc_reboot2payload.default_payload=reboot_payload.bin pmc_reboot2payload.reboot_action=via-payload pmc_reboot2payload.hekate_config_id=SWANDR pmc_reboot2payload.enabled=1 tegra_fbmem=0x800000@0xf5a00000"
# gpio 190 = VOL_UP, 191 = VOL_DOWN
if gpio input 190 && test ${recovery} = "0"; then
# normal boot
part start mmc ${mmc_idx} LNX root_part_start
part size mmc ${mmc_idx} LNX root_part_size
setenv bootargs "${bootargs_extra} ${bootargs_path} skip_initramfs ro rootwait root=/dev/mmcblk0p${app_part_num_dec} firmware_class.path=/vendor/firmware bluetooth.disable_ertm=1 "
mmc read 0x98000000 $root_part_start $root_part_size
bootm 0x98000000 0x98000000 0x8d000000
else
# recovery
part start mmc ${mmc_idx} SOS root_part_start
part size mmc ${mmc_idx} SOS root_part_size
setenv bootargs "${bootargs_extra} ${bootargs_path} firmware_class.path=/etc/firmware "
mmc read 0x98000000 $root_part_start $root_part_size
bootm 0x98000000 0x98000000 0x8d000000
fi
echo \\e Failed to launch kernel!
echo \\e
echo \\e Rebooting in 10s...
sleep 10
reset
Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 MiB

After

Width:  |  Height:  |  Size: 3.5 MiB

+18 -4
View File
@@ -24,7 +24,7 @@ DTB_PART = '/dev/block/by-name/DTB'
VENDOR_PART = '/dev/block/by-name/vendor'
NX_FILES = '/mnt/vendor/hos_data'
NX_BL_VERSION = '2020.04-03753-g53ff5d2195-rev6'
NX_BL_VERSION = '2022.10-g4f111ee6dc'
def FullOTA_PostValidate(info):
if 'INSTALL/bin/resize2fs_static' in info.input_zip.namelist():
@@ -32,7 +32,7 @@ def FullOTA_PostValidate(info):
info.script.AppendExtra('run_program("/tmp/install/bin/resize2fs_static", "' + VENDOR_PART + '");');
def FullOTA_Assertions(info):
if 'RADIO/coreboot.rom' in info.input_zip.namelist():
if 'RADIO/bl33.bin' in info.input_zip.namelist():
CopyBlobs(info.input_zip, info.output_zip)
AddBootloaderFlash(info, info.input_zip)
else:
@@ -68,8 +68,22 @@ def AddBootloaderFlash(info, input_zip):
info.script.AppendExtra(' ui_print("Flashing updated bootloader for " + getprop(ro.hardware));')
info.script.AppendExtra(' run_program("/system/bin/mkdir", "-p", "' + NX_FILES + '");')
info.script.AppendExtra(' run_program("/system/bin/mount", "/dev/block/by-name/hos_data", "' + NX_FILES + '");')
info.script.AppendExtra(' package_extract_file("firmware-update/coreboot.rom", "' + NX_FILES + '/switchroot/android/coreboot.rom");')
info.script.AppendExtra(' package_extract_file("firmware-update/boot.scr", "' + NX_FILES + '/switchroot/android/boot.scr");')
""" clean old bootloader """
info.script.AppendExtra(' ifelse(')
info.script.AppendExtra(' read_file("' + NX_FILES + '/switchroot/android/bl31.bin"),')
info.script.AppendExtra(' (')
info.script.AppendExtra(' ui_print("Your bootloader is already compatible with L4T-Loader");')
info.script.AppendExtra(' ),')
info.script.AppendExtra(' (')
info.script.AppendExtra(' ui_print("Removing coreboot, as it is unused by L4T-Loader");')
info.script.AppendExtra(' run_program("/system/bin/rm", "-f", "' + NX_FILES + '/switchroot/android/coreboot.rom");')
info.script.AppendExtra(' )')
info.script.AppendExtra(' );')
""" flash uploaded bl files """
info.script.AppendExtra(' package_extract_file("firmware-update/bl31.bin", "' + NX_FILES + '/switchroot/android/bl31.bin");')
info.script.AppendExtra(' package_extract_file("firmware-update/bl33.bin", "' + NX_FILES + '/switchroot/android/bl33.bin");')
info.script.AppendExtra(' package_extract_file("firmware-update/bootlogo_android.bmp", "' + NX_FILES + '/switchroot/android/bootlogo_android.bmp");')
info.script.AppendExtra(' package_extract_file("firmware-update/icon_android_hue.bmp", "' + NX_FILES + '/switchroot/android/icon_android_hue.bmp");')
info.script.AppendExtra(' package_extract_file("firmware-update/00-android.ini", "' + NX_FILES + '/bootloader/ini/00-android.ini");')
+78
View File
@@ -0,0 +1,78 @@
# Copyright (C) 2023 The LineageOS Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
LOCAL_PATH := $(call my-dir)
NX_VENDOR_PATH := ../../../../../vendor/nintendo
ATF_PATH := $(BUILD_TOP)/external/switch-atf
UBOOT_PATH := $(BUILD_TOP)/external/switch-uboot
BUILD_TOOLS_BINS := $(BUILD_TOP)/prebuilts/build-tools/$(HOST_PREBUILT_TAG)/bin
LINEAGE_TOOLS_PATH := $(BUILD_TOP)/prebuilts/tools-lineage/$(HOST_PREBUILT_TAG)/bin
TARGET_KERNEL_CLANG_PATH ?= $(BUILD_TOP)/prebuilts/clang/host/$(HOST_PREBUILT_TAG)/$(LLVM_PREBUILTS_VERSION)
# Platform defaults
BL31_MAKEARGS := PLAT=tegra TARGET_SOC=t210 TZDRAM_BASE=0xFFF00000 RESET_TO_BL31=1 COLD_BOOT_SINGLE_CPU=1 \
PROGRAMMABLE_RESET_ADDRESS=1 ENABLE_STACK_PROTECTOR=none
# Not supported in Linux 4.9
BL31_MAKEARGS += SDEI_SUPPORT=0
# Error reporting
BL31_MAKEARGS += CRASH_REPORTING=1 ENABLE_ASSERTIONS=1 LOG_LEVEL=0 PLAT_LOG_LEVEL_ASSERT=0
# ATF
include $(CLEAR_VARS)
LOCAL_MODULE := bl31
LOCAL_MODULE_SUFFIX := .bin
LOCAL_MODULE_CLASS := EXECUTABLES
LOCAL_MODULE_PATH := $(PRODUCT_OUT)
_atf_intermediates := $(call intermediates-dir-for,$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE))
_atf_bin := $(_atf_intermediates)/$(LOCAL_MODULE)$(LOCAL_MODULE_SUFFIX)
$(_atf_bin):
@mkdir -p $(dir $@)
$(hide) +$(KERNEL_MAKE_CMD) $(KERNEL_CROSS_COMPILE) \
CLANG_CCDIR=$(TARGET_KERNEL_CLANG_PATH)/bin/ CC=$(TARGET_KERNEL_CLANG_PATH)/bin/clang -C $(ATF_PATH) \
BUILD_BASE=$(abspath $(_atf_intermediates)) $(BL31_MAKEARGS) bl31
@cp $(dir $@)/tegra/t210/release/bl31.bin $@
include $(BUILD_SYSTEM)/base_rules.mk
INSTALLED_RADIOIMAGE_TARGET += $(PRODUCT_OUT)/bl31.bin
# U-Boot
include $(CLEAR_VARS)
LOCAL_MODULE := bl33
LOCAL_MODULE_SUFFIX := .bin
LOCAL_MODULE_CLASS := EXECUTABLES
LOCAL_MODULE_PATH := $(PRODUCT_OUT)
_uboot_intermediates := $(call intermediates-dir-for,$(LOCAL_MODULE_CLASS),$(LOCAL_MODULE))
_uboot_bin := $(_uboot_intermediates)/$(LOCAL_MODULE)$(LOCAL_MODULE_SUFFIX)
$(_uboot_bin):
@mkdir -p $(dir $@)
$(hide) +$(KERNEL_MAKE_CMD) $(KERNEL_CROSS_COMPILE) \
HOSTCC=$(TARGET_KERNEL_CLANG_PATH)/bin/clang HOSTLDFLAGS="-fuse-ld=lld" \
YACC=$(BUILD_TOOLS_BINS)/bison LEX=$(BUILD_TOOLS_BINS)/flex M4=$(BUILD_TOOLS_BINS)/m4 \
-C $(UBOOT_PATH) O=$(abspath $(_uboot_intermediates)) $(TARGET_TEGRA_UBOOT)_defconfig
$(hide) +$(KERNEL_MAKE_CMD) $(KERNEL_CROSS_COMPILE) \
HOSTCC=$(TARGET_KERNEL_CLANG_PATH)/bin/clang HOSTLDFLAGS="-fuse-ld=lld" \
YACC=$(BUILD_TOOLS_BINS)/bison LEX=$(BUILD_TOOLS_BINS)/flex M4=$(BUILD_TOOLS_BINS)/m4 \
-C $(UBOOT_PATH) O=$(abspath $(_uboot_intermediates)) u-boot-dtb.bin
@mv $(_uboot_intermediates)/u-boot-dtb.bin $(_uboot_bin)
include $(BUILD_SYSTEM)/base_rules.mk
INSTALLED_RADIOIMAGE_TARGET += $(PRODUCT_OUT)/bl33.bin
+8
View File
@@ -17,3 +17,11 @@ include device/nvidia/tegra-common/vendor/common-by-flags.mk
include device/nintendo/nx/vendor/bcm_firmware/bcm.mk
PRODUCT_PACKAGES += public.libraries
# Switch firmware files
PRODUCT_PACKAGES += \
00-android \
bootlogo_android \
icon_android_hue \
bl31 \
bl33