1 /*
2  * Copyright (c) 2006-2021, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2021-11-11     GuEe-GUI     the first version
9  */
10 
11 #include <rtthread.h>
12 
13 #include <virtio_console.h>
14 
console_init()15 static int console_init()
16 {
17     rt_err_t status = RT_EOK;
18     rt_device_t device = rt_device_find("virtio-console0");
19 
20     if (device != RT_NULL && rt_device_open(device, 0) == RT_EOK)
21     {
22         /* Create vport0p1 */
23         status = rt_device_control(device, VIRTIO_DEVICE_CTRL_CONSOLE_PORT_CREATE, RT_NULL);
24     }
25 
26     if (device != RT_NULL)
27     {
28         rt_device_close(device);
29     }
30 
31     return status;
32 }
33 INIT_ENV_EXPORT(console_init);
34 
console(int argc,char ** argv)35 static int console(int argc, char **argv)
36 {
37     rt_err_t result = RT_EOK;
38 
39     if (argc > 1)
40     {
41         if (!rt_strcmp(argv[1], "set"))
42         {
43             rt_kprintf("console change to %s\n", argv[2]);
44             rt_console_set_device(argv[2]);
45         }
46         else
47         {
48             rt_kprintf("Unknown command. Please enter 'console' for help\n");
49             result = -RT_ERROR;
50         }
51     }
52     else
53     {
54         rt_kprintf("Usage: \n");
55         rt_kprintf("console set <name>   - change console by name\n");
56         result = -RT_ERROR;
57     }
58     return result;
59 }
60 MSH_CMD_EXPORT(console, set console name);
61