@@ -28,93 +28,55 @@ function(create_arduino_bootloader_burn_target TARGET_NAME BOARD_ID PROGRAMMER P
28
28
endif ()
29
29
30
30
# look at bootloader.file
31
- set (BOOTLOADER_FOUND True )
32
- if (NOT ${BOARD_ID} .bootloader.file)
33
- set (BOOTLOADER_FOUND False )
34
- # Bootloader is probably defined in the 'menu' settings of the Arduino 1.6 SDK
35
- if (${BOARD_ID} .build .mcu)
36
- GET_MCU(${${BOARD_ID} .build .mcu} BOARD_MCU)
37
- if (NOT ${BOARD_ID} .menu.cpu.${BOARD_MCU} .bootloader.file)
38
- message ("Missing ${BOARD_ID} .bootloader.file, not creating bootloader burn target ${BOOTLOADER_TARGET} ." )
39
- return ()
40
- endif ()
41
- set (BOOTLOADER_FOUND True )
42
- set (${BOARD_ID} .bootloader.file ${${BOARD_ID} .menu.cpu.${BOARD_MCU} .bootloader.file)
43
- endif ()
44
- endif ()
45
-
46
- if (NOT ${BOOTLOADER_FOUND} )
31
+ _get_board_property_if_exists(${BOARD_ID} bootloader.file BOOTLOADER_FILE)
32
+ if (NOT BOOTLOADER_FILE)
33
+ message ("Missing bootloader.file, not creating bootloader burn target ${BOOTLOADER_TARGET} ." )
47
34
return ()
48
- endif ()
35
+ endif ()
49
36
50
37
# build bootloader.path from bootloader.file...
51
- string (REGEX MATCH "(.+/)*" ${BOARD_ID} .bootloader. path ${${BOARD_ID} .bootloader.file })
52
- string (REGEX REPLACE "/" "" ${BOARD_ID} .bootloader. path ${${BOARD_ID} .bootloader. path })
38
+ string (REGEX MATCH "(.+/)*" BOOTLOADER_PATH ${BOOTLOADER_FILE } )
39
+ string (REGEX REPLACE "/" "" BOOTLOADER_PATH ${BOOTLOADER_PATH } )
53
40
# and fix bootloader.file
54
- string (REGEX MATCH "/.(.+)$" ${BOARD_ID} .bootloader.file ${${BOARD_ID} .bootloader.file})
55
- string (REGEX REPLACE "/" "" ${BOARD_ID} .bootloader.file ${${BOARD_ID} .bootloader.file})
56
-
57
- foreach (ITEM unlock_bits high_fuses low_fuses path file)
58
- if (NOT ${BOARD_ID} .bootloader.${ITEM} )
59
- # Try the 'menu' settings of the Arduino 1.6 SDK
60
- if (NOT ${BOARD_ID} .menu.cpu.{BOARD_MCU}.bootloader.${ITEM} )
61
- message ("Missing ${BOARD_ID} .bootloader.${ITEM} , not creating bootloader burn target ${BOOTLOADER_TARGET} ." )
62
- return ()
63
- endif ()
64
- endif ()
65
- endforeach ()
41
+ string (REGEX MATCH "/.(.+)$" BOOTLOADER_FILE_NAME ${BOOTLOADER_FILE} )
42
+ string (REGEX REPLACE "/" "" BOOTLOADER_FILE_NAME ${BOOTLOADER_FILE_NAME} )
66
43
67
- if (NOT EXISTS "${ARDUINO_BOOTLOADERS_PATH} /${${BOARD_ID} .bootloader.path}/${${BOARD_ID} .bootloader.file}" )
68
- message ("${ARDUINO_BOOTLOADERS_PATH} /${${BOARD_ID} .bootloader.path}/${${BOARD_ID} .bootloader.file}" )
69
- message ("Missing bootloader image, not creating bootloader burn target ${BOOTLOADER_TARGET} ." )
44
+ if (NOT EXISTS "${ARDUINO_BOOTLOADERS_PATH} /${BOOTLOADER_PATH} /${BOOTLOADER_FILE_NAME} " )
45
+ message ("Missing bootloader image '${ARDUINO_BOOTLOADERS_PATH} /${BOOTLOADER_PATH} /${BOOTLOADER_FILE_NAME} ', not creating bootloader burn target ${BOOTLOADER_TARGET} ." )
70
46
return ()
71
47
endif ()
72
48
49
+ #check for required bootloader parameters
50
+ foreach (ITEM lock_bits unlock_bits high_fuses low_fuses)
51
+ #do not make fatal error if field doesn't exists, just don't create bootloader burn target
52
+ _get_board_property_if_exists(${BOARD_ID} bootloader.${ITEM} BOOTLOADER_${ITEM} )
53
+ if (NOT BOOTLOADER_${ITEM} )
54
+ message ("Missing bootloader.${ITEM} , not creating bootloader burn target ${BOOTLOADER_TARGET} ." )
55
+ return ()
56
+ endif ()
57
+ endforeach ()
58
+
73
59
# Erase the chip
74
60
list (APPEND AVRDUDE_ARGS "-e" )
75
61
76
62
# Set unlock bits and fuses (because chip is going to be erased)
77
-
78
- if (${BOARD_ID} .bootloader.unlock_bits)
79
- list (APPEND AVRDUDE_ARGS "-Ulock:w:${${BOARD_ID} .bootloader.unlock_bits}:m" )
80
- else ()
81
- # Arduino 1.6 SDK
82
- list (APPEND AVRDUDE_ARGS
83
- "-Ulock:w:${${BOARD_ID} .menu.cpu.${BOARD_MCU} .bootloader.unlock_bits}:m" )
84
- endif ()
85
-
86
- if (${BOARD_ID} .bootloader.extended_fuses)
87
- list (APPEND AVRDUDE_ARGS "-Uefuse:w:${${BOARD_ID} .bootloader.extended_fuses}:m" )
88
- elseif (${${BOARD_ID} .menu.cpu.${BOARD_MCU} .bootloader.extended_fuses})
89
- list (APPEND AVRDUDE_ARGS
90
- "-Uefuse:w:${${BOARD_ID} .menu.cpu.${BOARD_MCU} .bootloader.extended_fuses}:m" )
91
- endif ()
92
- if (${BOARD_ID} .bootloader.high_fuses)
93
- list (APPEND AVRDUDE_ARGS
94
- "-Uhfuse:w:${${BOARD_ID} .bootloader.high_fuses}:m"
95
- "-Ulfuse:w:${${BOARD_ID} .bootloader.low_fuses}:m" )
96
- else ()
97
- list (APPEND AVRDUDE_ARGS
98
- "-Uhfuse:w:${${BOARD_ID} .menu.cpu.${BOARD_MCU} .bootloader.high_fuses}:m"
99
- "-Ulfuse:w:${${BOARD_ID} .menu.cpu.${BOARD_MCU} .bootloader.low_fuses}:m" )
100
- endif ()
101
-
102
- # Set bootloader image
103
- list (APPEND AVRDUDE_ARGS "-Uflash:w:${${BOARD_ID} .bootloader.file}:i" )
104
-
105
- # Set lockbits
106
- if (${BOARD_ID} .bootloader.lock_bits)
107
- list (APPEND AVRDUDE_ARGS "-Ulock:w:${${BOARD_ID} .bootloader.lock_bits}:m" )
108
- else ()
109
- list (APPEND AVRDUDE_ARGS
110
- "-Ulock:w:${${BOARD_ID} .menu.cpu.${BOARD_MCU} .bootloader.lock_bits}:m" )
111
- endif ()
112
-
63
+ list (APPEND AVRDUDE_ARGS "-Ulock:w:${BOOTLOADER_unlock_bits} :m" )
64
+ # extended fuses is optional
65
+ _get_board_property_if_exists(${BOARD_ID} bootloader.extended_fuses BOOTLOADER_extended_fuses)
66
+ if (BOOTLOADER_extended_fuses)
67
+ list (APPEND AVRDUDE_ARGS "-Uefuse:w:${BOOTLOADER_extended_fuses} :m" )
68
+ endif ()
69
+
70
+ list (APPEND AVRDUDE_ARGS
71
+ "-Uhfuse:w:${BOOTLOADER_high_fuses} :m"
72
+ "-Ulfuse:w:${BOOTLOADER_low_fuses} :m"
73
+ "-Uflash:w:${BOOTLOADER_FILE_NAME} :i"
74
+ "-Ulock:w:${BOOTLOADER_lock_bits} :m" )
113
75
114
76
# Create burn bootloader target
115
77
add_custom_target (${BOOTLOADER_TARGET}
116
78
${ARDUINO_AVRDUDE_PROGRAM}
117
79
${AVRDUDE_ARGS}
118
- WORKING_DIRECTORY ${ARDUINO_BOOTLOADERS_PATH} /${${BOARD_ID} .bootloader. path }
80
+ WORKING_DIRECTORY ${ARDUINO_BOOTLOADERS_PATH} /${BOOTLOADER_PATH }
119
81
DEPENDS ${TARGET_NAME} )
120
82
endfunction ()
0 commit comments