1 // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
3 * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
13 #include <env_internal.h>
15 #include <generic-phy.h>
27 #include <remoteproc.h>
34 #include <asm/arch/stm32.h>
35 #include <asm/arch/sys_proto.h>
36 #include <jffs2/load_kernel.h>
37 #include <linux/err.h>
38 #include <power/regulator.h>
39 #include <usb/dwc2_udc.h>
41 /* SYSCFG registers */
42 #define SYSCFG_BOOTR 0x00
43 #define SYSCFG_PMCSETR 0x04
44 #define SYSCFG_IOCTRLSETR 0x18
45 #define SYSCFG_ICNR 0x1C
46 #define SYSCFG_CMPCR 0x20
47 #define SYSCFG_CMPENSETR 0x24
48 #define SYSCFG_PMCCLRR 0x44
50 #define SYSCFG_BOOTR_BOOT_MASK GENMASK(2, 0)
51 #define SYSCFG_BOOTR_BOOTPD_SHIFT 4
53 #define SYSCFG_IOCTRLSETR_HSLVEN_TRACE BIT(0)
54 #define SYSCFG_IOCTRLSETR_HSLVEN_QUADSPI BIT(1)
55 #define SYSCFG_IOCTRLSETR_HSLVEN_ETH BIT(2)
56 #define SYSCFG_IOCTRLSETR_HSLVEN_SDMMC BIT(3)
57 #define SYSCFG_IOCTRLSETR_HSLVEN_SPI BIT(4)
59 #define SYSCFG_CMPCR_SW_CTRL BIT(1)
60 #define SYSCFG_CMPCR_READY BIT(8)
62 #define SYSCFG_CMPENSETR_MPU_EN BIT(0)
64 #define SYSCFG_PMCSETR_ETH_CLK_SEL BIT(16)
65 #define SYSCFG_PMCSETR_ETH_REF_CLK_SEL BIT(17)
67 #define SYSCFG_PMCSETR_ETH_SELMII BIT(20)
69 #define SYSCFG_PMCSETR_ETH_SEL_MASK GENMASK(23, 21)
70 #define SYSCFG_PMCSETR_ETH_SEL_GMII_MII 0
71 #define SYSCFG_PMCSETR_ETH_SEL_RGMII BIT(21)
72 #define SYSCFG_PMCSETR_ETH_SEL_RMII BIT(23)
75 * Get a global data pointer
77 DECLARE_GLOBAL_DATA_PTR;
79 #define USB_LOW_THRESHOLD_UV 200000
80 #define USB_WARNING_LOW_THRESHOLD_UV 660000
81 #define USB_START_LOW_THRESHOLD_UV 1230000
82 #define USB_START_HIGH_THRESHOLD_UV 2150000
90 const char *fdt_compat;
93 if (IS_ENABLED(CONFIG_STM32MP1_OPTEE))
94 mode = "trusted with OP-TEE";
95 else if (IS_ENABLED(CONFIG_STM32MP1_TRUSTED))
100 printf("Board: stm32mp1 in %s mode", mode);
101 fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",
103 if (fdt_compat && fdt_compat_len)
104 printf(" (%s)", fdt_compat);
107 /* display the STMicroelectronics board identification */
108 if (CONFIG_IS_ENABLED(CMD_STBOARD)) {
109 ret = uclass_get_device_by_driver(UCLASS_MISC,
110 DM_GET_DRIVER(stm32mp_bsec),
113 ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_BOARD),
116 printf("Board: MB%04x Var%d.%d Rev.%c-%02d\n",
120 ((otp >> 8) & 0xF) - 1 + 'A',
127 static void board_key_check(void)
129 #if defined(CONFIG_FASTBOOT) || defined(CONFIG_CMD_STM32PROG)
131 struct gpio_desc gpio;
132 enum forced_boot_mode boot_mode = BOOT_NORMAL;
134 node = ofnode_path("/config");
135 if (!ofnode_valid(node)) {
136 debug("%s: no /config node?\n", __func__);
139 #ifdef CONFIG_FASTBOOT
140 if (gpio_request_by_name_nodev(node, "st,fastboot-gpios", 0,
141 &gpio, GPIOD_IS_IN)) {
142 debug("%s: could not find a /config/st,fastboot-gpios\n",
145 if (dm_gpio_get_value(&gpio)) {
146 puts("Fastboot key pressed, ");
147 boot_mode = BOOT_FASTBOOT;
150 dm_gpio_free(NULL, &gpio);
153 #ifdef CONFIG_CMD_STM32PROG
154 if (gpio_request_by_name_nodev(node, "st,stm32prog-gpios", 0,
155 &gpio, GPIOD_IS_IN)) {
156 debug("%s: could not find a /config/st,stm32prog-gpios\n",
159 if (dm_gpio_get_value(&gpio)) {
160 puts("STM32Programmer key pressed, ");
161 boot_mode = BOOT_STM32PROG;
163 dm_gpio_free(NULL, &gpio);
167 if (boot_mode != BOOT_NORMAL) {
168 puts("entering download mode...\n");
169 clrsetbits_le32(TAMP_BOOT_CONTEXT,
170 TAMP_BOOT_FORCED_MASK,
176 #if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG)
178 /* STMicroelectronics STUSB1600 Type-C controller */
179 #define STUSB1600_CC_CONNECTION_STATUS 0x0E
181 /* STUSB1600_CC_CONNECTION_STATUS bitfields */
182 #define STUSB1600_CC_ATTACH BIT(0)
184 static int stusb1600_init(struct udevice **dev_stusb1600)
187 struct udevice *dev, *bus;
191 *dev_stusb1600 = NULL;
193 /* if node stusb1600 is present, means DK1 or DK2 board */
194 node = ofnode_by_compatible(ofnode_null(), "st,stusb1600");
195 if (!ofnode_valid(node))
198 ret = ofnode_read_u32(node, "reg", &chip_addr);
202 ret = uclass_get_device_by_ofnode(UCLASS_I2C, ofnode_get_parent(node),
205 printf("bus for stusb1600 not found\n");
209 ret = dm_i2c_probe(bus, chip_addr, 0, &dev);
211 *dev_stusb1600 = dev;
216 static int stusb1600_cable_connected(struct udevice *dev)
220 if (dm_i2c_read(dev, STUSB1600_CC_CONNECTION_STATUS, &status, 1))
223 return status & STUSB1600_CC_ATTACH;
226 #include <usb/dwc2_udc.h>
227 int g_dnl_board_usb_cable_connected(void)
229 struct udevice *stusb1600;
230 struct udevice *dwc2_udc_otg;
233 if (!stusb1600_init(&stusb1600))
234 return stusb1600_cable_connected(stusb1600);
236 ret = uclass_get_device_by_driver(UCLASS_USB_GADGET_GENERIC,
237 DM_GET_DRIVER(dwc2_udc_otg),
240 debug("dwc2_udc_otg init failed\n");
242 return dwc2_udc_B_session_valid(dwc2_udc_otg);
245 #define STM32MP1_G_DNL_DFU_PRODUCT_NUM 0xdf11
246 #define STM32MP1_G_DNL_FASTBOOT_PRODUCT_NUM 0x0afb
248 int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
250 if (!strcmp(name, "usb_dnl_dfu"))
251 put_unaligned(STM32MP1_G_DNL_DFU_PRODUCT_NUM, &dev->idProduct);
252 else if (!strcmp(name, "usb_dnl_fastboot"))
253 put_unaligned(STM32MP1_G_DNL_FASTBOOT_PRODUCT_NUM,
256 put_unaligned(CONFIG_USB_GADGET_PRODUCT_NUM, &dev->idProduct);
261 #endif /* CONFIG_USB_GADGET */
264 static int get_led(struct udevice **dev, char *led_string)
269 led_name = fdtdec_get_config_string(gd->fdt_blob, led_string);
271 pr_debug("%s: could not find %s config string\n",
272 __func__, led_string);
275 ret = led_get_by_label(led_name, dev);
277 debug("%s: get=%d\n", __func__, ret);
284 static int setup_led(enum led_state_t cmd)
289 ret = get_led(&dev, "u-boot,boot-led");
293 ret = led_set_state(dev, cmd);
298 static void __maybe_unused led_error_blink(u32 nb_blink)
310 ret = get_led(&led, "u-boot,error-led");
312 /* make u-boot,error-led blinking */
313 /* if U32_MAX and 125ms interval, for 17.02 years */
314 for (i = 0; i < 2 * nb_blink; i++) {
315 led_set_state(led, LEDST_TOGGLE);
322 /* infinite: the boot process must be stopped */
323 if (nb_blink == U32_MAX)
328 static int board_check_usb_power(void)
330 struct ofnode_phandle_args adc_args;
335 int min_uV = USB_START_HIGH_THRESHOLD_UV;
336 int ret, uV, adc_count;
339 node = ofnode_path("/config");
340 if (!ofnode_valid(node)) {
341 debug("%s: no /config node?\n", __func__);
346 * Retrieve the ADC channels devices and get measurement
349 adc_count = ofnode_count_phandle_with_args(node, "st,adc_usb_pd",
350 "#io-channel-cells");
352 if (adc_count == -ENOENT)
355 pr_err("%s: can't find adc channel (%d)\n", __func__,
361 for (i = 0; i < adc_count; i++) {
362 if (ofnode_parse_phandle_with_args(node, "st,adc_usb_pd",
363 "#io-channel-cells", 0, i,
365 pr_debug("%s: can't find /config/st,adc_usb_pd\n",
370 ret = uclass_get_device_by_ofnode(UCLASS_ADC, adc_args.node,
374 pr_err("%s: Can't get adc device(%d)\n", __func__,
379 ret = adc_channel_single_shot(adc->name, adc_args.args[0],
382 pr_err("%s: single shot failed for %s[%d]!\n",
383 __func__, adc->name, adc_args.args[0]);
387 if (!adc_raw_to_uV(adc, raw, &uV)) {
392 pr_debug("%s: %s[%02d] = %u, %d uV\n", __func__,
393 adc->name, adc_args.args[0], raw, uV);
395 pr_err("%s: Can't get uV value for %s[%d]\n",
396 __func__, adc->name, adc_args.args[0]);
401 * If highest value is inside 1.23 Volts and 2.10 Volts, that means
402 * board is plugged on an USB-C 3A power supply and boot process can
405 if (max_uV > USB_START_LOW_THRESHOLD_UV &&
406 max_uV <= USB_START_HIGH_THRESHOLD_UV &&
407 min_uV <= USB_LOW_THRESHOLD_UV)
410 pr_err("****************************************************\n");
413 * If highest and lowest value are either both below
414 * USB_LOW_THRESHOLD_UV or both above USB_LOW_THRESHOLD_UV, that
415 * means USB TYPE-C is in unattached mode, this is an issue, make
416 * u-boot,error-led blinking and stop boot process.
418 if ((max_uV > USB_LOW_THRESHOLD_UV &&
419 min_uV > USB_LOW_THRESHOLD_UV) ||
420 (max_uV <= USB_LOW_THRESHOLD_UV &&
421 min_uV <= USB_LOW_THRESHOLD_UV)) {
422 pr_err("* ERROR USB TYPE-C connection in unattached mode *\n");
423 pr_err("* Check that USB TYPE-C cable is correctly plugged *\n");
424 /* with 125ms interval, led will blink for 17.02 years ....*/
428 if (max_uV > USB_LOW_THRESHOLD_UV &&
429 max_uV <= USB_WARNING_LOW_THRESHOLD_UV &&
430 min_uV <= USB_LOW_THRESHOLD_UV) {
431 pr_err("* WARNING 500mA power supply detected *\n");
435 if (max_uV > USB_WARNING_LOW_THRESHOLD_UV &&
436 max_uV <= USB_START_LOW_THRESHOLD_UV &&
437 min_uV <= USB_LOW_THRESHOLD_UV) {
438 pr_err("* WARNING 1.5mA power supply detected *\n");
443 * If highest value is above 2.15 Volts that means that the USB TypeC
444 * supplies more than 3 Amp, this is not compliant with TypeC specification
446 if (max_uV > USB_START_HIGH_THRESHOLD_UV) {
447 pr_err("* USB TYPE-C charger not compliant with *\n");
448 pr_err("* specification *\n");
449 pr_err("****************************************************\n\n");
450 /* with 125ms interval, led will blink for 17.02 years ....*/
453 pr_err("* Current too low, use a 3A power supply! *\n");
454 pr_err("****************************************************\n\n");
457 led_error_blink(nb_blink);
461 #endif /* CONFIG_ADC */
463 static void sysconf_init(void)
465 #ifndef CONFIG_STM32MP1_TRUSTED
467 #ifdef CONFIG_DM_REGULATOR
468 struct udevice *pwr_dev;
469 struct udevice *pwr_reg;
476 syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG);
478 /* interconnect update : select master using the port 1 */
481 /* today information is hardcoded in U-Boot */
482 writel(BIT(9), syscfg + SYSCFG_ICNR);
484 /* disable Pull-Down for boot pin connected to VDD */
485 bootr = readl(syscfg + SYSCFG_BOOTR);
486 bootr &= ~(SYSCFG_BOOTR_BOOT_MASK << SYSCFG_BOOTR_BOOTPD_SHIFT);
487 bootr |= (bootr & SYSCFG_BOOTR_BOOT_MASK) << SYSCFG_BOOTR_BOOTPD_SHIFT;
488 writel(bootr, syscfg + SYSCFG_BOOTR);
490 #ifdef CONFIG_DM_REGULATOR
491 /* High Speed Low Voltage Pad mode Enable for SPI, SDMMC, ETH, QSPI
492 * and TRACE. Needed above ~50MHz and conditioned by AFMUX selection.
493 * The customer will have to disable this for low frequencies
494 * or if AFMUX is selected but the function not used, typically for
495 * TRACE. Otherwise, impact on power consumption.
498 * enabling High Speed mode while VDD>2.7V
499 * with the OTP product_below_2v5 (OTP 18, BIT 13)
500 * erroneously set to 1 can damage the IC!
501 * => U-Boot set the register only if VDD < 2.7V (in DT)
502 * but this value need to be consistent with board design
504 ret = uclass_get_device_by_driver(UCLASS_PMIC,
505 DM_GET_DRIVER(stm32mp_pwr_pmic),
508 ret = uclass_get_device_by_driver(UCLASS_MISC,
509 DM_GET_DRIVER(stm32mp_bsec),
512 pr_err("Can't find stm32mp_bsec driver\n");
516 ret = misc_read(dev, STM32_BSEC_SHADOW(18), &otp, 4);
520 /* get VDD = vdd-supply */
521 ret = device_get_supply_regulator(pwr_dev, "vdd-supply",
524 /* check if VDD is Low Voltage */
526 if (regulator_get_value(pwr_reg) < 2700000) {
527 writel(SYSCFG_IOCTRLSETR_HSLVEN_TRACE |
528 SYSCFG_IOCTRLSETR_HSLVEN_QUADSPI |
529 SYSCFG_IOCTRLSETR_HSLVEN_ETH |
530 SYSCFG_IOCTRLSETR_HSLVEN_SDMMC |
531 SYSCFG_IOCTRLSETR_HSLVEN_SPI,
532 syscfg + SYSCFG_IOCTRLSETR);
535 pr_err("product_below_2v5=0: HSLVEN protected by HW\n");
538 pr_err("product_below_2v5=1: HSLVEN update is destructive, no update as VDD>2.7V\n");
541 debug("VDD unknown");
546 /* activate automatic I/O compensation
547 * warning: need to ensure CSI enabled and ready in clock driver
549 writel(SYSCFG_CMPENSETR_MPU_EN, syscfg + SYSCFG_CMPENSETR);
551 while (!(readl(syscfg + SYSCFG_CMPCR) & SYSCFG_CMPCR_READY))
553 clrbits_le32(syscfg + SYSCFG_CMPCR, SYSCFG_CMPCR_SW_CTRL);
557 #ifdef CONFIG_DM_REGULATOR
558 /* Fix to make I2C1 usable on DK2 for touchscreen usage in kernel */
559 static int dk2_i2c1_fix(void)
562 struct gpio_desc hdmi, audio;
565 node = ofnode_path("/soc/i2c@40012000/hdmi-transmitter@39");
566 if (!ofnode_valid(node)) {
567 pr_debug("%s: no hdmi-transmitter@39 ?\n", __func__);
571 if (gpio_request_by_name_nodev(node, "reset-gpios", 0,
572 &hdmi, GPIOD_IS_OUT)) {
573 pr_debug("%s: could not find reset-gpios\n",
578 node = ofnode_path("/soc/i2c@40012000/cs42l51@4a");
579 if (!ofnode_valid(node)) {
580 pr_debug("%s: no cs42l51@4a ?\n", __func__);
584 if (gpio_request_by_name_nodev(node, "reset-gpios", 0,
585 &audio, GPIOD_IS_OUT)) {
586 pr_debug("%s: could not find reset-gpios\n",
591 /* before power up, insure that HDMI and AUDIO IC is under reset */
592 ret = dm_gpio_set_value(&hdmi, 1);
594 pr_err("%s: can't set_value for hdmi_nrst gpio", __func__);
597 ret = dm_gpio_set_value(&audio, 1);
599 pr_err("%s: can't set_value for audio_nrst gpio", __func__);
603 /* power-up audio IC */
604 regulator_autoset_by_name("v1v8_audio", NULL);
606 /* power-up HDMI IC */
607 regulator_autoset_by_name("v1v2_hdmi", NULL);
608 regulator_autoset_by_name("v3v3_hdmi", NULL);
614 static bool board_is_dk2(void)
616 if (CONFIG_IS_ENABLED(TARGET_ST_STM32MP15x) &&
617 of_machine_is_compatible("st,stm32mp157c-dk2"))
624 /* board dependent setup after realloc */
629 /* address of boot parameters */
630 gd->bd->bi_boot_params = STM32_DDR_BASE + 0x100;
632 /* probe all PINCTRL for hog */
633 for (uclass_first_device(UCLASS_PINCTRL, &dev);
635 uclass_next_device(&dev)) {
636 pr_debug("probe pincontrol = %s\n", dev->name);
641 #ifdef CONFIG_DM_REGULATOR
645 regulators_enable_boot_on(_DEBUG);
650 if (CONFIG_IS_ENABLED(CONFIG_LED))
656 int board_late_init(void)
659 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
660 const void *fdt_compat;
667 fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",
669 if (fdt_compat && fdt_compat_len) {
670 if (strncmp(fdt_compat, "st,", 3) != 0)
671 env_set("board_name", fdt_compat);
673 env_set("board_name", fdt_compat + 3);
675 ret = uclass_get_device_by_driver(UCLASS_MISC,
676 DM_GET_DRIVER(stm32mp_bsec),
680 ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_BOARD),
683 snprintf(buf, sizeof(buf), "0x%04x", otp >> 16);
684 env_set("board_id", buf);
686 snprintf(buf, sizeof(buf), "0x%04x",
687 ((otp >> 8) & 0xF) - 1 + 0xA);
688 env_set("board_rev", buf);
693 /* for DK1/DK2 boards */
694 board_check_usb_power();
695 #endif /* CONFIG_ADC */
697 /* Check the boot-source to disable bootdelay */
698 boot_device = env_get("boot_device");
699 if (!strcmp(boot_device, "serial") || !strcmp(boot_device, "usb"))
700 env_set("bootdelay", "0");
705 void board_quiesce_devices(void)
708 setup_led(LEDST_OFF);
712 /* eth init function : weak called in eqos driver */
713 int board_interface_eth_init(struct udevice *dev,
714 phy_interface_t interface_type)
718 bool eth_clk_sel_reg = false;
719 bool eth_ref_clk_sel_reg = false;
721 /* Gigabit Ethernet 125MHz clock selection. */
722 eth_clk_sel_reg = dev_read_bool(dev, "st,eth_clk_sel");
724 /* Ethernet 50Mhz RMII clock selection */
725 eth_ref_clk_sel_reg =
726 dev_read_bool(dev, "st,eth_ref_clk_sel");
728 syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG);
733 switch (interface_type) {
734 case PHY_INTERFACE_MODE_MII:
735 value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII |
736 SYSCFG_PMCSETR_ETH_REF_CLK_SEL;
737 debug("%s: PHY_INTERFACE_MODE_MII\n", __func__);
739 case PHY_INTERFACE_MODE_GMII:
741 value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII |
742 SYSCFG_PMCSETR_ETH_CLK_SEL;
744 value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII;
745 debug("%s: PHY_INTERFACE_MODE_GMII\n", __func__);
747 case PHY_INTERFACE_MODE_RMII:
748 if (eth_ref_clk_sel_reg)
749 value = SYSCFG_PMCSETR_ETH_SEL_RMII |
750 SYSCFG_PMCSETR_ETH_REF_CLK_SEL;
752 value = SYSCFG_PMCSETR_ETH_SEL_RMII;
753 debug("%s: PHY_INTERFACE_MODE_RMII\n", __func__);
755 case PHY_INTERFACE_MODE_RGMII:
756 case PHY_INTERFACE_MODE_RGMII_ID:
757 case PHY_INTERFACE_MODE_RGMII_RXID:
758 case PHY_INTERFACE_MODE_RGMII_TXID:
760 value = SYSCFG_PMCSETR_ETH_SEL_RGMII |
761 SYSCFG_PMCSETR_ETH_CLK_SEL;
763 value = SYSCFG_PMCSETR_ETH_SEL_RGMII;
764 debug("%s: PHY_INTERFACE_MODE_RGMII\n", __func__);
767 debug("%s: Do not manage %d interface\n",
768 __func__, interface_type);
769 /* Do not manage others interfaces */
773 /* clear and set ETH configuration bits */
774 writel(SYSCFG_PMCSETR_ETH_SEL_MASK | SYSCFG_PMCSETR_ETH_SELMII |
775 SYSCFG_PMCSETR_ETH_REF_CLK_SEL | SYSCFG_PMCSETR_ETH_CLK_SEL,
776 syscfg + SYSCFG_PMCCLRR);
777 writel(value, syscfg + SYSCFG_PMCSETR);
782 enum env_location env_get_location(enum env_operation op, int prio)
784 u32 bootmode = get_bootmode();
789 switch (bootmode & TAMP_BOOT_DEVICE_MASK) {
790 #ifdef CONFIG_ENV_IS_IN_EXT4
792 case BOOT_FLASH_EMMC:
795 #ifdef CONFIG_ENV_IS_IN_UBI
796 case BOOT_FLASH_NAND:
799 #ifdef CONFIG_ENV_IS_IN_SPI_FLASH
801 return ENVL_SPI_FLASH;
808 #if defined(CONFIG_ENV_IS_IN_EXT4)
809 const char *env_ext4_get_intf(void)
811 u32 bootmode = get_bootmode();
813 switch (bootmode & TAMP_BOOT_DEVICE_MASK) {
815 case BOOT_FLASH_EMMC:
822 const char *env_ext4_get_dev_part(void)
824 static char *const dev_part[] = {"0:auto", "1:auto", "2:auto"};
825 u32 bootmode = get_bootmode();
827 return dev_part[(bootmode & TAMP_BOOT_INSTANCE_MASK) - 1];
831 #ifdef CONFIG_SYS_MTDPARTS_RUNTIME
833 #define MTDPARTS_LEN 256
834 #define MTDIDS_LEN 128
837 * The mtdparts_nand0 and mtdparts_nor0 variable tends to be long.
838 * If we need to access it before the env is relocated, then we need
839 * to use our own stack buffer. gd->env_buf will be too small.
841 * @param buf temporary buffer pointer MTDPARTS_LEN long
842 * @return mtdparts variable string, NULL if not found
844 static const char *env_get_mtdparts(const char *str, char *buf)
846 if (gd->flags & GD_FLG_ENV_READY)
848 if (env_get_f(str, buf, MTDPARTS_LEN) != -1)
855 * update the variables "mtdids" and "mtdparts" with content of mtdparts_<dev>
857 static void board_get_mtdparts(const char *dev,
861 char env_name[32] = "mtdparts_";
862 char tmp_mtdparts[MTDPARTS_LEN];
865 /* name of env variable to read = mtdparts_<dev> */
866 strcat(env_name, dev);
867 tmp = env_get_mtdparts(env_name, tmp_mtdparts);
869 /* mtdids: "<dev>=<dev>, ...." */
870 if (mtdids[0] != '\0')
876 /* mtdparts: "mtdparts=<dev>:<mtdparts_<dev>>;..." */
877 if (mtdparts[0] != '\0')
878 strncat(mtdparts, ";", MTDPARTS_LEN);
880 strcat(mtdparts, "mtdparts=");
881 strncat(mtdparts, dev, MTDPARTS_LEN);
882 strncat(mtdparts, ":", MTDPARTS_LEN);
883 strncat(mtdparts, tmp, MTDPARTS_LEN);
887 void board_mtdparts_default(const char **mtdids, const char **mtdparts)
889 struct mtd_info *mtd;
891 static char parts[3 * MTDPARTS_LEN + 1];
892 static char ids[MTDIDS_LEN + 1];
893 static bool mtd_initialized;
895 if (mtd_initialized) {
901 memset(parts, 0, sizeof(parts));
902 memset(ids, 0, sizeof(ids));
904 /* probe all MTD devices */
905 for (uclass_first_device(UCLASS_MTD, &dev);
907 uclass_next_device(&dev)) {
908 pr_debug("mtd device = %s\n", dev->name);
911 mtd = get_mtd_device_nm("nand0");
912 if (!IS_ERR_OR_NULL(mtd)) {
913 board_get_mtdparts("nand0", ids, parts);
917 mtd = get_mtd_device_nm("spi-nand0");
918 if (!IS_ERR_OR_NULL(mtd)) {
919 board_get_mtdparts("spi-nand0", ids, parts);
923 if (!uclass_get_device(UCLASS_SPI_FLASH, 0, &dev))
924 board_get_mtdparts("nor0", ids, parts);
926 mtd_initialized = true;
929 debug("%s:mtdids=%s & mtdparts=%s\n", __func__, ids, parts);
933 #if defined(CONFIG_OF_BOARD_SETUP)
934 int ft_board_setup(void *blob, bd_t *bd)
936 #ifdef CONFIG_FDT_FIXUP_PARTITIONS
937 struct node_info nodes[] = {
938 { "st,stm32f469-qspi", MTD_DEV_TYPE_NOR, },
939 { "st,stm32mp15-fmc2", MTD_DEV_TYPE_NAND, },
941 fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
948 #ifdef CONFIG_SET_DFU_ALT_INFO
949 #define DFU_ALT_BUF_LEN SZ_1K
951 static void board_get_alt_info(const char *dev, char *buff)
953 char var_name[32] = "dfu_alt_info_";
956 ALLOC_CACHE_ALIGN_BUFFER(char, tmp_alt, DFU_ALT_BUF_LEN);
958 /* name of env variable to read = dfu_alt_info_<dev> */
959 strcat(var_name, dev);
960 ret = env_get_f(var_name, tmp_alt, DFU_ALT_BUF_LEN);
964 strncat(buff, tmp_alt, DFU_ALT_BUF_LEN);
968 void set_dfu_alt_info(char *interface, char *devstr)
971 struct mtd_info *mtd;
973 ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
975 if (env_get("dfu_alt_info"))
978 memset(buf, 0, sizeof(buf));
980 /* probe all MTD devices */
983 board_get_alt_info("ram", buf);
985 if (!uclass_get_device(UCLASS_MMC, 0, &dev))
986 board_get_alt_info("mmc0", buf);
988 if (!uclass_get_device(UCLASS_MMC, 1, &dev))
989 board_get_alt_info("mmc1", buf);
991 if (!uclass_get_device(UCLASS_SPI_FLASH, 0, &dev))
992 board_get_alt_info("nor0", buf);
994 mtd = get_mtd_device_nm("nand0");
995 if (!IS_ERR_OR_NULL(mtd))
996 board_get_alt_info("nand0", buf);
998 mtd = get_mtd_device_nm("spi-nand0");
999 if (!IS_ERR_OR_NULL(mtd))
1000 board_get_alt_info("spi-nand0", buf);
1002 #ifdef CONFIG_DFU_VIRT
1003 strncat(buf, "&virt 0=OTP", DFU_ALT_BUF_LEN);
1005 if (IS_ENABLED(CONFIG_PMIC_STPMIC1))
1006 strncat(buf, "&virt 1=PMIC", DFU_ALT_BUF_LEN);
1009 env_set("dfu_alt_info", buf);
1010 puts("DFU alt info setting: done\n");
1013 #if CONFIG_IS_ENABLED(DFU_VIRT)
1015 #include <power/stpmic1.h>
1017 static int dfu_otp_read(u64 offset, u8 *buffer, long *size)
1019 struct udevice *dev;
1022 ret = uclass_get_device_by_driver(UCLASS_MISC,
1023 DM_GET_DRIVER(stm32mp_bsec),
1028 ret = misc_read(dev, offset + STM32_BSEC_OTP_OFFSET, buffer, *size);
1037 static int dfu_pmic_read(u64 offset, u8 *buffer, long *size)
1040 #ifdef CONFIG_PMIC_STPMIC1
1041 struct udevice *dev;
1043 ret = uclass_get_device_by_driver(UCLASS_MISC,
1044 DM_GET_DRIVER(stpmic1_nvm),
1049 ret = misc_read(dev, 0xF8 + offset, buffer, *size);
1054 if (ret == -EACCES) {
1059 pr_err("PMIC update not supported");
1066 int dfu_read_medium_virt(struct dfu_entity *dfu, u64 offset,
1067 void *buf, long *len)
1069 switch (dfu->data.virt.dev_num) {
1071 return dfu_otp_read(offset, buf, len);
1073 return dfu_pmic_read(offset, buf, len);
1079 int __weak dfu_get_medium_size_virt(struct dfu_entity *dfu, u64 *size)
1090 static void board_copro_image_process(ulong fw_image, size_t fw_size)
1092 int ret, id = 0; /* Copro id fixed to 0 as only one coproc on mp1 */
1094 if (!rproc_is_initialized())
1096 printf("Remote Processor %d initialization failed\n",
1101 ret = rproc_load(id, fw_image, fw_size);
1102 printf("Load Remote Processor %d with data@addr=0x%08lx %u bytes:%s\n",
1103 id, fw_image, fw_size, ret ? " Failed!" : " Success!");
1109 U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_COPRO, board_copro_image_process);