2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-08-16 18:00:53 +00:00
|
|
|
/*
|
|
|
|
* cmd_sdp.c -- sdp command
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 Toradex
|
|
|
|
* Author: Stefan Agner <stefan.agner@toradex.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-05-10 17:40:03 +00:00
|
|
|
#include <command.h>
|
2017-08-16 18:00:53 +00:00
|
|
|
#include <g_dnl.h>
|
|
|
|
#include <sdp.h>
|
|
|
|
#include <usb.h>
|
2023-09-15 00:21:46 +00:00
|
|
|
#include <linux/printk.h>
|
2017-08-16 18:00:53 +00:00
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
static int do_sdp(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
|
2017-08-16 18:00:53 +00:00
|
|
|
{
|
2023-09-01 09:49:52 +00:00
|
|
|
int controller_index;
|
2023-09-01 09:49:58 +00:00
|
|
|
struct udevice *udc;
|
2019-06-04 19:01:55 +00:00
|
|
|
int ret;
|
2017-08-16 18:00:53 +00:00
|
|
|
|
|
|
|
if (argc < 2)
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
|
2023-09-01 09:49:52 +00:00
|
|
|
controller_index = simple_strtoul(argv[1], NULL, 0);
|
2023-09-01 09:49:58 +00:00
|
|
|
ret = udc_device_get_by_index(controller_index, &udc);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2017-08-16 18:00:53 +00:00
|
|
|
|
|
|
|
g_dnl_clear_detach();
|
2019-06-04 19:01:55 +00:00
|
|
|
ret = g_dnl_register("usb_dnl_sdp");
|
|
|
|
if (ret) {
|
|
|
|
pr_err("SDP dnl register failed: %d\n", ret);
|
|
|
|
goto exit_register;
|
|
|
|
}
|
2017-08-16 18:00:53 +00:00
|
|
|
|
2023-09-01 09:49:58 +00:00
|
|
|
ret = sdp_init(udc);
|
2017-08-16 18:00:53 +00:00
|
|
|
if (ret) {
|
2018-02-15 06:08:55 +00:00
|
|
|
pr_err("SDP init failed: %d\n", ret);
|
2017-08-16 18:00:53 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This command typically does not return but jumps to an image */
|
2023-09-01 09:49:58 +00:00
|
|
|
sdp_handle(udc);
|
2018-02-15 06:08:55 +00:00
|
|
|
pr_err("SDP ended\n");
|
2017-08-16 18:00:53 +00:00
|
|
|
|
|
|
|
exit:
|
|
|
|
g_dnl_unregister();
|
2019-06-04 19:01:55 +00:00
|
|
|
exit_register:
|
2023-09-01 09:49:58 +00:00
|
|
|
udc_device_put(udc);
|
2017-08-16 18:00:53 +00:00
|
|
|
|
2019-06-04 19:01:55 +00:00
|
|
|
return CMD_RET_FAILURE;
|
2017-08-16 18:00:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_CMD(sdp, 2, 1, do_sdp,
|
|
|
|
"Serial Downloader Protocol",
|
|
|
|
"<USB_controller>\n"
|
|
|
|
" - serial downloader protocol via <USB_controller>\n"
|
|
|
|
);
|