diff --git a/arch/loongarch/config.mk b/arch/loongarch/config.mk index 14830572..4aba68b6 100644 --- a/arch/loongarch/config.mk +++ b/arch/loongarch/config.mk @@ -10,10 +10,17 @@ 64bit-bfd := elf64-loongarch ifdef CONFIG_64BIT -PLATFORM_CPPFLAGS += -mabi=lp64 -KBUILD_LDFLAGS += -m $(64bit-emul) -OBJCOPYFLAGS += -O $(64bit-bfd) -CONFIG_STANDALONE_LOAD_ADDR ?= 0x9000000080200000 +ifneq ($(CONFIG_GCC_VERSION), $(firstword $(shell echo "130000 $(CONFIG_GCC_VERSION)" | tr ' ' '\n' | sort -n))) +PLATFORM_CPPFLAGS += $(call cc-option, -mabi-lp64d) +PLATFORM_CPPFLAGS += $(call cc-option, -fpermissive) +PLATFORM_CPPFLAGS += $(call cc-option, -mno-relax) +KBUILD_LDFLAGS += --no-warn-rwx-segments +else +PLATFORM_CPPFLAGS += $(call cc-option, -mabi-lp64) +endif +KBUILD_LDFLAGS += -m $(64bit-emul) +OBJCOPYFLAGS += -O $(64bit-bfd) +CONFIG_STANDALONE_LOAD_ADDR ?= 0x9000000080200000 else PLATFORM_CPPFLAGS += -mabi=lp32 KBUILD_LDFLAGS += -m $(32bit-emul) diff --git a/arch/loongarch/lib/bootm.c b/arch/loongarch/lib/bootm.c index 85a3fd2a..50236efd 100644 --- a/arch/loongarch/lib/bootm.c +++ b/arch/loongarch/lib/bootm.c @@ -14,6 +14,8 @@ #include #include #include +#include +#include #if defined(CONFIG_LOONGSON_BOOT_FIXUP) extern void *build_boot_param(void); @@ -28,6 +30,9 @@ static int linux_argc; static char **linux_argv; static char *linux_argp; +// 新的传参规范里面无需把 command line 拆开成一个一个 直接字符串传进去就好 +static char *linux_command_line; + static char **linux_env; static char *linux_env_p; static int linux_env_idx; @@ -256,13 +261,52 @@ static void boot_prep_linux(bootm_headers_t *images) } } +/* + * 判断使用哪种传参方式 + * 0 代表旧的传参 + * 1 代表新的传参 + */ +static int judge_boot_param_type(bootm_headers_t *images) +{ + char* kernel_type; + kernel_type = image_get_name(images->legacy_hdr_os); + + if (!strncmp(kernel_type, "Linux-5", 7)) + return 0; + else if (!strncmp(kernel_type, "Linux-4", 7)) + return 0; + + return 1; +} + +static const char* boot_smbios_type2_board_name(void) +{ + struct udevice *dev; + ofnode parent_node, node; + + const char* board_name = NULL; + uclass_first_device(UCLASS_SYSINFO, &dev); + if (dev) { + parent_node = dev_read_subnode(dev, "smbios"); + if (!ofnode_valid(parent_node)) + return NULL; + + node = ofnode_find_subnode(parent_node, "baseboard"); + if (!ofnode_valid(node)) + return NULL; + + board_name = ofnode_read_string(node, "product"); + } + return board_name; +} + static void boot_jump_linux(bootm_headers_t *images) { typedef void __noreturn (*kernel_entry_t)(int, ulong, ulong, ulong); kernel_entry_t kernel = (kernel_entry_t)map_to_sysmem((void*)images->ep); #if defined(CONFIG_LOONGSON_BOOT_FIXUP) void *fw_arg2 = NULL, *fw_arg3 = NULL; - void *fdt = NULL, *bootparam = NULL; + void *bootparam = NULL; #endif debug("## Transferring control to Linux (at address %p) ...\n", kernel); @@ -277,21 +321,44 @@ static void boot_jump_linux(bootm_headers_t *images) #endif #if defined(CONFIG_LOONGSON_BOOT_FIXUP) - fdt = env_get("fdt_addr"); - if (fdt) { - fdt = (void *)simple_strtoul(fdt, NULL, 16); - if (fdt_check_header(fdt)) { - printf("Warning: invalid device tree. Used linux default dtb\n"); - fdt = NULL; + bootparam = build_boot_param(); + if (judge_boot_param_type(images)) { + int i; + const char* board_name; + // 见于 龙芯CPU统一系统架构规范(LA架构嵌入式系列).pdf 的 4.1 传参约定 一节 + fw_arg2 = (void*)(*(unsigned long long *)(bootparam + 8)); + board_name = boot_smbios_type2_board_name(); + + // 新的传参规范里面无需把 command line 拆开成一个一个 直接字符串传进去就好 + // 下标 0 的元素必定为 NULL 无视即可 + linux_command_line = (char*)calloc(256, sizeof(char)); + sprintf(linux_command_line, "%s", linux_argv[1]); + for (i = 2; i < linux_argc; ++i) { + sprintf(linux_command_line, "%s %s", linux_command_line, linux_argv[i]); } + // 把要匹配的板卡名字放到 command line 里面 + sprintf(linux_command_line, "%s bp_start=0x%.llx", linux_command_line, (unsigned long long)bootparam); + if (board_name) + sprintf(linux_command_line, "%s board_name=%s", linux_command_line, board_name); + + kernel(0, (ulong)linux_command_line, (ulong)fw_arg2, (ulong)fw_arg3); + } else { + void *fdt = NULL; + fdt = env_get("fdt_addr"); + if (fdt) { + fdt = (void *)simple_strtoul(fdt, NULL, 16); + if (fdt_check_header(fdt)) { + printf("Warning: invalid device tree. Used linux default dtb\n"); + fdt = NULL; + } + } + + fw_arg2 = bootparam; + fw_arg3 = fdt; + + kernel(linux_argc, (ulong)linux_argv, (ulong)fw_arg2, (ulong)fw_arg3); } - bootparam = build_boot_param(); - fw_arg2 = bootparam; - fw_arg3 = fdt; - - kernel(linux_argc, (ulong)linux_argv, (ulong)fw_arg2, - (ulong)fw_arg3); #else if (images->ft_len) { kernel(-2, (ulong)images->ft_addr, 0, 0); diff --git a/arch/loongarch/lib/spl.c b/arch/loongarch/lib/spl.c index 832dcda9..1e09c20b 100644 --- a/arch/loongarch/lib/spl.c +++ b/arch/loongarch/lib/spl.c @@ -55,14 +55,14 @@ void __noreturn board_init_f(ulong dummy) ulong new_sp; #ifdef DBG_ASM - printstr("Enter board_init_f...\r\n"); + printf("Enter board_init_f...\r\n"); #endif spl_mach_init(); ret = spl_early_init(); if (ret) { debug("spl_early_init() failed: %d\n", ret); #ifdef DBG_ASM - printstr("spl_early_init() failed.\r\n"); + printf("spl_early_init() failed.\r\n"); #endif hang(); } diff --git a/board/loongson/common/Kconfig b/board/loongson/common/Kconfig index 1f09b532..192646a7 100644 --- a/board/loongson/common/Kconfig +++ b/board/loongson/common/Kconfig @@ -60,4 +60,8 @@ config LOONGSON_BOARD_MMC_FS default n select CMD_UNZIP +config LOONGSON_MMC_HIGH_PERFORMANCE + bool "Change MMC-PAD to 0x7, will support HS200 mode" + default n + endmenu diff --git a/board/loongson/common/bootparam.c b/board/loongson/common/bootparam.c index fbfbb585..5c48dfa6 100644 --- a/board/loongson/common/bootparam.c +++ b/board/loongson/common/bootparam.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -19,9 +20,10 @@ #if defined(BOOT_PARAMS_BPI) -#ifdef ACPI_SUPPORT -const efi_guid_t smbios_guid = SMBIOS_TABLE_GUID; -#endif +// 无需一定要有 ACPI +// #ifdef ACPI_SUPPORT +// const efi_guid_t smbios_guid = SMBIOS_TABLE_GUID; +// #endif extern struct efi_system_table systab; extern efi_status_t efi_init_systab(void); @@ -134,13 +136,16 @@ u64 init_vbios(struct boot_params *bp, u64 offset) void loongson_smbios_init(void) { + const efi_guid_t smbios_guid = SMBIOS_TABLE_GUID; + write_smbios_table((ulong)SMBIOS_PHYSICAL_ADDRESS); -#ifdef ACPI_SUPPORT + // 无需一定要有 ACPI +// #ifdef ACPI_SUPPORT /* And expose them to our EFI payload */ - return efi_install_configuration_table(&smbios_guid, + efi_install_configuration_table(&smbios_guid, (void *)SMBIOS_PHYSICAL_ADDRESS); -#endif +// #endif } #ifdef ACPI_SUPPORT @@ -156,6 +161,24 @@ void loongson_acpi_init(void) } #endif +void loongson_fdt_init(void) +{ + // 新的传参规范里面 可以把 fdt 放在 efi table 里面 + const efi_guid_t fdt_guid = EFI_FDT_GUID; + void* fdt = (void*)env_get("fdt_addr"); + if (fdt) { + fdt = (void *)simple_strtoul(fdt, NULL, 16); + if (fdt_check_header(fdt)) { + printf("Warning: invalid device tree. Used linux default dtb\n"); + fdt = NULL; + } + } + + if (fdt) + efi_install_configuration_table(&fdt_guid, + (void *)fdt); +} + int init_boot_param(struct boot_params *bp) { u64 __maybe_unused tab_offset = sizeof(struct boot_params); @@ -184,6 +207,7 @@ int init_boot_param(struct boot_params *bp) #ifdef ACPI_SUPPORT loongson_acpi_init(); #endif + loongson_fdt_init(); return 0; } diff --git a/board/loongson/common/loongson_efi_systab.c b/board/loongson/common/loongson_efi_systab.c index c2951487..9cc084e2 100644 --- a/board/loongson/common/loongson_efi_systab.c +++ b/board/loongson/common/loongson_efi_systab.c @@ -19,6 +19,9 @@ enum efi_table_id { MAX_EFI_TABLES, }; +// 给16个efi table(不够可以加) 目前就 FDT SMBIOS ACPI +struct efi_configuration_table efi_tables[16]; + static struct efi_boot_services efi_boot_services = { .hdr = { .signature = EFI_BOOT_SERVICES_SIGNATURE, @@ -37,6 +40,14 @@ struct efi_runtime_services efi_runtime_services = { static u16 firmware_vendor[] = L"LoongSon"; +/* + * 由于 EFI 在 uboot 里面只有 x86 做了完善 + * 所以 这些 efi 的 table 由此处自行实现 + * 然后由于 tables 这个变量是需要手动赋值的 + * 以前的 NULL 是会导致写入崩溃的 + * 所以自行创建 efi_tables + */ + struct efi_system_table systab = { .hdr = { .signature = EFI_SYSTEM_TABLE_SIGNATURE, @@ -47,7 +58,7 @@ struct efi_system_table systab = { .fw_revision = FW_VERSION << 16 | FW_PATCHLEVEL << 8, .runtime = 0, .nr_tables = 0, - .tables = NULL, + .tables = efi_tables, }; /** diff --git a/board/loongson/common/loongson_update_menu.c b/board/loongson/common/loongson_update_menu.c index e67033b1..e2ff28de 100644 --- a/board/loongson/common/loongson_update_menu.c +++ b/board/loongson/common/loongson_update_menu.c @@ -87,7 +87,7 @@ static char *updatemenu_dtb[] = { "Update DTB (dtb.bin) to spi flash (by mmc)=loongson_update mmc dtb\0", #endif "Update DTB (dtb.bin) to spi flash (by tftp)=loongson_update tftp dtb\0", - "Clean DTB parts=sf probe;sf erase dtb 0x10000\0", + "Clean DTB parts=mtd erase dtb\0", NULL }; diff --git a/board/loongson/common/platform.c b/board/loongson/common/platform.c index 92275fca..a03b3071 100644 --- a/board/loongson/common/platform.c +++ b/board/loongson/common/platform.c @@ -609,6 +609,8 @@ void abort_key_handle_custom(int abort) abort_key_try_update_uboot_then_install_system, }; + mdelay(2000); + if (abort < 0 || abort >= sizeof(func_set) / sizeof(abort_key_handle_func)) return; ret = func_set[abort](); diff --git a/board/loongson/ls2k300/ls2k300.c b/board/loongson/ls2k300/ls2k300.c index 94733b79..fa0769b8 100644 --- a/board/loongson/ls2k300/ls2k300.c +++ b/board/loongson/ls2k300/ls2k300.c @@ -81,7 +81,13 @@ static void dev_fixup(void) //enhance the io driving force val = readl(LS_GENERAL_CFG4); +// MMC 高驱动力下可到 hs200 +#ifdef CONFIG_LOONGSON_MMC_HIGH_PERFORMANCE + val |= (0x3 << PAD_CTRL_DVO) | (0x3 << PAD_CTRL_GMAC) | (0x3 << PAD_CTRL_USB) + | (0x7 << PAD_CTRL_EMMC) | (0x7 << PAD_CTRL_SDIO); +#else val |= (0x3 << PAD_CTRL_DVO) | (0x3 << PAD_CTRL_GMAC) | (0x3 << PAD_CTRL_USB); +#endif writel(val, LS_GENERAL_CFG4); // All UARTs in 2 wire mode diff --git a/common/command.c b/common/command.c index 41c91c6d..93690f77 100644 --- a/common/command.c +++ b/common/command.c @@ -583,7 +583,8 @@ static int cmd_call(struct cmd_tbl *cmdtp, int flag, int argc, return result; } -enum command_ret_t cmd_process(int flag, int argc, char *const argv[], +// enum command_ret_t +int cmd_process(int flag, int argc, char *const argv[], int *repeatable, ulong *ticks) { enum command_ret_t rc = CMD_RET_SUCCESS; diff --git a/configs/loongson_2k300_mini_dp_defconfig b/configs/loongson_2k300_mini_dp_defconfig index 6992fa76..515b9762 100644 --- a/configs/loongson_2k300_mini_dp_defconfig +++ b/configs/loongson_2k300_mini_dp_defconfig @@ -26,6 +26,7 @@ CONFIG_CPU_1000MHZ=y CONFIG_LOONGSON_RECOVER=y CONFIG_LOONGSON_GENERAL_LOAD=y CONFIG_LOONGSON_BOARD_MMC_FS=y +CONFIG_LOONGSON_MMC_HIGH_PERFORMANCE=y CONFIG_SPL_PAYLOAD="u-boot.img" CONFIG_PHYS_64BIT=y CONFIG_SYS_LOAD_ADDR=0x9000000003000000 diff --git a/configs/loongson_2k300_pai_defconfig b/configs/loongson_2k300_pai_defconfig index ddf97527..c531ffb1 100644 --- a/configs/loongson_2k300_pai_defconfig +++ b/configs/loongson_2k300_pai_defconfig @@ -26,6 +26,7 @@ CONFIG_CPU_1000MHZ=y CONFIG_LOONGSON_RECOVER=y CONFIG_LOONGSON_GENERAL_LOAD=y CONFIG_LOONGSON_BOARD_MMC_FS=y +CONFIG_LOONGSON_MMC_HIGH_PERFORMANCE=y CONFIG_SPL_PAYLOAD="u-boot.img" CONFIG_PHYS_64BIT=y CONFIG_SYS_LOAD_ADDR=0x9000000003000000 diff --git a/drivers/mmc/ls_mmc.c b/drivers/mmc/ls_mmc.c index a3c3a1dc..503ae5d8 100644 --- a/drivers/mmc/ls_mmc.c +++ b/drivers/mmc/ls_mmc.c @@ -290,6 +290,10 @@ static int sdio_send_cmd(struct udevice *dev, struct mmc_cmd *cmd, struct mmc_da sdio_writel(host, SDICMDARG, cmd->cmdarg); sdio_writel(host, SDICMDCON, SDIO_MAKE_CMD(cmd_index, flag)); + // 部分EMMC芯片需要延迟 + // 否则指令发送频率一高会有数据传输问题 + udelay(1); + while ((cmd_fin == 0) && timeout--) { sdiintmsk = sdio_readl(host, SDIINTMSK); cmd_fin = SDIO_GET_CMDINT(sdiintmsk); @@ -345,6 +349,7 @@ out: sdio_writel(host, SDIINTMSK, (sdiintmsk & 0x1fe)); sdio_writel(host, SDIINTEN, 0x0); + return err; } diff --git a/drivers/ram/loongson/libmem_config_new_abi.a b/drivers/ram/loongson/libmem_config_new_abi.a new file mode 100644 index 00000000..6610616b Binary files /dev/null and b/drivers/ram/loongson/libmem_config_new_abi.a differ diff --git a/drivers/ram/loongson/ls_ddr4.c b/drivers/ram/loongson/ls_ddr4.c index 98d426e1..87ec6009 100644 --- a/drivers/ram/loongson/ls_ddr4.c +++ b/drivers/ram/loongson/ls_ddr4.c @@ -248,24 +248,24 @@ void mm_feature_init(struct mc_setting *mc) mm_ctrl_info.paster.mc1_row_num = MC1_ROW_NUM; mm_ctrl_info.paster.mc1_addr_mirror = MC1_ADDR_MIRROR; mm_ctrl_info.paster.mc1_bg_mirror = MC1_BG_MIRROR; - mm_ctrl_info.param_reg_array = ¶m_info; + mm_ctrl_info.param_reg_array = param_info; } -void print_mm_ctrl() +void print_mm_ctrl(void) { printf("=================================================================================\n"); printf(" mc_type:%u\n", mm_ctrl_info.mc_type); printf(" mc_regs_base:%llu\n", mm_ctrl_info.mc_regs_base); printf(" cache_mem_base:%llu\n", mm_ctrl_info.cache_mem_base); printf(" mem_base:%llu\n", mm_ctrl_info.mem_base); - printf(" ddr_freq:%lu\n", mm_ctrl_info.ddr_freq); - printf(" ddr_freq_2slot:%lu\n", mm_ctrl_info.ddr_freq_2slot); - printf(" dimm_info_in_flash_offset:%lu\n", mm_ctrl_info.dimm_info_in_flash_offset); - printf(" sameba_adj:%lu\n", mm_ctrl_info.sameba_adj); - printf(" samebg_adj:%lu\n", mm_ctrl_info.samebg_adj); - printf(" samec_adj:%lu\n", mm_ctrl_info.samec_adj); - printf(" samecs_adj:%lu\n", mm_ctrl_info.samecs_adj); - printf(" diffcs_adj:%lu\n", mm_ctrl_info.diffcs_adj); + printf(" ddr_freq:%llu\n", mm_ctrl_info.ddr_freq); + printf(" ddr_freq_2slot:%llu\n", mm_ctrl_info.ddr_freq_2slot); + printf(" dimm_info_in_flash_offset:%llu\n", mm_ctrl_info.dimm_info_in_flash_offset); + printf(" sameba_adj:%llu\n", mm_ctrl_info.sameba_adj); + printf(" samebg_adj:%llu\n", mm_ctrl_info.samebg_adj); + printf(" samec_adj:%llu\n", mm_ctrl_info.samec_adj); + printf(" samecs_adj:%llu\n", mm_ctrl_info.samecs_adj); + printf(" diffcs_adj:%llu\n", mm_ctrl_info.diffcs_adj); printf(" mc_interleave_offset:%llu\n", mm_ctrl_info.mc_interleave_offset); printf(" ref_clk:%u\n", mm_ctrl_info.ref_clk); printf("node_offset:%u\n", mm_ctrl_info.node_offset); diff --git a/drivers/video/loongson_fb.c b/drivers/video/loongson_fb.c index 4d101b5a..bddb577b 100644 --- a/drivers/video/loongson_fb.c +++ b/drivers/video/loongson_fb.c @@ -188,7 +188,7 @@ static int ls_disptiming_to_modesetting(struct ls_video_priv *priv, if (priv->conn_type == LS_CONNECTOR_VGA) { for (i = 0; i < ARRAY_SIZE(vgamode); i++) { - if (vgamode[i].hactive == timing->hactive.typ + if (vgamode[i].hactive == timing->hactive.typ && vgamode[i].vactive == timing->vactive.typ) { mode_id = i; break; @@ -251,7 +251,7 @@ static void config_pll(void __iomem *pll_base, struct ls_pll_cfg *pix_pll) writel((out | 1), pll_base); #elif defined(CONFIG_SOC_LS2K1000) - ulong out = ((ulong)(pix_pll->l1_loopc) << 32) | + ulong out = ((ulong)(pix_pll->l1_loopc) << 32) | (pix_pll->l1_frefc << 26) | (1UL << 42) | (0x3 << 10) | (0x1 << 7); writeq(0, pll_base); @@ -419,9 +419,12 @@ static int ls_dc_init(struct ls_video_priv *priv) static int ls_read_edid(struct ls_video_priv *priv, int block, u8 *buf) { + int ret = 0; +#if defined(CONFIG_DM_I2C) int shift = block * EDID_SIZE; struct udevice *chip; - int ret; +#endif + #ifdef CONFIG_VIDEO_BRIDGE if (priv->conn_type == LS_CONNECTOR_BRIDGE) { ret = video_bridge_read_edid(priv->connector, buf, EDID_SIZE); @@ -441,7 +444,7 @@ static int ls_read_edid(struct ls_video_priv *priv, int block, u8 *buf) return dm_i2c_read(chip, shift, buf, EDID_SIZE); } #endif - return 0; + return ret; } extern int ls_fill_display_timing_by_name(struct display_timing* timing, char* name); @@ -658,7 +661,7 @@ static int ls_video_probe(struct udevice *dev) debug("%s uc_plat: base 0x%lx, size 0x%x\n", dev->name, uc_plat->base, uc_plat->size); - + priv->ddc_bus = NULL; priv->connector = NULL; priv->conn_type = LS_CONNECTOR_UNKNOWN; @@ -716,10 +719,10 @@ static int ls_video_probe(struct udevice *dev) panel_enable_backlight(priv->connector); } - debug("%s - connector type: %s, pix fmt: %d, display resolution: %d x %d\n", dev->name, + debug("%s - connector type: %s, pix fmt: %d, display resolution: %d x %d\n", dev->name, priv->conn_type == LS_CONNECTOR_PANEL ? "Panel" : priv->conn_type == LS_CONNECTOR_VGA ? "VGA" : - priv->conn_type == LS_CONNECTOR_HDMI ? "HDMI" : + priv->conn_type == LS_CONNECTOR_HDMI ? "HDMI" : priv->conn_type == LS_CONNECTOR_BRIDGE ? "Bridge" :"Unknown", priv->pix_fmt, priv->timing.hactive.typ, priv->timing.vactive.typ); diff --git a/scripts/Makefile.spl b/scripts/Makefile.spl index d1bd9aa8..43ab8dca 100644 --- a/scripts/Makefile.spl +++ b/scripts/Makefile.spl @@ -124,7 +124,11 @@ PLATFORM_LIBS := $(filter-out %/lib.a, $(filter-out -lgcc, $(PLATFORM_LIBS))) $( endif ifdef CONFIG_LOONGSON_DDR4 -PLATFORM_LIBS += -L $(abspath $(srctree)/drivers/ram/loongson/) -lmem_config +ifneq ($(CONFIG_GCC_VERSION), $(firstword $(shell echo "130000 $(CONFIG_GCC_VERSION)" | tr ' ' '\n' | sort -n))) +PLATFORM_LIBS += $(abspath $(srctree)/drivers/ram/loongson/libmem_config_new_abi.a) +else +PLATFORM_LIBS += $(abspath $(srctree)/drivers/ram/loongson/libmem_config.a) +endif endif u-boot-spl-init := $(head-y) diff --git a/set_env.sh b/set_env.sh index ba3030ce..63e11bb9 100755 --- a/set_env.sh +++ b/set_env.sh @@ -1,52 +1,61 @@ #!/bin/bash -# AUTHOR: maoxiaochuan@loongson.cn -# Date: 2021-12-3 -# ORG: Loongson-GD - #set -x -function setup_mips_env() -{ - echo "====>setup env for MIPS..." - CC_PREFIX=/opt/mips64el-linux-gcc-8.x/host - export PATH=$CC_PREFIX/bin:$PATH - export LD_LIBRARY_PATH=$CC_PREFIX/lib:$LD_LIBRARY_PATH - export LD_LIBRARY_PATH=$CC_PREFIX/mips64el-buildroot-linux-gnu/lib64:$LD_LIBRARY_PATH - -# CC_PREFIX=/opt/mips-loongson-gcc8-linux-gnu-2021-06-04 -# export PATH=$CC_PREFIX/bin:$PATH -# export LD_LIBRARY_PATH=$CC_PREFIX/lib:$LD_LIBRARY_PATH - - export ARCH=mips -# export CROSS_COMPILE=mips-linux-gnu- - export CROSS_COMPILE=mips64el-linux- -} +abi1_toolchain_list=("/opt/loongson-gnu-toolchain-x86_64-loongarch64-linux-gnu" \ + "/opt/loongson-gnu-toolchain-8.3-x86_64-loongarch64-linux-gnu-rc1.4" \ + "/opt/loongson-gnu-toolchain-8.3-x86_64-loongarch64-linux-gnu-rc1.3-1" \ + "/opt/loongson-gnu-toolchain-8.3-x86_64-loongarch64-linux-gnu-rc1.2" \ + "/opt/toolchain-loongarch64-linux-gnu-gcc8-host-x86_64-2022-07-18") +abi2_toolchain_list=("/opt/loongarch64-linux-gnu-gcc13.3" \ + "/opt/loongarch64-linux-gnu-gcc14.2") +real_target=0 +real_toolchain="" function setup_loongarch_env() { echo "====>setup env for LoongArch..." -# CC_PREFIX=/opt/toolchain-loongarch64-linux-gnu-gcc8-host-x86_64-2022-07-18 - CC_PREFIX=/opt/loongson-gnu-toolchain-x86_64-loongarch64-linux-gnu - export PATH=$CC_PREFIX/bin:$PATH - export LD_LIBRARY_PATH=$CC_PREFIX/lib:$LD_LIBRARY_PATH - export LD_LIBRARY_PATH=$CC_PREFIX/loongarch64-linux-gnu/lib64:$LD_LIBRARY_PATH + CC_PREFIX=$real_toolchain + export PATH=$PATH:$CC_PREFIX/bin + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CC_PREFIX/lib + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CC_PREFIX/loongarch64-linux-gnu/lib64 export ARCH=loongarch export CROSS_COMPILE=loongarch64-linux-gnu- } +for i in ${abi1_toolchain_list[*]} +do + real_toolchain=$i + if [ -d $real_toolchain ]; then + real_target=1 + break; + fi +done if [ $# -eq 1 ] ; then - if [ "$1" == "mips" ]; then - setup_mips_env - else - setup_loongarch_env + if [[ "$1" == "abi2" ]]; then + real_target=0 + real_toolchain="" + for i in ${abi2_toolchain_list[*]} + do + real_toolchain=$i + if [ -d $real_toolchain ]; then + real_target=1 + break; + fi + done fi -else - setup_loongarch_env fi +if [ $real_target -eq 0 ]; then + echo "没有找到相关工具链的文件夹" +fi +echo "当前声明的工具链为:" +echo $real_toolchain + +setup_loongarch_env + #set +x