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>
|
2023-09-15 00:21:46 +00:00
|
|
|
#include <linux/printk.h>
|
2017-08-16 18:00:54 +00:00
|
|
|
|
|
|
|
static int spl_sdp_load_image(struct spl_image_info *spl_image,
|
|
|
|
struct spl_boot_device *bootdev)
|
|
|
|
{
|
2020-04-29 02:35:12 +00:00
|
|
|
const int controller_index = CONFIG_SPL_SDP_USB_DEV;
|
2023-09-01 09:49:58 +00:00
|
|
|
struct udevice *udc;
|
|
|
|
int ret;
|
2017-08-16 18:00:54 +00:00
|
|
|
|
2023-09-01 09:49:58 +00:00
|
|
|
ret = udc_device_get_by_index(controller_index, &udc);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2020-04-29 02:35:10 +00:00
|
|
|
|
2022-07-13 20:39:46 +00:00
|
|
|
board_usb_init(controller_index, USB_INIT_DEVICE);
|
2020-08-18 10:16:43 +00:00
|
|
|
|
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);
|
2023-09-01 09:49:57 +00:00
|
|
|
goto err_detach;
|
2019-06-04 19:01:55 +00:00
|
|
|
}
|
2017-08-16 18:00:54 +00:00
|
|
|
|
2023-09-01 09:49:58 +00:00
|
|
|
ret = sdp_init(udc);
|
2017-08-16 18:00:54 +00:00
|
|
|
if (ret) {
|
2018-02-15 06:08:55 +00:00
|
|
|
pr_err("SDP init failed: %d\n", ret);
|
2023-09-01 09:49:57 +00:00
|
|
|
goto err_unregister;
|
2017-08-16 18:00:54 +00:00
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*/
|
2023-09-01 09:49:58 +00:00
|
|
|
ret = spl_sdp_handle(udc, spl_image, bootdev);
|
2019-06-04 19:56:29 +00:00
|
|
|
debug("SDP ended\n");
|
2017-08-16 18:00:54 +00:00
|
|
|
|
2023-09-01 09:49:57 +00:00
|
|
|
err_unregister:
|
|
|
|
g_dnl_unregister();
|
|
|
|
err_detach:
|
2023-09-01 09:49:58 +00:00
|
|
|
udc_device_put(udc);
|
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);
|