Skip to content

Commit

Permalink
Merge pull request #1061 from veremenko-y/pico_ioctl
Browse files Browse the repository at this point in the history
Pi Pico IOCTL device
  • Loading branch information
EtchedPixels authored Apr 7, 2024
2 parents c885dec + 6391b9b commit 6d281d7
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Kernel/platform/platform-rpipico/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ clean:
$(MAKE) -C ../../../Applications/cave -f Makefile.armm0 clean
$(MAKE) -C ../../../Applications/cursesgames -f Makefile.armm0 clean
$(MAKE) -C ../../../Standalone clean
$(MAKE) -C utils clean

world: build/fuzix.elf
$(MAKE) -C ../../../Library/libs -f Makefile.armm0
Expand All @@ -42,6 +43,7 @@ world: build/fuzix.elf
$(MAKE) -C ../../../Applications/cave -f Makefile.armm0
$(MAKE) -C ../../../Applications/cursesgames -f Makefile.armm0
$(MAKE) -C ../../../Standalone
$(MAKE) -C utils

uf2conv: tools/uf2conv.c
cc -O -g -o $@ $<
Expand Down
2 changes: 2 additions & 0 deletions Kernel/platform/platform-rpipico/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#define CONFIG_PLATFORM_SWAPCTL
/* Platform manages process brk. */
#define CONFIG_PLATFORM_BRK
/* Platform IOCTL on /dev/sys (maj:min)(4:6) */
#define CONFIG_DEV_PLATFORM

#define CONFIG_32BIT
#define CONFIG_USERMEM_DIRECT
Expand Down
13 changes: 13 additions & 0 deletions Kernel/platform/platform-rpipico/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#include <printf.h>
#include <exec.h>
#include "picosdk.h"
#include "pico_ioctl.h"
#include <pico/multicore.h>
#include <pico/bootrom.h>
#include <hardware/watchdog.h>

uint8_t sys_cpu = A_ARM;
Expand Down Expand Up @@ -33,6 +35,17 @@ void plt_monitor(void)
for(;;) { sleep_until(at_the_end_of_time); }
}

int plt_dev_ioctl(uarg_t request, char *data)
{
used(data);
if (request == PICOIOC_FLASH)
{
reset_usb_boot(0, 0);
return 0;
}
return -1;
}

uaddr_t pagemap_base(void)
{
return PROGBASE;
Expand Down
7 changes: 7 additions & 0 deletions Kernel/platform/platform-rpipico/pico_ioctl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef PICO_IOCTL_H
#define PICO_IOCTL_H

/* Reboot PI Pico into flash mode */
#define PICOIOC_FLASH 0x0001

#endif
11 changes: 10 additions & 1 deletion Kernel/platform/platform-rpipico/update-flash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,14 @@ mknod hdb 60660 16
mknod hdb1 60660 17
mknod hdb2 60660 18
mknod null 20666 1024
mknod mem 20660 1025
mknod kmem 20660 1025
mknod zero 20444 1026
mknod proc 20666 1027
mknod mem 20660 1028
mknod rtc 20600 1029
mknod sys 20644 1030
mknod i2c 20600 1031
mknod gpio 20600 1032
cd /
bget ../../../Applications/util/init init
Expand Down Expand Up @@ -179,6 +184,8 @@ bget ../../../Applications/util/whoami
bget ../../../Applications/util/write
bget ../../../Applications/util/xargs
bget ../../../Applications/util/yes
bget utils/pico
bget utils/picoioctl
chmod 0755 banner
chmod 0755 basename
Expand Down Expand Up @@ -265,6 +272,8 @@ chmod 0755 whoami
chmod 0755 write
chmod 0755 xargs
chmod 0755 yes
chmod 0755 pico
chmod 0755 picoioctl
ln cp mv
ln cp ln
ln reboot halt
Expand Down
24 changes: 24 additions & 0 deletions Kernel/platform/platform-rpipico/utils/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
ROOT=../../../..
FUZIX_ROOT=$(ROOT)
USERCPU=armm0
VERBOSE=1
include $(FUZIX_ROOT)/Target/rules.$(USERCPU)

UTILS = picoioctl.c
UTILSBIN = $(UTILS:.c=)

.PHONY: all clean

all: $(UTILSBIN)

clean:
rm -f *.o
rm -f $(UTILSBIN)
rm -f progbase.h
rm -f ps.c

$(UTILSBIN): %: %.o
$(LINKER) $(CRT0) $^ -o $@ $(LINKER_OPT) $(LINKER_TAIL)

%.o: %.c
$(CC) $(CFLAGS) $(CCOPTS) -c $<
17 changes: 17 additions & 0 deletions Kernel/platform/platform-rpipico/utils/pico
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
if { test $# -eq 0 || test "$1" = "--help"; }; then
echo -e "\
usage: $0 [ --help ] <commmand>\n\
Command list:\n\
\tflash\tUnmount filesystem and reboot into flash mode."
else
case $1 in
flash)
killall
umount -a
substroot remount % ro
echo "Rebooting into flash mode"
picoioctl flash
;;
*) echo "Invalid command. Use --help to list available options." ;;
esac
fi
31 changes: 31 additions & 0 deletions Kernel/platform/platform-rpipico/utils/picoioctl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include "../pico_ioctl.h"

int main(int argc, char **argv)
{
if (argc == 1 || strcmp(argv[1], "--help") == 0)
{
puts("usage: picoioctl [ --help ] <commmand>");
puts("Command list:");
puts("\tflash\tReset into flash mode.");
return 0;
}
int fd = open("/dev/sys", O_RDWR, 0);
if (!fd)
{
puts("Failed to open /dev/sys.");
exit(1);
}
if (ioctl(fd, PICOIOC_FLASH) != 0)
{
puts("Failed to perform operation.");
close(fd);
exit(1);
}
close(fd);
return 0;
}

0 comments on commit 6d281d7

Please sign in to comment.