Skip to content

Commit

Permalink
First commit, create kendryte k210 openmv
Browse files Browse the repository at this point in the history
  • Loading branch information
hukaisunny committed Nov 5, 2018
0 parents commit b1b127c
Show file tree
Hide file tree
Showing 3,285 changed files with 654,835 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
30 changes: 30 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
### This file is used for build example projects.

# set this will supress some warnings
set(BUILDING_SDK "yes" CACHE INTERNAL "")

# basic config
if (NOT PROJ)
message(FATAL_ERROR "PROJ must be set. e.g. -DPROJ=hello_world")
endif ()
cmake_minimum_required(VERSION 3.0)
include(./cmake/common.cmake)
project(${PROJ})

# config self use headers
include(./cmake/macros.internal.cmake)
header_directories(${SDK_ROOT}/lib)
# build library first
add_subdirectory(lib)

# TODO
#add_subdirectory(third_party)

# compile project
add_custom_target(build_metis ALL
COMMAND ${CMAKE_MAKE_PROGRAM}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/openmv/src/micropython/ports/k210-standalone
COMMENT "Original metis makefile target")
add_source_files(src/${PROJ}/main/*.c)
include(./cmake/executable.cmake)

5 changes: 5 additions & 0 deletions README.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Kendryte-standalone-opemv build step:
1. mkdir build
2. cd build
3. cmake .. -DPROJ=openmv -DTOOLCHAIN=/opt/maix-toolchain/bin (risv toolchain path)
4. make
44 changes: 44 additions & 0 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
### This file is used for build library standalone.

# set this will supress some warnings
set(BUILDING_SDK "yes" CACHE INTERNAL "")

# basic config
cmake_minimum_required(VERSION 3.0)
include(./common.cmake)
project(kendryte)

# config self use headers
include(./macros.internal.cmake)
header_directories(${SDK_ROOT}/lib)

# include lib make file
include(../lib/CMakeLists.txt)

# find headers files to INSTALL
file(GLOB_RECURSE LIB_HEADERS
"../lib/*.h"
"../lib/*.hpp"
)
set_target_properties(kendryte PROPERTIES PUBLIC_HEADER "${LIB_HEADERS}")

# copy .a file and headers
install(TARGETS kendryte
EXPORT kendryte
ARCHIVE
DESTINATION ${CMAKE_BINARY_DIR}/archive
PUBLIC_HEADER DESTINATION ${CMAKE_BINARY_DIR}/archive/include
)

# copy utils files
install(DIRECTORY
../lds
../utils
../cmake
DESTINATION ${CMAKE_BINARY_DIR}/archive
PATTERN "*internal*" EXCLUDE
PATTERN "CMakeLists.txt" EXCLUDE
)

# show information
include(./dump-config.cmake)
3 changes: 3 additions & 0 deletions cmake/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
prepend `common.cmake` before

append `executable.cmake` after
34 changes: 34 additions & 0 deletions cmake/common.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
cmake_minimum_required(VERSION 3.0)

include(${CMAKE_CURRENT_LIST_DIR}/macros.cmake)

global_set(CMAKE_C_COMPILER_WORKS 1)
global_set(CMAKE_CXX_COMPILER_WORKS 1)

global_set(CMAKE_SYSTEM_NAME "Generic")
if (NOT CMAKE_BUILD_TYPE)
global_set(CMAKE_BUILD_TYPE Debug)
else ()
if ((NOT CMAKE_BUILD_TYPE STREQUAL "Debug") AND (NOT CMAKE_BUILD_TYPE STREQUAL "Release"))
message(FATAL_ERROR "CMAKE_BUILD_TYPE must either be Debug or Release instead of ${CMAKE_BUILD_TYPE}")
endif ()
endif ()

# - Debug & Release
IF (CMAKE_BUILD_TYPE STREQUAL Debug)
add_definitions(-DDEBUG=1)
ENDIF ()

# definitions in macros
add_definitions(-DCONFIG_LOG_LEVEL=LOG_VERBOSE -DCONFIG_LOG_ENABLE -DCONFIG_LOG_COLORS -DLOG_KERNEL -D__riscv64 -DFPGA_PLL)

if (NOT SDK_ROOT)
get_filename_component(_SDK_ROOT ${CMAKE_CURRENT_LIST_DIR} DIRECTORY)
global_set(SDK_ROOT ${_SDK_ROOT})
endif ()

include(${CMAKE_CURRENT_LIST_DIR}/toolchain.cmake)

include(${CMAKE_CURRENT_LIST_DIR}/compile-flags.cmake)

include(${CMAKE_CURRENT_LIST_DIR}/fix-9985.cmake)
54 changes: 54 additions & 0 deletions cmake/compile-flags.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
add_compile_flags(LD
-nostartfiles
-static
-Wl,--gc-sections
-Wl,-static
-Wl,--start-group
-Wl,--whole-archive
-Wl,--no-whole-archive
-Wl,--end-group
-Wl,-EL
-T ${SDK_ROOT}/lds/kendryte.ld
)

# C Flags Settings
add_compile_flags(BOTH
-mcmodel=medany
-fno-common
-ffunction-sections
-fdata-sections
-fstrict-volatile-bitfields
-fno-zero-initialized-in-bss
-Os
-ggdb
)

add_compile_flags(C -std=gnu11)
add_compile_flags(CXX -std=gnu++17)

if (BUILDING_SDK)
add_compile_flags(BOTH
-Wall
-Werror=all
-Wno-error=unused-function
-Wno-error=unused-but-set-variable
-Wno-error=unused-variable
-Wno-error=deprecated-declarations
-Wextra
-Werror=frame-larger-than=65536
-Wno-unused-parameter
-Wno-sign-compare
-Wno-error=missing-braces
-Wno-error=return-type
-Wno-error=pointer-sign
-Wno-missing-braces
-Wno-pointer-to-int-cast
-Wno-strict-aliasing
-Wno-implicit-fallthrough
)

add_compile_flags(C -Wno-old-style-declaration)
else ()
add_compile_flags(BOTH -L${SDK_ROOT}/include/)
endif ()

13 changes: 13 additions & 0 deletions cmake/dump-config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
message("")
message("Project: ${PROJECT_NAME}")
message(" TOOLCHAIN=${TOOLCHAIN}")
message(" KENDRYTE IDE=${KENDRYTE_IDE}")
message("")
message(" CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}")
message(" CMAKE_C_COMPILER=${CMAKE_C_COMPILER}")
message(" CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}")
message(" CMAKE_LINKER=${CMAKE_LINKER}")
message(" CMAKE_OBJCOPY=${CMAKE_OBJCOPY}")
message("Makefile created.")
message("")
message("")
37 changes: 37 additions & 0 deletions cmake/executable.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
if (NOT BUILDING_SDK)
add_library(kendryte STATIC IMPORTED)
set_property(TARGET kendryte PROPERTY IMPORTED_LOCATION ${SDK_ROOT}/libmaix.a)
include_directories(${SDK_ROOT}/include/)
endif ()

add_executable(${PROJECT_NAME} ${SOURCE_FILES})
# add_dependencies(${PROJECT_NAME} kendryte) # TODO: third_party
# target_link_libraries(${PROJECT_NAME} kendryte) # TODO: third_party
# link_directories(${CMAKE_BINARY_DIR})
target_link_libraries(${PROJECT_NAME}
${SDK_ROOT}/src/openmv/src/micropython/ports/k210-standalone/micropython.a
)
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE C)

target_link_libraries(${PROJECT_NAME}
-Wl,--start-group
gcc m c kendryte
-Wl,--end-group
)
IF(SUFFIX)
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SUFFIX ${SUFFIX})
ENDIF()

#message("CMAKE_OBJCOPY=${CMAKE_OBJCOPY}")

# Build target
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_OBJCOPY} --output-format=binary ${CMAKE_BINARY_DIR}/${PROJECT_NAME}${SUFFIX} ${CMAKE_BINARY_DIR}/${PROJECT_NAME}.bin
DEPENDS ${PROJECT_NAME}
COMMENT "Generating .bin file ...")


add_custom_target(firmware DEPENDS ${PROJECT_NAME}.firmware.bin)

# show information
include(${CMAKE_CURRENT_LIST_DIR}/dump-config.cmake)
3 changes: 3 additions & 0 deletions cmake/fix-9985.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### http://www.cmake.org/Bug/view.php?id=9985
string(REPLACE "-rdynamic" "" CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS}")
string(REPLACE "-rdynamic" "" CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS}")
65 changes: 65 additions & 0 deletions cmake/macros.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
macro(global_set Name Value)
# message("set ${Name} to " ${ARGN})
set(${Name} "${Value}" CACHE STRING "NoDesc" FORCE)
endmacro()

macro(condition_set Name Value)
if (NOT ${Name})
global_set(${Name} ${Value})
else ()
# message("exists ${Name} is " ${ARGN})
endif ()
endmacro()


set(SOURCE_FILES "" CACHE STRING "Source Files" FORCE)
macro(add_source_files)
# message(" + add_source_files ${ARGN}")
file(GLOB_RECURSE newlist ${ARGN})

foreach (filepath ${newlist})
string(FIND ${filepath} ${CMAKE_BINARY_DIR} found)
if (NOT found EQUAL 0)
set(SOURCE_FILES ${SOURCE_FILES} ${filepath} CACHE STRING "Source Files" FORCE)
endif ()
endforeach ()
endmacro()

function(JOIN VALUES GLUE OUTPUT)
string(REGEX REPLACE "([^\\]|^);" "\\1${GLUE}" _TMP_STR "${VALUES}")
string(REGEX REPLACE "[\\](.)" "\\1" _TMP_STR "${_TMP_STR}") #fixes escaping
set(${OUTPUT} "${_TMP_STR}" PARENT_SCOPE)
endfunction()

global_set(LDFLAGS "")
global_set(CMAKE_EXE_LINKER_FLAGS "")
global_set(CMAKE_SHARED_LINKER_FLAGS "")
global_set(CMAKE_MODULE_LINKER_FLAGS "")

macro(add_compile_flags WHERE)
JOIN("${ARGN}" " " STRING_ARGS)
if (${WHERE} STREQUAL C)
global_set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${STRING_ARGS}")

elseif (${WHERE} STREQUAL CXX)
global_set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${STRING_ARGS}")

elseif (${WHERE} STREQUAL LD)
global_set(LDFLAGS "${LDFLAGS} ${STRING_ARGS}")
global_set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${STRING_ARGS}")
global_set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${STRING_ARGS}")
global_set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${STRING_ARGS}")

elseif (${WHERE} STREQUAL BOTH)
add_compile_flags(C ${ARGN})
add_compile_flags(CXX ${ARGN})

elseif (${WHERE} STREQUAL ALL)
add_compile_flags(C ${ARGN})
add_compile_flags(CXX ${ARGN})
add_compile_flags(LD ${ARGN})

else ()
message(FATAL_ERROR "add_compile_flags - only support: C, CXX, BOTH, LD, ALL")
endif ()
endmacro()
12 changes: 12 additions & 0 deletions cmake/macros.internal.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Add lib headers
macro(header_directories parent)
file(GLOB_RECURSE newList ${parent}/*.h)
set(dir_list "")
foreach (file_path ${newList})
get_filename_component(dir_path ${file_path} DIRECTORY)
set(dir_list ${dir_list} ${dir_path})
endforeach ()
list(REMOVE_DUPLICATES dir_list)

include_directories(${dir_list})
endmacro()
22 changes: 22 additions & 0 deletions cmake/toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
if (NOT TOOLCHAIN)
message(FATAL_ERROR "TOOLCHAIN must be set, to absolute path of kendryte-toolchain dist/bin folder.")
endif ()

if (WIN32)
set(EXT ".exe")
else ()
set(EXT "")
endif ()

condition_set(CMAKE_C_COMPILER "${TOOLCHAIN}/riscv64-unknown-elf-gcc${EXT}" CACHE INTERNAL "")
condition_set(CMAKE_CXX_COMPILER "${TOOLCHAIN}/riscv64-unknown-elf-g++${EXT}" CACHE INTERNAL "")
condition_set(CMAKE_LINKER "${TOOLCHAIN}/riscv64-unknown-elf-ld${EXT}" CACHE INTERNAL "")
condition_set(CMAKE_AR "${TOOLCHAIN}/riscv64-unknown-elf-ar${EXT}" CACHE INTERNAL "")
condition_set(CMAKE_CXX_COMPILER_AR "${CMAKE_AR}${EXT}" CACHE INTERNAL "")
condition_set(CMAKE_C_COMPILER_AR "${CMAKE_AR}${EXT}" CACHE INTERNAL "")
condition_set(CMAKE_OBJCOPY "${TOOLCHAIN}/riscv64-unknown-elf-objcopy${EXT}" CACHE INTERNAL "")

get_filename_component(_BIN_DIR "${CMAKE_C_COMPILER}" DIRECTORY)
if (NOT "${TOOLCHAIN}" STREQUAL "${_BIN_DIR}")
message(FATAL_ERROR "CMAKE_C_COMPILER is not in kendryte-toolchain dist/bin folder.")
endif ()
Loading

0 comments on commit b1b127c

Please sign in to comment.