boot2-pico.py 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # WizIO 2021 Georgi Angelov
  2. # http://www.wizio.eu/
  3. # https://github.com/Wiz-IO/wizio-pico
  4. import os
  5. from os.path import join
  6. from SCons.Script import DefaultEnvironment, Builder
  7. from common import *
  8. def dev_create_asm(target, source, env):
  9. py = join(env.framework_dir, env.sdk, "boot_stage2", "pad_checksum")
  10. dir = join(env["BUILD_DIR"], env["PROGNAME"])
  11. env.Execute("python " + py + " -s 0xffffffff " + dir + ".bin " + dir + ".S")
  12. f = open(dir + ".S", "a")
  13. f.write('\n#include "../link.S')
  14. f.close()
  15. def dev_compiler(env):
  16. env.Replace(
  17. BUILD_DIR = env.subst("$BUILD_DIR").replace("\\", "/"),
  18. AR="arm-none-eabi-ar",
  19. AS="arm-none-eabi-as",
  20. CC="arm-none-eabi-gcc",
  21. GDB="arm-none-eabi-gdb",
  22. CXX="arm-none-eabi-g++",
  23. OBJCOPY="arm-none-eabi-objcopy",
  24. RANLIB="arm-none-eabi-ranlib",
  25. SIZETOOL="arm-none-eabi-size",
  26. ARFLAGS=["rc"],
  27. SIZEPROGREGEXP=r"^(?:\.text|\.data|\.bootloader)\s+(\d+).*",
  28. SIZEDATAREGEXP=r"^(?:\.data|\.bss|\.noinit)\s+(\d+).*",
  29. SIZECHECKCMD="$SIZETOOL -A -d $SOURCES",
  30. SIZEPRINTCMD='$SIZETOOL --mcu=$BOARD_MCU -C -d $SOURCES',
  31. PROGSUFFIX=".elf",
  32. PROGNAME = "BOOT-2"
  33. )
  34. env.cortex = ["-mcpu=cortex-m0plus", "-mthumb"]
  35. def dev_init(env, platform):
  36. print( "RASPBERRYPI PI PICO RP2040 BOOT STAGE 2 COMPILER")
  37. env.platform = platform
  38. env.framework_dir = env.PioPlatform().get_package_dir("framework-wizio-pico")
  39. env.libs = []
  40. dev_compiler(env)
  41. dev_create_template(env)
  42. env.Append(
  43. ASFLAGS=[ env.cortex, "-x", "assembler-with-cpp" ],
  44. CPPDEFINES = [ "PICO_FLASH_SPI_CLKDIV=2"],
  45. CPPPATH = [
  46. join("$PROJECT_DIR", "include"),
  47. join(env.framework_dir, env.sdk, "include"),
  48. join(env.framework_dir, env.sdk, "boards"),
  49. join(env.framework_dir, env.sdk, "boot_stage2", "asminclude"),
  50. ],
  51. CFLAGS = [
  52. env.cortex,
  53. "-Os",
  54. "-fdata-sections",
  55. "-ffunction-sections",
  56. "-Wall",
  57. "-Wfatal-errors",
  58. "-Wstrict-prototypes",
  59. ],
  60. LINKFLAGS = [
  61. env.cortex,
  62. "-Os",
  63. "-nostartfiles",
  64. "-nostdlib",
  65. "-Wall",
  66. "-Wfatal-errors",
  67. "--entry=_stage2_boot"
  68. ],
  69. LDSCRIPT_PATH = [ join(env.framework_dir, env.sdk, "boot_stage2", "boot_stage2.ld") ],
  70. BUILDERS = dict(
  71. ElfToBin = Builder(
  72. action = env.VerboseAction(" ".join([
  73. "$OBJCOPY",
  74. "-O",
  75. "binary",
  76. "$SOURCES",
  77. "$TARGET",
  78. ]), "Building $TARGET"),
  79. suffix = ".bin"
  80. )
  81. ),
  82. UPLOADCMD = dev_create_asm
  83. )
  84. libs = []
  85. env.Append(LIBS = libs)
  86. # Select file, Clean, Upload, Get boot2.S from build folder
  87. env.BuildSources(join("$BUILD_DIR", "BOOT2"), join(env.framework_dir, env.sdk, "boot_stage2"), src_filter="-<*> +<boot2_w25q080.S>") # is default
  88. #env.BuildSources(join("$BUILD_DIR", "BOOT2"), join(env.framework_dir, env.sdk, "boot_stage2"), src_filter="-<*> +<boot2_w25x10cl.S>")
  89. #env.BuildSources(join("$BUILD_DIR", "BOOT2"), join(env.framework_dir, env.sdk, "boot_stage2"), src_filter="-<*> +<boot2_is25lp080.S>")
  90. #env.BuildSources(join("$BUILD_DIR", "BOOT2"), join(env.framework_dir, env.sdk, "boot_stage2"), src_filter="-<*> +<boot2_generic_03h.S>")
  91. #env.BuildSources(join("$BUILD_DIR", "BOOT2"), join(env.framework_dir, env.sdk, "boot_stage2"), src_filter="-<*> +<boot2_usb_blinky.S>")