diff --git a/CMakeLists.txt b/CMakeLists.txt index 77ef62c19..f2f3b78aa 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,9 @@ set(compile_time "${DATE}\" \"${TIME}" CACHE STRING " " FORCE) add_subdirectory(mkrtos_bootstrap) add_subdirectory(mkrtos_knl) -# add_subdirectory(mkrtos_img) +if ((NOT DEFINED CONFIG_MMU) OR (CONFIG_MMU STREQUAL "n")) + add_subdirectory(mkrtos_img) +endif() add_subdirectory(mkrtos_user) diff --git a/mkrtos_bootstrap/CMakeLists.txt b/mkrtos_bootstrap/CMakeLists.txt index 786f12eff..eff672d62 100755 --- a/mkrtos_bootstrap/CMakeLists.txt +++ b/mkrtos_bootstrap/CMakeLists.txt @@ -34,7 +34,7 @@ if (${CONFIG_CPU_TYPE} STREQUAL "stm32f1") ${CMAKE_SOURCE_DIR}/mkrtos_bsp/STM32/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/CoreSupport ) add_subdirectory(bsp/STM32F1) - set(PACK_CMD "${CMAKE_OBJCOPY} -I binary -O elf32-littlearm -B arm rootfs.cpio rootfs.cpio.elf --rename-section .data=.cpio") + set(LINKS_FLAGS " --gc-section ") elseif(${CONFIG_CPU_TYPE} STREQUAL "stm32f2" ) file(GLOB bsp_src ${CMAKE_SOURCE_DIR}/mkrtos_bsp/STM32/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/STM32F2xx_StdPeriph_Driver/src/*.c) @@ -47,7 +47,8 @@ elseif(${CONFIG_CPU_TYPE} STREQUAL "stm32f2" ) ${CMAKE_SOURCE_DIR}/mkrtos_bsp/STM32/STM32F2xx_StdPeriph_Lib_V1.1.0/Libraries/CMSIS/Device/ST/STM32F2xx/Include ) add_subdirectory(bsp/STM32F2) - set(PACK_CMD "${CMAKE_OBJCOPY} -I binary -O elf32-littlearm -B arm rootfs.cpio rootfs.cpio.elf --rename-section .data=.cpio") + set(LINKS_FLAGS " --gc-section ") + elseif(${CONFIG_CPU_TYPE} STREQUAL "stm32f4" ) if(${CONFIG_BOARD_NAME} STREQUAL "STM32F407VET6" ) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSTM32F40_41xxx ") @@ -65,14 +66,16 @@ elseif(${CONFIG_CPU_TYPE} STREQUAL "stm32f4" ) ${CMAKE_SOURCE_DIR}/mkrtos_bsp/STM32/STM32F4xx_DSP_StdPeriph_Lib_V1.9.0/Libraries/CMSIS/Device/ST/STM32F4xx/Include ) add_subdirectory(bsp/STM32F4) - set(PACK_CMD "${CMAKE_OBJCOPY} -I binary -O elf32-littlearm -B arm rootfs.cpio rootfs.cpio.elf --rename-section .data=.cpio") + set(LINKS_FLAGS " --gc-section ") + elseif(${CONFIG_CPU_TYPE} STREQUAL "Cortex-R52" ) include_directories( ${CMAKE_SOURCE_DIR}/mkrtos_bootstrap/bsp/Cortex-R52 ) add_subdirectory(bsp/Cortex-R52) - set(PACK_CMD "${CMAKE_OBJCOPY} -I binary -O elf32-littlearm -B arm rootfs.cpio rootfs.cpio.elf --rename-section .data=.cpio") + set(LINKS_FLAGS " --gc-section ") + elseif(${CONFIG_CPU_TYPE} STREQUAL "swm34s" ) file(GLOB bsp_src @@ -89,49 +92,55 @@ elseif(${CONFIG_CPU_TYPE} STREQUAL "swm34s" ) ${CMAKE_SOURCE_DIR}/mkrtos_bsp/SWM34/SWM341_StdPeriph_Driver/SWM341_StdPeriph_Driver ) add_subdirectory(bsp/SWM34S) - set(PACK_CMD "${CMAKE_OBJCOPY} -I binary -O elf32-littlearm -B arm rootfs.cpio rootfs.cpio.elf --rename-section .data=.cpio") + set(LINKS_FLAGS " --gc-section ") + elseif(${CONFIG_CPU_TYPE} STREQUAL "aarch64_qemu" ) include_directories( ${CMAKE_SOURCE_DIR}/mkrtos_bootstrap/bsp/AARCH64_QEMU ) add_subdirectory(bsp/AARCH64_QEMU) - set(PACK_CMD "${CMAKE_OBJCOPY} -I binary -O elf64-littleaarch64 -B aarch64 rootfs.cpio rootfs.cpio.elf --rename-section .data=.cpio") + set(LINKS_FLAGS " ") + endif() -add_custom_target( - gen_sys_cpio +if ((DEFINED CONFIG_MMU) AND (CONFIG_MMU STREQUAL "y")) + add_custom_target( + gen_sys_cpio - COMMAND - cd ${CMAKE_SOURCE_DIR}/build/output/cpio - COMMAND - ls | cpio -H newc -o > ${CMAKE_SOURCE_DIR}/build/output/rootfs.cpio - COMMAND - cd ${CMAKE_SOURCE_DIR}/build/output - COMMAND - eval ${PACK_CMD} - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/build/output - BYPRODUCTS ${CMAKE_SOURCE_DIR}/build/output/rootfs.cpio.elf + COMMAND + cd ${CMAKE_SOURCE_DIR}/build/output/cpio + COMMAND + ls | cpio -H newc -o > ${CMAKE_SOURCE_DIR}/build/output/rootfs.cpio + COMMAND + cd ${CMAKE_SOURCE_DIR}/build/output + COMMAND + ${CMAKE_OBJCOPY} -I binary -O elf64-littleaarch64 -B aarch64 rootfs.cpio rootfs.cpio.elf --rename-section .data=.cpio + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/build/output + BYPRODUCTS ${CMAKE_SOURCE_DIR}/build/output/rootfs.cpio.elf + ) + add_dependencies( + gen_sys_cpio + mkrtos_dump ) - # ${CMAKE_OBJCOPY} -I binary -O elf64-littleaarch64 -B aarch64 rootfs.cpio rootfs.cpio.elf --rename-section .data=.cpio -add_dependencies( - gen_sys_cpio - mkrtos_dump -) - -set_source_files_properties(${CMAKE_SOURCE_DIR}/build/output/rootfs.cpio.elf PROPERTIES EXTERNAL_OBJECT true) - -add_executable(bootstrap.elf + set_source_files_properties(${CMAKE_SOURCE_DIR}/build/output/rootfs.cpio.elf PROPERTIES EXTERNAL_OBJECT true) + add_executable(bootstrap.elf + ${deps} + ${CMAKE_SOURCE_DIR}/build/output/rootfs.cpio.elf + ) + add_dependencies(bootstrap.elf gen_sys_cpio) +else() + add_executable(bootstrap.elf ${deps} - ${CMAKE_SOURCE_DIR}/build/output/rootfs.cpio.elf -) + ) +endif() + # message("CONFIG_CPU_TYPE="${CONFIG_CPU_TYPE}) string(TOUPPER ${CONFIG_CPU_TYPE} cpu_type) set_target_properties(bootstrap.elf PROPERTIES LINK_FLAGS -"-T ${CMAKE_CURRENT_LIST_DIR}/bsp/${cpu_type}/link.lds") +"-T ${CMAKE_CURRENT_LIST_DIR}/bsp/${cpu_type}/link.lds ${LINKS_FLAGS} ") target_link_libraries( bootstrap.elf - # mk_bsp --whole-archive boot_bsp --no-whole-archive @@ -154,5 +163,4 @@ add_custom_target( ${CMAKE_SIZE} bootstrap.elf ) add_dependencies(bootstrap_dump bootstrap.elf) -add_dependencies(bootstrap.elf boot_bsp) -add_dependencies(bootstrap.elf gen_sys_cpio) \ No newline at end of file +add_dependencies(bootstrap.elf boot_bsp) \ No newline at end of file diff --git a/mkrtos_bootstrap/bsp/STM32F2/link.lds b/mkrtos_bootstrap/bsp/STM32F2/link.lds index b991560c6..446c13e01 100755 --- a/mkrtos_bootstrap/bsp/STM32F2/link.lds +++ b/mkrtos_bootstrap/bsp/STM32F2/link.lds @@ -49,7 +49,11 @@ SECTIONS KEEP (*(SORT(.mkrtos.init.*))) _mkrtos_init_end = .; - + . = ALIGN(4); + cpio_start = .; + *(.cpio*) + . = ALIGN(4096); + cpio_end = .; . = ALIGN(4); _etext = .; /* define a global symbols at end of code */ diff --git a/mkrtos_bootstrap/bsp/STM32F4/link.lds b/mkrtos_bootstrap/bsp/STM32F4/link.lds index b991560c6..26bc5407c 100755 --- a/mkrtos_bootstrap/bsp/STM32F4/link.lds +++ b/mkrtos_bootstrap/bsp/STM32F4/link.lds @@ -48,7 +48,12 @@ SECTIONS _mkrtos_init_start = .; KEEP (*(SORT(.mkrtos.init.*))) _mkrtos_init_end = .; - + + . = ALIGN(4); + cpio_start = .; + *(.cpio*) + . = ALIGN(4096); + cpio_end = .; . = ALIGN(4); _etext = .; /* define a global symbols at end of code */ diff --git a/mkrtos_knl/CMakeLists.txt b/mkrtos_knl/CMakeLists.txt index a71bcc9c7..4a43cd5ba 100755 --- a/mkrtos_knl/CMakeLists.txt +++ b/mkrtos_knl/CMakeLists.txt @@ -71,12 +71,18 @@ add_custom_target( COMMAND cp mkrtos.elf ${CMAKE_SOURCE_DIR}/build/output/mkrtos.elf COMMAND - cp mkrtos.elf ${CMAKE_SOURCE_DIR}/build/output/cpio/mkrtos.elf - COMMAND ${CMAKE_OBJDUMP} -s -S mkrtos.elf > ${CMAKE_SOURCE_DIR}/build/output/mkrtos.S COMMAND ${CMAKE_SIZE} mkrtos.elf ) +if ((DEFINED CONFIG_ELF_LAUNCH) AND (CONFIG_ELF_LAUNCH STREQUAL "y")) + add_custom_target( + mkrtos_dump_elf ALL + COMMAND + cp init.elf ${CMAKE_SOURCE_DIR}/build/output/cpio/mkrtos.elf + ) + add_dependencies(mkrtos_dump_elf mkrtos_dump) +endif() add_dependencies(mkrtos.elf link_file_dump) add_dependencies(mkrtos_dump mkrtos.elf) add_dependencies(mkrtos_dump knl) diff --git a/mkrtos_script/debug_m3.sh b/mkrtos_script/debug_m3.sh index 1fcf5344e..f0087f26f 100755 --- a/mkrtos_script/debug_m3.sh +++ b/mkrtos_script/debug_m3.sh @@ -1,6 +1,6 @@ #!/bin/bash -if [ -z "$1"]; then +if [ -z "$1" ]; then echo "usage: ./debug.sh [tcp port]" exit fi diff --git a/mkrtos_user/CMakeLists.txt b/mkrtos_user/CMakeLists.txt index a3353edc2..e96451ce6 100644 --- a/mkrtos_user/CMakeLists.txt +++ b/mkrtos_user/CMakeLists.txt @@ -14,7 +14,7 @@ if (${CONFIG_ARCH} STREQUAL "cortex-m3" OR " ) set(CORTEX_M_LINK_FLAGS "-pie") - set(LIBC_NAME "mulsc") + set(LIBC_NAME "muslc") set(ARCH_NAME "armv7_8m") include_directories( diff --git a/mkrtos_user/lib/sys_util/CMakeLists.txt b/mkrtos_user/lib/sys_util/CMakeLists.txt index ee15d8ccc..125f2947e 100644 --- a/mkrtos_user/lib/sys_util/CMakeLists.txt +++ b/mkrtos_user/lib/sys_util/CMakeLists.txt @@ -2,11 +2,11 @@ cmake_minimum_required(VERSION 3.13) file(GLOB_RECURSE deps *.c *.S) -if (DEFINED CONFIG_ELF_LAUNCH) - if (CONFIG_ELF_LAUNCH STREQUAL "y") - list(REMOVE_ITEM deps ${CMAKE_SOURCE_DIR}/mkrtos_user/lib/sys_util/src/u_app_loader.c) - list(APPEND deps ${CMAKE_SOURCE_DIR}/mkrtos_user/lib/sys_util/src/u_elf_loader.c) - endif() +if ((DEFINED CONFIG_ELF_LAUNCH) AND (CONFIG_ELF_LAUNCH STREQUAL "y")) + list(REMOVE_ITEM deps ${CMAKE_SOURCE_DIR}/mkrtos_user/lib/sys_util/src/u_app_loader.c) +else() + list(REMOVE_ITEM deps ${CMAKE_SOURCE_DIR}/mkrtos_user/lib/sys_util/src/u_elf_loader.c) + list(REMOVE_ITEM deps ${CMAKE_SOURCE_DIR}/mkrtos_user/lib/sys_util/src/u_elf64.c) endif() add_library( diff --git a/mkrtos_user/server/fs/cpiofs/CMakeLists.txt b/mkrtos_user/server/fs/cpiofs/CMakeLists.txt index e2ac89751..9bc437226 100644 --- a/mkrtos_user/server/fs/cpiofs/CMakeLists.txt +++ b/mkrtos_user/server/fs/cpiofs/CMakeLists.txt @@ -59,9 +59,14 @@ add_custom_target( mkdir -p ${CMAKE_SOURCE_DIR}/build/output/cpio COMMAND cp cpiofs.bin ${CMAKE_SOURCE_DIR}/build/output/cpio/cpiofs - COMMAND - cp cpiofs.elf ${CMAKE_SOURCE_DIR}/build/output/cpio/cpiofs.elf ) - +if ((DEFINED CONFIG_ELF_LAUNCH) AND (CONFIG_ELF_LAUNCH STREQUAL "y")) + add_custom_target( + cpiofs_dump_elf ALL + COMMAND + cp cpiofs.elf ${CMAKE_SOURCE_DIR}/build/output/cpio/cpiofs.elf + ) + add_dependencies(cpiofs_dump_elf cpiofs_dump) +endif() add_dependencies(cpiofs_dump cpiofs.elf) \ No newline at end of file diff --git a/mkrtos_user/server/init/CMakeLists.txt b/mkrtos_user/server/init/CMakeLists.txt index 7c347f34a..047a2e925 100644 --- a/mkrtos_user/server/init/CMakeLists.txt +++ b/mkrtos_user/server/init/CMakeLists.txt @@ -42,21 +42,26 @@ add_custom_target( ${CMAKE_OBJDUMP} -s -S init.elf > ${CMAKE_SOURCE_DIR}/build/output/init.S # COMMAND # ${CMAKE_READELF} -a init.elf > ${CMAKE_SOURCE_DIR}/build/output/init.txt - # COMMAND - # ${CMAKE_OBJCOPY} -O binary -S init.elf init.bin + COMMAND + ${CMAKE_OBJCOPY} -O binary -S init.elf init.bin COMMAND ${CMAKE_SIZE} init.elf COMMAND mkdir -p ${CMAKE_SOURCE_DIR}/build/output - # COMMAND - # cp init.bin ${CMAKE_SOURCE_DIR}/build/output/init - # COMMAND - # cp init.elf ${CMAKE_SOURCE_DIR}/build/output/init.elf COMMAND - cp init.elf ${CMAKE_SOURCE_DIR}/build/output/cpio/init.elf + cp init.bin ${CMAKE_SOURCE_DIR}/build/output/init COMMAND cp ${CMAKE_CURRENT_LIST_DIR}/src/init.cfg ${CMAKE_SOURCE_DIR}/build/output/cpio/ + COMMAND + cp init.elf ${CMAKE_SOURCE_DIR}/build/output/init.elf ) - +if ((DEFINED CONFIG_ELF_LAUNCH) AND (CONFIG_ELF_LAUNCH STREQUAL "y")) + add_custom_target( + init_dump_elf ALL + COMMAND + cp init.elf ${CMAKE_SOURCE_DIR}/build/output/cpio/init.elf + ) + add_dependencies(init_dump_elf init_dump) +endif() add_dependencies(init_dump init.elf) add_dependencies(init.elf libc_be util) diff --git a/mkrtos_user/server/shell/CMakeLists.txt b/mkrtos_user/server/shell/CMakeLists.txt index 37cd962f3..e0573a33d 100644 --- a/mkrtos_user/server/shell/CMakeLists.txt +++ b/mkrtos_user/server/shell/CMakeLists.txt @@ -47,9 +47,16 @@ add_custom_target( COMMAND mkdir -p ${CMAKE_SOURCE_DIR}/build/output/cpio COMMAND - cp sh.elf ${CMAKE_SOURCE_DIR}/build/output/cpio/sh.elf + cp sh.bin ${CMAKE_SOURCE_DIR}/build/output/cpio/sh ) - +if ((DEFINED CONFIG_ELF_LAUNCH) AND (CONFIG_ELF_LAUNCH STREQUAL "y")) + add_custom_target( + sh_dump_elf ALL + COMMAND + cp sh.elf ${CMAKE_SOURCE_DIR}/build/output/cpio/sh.elf + ) + add_dependencies(sh_dump_elf shell_dump) +endif() add_dependencies(shell_dump sh.elf) add_dependencies(shell_dump sys) add_dependencies(shell_dump sys_util) diff --git a/mkrtos_user/server/tinycc-arm-thumb/CMakeLists.txt b/mkrtos_user/server/tinycc-arm-thumb/CMakeLists.txt index c8840dc51..60d4e0385 100644 --- a/mkrtos_user/server/tinycc-arm-thumb/CMakeLists.txt +++ b/mkrtos_user/server/tinycc-arm-thumb/CMakeLists.txt @@ -78,10 +78,16 @@ add_custom_target( mkdir -p ${CMAKE_SOURCE_DIR}/build/output/cpio # COMMAND # cp tcc.bin ${CMAKE_SOURCE_DIR}/build/output/cpio/tcc - COMMAND - cp tcc.elf ${CMAKE_SOURCE_DIR}/build/output/cpio/tcc.elf -) +) +if ((DEFINED CONFIG_ELF_LAUNCH) AND (CONFIG_ELF_LAUNCH STREQUAL "y")) + add_custom_target( + tcc_dump_elf ALL + COMMAND + cp tcc.elf ${CMAKE_SOURCE_DIR}/build/output/cpio/tcc.elf + ) + add_dependencies(tcc_dump_elf tcc_dump) +endif() add_dependencies(tcc_dump tcc.elf) add_dependencies(tcc_dump sys) add_dependencies(tcc_dump sys_util)