2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-08-16 18:00:54 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2016 Toradex
|
|
|
|
* Author: Stefan Agner <stefan.agner@toradex.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2017-08-16 18:00:54 +00:00
|
|
|
#include <spl.h>
|
|
|
|
#include <usb.h>
|
|
|
|
#include <g_dnl.h>
|
|
|
|
#include <sdp.h>
|
|
|
|
|
|
|
|
static int spl_sdp_load_image(struct spl_image_info *spl_image,
|
|
|
|
struct spl_boot_device *bootdev)
|
|
|
|
{
|
|
|
|
int ret;
|
2020-04-29 02:35:12 +00:00
|
|
|
const int controller_index = CONFIG_SPL_SDP_USB_DEV;
|
2017-08-16 18:00:54 +00:00
|
|
|
|
2020-04-29 02:35:14 +00:00
|
|
|
usb_gadget_initialize(controller_index);
|
2020-04-29 02:35:10 +00:00
|
|
|
|
2020-08-18 10:16:43 +00:00
|
|
|
board_usb_init(0, USB_INIT_DEVICE);
|
|
|
|
|
2017-08-16 18:00:54 +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);
|
|
|
|
return ret;
|
|
|
|
}
|
2017-08-16 18:00:54 +00:00
|
|
|
|
|
|
|
ret = sdp_init(controller_index);
|
|
|
|
if (ret) {
|
2018-02-15 06:08:55 +00:00
|
|
|
pr_err("SDP init failed: %d\n", ret);
|
2017-08-16 18:00:54 +00:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2019-06-04 19:56:29 +00:00
|
|
|
/*
|
|
|
|
* This command either loads a legacy image, jumps and never returns,
|
|
|
|
* or it loads a FIT image and returns it to be handled by the SPL
|
|
|
|
* code.
|
|
|
|
*/
|
2022-01-14 13:31:38 +00:00
|
|
|
ret = spl_sdp_handle(controller_index, spl_image, bootdev);
|
2019-06-04 19:56:29 +00:00
|
|
|
debug("SDP ended\n");
|
2017-08-16 18:00:54 +00:00
|
|
|
|
2020-04-29 02:35:14 +00:00
|
|
|
usb_gadget_release(controller_index);
|
2019-06-04 19:56:29 +00:00
|
|
|
return ret;
|
2017-08-16 18:00:54 +00:00
|
|
|
}
|
|
|
|
SPL_LOAD_IMAGE_METHOD("USB SDP", 0, BOOT_DEVICE_BOARD, spl_sdp_load_image);
|