fs work, initrd/stdio

master
Clyne Sullivan 6 years ago
parent e88b4f9040
commit 22615096de

@ -25,11 +25,9 @@ OBJCOPY = objcopy
MCUFLAGS = -mthumb -mcpu=cortex-m4 #-mfloat-abi=hard -mfpu=fpv4-sp-d16
AFLAGS = $(MCUFLAGS)
CFLAGS = $(MCUFLAGS) -ggdb --specs=nosys.specs \
-I.. \
-fno-builtin -fsigned-char -ffreestanding \
-Wall -Werror -Wextra -pedantic \
-Wno-overlength-strings -Wno-discarded-qualifiers
CFLAGS = $(MCUFLAGS) -ggdb -ffreestanding -nostdlib -fsigned-char -I.. \
-Wall -Werror -Wextra -pedantic
#-Wno-overlength-strings -Wno-discarded-qualifiers
LFLAGS = -T link.ld
OUT = main.elf

@ -1,4 +1,6 @@
all:
@arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -fsigned-char -Os -nostdinc \
@arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -fsigned-char -Os \
-nostdinc -nostdlib \
-fdata-sections -ffunction-sections -Wl,--gc-sections \
-I../src/pdclib/include -I../src/pdclib/platform/stmos/include \
test.c ../src/pdclib/pdclib.a -s -o test -pie
test.c ../src/pdclib/pdclib.a -s -o test

Binary file not shown.

@ -1,4 +1,12 @@
#include <stdio.h>
#include <stdlib.h>
int main(void);
void _start(void)
{
exit(main());
}
int main(void)
{

@ -56,26 +56,6 @@ SECTIONS {
. = ALIGN(8);
} > FLASH
/* ARM stuff */
.ARM.exidx : {
*(.ARM.exidx)
} > FLASH
/* init_array/fini_array (TODO understand this) */
.init_array : {
__init_array_start = .;
KEEP(*(.init_array.*))
KEEP(*(.init_array*))
__init_array_end = .;
} > FLASH
.fini_array : {
__fini_array_start = .;
KEEP(*(.fini_array.*))
KEEP(*(.fini_array*))
__fini_array_end = .;
} > FLASH
/* initialized data */
_sidata = LOADADDR(.data);
.data : {

@ -1,5 +1,4 @@
#include <stdint.h>
#include <string.h>
#include <kernel/heap.h>
#include <kernel/vfs.h>
@ -30,6 +29,16 @@ static const vfs_volume_funcs initrd_funcs = {
0 // readdir
};
int initrd_strncmp(const char *a, const char *b, unsigned int n)
{
for (unsigned int i = 0; i < n; i++) {
if (a[i] != b[i])
return 1;
}
return 0;
}
void initrd_init(void)
{
vfs_mount(&initrd_funcs, VFS_READONLY);
@ -40,7 +49,7 @@ void *initrd_open(const char *file)
char *ptr;
for (uint32_t i = 0; ptr = initrd_getfile(i), ptr != 0; i++) {
uint32_t len = *((uint32_t *)ptr);
if (!strncmp(file, ptr + 4, len)) {
if (!initrd_strncmp(file, ptr + 4, len)) {
initrd_info *file = (initrd_info *)malloc(
sizeof(initrd_info));
file->address = ptr + len + 8;

@ -20,7 +20,7 @@
#include "gpio.h"
static const GPIO_TypeDef *gpio_ports[8] = {
static GPIO_TypeDef *gpio_ports[8] = {
GPIOA, GPIOB, GPIOC, GPIOD,
GPIOE, GPIOF, GPIOG, GPIOH
};

@ -105,7 +105,7 @@ LoopFillZerobss:
bcc FillZerobss
/* Call static constructors */
bl __libc_init_array
//bl __libc_init_array
/* Call the application's entry point.*/
bl main

@ -87,7 +87,7 @@ void task_sleep(uint32_t ms)
pid_t task_getpid(void)
{
return task_current->pid;
return task_current != 0 ? task_current->pid : 0;
}
pid_t task_waitpid(pid_t pid, int *wstatus, int options)

@ -43,12 +43,12 @@ void vfs_init(void)
vfs_mount(&stdio_funcs, 0);
// order is crucial
vfs_open("in", VFS_FILE_READ);
vfs_open("out", VFS_FILE_WRITE);
vfs_open("err", VFS_FILE_WRITE);
vfs_open(" in", VFS_FILE_READ);
vfs_open(" out", VFS_FILE_WRITE);
vfs_open(" err", VFS_FILE_WRITE);
}
int vfs_mount(vfs_volume_funcs *funcs, uint32_t flags)
int vfs_mount(const vfs_volume_funcs *funcs, uint32_t flags)
{
for (int i = 0; i < VFS_MAX_VOLS; i++) {
if (!(vfs_volumes[i].flags && VFS_MOUNTED)) {
@ -64,10 +64,14 @@ int vfs_mount(vfs_volume_funcs *funcs, uint32_t flags)
int vfs_get_drive(const char *path)
{
// Validate parameters
if (path[0] == '\0' || path[1] == '\0' || path[1] != ':' ||
path[2] == '\0' || path[2] != '/')
if (path[0] == '\0')
return -1;
// Default to 'A' if no drive specified (A gives stdio)
if (path[1] == '\0' || path[1] != ':' ||
path[2] == '\0' || path[2] != '/')
return 0;
// Find chosen drive
int drive = -1;
for (int i = 0; i < VFS_MAX_VOLS; i++) {
@ -103,11 +107,14 @@ int vfs_open(const char *path, uint32_t flags)
if (file == -1)
return -1;
void *fsinfo = vfs_volumes[drive].funcs->open(path + 3);
if (fsinfo == 0)
return -1;
vfs_files[file].flags = VFS_FILE_OPEN | flags;
vfs_files[file].vol = drive;
vfs_files[file].pid = task_getpid();
vfs_files[file].fsinfo =
vfs_volumes[drive].funcs->open(path + 3);
vfs_files[file].fsinfo = fsinfo;
return file;
}

@ -22,7 +22,7 @@ typedef struct vfs_volume_funcs_t {
typedef struct {
uint32_t flags;
vfs_volume_funcs *funcs;
const vfs_volume_funcs *funcs;
} vfs_volume;
// Indicates an opened file
@ -43,7 +43,7 @@ typedef struct {
void vfs_init(void);
int vfs_mount(vfs_volume_funcs *funcs, uint32_t flags);
int vfs_mount(const vfs_volume_funcs *funcs, uint32_t flags);
int vfs_open(const char *path, uint32_t flags);
int vfs_close(int fd);
uint32_t vfs_read(int fd, uint32_t count, uint8_t *buffer);

@ -6,6 +6,11 @@
//
// Task-related calls
#define WEXITSTATUS(s) ((s) & 0xFF)
#define WIFEXITED(s) ((s) & (1 << 8))
#define WIFSIGNALED(s) ((s) & (1 << 9))
#define WTERMSIG(s) ((s) & (1 << 10))
void _exit(int code);
int fork(void);
@ -35,7 +40,9 @@ unsigned int ticks(void);
// Set if EOF has been reached
#define VFS_EOF (1 << 3)
#ifndef EOF
#define EOF (-1)
#endif // EOF
struct dirent {
char name[32];

@ -19,10 +19,11 @@ void user_main(void)
{
gpio(GPIO_MODE, 5, OUTPUT);
int test = vfs_open("A:/hello", VFS_FILE_READ);
int test = vfs_open("B:/hello", VFS_FILE_READ);
char *buf = malloc(20);
int count = vfs_read(test, 20, (uint8_t *)buf);
(void)count;
buf[count] = '\0';
vfs_close(test);
// if (fork() == 0) {
// while (1) {

Loading…
Cancel
Save