I need to add some new features to u-boot like pressing specified button to setup my device using blinking LED as a device response. The problem is that I don't where u-boot starts to execute C code. What file should I modify?
I use STM32F429I-Discovery for testing and have already installed everything I need to run kernel using buildroot. One of the LEDs (GPIO_13) is constantly blinking, so, I tried searching for the code that provides such functionality. It looks like led.c and gpio_led.c must do the thing but changing them gives nothing.
Update.
Well, I was trying to dig into triggers but it looks like modifying .dts file doesn't have impact on LED blinking. Commenting code in the corresponding heartbeat-trigger turns off the LED, however, there is no GPIO choice, so, I cannot change the green LED to the red one. After moving "linux,default-trigger" to GPIO14 in the .dts file I recompile u-boot and linux with buildroot but nothing changes. Here are my changes (I took some code from stm32f746-disco.c):
stm32f429-disco.dts
/dts-v1/;
#include "stm32f429.dtsi"
#include "stm32f429-pinctrl.dtsi"
#include <dt-bindings/input/input.h>
/ {
model = "STMicroelectronics STM32F429i-DISCO board";
compatible = "st,stm32f429i-disco", "st,stm32f429";
chosen {
bootargs = "root=/dev/ram";
stdout-path = "serial0:115200n8";
};
memory {
reg = <0x90000000 0x800000>;
};
aliases {
serial0 = &usart1;
};
leds {
compatible = "st,leds";
red {
gpios = <&gpiog 14 0>;
linux,default-trigger = "heartbeat";
};
green {
gpios = <&gpiog 13 0>;
};
};
gpio_keys {
compatible = "gpio-keys";
#address-cells = <1>;
#size-cells = <0>;
autorepeat;
button@0 {
label = "User";
linux,code = <KEY_HOME>;
gpios = <&gpioa 0 0>;
};
};
/* This turns on vbus for otg for host mode (dwc2) */
vcc5v_otg: vcc5v-otg-regulator {
compatible = "regulator-fixed";
gpio = <&gpioc 4 0>;
regulator-name = "vcc5_host1";
regulator-always-on;
};
};
&clk_hse {
clock-frequency = <8000000>;
};
stm32f429-discovery.c
#include <common.h>
#include <dm.h>
#include <ram.h>
#include <spl.h>
#include <asm/io.h>
#include <asm/armv7m.h>
#include <asm/arch/stm32.h>
#include <asm/arch/gpio.h>
#include <asm/arch/stm32_periph.h>
#include <asm/arch/stm32_defs.h>
#include <asm/gpio.h>
DECLARE_GLOBAL_DATA_PTR;
int dram_init(void)
{
int rv;
struct udevice *dev;
rv = uclass_get_device(UCLASS_RAM, 0, &dev);
if (rv) {
debug("DRAM init failed: %d\n", rv);
return rv;
}
if (fdtdec_setup_memory_size() != 0)
rv = -EINVAL;
return rv;
}
int dram_init_banksize(void)
{
fdtdec_setup_memory_banksize();
return 0;
}
u32 get_board_rev(void)
{
return 0;
}
int board_early_init_f(void)
{
return 0;
}
int board_init(void)
{
gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
struct gpio_desc gpio = {};
int node, offset_node;
node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,leds");
offset_node = fdt_subnode_offset(gd->fdt_blob, node, "green");
if (node < 0)
return -1;
gpio_request_by_name_nodev(offset_to_ofnode(offset_node), "gpios", 0, &gpio, GPIOD_IS_OUT);
if (dm_gpio_is_valid(&gpio)) {
dm_gpio_set_value(&gpio, 1);
}
return 0;
}
#ifdef CONFIG_MISC_INIT_R
int misc_init_r(void)
{
char serialno[25];
uint32_t u_id_low, u_id_mid, u_id_high;
if (!env_get("serial#")) {
u_id_low = readl(&STM32_U_ID->u_id_low);
u_id_mid = readl(&STM32_U_ID->u_id_mid);
u_id_high = readl(&STM32_U_ID->u_id_high);
sprintf(serialno, "%08x%08x%08x",
u_id_high, u_id_mid, u_id_low);
env_set("serial#", serialno);
}
return 0;
}
The LEDs are defined in the device tree (U-Boot file arch/arm/dts/stm32f429-disco.dts, Linux kernel file arch/arm/boot/dts/stm32f429-disco.dts)
leds {
compatible = "gpio-leds";
red {
gpios = <&gpiog 14 0>;
};
green {
gpios = <&gpiog 13 0>;
linux,default-trigger = "heartbeat";
};
};
In Linux you can change the trigger by writing to the appropriate trigger file. This should be
/sys/class/leds/green/trigger
The U-Boot driver for GPIO is drivers/gpio/stm32_gpio.c
You can use function dm_gpio_set_value() to set a GPIO as input and dm_gpio_get_value() to read the value.
You may want to use the FASTBOOT part of board/st/stm32mp1/stm32mp1.c as a template.