From 2482d2165ce0948b009a5a82624c5eb870d78b36 Mon Sep 17 00:00:00 2001 From: Yaroslav Veremenko Date: Fri, 1 Nov 2024 16:53:19 -0600 Subject: [PATCH 1/7] rpipico: sd card fast speed --- Kernel/platform/platform-rpipico/devsdspi.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Kernel/platform/platform-rpipico/devsdspi.c b/Kernel/platform/platform-rpipico/devsdspi.c index e4f392e2a1..e1b7d7c7a2 100644 --- a/Kernel/platform/platform-rpipico/devsdspi.c +++ b/Kernel/platform/platform-rpipico/devsdspi.c @@ -46,6 +46,9 @@ #endif +#define SLOW_SPEED 250000 +#define FAST_SPEED 4000000 + void sd_rawinit(void) { //initilase GPIO ports @@ -62,13 +65,15 @@ void sd_rawinit(void) gpio_set_dir(Pico_SD_CS, true); //initalise SPI module - spi_init(Pico_SD_SPI_MOD, 250000); + + spi_init(Pico_SD_SPI_MOD, SLOW_SPEED); spi_set_format(Pico_SD_SPI_MOD, 8, 0, 0, SPI_MSB_FIRST); } void sd_spi_clock(bool go_fast) { - spi_set_baudrate(Pico_SD_SPI_MOD, 250000); + spi_set_baudrate(Pico_SD_SPI_MOD, + go_fast ? FAST_SPEED : SLOW_SPEED); } void sd_spi_raise_cs(void) From bba974fdd27b74366fe7c35dac258e8c24ef5385 Mon Sep 17 00:00:00 2001 From: Yaroslav Veremenko Date: Fri, 1 Nov 2024 16:58:49 -0600 Subject: [PATCH 2/7] rpipico: added missing sys_close --- Kernel/platform/platform-rpipico/devices.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Kernel/platform/platform-rpipico/devices.c b/Kernel/platform/platform-rpipico/devices.c index 2e35f6ec0c..870bb35735 100644 --- a/Kernel/platform/platform-rpipico/devices.c +++ b/Kernel/platform/platform-rpipico/devices.c @@ -26,7 +26,7 @@ struct devsw dev_tab[] = /* The device driver switch table */ /* 3: /dev/lpr Printer devices */ { no_open, no_close, no_rdwr, no_rdwr, no_ioctl }, /* 4: /dev/mem etc System devices (one offs) */ - { no_open, no_close, sys_read, sys_write, sys_ioctl }, + { no_open, sys_close, sys_read, sys_write, sys_ioctl }, /* Pack to 7 with nxio if adding private devices and start at 8 */ }; From c99b824300c800ae20618f3a89408394a26bcbd4 Mon Sep 17 00:00:00 2001 From: Yaroslav Veremenko Date: Fri, 1 Nov 2024 16:59:34 -0600 Subject: [PATCH 3/7] rpipico: fixed swapper return value causing issues --- Kernel/platform/platform-rpipico/swapper.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Kernel/platform/platform-rpipico/swapper.c b/Kernel/platform/platform-rpipico/swapper.c index 71eb209539..4d959c9932 100644 --- a/Kernel/platform/platform-rpipico/swapper.c +++ b/Kernel/platform/platform-rpipico/swapper.c @@ -32,6 +32,7 @@ static uint8_t get_slot(ptptr p) uint8_t slot = p - ptab; if (slot >= PTABSIZE) panic("bad ptab"); + return slot; } static uaddr_t get_proc_size(ptptr p) From 6419209a72edc2ac288b6e93bde59879b3d501ed Mon Sep 17 00:00:00 2001 From: Yaroslav Veremenko Date: Fri, 1 Nov 2024 16:59:46 -0600 Subject: [PATCH 4/7] rpipico: rudimentary rp2350 support Date: Fri Nov 1 16:55:35 2024 -0600 --- Kernel/platform/platform-rpipico/Makefile | 17 +++++++++++++---- Kernel/platform/platform-rpipico/devices.c | 1 - .../platform/platform-rpipico/update-flash.sh | 4 ---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Kernel/platform/platform-rpipico/Makefile b/Kernel/platform/platform-rpipico/Makefile index b5cac1092c..5ce9f2bb57 100644 --- a/Kernel/platform/platform-rpipico/Makefile +++ b/Kernel/platform/platform-rpipico/Makefile @@ -1,6 +1,18 @@ # Set one of these depending. export PICO_SDK_FETCH_FROM_GIT = yes #export PICO_SDK_PATH = ${HOME}/.pico-sdk/sdk/1.5.1 +#export PICO_SDK_PATH = ${HOME}/doclocal/pico-sdk +SUBTARGET=pico + +# Set 'SUBTARGET' to one of pico-sdk compatible boards +ifndef SUBTARGET +$(error "Must set SUBTARGET to pico, pico_w or pico2") +endif + +FSFAMILY=rp2040 +ifeq (SUBTARGET, 'pico2') +FSFAMILY=data +endif include ../../../version.mk @@ -12,7 +24,7 @@ build/fuzix.elf: ../../version.c build/Makefile build/Makefile: CMakeLists.txt $(wildcard ../../*.[chS]) $(wildcard ../../*/*.[chS]) mkdir -p build - (cd build && cmake ..) + (cd build && cmake -DPICO_BOARD=${SUBTARGET} ..) image:: world uf2conv ./update-flash.sh @@ -20,9 +32,6 @@ image:: world uf2conv arm-none-eabi-objcopy -I binary -O elf32-littlearm --change-section-vma .data=0x10018000 filesystem.ftl filesystem.elf ./uf2conv filesystem.ftl filesystem.uf2 0x10018000 -image-sd:: world uf2conv - ./update-flash.sh sd - diskimage: clean: diff --git a/Kernel/platform/platform-rpipico/devices.c b/Kernel/platform/platform-rpipico/devices.c index 870bb35735..a47d294517 100644 --- a/Kernel/platform/platform-rpipico/devices.c +++ b/Kernel/platform/platform-rpipico/devices.c @@ -10,7 +10,6 @@ #include "globals.h" #include "picosdk.h" #include -#include #include "core1.h" struct devsw dev_tab[] = /* The device driver switch table */ diff --git a/Kernel/platform/platform-rpipico/update-flash.sh b/Kernel/platform/platform-rpipico/update-flash.sh index c68acfc5b7..31ba461035 100755 --- a/Kernel/platform/platform-rpipico/update-flash.sh +++ b/Kernel/platform/platform-rpipico/update-flash.sh @@ -5,10 +5,6 @@ IMG=filesystem.img FSSIZE=2547 -if [ "$1" = "sd" ]; then - FSSIZE=65535 -fi - rm -f ${IMG} ../../../Standalone/mkfs ${IMG} 32 $FSSIZE ../../../Standalone/ucp ${IMG} < Date: Wed, 6 Nov 2024 19:14:57 -0700 Subject: [PATCH 5/7] rpipico: removed uf2conv in favour of picotool picotool is already required for pico-sdk, and allows easy support for rp2350 --- Kernel/platform/platform-rpipico/Makefile | 14 ++-- .../platform/platform-rpipico/tools/uf2conv.c | 73 ------------------ .../platform-rpipico/tools/uf2format.h | 77 ------------------- 3 files changed, 7 insertions(+), 157 deletions(-) delete mode 100644 Kernel/platform/platform-rpipico/tools/uf2conv.c delete mode 100644 Kernel/platform/platform-rpipico/tools/uf2format.h diff --git a/Kernel/platform/platform-rpipico/Makefile b/Kernel/platform/platform-rpipico/Makefile index 5ce9f2bb57..e6f68f1ca1 100644 --- a/Kernel/platform/platform-rpipico/Makefile +++ b/Kernel/platform/platform-rpipico/Makefile @@ -14,6 +14,12 @@ ifeq (SUBTARGET, 'pico2') FSFAMILY=data endif +PICOTOOL=picotool + +ifeq (, $(shell which picotool)) +PICOTOOL=build/_deps/picotool/picotool +endif + include ../../../version.mk build/fuzix.elf: ../../version.c build/Makefile @@ -26,11 +32,9 @@ build/Makefile: CMakeLists.txt $(wildcard ../../*.[chS]) $(wildcard ../../*/*.[c mkdir -p build (cd build && cmake -DPICO_BOARD=${SUBTARGET} ..) -image:: world uf2conv +image:: world ./update-flash.sh ../../../Standalone/mkftl -s 1952 -e 0x1000 -g 10 filesystem.img -o filesystem.ftl - arm-none-eabi-objcopy -I binary -O elf32-littlearm --change-section-vma .data=0x10018000 filesystem.ftl filesystem.elf - ./uf2conv filesystem.ftl filesystem.uf2 0x10018000 diskimage: @@ -59,7 +63,3 @@ world: build/fuzix.elf $(MAKE) -C ../../../Applications/cursesgames -f Makefile.armm0 $(MAKE) -C ../../../Standalone $(MAKE) -C utils - -uf2conv: tools/uf2conv.c - cc -O -g -o $@ $< - diff --git a/Kernel/platform/platform-rpipico/tools/uf2conv.c b/Kernel/platform/platform-rpipico/tools/uf2conv.c deleted file mode 100644 index db89cf2f9d..0000000000 --- a/Kernel/platform/platform-rpipico/tools/uf2conv.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - * MIT License - * - * Copyright (c) Microsoft Corporation. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE - */ - -#include -#include -#include -#include "uf2format.h" - -int main(int argc, char **argv) { - if (argc != 4) { - fprintf(stderr, "USAGE: %s file.bin file.uf2 address\n", argv[0]); - return 1; - } - FILE *f = fopen(argv[1], "rb"); - if (!f) { - fprintf(stderr, "No such file: %s\n", argv[1]); - return 1; - } - - fseek(f, 0L, SEEK_END); - uint32_t sz = ftell(f); - fseek(f, 0L, SEEK_SET); - - const char *outname = argc > 2 ? argv[2] : "flash.uf2"; - - FILE *fout = fopen(argv[2], "wb"); - uint32_t address = strtoul(argv[3], NULL, 0); - - UF2_Block bl; - memset(&bl, 0, sizeof(bl)); - - bl.magicStart0 = UF2_MAGIC_START0; - bl.magicStart1 = UF2_MAGIC_START1; - bl.magicEnd = UF2_MAGIC_END; - bl.flags = UF2_FLAG_FAMILY_ID_PRESENT; - bl.fileSize = RP2040_FAMILY_ID; - bl.targetAddr = address; - bl.numBlocks = (sz + 255) / 256; - bl.payloadSize = 256; - int numbl = 0; - while (fread(bl.data, 1, bl.payloadSize, f)) { - bl.blockNo = numbl++; - fwrite(&bl, 1, sizeof(bl), fout); - bl.targetAddr += bl.payloadSize; - // clear for next iteration, in case we get a short read - memset(bl.data, 0, sizeof(bl.data)); - } - fclose(fout); - fclose(f); - printf("Wrote %d blocks to %s\n", numbl, outname); - return 0; -} diff --git a/Kernel/platform/platform-rpipico/tools/uf2format.h b/Kernel/platform/platform-rpipico/tools/uf2format.h deleted file mode 100644 index d8beb1c74c..0000000000 --- a/Kernel/platform/platform-rpipico/tools/uf2format.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * MIT License - * - * Copyright (c) Microsoft Corporation. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE - */ - -#ifndef UF2FORMAT_H -#define UF2FORMAT_H 1 - -#include -#include - -// All entries are little endian. - -// if you increase that, you will also need to update the linker script file -#define APP_START_ADDRESS 0x00002000 - -#define UF2_MAGIC_START0 0x0A324655UL // "UF2\n" -#define UF2_MAGIC_START1 0x9E5D5157UL // Randomly selected -#define UF2_MAGIC_END 0x0AB16F30UL // Ditto - -// If set, the block is "comment" and should not be flashed to the device -#define UF2_FLAG_NOFLASH 0x00000001 -#define UF2_FLAG_FILE 0x00001000 -#define UF2_FILENAME_MAX 150 -#define UF2_MAX_PAYLOAD (476 - 10) // leaving some space for filename -// for this bootloader -#define UF2_MAX_FILESIZE (64 * 1024 * 1024) - -#define UF2_FLAG_FAMILY_ID_PRESENT 0x00002000u -#define UF2_FLAG_MD5_PRESENT 0x00004000u - -#define RP2040_FAMILY_ID 0xe48bff56 - -typedef struct { - // 32 byte header - uint32_t magicStart0; - uint32_t magicStart1; - uint32_t flags; - uint32_t targetAddr; - uint32_t payloadSize; - uint32_t blockNo; - uint32_t numBlocks; - uint32_t fileSize; - - // raw data, followed by filename (NUL-terminated) at payloadSize - uint8_t data[476]; - - // store magic also at the end to limit damage from partial block reads - uint32_t magicEnd; -} UF2_Block; - -static inline bool is_uf2_block(void *data) { - UF2_Block *bl = (UF2_Block *)data; - return bl->magicStart0 == UF2_MAGIC_START0 && bl->magicStart1 == UF2_MAGIC_START1 && - bl->magicEnd == UF2_MAGIC_END; -} - -#endif From a3f4fd8d55e4543b2f80c234396cb7425cb19a97 Mon Sep 17 00:00:00 2001 From: Yaroslav Veremenko Date: Mon, 28 Oct 2024 13:33:07 -0600 Subject: [PATCH 6/7] net: added missing extern --- Kernel/syscall_net.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Kernel/syscall_net.c b/Kernel/syscall_net.c index 81556045eb..0ef8e75a64 100644 --- a/Kernel/syscall_net.c +++ b/Kernel/syscall_net.c @@ -13,6 +13,7 @@ #ifdef CONFIG_NET +extern void netdev_init(void); #define N_MAKE 0x80 #define N_SOCKFD 0x40 From b886d1fad1d42aa8db7406dc98f05fcdadff6544 Mon Sep 17 00:00:00 2001 From: Yaroslav Veremenko Date: Mon, 28 Oct 2024 13:36:07 -0600 Subject: [PATCH 7/7] rpipico: rudimentary net support --- Kernel/platform/platform-rpipico/CMakeLists.txt | 3 +++ Kernel/platform/platform-rpipico/config.h | 15 ++++++++++++++- Kernel/platform/platform-rpipico/devices.c | 7 +++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Kernel/platform/platform-rpipico/CMakeLists.txt b/Kernel/platform/platform-rpipico/CMakeLists.txt index 765a1bd07e..0081014c4a 100644 --- a/Kernel/platform/platform-rpipico/CMakeLists.txt +++ b/Kernel/platform/platform-rpipico/CMakeLists.txt @@ -71,6 +71,9 @@ add_executable(fuzix ../../tty.c ../../usermem.c ../../version.c + ../../dev/net/net_native.c + ../../syscall_net.c + ../../network.c ) target_link_libraries(fuzix diff --git a/Kernel/platform/platform-rpipico/config.h b/Kernel/platform/platform-rpipico/config.h index fe3ba9f37a..e7260099d3 100644 --- a/Kernel/platform/platform-rpipico/config.h +++ b/Kernel/platform/platform-rpipico/config.h @@ -28,6 +28,9 @@ #undef CONFIG_IDUMP /* Enable to make ^A drop back into the monitor */ #undef CONFIG_MONITOR +/* Enable to support network stack */ +#undef CONFIG_NET +#undef CONFIG_NET_NATIVE /* Profil syscall support (not yet complete) */ #undef CONFIG_PROFIL /* Multiple processes in memory at once */ @@ -68,7 +71,17 @@ #define UDATA_BLKS 3 #define UDATA_SIZE (UDATA_BLKS << BLKSHIFT) -#define USERMEM (160*1024) + +#define TOTALMEM 160 +#define NETMEM 0 + +#ifdef CONFIG_NET +#undef NETMEM +#define NETMEM 10 +#endif + +#define USERMEM ((TOTALMEM-NETMEM)*1024) + #define PROGSIZE (65536 - UDATA_SIZE) extern uint8_t progbase[USERMEM]; #define udata (*(struct u_data*)progbase) diff --git a/Kernel/platform/platform-rpipico/devices.c b/Kernel/platform/platform-rpipico/devices.c index a47d294517..569b99a141 100644 --- a/Kernel/platform/platform-rpipico/devices.c +++ b/Kernel/platform/platform-rpipico/devices.c @@ -62,6 +62,10 @@ static void timer_tick_cb(unsigned alarm) irqrestore(irq); } +#ifdef CONFIG_NET +extern void netdev_init(void); +#endif + void device_init(void) { /* Timer interrup must be initialized before blcok devices. @@ -75,6 +79,9 @@ void device_init(void) * cause a crash on startup... oddly. */ #ifdef CONFIG_PICO_FLASH flash_dev_init(); +#endif +#ifdef CONFIG_NET + netdev_init(); #endif sd_rawinit(); devsd_init();