We will be able to display the shell by connecting the cheap Linux board G-cluster to the TV and sticking the USB keyboard!
In the article I posted last time, [Preparation] I played with cheap Linux board G-cluster (no screen output) ", from a personal computer with UART It starts from accessing the shell of G-cluster! !!
This time, we will proceed with the goal of "making it possible to display free character strings on the screen"! (This time I will not introduce Python that I planned last time. I may do it next time)
Even if you say that you want to display a character string, it's boring to just display the characters, so I'd like to make it possible to display a simple shell.
When you hear "put a shell on the screen", you might think that "Ctrl + Alt + F1" will switch to tty. But that's the story on X. Since X is not running on G-cluster (I want to do it in the future), I have to make it from the screen by myself.
On the file system, there was a pipe called "remotectl_pipe" that seems to be used for screen display, so I tried stringing with this name.
Then I found something like the following
echo "firstboot $WELCOME" > /cavium/remotectl_pipe
echo 'firstboot 5' > /cavium/remotectl_pipe
echo gc_warning Firmware found > /cavium/remotectl_pipe
echo wifi_err ap > /cavium/remotectl_pipe
echo network_connect > /cavium/remotectl_pipe
echo network_disconnect > /cavium/remotectl_pipe
In this way, it seems that basically the screen that is always prepared is requested and displayed with a pipe.
Here, while hitting this command in various ways, I noticed something.
In ʻecho gc_warning Firmware found> / cavium / remotectl_pipehere, it seems that the
Firmware found` part can be changed freely.
That's why you can now display any character on the screen. You can also use \ n
and Japanese, so it seems to be difficult to display it.
At the Linux kernel level, there is a function that automatically mounts when you insert a USB keyboard. When you actually stab it, / dev / event *
is added, and if you touch the keyboard while it is open with cat, characters will come out.
But it's not well-formed, so I don't know what it is. I tried to display the key code on the TV. The code is Accessing Keys from Linux Input Device Almost the same site, only the display part is changed.
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <linux/input.h>
#include <string.h>
#include <stdio.h>
static const char *const evval[3] = {
"RELEASED",
"PRESSED ",
"REPEATED"
};
int main(void)
{
const char *dev = "/dev/input/event1";
struct input_event ev;
ssize_t n;
int fd;
fd = open(dev, O_RDONLY);
if (fd == -1) {
fprintf(stderr, "Cannot open %s: %s.\n", dev, strerror(errno));
return EXIT_FAILURE;
}
while (1) {
n = read(fd, &ev, sizeof ev);
if (n == (ssize_t)-1) {
if (errno == EINTR)
continue;
else
break;
} else
if (n != sizeof ev) {
errno = EIO;
break;
}
if (ev.type == EV_KEY && ev.value >= 0 && ev.value <= 2)
printf("%s 0x%04x (%d)\n", evval[ev.value], (int)ev.code, (int)ev.code);
}
fflush(stdout);
fprintf(stderr, "%s.\n", strerror(errno));
return EXIT_FAILURE;
}
You can now display the key code on the screen.
I wrote it without thinking about it, so I haven't implemented capital letters or scrolling, but I can move the shell like this.
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <linux/input.h>
#include <string.h>
#include <stdio.h>
#define N 100000
static const char *const evval[3] = {
"RELEASED",
"PRESSED ",
"REPEATED"
};
int main(void)
{
const char *dev = "/dev/event1";
// const char *dev = "/dev/input/event3";
// ref: https://gist.github.com/rickyzhang82/8581a762c9f9fc6ddb8390872552c250
const int keytable[127] = {' ', ' ', '1', '2', '3', '4', '5', '6', '7', '8',
'9', '0', '-', '=', ' ', ' ', 'q', 'w', 'e', 'r',
't', 'y', 'u', 'i', 'o', 'p', '[', ']', ' ', ' ',
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';',
'\'', '`', ' ', '\\', 'z', 'x', 'c', 'v', 'b', 'n',
'm', ',', '.', '/', ' ', '*', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', '-', ' ', ' ', ' ', '+', ' ',
' ', ' ', ' ', ' ', ' ', '.', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ', ' ', ' ', ' '
};
struct input_event ev;
ssize_t n;
int fd;
char result[N] = {'\0'};
char inputing[N] = {'\0'};
char inputkey;
int inputi = 0;
FILE *file;
char line[N];
fd = open(dev, O_RDONLY);
if (fd == -1) {
fprintf(stderr, "Cannot open %s: %s.\n", dev, strerror(errno));
return EXIT_FAILURE;
}
while (1) {
n = read(fd, &ev, sizeof ev);
if (n == (ssize_t)-1) {
if (errno == EINTR)
continue;
else
break;
} else
if (n != sizeof ev) {
errno = EIO;
break;
}
if (ev.type == EV_KEY && ev.value == 1) {
inputkey = keytable[(int)ev.code];
if((int)ev.code == 28) {
sprintf(result, "%s &> cmdtmp", inputing);
system(result);
strcat(inputing, "\\n");
file = fopen("cmdtmp", "r");
while(fgets(line, N, file)!=NULL){
line[strcspn(line, "\r\n")] = 0;
strcat(inputing, line);
strcat(inputing, "\\n");
}
fclose(file);
sprintf(result, "echo \"gc_warning > %s\" > /cavium/remotectl_pipe", inputing);
printf("%s\n", result);
system(result);
inputing[0] = '\0';
inputi = 0;
} else {
inputing[inputi] = inputkey;
inputing[inputi+1] = '\0';
inputi++;
sprintf(result, "echo \"gc_warning > %s\" > /cavium/remotectl_pipe", inputing);
printf("%s\n", result);
system(result);
}
//printf("%s 0x%04x (%d)\n", evval[ev.value], (int)ev.code, (int)ev.code);
//sprintf(result, "echo \"gc_warning %s 0x%04x (%d)\" > /cavium/remotectl_pipe", evval[ev.value], (int)ev.code, (int)ev.code);
//sprintf(result, "echo \"gc_warning %s 0x%04x (%d)\" > remotectl_pipe", evval[ev.value], (int)ev.code, (int)ev.code);
//system(result);
//printf("%s\n", result);
}
}
fflush(stdout);
fprintf(stderr, "%s.\n", strerror(errno));
return EXIT_FAILURE;
}
Now you can move the shell on your TV like the gif at the beginning.
This time, I'm honestly not very satisfied because I just wrote that I can run the shell and use the TV screen for the time being.
The next goal is to use the USB firmware update function of G-cluster to burn the image and run any program without hardware modification. It will take more time, so please be patient. ..
After that, since I have purchased a large amount of g-cluster, I plan to play various things such as arranging them as Wi-Fi modules at regular intervals and using them for position detection.
I will post it when progress is made! Thank you very much.
Recommended Posts