diff --git a/cmds/Makefile b/cmds/Makefile index 8d6c4454..5bcb4278 100644 --- a/cmds/Makefile +++ b/cmds/Makefile @@ -6,8 +6,8 @@ # %LICENSE% # -PLO_ALLCOMMANDS = alias app bankswitch bitstream bootcm4 bootrom call console copy dump \ - echo erase go help jffs2 kernel kernelimg lspci map mem mpu otp phfs reboot script \ +PLO_ALLCOMMANDS = alias app blob bankswitch bitstream bootcm4 bootrom call console copy \ + dump echo erase go help jffs2 kernel kernelimg lspci map mem mpu otp phfs reboot script \ test-dev test-ddr wait PLO_COMMANDS ?= $(PLO_ALLCOMMANDS) diff --git a/cmds/app.c b/cmds/app.c index 4e157e85..a7a95ed5 100644 --- a/cmds/app.c +++ b/cmds/app.c @@ -6,7 +6,7 @@ * Load application * * Copyright 2020-2021 Phoenix Systems - * Author: Hubert Buczynski, Gerard Swiderski + * Author: Hubert Buczynski, Gerard Swiderski, Aleksander Kaminski * * This file is part of Phoenix-RTOS. * diff --git a/cmds/blob.c b/cmds/blob.c new file mode 100644 index 00000000..4dfa20b1 --- /dev/null +++ b/cmds/blob.c @@ -0,0 +1,170 @@ +/* + * Phoenix-RTOS + * + * Operating system loader + * + * Load application + * + * Copyright 2020-2021, 2024 Phoenix Systems + * Author: Hubert Buczynski, Gerard Swiderski, Aleksander Kaminski + * + * This file is part of Phoenix-RTOS. + * + * %LICENSE% + */ + +#include "cmd.h" + +#include +#include +#include +#include + + +static void cmd_blobInfo(void) +{ + lib_printf("put file in the syspage, usage: blob [ ]"); +} + +static int cmd_cp2ent(handler_t handler, const mapent_t *entry) +{ + ssize_t len; + u8 buff[SIZE_MSG_BUFF]; + size_t offs, sz = entry->end - entry->start; + + for (offs = 0; offs < sz; offs += len) { + len = phfs_read(handler, offs, buff, min(SIZE_MSG_BUFF, sz - offs)); + if (len < 0) { + log_error("\nCan't read data"); + return len; + } + hal_memcpy((void *)(entry->start + offs), buff, len); + } + + return EOK; +} + +static int cmd_blobLoad(handler_t handler, size_t size, const char *name, const char *map) +{ + int res; + + unsigned int attr; + addr_t start, end, offs, addr; + + syspage_prog_t *prog; + const mapent_t *entry; + + if (phfs_aliasAddrResolve(handler, &offs) < 0) { + offs = 0; + } + + if (syspage_mapAttrResolve(map, &attr) < 0 || + syspage_mapRangeResolve(map, &start, &end) < 0) { + log_error("\n%s does not exist", map); + return -EINVAL; + } + + /* Check whether map's range coincides with device's address space */ + res = phfs_map(handler, offs, size, mAttrRead, start, end - start, attr, &addr); + if (res < 0) { + log_error("\nDevice is not mappable in %s", map); + return res; + } + + if (res == dev_isMappable) { + entry = syspage_entryAdd(NULL, addr + offs, size, SIZE_PAGE); + if (entry == NULL) { + log_error("\nCannot allocate memory for %s", name); + return -ENOMEM; + } + } + else if (res == dev_isNotMappable) { + entry = syspage_entryAdd(map, (addr_t)-1, size, SIZE_PAGE); + if (entry == NULL) { + log_error("\nCannot allocate memory for %s", name); + return -ENOMEM; + } + + /* Copy file to the selected entry */ + res = cmd_cp2ent(handler, entry); + if (res < 0) { + return res; + } + } + else { + log_error("\nDevice mappable routine failed"); + return -ENOMEM; + } + + prog = syspage_progAdd(name, 0); + if (prog == NULL) { + log_error("\nCannot add syspage program for %s", name); + } + + prog->imaps = NULL; + prog->imapSz = 0; + prog->dmaps = NULL; + prog->dmapSz = 0; + prog->start = entry->start; + prog->end = entry->end; + + return EOK; +} + + +static int cmd_blob(int argc, char *argv[]) +{ + int res; + const char *dev; + const char *name; + const char *map; + + handler_t handler; + phfs_stat_t stat; + + /* Parse command arguments */ + if (argc == 1) { + syspage_progShow(); + return CMD_EXIT_SUCCESS; + } + if (argc != 4) { + log_error("\n%s: Wrong argument count", argv[0]); + return CMD_EXIT_FAILURE; + } + + dev = argv[1]; + name = argv[2]; + map = argv[3]; + + /* Open file */ + res = phfs_open(dev, name, 0, &handler); + if (res < 0) { + log_error("\nCan't open %s on %s (%d)", name, dev, res); + return CMD_EXIT_FAILURE; + } + + /* Get file's properties */ + res = phfs_stat(handler, &stat); + if (res < 0) { + log_error("\nCan't get stat from %s (%d)", name, res); + phfs_close(handler); + return CMD_EXIT_FAILURE; + } + + res = cmd_blobLoad(handler, stat.size, name, map); + if (res < 0) { + log_error("\nCan't load %s to %s via %s (%d)", name, map, dev, res); + phfs_close(handler); + return CMD_EXIT_FAILURE; + } + + log_info("\nLoaded %s", name); + phfs_close(handler); + + return CMD_EXIT_SUCCESS; +} + + +static const cmd_t app_cmd __attribute__((section("commands"), used)) = { + .name = "blob", .run = cmd_blob, .info = cmd_blobInfo +}; diff --git a/hal/armv7a/imx6ull/Makefile b/hal/armv7a/imx6ull/Makefile index f1789f04..8e99dccb 100644 --- a/hal/armv7a/imx6ull/Makefile +++ b/hal/armv7a/imx6ull/Makefile @@ -18,7 +18,7 @@ CFLAGS:=$(filter-out -mfpu% , $(CFLAGS)) CFLAGS += -DVADDR_KERNEL_INIT=$(VADDR_KERNEL_INIT) -PLO_COMMANDS ?= alias app call console copy dump echo erase go help jffs2 kernel map mem phfs script \ +PLO_COMMANDS ?= alias app blob call console copy dump echo erase go help jffs2 kernel map mem phfs script \ test-dev test-ddr wait PLO_ALLDEVICES := nand-imx6ull flash-imx6ull uart-imx6ull usbc-cdc diff --git a/hal/armv7a/zynq7000/Makefile b/hal/armv7a/zynq7000/Makefile index e00b89b7..1ff25ba2 100644 --- a/hal/armv7a/zynq7000/Makefile +++ b/hal/armv7a/zynq7000/Makefile @@ -14,7 +14,7 @@ CFLAGS := $(filter-out -mfpu% , $(CFLAGS)) CFLAGS += -DVADDR_KERNEL_INIT=$(VADDR_KERNEL_INIT) -PLO_COMMANDS ?= alias app bitstream call console copy dump echo erase go help jffs2 kernel map mem \ +PLO_COMMANDS ?= alias app blob bitstream call console copy dump echo erase go help jffs2 kernel map mem \ phfs reboot script test-ddr test-dev wait PLO_ALLDEVICES := gpio-zynq7000 usbc-cdc uart-zynq7000 flash-zynq7000 sdcard-zynq7000 diff --git a/hal/armv7m/imxrt/10xx/105x/Makefile b/hal/armv7m/imxrt/10xx/105x/Makefile index 87ab0cb4..42e52a06 100644 --- a/hal/armv7m/imxrt/10xx/105x/Makefile +++ b/hal/armv7m/imxrt/10xx/105x/Makefile @@ -12,7 +12,7 @@ LDFLAGS:=$(filter-out -Tdata% , $(LDFLAGS)) CFLAGS:=$(filter-out -mfloat-abi% , $(CFLAGS)) CFLAGS+= -mfloat-abi=soft -PLO_COMMANDS ?= alias app call console copy dump echo erase go help kernel kernelimg map \ +PLO_COMMANDS ?= alias app blob call console copy dump echo erase go help kernel kernelimg map \ mem mpu otp phfs reboot script wait # pipe-rtt is disabled due to small amount of space in DTCM; RTT_ADDR is not defined for this architecture diff --git a/hal/armv7m/imxrt/10xx/106x/Makefile b/hal/armv7m/imxrt/10xx/106x/Makefile index 64ae2da8..9561a058 100644 --- a/hal/armv7m/imxrt/10xx/106x/Makefile +++ b/hal/armv7m/imxrt/10xx/106x/Makefile @@ -12,7 +12,7 @@ LDFLAGS:=$(filter-out -Tdata% , $(LDFLAGS)) CFLAGS:=$(filter-out -mfloat-abi% , $(CFLAGS)) CFLAGS+= -mfloat-abi=soft -PLO_COMMANDS ?= alias app bootrom call console copy dump echo erase go help kernel kernelimg map \ +PLO_COMMANDS ?= alias app bootrom blob call console copy dump echo erase go help kernel kernelimg map \ mem mpu otp phfs reboot script wait PLO_ALLDEVICES := pipe-rtt usbc-cdc uart-imxrt106x flash-imxrt diff --git a/hal/armv7m/stm32/l4/Makefile b/hal/armv7m/stm32/l4/Makefile index 94c48a96..25d54aba 100644 --- a/hal/armv7m/stm32/l4/Makefile +++ b/hal/armv7m/stm32/l4/Makefile @@ -12,7 +12,7 @@ LDFLAGS := $(filter-out -Tdata% , $(LDFLAGS)) CFLAGS := $(filter-out -mfloat-abi% , $(CFLAGS)) CFLAGS += -mfloat-abi=soft -PLO_COMMANDS ?= alias app bankswitch call console copy dump echo go help kernelimg map mem mpu \ +PLO_COMMANDS ?= alias app bankswitch blob call console copy dump echo go help kernelimg map mem mpu \ phfs reboot script wait PLO_ALLDEVICES := pipe-rtt uart-stm32l4x6 flash-stm32 ram-storage diff --git a/hal/armv8m/nrf/91/Makefile b/hal/armv8m/nrf/91/Makefile index b03472e6..5206d11a 100644 --- a/hal/armv8m/nrf/91/Makefile +++ b/hal/armv8m/nrf/91/Makefile @@ -12,7 +12,7 @@ LDFLAGS := $(filter-out -Tdata% , $(LDFLAGS)) CFLAGS := $(filter-out -mfloat-abi% , $(CFLAGS)) CFLAGS += -mfloat-abi=soft -PLO_COMMANDS ?= alias app call console copy dump echo go help kernel kernelimg map mem phfs \ +PLO_COMMANDS ?= alias app blob call console copy dump echo go help kernel kernelimg map mem phfs \ reboot script wait PLO_ALLDEVICES := uart-nrf9160 flash-nrf9160 diff --git a/hal/ia32/Makefile b/hal/ia32/Makefile index 8ab1a52c..a2b7b956 100644 --- a/hal/ia32/Makefile +++ b/hal/ia32/Makefile @@ -9,7 +9,7 @@ CFLAGS += -DVADDR_KERNEL_BASE=$(VADDR_KERNEL_BASE) CFLAGS += -Ihal/ia32 -PLO_COMMANDS ?= alias app call console copy dump echo go help kernel lspci map mem phfs script reboot syspage wait +PLO_COMMANDS ?= alias app blob call console copy dump echo go help kernel lspci map mem phfs script reboot syspage wait PLO_ALLDEVICES := disk-bios tty-bios uart-16550 diff --git a/hal/riscv64/generic/Makefile b/hal/riscv64/generic/Makefile index 364e8561..f448fa15 100644 --- a/hal/riscv64/generic/Makefile +++ b/hal/riscv64/generic/Makefile @@ -10,7 +10,7 @@ CFLAGS += -DVADDR_KERNEL_INIT=$(VADDR_KERNEL_INIT) GCCLIB := $(shell $(CC) $(CFLAGS) -print-libgcc-file-name) -PLO_COMMANDS ?= alias app call console copy dump echo go help kernel map mem phfs reboot script wait +PLO_COMMANDS ?= alias app blob call console copy dump echo go help kernel map mem phfs reboot script wait # tty-spike and uart-16550 registers under same major PLO_ALLDEVICES := ram-storage tty-spike uart-16550 diff --git a/hal/sparcv8leon3/gaisler/gr712rc/Makefile b/hal/sparcv8leon3/gaisler/gr712rc/Makefile index d8049ae5..7481554b 100644 --- a/hal/sparcv8leon3/gaisler/gr712rc/Makefile +++ b/hal/sparcv8leon3/gaisler/gr712rc/Makefile @@ -8,7 +8,7 @@ CFLAGS += -DVADDR_KERNEL_INIT=$(VADDR_KERNEL_INIT) -PLO_COMMANDS ?= alias app call console copy dump echo go help jffs2 kernel map mem phfs reboot script wait test-dev +PLO_COMMANDS ?= alias app blob call console copy dump echo go help jffs2 kernel map mem phfs reboot script wait test-dev PLO_ALLDEVICES := uart-grlib flash-gr712rc diff --git a/hal/sparcv8leon3/gaisler/gr716/Makefile b/hal/sparcv8leon3/gaisler/gr716/Makefile index c2e73c05..7bb64496 100644 --- a/hal/sparcv8leon3/gaisler/gr716/Makefile +++ b/hal/sparcv8leon3/gaisler/gr716/Makefile @@ -14,7 +14,7 @@ LDFLAGS:=$(filter-out -Wl$(comma)--section-start% , $(LDFLAGS)) 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 +PLO_COMMANDS ?= alias app blob call console copy dump echo go help kernel map mem phfs reboot script wait PLO_ALLDEVICES := gpio-gr716 uart-grlib flash-gr716