Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmds/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#

PLO_ALLCOMMANDS = alias app bankswitch bitstream blob bootcm4 bootrom bridge call console \
copy devices dump echo erase go help jffs2 kernel kernelimg lspci map mem mpu otp phfs \
ptable reboot script stop test-dev test-ddr wait watchdog vbe
copy devices dump echo erase go help jffs2 kernel kernelimg lspci map mem mpu otp part phfs \
ptable reboot sched script stop test-dev test-ddr wait watchdog vbe

PLO_COMMANDS ?= $(PLO_ALLCOMMANDS)
PLO_APPLETS = $(filter $(PLO_ALLCOMMANDS), $(PLO_COMMANDS))
Expand Down
71 changes: 67 additions & 4 deletions cmds/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,49 @@ static size_t cmd_mapsParse(char *maps, char sep)
}


static int cmd_appLoad(handler_t handler, size_t size, const char *name, char *imaps, char *dmaps, const char *appArgv, u32 flags)
static int cmd_partitionCreate(const char *name, syspage_part_t **part, char *imaps, size_t imapSz, char *dmaps, size_t dmapSz)
{
int res;
syspage_part_t *partition;

partition = syspage_partAdd();
if (partition == NULL) {
log_error("\nCannot allocate memory for %s", name);
return -ENOMEM;
}

partition->allocMaps = syspage_alloc(sizeof(u8));
partition->accessMaps = syspage_alloc((imapSz + dmapSz - 1) * sizeof(u8));
partition->name = syspage_alloc(hal_strlen(name) + 1);
if ((partition->allocMaps == NULL) ||
(partition->accessMaps == NULL) ||
(partition->name == NULL)) {
log_error("\nCannot allocate memory for %s", name);
return -ENOMEM;
}

cmd_mapsAdd2Prog(partition->allocMaps, 1, dmaps);
cmd_mapsAdd2Prog(partition->accessMaps, dmapSz - 1, dmaps + (hal_strlen(dmaps) + 1));
cmd_mapsAdd2Prog(partition->accessMaps + dmapSz - 1, imapSz, imaps);
partition->allocMapSz = 1;
partition->accessMapSz = imapSz + dmapSz - 1;
partition->availableMem = (size_t)-1;
partition->usedMem = 0;
partition->flags = pFlagIPCAll | pFlagSpawnAll; /* For backwards compatibility */
partition->schedWindowsMask = 1U;
hal_strcpy(partition->name, name);

res = hal_getPartData(partition, imaps, imapSz, dmaps, dmapSz);
if (res < 0) {
return res;
}
*part = partition;

return EOK;
}


static int cmd_appLoad(handler_t handler, size_t size, const char *name, char *imaps, char *dmaps, const char *appArgv, u32 flags, char *partName)
{
int res;
Elf32_Ehdr hdr;
Expand All @@ -92,6 +134,7 @@ static int cmd_appLoad(handler_t handler, size_t size, const char *name, char *i

syspage_prog_t *prog;
const mapent_t *entry;
syspage_part_t *partition;

/* Check ELF header */
if ((res = phfs_read(handler, 0, &hdr, sizeof(Elf32_Ehdr))) < 0) {
Expand Down Expand Up @@ -144,6 +187,16 @@ static int cmd_appLoad(handler_t handler, size_t size, const char *name, char *i
return -ENOMEM;
}

if (partName == NULL) {
if ((res = cmd_partitionCreate(name, &partition, imaps, imapSz, dmaps, dmapSz)) != EOK) {
return res;
}
}
else if (syspage_partResolve(partName, &partition) != EOK) {
log_error("\nPartition `%s` does not exist!", partName);
return -EINVAL;
}

if ((prog = syspage_progAdd(appArgv, flags)) == NULL ||
(prog->imaps = syspage_alloc(imapSz * sizeof(u8))) == NULL ||
(prog->dmaps = syspage_alloc(dmapSz * sizeof(u8))) == NULL) {
Expand All @@ -160,6 +213,7 @@ static int cmd_appLoad(handler_t handler, size_t size, const char *name, char *i
prog->dmapSz = dmapSz;
prog->start = entry->start;
prog->end = entry->end;
prog->partition = partition;

return EOK;
}
Expand All @@ -175,6 +229,7 @@ static int cmd_app(int argc, char *argv[])

const char *appArgv;
char name[SIZE_CMD_ARG_LINE];
char *part;

handler_t handler;
phfs_stat_t stat;
Expand All @@ -184,7 +239,7 @@ static int cmd_app(int argc, char *argv[])
syspage_progShow();
return CMD_EXIT_SUCCESS;
}
else if (argc < 5 || argc > 6) {
else if (argc < 5 || argc > 7) {
log_error("\n%s: Wrong argument count", argv[0]);
return CMD_EXIT_FAILURE;
}
Expand All @@ -210,7 +265,7 @@ static int cmd_app(int argc, char *argv[])
}
}

if (argvID != (argc - 3)) {
if (argvID > (argc - 3)) {
log_error("\n%s: Invalid arg, 'dmap' is not declared", argv[0]);
return CMD_EXIT_FAILURE;
}
Expand All @@ -231,6 +286,14 @@ static int cmd_app(int argc, char *argv[])
/* ARG_5: maps for data */
dmaps = argv[++argvID];

/* ARG_6: partition name */
if (argc > ++argvID) {
part = argv[argvID];
}
else {
part = NULL;
}

/* Open file */
res = phfs_open(argv[1], name, 0, &handler);
if (res < 0) {
Expand All @@ -246,7 +309,7 @@ static int cmd_app(int argc, char *argv[])
return CMD_EXIT_FAILURE;
}

res = cmd_appLoad(handler, stat.size, name, imaps, dmaps, appArgv, flags);
res = cmd_appLoad(handler, stat.size, name, imaps, dmaps, appArgv, flags, part);
if (res < 0) {
log_error("\nCan't load %s to %s via %s (%d)", name, imaps, argv[1], res);
phfs_close(handler);
Expand Down
64 changes: 34 additions & 30 deletions cmds/mpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,54 +82,58 @@ static void mpu_regionPrint(const char *name, u32 rbar, u32 rasr)

static void cmd_mpuInfo(void)
{
lib_printf("prints the use of MPU regions, usage: mpu [all]");
lib_printf("prints the use of MPU regions, usage: mpu [partition name]");
}


static int cmd_mpu(int argc, char *argv[])
{
const char *name;
unsigned int i, regCnt;
const mpu_region_t *region;
const mpu_common_t *const mpu_common = mpu_getCommon();
unsigned int i;
const syspage_part_t *part = syspage_partsGet();
const syspage_part_t *firstPart = part;
const unsigned int regMax = mpu_getMaxRegionsCount();

if (argc == 1) {
regCnt = mpu_common->regCnt;
}
else if (argc == 2) {
if (hal_strcmp(argv[1], "all") != 0) {
log_error("\n%s: Wrong arguments", argv[0]);
return CMD_EXIT_FAILURE;
}

regCnt = mpu_common->regMax;
}
else {
log_error("\n%s: Wrong argument count", argv[0]);
if (part == NULL) {
log_error("\nNo partitions in syspage!");
return CMD_EXIT_FAILURE;
}

if (mpu_common->regMax != sizeof(((hal_syspage_t *)0)->mpu.table) / sizeof(((hal_syspage_t *)0)->mpu.table[0])) {
log_error("\n%s: MPU hal is not initialized or unsupported type was detected", argv[0]);
if (argc > 2) {
log_error("\n%s: Wrong argument count", argv[0]);
return CMD_EXIT_FAILURE;
}

lib_printf(CONSOLE_BOLD "\n%-9s %-7s %-4s %-11s %-11s %-3s %-3s %-9s %-4s %-2s %-2s %-2s\n" CONSOLE_NORMAL,
"MAP NAME", "REGION", "SUB", "START", "END", "EN", "XN", "PERM P/U", "TEX", "S", "C", "B");
do {
name = part->name;
if ((argc == 2) && (hal_strcmp(name, argv[1]) != 0)) {
part = part->next;
continue;
}
lib_printf("\n%-16s", name);
lib_printf(CONSOLE_BOLD "\n%-9s %-7s %-4s %-11s %-11s %-3s %-3s %-9s %-4s %-2s %-2s %-2s\n" CONSOLE_NORMAL,
"MAP NAME", "REGION", "SUB", "START", "END", "EN", "XN", "PERM P/U", "TEX", "S", "C", "B");
for (i = 0; i < part->hal.mpu.allocCnt; i++) {
name = syspage_mapName(part->hal.mpu.map[i]);
if (name == NULL) {
name = "<none>";
}
mpu_regionPrint(name, part->hal.mpu.table[i].rbar, part->hal.mpu.table[i].rasr);
}

for (i = 0; i < regCnt; i++) {
region = &mpu_common->region[i];
name = syspage_mapName(mpu_common->mapId[i]);
lib_printf("Configured %d of %d MPU regions.\n", part->hal.mpu.allocCnt, regMax);

if (name == NULL) {
name = "<none>";
if (argc == 2) {
return CMD_EXIT_SUCCESS;
}

mpu_regionPrint(name, region->rbar, region->rasr);
}
part = part->next;
} while (part != firstPart);

lib_printf("\nConfigured %d of %d MPU regions based on %d map definitions.\n",
mpu_common->regCnt, mpu_common->regMax, mpu_common->mapCnt);
if (argc == 2) {
log_error("\nPartition %s not found in syspage!", argv[1]);
return CMD_EXIT_FAILURE;
}

return CMD_EXIT_SUCCESS;
}
Expand Down
Loading
Loading