Skip to content

Commit

Permalink
Add stress test firmware to support Facedancer stress test
Browse files Browse the repository at this point in the history
  • Loading branch information
kauwua committed Jun 4, 2024
1 parent 4118ebe commit 72a0ab9
Show file tree
Hide file tree
Showing 9 changed files with 836 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ add_subdirectory(test_firmware_serdes)
add_subdirectory(test_firmware_unittests)
add_subdirectory(test_firmware_usb_loopback)
add_subdirectory(test_firmware_usb_speedtest)
add_subdirectory(test_firmware_fifo)
add_subdirectory(test_firmware_usb_loopback_separate_usb_stacks)
add_subdirectory(test_firmware_usb_stress_test)
add_subdirectory(test_firmware_fifo)
57 changes: 57 additions & 0 deletions tests/test_firmware_usb_stress_test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Prerequisites
*.d

# astyle generated
*.*.orig

# Object files
*.o
*.ko
*.obj
*.elf
*.bin
*.lst

# Linker output
*.ilk
*.map
*.exp

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
1 change: 1 addition & 0 deletions tests/test_firmware_usb_stress_test/.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* bvernoux 18June2022 => Changed SECTION ".DMADATA :" to ".DMADATA (NOLOAD) :" => Added in section ".DMADATA" => *(.DMADATA*) => To have a correct _dmadata_end (as before _dmadata_start was always equal to _dmadata_end)*/ENTRY( _start )__stack_size = 2048;PROVIDE( _stack_size = __stack_size );MEMORY{ FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 448K RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 16K RAMX (xrw) : ORIGIN = 0x20020000, LENGTH = 96K}SECTIONS{ .init : { _sinit = .; . = ALIGN(4); KEEP(*(SORT_NONE(.init))) . = ALIGN(4); _einit = .; } >FLASH AT>FLASH .vector : { *(.vector); . = ALIGN(64); } >FLASH AT>FLASH .text : { . = ALIGN(4); *(.text) *(.text.*) *(.rodata) *(.rodata*) *(.glue_7) *(.glue_7t) *(.gnu.linkonce.t.*) . = ALIGN(4); } >FLASH AT>FLASH .fini : { KEEP(*(SORT_NONE(.fini))) . = ALIGN(4); } >FLASH AT>FLASH PROVIDE( _etext = . ); PROVIDE( _eitcm = . ); .preinit_array : { PROVIDE_HIDDEN (__preinit_array_start = .); KEEP (*(.preinit_array)) PROVIDE_HIDDEN (__preinit_array_end = .); } >FLASH AT>FLASH .init_array : { PROVIDE_HIDDEN (__init_array_start = .); KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*))) KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors)) PROVIDE_HIDDEN (__init_array_end = .); } >FLASH AT>FLASH .fini_array : { PROVIDE_HIDDEN (__fini_array_start = .); KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*))) KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors)) PROVIDE_HIDDEN (__fini_array_end = .); } >FLASH AT>FLASH .ctors : { /* gcc uses crtbegin.o to find the start of the constructors, so we make sure it is first. Because this is a wildcard, it doesn't matter if the user does not actually link against crtbegin.o; the linker won't look for a file to match a wildcard. The wildcard also means that it doesn't matter which directory crtbegin.o is in. */ KEEP (*crtbegin.o(.ctors)) KEEP (*crtbegin?.o(.ctors)) /* We don't want to include the .ctor section from the crtend.o file until after the sorted ctors. The .ctor section from the crtend file contains the end of ctors marker and it must be last */ KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors)) KEEP (*(SORT(.ctors.*))) KEEP (*(.ctors)) } >FLASH AT>FLASH .dtors : { KEEP (*crtbegin.o(.dtors)) KEEP (*crtbegin?.o(.dtors)) KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors)) KEEP (*(SORT(.dtors.*))) KEEP (*(.dtors)) } >FLASH AT>FLASH .dalign : { . = ALIGN(4); PROVIDE(_data_vma = .); } >RAM AT>FLASH .dlalign : { . = ALIGN(4); PROVIDE(_data_lma = .); } >FLASH AT>FLASH .data : { *(.gnu.linkonce.r.*) *(.data .data.*) *(.gnu.linkonce.d.*) . = ALIGN(8); PROVIDE( __global_pointer$ = . + 0x800 ); *(.sdata .sdata.*) *(.sdata2.*) *(.gnu.linkonce.s.*) . = ALIGN(8); *(.srodata.cst16) *(.srodata.cst8) *(.srodata.cst4) *(.srodata.cst2) *(.srodata .srodata.*) . = ALIGN(4); PROVIDE( _edata = .); } >RAM AT>FLASH .bss : { . = ALIGN(4); PROVIDE( _sbss = .); *(.sbss*) *(.gnu.linkonce.sb.*) *(.bss*) *(.gnu.linkonce.b.*) *(COMMON*) . = ALIGN(4); PROVIDE( _ebss = .); } >RAM AT>FLASH PROVIDE( _end = _ebss); PROVIDE( end = . ); .DMADATA (NOLOAD) : { . = ALIGN(16); PROVIDE( _dmadata_start = .); *(.dmadata*) *(.dmadata.*) *(.DMADATA*) . = ALIGN(16); PROVIDE( _dmadata_end = .); } >RAMX AT>FLASH /**/ .stack ORIGIN(RAM) + LENGTH(RAM) - __stack_size : { . = ALIGN(4); PROVIDE(_susrstack = . ); . = . + __stack_size; PROVIDE( _eusrstack = .); } >RAM }
Expand Down
101 changes: 101 additions & 0 deletions tests/test_firmware_usb_stress_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
project(test_firmware_usb_stress_test LANGUAGES C)
set(CMAKE_EXECUTABLE_SUFFIX_C ".elf")

add_executable(${PROJECT_NAME})

target_sources(${PROJECT_NAME} PUBLIC
${CMAKE_CURRENT_LIST_DIR}/User/main.c
)
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR}/User)

##### Define program options

#### wch-ch56x-lib options

target_compile_definitions(wch-ch56x-lib-scheduled INTERFACE POOL_BLOCK_SIZE=512 POOL_BLOCK_NUM=40 INTERRUPT_QUEUE_SIZE=20)

#### logging options

# set(LOG_OUTPUT "printf")
# set(LOG_LEVEL 1)
# set(LOG_FILTER_IDS "1")

if (DEFINED LOG_OUTPUT)
if (${LOG_OUTPUT} STREQUAL "buffer")
target_compile_definitions(${PROJECT_NAME} PRIVATE LOG_TYPE_BUFFER=1)
endif()
if (${LOG_OUTPUT} STREQUAL "serdes")
target_compile_definitions(${PROJECT_NAME} PRIVATE LOG_TYPE_SERDES=1)
endif()
if (${LOG_OUTPUT} STREQUAL "printf")
target_compile_definitions(${PROJECT_NAME} PRIVATE LOG_TYPE_PRINTF=1)
endif()
endif()

if (DEFINED LOG_LEVEL)
target_compile_definitions(${PROJECT_NAME} PRIVATE LOG_LEVEL=${LOG_LEVEL})
endif()

if (DEFINED LOG_FILTER_IDS)
target_compile_definitions(${PROJECT_NAME} PRIVATE LOG_FILTER_IDS=${LOG_FILTER_IDS})
endif()

if (DEFINED STATIC_ANALYSIS)
target_compile_options(${PROJECT_NAME} PRIVATE -fanalyzer)
endif()

##### Compilation and linkage options

target_compile_options(${PROJECT_NAME} PRIVATE
-Werror -Warray-bounds=2 -Wno-comment -pedantic -Wall -Wno-error=unused-parameter
-Wbad-function-cast -Wredundant-decls -Wmissing-prototypes -Wchar-subscripts -Wshadow -Wundef -Wwrite-strings -Wunused -Wuninitialized -Wpointer-arith -Winline -Wformat -Wformat-security -Winit-self -Wmissing-include-dirs -Wnested-externs -Wmissing-declarations -Wempty-body -Wignored-qualifiers -Wmissing-field-initializers -Wtype-limits -Wcast-align -Wswitch-enum
-Wextra -Wclobbered -Wcast-function-type -Wimplicit-fallthrough=3 -Wmissing-parameter-type -Wold-style-declaration -Woverride-init -Wshift-negative-value -Wunused-but-set-parameter
)

if (DEFINED EXTRACFLAGS)
target_compile_options(${PROJECT_NAME} PRIVATE
-Wunused-parameter -Wno-error=unused-parameter
-Wsign-compare -Wno-error=sign-compare
-Wconversion -Wno-error=conversion -Wno-error=sign-conversion -Wno-error=float-conversion
)
endif()

if (${RISCV_GCC_TOOLCHAIN_PREFIX} STREQUAL "riscv-none-embed-gcc")
message("Using riscv-none-embed-gcc")
target_compile_options(${PROJECT_NAME} PRIVATE -march=rv32imac)
elseif(${RISCV_GCC_TOOLCHAIN_PREFIX} STREQUAL "riscv-none-elf-gcc")
message("Using riscv-none-elf-gcc")
target_compile_options(${PROJECT_NAME} PRIVATE -march=rv32imac_zicsr)
else()
message("Toolchain not found")
endif()

target_compile_options(${PROJECT_NAME} PRIVATE -std=gnu99 -MMD -MP -mno-strict-align -mabi=ilp32 -msmall-data-limit=8 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections)
target_compile_options(${PROJECT_NAME} PRIVATE $<$<CONFIG:Debug>:-Og> $<$<CONFIG:Release>:-Oz>)
target_link_options(${PROJECT_NAME} PRIVATE -T "${CMAKE_CURRENT_LIST_DIR}/.ld" -nostartfiles LINKER:--gc-sections LINKER:--print-memory-usage -Wl,-Map,${PROJECT_NAME}.map --specs=nano.specs --specs=nosys.specs)
target_link_libraries(${PROJECT_NAME} wch-ch56x-lib-scheduled)

##### Generate additional targets

add_custom_target(${PROJECT_NAME}.bin ALL DEPENDS ${PROJECT_NAME}.elf)
add_custom_target(${PROJECT_NAME}.hex ALL DEPENDS ${PROJECT_NAME}.elf)
add_custom_target(${PROJECT_NAME}.lst ALL DEPENDS ${PROJECT_NAME}.elf)

add_custom_command(TARGET ${PROJECT_NAME}.bin
COMMAND ${CMAKE_OBJCOPY} -O binary ${PROJECT_NAME}.elf
${PROJECT_NAME}.bin)

add_custom_command(TARGET ${PROJECT_NAME}.hex
COMMAND ${CMAKE_OBJCOPY} -O ihex ${PROJECT_NAME}.elf
${PROJECT_NAME}.hex)

add_custom_command(TARGET ${PROJECT_NAME}.lst
COMMAND ${CMAKE_OBJDUMP} --source --all-headers --demangle --line-numbers --wide ${PROJECT_NAME}.elf > ${PROJECT_NAME}.lst)

##### Export generated files

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.bin DESTINATION ${CMAKE_SOURCE_DIR}/out/${PROJECT_NAME})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.hex DESTINATION ${CMAKE_SOURCE_DIR}/out/${PROJECT_NAME})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.elf DESTINATION ${CMAKE_SOURCE_DIR}/out/${PROJECT_NAME})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.lst DESTINATION ${CMAKE_SOURCE_DIR}/out/${PROJECT_NAME})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.map DESTINATION ${CMAKE_SOURCE_DIR}/out/${PROJECT_NAME})
32 changes: 32 additions & 0 deletions tests/test_firmware_usb_stress_test/User/definitions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/********************************** (C) COPYRIGHT *******************************
Copyright (c) 2023 Quarkslab
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*******************************************************************************/

#ifndef DEFINITIONS_H
#define DEFINITIONS_H

#define ENDP_1_15_MAX_PACKET_SIZE 1024
/* Global define */
// DEF_ENDP_OUT_BURST_LEVEL / DEF_ENDP_IN_BURST_LEVEL maximum burst size 16
// defined by the USB3 specification Warning USB3 endpoint bulk with 8 or 16
// burst can be problematic on some PC
#define DEF_ENDP_OUT_BURST_LEVEL 4
#define DEF_ENDP_IN_BURST_LEVEL (DEF_ENDP_OUT_BURST_LEVEL)
#define DEF_ENDP_MAX_SIZE (DEF_ENDP1_OUT_BURST_LEVEL * 1024)

#define MAX_TRANSFER_LENGTH 768

#endif
Loading

0 comments on commit 72a0ab9

Please sign in to comment.