mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-08 14:14:32 +00:00
84f8e36f03
Initial implementation invokes device_bind_with_driver_data() with driver_data parameter equal to 0. For driver with driver data, the bind command can't bind correctly this driver or even worse causes data abort as shown below: As example, for debug purpose on STM32MP1 platform, ethernet (dwc_eth_qos.c) driver needed to be unbinded/binded. This driver is using driver data: static const struct udevice_id eqos_ids[] = { { .compatible = "nvidia,tegra186-eqos", .data = (ulong)&eqos_tegra186_config }, { .compatible = "snps,dwmac-4.20a", .data = (ulong)&eqos_stm32_config }, { } }; After unbinding/binding this driver and probing it (with the dhcp command), we got a prefetch abort as below: STM32MP> unbind eth ethernet@5800a000 STM32MP> bind /soc/ethernet@5800a000 eth_eqos STM32MP> dhcp prefetch abort pc : [<4310801c>] lr : [<ffc8f4ad>] reloc pc : [<035ba01c>] lr : [<c01414ad>] sp : fdaf19b0 ip : ffcea83c fp : 00000001 r10: ffcfd4a0 r9 : fdaffed0 r8 : 00000000 r7 : ffcff304 r6 : fdc63220 r5 : 00000000 r4 : fdc5b108 r3 : 43108020 r2 : 00003d39 r1 : ffcea544 r0 : fdc63220 Flags: nZCv IRQs off FIQs off Mode SVC_32 Code: data abort pc : [<ffc4f9c0>] lr : [<ffc4f9ad>] reloc pc : [<c01019c0>] lr : [<c01019ad>] sp : fdaf18b8 ip : 00000000 fp : 00000001 r10: ffcd69b2 r9 : fdaffed0 r8 : ffcd69aa r7 : 00000000 r6 : 00000008 r5 : 4310801c r4 : fffffffc r3 : 00000001 r2 : 00000028 r1 : 00000000 r0 : 00000006 Flags: NzCv IRQs on FIQs on Mode SVC_32 (T) Code: 2f00 d1e9 2c00 dce9 (f855) 2024 Resetting CPU ... Signed-off-by: Patrice Chotard <patrice.chotard@st.com> Cc: Jean-Jacques Hiblot <jjhiblot@ti.com> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Simon Glass <sjg@chromium.org>
257 lines
5.2 KiB
C
257 lines
5.2 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
/*
|
|
* Copyright (c) 2018 JJ Hiblot <jjhiblot@ti.com>
|
|
*/
|
|
|
|
#include <common.h>
|
|
#include <command.h>
|
|
#include <dm.h>
|
|
#include <dm/device-internal.h>
|
|
#include <dm/lists.h>
|
|
#include <dm/root.h>
|
|
#include <dm/uclass-internal.h>
|
|
|
|
static int bind_by_class_index(const char *uclass, int index,
|
|
const char *drv_name)
|
|
{
|
|
static enum uclass_id uclass_id;
|
|
struct udevice *dev;
|
|
struct udevice *parent;
|
|
int ret;
|
|
struct driver *drv;
|
|
|
|
drv = lists_driver_lookup_name(drv_name);
|
|
if (!drv) {
|
|
printf("Cannot find driver '%s'\n", drv_name);
|
|
return -ENOENT;
|
|
}
|
|
|
|
uclass_id = uclass_get_by_name(uclass);
|
|
if (uclass_id == UCLASS_INVALID) {
|
|
printf("%s is not a valid uclass\n", uclass);
|
|
return -EINVAL;
|
|
}
|
|
|
|
ret = uclass_find_device(uclass_id, index, &parent);
|
|
if (!parent || ret) {
|
|
printf("Cannot find device %d of class %s\n", index, uclass);
|
|
return ret;
|
|
}
|
|
|
|
ret = device_bind_with_driver_data(parent, drv, drv->name, 0,
|
|
ofnode_null(), &dev);
|
|
if (!dev || ret) {
|
|
printf("Unable to bind. err:%d\n", ret);
|
|
return ret;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int find_dev(const char *uclass, int index, struct udevice **devp)
|
|
{
|
|
static enum uclass_id uclass_id;
|
|
int rc;
|
|
|
|
uclass_id = uclass_get_by_name(uclass);
|
|
if (uclass_id == UCLASS_INVALID) {
|
|
printf("%s is not a valid uclass\n", uclass);
|
|
return -EINVAL;
|
|
}
|
|
|
|
rc = uclass_find_device(uclass_id, index, devp);
|
|
if (!*devp || rc) {
|
|
printf("Cannot find device %d of class %s\n", index, uclass);
|
|
return rc;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int unbind_by_class_index(const char *uclass, int index)
|
|
{
|
|
int ret;
|
|
struct udevice *dev;
|
|
|
|
ret = find_dev(uclass, index, &dev);
|
|
if (ret)
|
|
return ret;
|
|
|
|
ret = device_remove(dev, DM_REMOVE_NORMAL);
|
|
if (ret) {
|
|
printf("Unable to remove. err:%d\n", ret);
|
|
return ret;
|
|
}
|
|
|
|
ret = device_unbind(dev);
|
|
if (ret) {
|
|
printf("Unable to unbind. err:%d\n", ret);
|
|
return ret;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int unbind_child_by_class_index(const char *uclass, int index,
|
|
const char *drv_name)
|
|
{
|
|
struct udevice *parent;
|
|
int ret;
|
|
struct driver *drv;
|
|
|
|
drv = lists_driver_lookup_name(drv_name);
|
|
if (!drv) {
|
|
printf("Cannot find driver '%s'\n", drv_name);
|
|
return -ENOENT;
|
|
}
|
|
|
|
ret = find_dev(uclass, index, &parent);
|
|
if (ret)
|
|
return ret;
|
|
|
|
ret = device_chld_remove(parent, drv, DM_REMOVE_NORMAL);
|
|
if (ret)
|
|
printf("Unable to remove all. err:%d\n", ret);
|
|
|
|
ret = device_chld_unbind(parent, drv);
|
|
if (ret)
|
|
printf("Unable to unbind all. err:%d\n", ret);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int bind_by_node_path(const char *path, const char *drv_name)
|
|
{
|
|
struct udevice *dev;
|
|
struct udevice *parent = NULL;
|
|
int ret;
|
|
ofnode ofnode;
|
|
struct driver *drv;
|
|
|
|
drv = lists_driver_lookup_name(drv_name);
|
|
if (!drv) {
|
|
printf("%s is not a valid driver name\n", drv_name);
|
|
return -ENOENT;
|
|
}
|
|
|
|
ofnode = ofnode_path(path);
|
|
if (!ofnode_valid(ofnode)) {
|
|
printf("%s is not a valid node path\n", path);
|
|
return -EINVAL;
|
|
}
|
|
|
|
while (ofnode_valid(ofnode)) {
|
|
if (!device_find_global_by_ofnode(ofnode, &parent))
|
|
break;
|
|
ofnode = ofnode_get_parent(ofnode);
|
|
}
|
|
|
|
if (!parent) {
|
|
printf("Cannot find a parent device for node path %s\n", path);
|
|
return -ENODEV;
|
|
}
|
|
|
|
ofnode = ofnode_path(path);
|
|
ret = lists_bind_fdt(parent, ofnode, &dev, false);
|
|
|
|
if (!dev || ret) {
|
|
printf("Unable to bind. err:%d\n", ret);
|
|
return ret;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int unbind_by_node_path(const char *path)
|
|
{
|
|
struct udevice *dev;
|
|
int ret;
|
|
ofnode ofnode;
|
|
|
|
ofnode = ofnode_path(path);
|
|
if (!ofnode_valid(ofnode)) {
|
|
printf("%s is not a valid node path\n", path);
|
|
return -EINVAL;
|
|
}
|
|
|
|
ret = device_find_global_by_ofnode(ofnode, &dev);
|
|
|
|
if (!dev || ret) {
|
|
printf("Cannot find a device with path %s\n", path);
|
|
return -ENODEV;
|
|
}
|
|
|
|
ret = device_remove(dev, DM_REMOVE_NORMAL);
|
|
if (ret) {
|
|
printf("Unable to remove. err:%d\n", ret);
|
|
return ret;
|
|
}
|
|
|
|
ret = device_unbind(dev);
|
|
if (ret) {
|
|
printf("Unable to unbind. err:%d\n", ret);
|
|
return ret;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int do_bind_unbind(struct cmd_tbl *cmdtp, int flag, int argc,
|
|
char *const argv[])
|
|
{
|
|
int ret = 0;
|
|
bool bind;
|
|
bool by_node;
|
|
|
|
if (argc < 2)
|
|
return CMD_RET_USAGE;
|
|
|
|
bind = (argv[0][0] == 'b');
|
|
by_node = (argv[1][0] == '/');
|
|
|
|
if (by_node && bind) {
|
|
if (argc != 3)
|
|
return CMD_RET_USAGE;
|
|
ret = bind_by_node_path(argv[1], argv[2]);
|
|
} else if (by_node && !bind) {
|
|
if (argc != 2)
|
|
return CMD_RET_USAGE;
|
|
ret = unbind_by_node_path(argv[1]);
|
|
} else if (!by_node && bind) {
|
|
int index = (argc > 2) ? simple_strtoul(argv[2], NULL, 10) : 0;
|
|
|
|
if (argc != 4)
|
|
return CMD_RET_USAGE;
|
|
ret = bind_by_class_index(argv[1], index, argv[3]);
|
|
} else if (!by_node && !bind) {
|
|
int index = (argc > 2) ? simple_strtoul(argv[2], NULL, 10) : 0;
|
|
|
|
if (argc == 3)
|
|
ret = unbind_by_class_index(argv[1], index);
|
|
else if (argc == 4)
|
|
ret = unbind_child_by_class_index(argv[1], index,
|
|
argv[3]);
|
|
else
|
|
return CMD_RET_USAGE;
|
|
}
|
|
|
|
if (ret)
|
|
return CMD_RET_FAILURE;
|
|
else
|
|
return CMD_RET_SUCCESS;
|
|
}
|
|
|
|
U_BOOT_CMD(
|
|
bind, 4, 0, do_bind_unbind,
|
|
"Bind a device to a driver",
|
|
"<node path> <driver>\n"
|
|
"bind <class> <index> <driver>\n"
|
|
);
|
|
|
|
U_BOOT_CMD(
|
|
unbind, 4, 0, do_bind_unbind,
|
|
"Unbind a device from a driver",
|
|
"<node path>\n"
|
|
"unbind <class> <index>\n"
|
|
"unbind <class> <index> <driver>\n"
|
|
);
|