Ignore:
Timestamp:
Jan 21, 2018, 12:10:09 AM (6 years ago)
Author:
coas-nagasima
Message:

prototoolに関連するプロジェクトをnewlibからmuslを使うよう変更・更新
ntshellをnewlibの下位の実装から、muslのsyscallの実装に変更・更新
以下のOSSをアップデート
・mruby-1.3.0
・musl-1.1.18
・onigmo-6.1.3
・tcc-0.9.27
以下のOSSを追加
・openssl-1.1.0e
・curl-7.57.0
・zlib-1.2.11
以下のmrbgemsを追加
・iij/mruby-digest
・iij/mruby-env
・iij/mruby-errno
・iij/mruby-iijson
・iij/mruby-ipaddr
・iij/mruby-mock
・iij/mruby-require
・iij/mruby-tls-openssl

File:
1 edited

Legend:

Unmodified
Added
Removed
  • EcnlProtoTool/trunk/ntshell/src/main.c

    r321 r331  
    4040 */
    4141
     42#include "shellif.h"
    4243#include <kernel.h>
    43 #include <t_syslog.h>
    4444#include <t_stdlib.h>
    4545#include <sil.h>
    46 #include <stdlib.h>
     46#include <setjmp.h>
    4747#include <string.h>
    48 #include <stdio.h>
    49 #include <setjmp.h>
    5048#include "syssvc/serial.h"
    5149#include "syssvc/syslog.h"
     
    6462#include <net/if_var.h>
    6563#include <netinet/udp_var.h>
    66 #include <ethernet_api.h>
    6764#include "ffarch.h"
    68 #include "gpio_api.h"
    6965#include "ff.h"
    7066#include "websocket_fbs.h"
    71 #include "ntshell.h"
    72 #include "ntstdio.h"
     67#include "core/ntshell.h"
     68#include "core/ntlibc.h"
     69#include "util/ntstdio.h"
    7370#include "usrcmd.h"
    74 #include "ntopt.h"
    75 
    76 #ifndef _MSC_VER
    77 void strcpy_s(char *dst, int size, const char *src);
    78 #endif
     71#include "util/ntopt.h"
     72#include "socket_stub.h"
    7973
    8074ID ws_api_mailboxid = MAIN_DATAQUEUE;
     
    8680ntstdio_t ntstdio;
    8781
    88 const uint8_t mac_addr[6] = {0x00, 0x30, 0x13, 0x06, 0x62, 0xC0};
    89 const char host_name[] = "GR-PEACH";
     82const uint8_t mac_addr[6] = {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC};
     83const struct utsname host_name = {
     84        "TOPPERS/ASP3",
     85    "GR-PEACH",
     86    "3.1.0",
     87    "3.1.0",
     88    "GR-PEACH",
     89    "toppers.jp"
     90};
    9091
    9192static void netif_link_callback(T_IFNET *ether);
     
    228229        char buf[1];
    229230        if(serial_rea_dat(SIO_PORTID, buf, 1) != 1)
    230                 return -1;
     231                return -EIO;
    231232        return buf[0];
    232233}
     
    305306
    306307        if (exec) {
    307                 strcpy_s(command, sizeof(command), "mruby -b 1:/upload/main.mrb");
     308                ntlibc_strlcpy(command, "mruby -b 1:/upload/main.mrb", sizeof(command));
    308309
    309310                execute_command(1);
     
    371372}
    372373
    373 int gethostname(char *name, size_t len)
    374 {
    375         return strlcpy(name, host_name, len);
    376 }
    377 
    378 static int usrcmd_ntopt_callback(int argc, char **argv, void *extobj);
     374int shell_uname(struct utsname *uts)
     375{
     376        return memcpy(uts, &host_name, sizeof(host_name));
     377}
     378
     379static int usrcmd_ntopt_callback(long *args, void *extobj);
    379380int mruby_exit_code;
    380381volatile int mruby_state;
    381 typedef void (*PowerOn_Reset_t)(int argc, char **argv);
     382typedef void (*PowerOn_Reset_t)(long *args);
    382383jmp_buf process_exit;
    383384
     
    392393}
    393394
    394 static int usrcmd_ntopt_callback(int argc, char **argv, void *extobj)
    395 {
     395typedef struct
     396{
     397        const cmd_table_t *table;
     398        int count;
     399} cmd_table_info_t;
     400
     401static const cmd_table_t cmdlist[] = {
     402        {"cd", "change directory", usrcmd_cd },
     403        {"ls", "list files", usrcmd_ls },
     404        {"cp", "copy file", usrcmd_cp },
     405        {"rm", "remove file", usrcmd_rm },
     406        {"mv", "move file", usrcmd_mv },
     407        {"mkdir", "Make directory", usrcmd_mkdir},
     408        {"hexdump", "Hex dump", usrcmd_hexdump},
     409        {"info", "This is a description text string for info command.", usrcmd_info},
     410        {"exit", "Exit Natural Tyny Shell", usrcmd_exit},
     411};
     412cmd_table_info_t cmd_table_info = { cmdlist, sizeof(cmdlist) / sizeof(cmdlist[0]) };
     413
     414static int usrcmd_ntopt_callback(long *args, void *extobj)
     415{
     416        const cmd_table_t *p = cmd_table_info.table;
     417        if (ntlibc_strcmp((const char *)args[1], "help") == 0) {
     418                usrcmd_help(args[0], (char **)&args[1]);
     419        }
     420        else for (int i = 0; i < cmd_table_info.count; i++) {
     421                if (ntlibc_strcmp((const char *)args[1], p->cmd) == 0) {
     422                        return p->func(args[0], (char **)&args[1]);
     423                }
     424                p++;
     425        }
    396426        if (setjmp(process_exit) == 0) {
    397                 (*((PowerOn_Reset_t *)0x18200000))(argc, argv);
     427                (*((PowerOn_Reset_t *)0x18200000))(args);
    398428        }
    399429        clean_fd();
     430        return 0;
     431}
     432
     433int usrcmd_help(int argc, char **argv)
     434{
     435        const cmd_table_t *p = cmd_table_info.table;
     436        for (int i = 0; i < cmd_table_info.count; i++) {
     437                ntstdio_puts(&ntstdio, p->cmd);
     438                ntstdio_puts(&ntstdio, "\t:");
     439                ntstdio_puts(&ntstdio, p->desc);
     440                ntstdio_puts(&ntstdio, "\n");
     441                p++;
     442        }
    400443        return 0;
    401444}
     
    422465
    423466void shell_exit(int exitcd)
     467{
     468        mruby_exit_code = exitcd;
     469        longjmp(process_exit, 1);
     470}
     471
     472void shell_exit_group(int exitcd)
    424473{
    425474        mruby_exit_code = exitcd;
     
    458507static int cmd_execute(const char *text, void *extobj)
    459508{
    460         strlcpy(command, text, sizeof(command));
     509        ntlibc_strlcpy(command, text, sizeof(command));
    461510        return execute_command(1);
    462511}
     
    464513int stdio_close(struct _IO_FILE *fp)
    465514{
    466         return -1;
     515        return -EPERM;
    467516}
    468517
    469518size_t stdio_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
    470519{
    471         return -1;
     520        return -EPERM;
    472521}
    473522
    474523size_t stdio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
    475524{
    476         return -1;
     525        return -EPERM;
    477526}
    478527
     
    507556int sio_close(struct _IO_FILE *fp)
    508557{
    509         return -1;
     558        return -EPERM;
    510559}
    511560
    512561size_t sio_read(struct _IO_FILE *fp, unsigned char *data, size_t len)
    513562{
    514         return -1;
     563        return -EPERM;
    515564}
    516565
    517566size_t sio_write(struct _IO_FILE *fp, const unsigned char *data, size_t len)
    518567{
    519         return -1;
    520 }
     568        return -EPERM;
     569}
     570
     571off_t sio_seek(struct _IO_FILE *fp, off_t ofs, int org)
     572{
     573        return -EPERM;
     574}
     575
     576int sio_ioctl(struct _IO_FILE *fp, int request, void *arg)
     577{
     578        switch (request) {
     579        case TIOCGWINSZ:
     580                return 0;
     581        case TCGETS:
     582                return sio_tcgetattr(fp->fd, (struct termios *)arg);
     583        case TCSETS + TCSANOW:
     584        case TCSETS + TCSADRAIN:
     585        case TCSETS + TCSAFLUSH:
     586                return sio_tcsetattr(fp->fd, request - TCSETS, (const struct termios *)arg);
     587        }
     588
     589        return -EINVAL;
     590}
     591
     592int shell_clock_getres(clockid_t clk_id, struct timespec *res)
     593{
     594        if (clk_id != CLOCK_REALTIME)
     595                return -EINVAL;
     596
     597        memset(&res->tv_sec, 0xFF, sizeof(res->tv_sec));
     598        res->tv_nsec = 0;
     599
     600        return 0;
     601}
     602
     603int shell_clock_gettime(clockid_t clk_id, struct timespec *tp)
     604{
     605        SYSTIM now = 0;
     606
     607        if (clk_id != CLOCK_REALTIME)
     608                return -EINVAL;
     609
     610        get_tim(&now);
     611        tp->tv_sec = now / 1000000;
     612        tp->tv_nsec = (now % 1000000) * 1000;
     613
     614        return 0;
     615}
     616
     617int shell_clock_settime(clockid_t clk_id, const struct timespec *tp)
     618{
     619        if (clk_id != CLOCK_REALTIME)
     620                return -EINVAL;
     621
     622        rtc_write(tp->tv_sec);
     623
     624        return 0;
     625}
     626
     627sigset_t g_sigmask;
     628
     629int shell_sigprocmask(int how, const sigset_t *restrict set, sigset_t *restrict old)
     630{
     631        if (old != NULL)
     632                memcpy(old, &g_sigmask, sizeof(sigset_t));
     633
     634        switch (how) {
     635        case SIG_BLOCK:
     636                for (int i = 0; i < sizeof(g_sigmask.__bits) / sizeof(g_sigmask.__bits[0]); i++) {
     637                        g_sigmask.__bits[i] |= set->__bits[i];
     638                }
     639                break;
     640        case SIG_UNBLOCK:
     641                for (int i = 0; i < sizeof(g_sigmask.__bits) / sizeof(g_sigmask.__bits[0]); i++) {
     642                        g_sigmask.__bits[i] &= ~set->__bits[i];
     643                }
     644                break;
     645        case SIG_SETMASK:
     646                memcpy(&g_sigmask, set, sizeof(sigset_t));
     647                break;
     648        default:
     649                return -EINVAL;
     650        }
     651
     652        return 0;
     653}
     654
     655struct sigaction sigtable[6];
     656
     657int shell_sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old)
     658{
     659        struct sigaction *sat;
     660
     661        switch(sig){
     662        case SIGALRM:
     663                sat = &sigtable[0];
     664                break;
     665        case SIGFPE:
     666                sat = &sigtable[1];
     667                break;
     668        case SIGILL:
     669                sat = &sigtable[2];
     670                break;
     671        case SIGSEGV:
     672                sat = &sigtable[3];
     673                break;
     674        case SIGBUS:
     675                sat = &sigtable[4];
     676                break;
     677        case SIGABRT:
     678                sat = &sigtable[5];
     679                break;
     680        default:
     681                return -EINVAL;
     682        }
     683
     684        if (old != NULL)
     685                memcpy(old, sat, sizeof(struct sigaction));
     686
     687        memcpy(sat, sa, sizeof(struct sigaction));
     688
     689        return 0;
     690}
     691
     692int shell_madvise(void *a, size_t b, int c)
     693{
     694        return 0;
     695}
     696
Note: See TracChangeset for help on using the changeset viewer.