-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1061 from veremenko-y/pico_ioctl
Pi Pico IOCTL device
- Loading branch information
Showing
8 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 $< |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |