Added first demo

This commit is contained in:
regymm 2024-01-27 15:55:57 +09:00
parent 5ced01aed7
commit 41013d4c9d
5 changed files with 399 additions and 0 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
*.wasm
*.js
installed/

41
Makefile Normal file
View file

@ -0,0 +1,41 @@
EMSCRIPTEN_DIR=/usr/lib/emscripten
all: wasmFPGALoader.js
build_libusb:
cd libusb && \
autoreconf -fiv && \
$(EMSCRIPTEN_DIR)/emconfigure ./configure -host=wasm32-emscripten -prefix=$(PWD)/installed && \
$(EMSCRIPTEN_DIR)/emmake make install
build_libftdi:
cp libftdi_CMakeLists.txt libftdi/CMakeLists.txt && \
cd libftdi && \
mkdir -p build && cd build && \
$(EMSCRIPTEN_DIR)/emcmake cmake -DFTDI_EEPROM=OFF .. && \
$(EMSCRIPTEN_DIR)/emmake make && \
cp src/libftdi1.a ../../installed/lib/ && \
mkdir -p ../../installed/include/libftdi1 && \
cp ../src/ftdi.h ../../installed/include/libftdi1/
# TODO: let cmake install to corrrect directory
EMCC=${EMSCRIPTEN_DIR}/emcc
INCLUDES=-I./installed/include/libftdi1 -I./installed/include/libusb-1.0
DEFINES=-DBLASTERII_DIR=\"\" -DDATA_DIR=\"/usr/local/share\" -DFTDI_VERSION=105 -DISE_DIR=\"/opt/Xilinx/14.7\" -DUSE_DEVICE_ARG -DVERSION=\"v0.11.0-wasm\"
#OPTIMIZE=-O3 # release, takes 30 mins
OPTIMIZE=-O1 # iteration
#OPTIMIZE=-g # debug
CFLAGS=$(OPTIMIZE) -pthread -fexceptions $(INCLUDES) $(DEFINES)
LDFLAGS=$(OPTIMIZE) --bind -fexceptions installed/lib/libusb-1.0.a installed/lib/libftdi1.a -s "EXPORTED_RUNTIME_METHODS=['callMain']" -s ASYNCIFY -s ASYNCIFY_STACK_SIZE=512000 -s ALLOW_MEMORY_GROWTH -s INVOKE_RUN=0 -s USE_PTHREADS=1 # -s TOTAL_MEMORY=2048MB -s ASSERTIONS=1 --shell-file wasmFPGAloader_shell.html -s NO_EXIT_RUNTIME=1 #-s NO_DISABLE_EXCEPTION_CATCHING -s DISABLE_EXCEPTION_CATCHING=0 # -s SAFE_HEAP=0 -s NO_DISABLE_EXCEPTION_CATCHING -s MEMORY64=0
SOURCES=openFPGALoader/src/altera.cpp openFPGALoader/src/anlogicBitParser.cpp openFPGALoader/src/anlogicCable.cpp openFPGALoader/src/anlogic.cpp openFPGALoader/src/bitparser.cpp openFPGALoader/src/ch347jtag.cpp openFPGALoader/src/ch552_jtag.cpp openFPGALoader/src/colognechipCfgParser.cpp openFPGALoader/src/colognechip.cpp openFPGALoader/src/common.cpp openFPGALoader/src/configBitstreamParser.cpp openFPGALoader/src/device.cpp openFPGALoader/src/dfu.cpp openFPGALoader/src/dfuFileParser.cpp openFPGALoader/src/dirtyJtag.cpp openFPGALoader/src/display.cpp openFPGALoader/src/efinix.cpp openFPGALoader/src/efinixHexParser.cpp openFPGALoader/src/epcq.cpp openFPGALoader/src/feaparser.cpp openFPGALoader/src/fsparser.cpp openFPGALoader/src/ftdiJtagBitbang.cpp openFPGALoader/src/ftdiJtagMPSSE.cpp openFPGALoader/src/ftdipp_mpsse.cpp openFPGALoader/src/ftdispi.cpp openFPGALoader/src/fx2_ll.cpp openFPGALoader/src/gowin.cpp openFPGALoader/src/ice40.cpp openFPGALoader/src/ihexParser.cpp openFPGALoader/src/jedParser.cpp openFPGALoader/src/jlink.cpp openFPGALoader/src/jtag.cpp openFPGALoader/src/latticeBitParser.cpp openFPGALoader/src/lattice.cpp openFPGALoader/src/libusb_ll.cpp openFPGALoader/src/main.cpp openFPGALoader/src/mcsParser.cpp openFPGALoader/src/pathHelper.cpp openFPGALoader/src/pofParser.cpp openFPGALoader/src/progressBar.cpp openFPGALoader/src/rawParser.cpp openFPGALoader/src/remoteBitbang_client.cpp openFPGALoader/src/spiFlash.cpp openFPGALoader/src/spiInterface.cpp openFPGALoader/src/svf_jtag.cpp openFPGALoader/src/usbBlaster.cpp openFPGALoader/src/xilinx.cpp openFPGALoader/src/xilinxMapParser.cpp openFPGALoader/src/xvc_client.cpp openFPGALoader/src/xvc_server.cpp
OBJECTS=$(SOURCES:.cpp=.o)
%.o:%.cpp
$(EMCC) $(CFLAGS) -c $< -o $@
wasmFPGALoader.js: $(OBJECTS)
$(EMCC) $(LDFLAGS) $(OBJECTS) -o $@
clean:
-rm wasmFPGAloader.{js,wasm} $(OBJECTS)

264
libftdi_CMakeLists.txt Normal file
View file

@ -0,0 +1,264 @@
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
message(STATUS "CMake version: ${CMAKE_VERSION}")
# Project
project(libftdi1 C)
set(MAJOR_VERSION 1)
set(MINOR_VERSION 5)
set(PACKAGE libftdi1)
set(VERSION_STRING ${MAJOR_VERSION}.${MINOR_VERSION})
set(VERSION ${VERSION_STRING})
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# use custom link flags and libusb location
link_libraries("-s NO_EXIT_RUNTIME=1 -s \"EXPORTED_RUNTIME_METHODS=['ccall']\" --bind -s ASYNCIFY -s ALLOW_MEMORY_GROWTH")
set(LIBUSB_WASM_DIR /home/petergu/FPGAOL/wasmFPGAloader/libusb/installed)
set(LIBUSB_INCLUDE_DIR ${LIBUSB_WASM_DIR}/include/libusb-1.0)
set(LIBUSB_LIBRARIES ${LIBUSB_WASM_DIR}/lib/libusb-1.0.a)
include_directories(${LIBUSB_INCLUDE_DIR})
link_directories(${LIBUSB_WASM_DIR}/lib)
# Support new if() IN_LIST operator
if(POLICY CMP0057)
cmake_policy(SET CMP0057 NEW)
endif()
# Included scripts do automatic cmake_policy() PUSH and POP
if(POLICY CMP0011)
cmake_policy(SET CMP0011 NEW)
endif()
# Target link properties INTERFACE_LINK_OPTIONS, INTERFACE_LINK_DIRECTORIES
# and INTERFACE_LINK_DEPENDS are now transitive over private dependencies
# of static libraries
if(POLICY CMP0099)
cmake_policy(SET CMP0099 NEW)
endif()
# CMake
if("${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif("${CMAKE_BUILD_TYPE}" STREQUAL "")
set(CMAKE_COLOR_MAKEFILE ON)
add_definitions(-Wall)
include(CMakeOptions.txt)
# Debug build
message("-- Build type: ${CMAKE_BUILD_TYPE}")
if(${CMAKE_BUILD_TYPE} STREQUAL Debug)
add_definitions(-DDEBUG)
endif(${CMAKE_BUILD_TYPE} STREQUAL Debug)
# Find libusb
# do not use this
#find_package ( LibUSB REQUIRED )
#include_directories ( ${LIBUSB_INCLUDE_DIR} )
# Find Boost
if (FTDIPP OR BUILD_TESTS)
find_package( Boost REQUIRED )
endif()
# Set components
set(CPACK_COMPONENTS_ALL sharedlibs staticlibs headers)
set(CPACK_COMPONENT_SHAREDLIBS_DISPLAY_NAME "Shared libraries")
set(CPACK_COMPONENT_STATICLIBS_DISPLAY_NAME "Static libraries")
set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C++ Headers")
set(CPACK_COMPONENT_SHAREDLIBS_DESCRIPTION
"Shared library for general use.")
set(CPACK_COMPONENT_STATICLIBS_DESCRIPTION
"Static library, good if you want to embed libftdi1 in your application.")
set(CPACK_COMPONENT_HEADERS_DESCRIPTION
"C/C++ header files.")
set(CPACK_COMPONENT_SHAREDLIBS_GROUP "Development")
set(CPACK_COMPONENT_STATICLIBS_GROUP "Development")
set(CPACK_COMPONENT_HEADERS_GROUP "Development")
# guess LIB_SUFFIX, don't take debian multiarch into account
if ( NOT DEFINED LIB_SUFFIX )
if( CMAKE_SYSTEM_NAME MATCHES "Linux"
AND NOT CMAKE_CROSSCOMPILING
AND NOT EXISTS "/etc/debian_version"
AND NOT EXISTS "/etc/arch-release" )
if ( "${CMAKE_SIZEOF_VOID_P}" EQUAL "8" )
set ( LIB_SUFFIX 64 )
endif ()
endif ()
endif ()
if(NOT APPLE)
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
SET(PACK_ARCH "")
else(CMAKE_SIZEOF_VOID_P EQUAL 8)
SET(PACK_ARCH .x86_64)
endif(CMAKE_SIZEOF_VOID_P EQUAL 4)
else(NOT APPLE)
SET(PACK_ARCH "")
endif(NOT APPLE)
# Package information
set(CPACK_PACKAGE_VERSION ${VERSION_STRING})
set(CPACK_PACKAGE_CONTACT "Intra2net AG <libftdi@developer.intra2net.com>")
set(CPACK_PACKAGE_DESCRIPTION "libftdi1 library.")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY ${CPACK_PACKAGE_DESCRIPTION})
# Package settings
if ( UNIX )
set(CPACK_GENERATOR "DEB;RPM")
set(CPACK_CMAKE_GENERATOR "Unix Makefiles")
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}${PACK_ARCH})
endif ()
if ( WIN32 )
set ( CPACK_GENERATOR "NSIS" )
set ( CPACK_CMAKE_GENERATOR "MinGW Makefiles" )
set ( CPACK_PACKAGE_NAME "${PROJECT_NAME}" )
set ( CPACK_PACKAGE_VENDOR "" )
set ( CPACK_PACKAGE_INSTALL_DIRECTORY "libftdi1" )
set ( CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION_STRING}-win32")
set ( CPACK_NSIS_DISPLAY_NAME "libftdi1" )
set ( CPACK_NSIS_MODIFY_PATH ON )
endif ()
set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE)
set(CPACK_SOURCE_GENERATOR TGZ)
set(CPACK_SOURCE_IGNORE_FILES "\\\\.git;~$;build/")
set(CPACK_SOURCE_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION})
# Subdirectories
if ( UNIX )
set ( CPACK_SET_DESTDIR ON )
endif ()
# "make dist" target
set(ARCHIVE_NAME ${CMAKE_PROJECT_NAME}-${VERSION_STRING})
add_custom_target(dist
COMMAND git archive --prefix=${ARCHIVE_NAME}/ HEAD
| bzip2 > ${PROJECT_BINARY_DIR}/${ARCHIVE_NAME}.tar.bz2
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_subdirectory(src)
add_subdirectory(packages)
if ( DOCUMENTATION )
add_subdirectory(doc)
endif ( DOCUMENTATION )
if ( FTDIPP )
project(libftdi1 C CXX)
add_subdirectory(ftdipp)
endif ( FTDIPP )
if ( PYTHON_BINDINGS )
add_subdirectory(python)
endif ( PYTHON_BINDINGS )
if ( FTDI_EEPROM )
add_subdirectory(ftdi_eeprom)
endif ( FTDI_EEPROM )
if ( EXAMPLES )
add_subdirectory(examples)
endif ( EXAMPLES )
if ( BUILD_TESTS )
project(libftdi1 C CXX)
add_subdirectory(test)
endif ( BUILD_TESTS )
# PkgConfig
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix ${CMAKE_INSTALL_PREFIX}/bin)
set(includedir ${CMAKE_INSTALL_PREFIX}/include/${PROJECT_NAME})
if(${UNIX})
set(libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
endif(${UNIX})
if(${WIN32})
set(libdir ${CMAKE_INSTALL_PREFIX}/bin)
endif(${WIN32})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libftdi1.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libftdi1.pc @ONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libftdipp1.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libftdipp1.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libftdi1.pc ${CMAKE_CURRENT_BINARY_DIR}/libftdipp1.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
if (UNIX OR MINGW)
configure_file ( libftdi1-config.in ${CMAKE_CURRENT_BINARY_DIR}/libftdi1-config @ONLY )
install ( PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libftdi1-config
DESTINATION bin )
endif ()
# config script install path
if ( NOT DEFINED LIBFTDI_CMAKE_CONFIG_DIR )
set ( LIBFTDI_CMAKE_CONFIG_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/libftdi1 )
endif ()
set ( LIBFTDI_INCLUDE_DIR ${includedir} )
set ( LIBFTDI_INCLUDE_DIRS ${LIBFTDI_INCLUDE_DIR} )
set ( LIBFTDI_LIBRARY ftdi1 )
set ( LIBFTDI_LIBRARIES ${LIBFTDI_LIBRARY} )
list ( APPEND LIBFTDI_LIBRARIES ${LIBUSB_LIBRARIES} )
set ( LIBFTDI_STATIC_LIBRARY ftdi1.a )
set ( LIBFTDI_STATIC_LIBRARIES ${LIBFTDI_STATIC_LIBRARY} )
list ( APPEND LIBFTDI_STATIC_LIBRARIES ${LIBUSB_LIBRARIES} )
if ( FTDIPP )
set ( LIBFTDIPP_LIBRARY ftdipp1 )
set ( LIBFTDIPP_LIBRARIES ${LIBFTDIPP_LIBRARY} )
list ( APPEND LIBFTDIPP_LIBRARIES ${LIBUSB_LIBRARIES} )
endif ()
set ( LIBFTDI_LIBRARY_DIRS ${libdir} )
set ( LIBFTDI_ROOT_DIR ${prefix} )
set ( LIBFTDI_VERSION_STRING ${VERSION_STRING} )
set ( LIBFTDI_VERSION_MAJOR ${MAJOR_VERSION} )
set ( LIBFTDI_VERSION_MINOR ${MINOR_VERSION} )
set ( LIBFTDI_USE_FILE ${CMAKE_INSTALL_PREFIX}/${LIBFTDI_CMAKE_CONFIG_DIR}/UseLibFTDI1.cmake )
include(CMakePackageConfigHelpers)
configure_package_config_file (
cmake/LibFTDI1Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/LibFTDI1Config.cmake
INSTALL_DESTINATION ${LIBFTDI_CMAKE_CONFIG_DIR}
PATH_VARS
LIBFTDI_USE_FILE
LIBFTDI_ROOT_DIR
LIBFTDI_INCLUDE_DIR
LIBFTDI_INCLUDE_DIRS
LIBFTDI_LIBRARY_DIRS
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
write_basic_package_version_file (
LibFTDI1ConfigVersion.cmake
VERSION ${LIBFTDI_VERSION_STRING}
COMPATIBILITY AnyNewerVersion
)
install (
FILES
${CMAKE_CURRENT_BINARY_DIR}/LibFTDI1Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/LibFTDI1ConfigVersion.cmake
cmake/UseLibFTDI1.cmake
DESTINATION ${LIBFTDI_CMAKE_CONFIG_DIR}
)
include(CPack)
message (STATUS "Summary of build options:
Build static libs: ${STATICLIBS}
Build C++ bindings: ${FTDIPP}
Build Python bindings: ${PYTHON_BINDINGS}
Build ftdi_eeprom: ${FTDI_EEPROM}
Build examples: ${EXAMPLES}
Build tests: ${BUILD_TESTS}
Build API documentation: ${DOCUMENTATION}
")

17
nginx.conf Normal file
View file

@ -0,0 +1,17 @@
server {
listen 443 ssl;
server_name 100.104.190.55;
server_name 192.168.123.233;
ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key;
root /usr/share/nginx/html;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
add_header 'Cross-Origin-Embedder-Policy' 'require-corp';
add_header 'Cross-Origin-Opener-Policy' 'same-origin';
}
}

74
wasmFPGALoader.html Normal file
View file

@ -0,0 +1,74 @@
<!DOCTYPE html>
<html>
<head>
<title>wasmFPGAloader -- FPGAOL-CE</title>
</head>
<body>
<button id="connectBtn">Connect</button>
<button id="testBtn">openFPGAloader --detect</button>
<p id="status0"></p>
<input type="file" id="upload" onchange="uploadFile()">
<button id="testBtn2">Blast</button>
<script>
const connectBtn = document.getElementById('connectBtn');
connectBtn.addEventListener('click', connect_a_device);
async function connect_a_device() {
console.log('connect_a_device')
await navigator.usb.requestDevice({ filters: [] });
}
const testBtn = document.getElementById('testBtn');
testBtn.addEventListener('click', ofl_detect);
async function ofl_detect() {
console.log('openFPGAloader detect')
try{
await Module.callMain(["--detect"]);
}
catch (err) {
console.log("Detecting JTAG downloader error: " + err.message)
}
}
const testBtn2 = document.getElementById('testBtn2');
testBtn2.addEventListener('click', test_usb_2);
async function test_usb_2() {
console.log('test_usb_2')
await Module.callMain(["-b", "tangnano9k", "" + document.getElementById('upload').files[0].name]);
//await Module.ccall('myMain', null, null, null);
}
var Module = {
onRuntimeInitialized: function() {
console.log('wasm loaded');
},
print: function(text) {
console.log(text);
},
printErr: function(text) {
console.log('Err: ' + text);
}
};
function uploadFile() {
var fileInput = document.getElementById('upload');
var file = fileInput.files[0];
var reader = new FileReader();
reader.onload = function() {
// Create a Uint8Array from file content
var data = new Uint8Array(reader.result);
// Use Emscripten's FS API to write the file to the virtual filesystem
FS.writeFile('' + file.name, data);
console.log('File writen to WASM file system: ' + file.name);
// Optionally, call a function defined in your WebAssembly module that needs access to the file
// For example, if your module has a function that takes the file path as argument
// Module.ccall('yourFunctionName', 'returnType', ['param1Type'], ['/working/' + file.name]);
};
reader.readAsArrayBuffer(file);
}
</script>
<script src="./wasmFPGALoader.js"></script>
</body>
</html>