[Shell startup] I tried to display the shell on the TV with a cheap Linux board G-cluster

In this article

We will be able to display the shell by connecting the cheap Linux board G-cluster to the TV and sticking the USB keyboard!

output.gif

Prerequisites

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.

Rough procedure

  1. Analyze various apps to find out about screen display
  2. Make it possible to get information from a USB keyboard
  3. Write a suitable program to be a shell

Analyze various apps to find out about screen display

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 theFirmware 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.

Make it possible to get information from a USB keyboard

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.

output2.gif

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.

output3.gif

Write a suitable program to be a shell

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.

from now on

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

[Shell startup] I tried to display the shell on the TV with a cheap Linux board G-cluster
I tried to register a station on the IoT platform "Rimotte"
I tried to get started with Bitcoin Systre on the weekend
I tried to display GUI on Mac with X Window System
I tried to create Bulls and Cows with a shell program
[Python] I tried to visualize the night on the Galactic Railroad with WordCloud!
I tried to draw a system configuration diagram with Diagrams on Docker
I tried with the top 100 PyPI packages> I tried to graph the packages installed on Python
I tried to display the altitude value of DTM in a graph
I tried to save the data with discord
I tried to operate Linux with Discord Bot
I tried playing with the calculator on tkinter
I tried to display the infection condition of coronavirus on the heat map of seaborn
I tried to create a model with the sample of Amazon SageMaker Autopilot
I tried to learn the sin function with chainer
I tried to create a table only with Django
I tried to implement Minesweeper on terminal with python
I tried to touch the CSV file with Python
I tried to draw a route map with Python
I tried to solve the soma cube with python
I tried to solve the problem with Python Vol.1
I tried installing the Linux kernel on virtualbox + vagrant
I tried to notify the honeypot report on LINE
I tried to make something like a chatbot with the Seq2Seq model of TensorFlow
[Don't refer to 04.02.17] Display the temperature sensor on a real-time graph with rasberry pi 3.
I tried to implement a volume moving average with Quantx
I tried to analyze the whole novel "Weathering with You" ☔️
I tried to display the point cloud data DB of Shizuoka prefecture with Vue + Leaflet
I wanted to run the motor with Raspberry Pi, so I tried using Waveshare's Motor Driver Board
I tried to find the average of the sequence with TensorFlow
I tried to automatically create a report with Markov chain
I tried to rewrite the WEB server of the normal Linux programming 1st edition with C ++ 14
I tried to notify the train delay information with LINE Notify
[Linux] Copy data from Linux to Windows with a shell script
I tried to solve a combination optimization problem with Qiskit
I tried to display the time and today's weather w
I tried to reintroduce Linux
I also tried to imitate the function monad and State monad with a generator in Python
I tried to sort a random FizzBuzz column with bubble sort.
I wrote a doctest in "I tried to simulate the probability of a bingo game with Python"
I tried changing the python script from 2.7.11 to 3.6.0 on windows10
I tried to launch ipython cluster to the minimum on AWS
I tried to divide the file into folders with Python
I tried to divide with a deep learning language model
When generating a large number of graphs with matplotlib, I do not want to display the graph on the screen (jupyter environment)
I tried to unlock the entrance 2 lock sesame with a single push of the AWS IoT button
I tried to predict the number of domestically infected people of the new corona with a mathematical model
I tried using "Asciichart Py" which can draw a beautiful graph on the console with Python.
[Python] I tried to make a simple program that works on the command line using argparse.
A story that didn't work when I tried to log in with the Python requests module
I tried to build a SATA software RAID configuration that boots the OS on Ubuntu Server
I tried to create a server environment that runs on Windows 10
I tried to create an environment of MkDocs on Amazon Linux
I tried to describe the traffic in real time with WebSocket
I tried to solve the ant book beginner's edition with python
[Linux] I tried to summarize the command of resource confirmation system
I tried to automate the watering of the planter with Raspberry Pi
A memorandum when I tried to get it automatically with selenium
I tried cross-validation based on the grid search results with scikit-learn
[3rd] I tried to make a certain authenticator-like tool with python
[Python] A memo that I tried to get started with asyncio