2020-10-26 17:18:48 +01:00
|
|
|
/****************************************************************************
|
2021-06-16 10:29:25 +02:00
|
|
|
* apps/system/adb/adb_main.c
|
2020-10-26 17:18:48 +01:00
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "adb.h"
|
|
|
|
|
2022-01-23 09:31:43 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <syslog.h>
|
|
|
|
|
2023-07-29 10:11:39 +02:00
|
|
|
#if defined(CONFIG_ADBD_BOARD_INIT) || defined (CONFIG_BOARDCTL_RESET) || \
|
|
|
|
defined(CONFIG_ADBD_USB_BOARDCTL)
|
2020-12-17 03:23:26 +01:00
|
|
|
# include <sys/boardctl.h>
|
2020-10-26 17:18:48 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_ADBD_NET_INIT
|
|
|
|
#include "netutils/netinit.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-07-27 09:22:55 +02:00
|
|
|
void adb_log_impl(int priority, FAR const char *func, int line,
|
|
|
|
FAR const char *fmt, ...)
|
2020-10-26 17:18:48 +01:00
|
|
|
{
|
2022-01-23 09:31:43 +01:00
|
|
|
struct va_format vaf;
|
2020-10-26 17:18:48 +01:00
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2022-01-23 09:31:43 +01:00
|
|
|
vaf.fmt = fmt;
|
|
|
|
vaf.va = ≈
|
2023-07-27 09:22:55 +02:00
|
|
|
|
|
|
|
switch (priority)
|
|
|
|
{
|
|
|
|
case ADB_INFO:
|
|
|
|
priority = LOG_INFO;
|
|
|
|
break;
|
|
|
|
case ADB_ERR:
|
|
|
|
priority = LOG_ERR;
|
|
|
|
break;
|
|
|
|
case ADB_WARN:
|
|
|
|
priority = LOG_WARNING;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
priority = LOG_INFO;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
syslog(priority, "%s (%d): %pV", func, line, &vaf);
|
2020-10-26 17:18:48 +01:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2020-12-08 14:16:57 +01:00
|
|
|
void adb_reboot_impl(const char *target)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_BOARDCTL_RESET
|
2022-01-23 10:45:35 +01:00
|
|
|
if (strcmp(target, "recovery") == 0)
|
|
|
|
{
|
2023-04-01 13:35:42 +02:00
|
|
|
boardctl(BOARDIOC_RESET, BOARDIOC_SOFTRESETCAUSE_ENTER_RECOVERY);
|
2022-01-23 10:45:35 +01:00
|
|
|
}
|
|
|
|
else if (strcmp(target, "bootloader") == 0)
|
|
|
|
{
|
2023-04-01 13:35:42 +02:00
|
|
|
boardctl(BOARDIOC_RESET, BOARDIOC_SOFTRESETCAUSE_ENTER_BOOTLOADER);
|
2022-01-23 10:45:35 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-04-01 13:35:42 +02:00
|
|
|
boardctl(BOARDIOC_RESET, BOARDIOC_SOFTRESETCAUSE_USER_REBOOT);
|
2022-01-23 10:45:35 +01:00
|
|
|
}
|
2020-12-08 14:16:57 +01:00
|
|
|
#else
|
|
|
|
adb_log("reboot not implemented\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-10-26 17:18:48 +01:00
|
|
|
int main(int argc, FAR char **argv)
|
|
|
|
{
|
|
|
|
adb_context_t *ctx;
|
|
|
|
|
|
|
|
#ifdef CONFIG_ADBD_BOARD_INIT
|
|
|
|
boardctl(BOARDIOC_INIT, 0);
|
2023-07-29 10:11:39 +02:00
|
|
|
#endif /* CONFIG_ADBD_BOARD_INIT */
|
2020-10-26 17:18:48 +01:00
|
|
|
|
2023-07-29 10:11:39 +02:00
|
|
|
#ifdef CONFIG_ADBD_USB_BOARDCTL
|
2020-10-26 17:18:48 +01:00
|
|
|
|
2023-07-29 10:11:39 +02:00
|
|
|
/* Setup USBADB device */
|
2020-10-26 17:18:48 +01:00
|
|
|
|
|
|
|
struct boardioc_usbdev_ctrl_s ctrl;
|
2023-07-29 10:11:39 +02:00
|
|
|
#ifdef CONFIG_USBDEV_COMPOSITE
|
|
|
|
uint8_t usbdev = BOARDIOC_USBDEV_COMPOSITE;
|
|
|
|
#else
|
|
|
|
uint8_t usbdev = BOARDIOC_USBDEV_ADB;
|
|
|
|
#endif
|
2020-10-26 17:18:48 +01:00
|
|
|
FAR void *handle;
|
2023-07-29 10:11:39 +02:00
|
|
|
int ret;
|
2020-10-26 17:18:48 +01:00
|
|
|
|
|
|
|
/* Perform architecture-specific initialization */
|
|
|
|
|
2023-07-29 10:11:39 +02:00
|
|
|
ctrl.usbdev = usbdev;
|
2020-10-26 17:18:48 +01:00
|
|
|
ctrl.action = BOARDIOC_USBDEV_INITIALIZE;
|
|
|
|
ctrl.instance = 0;
|
|
|
|
ctrl.config = 0;
|
|
|
|
ctrl.handle = NULL;
|
|
|
|
|
|
|
|
ret = boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
printf("boardctl(BOARDIOC_USBDEV_CONTROL) failed: %d\n", ret);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-07-29 10:11:39 +02:00
|
|
|
/* Connect the USB composite device device */
|
2020-10-26 17:18:48 +01:00
|
|
|
|
2023-07-29 10:11:39 +02:00
|
|
|
ctrl.usbdev = usbdev;
|
2020-10-26 17:18:48 +01:00
|
|
|
ctrl.action = BOARDIOC_USBDEV_CONNECT;
|
|
|
|
ctrl.instance = 0;
|
|
|
|
ctrl.config = 0;
|
|
|
|
ctrl.handle = &handle;
|
|
|
|
|
|
|
|
ret = boardctl(BOARDIOC_USBDEV_CONTROL, (uintptr_t)&ctrl);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
printf("boardctl(BOARDIOC_USBDEV_CONTROL) failed: %d\n", ret);
|
|
|
|
return 1;
|
|
|
|
}
|
2023-07-29 10:11:39 +02:00
|
|
|
#endif /* ADBD_USB_BOARDCTL */
|
2020-10-26 17:18:48 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_ADBD_NET_INIT
|
|
|
|
/* Bring up the network */
|
|
|
|
|
|
|
|
netinit_bringup();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
ctx = adb_hal_create_context();
|
|
|
|
if (!ctx)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
adb_hal_run(ctx);
|
|
|
|
adb_hal_destroy_context(ctx);
|
|
|
|
return 0;
|
|
|
|
}
|