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 ret = uclass_get_device_by_driver(UCLASS_MISC,
108 DM_GET_DRIVER(stm32mp_bsec),
112 ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_BOARD),
114 if (ret > 0 && otp) {
115 printf("Board: MB%04x Var%d Rev.%c-%02d\n",
118 ((otp >> 8) & 0xF) - 1 + 'A',
125 static void board_key_check(void)
127 #if defined(CONFIG_FASTBOOT) || defined(CONFIG_CMD_STM32PROG)
129 struct gpio_desc gpio;
130 enum forced_boot_mode boot_mode = BOOT_NORMAL;
132 node = ofnode_path("/config");
133 if (!ofnode_valid(node)) {
134 debug("%s: no /config node?\n", __func__);
137 #ifdef CONFIG_FASTBOOT
138 if (gpio_request_by_name_nodev(node, "st,fastboot-gpios", 0,
139 &gpio, GPIOD_IS_IN)) {
140 debug("%s: could not find a /config/st,fastboot-gpios\n",
143 if (dm_gpio_get_value(&gpio)) {
144 puts("Fastboot key pressed, ");
145 boot_mode = BOOT_FASTBOOT;
148 dm_gpio_free(NULL, &gpio);
151 #ifdef CONFIG_CMD_STM32PROG
152 if (gpio_request_by_name_nodev(node, "st,stm32prog-gpios", 0,
153 &gpio, GPIOD_IS_IN)) {
154 debug("%s: could not find a /config/st,stm32prog-gpios\n",
157 if (dm_gpio_get_value(&gpio)) {
158 puts("STM32Programmer key pressed, ");
159 boot_mode = BOOT_STM32PROG;
161 dm_gpio_free(NULL, &gpio);
165 if (boot_mode != BOOT_NORMAL) {
166 puts("entering download mode...\n");
167 clrsetbits_le32(TAMP_BOOT_CONTEXT,
168 TAMP_BOOT_FORCED_MASK,
174 #if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG)
176 /* STMicroelectronics STUSB1600 Type-C controller */
177 #define STUSB1600_CC_CONNECTION_STATUS 0x0E
179 /* STUSB1600_CC_CONNECTION_STATUS bitfields */
180 #define STUSB1600_CC_ATTACH BIT(0)
182 static int stusb1600_init(struct udevice **dev_stusb1600)
185 struct udevice *dev, *bus;
189 *dev_stusb1600 = NULL;
191 /* if node stusb1600 is present, means DK1 or DK2 board */
192 node = ofnode_by_compatible(ofnode_null(), "st,stusb1600");
193 if (!ofnode_valid(node))
196 ret = ofnode_read_u32(node, "reg", &chip_addr);
200 ret = uclass_get_device_by_ofnode(UCLASS_I2C, ofnode_get_parent(node),
203 printf("bus for stusb1600 not found\n");
207 ret = dm_i2c_probe(bus, chip_addr, 0, &dev);
209 *dev_stusb1600 = dev;
214 static int stusb1600_cable_connected(struct udevice *dev)
218 if (dm_i2c_read(dev, STUSB1600_CC_CONNECTION_STATUS, &status, 1))
221 return status & STUSB1600_CC_ATTACH;
224 #include <usb/dwc2_udc.h>
225 int g_dnl_board_usb_cable_connected(void)
227 struct udevice *stusb1600;
228 struct udevice *dwc2_udc_otg;
231 if (!stusb1600_init(&stusb1600))
232 return stusb1600_cable_connected(stusb1600);
234 ret = uclass_get_device_by_driver(UCLASS_USB_GADGET_GENERIC,
235 DM_GET_DRIVER(dwc2_udc_otg),
238 debug("dwc2_udc_otg init failed\n");
240 return dwc2_udc_B_session_valid(dwc2_udc_otg);
243 #define STM32MP1_G_DNL_DFU_PRODUCT_NUM 0xdf11
244 #define STM32MP1_G_DNL_FASTBOOT_PRODUCT_NUM 0x0afb
246 int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name)
248 if (!strcmp(name, "usb_dnl_dfu"))
249 put_unaligned(STM32MP1_G_DNL_DFU_PRODUCT_NUM, &dev->idProduct);
250 else if (!strcmp(name, "usb_dnl_fastboot"))
251 put_unaligned(STM32MP1_G_DNL_FASTBOOT_PRODUCT_NUM,
254 put_unaligned(CONFIG_USB_GADGET_PRODUCT_NUM, &dev->idProduct);
259 #endif /* CONFIG_USB_GADGET */
262 static int get_led(struct udevice **dev, char *led_string)
267 led_name = fdtdec_get_config_string(gd->fdt_blob, led_string);
269 pr_debug("%s: could not find %s config string\n",
270 __func__, led_string);
273 ret = led_get_by_label(led_name, dev);
275 debug("%s: get=%d\n", __func__, ret);
282 static int setup_led(enum led_state_t cmd)
287 ret = get_led(&dev, "u-boot,boot-led");
291 ret = led_set_state(dev, cmd);
296 static void __maybe_unused led_error_blink(u32 nb_blink)
308 ret = get_led(&led, "u-boot,error-led");
310 /* make u-boot,error-led blinking */
311 /* if U32_MAX and 125ms interval, for 17.02 years */
312 for (i = 0; i < 2 * nb_blink; i++) {
313 led_set_state(led, LEDST_TOGGLE);
320 /* infinite: the boot process must be stopped */
321 if (nb_blink == U32_MAX)
326 static int board_check_usb_power(void)
328 struct ofnode_phandle_args adc_args;
333 int min_uV = USB_START_HIGH_THRESHOLD_UV;
334 int ret, uV, adc_count;
337 node = ofnode_path("/config");
338 if (!ofnode_valid(node)) {
339 debug("%s: no /config node?\n", __func__);
344 * Retrieve the ADC channels devices and get measurement
347 adc_count = ofnode_count_phandle_with_args(node, "st,adc_usb_pd",
348 "#io-channel-cells");
350 if (adc_count == -ENOENT)
353 pr_err("%s: can't find adc channel (%d)\n", __func__,
359 for (i = 0; i < adc_count; i++) {
360 if (ofnode_parse_phandle_with_args(node, "st,adc_usb_pd",
361 "#io-channel-cells", 0, i,
363 pr_debug("%s: can't find /config/st,adc_usb_pd\n",
368 ret = uclass_get_device_by_ofnode(UCLASS_ADC, adc_args.node,
372 pr_err("%s: Can't get adc device(%d)\n", __func__,
377 ret = adc_channel_single_shot(adc->name, adc_args.args[0],
380 pr_err("%s: single shot failed for %s[%d]!\n",
381 __func__, adc->name, adc_args.args[0]);
385 if (!adc_raw_to_uV(adc, raw, &uV)) {
390 pr_debug("%s: %s[%02d] = %u, %d uV\n", __func__,
391 adc->name, adc_args.args[0], raw, uV);
393 pr_err("%s: Can't get uV value for %s[%d]\n",
394 __func__, adc->name, adc_args.args[0]);
399 * If highest value is inside 1.23 Volts and 2.10 Volts, that means
400 * board is plugged on an USB-C 3A power supply and boot process can
403 if (max_uV > USB_START_LOW_THRESHOLD_UV &&
404 max_uV <= USB_START_HIGH_THRESHOLD_UV &&
405 min_uV <= USB_LOW_THRESHOLD_UV)
408 pr_err("****************************************************\n");
411 * If highest and lowest value are either both below
412 * USB_LOW_THRESHOLD_UV or both above USB_LOW_THRESHOLD_UV, that
413 * means USB TYPE-C is in unattached mode, this is an issue, make
414 * u-boot,error-led blinking and stop boot process.
416 if ((max_uV > USB_LOW_THRESHOLD_UV &&
417 min_uV > USB_LOW_THRESHOLD_UV) ||
418 (max_uV <= USB_LOW_THRESHOLD_UV &&
419 min_uV <= USB_LOW_THRESHOLD_UV)) {
420 pr_err("* ERROR USB TYPE-C connection in unattached mode *\n");
421 pr_err("* Check that USB TYPE-C cable is correctly plugged *\n");
422 /* with 125ms interval, led will blink for 17.02 years ....*/
426 if (max_uV > USB_LOW_THRESHOLD_UV &&
427 max_uV <= USB_WARNING_LOW_THRESHOLD_UV &&
428 min_uV <= USB_LOW_THRESHOLD_UV) {
429 pr_err("* WARNING 500mA power supply detected *\n");
433 if (max_uV > USB_WARNING_LOW_THRESHOLD_UV &&
434 max_uV <= USB_START_LOW_THRESHOLD_UV &&
435 min_uV <= USB_LOW_THRESHOLD_UV) {
436 pr_err("* WARNING 1.5mA power supply detected *\n");
441 * If highest value is above 2.15 Volts that means that the USB TypeC
442 * supplies more than 3 Amp, this is not compliant with TypeC specification
444 if (max_uV > USB_START_HIGH_THRESHOLD_UV) {
445 pr_err("* USB TYPE-C charger not compliant with *\n");
446 pr_err("* specification *\n");
447 pr_err("****************************************************\n\n");
448 /* with 125ms interval, led will blink for 17.02 years ....*/
451 pr_err("* Current too low, use a 3A power supply! *\n");
452 pr_err("****************************************************\n\n");
455 led_error_blink(nb_blink);
459 #endif /* CONFIG_ADC */
461 static void sysconf_init(void)
463 #ifndef CONFIG_STM32MP1_TRUSTED
465 #ifdef CONFIG_DM_REGULATOR
466 struct udevice *pwr_dev;
467 struct udevice *pwr_reg;
474 syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG);
476 /* interconnect update : select master using the port 1 */
479 /* today information is hardcoded in U-Boot */
480 writel(BIT(9), syscfg + SYSCFG_ICNR);
482 /* disable Pull-Down for boot pin connected to VDD */
483 bootr = readl(syscfg + SYSCFG_BOOTR);
484 bootr &= ~(SYSCFG_BOOTR_BOOT_MASK << SYSCFG_BOOTR_BOOTPD_SHIFT);
485 bootr |= (bootr & SYSCFG_BOOTR_BOOT_MASK) << SYSCFG_BOOTR_BOOTPD_SHIFT;
486 writel(bootr, syscfg + SYSCFG_BOOTR);
488 #ifdef CONFIG_DM_REGULATOR
489 /* High Speed Low Voltage Pad mode Enable for SPI, SDMMC, ETH, QSPI
490 * and TRACE. Needed above ~50MHz and conditioned by AFMUX selection.
491 * The customer will have to disable this for low frequencies
492 * or if AFMUX is selected but the function not used, typically for
493 * TRACE. Otherwise, impact on power consumption.
496 * enabling High Speed mode while VDD>2.7V
497 * with the OTP product_below_2v5 (OTP 18, BIT 13)
498 * erroneously set to 1 can damage the IC!
499 * => U-Boot set the register only if VDD < 2.7V (in DT)
500 * but this value need to be consistent with board design
502 ret = uclass_get_device_by_driver(UCLASS_PMIC,
503 DM_GET_DRIVER(stm32mp_pwr_pmic),
506 ret = uclass_get_device_by_driver(UCLASS_MISC,
507 DM_GET_DRIVER(stm32mp_bsec),
510 pr_err("Can't find stm32mp_bsec driver\n");
514 ret = misc_read(dev, STM32_BSEC_SHADOW(18), &otp, 4);
518 /* get VDD = vdd-supply */
519 ret = device_get_supply_regulator(pwr_dev, "vdd-supply",
522 /* check if VDD is Low Voltage */
524 if (regulator_get_value(pwr_reg) < 2700000) {
525 writel(SYSCFG_IOCTRLSETR_HSLVEN_TRACE |
526 SYSCFG_IOCTRLSETR_HSLVEN_QUADSPI |
527 SYSCFG_IOCTRLSETR_HSLVEN_ETH |
528 SYSCFG_IOCTRLSETR_HSLVEN_SDMMC |
529 SYSCFG_IOCTRLSETR_HSLVEN_SPI,
530 syscfg + SYSCFG_IOCTRLSETR);
533 pr_err("product_below_2v5=0: HSLVEN protected by HW\n");
536 pr_err("product_below_2v5=1: HSLVEN update is destructive, no update as VDD>2.7V\n");
539 debug("VDD unknown");
544 /* activate automatic I/O compensation
545 * warning: need to ensure CSI enabled and ready in clock driver
547 writel(SYSCFG_CMPENSETR_MPU_EN, syscfg + SYSCFG_CMPENSETR);
549 while (!(readl(syscfg + SYSCFG_CMPCR) & SYSCFG_CMPCR_READY))
551 clrbits_le32(syscfg + SYSCFG_CMPCR, SYSCFG_CMPCR_SW_CTRL);
555 #ifdef CONFIG_DM_REGULATOR
556 /* Fix to make I2C1 usable on DK2 for touchscreen usage in kernel */
557 static int dk2_i2c1_fix(void)
560 struct gpio_desc hdmi, audio;
563 node = ofnode_path("/soc/i2c@40012000/hdmi-transmitter@39");
564 if (!ofnode_valid(node)) {
565 pr_debug("%s: no hdmi-transmitter@39 ?\n", __func__);
569 if (gpio_request_by_name_nodev(node, "reset-gpios", 0,
570 &hdmi, GPIOD_IS_OUT)) {
571 pr_debug("%s: could not find reset-gpios\n",
576 node = ofnode_path("/soc/i2c@40012000/cs42l51@4a");
577 if (!ofnode_valid(node)) {
578 pr_debug("%s: no cs42l51@4a ?\n", __func__);
582 if (gpio_request_by_name_nodev(node, "reset-gpios", 0,
583 &audio, GPIOD_IS_OUT)) {
584 pr_debug("%s: could not find reset-gpios\n",
589 /* before power up, insure that HDMI and AUDIO IC is under reset */
590 ret = dm_gpio_set_value(&hdmi, 1);
592 pr_err("%s: can't set_value for hdmi_nrst gpio", __func__);
595 ret = dm_gpio_set_value(&audio, 1);
597 pr_err("%s: can't set_value for audio_nrst gpio", __func__);
601 /* power-up audio IC */
602 regulator_autoset_by_name("v1v8_audio", NULL);
604 /* power-up HDMI IC */
605 regulator_autoset_by_name("v1v2_hdmi", NULL);
606 regulator_autoset_by_name("v3v3_hdmi", NULL);
612 static bool board_is_dk2(void)
614 if (CONFIG_IS_ENABLED(TARGET_ST_STM32MP15x) &&
615 of_machine_is_compatible("st,stm32mp157c-dk2"))
622 /* board dependent setup after realloc */
627 /* address of boot parameters */
628 gd->bd->bi_boot_params = STM32_DDR_BASE + 0x100;
630 /* probe all PINCTRL for hog */
631 for (uclass_first_device(UCLASS_PINCTRL, &dev);
633 uclass_next_device(&dev)) {
634 pr_debug("probe pincontrol = %s\n", dev->name);
639 #ifdef CONFIG_DM_REGULATOR
643 regulators_enable_boot_on(_DEBUG);
648 if (CONFIG_IS_ENABLED(CONFIG_LED))
654 int board_late_init(void)
657 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
658 const void *fdt_compat;
665 fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",
667 if (fdt_compat && fdt_compat_len) {
668 if (strncmp(fdt_compat, "st,", 3) != 0)
669 env_set("board_name", fdt_compat);
671 env_set("board_name", fdt_compat + 3);
673 ret = uclass_get_device_by_driver(UCLASS_MISC,
674 DM_GET_DRIVER(stm32mp_bsec),
678 ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_BOARD),
681 snprintf(buf, sizeof(buf), "0x%04x", otp >> 16);
682 env_set("board_id", buf);
684 snprintf(buf, sizeof(buf), "0x%04x",
685 ((otp >> 8) & 0xF) - 1 + 0xA);
686 env_set("board_rev", buf);
691 /* for DK1/DK2 boards */
692 board_check_usb_power();
693 #endif /* CONFIG_ADC */
695 /* Check the boot-source to disable bootdelay */
696 boot_device = env_get("boot_device");
697 if (!strcmp(boot_device, "serial") || !strcmp(boot_device, "usb"))
698 env_set("bootdelay", "0");
703 void board_quiesce_devices(void)
706 setup_led(LEDST_OFF);
710 /* eth init function : weak called in eqos driver */
711 int board_interface_eth_init(struct udevice *dev,
712 phy_interface_t interface_type)
716 bool eth_clk_sel_reg = false;
717 bool eth_ref_clk_sel_reg = false;
719 /* Gigabit Ethernet 125MHz clock selection. */
720 eth_clk_sel_reg = dev_read_bool(dev, "st,eth_clk_sel");
722 /* Ethernet 50Mhz RMII clock selection */
723 eth_ref_clk_sel_reg =
724 dev_read_bool(dev, "st,eth_ref_clk_sel");
726 syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG);
731 switch (interface_type) {
732 case PHY_INTERFACE_MODE_MII:
733 value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII |
734 SYSCFG_PMCSETR_ETH_REF_CLK_SEL;
735 debug("%s: PHY_INTERFACE_MODE_MII\n", __func__);
737 case PHY_INTERFACE_MODE_GMII:
739 value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII |
740 SYSCFG_PMCSETR_ETH_CLK_SEL;
742 value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII;
743 debug("%s: PHY_INTERFACE_MODE_GMII\n", __func__);
745 case PHY_INTERFACE_MODE_RMII:
746 if (eth_ref_clk_sel_reg)
747 value = SYSCFG_PMCSETR_ETH_SEL_RMII |
748 SYSCFG_PMCSETR_ETH_REF_CLK_SEL;
750 value = SYSCFG_PMCSETR_ETH_SEL_RMII;
751 debug("%s: PHY_INTERFACE_MODE_RMII\n", __func__);
753 case PHY_INTERFACE_MODE_RGMII:
754 case PHY_INTERFACE_MODE_RGMII_ID:
755 case PHY_INTERFACE_MODE_RGMII_RXID:
756 case PHY_INTERFACE_MODE_RGMII_TXID:
758 value = SYSCFG_PMCSETR_ETH_SEL_RGMII |
759 SYSCFG_PMCSETR_ETH_CLK_SEL;
761 value = SYSCFG_PMCSETR_ETH_SEL_RGMII;
762 debug("%s: PHY_INTERFACE_MODE_RGMII\n", __func__);
765 debug("%s: Do not manage %d interface\n",
766 __func__, interface_type);
767 /* Do not manage others interfaces */
771 /* clear and set ETH configuration bits */
772 writel(SYSCFG_PMCSETR_ETH_SEL_MASK | SYSCFG_PMCSETR_ETH_SELMII |
773 SYSCFG_PMCSETR_ETH_REF_CLK_SEL | SYSCFG_PMCSETR_ETH_CLK_SEL,
774 syscfg + SYSCFG_PMCCLRR);
775 writel(value, syscfg + SYSCFG_PMCSETR);
780 enum env_location env_get_location(enum env_operation op, int prio)
782 u32 bootmode = get_bootmode();
787 switch (bootmode & TAMP_BOOT_DEVICE_MASK) {
788 #ifdef CONFIG_ENV_IS_IN_EXT4
790 case BOOT_FLASH_EMMC:
793 #ifdef CONFIG_ENV_IS_IN_UBI
794 case BOOT_FLASH_NAND:
797 #ifdef CONFIG_ENV_IS_IN_SPI_FLASH
799 return ENVL_SPI_FLASH;
806 #if defined(CONFIG_ENV_IS_IN_EXT4)
807 const char *env_ext4_get_intf(void)
809 u32 bootmode = get_bootmode();
811 switch (bootmode & TAMP_BOOT_DEVICE_MASK) {
813 case BOOT_FLASH_EMMC:
820 const char *env_ext4_get_dev_part(void)
822 static char *const dev_part[] = {"0:auto", "1:auto", "2:auto"};
823 u32 bootmode = get_bootmode();
825 return dev_part[(bootmode & TAMP_BOOT_INSTANCE_MASK) - 1];
829 #ifdef CONFIG_SYS_MTDPARTS_RUNTIME
831 #define MTDPARTS_LEN 256
832 #define MTDIDS_LEN 128
835 * The mtdparts_nand0 and mtdparts_nor0 variable tends to be long.
836 * If we need to access it before the env is relocated, then we need
837 * to use our own stack buffer. gd->env_buf will be too small.
839 * @param buf temporary buffer pointer MTDPARTS_LEN long
840 * @return mtdparts variable string, NULL if not found
842 static const char *env_get_mtdparts(const char *str, char *buf)
844 if (gd->flags & GD_FLG_ENV_READY)
846 if (env_get_f(str, buf, MTDPARTS_LEN) != -1)
853 * update the variables "mtdids" and "mtdparts" with content of mtdparts_<dev>
855 static void board_get_mtdparts(const char *dev,
859 char env_name[32] = "mtdparts_";
860 char tmp_mtdparts[MTDPARTS_LEN];
863 /* name of env variable to read = mtdparts_<dev> */
864 strcat(env_name, dev);
865 tmp = env_get_mtdparts(env_name, tmp_mtdparts);
867 /* mtdids: "<dev>=<dev>, ...." */
868 if (mtdids[0] != '\0')
874 /* mtdparts: "mtdparts=<dev>:<mtdparts_<dev>>;..." */
875 if (mtdparts[0] != '\0')
876 strncat(mtdparts, ";", MTDPARTS_LEN);
878 strcat(mtdparts, "mtdparts=");
879 strncat(mtdparts, dev, MTDPARTS_LEN);
880 strncat(mtdparts, ":", MTDPARTS_LEN);
881 strncat(mtdparts, tmp, MTDPARTS_LEN);
885 void board_mtdparts_default(const char **mtdids, const char **mtdparts)
887 struct mtd_info *mtd;
889 static char parts[3 * MTDPARTS_LEN + 1];
890 static char ids[MTDIDS_LEN + 1];
891 static bool mtd_initialized;
893 if (mtd_initialized) {
899 memset(parts, 0, sizeof(parts));
900 memset(ids, 0, sizeof(ids));
902 /* probe all MTD devices */
903 for (uclass_first_device(UCLASS_MTD, &dev);
905 uclass_next_device(&dev)) {
906 pr_debug("mtd device = %s\n", dev->name);
909 mtd = get_mtd_device_nm("nand0");
910 if (!IS_ERR_OR_NULL(mtd)) {
911 board_get_mtdparts("nand0", ids, parts);
915 mtd = get_mtd_device_nm("spi-nand0");
916 if (!IS_ERR_OR_NULL(mtd)) {
917 board_get_mtdparts("spi-nand0", ids, parts);
921 if (!uclass_get_device(UCLASS_SPI_FLASH, 0, &dev))
922 board_get_mtdparts("nor0", ids, parts);
924 mtd_initialized = true;
927 debug("%s:mtdids=%s & mtdparts=%s\n", __func__, ids, parts);
931 #if defined(CONFIG_OF_BOARD_SETUP)
932 int ft_board_setup(void *blob, bd_t *bd)
934 #ifdef CONFIG_FDT_FIXUP_PARTITIONS
935 struct node_info nodes[] = {
936 { "st,stm32f469-qspi", MTD_DEV_TYPE_NOR, },
937 { "st,stm32mp15-fmc2", MTD_DEV_TYPE_NAND, },
939 fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
946 #ifdef CONFIG_SET_DFU_ALT_INFO
947 #define DFU_ALT_BUF_LEN SZ_1K
949 static void board_get_alt_info(const char *dev, char *buff)
951 char var_name[32] = "dfu_alt_info_";
954 ALLOC_CACHE_ALIGN_BUFFER(char, tmp_alt, DFU_ALT_BUF_LEN);
956 /* name of env variable to read = dfu_alt_info_<dev> */
957 strcat(var_name, dev);
958 ret = env_get_f(var_name, tmp_alt, DFU_ALT_BUF_LEN);
962 strncat(buff, tmp_alt, DFU_ALT_BUF_LEN);
966 void set_dfu_alt_info(char *interface, char *devstr)
969 struct mtd_info *mtd;
971 ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
973 if (env_get("dfu_alt_info"))
976 memset(buf, 0, sizeof(buf));
978 /* probe all MTD devices */
981 board_get_alt_info("ram", buf);
983 if (!uclass_get_device(UCLASS_MMC, 0, &dev))
984 board_get_alt_info("mmc0", buf);
986 if (!uclass_get_device(UCLASS_MMC, 1, &dev))
987 board_get_alt_info("mmc1", buf);
989 if (!uclass_get_device(UCLASS_SPI_FLASH, 0, &dev))
990 board_get_alt_info("nor0", buf);
992 mtd = get_mtd_device_nm("nand0");
993 if (!IS_ERR_OR_NULL(mtd))
994 board_get_alt_info("nand0", buf);
996 mtd = get_mtd_device_nm("spi-nand0");
997 if (!IS_ERR_OR_NULL(mtd))
998 board_get_alt_info("spi-nand0", buf);
1000 #ifdef CONFIG_DFU_VIRT
1001 strncat(buf, "&virt 0=OTP", DFU_ALT_BUF_LEN);
1003 if (IS_ENABLED(CONFIG_PMIC_STPMIC1))
1004 strncat(buf, "&virt 1=PMIC", DFU_ALT_BUF_LEN);
1007 env_set("dfu_alt_info", buf);
1008 puts("DFU alt info setting: done\n");
1011 #if CONFIG_IS_ENABLED(DFU_VIRT)
1013 #include <power/stpmic1.h>
1015 int dfu_otp_read(u64 offset, u8 *buffer, long *size)
1017 struct udevice *dev;
1020 ret = uclass_get_device_by_driver(UCLASS_MISC,
1021 DM_GET_DRIVER(stm32mp_bsec),
1026 ret = misc_read(dev, offset + STM32_BSEC_OTP_OFFSET, buffer, *size);
1035 int dfu_pmic_read(u64 offset, u8 *buffer, long *size)
1038 #ifdef CONFIG_PMIC_STPMIC1
1039 struct udevice *dev;
1041 ret = uclass_get_device_by_driver(UCLASS_MISC,
1042 DM_GET_DRIVER(stpmic1_nvm),
1047 ret = misc_read(dev, 0xF8 + offset, buffer, *size);
1052 if (ret == -EACCES) {
1057 pr_err("PMIC update not supported");
1064 int dfu_read_medium_virt(struct dfu_entity *dfu, u64 offset,
1065 void *buf, long *len)
1067 switch (dfu->data.virt.dev_num) {
1069 return dfu_otp_read(offset, buf, len);
1071 return dfu_pmic_read(offset, buf, len);
1077 int __weak dfu_get_medium_size_virt(struct dfu_entity *dfu, u64 *size)
1088 static void board_copro_image_process(ulong fw_image, size_t fw_size)
1090 int ret, id = 0; /* Copro id fixed to 0 as only one coproc on mp1 */
1092 if (!rproc_is_initialized())
1094 printf("Remote Processor %d initialization failed\n",
1099 ret = rproc_load(id, fw_image, fw_size);
1100 printf("Load Remote Processor %d with data@addr=0x%08lx %u bytes:%s\n",
1101 id, fw_image, fw_size, ret ? " Failed!" : " Success!");
1107 U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_COPRO, board_copro_image_process);