From 769b3dbcea116b83f913a6aae00b4e43633be82c Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Fri, 30 Mar 2018 11:39:33 -0400 Subject: [PATCH] new initrd format, 2nd layer for keypad --- Makefile | 5 +- include/initrd.h | 32 ++++--------- initrd.c | 42 ----------------- boot => initrd/boot | 0 libinterp.a | Bin 65730 -> 65754 bytes src/initrd.c | 112 +++++++++++--------------------------------- src/keypad.c | 41 ++++++++++++---- src/main.c | 4 +- src/script.c | 2 +- src/stdlib.c | 4 +- rba => tools/rba | Bin 11 files changed, 77 insertions(+), 165 deletions(-) delete mode 100644 initrd.c rename boot => initrd/boot (100%) rename rba => tools/rba (100%) diff --git a/Makefile b/Makefile index b3acc2a..d672a52 100644 --- a/Makefile +++ b/Makefile @@ -21,7 +21,7 @@ CROSS = arm-none-eabi- CC = gcc AS = as -AR = ar +AR = tools/rba OBJCOPY = objcopy STRIP = strip @@ -46,11 +46,10 @@ INITRD = initrd.img all: $(OUT) -#@$(CROSS)$(STRIP) --only-keep-debug $(OUT) $(OUT): $(OFILES) initrd/init libinterp.a @echo " INITRD " $(INITRD) @rm -f $(INITRD) - @$(CROSS)$(AR) r $(INITRD) initrd/* + @$(AR) $(INITRD) initrd/* @$(CROSS)$(OBJCOPY) -B arm -I binary -O elf32-littlearm $(INITRD) out/initrd.img.o @echo " LINK " $(OUT) @$(CROSS)$(CC) $(CFLAGS) $(LFLAGS) out/*.o -o $(OUT) -L. -linterp -lm diff --git a/include/initrd.h b/include/initrd.h index 1f7c0b6..3957066 100644 --- a/include/initrd.h +++ b/include/initrd.h @@ -26,45 +26,31 @@ #include -/** - * Structure for the archive's header. - */ -typedef struct -{ - char signature[8]; /**< The archive's signature */ -} __attribute__ ((packed)) initrd_header; - -/** - * Structure for a file entry in the archive. - */ -typedef struct -{ - char name[16]; /**< The name of the file */ - uint8_t unused[32]; /**< Unused information */ - char size[10]; /**< The file's size in bytes (as string) */ - char sig[2]; /**< A signature to start file data */ -} __attribute__ ((packed)) initrd_file; - /** * Confirms the initrd image is loaded and valid. * @return non-zero if valid image found */ uint8_t initrd_validate(void); +/** + * Gets the file name of the index'th file in the archive. + * @param index the index of the file + * @return the file's name, or zero if not found + */ +char *initrd_getfile(uint32_t index); + /** * Gets contents of the given file. * @param name the file's name * @return pointer to file data, null if not found */ -char *initrd_getfile(const char *name); +char *initrd_readfile(const char *name); /** * Gets the size of the given file. * @param name the file's name * @return the file's size, in bytes */ -uint32_t initrd_getfilesize(const char *name); - -char *initrd_getnfile(unsigned int index); +uint32_t initrd_filesize(const char *name); #endif // INITRD_H_ diff --git a/initrd.c b/initrd.c deleted file mode 100644 index 3f36cd9..0000000 --- a/initrd.c +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include - -extern uint8_t *initrd_start; -extern uint32_t initrd_size; - -char *getfile(uint32_t offset) -{ - char *ptr = initrd_start; - for (uint32_t i = 0; i < offset; i++) { - uint32_t len = *((uint32_t *)ptr); - uint32_t datalen = *((uint32_t *)(ptr + 4 + len)); - ptr += len + datalen + 8; - if (ptr >= (char *)(initrd_start + initrd_size)) - return 0; - } - - return ptr; -} - -char *readfile(const char *name) -{ - char *ptr; - for (uint32_t i = 0; ptr = getfile(i), ptr != 0; i++) { - uint32_t len = *((uint32_t *)ptr); - if (!strncmp(name, ptr + 4, len)) - return ptr + len + 8; - } - return 0; -} - -uint32_t filesize(const char *name) -{ - char *ptr; - for (uint32_t i = 0; ptr = getfile(i), ptr != 0; i++) { - uint32_t len = *((uint32_t *)ptr); - if (!strncmp(name, ptr + 4, len)) - return *((uint32_t *)ptr + len + 4); - } - return 0; -} - diff --git a/boot b/initrd/boot similarity index 100% rename from boot rename to initrd/boot diff --git a/libinterp.a b/libinterp.a index 7c9e7a9a51dede0cc646cc5be8663838b5e2fc2f..04391e1deab3ed92d758cec68b99c0349ca1cd77 100644 GIT binary patch delta 10195 zcmb_idstP~wqJAZwf0`FwRxz>hS+-n0viwzP!L1}O;FUW;G;rC5fjC?0zR_N*;ZCs zr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=>S73Ilx(ic`8RaMP_FBEqsm#JPJS=|$H~bb z7K>Zd7?hQ*zx?n&f7V?&&Z@6(z4en@edQdTi6(gSHX9^P4MERA2z{=`ue+UV;fE_hpK@mGvr4}*a%~D0-Cl3ktQI{ ecvW4PY8*}0w5!#E!i?lI(A@#~_aCTvpZ^B^B16sq diff --git a/src/initrd.c b/src/initrd.c index b8e8d09..1534210 100644 --- a/src/initrd.c +++ b/src/initrd.c @@ -1,9 +1,6 @@ /** * @file initrd.c * Initrd image support - * An archive file (made with ar) can be linked into the final executable to - * allow files to be loaded in memory on boot. See mkinitrd.sh or the Makefile - * for more info. * * Copyright (C) 2018 Clyne Sullivan * @@ -21,110 +18,57 @@ * along with this program. If not, see . */ +/** + * The format of the initrd file is custom; made with the 'rba' utility. + */ + #include +#include extern uint8_t _binary_initrd_img_start[]; extern uint8_t _binary_initrd_img_size[]; -static const void *initrd_start = (void *)_binary_initrd_img_start; +static const uint8_t *initrd_start = (uint8_t *)_binary_initrd_img_start; static const uint32_t initrd_size = (uint32_t)_binary_initrd_img_size; -static const char *initrd_sig = "!\n"; - uint8_t initrd_validate(void) { - initrd_header *header = (initrd_header *)initrd_start; - for (uint8_t i = 0; i < 8; i++) { - if (header->signature[i] != initrd_sig[i]) - return 0; - } - - return 1; + return 1; // TODO maybe add header/signature to archiver? } -uint8_t initrd_nametest(char *file, const char *want) +char *initrd_getfile(uint32_t offset) { - for (uint8_t i = 0; i < 16; i++) { - if (want[i] == '\0') - return (file[i] == '/'); - else if (want[i] != file[i]) + char *ptr = initrd_start; + for (uint32_t i = 0; i < offset; i++) { + uint32_t len = *((uint32_t *)ptr); + uint32_t datalen = *((uint32_t *)(ptr + 4 + len)); + ptr += len + datalen + 8; + if (ptr >= (char *)(initrd_start + initrd_size)) return 0; } - return 0; -} - -uint32_t ipow10(uint8_t n) -{ - uint32_t i = 1; - while (n--) - i *= 10; - return i; -} - -uint32_t initrd_getsize(initrd_file *file) -{ - uint32_t size = 0; - char *p = file->size + 10; - while (*--p == ' '); - - for (int8_t i = p - file->size, j = 0; i >= 0; i--, j++) - size += (*p-- - '0') * ipow10(j); - - return size; + return ptr; } -initrd_file *initrd_getfileptr(const char *name) +char *initrd_readfile(const char *name) { - initrd_file *file = (initrd_file *)((uint8_t *)initrd_start + sizeof(initrd_header)); - uint32_t offset = sizeof(initrd_header); - - while (offset < initrd_size) { - if (initrd_nametest(file->name, name)) - return file; - uint32_t size = initrd_getsize(file) + sizeof(initrd_file); - offset += size; - file = (initrd_file *)((uint8_t *)file + size + 1); + char *ptr; + for (uint32_t i = 0; ptr = initrd_getfile(i), ptr != 0; i++) { + uint32_t len = *((uint32_t *)ptr); + if (!strncmp(name, ptr + 4, len)) + return ptr + len + 8; } - return 0; } -char *initrd_getnfile(unsigned int index) +uint32_t initrd_filesize(const char *name) { - initrd_file *file = (initrd_file *)((uint8_t *)initrd_start + sizeof(initrd_header)); - uint32_t offset = sizeof(initrd_header); - - for (unsigned int i = 0; i < index; i++) { - uint32_t size = initrd_getsize(file) + sizeof(initrd_file); - offset += size; - file = (initrd_file *)((uint8_t *)file + size); - if (file->name[0] == '\n') - file = (initrd_file *)((uint32_t)file + 1); + char *ptr; + for (uint32_t i = 0; ptr = initrd_getfile(i), ptr != 0; i++) { + uint32_t len = *((uint32_t *)ptr); + if (!strncmp(name, ptr + 4, len)) + return *((uint32_t *)(ptr + len + 4)); } - if ((uint32_t)file >= (uint32_t)initrd_start + initrd_size) - return 0; - return file->name; -} - -char *initrd_getfile(const char *name) -{ - initrd_file *file = initrd_getfileptr(name); - if (file == 0) - return 0; - - - char *ptr = (char *)file + sizeof(initrd_file); - ptr[initrd_getsize(file) - 1] = 0; - return ptr; -} - -uint32_t initrd_getfilesize(const char *name) -{ - initrd_file *file = initrd_getfileptr(name); - if (file == 0) - return 0; - - return initrd_getsize(file); + return 0; } diff --git a/src/keypad.c b/src/keypad.c index 5b04eec..22fc967 100644 --- a/src/keypad.c +++ b/src/keypad.c @@ -53,16 +53,29 @@ static const port_t keypad_cols[COLS] = { { COL_3 }, { COL_4 } }; +#define K_2ND 0x000000FF +#define K_HOLD 0x000001FF + static const char keypad_map[ROWS * COLS * 4] = { - "&\0\0\0" "|\0\0\0" "pi\0\0" "==\0\0" "!=\0\0" - "x\0\0\0" "y\0\0\0" "z\0\0\0" "=\0\0\0" "sin\0" - "7\0\0\0" "8\0\0\0" "9\0\0\0" "(\0\0\0" ")\0\0\0" - "4\0\0\0" "5\0\0\0" "6\0\0\0" "/\0\0\0" "%\0\0\0" - "1\0\0\0" "2\0\0\0" "3\0\0\0" "*\0\0\0" "-\0\0\0" - ".\0\0\0" "0\0\0\0" "\b\0\0\0" "\n\0\0\0" "+\0\0\0" + "\xFF\0\0\0" ">\0\0\0" ">=\0\0" "==\0\0" "=\0\0\0" + "x\0\0\0" "<\0\0\0" "<=\0\0" "!=\0\0" "%\0\0\0" + "7\0\0\0" "8\0\0\0" "9\0\0\0" "(\0\0\0" ")\0\0\0" + "4\0\0\0" "5\0\0\0" "6\0\0\0" "/\0\0\0" "*\0\0\0" + "1\0\0\0" "2\0\0\0" "3\0\0\0" "-\0\0\0" "+\0\0\0" + ".\0\0\0" "0\0\0\0" "\0\0\0\0" "\b\0\0\0" "\n\0\0\0" +}; + +static const char keypad_map_2nd[ROWS * COLS * 4] = { + "a\0\0\0" "b\0\0\0" "c\0\0\0" "d\0\0\0" "e\0\0\0" + "f\0\0\0" "g\0\0\0" "h\0\0\0" "i\0\0\0" "j\0\0\0" + "k\0\0\0" "l\0\0\0" "m\0\0\0" "n\0\0\0" "o\0\0\0" + "p\0\0\0" "q\0\0\0" "r\0\0\0" "s\0\0\0" "t\0\0\0" + "u\0\0\0" "v\0\0\0" "w\0\0\0" "x\0\0\0" "y\0\0\0" + "z\0\0\0" "\0\0\0\0" "\0\0\0\0" "\0\0\0\0" "\xFF\x01\0\0" }; -#define KEY(r, c, i) keypad_map[r * COLS * 4 + c * 4 + i] +#define KEY(r, c, i) map[r * COLS * 4 + c * 4 + i] +#define KEYCODE(r, c) *((uint32_t *)(map + (r * COLS * 4 + c * 4))) #define BUFFER_SIZE 8 static char keypad_buffer[BUFFER_SIZE]; @@ -71,12 +84,24 @@ static int keypad_buffer_pos = -1; void keypad_task(void) { unsigned int col = 0; + unsigned char use2nd = 0; + unsigned char hold = 0; while (1) { gpio_dout(keypad_cols[col].port, keypad_cols[col].pin, 1); delay(10); for (unsigned int row = 0; row < ROWS; row++) { if (gpio_din(keypad_rows[row].port, keypad_rows[row].pin)) { - if (keypad_buffer_pos < BUFFER_SIZE) { + char *map = (use2nd == 0) ? keypad_map : keypad_map_2nd; + if (KEYCODE(row, col) == K_2ND) { + use2nd = 1; + } else if (KEYCODE(row, col) == K_HOLD) { + if (use2nd != 0) { + if ((hold ^= 1) == 0) + use2nd = 0; + } + } else if (keypad_buffer_pos < BUFFER_SIZE) { + if (use2nd != 0 && hold == 0) + use2nd = 0; for (unsigned int i = 0; KEY(row, col, i) != '\0'; i++) keypad_buffer[++keypad_buffer_pos] = KEY(row, col, i); } diff --git a/src/main.c b/src/main.c index d21407a..b39053a 100644 --- a/src/main.c +++ b/src/main.c @@ -90,7 +90,7 @@ void task_interpreter(void) instance *it = inewinstance(); script_loadlib(it); - char *s = initrd_getfile("init"); + char *s = initrd_readfile("init"); if (s == 0) { dsp_puts("can't find init"); goto end; @@ -98,7 +98,7 @@ void task_interpreter(void) char *linebuf = (char *)malloc(120); uint32_t i = 0, prev = 0, lc; - uint32_t size = initrd_getfilesize("init"); + uint32_t size = initrd_filesize("init"); int ret = 0; while (i < size) { for (; s[i] != '\n' && s[i] != '\0'; i++); diff --git a/src/script.c b/src/script.c index 733bc4a..95d62c0 100644 --- a/src/script.c +++ b/src/script.c @@ -107,7 +107,7 @@ int script_filemenu(instance *it) char *fname; strncpy(listbuf, " : \0", 4); dsp_puts("Choose a file: \n"); - for (unsigned int i = 0; (fname = initrd_getnfile(i)) != 0; i++) { + for (unsigned int i = 0; (fname = initrd_getfile(i)) != 0; i++) { listbuf[0] = i + '0'; dsp_puts(listbuf); dsp_puts(strncpy(buf, fname, 16)); diff --git a/src/stdlib.c b/src/stdlib.c index 950f356..b7b11dc 100644 --- a/src/stdlib.c +++ b/src/stdlib.c @@ -23,8 +23,8 @@ #include #include +#include #include -#include #include extern char *itoa(int, char *, int); @@ -61,7 +61,7 @@ char *snprintf(char *buf, unsigned int max, const char *format, ...) itoa(va_arg(args, unsigned int), nbuf, 16); break; case 'f': - itoa((int)va_arg(args, double), nbuf, 10); + itoa(va_arg(args, double), nbuf, 10); break; default: buf[off++] = format[i]; diff --git a/rba b/tools/rba similarity index 100% rename from rba rename to tools/rba