Skip to content

Commit

Permalink
cmds: implement device driver enumeration tool
Browse files Browse the repository at this point in the history
JIRA: RTOS-848
  • Loading branch information
gerard5 committed Jun 25, 2024
1 parent 4bb5c31 commit 7ff36b5
Show file tree
Hide file tree
Showing 15 changed files with 132 additions and 20 deletions.
2 changes: 1 addition & 1 deletion cmds/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# %LICENSE%
#

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

Expand Down
73 changes: 73 additions & 0 deletions cmds/devices.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Phoenix-RTOS
*
* Operating system loader
*
* List device drivers
*
* Copyright 2024 Phoenix Systems
* Author: Gerard Swiderski
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/


#include <devices/devs.h>

#include "cmd.h"

#define DEVS_HEADER_FORMAT "%5s %5s %-10s %s"
#define DEVS_ENTRY_FORMAT "%5u %5u %-10s %s"


static void cmd_devsInfo(void)
{
lib_printf("enumerates registered device drivers");
}


static const char *devClassName(unsigned int major)
{
static const char *className[] = {
"uart", "usb", "storage", "tty", "ram", "nand-data", "nand-meta", "nand-raw", "pipe"
};

return (major < (sizeof(className) / sizeof(className[0]))) ?
className[major] :
"unknown";
}


static int cmd_devs(int argc, char *argv[])
{
unsigned int ctx = 0;
unsigned int major = 0;
unsigned int minor = 0;

if (argc != 1) {
log_error("\n%s: Wrong argument count", argv[0]);
return CMD_EXIT_FAILURE;
}

lib_printf("\n\033[1m" DEVS_HEADER_FORMAT "\033[0m\n", "MAJOR", "MINOR", "CLASS", "DRIVER NAME");

for (;;) {
const dev_t *dev = devs_iterNext(&ctx, &major, &minor);
if (dev == DEVS_ITER_STOP) {
break;
}

if (dev != NULL) {
lib_printf(DEVS_ENTRY_FORMAT "\n", major, minor, devClassName(major), dev->name);
}
}

return CMD_EXIT_SUCCESS;
}


static const cmd_t devices_cmd __attribute__((section("commands"), used)) = {
.name = "devices", .run = cmd_devs, .info = cmd_devsInfo
};
32 changes: 31 additions & 1 deletion devices/devs.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#define SIZE_MAJOR 9
#define SIZE_MINOR 16


struct {
const dev_t *devs[SIZE_MAJOR][SIZE_MINOR];
} devs_common;
Expand Down Expand Up @@ -62,6 +61,37 @@ void devs_init(void)
}
}


const dev_t *devs_iterNext(unsigned int *ctx, unsigned int *major, unsigned int *minor)
{
unsigned int currMajor, currMinor;

if ((ctx == NULL) || (major == NULL) || (minor == NULL)) {
return NULL;
}

currMajor = ((*ctx >> 16) & 0xffff);
currMinor = (*ctx & 0xffff);
while (currMajor < SIZE_MAJOR) {
while (currMinor < SIZE_MINOR) {
const dev_t *dev = devs_common.devs[currMajor][currMinor];

*major = currMajor;
*minor = currMinor++;
*ctx = (*ctx & ~0xffff) + currMinor;

return dev;
}
currMajor++;
currMinor = 0;
*ctx = (*ctx & 0xffff) | (currMajor << 16);
}

/* Iterator has finished enumerating */
return DEVS_ITER_STOP;
}


static const dev_t *devs_get(unsigned int major, unsigned int minor)
{
return ((major < SIZE_MAJOR) && (minor < SIZE_MINOR)) ?
Expand Down
5 changes: 5 additions & 0 deletions devices/devs.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#define DEV_NAND_RAW 7
#define DEV_PIPE 8

#define DEVS_ITER_STOP ((const dev_t *)-1)

/* clang-format off */
enum { dev_isMappable = 0, dev_isNotMappable };
Expand Down Expand Up @@ -63,6 +64,10 @@ extern void devs_register(unsigned int major, unsigned int nb, const dev_t *dev)
extern void devs_init(void);


/* Enumerate all devices */
const dev_t *devs_iterNext(unsigned int *ctx, unsigned int *major, unsigned int *minor);


/* Check whether device is available */
extern int devs_check(unsigned int major, unsigned int minor);

Expand Down
4 changes: 2 additions & 2 deletions hal/armv7a/imx6ull/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ CFLAGS:=$(filter-out -mfpu% , $(CFLAGS))

CFLAGS += -DVADDR_KERNEL_INIT=$(VADDR_KERNEL_INIT)

PLO_COMMANDS ?= alias app blob call console copy dump echo erase go help jffs2 kernel map mem phfs script \
stop test-dev test-ddr wait
PLO_COMMANDS ?= alias app blob call console copy devices dump echo erase go help jffs2 kernel map mem phfs \
script stop test-dev test-ddr wait

PLO_ALLDEVICES := nand-imx6ull flash-imx6ull uart-imx6ull usbc-cdc

Expand Down
4 changes: 2 additions & 2 deletions hal/armv7a/zynq7000/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ CFLAGS := $(filter-out -mfpu% , $(CFLAGS))

CFLAGS += -DVADDR_KERNEL_INIT=$(VADDR_KERNEL_INIT)

PLO_COMMANDS ?= alias app blob bitstream call console copy dump echo erase go help jffs2 kernel map mem \
phfs reboot script stop test-ddr test-dev wait
PLO_COMMANDS ?= alias app bitstream blob call console copy devices dump echo erase go help jffs2 kernel \
map mem phfs reboot script stop test-ddr test-dev wait

PLO_ALLDEVICES := gpio-zynq7000 usbc-cdc uart-zynq7000 flash-zynq7000 sdcard-zynq7000

Expand Down
4 changes: 2 additions & 2 deletions hal/armv7m/imxrt/10xx/105x/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ LDFLAGS:=$(filter-out -Tdata% , $(LDFLAGS))
CFLAGS:=$(filter-out -mfloat-abi% , $(CFLAGS))
CFLAGS+= -mfloat-abi=soft

PLO_COMMANDS ?= alias app blob call console copy dump echo erase go help kernel kernelimg map \
mem mpu otp phfs reboot script stop wait
PLO_COMMANDS ?= alias app blob call console copy devices dump echo erase go help kernel \
kernelimg map mem mpu otp phfs reboot script stop wait

# pipe-rtt is disabled due to small amount of space in DTCM; RTT_ADDR is not defined for this architecture
PLO_ALLDEVICES := usbc-cdc uart-imxrt106x flash-imxrt
Expand Down
4 changes: 2 additions & 2 deletions hal/armv7m/imxrt/10xx/106x/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ LDFLAGS:=$(filter-out -Tdata% , $(LDFLAGS))
CFLAGS:=$(filter-out -mfloat-abi% , $(CFLAGS))
CFLAGS+= -mfloat-abi=soft

PLO_COMMANDS ?= alias app bootrom blob call console copy dump echo erase go help kernel kernelimg map \
mem mpu otp phfs reboot script stop wait
PLO_COMMANDS ?= alias app blob bootrom call console copy devices dump echo erase go help kernel \
kernelimg map mem mpu otp phfs reboot script stop wait

PLO_ALLDEVICES := pipe-rtt usbc-cdc uart-imxrt106x flash-imxrt

Expand Down
4 changes: 2 additions & 2 deletions hal/armv7m/imxrt/117x/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ LDFLAGS := $(filter-out -Tdata% , $(LDFLAGS))
CFLAGS := $(filter-out -mfloat-abi% , $(CFLAGS))
CFLAGS += -mfloat-abi=soft

PLO_COMMANDS ?= alias app blob bootcm4 bootrom call console copy dump echo erase go help kernel kernelimg \
map mem mpu otp phfs reboot script stop wait
PLO_COMMANDS ?= alias app blob bootcm4 bootrom call console copy devices dump echo erase go help \
kernel kernelimg map mem mpu otp phfs reboot script stop wait

PLO_ALLDEVICES := pipe-rtt usbc-cdc uart-imxrt117x flash-imxrt

Expand Down
4 changes: 2 additions & 2 deletions hal/armv7m/stm32/l4/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ LDFLAGS := $(filter-out -Tdata% , $(LDFLAGS))
CFLAGS := $(filter-out -mfloat-abi% , $(CFLAGS))
CFLAGS += -mfloat-abi=soft

PLO_COMMANDS ?= alias app bankswitch blob call console copy dump echo go help kernelimg map mem mpu \
phfs reboot script stop wait
PLO_COMMANDS ?= alias app bankswitch blob call console copy devices dump echo go help kernelimg \
map mem mpu phfs reboot script stop wait

PLO_ALLDEVICES := pipe-rtt uart-stm32l4x6 flash-stm32 ram-storage

Expand Down
4 changes: 2 additions & 2 deletions hal/armv8m/nrf/91/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ LDFLAGS := $(filter-out -Tdata% , $(LDFLAGS))
CFLAGS := $(filter-out -mfloat-abi% , $(CFLAGS))
CFLAGS += -mfloat-abi=soft

PLO_COMMANDS ?= alias app blob call console copy dump echo go help kernel kernelimg map mem phfs \
reboot script stop wait
PLO_COMMANDS ?= alias app blob call console copy devices dump echo go help kernel kernelimg map \
mem phfs reboot script stop wait

PLO_ALLDEVICES := uart-nrf9160 flash-nrf9160

Expand Down
3 changes: 2 additions & 1 deletion hal/ia32/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
CFLAGS += -DVADDR_KERNEL_BASE=$(VADDR_KERNEL_BASE)
CFLAGS += -Ihal/ia32

PLO_COMMANDS ?= alias app blob call console copy dump echo go help kernel lspci map mem phfs script reboot stop syspage wait
PLO_COMMANDS ?= alias app blob call console copy devices dump echo go help kernel lspci map mem \
phfs script reboot stop syspage wait

PLO_ALLDEVICES := disk-bios tty-bios uart-16550

Expand Down
3 changes: 2 additions & 1 deletion hal/riscv64/generic/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ CFLAGS += -DVADDR_KERNEL_INIT=$(VADDR_KERNEL_INIT)

GCCLIB := $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)

PLO_COMMANDS ?= alias app blob call console copy dump echo go help kernel map mem phfs reboot script stop wait
PLO_COMMANDS ?= alias app blob call console copy devices dump echo go help kernel \
map mem phfs reboot script stop wait

# tty-spike and uart-16550 registers under same major
PLO_ALLDEVICES := ram-storage tty-spike uart-16550
Expand Down
3 changes: 2 additions & 1 deletion hal/sparcv8leon3/gaisler/gr712rc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

CFLAGS += -DVADDR_KERNEL_INIT=$(VADDR_KERNEL_INIT)

PLO_COMMANDS ?= alias app blob call console copy dump echo go help jffs2 kernel map mem phfs reboot script stop wait test-dev
PLO_COMMANDS ?= alias app blob call console copy devices dump echo go help jffs2 kernel map mem phfs \
reboot script stop wait test-dev

PLO_ALLDEVICES := uart-grlib flash-gr712rc

Expand Down
3 changes: 2 additions & 1 deletion hal/sparcv8leon3/gaisler/gr716/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ LDFLAGS:=$(filter-out -Wl$(comma)--section-start% , $(LDFLAGS))

CFLAGS += -DVADDR_KERNEL_INIT=$(VADDR_KERNEL_INIT)

PLO_COMMANDS ?= alias app blob call console copy dump echo go help kernel map mem phfs reboot script stop wait
PLO_COMMANDS ?= alias app blob call console copy devices dump echo go help kernel map mem phfs reboot \
script stop wait

PLO_ALLDEVICES := gpio-gr716 uart-grlib flash-gr716

Expand Down

0 comments on commit 7ff36b5

Please sign in to comment.