diff --git a/.github/workflows/build-firmware.yaml b/.github/workflows/build-firmware.yaml index c7db4975ab..d9d3911105 100644 --- a/.github/workflows/build-firmware.yaml +++ b/.github/workflows/build-firmware.yaml @@ -89,10 +89,16 @@ jobs: - uses: actions/checkout@v1 with: submodules: recursive + - uses: actions/setup-java@v1 with: java-version: '8' + - name: Install multilib, mingw, ncftp and mtools + run: | + sudo apt-get update + sudo apt-get install gcc-multilib g++-multilib g++-mingw-w64 gcc-mingw-w64 ncftp mtools + - name: Generate Configs if: ${{ matrix.skip-config != 'yes' }} working-directory: ./firmware/ @@ -137,12 +143,6 @@ jobs: - name: Test Compiler run: arm-none-eabi-gcc -v - - name: Install multilib, mingw, and ncftp - run: | - sudo apt-get update - sudo apt-get install gcc-multilib g++-multilib g++-mingw-w64 gcc-mingw-w64 ncftp - - - name: Configs Set FTP variables env: ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true' diff --git a/firmware/Makefile b/firmware/Makefile index d8a03f55b2..a7745796e8 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -202,6 +202,7 @@ $(info LDSCRIPT: $(LDSCRIPT)) # setting. CSRC = $(ALLCSRC) \ $(CHIBIOS)/os/various/syscalls.c \ + $(CHIBIOS_CONTRIB)/os/various/ramdisk.c \ $(TRIGGER_SRC) \ $(TRIGGER_DECODERS_SRC) \ $(DEV_SRC) \ diff --git a/firmware/config/stm32f4ems/efifeatures.h b/firmware/config/stm32f4ems/efifeatures.h index fa26a70407..74bde654de 100644 --- a/firmware/config/stm32f4ems/efifeatures.h +++ b/firmware/config/stm32f4ems/efifeatures.h @@ -253,6 +253,10 @@ #define EFI_FILE_LOGGING TRUE #endif +#ifndef EFI_EMBED_INI_MSD +#define EFI_EMBED_INI_MSD TRUE +#endif + #ifndef EFI_USB_SERIAL #define EFI_USB_SERIAL TRUE #endif diff --git a/firmware/gen_config_board.sh b/firmware/gen_config_board.sh index 578d18cd35..f68e4117d7 100755 --- a/firmware/gen_config_board.sh +++ b/firmware/gen_config_board.sh @@ -2,7 +2,7 @@ # file gen_config_board.sh -#set -x +set -e echo "This script reads rusefi_config.txt and produces firmware persistent configuration headers" echo "the storage section of rusefiXXX.ini is updated as well" @@ -38,4 +38,6 @@ java -DSystemOut.name=gen_config_board \ [ $? -eq 0 ] || { echo "ERROR generating TunerStudio config for ${BOARDNAME}"; exit 1; } +./hw_layer/mass_storage/create_ini_image.sh ./tunerstudio/generated/rusefi_${SHORT_BOARDNAME}.ini ./hw_layer/mass_storage/ramdisk_image.h + exit 0 diff --git a/firmware/hw_layer/mass_storage/README.txt b/firmware/hw_layer/mass_storage/README.txt new file mode 100644 index 0000000000..79770a0826 --- /dev/null +++ b/firmware/hw_layer/mass_storage/README.txt @@ -0,0 +1,4 @@ +Welcome to rusEFI! + +Unzip rusefi.ini.zip to your PC, and use the extracted +ini file with TunerStudio to connect to your ECU. \ No newline at end of file diff --git a/firmware/hw_layer/mass_storage/Readme.md b/firmware/hw_layer/mass_storage/Readme.md deleted file mode 100644 index 4a1c314432..0000000000 --- a/firmware/hw_layer/mass_storage/Readme.md +++ /dev/null @@ -1,40 +0,0 @@ -https://github.com/tegesoft/Chibios-USB-Devices/ -http://www.chibios.com/forum/viewtopic.php?f=3&t=619 - -Mass Storage Device -=================== - -This driver implements a USB mass storage device. It requires a Chibios block device (e.g mmc_spi or SDC) - -Example usage: --------------- -```c - -USBMassStorageDriver UMSD1; - -mmcObjectInit(&MMCD1); -mmcStart(&MMCD1, &mmccfg); -mmcConnect(&MMCD1); - -msdInit(&USBD1, &MMCD1, &UMSD1); -``` - -Events: --------------- -```c -chEvtRegisterMask(&UMSD1.evt_connected, &listener_connected, 1); -chEvtRegisterMask(&UMSD1.evt_ejected, &listener_ejected, 2); - -while(TRUE) { - if(chEvtWaitOneTimeout(1, TIME_IMMEDIATE)) { - /* drive is now connected */ - - /* wait until the drive is ejected */ - chEvtWaitOne(2); - - /* drive is now ejected. do something */ - } - - chThdSleepMilliseconds(1000); -} -``` \ No newline at end of file diff --git a/firmware/hw_layer/mass_storage/create_ini_image.sh b/firmware/hw_layer/mass_storage/create_ini_image.sh new file mode 100755 index 0000000000..b6c0203abd --- /dev/null +++ b/firmware/hw_layer/mass_storage/create_ini_image.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# fail on error +set -e + +rm -f rusefi.zip ramdisk_image.h + +# copy 100KB of zeroes +dd if=/dev/zero of=ramdisk.image bs=1024 count=100 + +# create a FAT filesystem inside, name it RUSEFI +mkfs.fat ramdisk.image +fatlabel ramdisk.image RUSEFI + +# -j option dumps all files in the root of the zip (instead of inside directories) +zip -j rusefi.ini.zip $1 + +# Put the zip inside the filesystem +mcopy -i ramdisk.image rusefi.ini.zip :: +# Put a readme text file in there too +mcopy -i ramdisk.image hw_layer/mass_storage/README.txt :: + +# write out as a C array, with "static const" tacked on the front +xxd -i ramdisk.image \ + | cat <(echo -n "static const ") - \ + > $2 + +rm ramdisk.image rusefi.ini.zip diff --git a/firmware/hw_layer/mass_storage/null_device.cpp b/firmware/hw_layer/mass_storage/null_device.cpp index 885cf37031..af389d68c8 100644 --- a/firmware/hw_layer/mass_storage/null_device.cpp +++ b/firmware/hw_layer/mass_storage/null_device.cpp @@ -10,6 +10,18 @@ #include "hal.h" +#if EFI_EMBED_INI_MSD +#include "ramdisk.h" +#include "ramdisk_image.h" + +// If the ramdisk image told us not to use it, don't use it. +#ifdef RAMDISK_INVALID +#undef EFI_EMBED_INI_MSD +#define EFI_EMBED_INI_MSD FALSE +#endif + +#endif + #include struct NullDevice { @@ -65,11 +77,34 @@ static const struct BaseBlockDeviceVMT ndVmt = { nd_get_info }; +#if EFI_EMBED_INI_MSD +static RamDisk ramdisk; +#else // This device is always ready and has no state static NullDevice nd = { &ndVmt, BLK_READY }; +#endif #if HAL_USE_USB_MSD void msdMountNullDevice(USBMassStorageDriver* msdp, USBDriver *usbp, uint8_t* blkbuf, const scsi_inquiry_response_t* inquiry) { + // TODO: implement multi-LUN so we can mount the ini image and SD card at the same time + +#if EFI_EMBED_INI_MSD + ramdiskObjectInit(&ramdisk); + + constexpr size_t ramdiskSize = sizeof(ramdisk_image); + constexpr size_t blockSize = 512; + constexpr size_t blockCount = ramdiskSize / blockSize; + + // Ramdisk should be a round number of blocks + static_assert(ramdiskSize % blockSize == 0); + + ramdiskStart(&ramdisk, const_cast(ramdisk_image), blockSize, blockCount, /*readonly =*/ true); + + msdStart(msdp, usbp, (BaseBlockDevice*)&ramdisk, blkbuf, inquiry, nullptr); + +#else + // No embedded ini file, just mount the null device instead msdStart(msdp, usbp, (BaseBlockDevice*)&nd, blkbuf, inquiry, nullptr); +#endif } #endif diff --git a/firmware/hw_layer/mass_storage/ramdisk_image.h b/firmware/hw_layer/mass_storage/ramdisk_image.h new file mode 100644 index 0000000000..3bdbd9a758 --- /dev/null +++ b/firmware/hw_layer/mass_storage/ramdisk_image.h @@ -0,0 +1,4 @@ +// This file will be replaced by a ramdisk image containing the corresponding ini +// Defining this macro tells the ramdisk to instead mount a null device instead of +// the filesystem image, since we don't have one. +#define RAMDISK_INVALID