Patrick Williams | 44b3caf | 2024-04-12 16:51:14 -0500 | [diff] [blame^] | 1 | From ae098fd5c47f6d805b356c892558a85d571bed67 Mon Sep 17 00:00:00 2001 |
Patrick Williams | ac13d5f | 2023-11-24 18:59:46 -0600 | [diff] [blame] | 2 | From: Rui Miguel Silva <rui.silva@linaro.org> |
| 3 | Date: Tue, 18 Jul 2023 12:14:47 +0100 |
Patrick Williams | 44b3caf | 2024-04-12 16:51:14 -0500 | [diff] [blame^] | 4 | Subject: [PATCH] corstone1000: set kernel_addr based on boot_idx |
Patrick Williams | ac13d5f | 2023-11-24 18:59:46 -0600 | [diff] [blame] | 5 | |
| 6 | We need to distinguish between boot banks and from which |
| 7 | partition to load the kernel+initramfs to memory. |
| 8 | |
| 9 | For that, fetch the boot index, fetch the correspondent |
| 10 | partition, calculate the correct kernel address and |
| 11 | then set the env variable kernel_addr with that value. |
| 12 | |
| 13 | Upstream-Status: Pending |
| 14 | Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org> |
| 15 | --- |
| 16 | board/armltd/corstone1000/corstone1000.c | 58 +++++++++++++++++++++- |
| 17 | board/armltd/corstone1000/corstone1000.env | 8 --- |
| 18 | configs/corstone1000_defconfig | 1 + |
| 19 | 3 files changed, 58 insertions(+), 9 deletions(-) |
| 20 | |
| 21 | diff --git a/board/armltd/corstone1000/corstone1000.c b/board/armltd/corstone1000/corstone1000.c |
| 22 | index ba6d024b80..a045262ebb 100644 |
| 23 | --- a/board/armltd/corstone1000/corstone1000.c |
| 24 | +++ b/board/armltd/corstone1000/corstone1000.c |
| 25 | @@ -5,15 +5,25 @@ |
| 26 | * Rui Miguel Silva <rui.silva@linaro.org> |
| 27 | */ |
| 28 | |
| 29 | +#include <blk.h> |
| 30 | #include <common.h> |
| 31 | #include <cpu_func.h> |
| 32 | #include <dm.h> |
| 33 | +#include <env.h> |
| 34 | #include <fwu.h> |
| 35 | #include <netdev.h> |
| 36 | +#include <nvmxip.h> |
| 37 | +#include <part.h> |
| 38 | #include <dm/platform_data/serial_pl01x.h> |
| 39 | #include <asm/armv8/mmu.h> |
| 40 | #include <asm/global_data.h> |
| 41 | |
| 42 | +#define CORSTONE1000_KERNEL_PARTS 2 |
| 43 | +#define CORSTONE1000_KERNEL_PRIMARY "kernel_primary" |
| 44 | +#define CORSTONE1000_KERNEL_SECONDARY "kernel_secondary" |
| 45 | + |
| 46 | +static int corstone1000_boot_idx; |
| 47 | + |
| 48 | static struct mm_region corstone1000_mem_map[] = { |
| 49 | { |
| 50 | /* CVM */ |
| 51 | @@ -110,5 +120,51 @@ int dram_init_banksize(void) |
| 52 | |
| 53 | void fwu_plat_get_bootidx(uint *boot_idx) |
| 54 | { |
| 55 | - *boot_idx = 0; |
| 56 | + *boot_idx = corstone1000_boot_idx; |
| 57 | +} |
| 58 | + |
| 59 | +int board_late_init(void) |
| 60 | +{ |
| 61 | + struct disk_partition part_info; |
| 62 | + struct udevice *dev, *bdev; |
| 63 | + struct nvmxip_plat *plat; |
| 64 | + struct blk_desc *desc; |
| 65 | + int ret; |
| 66 | + |
| 67 | + ret = uclass_first_device_err(UCLASS_NVMXIP, &dev); |
| 68 | + if (ret < 0) { |
| 69 | + log_err("Cannot find kernel device\n"); |
| 70 | + return ret; |
| 71 | + } |
| 72 | + |
| 73 | + plat = dev_get_plat(dev); |
| 74 | + device_find_first_child(dev, &bdev); |
| 75 | + desc = dev_get_uclass_plat(bdev); |
| 76 | + ret = fwu_get_active_index(&corstone1000_boot_idx); |
| 77 | + if (ret < 0) |
| 78 | + log_err("corstone1000: failed to read boot index\n"); |
| 79 | + |
| 80 | + if (!corstone1000_boot_idx) |
| 81 | + ret = part_get_info_by_name(desc, CORSTONE1000_KERNEL_PRIMARY, |
| 82 | + &part_info); |
| 83 | + else |
| 84 | + ret = part_get_info_by_name(desc, CORSTONE1000_KERNEL_SECONDARY, |
| 85 | + &part_info); |
| 86 | + |
| 87 | + if (ret < 0) { |
| 88 | + log_err("failed to fetch kernel partition index: %d\n", |
| 89 | + corstone1000_boot_idx); |
| 90 | + return ret; |
| 91 | + } |
| 92 | + |
| 93 | + ret = 0; |
| 94 | + |
| 95 | + ret |= env_set_hex("kernel_addr", plat->phys_base + |
| 96 | + (part_info.start * part_info.blksz)); |
| 97 | + ret |= env_set_hex("kernel_size", part_info.size * part_info.blksz); |
| 98 | + |
| 99 | + if (ret < 0) |
| 100 | + log_err("failed to setup kernel addr and size\n"); |
| 101 | + |
| 102 | + return ret; |
| 103 | } |
| 104 | diff --git a/board/armltd/corstone1000/corstone1000.env b/board/armltd/corstone1000/corstone1000.env |
| 105 | index a6ee496221..ee318b1b1c 100644 |
| 106 | --- a/board/armltd/corstone1000/corstone1000.env |
| 107 | +++ b/board/armltd/corstone1000/corstone1000.env |
| 108 | @@ -2,12 +2,4 @@ |
| 109 | |
| 110 | usb_pgood_delay=250 |
| 111 | boot_bank_flag=0x08005006 |
| 112 | -kernel_addr_bank_0=0x08280000 |
| 113 | -kernel_addr_bank_1=0x0936E000 |
| 114 | -retrieve_kernel_load_addr= |
| 115 | - if itest.l *${boot_bank_flag} == 0; then |
| 116 | - setenv kernel_addr $kernel_addr_bank_0; |
| 117 | - else |
| 118 | - setenv kernel_addr $kernel_addr_bank_1; |
| 119 | - fi; |
| 120 | kernel_addr_r=0x88200000 |
| 121 | diff --git a/configs/corstone1000_defconfig b/configs/corstone1000_defconfig |
| 122 | index 4c75a01818..0232131a11 100644 |
| 123 | --- a/configs/corstone1000_defconfig |
| 124 | +++ b/configs/corstone1000_defconfig |
| 125 | @@ -20,6 +20,7 @@ CONFIG_CONSOLE_RECORD=y |
| 126 | CONFIG_LOGLEVEL=7 |
| 127 | # CONFIG_DISPLAY_CPUINFO is not set |
| 128 | # CONFIG_DISPLAY_BOARDINFO is not set |
| 129 | +CONFIG_BOARD_LATE_INIT=y |
| 130 | CONFIG_SYS_MAXARGS=64 |
| 131 | CONFIG_SYS_CBSIZE=512 |
| 132 | # CONFIG_CMD_CONSOLE is not set |