lin
2025-08-20 171e08343a9b6df6c31197f5b4800e8004800f5b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
define soong_config_add
$(strip \
    $(if $(1),,$(error Parameter 1 namespace empty))
    $(if $(2),,$(error Parameter 2 configkey empty))
    $(eval SOONG_CONFIG_NAMESPACES := $(sort $(1) $(SOONG_CONFIG_NAMESPACES)))
    $(eval SOONG_CONFIG_$(1) := $(sort $(2) $(SOONG_CONFIG_$(1))))
    $(eval SOONG_CONFIG_$(1)_$(2) := $(3))
)
endef
 
# For auto load partition size config
define get_sys_partition_path
$(strip \
    $(if $(BOARD_ADD_PACK_CONFIG),
        $(eval __exist := $(filter %/sys_partition.fex,$(BOARD_ADD_PACK_CONFIG)))
        $(if $(__exist),
            $(eval __sys_partition_path := $(shell dirname $(__exist)))
        ),
        $(if $(wildcard $(TOP_DIR)../*/device/config/chips),
            $(eval __chip_path := $(shell cd $(TOP_DIR)../*/device/config/chips && pwd))
            $(eval __sys_partition_path := $(__chip_path)/$(TARGET_BOARD_IC)/configs/$(PRODUCT_BOARD)/android),
            $(eval __chip_path := $(shell cd $(TOP_DIR)../*/tools/pack/chips && pwd))
            $(eval __sys_partition_path := $(__chip_path)/$(TARGET_BOARD_CHIP)/configs/$(PRODUCT_BOARD))
        )
    )
    $(shell echo $(__sys_partition_path))
)
endef
 
define get_partition_size
$(strip \
    $(eval __def := $(call get_sys_partition_path)/sys_partition.fex)
    $(if $(strip $(1)),,$(error Parameter 1 partition name empty))
    $(if $(strip $(2)),$(eval __cfg := $(2)),$(eval __cfg := $(__def)))
    $(if $(wildcard $(__cfg)),,$(error Config file $(__cfg) not found))
    $(eval __size := $(shell sed -n '/^\s*name\s*=\s*$(1)\s*$$/,/^\s*user_type\s*=/p' $(__cfg) | awk -F= '/size/{print $$2}'))
    $(if $(__size),,$(error Cannot find size config for partition $(1)))
    $(eval __number := $(shell echo $(__size) | sed 's|[a-z,A-Z]*$$||g'))
    $(eval __dimension :=$(shell echo $(__size) | sed 's|^[0-9,.]\+||g'))
    $(if $(__dimension),
        $(if $(filter B b,$(__dimension)),
            $(eval __m := 1),
            $(if $(filter K k,$(__dimension)),
                $(eval __m := 1024),
                $(if $(filter M m,$(__dimension)),
                    $(eval __m := 1048576),
                    $(if $(filter G g,$(__dimension)),
                        $(eval __m := 1073741824),
                        $(error Error Dimension($(__dimension)))
                    )
                )
            )
        ),
        $(eval __m := 512)
    )
    $(shell echo "$(__m) * $(__number)" | bc | awk -F. '{print $$1}')
)
endef
 
define copy-user-file
LOCAL_PATH := $$(shell dirname $1)
include $$(CLEAR_VARS)
LOCAL_MODULE := $$(subst /,-,$2)
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_PATH := $$(shell dirname $2)
ifeq ($$(filter $$(PRODUCT_OUT)%,$$(LOCAL_MODULE_PATH)),)
LOCAL_MODULE_PATH := $$(PRODUCT_OUT)/$$(LOCAL_MODULE_PATH)
endif
LOCAL_MODULE_STEM := $$(shell basename $2)
LOCAL_SRC_FILES := $$(shell basename $1)
include $$(BUILD_PREBUILT)
endef
 
define get-copy-file-src
$(strip $(shell echo $(1) | awk -F':' '{print $$1}'))
endef
 
define get-copy-file-dst
$(strip $(shell echo $(1) | awk -F':' '{print $$2}'))
endef
 
define get-copy-file-name
$(strip $(subst /,-,$(call get-copy-file-dst,$(1))))
endef
 
define define-copy-target
$(foreach f,$(1),\
    $(eval __internal_current_name := $(call get-copy-file-name,$(f))) \
    $(if $(filter $(__internal_current_name),$(__internal_total_name)), \
        $(warning $(__internal_current_name) allready defined, skip.), \
        $(eval __internal_total_name += $(__internal_current_name)) \
        $(eval $(call copy-user-file,$(call get-copy-file-src,$(f)),$(call get-copy-file-dst,$(f)))) \
    ) \
)
endef
 
define get-copy-target
$(eval __name :=) \
$(foreach f,$(1),\
    $(eval __name += $(call get-copy-file-name,$(f)))) \
$(__name)
endef