Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
CI: https://source.denx.de/u-boot/custodians/u-boot-riscv/-/pipelines/20690

- RISC-V: Add NULL check after parsing compatible string
- Board: Add Milk-V Mars CM board
- Andes: Unify naming policy
  • Loading branch information
trini committed May 14, 2024
2 parents d456f2f + 2b8dc36 commit 676903c
Show file tree
Hide file tree
Showing 27 changed files with 337 additions and 56 deletions.
4 changes: 2 additions & 2 deletions arch/riscv/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ config SPL_ZERO_MEM_BEFORE_USE
Sifive core devices that uses L2 cache to store SPL.

# board-specific options below
source "board/AndesTech/ae350/Kconfig"
source "board/andestech/ae350/Kconfig"
source "board/emulation/qemu-riscv/Kconfig"
source "board/microchip/mpfs_icicle/Kconfig"
source "board/openpiton/riscv64/Kconfig"
Expand All @@ -93,7 +93,7 @@ source "board/thead/th1520_lpi4a/Kconfig"
source "board/xilinx/mbv/Kconfig"

# platform-specific options below
source "arch/riscv/cpu/andesv5/Kconfig"
source "arch/riscv/cpu/andes/Kconfig"
source "arch/riscv/cpu/cv1800b/Kconfig"
source "arch/riscv/cpu/fu540/Kconfig"
source "arch/riscv/cpu/fu740/Kconfig"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
config RISCV_NDS
config RISCV_ANDES
bool
select ARCH_EARLY_INIT_R
select SYS_CACHE_SHIFT_6
Expand All @@ -8,7 +8,7 @@ config RISCV_NDS
imply ANDES_PLMT_TIMER
imply SPL_ANDES_PLMT_TIMER
imply ANDES_PLICSW if (RISCV_MMODE || SPL_RISCV_MMODE)
imply V5L2_CACHE
imply ANDES_L2_CACHE
imply SPL_CPU
imply SPL_OPENSBI
imply SPL_LOAD_FIT
Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions arch/riscv/cpu/andesv5/cache.c → arch/riscv/cpu/andes/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
#include <dm/uclass-internal.h>
#include <asm/arch-andes/csr.h>

#ifdef CONFIG_V5L2_CACHE
#ifdef CONFIG_ANDES_L2_CACHE
void enable_caches(void)
{
struct udevice *dev;
int ret;

ret = uclass_get_device_by_driver(UCLASS_CACHE,
DM_DRIVER_GET(v5l2_cache),
DM_DRIVER_GET(andes_l2_cache),
&dev);
if (ret) {
log_debug("Cannot enable v5l2 cache\n");
log_debug("Cannot enable Andes L2 cache\n");
} else {
ret = cache_enable(dev);
if (ret)
log_debug("v5l2 cache enable failed\n");
log_debug("Failed to enable Andes L2 cache\n");
}
}

Expand Down Expand Up @@ -78,7 +78,7 @@ void dcache_enable(void)
asm volatile("csrsi %0, 0x2" :: "i"(CSR_MCACHE_CTL));
#endif

#ifdef CONFIG_V5L2_CACHE
#ifdef CONFIG_ANDES_L2_CACHE
cache_ops(cache_enable);
#endif
}
Expand All @@ -89,7 +89,7 @@ void dcache_disable(void)
asm volatile("csrci %0, 0x2" :: "i"(CSR_MCACHE_CTL));
#endif

#ifdef CONFIG_V5L2_CACHE
#ifdef CONFIG_ANDES_L2_CACHE
cache_ops(cache_disable);
#endif
}
Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions arch/riscv/include/asm/arch-jh7110/eeprom.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
u8 get_pcb_revision_from_eeprom(void);
u32 get_ddr_size_from_eeprom(void);

/**
* get_mmc_size_from_eeprom() - read eMMC size from EEPROM
*
* @return: size in GiB or 0 on error.
*/
u32 get_mmc_size_from_eeprom(void);

/**
* get_product_id_from_eeprom - get product ID string
*
Expand Down
16 changes: 5 additions & 11 deletions arch/riscv/lib/interrupts.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,20 @@ static void show_regs(struct pt_regs *regs)
#endif
}

#if defined(CONFIG_FRAMEPOINTER) || defined(CONFIG_SPL_FRAMEPOINTER)
static void show_backtrace(struct pt_regs *regs)
static void __maybe_unused show_backtrace(struct pt_regs *regs)
{
uintptr_t *fp = (uintptr_t *)regs->s0;
unsigned count = 0;
ulong ra;

printf("backtrace:\n");
printf("\nbacktrace:\n");

/* there are a few entry points where the s0 register is
* set to gd, so to avoid changing those, just abort if
* the value is the same */
while (fp != NULL && fp != (uintptr_t *)gd) {
ra = fp[-1];
printf("backtrace %2d: FP: " REG_FMT " RA: " REG_FMT,
printf("%3d: FP: " REG_FMT " RA: " REG_FMT,
count, (ulong)fp, ra);

if (gd && gd->flags & GD_FLG_RELOC)
Expand All @@ -87,12 +86,6 @@ static void show_backtrace(struct pt_regs *regs)
count++;
}
}
#else
static void show_backtrace(struct pt_regs *regs)
{
printf("No backtrace support enabled\n");
}
#endif

/**
* instr_len() - get instruction length
Expand Down Expand Up @@ -165,7 +158,8 @@ static void _exit_trap(ulong code, ulong epc, ulong tval, struct pt_regs *regs)
epc - gd->reloc_off, regs->ra - gd->reloc_off);

show_regs(regs);
show_backtrace(regs);
if (CONFIG_IS_ENABLED(FRAMEPOINTER))
show_backtrace(regs);
show_code(epc);
show_efi_loaded_images(epc);
panic("\n");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
if TARGET_ANDES_AE350

config SYS_CPU
default "andesv5"
default "andes"

config SYS_BOARD
default "ae350"

config SYS_VENDOR
default "AndesTech"
default "andestech"

config SYS_SOC
default "ae350"
Expand All @@ -33,7 +33,7 @@ config SYS_FDT_BASE

config BOARD_SPECIFIC_OPTIONS # dummy
def_bool y
select RISCV_NDS
select RISCV_ANDES
select SUPPORT_SPL
select BINMAN if SPL
imply SMP
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
AE350 BOARD
M: Rick Chen <[email protected]>
S: Maintained
F: board/AndesTech/ae350/
F: board/andestech/ae350/
F: include/configs/ae350.h
F: configs/ae350_rv32_defconfig
F: configs/ae350_rv32_falcon_defconfig
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void *board_fdt_blob_setup(int *err)
#ifdef CONFIG_SPL_BOARD_INIT
void spl_board_init()
{
/* enable v5l2 cache */
/* enable andes-l2 cache */
if (!CONFIG_IS_ENABLED(SYS_DCACHE_OFF))
enable_caches();
}
Expand Down
9 changes: 9 additions & 0 deletions board/starfive/visionfive2/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,13 @@ config BOARD_SPECIFIC_OPTIONS # dummy
imply PHY_LIB
imply PHY_MSCC

config STARFIVE_NO_EMMC
bool "Report eMMC size as zero"
help
The serial number string in the EEPROM is meant to report the
size of onboard eMMC. Unfortunately some Milk-V Mars CM Lite
modules without eMMC show a non-zero size here.

Set to 'Y' if you have a Mars CM Lite module.

endif
28 changes: 27 additions & 1 deletion board/starfive/visionfive2/spl.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,30 @@ void spl_fdt_fixup_mars(void *fdt)
}
}

void spl_fdt_fixup_mars_cm(void *fdt)
{
const char *compat;
const char *model;

spl_fdt_fixup_mars(fdt);

if (!get_mmc_size_from_eeprom()) {
int offset;

model = "Milk-V Mars CM Lite";
compat = "milkv,mars-cm-lite\0starfive,jh7110";

offset = fdt_path_offset(fdt, "/soc/pinctrl/mmc0-pins/mmc0-pins-rest");
/* GPIOMUX(22, GPOUT_SYS_SDIO0_RST, GPOEN_ENABLE, GPI_NONE) */
fdt_setprop_u32(fdt, offset, "pinmux", 0xff130016);
} else {
model = "Milk-V Mars CM";
compat = "milkv,mars-cm\0starfive,jh7110";
}
fdt_setprop(fdt, fdt_path_offset(fdt, "/"), "compatible", compat, sizeof(compat));
fdt_setprop_string(fdt, fdt_path_offset(fdt, "/"), "model", model);
}

void spl_fdt_fixup_version_a(void *fdt)
{
static const char compat[] = "starfive,visionfive-2-v1.2a\0starfive,jh7110";
Expand Down Expand Up @@ -236,7 +260,9 @@ void spl_perform_fixups(struct spl_image_info *spl_image)
pr_err("Can't read EEPROM\n");
return;
}
if (!strncmp(product_id, "MARS", 4)) {
if (!strncmp(product_id, "MARC", 4)) {
spl_fdt_fixup_mars_cm(spl_image->fdt_addr);
} else if (!strncmp(product_id, "MARS", 4)) {
spl_fdt_fixup_mars(spl_image->fdt_addr);
} else if (!strncmp(product_id, "VF7110", 6)) {
version = get_pcb_revision_from_eeprom();
Expand Down
11 changes: 10 additions & 1 deletion board/starfive/visionfive2/starfive_visionfive2.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ DECLARE_GLOBAL_DATA_PTR;
#define JH7110_L2_PREFETCHER_HART_OFFSET 0x2000
#define FDTFILE_MILK_V_MARS \
"starfive/jh7110-milkv-mars.dtb"
#define FDTFILE_MILK_V_MARS_CM \
"starfive/jh7110-milkv-mars-cm.dtb"
#define FDTFILE_MILK_V_MARS_CM_LITE \
"starfive/jh7110-milkv-mars-cm-lite.dtb"
#define FDTFILE_VISIONFIVE2_1_2A \
"starfive/jh7110-starfive-visionfive-2-v1.2a.dtb"
#define FDTFILE_VISIONFIVE2_1_3B \
Expand Down Expand Up @@ -61,7 +65,12 @@ static void set_fdtfile(void)
log_err("Can't read EEPROM\n");
return;
}
if (!strncmp(product_id, "MARS", 4)) {
if (!strncmp(product_id, "MARC", 4)) {
if (get_mmc_size_from_eeprom())
fdtfile = FDTFILE_MILK_V_MARS_CM;
else
fdtfile = FDTFILE_MILK_V_MARS_CM_LITE;
} else if (!strncmp(product_id, "MARS", 4)) {
fdtfile = FDTFILE_MILK_V_MARS;
} else if (!strncmp(product_id, "VF7110", 6)) {
version = get_pcb_revision_from_eeprom();
Expand Down
43 changes: 42 additions & 1 deletion board/starfive/visionfive2/visionfive2-i2c-eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,24 @@ static void set_product_id(char *string)
update_crc();
}

/**
* set_vendor() - set vendor name
*
* Takes a pointer to a string representing the vendor name, e.g.
* "StarFive Technology Co., Ltd.", stores it in the vendor field
* of the EEPROM local copy, and updates the CRC of the local copy.
*/
static void set_vendor(char *string)
{
memset(pbuf.eeprom.atom1.data.vstr, 0,
sizeof(pbuf.eeprom.atom1.data.vstr));

strncpy(pbuf.eeprom.atom1.data.vstr,
string, sizeof(pbuf.eeprom.atom1.data.vstr) - 1);

update_crc();
}

const char *get_product_id_from_eeprom(void)
{
if (read_eeprom())
Expand Down Expand Up @@ -463,6 +481,9 @@ int do_mac(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
} else if (!strcmp(cmd, "product_id")) {
set_product_id(argv[2]);
return 0;
} else if (!strcmp(cmd, "vendor")) {
set_vendor(argv[2]);
return 0;
}

return CMD_RET_USAGE;
Expand Down Expand Up @@ -548,6 +569,24 @@ u32 get_ddr_size_from_eeprom(void)
return hextoul(&pbuf.eeprom.atom1.data.pstr[14], NULL);
}

u32 get_mmc_size_from_eeprom(void)
{
u32 size;

if (IS_ENABLED(CONFIG_STARFIVE_NO_EMMC))
return 0;

if (read_eeprom())
return 0;

size = dectoul(&pbuf.eeprom.atom1.data.pstr[19], NULL);

if (pbuf.eeprom.atom1.data.pstr[21] == 'T')
size <<= 10;

return size;
}

U_BOOT_LONGHELP(mac,
"\n"
" - display EEPROM content\n"
Expand All @@ -568,7 +607,9 @@ U_BOOT_LONGHELP(mac,
"mac bom_revision <A>\n"
" - stores a StarFive BOM revision into the local EEPROM copy\n"
"mac product_id <VF7110A1-2228-D008E000-xxxxxxxx>\n"
" - stores a StarFive product ID into the local EEPROM copy\n");
" - stores a StarFive product ID into the local EEPROM copy\n"
"mac vendor <Vendor Name>\n"
" - set vendor string\n");

U_BOOT_CMD(
mac, 3, 1, do_mac,
Expand Down
1 change: 1 addition & 0 deletions configs/starfive_visionfive2_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ CONFIG_SPL_I2C=y
CONFIG_SPL_DM_SPI_FLASH=y
CONFIG_SPL_DM_RESET=y
CONFIG_SPL_SPI_LOAD=y
CONFIG_SPL_YMODEM_SUPPORT=y
CONFIG_SYS_PROMPT="StarFive # "
CONFIG_CMD_EEPROM=y
CONFIG_SYS_EEPROM_SIZE=512
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion doc/board/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Board-specific doc

actions/index
advantech/index
AndesTech/index
andestech/index
allwinner/index
amlogic/index
anbernic/index
Expand Down
3 changes: 2 additions & 1 deletion doc/board/starfive/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ StarFive
.. toctree::
:maxdepth: 1

milk-v_mars.rst
milk-v_mars
milk-v_mars_cm
visionfive2
Loading

0 comments on commit 676903c

Please sign in to comment.