@@ -499,7 +499,9 @@ def generate_project_ld_script(sdk_config, ignore_targets=None):
499
499
"env_file" : os .path .join ("$BUILD_DIR" , "config.env" ),
500
500
"libraries_list" : libraries_list ,
501
501
"objdump" : os .path .join (
502
- TOOLCHAIN_DIR , "bin" , env .subst ("$CC" ).replace ("-gcc" , "-objdump" ),
502
+ TOOLCHAIN_DIR ,
503
+ "bin" ,
504
+ env .subst ("$CC" ).replace ("-gcc" , "-objdump" ),
503
505
),
504
506
}
505
507
@@ -803,19 +805,90 @@ def find_default_component(target_configs):
803
805
return ""
804
806
805
807
806
- def create_verion_file ():
808
+ def create_version_file ():
807
809
version_file = os .path .join (FRAMEWORK_DIR , "version.txt" )
808
810
if not os .path .isfile (version_file ):
809
811
with open (version_file , "w" ) as fp :
810
812
fp .write (platform .get_package_version ("framework-espidf" ))
811
813
812
814
813
- #
815
+ def generate_empty_partition_image (binary_path , image_size ):
816
+ empty_partition = env .Command (
817
+ binary_path ,
818
+ None ,
819
+ env .VerboseAction (
820
+ '"$PYTHONEXE" "%s" %s $TARGET'
821
+ % (
822
+ os .path .join (
823
+ FRAMEWORK_DIR ,
824
+ "components" ,
825
+ "partition_table" ,
826
+ "gen_empty_partition.py" ,
827
+ ),
828
+ image_size ,
829
+ ),
830
+ "Generating an empty partition $TARGET" ,
831
+ ),
832
+ )
833
+
834
+ env .Depends ("$BUILD_DIR/$PROGNAME$PROGSUFFIX" , empty_partition )
835
+
836
+
837
+ def get_partition_info (pt_path , pt_offset , pt_params ):
838
+ assert os .path .isfile (pt_path )
839
+ cmd = [
840
+ env .subst ("$PYTHONEXE" ),
841
+ os .path .join (FRAMEWORK_DIR , "components" , "partition_table" , "parttool.py" ),
842
+ "-q" ,
843
+ "--partition-table-offset" ,
844
+ hex (pt_offset ),
845
+ "--partition-table-file" ,
846
+ pt_path ,
847
+ "get_partition_info" ,
848
+ "--info" ,
849
+ "size" ,
850
+ "offset" ,
851
+ ]
852
+
853
+ if pt_params ["name" ] == "boot" :
854
+ cmd .append ("--partition-boot-default" )
855
+ else :
856
+ cmd .extend (
857
+ [
858
+ "--partition-type" ,
859
+ pt_params ["type" ],
860
+ "--partition-subtype" ,
861
+ pt_params ["subtype" ],
862
+ ]
863
+ )
864
+
865
+ result = exec_command (cmd )
866
+ if result ["returncode" ] != 0 :
867
+ sys .stderr .write (
868
+ "Couldn't extract information for %s/%s from the partition table\n "
869
+ % (pt_params ["type" ], pt_params ["subtype" ])
870
+ )
871
+ sys .stderr .write (result ["out" ] + "\n " )
872
+ sys .stderr .write (result ["err" ] + "\n " )
873
+ env .Exit (1 )
874
+
875
+ size = offset = 0
876
+ if result ["out" ].strip ():
877
+ size , offset = result ["out" ].strip ().split (" " , 1 )
878
+
879
+ return {"size" : size , "offset" : offset }
880
+
881
+
882
+ def get_app_partition_offset (pt_table , pt_offset ):
883
+ # Get the default boot partition offset
884
+ app_params = get_partition_info (pt_table , pt_offset , {"name" : "boot" })
885
+ return app_params .get ("offset" , "0x10000" )
886
+
887
+
814
888
# ESP-IDF package doesn't contain .git folder, instead package version is specified
815
889
# in a special file "version.h" in the root folder of the package
816
- #
817
890
818
- create_verion_file ()
891
+ create_version_file ()
819
892
820
893
#
821
894
# Generate final linker script
@@ -845,6 +918,7 @@ def create_verion_file():
845
918
846
919
fwpartitions_dir = os .path .join (FRAMEWORK_DIR , "components" , "partition_table" )
847
920
partitions_csv = board .get ("build.partitions" , "partitions_singleapp.csv" )
921
+
848
922
env .Replace (
849
923
PARTITIONS_TABLE_CSV = os .path .abspath (
850
924
os .path .join (fwpartitions_dir , partitions_csv )
@@ -913,6 +987,7 @@ def create_verion_file():
913
987
[
914
988
"-DIDF_TARGET=" + idf_variant ,
915
989
"-DEXTRA_COMPONENT_DIRS:PATH=" + ";" .join (extra_components ),
990
+ "-DPYTHON=" + env .subst ("$PYTHONEXE" ),
916
991
]
917
992
+ click .parser .split_arg_string (board .get ("build.cmake_extra_args" , "" )),
918
993
)
@@ -1057,6 +1132,7 @@ def _skip_prj_source_files(node):
1057
1132
)
1058
1133
)
1059
1134
1135
+ partition_table_offset = sdk_config .get ("PARTITION_TABLE_OFFSET" , 0x8000 )
1060
1136
project_flags .update (link_args )
1061
1137
env .MergeFlags (project_flags )
1062
1138
env .Prepend (
@@ -1065,8 +1141,14 @@ def _skip_prj_source_files(node):
1065
1141
LINKFLAGS = extra_flags ,
1066
1142
LIBS = libs ,
1067
1143
FLASH_EXTRA_IMAGES = [
1068
- ("0x1000" , os .path .join ("$BUILD_DIR" , "bootloader.bin" )),
1069
- ("0x8000" , os .path .join ("$BUILD_DIR" , "partitions.bin" )),
1144
+ (
1145
+ board .get ("upload.bootloader_offset" , "0x1000" ),
1146
+ os .path .join ("$BUILD_DIR" , "bootloader.bin" ),
1147
+ ),
1148
+ (
1149
+ board .get ("upload.partition_table_offset" , hex (partition_table_offset )),
1150
+ os .path .join ("$BUILD_DIR" , "partitions.bin" ),
1151
+ ),
1070
1152
],
1071
1153
)
1072
1154
@@ -1087,3 +1169,42 @@ def _skip_prj_source_files(node):
1087
1169
ulp_dir = os .path .join (env .subst ("$PROJECT_DIR" ), "ulp" )
1088
1170
if os .path .isdir (ulp_dir ) and os .listdir (ulp_dir ):
1089
1171
env .SConscript ("ulp.py" , exports = "env project_config idf_variant" )
1172
+
1173
+ #
1174
+ # Process OTA partition and image
1175
+ #
1176
+
1177
+ ota_partition_params = get_partition_info (
1178
+ env .subst ("$PARTITIONS_TABLE_CSV" ),
1179
+ partition_table_offset ,
1180
+ {"name" : "ota" , "type" : "data" , "subtype" : "ota" },
1181
+ )
1182
+
1183
+ if ota_partition_params ["size" ] and ota_partition_params ["offset" ]:
1184
+ # Generate an empty image if OTA is enabled in partition table
1185
+ ota_partition_image = os .path .join ("$BUILD_DIR" , "ota_data_initial.bin" )
1186
+ generate_empty_partition_image (ota_partition_image , ota_partition_params ["size" ])
1187
+
1188
+ env .Append (
1189
+ FLASH_EXTRA_IMAGES = [
1190
+ (
1191
+ board .get (
1192
+ "upload.ota_partition_offset" , ota_partition_params ["offset" ]
1193
+ ),
1194
+ ota_partition_image ,
1195
+ )
1196
+ ]
1197
+ )
1198
+
1199
+ #
1200
+ # Configure application partition offset
1201
+ #
1202
+
1203
+ env .Replace (
1204
+ ESP32_APP_OFFSET = get_app_partition_offset (
1205
+ env .subst ("$PARTITIONS_TABLE_CSV" ), partition_table_offset
1206
+ )
1207
+ )
1208
+
1209
+ # Propagate application offset to debug configurations
1210
+ env ["IDE_EXTRA_DATA" ].update ({"application_offset" : env .subst ("$ESP32_APP_OFFSET" )})
0 commit comments