diff options
author | Maximilian Brune <maximilian.brune@9elements.com> | 2024-01-14 22:31:15 +0600 |
---|---|---|
committer | ron minnich <rminnich@gmail.com> | 2024-03-02 16:36:33 +0000 |
commit | e26bcaefbeb1d64cf2a78ad54e0f6ad4affab086 (patch) | |
tree | 37c44616d0d4b87d3099ea7c504d30f2f141ea2a /src/mainboard/sifive/hifive-unmatched/fixup_fdt.c | |
parent | 62407ac1979e372fdbe8a71d3dfee3f797332bbb (diff) |
mb/sifive: Add Hifive Unmatched mainboard
working:
Linux v6.3.5
poweroff via Linux PMIC driver
UART console output
SPI -> SDCARD
I2C -> PMIC
16 GB LPDDR4 memory
VSC8541XMV-02 (gigabit ethernet PHY)
PCIe x16 Slot
M.2 NVMe Slot
MSEL: only '1100' has been tested
untested:
M.2 WiFi/Bluetooth Slot
tested bootflow:
ZSBL -> coreboot --FDT-> Linuxboot -> uroot --kexec-> ubuntu
defconfig used:
CONFIG_VENDOR_SIFIVE=y
CONFIG_BOARD_SIFIVE_HIFIVE_UNMATCHED=y
CONFIG_PAYLOAD_NONE=n
CONFIG_PAYLOAD_ELF=y
CONFIG_PAYLOAD_FILE="[path-to-linux]/arch/riscv/boot/Image"
CONFIG_PAYLOAD_IS_FLAT_BINARY=y
CONFIG_PAYLOAD_OPTIONS="-l 0x82000000 -e 0x82000000"
CONFIG_COMPRESSED_PAYLOAD_LZMA=y
uroot kexec command:
kexec -d --cmdline "console=ttySIF0 root=/dev/mmcblk0p1 debug" \
--initrd /mnt/boot/initrd.img-6.5.0-9-generic \
/mnt/boot/vmlinuz-6.5.0-9-generic
Signed-off-by: Maximilian Brune <maximilian.brune@9elements.com>
Change-Id: Ife0afdce89d5a1a1b936c30c8027f1bc191b8c53
Reviewed-on: https://review.coreboot.org/c/coreboot/+/79954
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: ron minnich <rminnich@gmail.com>
Diffstat (limited to 'src/mainboard/sifive/hifive-unmatched/fixup_fdt.c')
-rw-r--r-- | src/mainboard/sifive/hifive-unmatched/fixup_fdt.c | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/src/mainboard/sifive/hifive-unmatched/fixup_fdt.c b/src/mainboard/sifive/hifive-unmatched/fixup_fdt.c new file mode 100644 index 0000000000..ed24ee36d7 --- /dev/null +++ b/src/mainboard/sifive/hifive-unmatched/fixup_fdt.c @@ -0,0 +1,106 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <console/console.h> +#include <soc/otp.h> +#include <soc/sdram.h> +#include <cbfs.h> +#include <device_tree.h> +#include <bootstate.h> +#include <mcall.h> + +static void do_fixup_mac(struct device_tree_node *node) +{ + uint32_t serial = otp_read_serial(); + static unsigned char mac[6] = { 0x70, 0xb3, 0xd5, 0x92, 0xf0, 0x00 }; + if (serial != ~0) { + mac[5] |= (serial >> 0) & 0xff; + mac[4] |= (serial >> 8) & 0xff; + mac[3] |= (serial >> 16) & 0xff; + } + dt_add_bin_prop(node, "local-mac-address", mac, 6); +} + +static void fixup_mac(struct device_tree_node *parent) +{ + struct device_tree_property *prop; + const char *name = "local-mac-address"; + + list_for_each(prop, parent->properties, list_node) { + if (!strcmp(name, prop->prop.name)) + do_fixup_mac(parent); + } + + struct device_tree_node *child; + list_for_each(child, parent->children, list_node) { + fixup_mac(child); + } +} + +static void do_fixup_memory(struct device_tree_node *node) +{ + u64 addrs[1], sizes[1]; + addrs[0] = 0x80000000; + sizes[0] = sdram_size(); + dt_add_reg_prop(node, addrs, sizes, 1, 2, 2); +} + +static void fixup_memory(struct device_tree_node *parent) +{ + struct device_tree_property *prop; + const char *name = "device_type"; + const char *value = "memory"; + + list_for_each(prop, parent->properties, list_node) { + if (!strcmp(name, prop->prop.name)) { + if (!strcmp(value, (char *)prop->prop.data)) + do_fixup_memory(parent); + } + } + + struct device_tree_node *child; + list_for_each(child, parent->children, list_node) { + fixup_memory(child); + } +} + +static void fixup_fdt(void *unused) +{ + printk(BIOS_DEBUG, "fix up FDT\n"); + + void *fdt_rom; + struct device_tree *tree; + + /* load flat dt from cbfs */ + fdt_rom = cbfs_map("fallback/DTB", NULL); + + if (fdt_rom == NULL) { + printk(BIOS_ERR, "Unable to load fallback/DTB from CBFS\n"); + return; + } + + /* Expand DT into a tree */ + tree = fdt_unflatten(fdt_rom); + + /* fixup tree */ + fixup_mac(tree->root); + fixup_memory(tree->root); + + /* convert the tree to a flat dt */ + void *dt = malloc(dt_flat_size(tree)); + + if (dt == NULL) { + printk(BIOS_ERR, "Unable to allocate memory for flat device tree\n"); + return; + } + + dt_flatten(tree, dt); + + /* update HLS */ + for (int i = 0; i < CONFIG_MAX_CPUS; i++) + OTHER_HLS(i)->fdt = dt; +} + +BOOT_STATE_INIT_ENTRY(BS_WRITE_TABLES, BS_ON_EXIT, fixup_fdt, NULL); |