ninja2mdk.cmd 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. @echo off
  2. setlocal ENABLEDELAYEDEXPANSION
  3. ::--------------------------------------------------------
  4. ::-- %1: board-name
  5. ::-- %2: app-dir
  6. ::-- %3: cfg-dir
  7. ::-- %4: lib-name
  8. ::--------------------------------------------------------
  9. if "%2" == "" (
  10. @echo Usage:
  11. @echo %~nx0 board-name app-dir cfg-dir [lib-name]
  12. @echo Example:
  13. @echo %~nx0 lark_dvb_watch samples\hello_world .
  14. goto :eof
  15. )
  16. set lib=
  17. if not "%4" == "" (
  18. set lib=%4
  19. )
  20. set tc=clang
  21. set board=%1
  22. set adir=%~2
  23. set cfgdir=%3
  24. set cfgfile=%cfgdir:\=/%/prj.conf
  25. set bdir=%~2\outdir\%board%\mdk_%tc%
  26. set sdir=%cd%
  27. set zdir=%sdir%
  28. set mdk=%sdir%\tools\mdk_%tc%
  29. rmdir /S /Q %bdir% >nul 2>nul
  30. call "%zdir%\zephyr-env.cmd"
  31. cmake -GNinja -DBOARD=%board% -H%adir% -B%bdir% -DCONF_FILE=%cfgfile%
  32. call :GET_SOC_NAME soc_name
  33. call :GET_SYSCALL_INCS syscall_incs
  34. python %zdir%/scripts/parse_syscalls.py %syscall_incs% --json-file %bdir%/zephyr/misc/generated/syscalls.json --tag-struct-file %bdir%/zephyr/misc/generated/struct_tags.json
  35. python %zdir%/scripts/gen_kobject_list.py --validation-output %bdir%/zephyr/include/generated/driver-validation.h --include %bdir%/zephyr/misc/generated/struct_tags.json
  36. python %zdir%/scripts/gen_kobject_list.py --kobj-types-output %bdir%/zephyr/include/generated/kobj-types-enum.h --kobj-otype-output %bdir%/zephyr/include/generated/otype-to-str.h --kobj-size-output %bdir%/zephyr/include/generated/otype-to-size.h --include %bdir%/zephyr/misc/generated/struct_tags.json
  37. python %zdir%/scripts/gen_syscalls.py --json-file %bdir%/zephyr/misc/generated/syscalls.json --base-output %bdir%/zephyr/include/generated/syscalls --syscall-dispatch %bdir%/zephyr/include/generated/syscall_dispatch.c --syscall-list %bdir%/zephyr/include/generated/syscall_list.h --split-type k_timeout_t
  38. set offs=arch/arm/core/offsets/offsets.c
  39. %GNUARMEMB_TOOLCHAIN_PATH%\bin\arm-none-eabi-gcc.exe ^
  40. -DKERNEL -D_FORTIFY_SOURCE=2 -D__PROGRAM_START -D__ZEPHYR__=1 ^
  41. -I%zdir%/kernel/include -I%zdir%/arch/arm/include -I%zdir%/include -I%bdir%/zephyr/include/generated -I%zdir%/drivers -I%zdir%/subsys/tracing/include -I%zdir%/subsys/tracing/sysview -I%sdir%/soc/arm/actions/leopard -I%sdir%/../thirdparty/hal/cmsis/CMSIS/Core/Include -I%zdir%/modules/segger -I%zdir%/../thirdparty/debug/segger/SEGGER -I%zdir%/../thirdparty/debug/segger/Config -I%sdir%/../thirdparty/debug/segger/systemview -isystem %zdir%/lib/libc/minimal/include -isystem %GNUARMEMB_TOOLCHAIN_PATH%/lib/gcc/arm-none-eabi/9.3.1/include ^
  42. -Os -imacros%bdir%/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -mcpu=cortex-m33+nodsp -mthumb -mabi=aapcs -imacros%zdir%/include/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-main -Wno-address-of-packed-member -Wno-pointer-sign -Wpointer-arith -Wno-unused-but-set-variable -Werror=implicit-int -fno-asynchronous-unwind-tables -fno-pie -fno-pic -fno-strict-overflow -fno-reorder-functions -fno-defer-pop -ffunction-sections -fdata-sections -std=c99 -nostdinc ^
  43. -MD -MT %bdir%/zephyr/CMakeFiles/offsets.dir/%offs%.obj -MF %bdir%/zephyr/CMakeFiles/offsets.dir/%offs%.obj.d ^
  44. -o %bdir%/zephyr/CMakeFiles/offsets.dir/%offs%.obj -c %zdir%/%offs%
  45. python %zdir%/scripts/gen_offset_header.py -i %bdir%/zephyr/CMakeFiles/offsets.dir/%offs%.obj -o %bdir%/zephyr/include/generated/offsets.h
  46. copy /Y %mdk%\common\* %bdir%\
  47. copy /Y %mdk%\soc\%soc_name%\* %bdir%\
  48. if exist %mdk%\boards\%board% (
  49. copy /Y %mdk%\boards\%board%\* %bdir%
  50. )
  51. call :GEN_PACK_BAT %board% %adir% %bdir%
  52. if exist %adir%\mdk_%tc% (
  53. copy /Y %adir%\mdk_%tc%\* %bdir%
  54. )
  55. if exist %adir%\%cfgdir%\mdk_%tc% (
  56. copy /Y %adir%\%cfgdir%\mdk_%tc%\* %bdir%
  57. )
  58. %sdir%\tools\ninja2mdk.exe %bdir%\build.ninja %bdir%\template.uvprojx %bdir%\mdk_%tc%.uvprojx %lib%
  59. del /S /Q %bdir%\template.* >nul 2>nul
  60. mkdir %bdir%\tmp
  61. move /Y %bdir%\zephyr\.config %bdir%\tmp\ >nul 2>nul
  62. echo /*empty file*/ > %bdir%\tmp\ksyms.S
  63. move /Y %bdir%\zephyr\include %bdir%\tmp\ >nul 2>nul
  64. rmdir /S /Q %bdir%\app %bdir%\src %bdir%\CMakeFiles %bdir%\Kconfig %bdir%\thirdparty %bdir%\zephyr >nul 2>nul
  65. del /S /Q %bdir%\cmake_install.cmake %bdir%\CMakeCache.txt %bdir%\zephyr_modules.txt %bdir%\zephyr_settings.txt >nul 2>nul
  66. move /Y %bdir%\tmp %bdir%\zephyr >nul 2>nul
  67. goto:eof
  68. ::--------------------------------------------------------
  69. ::-- get soc name
  70. ::-- %1: ret var
  71. ::--------------------------------------------------------
  72. :GET_SOC_NAME
  73. for /f "tokens=1-3 delims= " %%a in (%bdir%\zephyr\include\generated\autoconf.h) do (
  74. if "%%b" == "CONFIG_SOC_SERIES" (
  75. set %1=%%~c
  76. )
  77. )
  78. goto:eof
  79. ::--------------------------------------------------------
  80. ::-- get syscalls incs
  81. ::-- %1: ret var
  82. ::--------------------------------------------------------
  83. :GET_SYSCALL_INCS
  84. for /f "tokens=1-3 delims= " %%a in (%bdir%\zephyr\include\generated\autoconf.h) do (
  85. if "%%b" == "CONFIG_ZTEST" (
  86. set ztestinc=--include %zdir%/subsys/testsuite/ztest/include
  87. )
  88. if "%%b" == "CONFIG_TRACING" (
  89. set tracinginc=--include %zdir%/subsys/tracing/include
  90. )
  91. if "%%b" == "CONFIG_APPLICATION_DEFINED_SYSCALL" (
  92. set appinc=--include %adir%
  93. )
  94. )
  95. set %1=--include %zdir%/include --include %zdir%/drivers --include %zdir%/subsys/net %ztestinc% %appinc% %tracinginc%
  96. goto:eof
  97. ::--------------------------------------------------------
  98. ::-- gen pack bat
  99. ::-- %1: board
  100. ::-- %2: app dir
  101. ::-- %3: build dir
  102. ::--------------------------------------------------------
  103. :GEN_PACK_BAT
  104. set zbase=..\..\..\..\..\..\zephyr
  105. echo @echo off > %3\PackCommand.bat
  106. echo copy /Y /B zephyr.bin %zbase%\boards\arm\%1\%~n2.bin >> %3\PackCommand.bat
  107. goto:eof