diff --git a/devices/flash-dummy/Makefile b/devices/flash-dummy/Makefile new file mode 100644 index 00000000..e9b56e33 --- /dev/null +++ b/devices/flash-dummy/Makefile @@ -0,0 +1,9 @@ +# +# Makefile for flash-dummy +# +# Copyright 2023 Phoenix Systems +# +# %LICENSE% +# + +OBJS += $(addprefix $(PREFIX_O)devices/flash-dummy/, flashdrv.o) diff --git a/devices/flash-dummy/flashdrv.c b/devices/flash-dummy/flashdrv.c new file mode 100644 index 00000000..a8fd07ce --- /dev/null +++ b/devices/flash-dummy/flashdrv.c @@ -0,0 +1,110 @@ +/* + * Phoenix-RTOS + * + * plo - operating system loader + * + * Dummy flash driver + * + * Copyright 2023 Phoenix Systems + * Author: Lukasz Leczkowski + * + * This file is part of Phoenix-RTOS. + * + * %LICENSE% + */ + +#include +#include +#include + + +static int flashdrv_isValidMinor(unsigned int minor) +{ + return (minor < FLASH_NO) ? 1 : 0; +} + + +/* Device interface */ +static ssize_t flashdrv_read(unsigned int minor, addr_t offs, void *buff, size_t len, time_t timeout) +{ + char *memptr; + ssize_t ret = -EINVAL; + + (void)timeout; + + if (flashdrv_isValidMinor(minor) != 0) { + memptr = FLASH_START; + + hal_memcpy(buff, memptr + offs, len); + ret = (ssize_t)len; + } + + return ret; +} + + +static ssize_t flashdrv_write(unsigned int minor, addr_t offs, const void *buff, size_t len) +{ + return -ENOSYS; +} + + +static int flashdrv_done(unsigned int minor) +{ + if (flashdrv_isValidMinor(minor) == 0) { + return -EINVAL; + } + + /* Nothing to do */ + + return EOK; +} + + +static int flashdrv_sync(unsigned int minor) +{ + if (flashdrv_isValidMinor(minor) == 0) { + return -EINVAL; + } + + /* Nothing to do */ + + return EOK; +} + + +static int flashdrv_map(unsigned int minor, addr_t addr, size_t sz, int mode, addr_t memaddr, size_t memsz, int memmode, addr_t *a) +{ + if (flashdrv_isValidMinor(minor) == 0) { + return -EINVAL; + } + + /* Data can be copied from device to map */ + return dev_isNotMappable; +} + + +static int flashdrv_init(unsigned int minor) +{ + if (flashdrv_isValidMinor(minor) == 0) { + return -EINVAL; + } + + return EOK; +} + + +__attribute__((constructor)) static void flashdrv_reg(void) +{ + static const dev_handler_t h = { + .init = flashdrv_init, + .done = flashdrv_done, + .read = flashdrv_read, + .write = flashdrv_write, + .erase = NULL, + .sync = flashdrv_sync, + .map = flashdrv_map + }; + + devs_register(DEV_STORAGE, FLASH_NO, &h); +} diff --git a/hal/sparcv8leon3/gaisler/gr712rc/Makefile b/hal/sparcv8leon3/gaisler/gr712rc/Makefile index d6c193d6..6a6ab662 100644 --- a/hal/sparcv8leon3/gaisler/gr712rc/Makefile +++ b/hal/sparcv8leon3/gaisler/gr712rc/Makefile @@ -11,5 +11,6 @@ CFLAGS += -DVADDR_KERNEL_INIT=$(VADDR_KERNEL_INIT) PLO_COMMANDS := alias app call console copy dump echo go help kernel map mem phfs reboot script wait include devices/uart-grlib/Makefile +include devices/flash-dummy/Makefile OBJS += $(addprefix $(PREFIX_O)hal/$(TARGET_SUFF)/gaisler/$(TARGET_SUBFAMILY)/, _init.o hal.o gr712rc.o) diff --git a/hal/sparcv8leon3/gaisler/gr712rc/peripherals.h b/hal/sparcv8leon3/gaisler/gr712rc/peripherals.h index ced2e00a..ce8c4cd3 100644 --- a/hal/sparcv8leon3/gaisler/gr712rc/peripherals.h +++ b/hal/sparcv8leon3/gaisler/gr712rc/peripherals.h @@ -40,5 +40,7 @@ #define GPT_TRLDVAL4 17 /* Timer 4 reload value reg : 0x44 */ #define GPT_TCTRL4 18 /* Timer 4 control register : 0x48 */ +#define FLASH_NO 1 +#define FLASH_START ((void *)0x47e00000) #endif