-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
680 lines (587 loc) · 28.5 KB
/
Makefile
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
#
# Voice Signal Preprocess
# Copyright (C) 2001-2023 NationalChip Co., Ltd
# ALL RIGHTS RESERVED!
#
# Makefile: MCU Top Makefile
#
#=================================================================================#
# Toolchain Configurations
.PHONY: uart defconfig menuconfig post_config autoconf
all: build
# absolute path
CURDIR := $(shell pwd)
Q := @
obj := $(CURDIR)/scripts/kconfig
SUBDIR := $(obj)
CONFIG_KCONFIG := Kconfig
ifeq ($(quiet),silent_)
silent := -s
endif
ifneq (,$(wildcard $(CURDIR)/.config))
include $(CURDIR)/.config
endif
uart :
@make -f uart_boot.mk
defconfig : .config $(obj)/conf
@echo | $(obj)/conf --oldconfig Kconfig
@scripts/autoconf.sh > /dev/null
@scripts/config_parse.sh > /dev/null
novuiconfig : $(obj)/mconf $(obj)/conf
@cp .config novui.config
@mv lvp/vui .
$(Q)$< $(CONFIG_KCONFIG)
@scripts/autoconf.sh > /dev/null
@scripts/config_parse.sh > /dev/null
@test -f lvp/vui/Kconfig || sed -i "3 i#include \"vui/vuiconf.h\"" ./include/autoconf.h
@mv vui lvp
@mv novui.config .config
menuconfig : $(obj)/mconf $(obj)/conf
$(Q)$< $(CONFIG_KCONFIG)
@scripts/autoconf.sh > /dev/null
@scripts/config_parse.sh > /dev/null
@test -f lvp/vui/Kconfig || sed -i "3 i#include \"vui/vuiconf.h\"" ./include/autoconf.h
multiboot:
@echo -e "\033[36m _____________________________/Note\___________________________________ \033[0m"
@echo -e "\033[36m / \ \033[0m"
@echo -e "\033[36m Multi-boot supports running two firmwares on one flash ! \033[0m"
@echo -e "\033[36m Need prepare first.config and second.config of the two firmwares \033[0m"
@echo -e "\033[36m \______________________________________________________________________/ \033[0m"
@
@rm ./_output/ -rf
@mkdir ./_output/
@test -f first.config || echo -e "\033[31m "Cannot find ./first.config, need first.config and second.config!" \033[0m"
@test -f second.config || echo -e "\033[31m "Cannot find ./second.config, need first.config and second.config!" \033[0m"
@cp first.config ./_output/
@cp second.config ./_output/
@sed -i '/CONFIG_BOARD_SUPPORT_MULTIBOOT */d' ./_output/first.config
@sed -i '/CONFIG_MULTIBOOT_FIRST_BIN */d' ./_output/first.config
@sed -i '/CONFIG_MULTIBOOT_SECOND_BIN */d' ./_output/first.config
@sed -i '/CONFIG_SECOND_BIN_OFFSET */d' ./_output/first.config
@sed -i '/CONFIG_SECOND_BIN_STAGE2_BIN_SIZE */d' ./_output/first.config
@sed -i '/CONFIG_SECOND_BIN_NPU_SRAM_SIZE_KB */d' ./_output/first.config
@sed -i "5 iCONFIG_BOARD_SUPPORT_MULTIBOOT=y" ./_output/first.config
@sed -i "5 iCONFIG_MULTIBOOT_FIRST_BIN=y" ./_output/first.config
@sed -i "5 iCONFIG_SECOND_BIN_OFFSET=0x0" ./_output/first.config
@sed -i "5 iCONFIG_SECOND_BIN_STAGE2_BIN_SIZE=0x0" ./_output/first.config
@sed -i "5 iCONFIG_SECOND_BIN_NPU_SRAM_SIZE_KB=0" ./_output/first.config
@
@
@sed -i '/CONFIG_BOARD_SUPPORT_MULTIBOOT */d' ./_output/second.config
@sed -i '/CONFIG_MULTIBOOT_FIRST_BIN */d' ./_output/second.config
@sed -i '/CONFIG_MULTIBOOT_SECOND_BIN */d' ./_output/second.config
@sed -i '/CONFIG_SECOND_BIN_OFFSET */d' ./_output/second.config
@sed -i '/CONFIG_SECOND_BIN_STAGE2_BIN_SIZE */d' ./_output/second.config
@sed -i '/CONFIG_SECOND_BIN_NPU_SRAM_SIZE_KB */d' ./_output/second.config
@
@sed -i "5 iCONFIG_BOARD_SUPPORT_MULTIBOOT=y" ./_output/second.config
@sed -i "5 iCONFIG_MULTIBOOT_SECOND_BIN=y" ./_output/second.config
@sed -i "5 iCONFIG_SECOND_BIN_OFFSET=0x0" ./_output/second.config
@sed -i "5 iCONFIG_SECOND_BIN_STAGE2_BIN_SIZE=0x0" ./_output/second.config
@sed -i "5 iCONFIG_SECOND_BIN_NPU_SRAM_SIZE_KB=0" ./_output/second.config
@
@echo -e "\033[36m _____________________________/Note\___________________________________ \033[0m"
@echo -e "\033[36m / \ \033[0m"
@echo -e "\033[36m Start build first part! \033[0m"
@echo -e "\033[36m \______________________________________________________________________/ \033[0m"
@cp ./_output/first.config .config
@echo | $(obj)/conf --oldconfig Kconfig
@scripts/autoconf.sh > /dev/null
@scripts/config_parse.sh > /dev/null
@make clean;make
@echo -e "\033[36m _____________________________/Note\___________________________________ \033[0m"
@echo -e "\033[36m / \ \033[0m"
@echo -e "\033[36m Build first part done! \033[0m"
@echo -e "\033[36m \______________________________________________________________________/ \033[0m"
@
@cp output/mcu_nor.bin ./_output/first_mcu_nor.bin
@
@sed -i '/CONFIG_SECOND_BIN_OFFSET */d' ./_output/second.config
@sed -i "5 iCONFIG_SECOND_BIN_OFFSET=0x$$(echo "obase=16;ibase=10;$$(stat -c %s _output/first_mcu_nor.bin | tr -d '\n')" | bc)" ./_output/second.config
@
@echo -e "\033[36m _____________________________/Note\___________________________________ \033[0m"
@echo -e "\033[36m / \ \033[0m"
@echo -e "\033[36m Start build second part! \033[0m"
@echo -e "\033[36m \______________________________________________________________________/ \033[0m"
@cp ./_output/first.config .config
@cp ./_output/second.config .config
@echo | $(obj)/conf --oldconfig Kconfig
@scripts/autoconf.sh > /dev/null
@scripts/config_parse.sh > /dev/null
@make clean;make
@echo -e "\033[36m _____________________________/Note\___________________________________ \033[0m"
@echo -e "\033[36m / \ \033[0m"
@echo -e "\033[36m Build second part done! \033[0m"
@echo -e "\033[36m \______________________________________________________________________/ \033[0m"
@
@
@cp output/mcu.elf ./_output/second_mcu_nor.elf
@cp output/mcu_nor.bin ./_output/second_mcu_nor.bin
@
@sed -i '/CONFIG_SECOND_BIN_NPU_SRAM_SIZE_KB */d' ./_output/first.config
@sed -i "5 iCONFIG_SECOND_BIN_NPU_SRAM_SIZE_KB=$$(grep CONFIG_NPU_SRAM_SIZE_KB ./second.config | cut -d = -f 2)" ./_output/first.config
@
@sed -i '/CONFIG_SECOND_BIN_STAGE2_BIN_SIZE */d' ./_output/first.config
@sed -i "5 iCONFIG_SECOND_BIN_STAGE2_BIN_SIZE=0x$$(echo "obase=16;ibase=10;$$(echo "\
$$(echo "obase=10;ibase=16; $$(readelf -s ./_output/second_mcu_nor.elf |grep -E "_stage2_sram_end_text_" | awk '{str = $$2};NR==1{str1 = str};NR==1{printf str};' | xargs echo | tr [:lower:] [:upper:])" | bc) \
- $$(echo "obase=10;ibase=16; $$(readelf -s ./_output/second_mcu_nor.elf |grep -E "_stage2_sram_start_text_" | awk '{str = $$2};NR==1{str1 = str};NR==1{printf str};' | xargs echo | tr [:lower:] [:upper:])" | bc) \
+ $$(echo "obase=10;ibase=16; $$(readelf -s ./_output/second_mcu_nor.elf |grep -E "_stage2_sram_end_data_" | awk '{str = $$2};NR==1{str1 = str};NR==1{printf str};' | xargs echo | tr [:lower:] [:upper:])" | bc) \
- $$(echo "obase=10;ibase=16; $$(readelf -s ./_output/second_mcu_nor.elf |grep -E "_stage2_sram_start_data_" | awk '{str = $$2};NR==1{str1 = str};NR==1{printf str};' | xargs echo | tr [:lower:] [:upper:])" | bc)"\
| bc)" | bc)" ./_output/first.config
# @echo "obase=16;ibase=10;$$(echo "\
$$(echo "obase=10;ibase=16; $$(readelf -s output/mcu.elf |grep -E "_stage2_sram_end_text_" | awk '{str = $$2};NR==1{str1 = str};NR==1{printf str};' | xargs echo | tr [:lower:] [:upper:])" | bc) \
- $$(echo "obase=10;ibase=16; $$(readelf -s output/mcu.elf |grep -E "_stage2_sram_start_text_" | awk '{str = $$2};NR==1{str1 = str};NR==1{printf str};' | xargs echo | tr [:lower:] [:upper:])" | bc) \
+ $$(echo "obase=10;ibase=16; $$(readelf -s output/mcu.elf |grep -E "_stage2_sram_end_data_" | awk '{str = $$2};NR==1{str1 = str};NR==1{printf str};' | xargs echo | tr [:lower:] [:upper:])" | bc) \
- $$(echo "obase=10;ibase=16; $$(readelf -s output/mcu.elf |grep -E "_stage2_sram_start_data_" | awk '{str = $$2};NR==1{str1 = str};NR==1{printf str};' | xargs echo | tr [:lower:] [:upper:])" | bc)"\
| bc)" | bc
@
@sed -i '/CONFIG_SECOND_BIN_OFFSET */d' ./_output/first.config
@sed -i "5 iCONFIG_SECOND_BIN_OFFSET=0x$$(echo "obase=16;ibase=10;$$(stat -c %s _output/first_mcu_nor.bin | tr -d '\n')" | bc)" ./_output/first.config
@
@cp ./_output/first.config .config
@echo | $(obj)/conf --oldconfig Kconfig
@scripts/autoconf.sh > /dev/null
@scripts/config_parse.sh > /dev/null
@make clean;make
@
@cp output/mcu_nor.bin ./_output/first_mcu_nor.bin
@
@echo $$(stat -c %s _output/first_mcu_nor.bin | tr -d '\n')
@dd if=./_output/first_mcu_nor.bin bs=1 count=$$(stat -c %s _output/first_mcu_nor.bin | tr -d '\n') skip=0 seek=0 of=./_output/mcu_nor.bin
@dd if=./_output/second_mcu_nor.bin bs=1 count=$$(stat -c %s _output/second_mcu_nor.bin | tr -d '\n') skip=0 seek=$$(stat -c %s _output/first_mcu_nor.bin | tr -d '\n') of=./_output/mcu_nor.bin
@cp ./_output/mcu_nor.bin ./output/
@
@
@echo -e "\033[36m _____________________________/Note\___________________________________ \033[0m"
@echo -e "\033[36m / \ \033[0m"
@echo -e "\033[36m Multboot firmware: \033[0m"
@echo -e "\033[36m $$(ls -l ./output/mcu_nor.bin) \033[0m"
@echo -e "\033[31m Please make sure the flash size is larger than the firmware size ! \033[0m"
@echo -e "\033[36m \______________________________________________________________________/ \033[0m"
$(obj)/mconf:
$(Q)$(MAKE) -C $(SUBDIR) prepare
$(Q)$(MAKE) -C $(SUBDIR)
$(obj)/conf:
$(Q)$(MAKE) -C $(SUBDIR) prepare
$(Q)$(MAKE) -C $(SUBDIR)
autoconf:
@scripts/autoconf.sh > /dev/null
post_config:
@scripts/config_parse.sh > /dev/null
#==================================================================================#
CROSS_COMPILE = csky-abiv2-elf-
AR = $(CROSS_COMPILE)ar
AS = $(CROSS_COMPILE)as
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)ld
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
NM = $(CROSS_COMPILE)nm
STRIP = $(CROSS_COMPILE)strip
READELF = $(CROSS_COMPILE)readelf -a
SHELL = /bin/bash
#==================================================================================#
#=================================================================================#
# Flags Configurations
#---------------------------------------------------------------------------------#
# Optimization options (add to CCFLAGS ):
# -O0 -g = Level 0 no optimization, debug info is enabled
# -O1 = Level 1 (incompatible with -g option (gebug info))
# -O2 = Level 2 (incompatible with -g option)
# -O3 = Level 3 (incompatible with -g option)
#---------------------------------------------------------------------------------#
# The pre-processor and compiler options.
# Schema Flags
ifeq ($(CONFIG_MCU_BUILD_SCHEMA_DEBUG), y)
CCFLAGS += -O0
endif
ifeq ($(CONFIG_MCU_BUILD_SCHEMA_RELEASE), y)
CCFLAGS += -O2
endif
ifeq ($(CONFIG_MCU_BUILD_SCHEMA_OPTIMIZED_SPEED), y)
CCFLAGS += -O3
endif
ifeq ($(CONFIG_MCU_BUILD_SCHEMA_OPTIMIZED_SIZE), y)
CCFLAGS += -Os
endif
GCCVERSION = $(shell $(CC) --version | grep csky-abiv2-elf-gcc)
ifeq "$(GCCVERSION)" "csky-abiv2-elf-gcc (C-SKY Tools V3.10.15 Minilibc abiv2 B20190929) 6.3.0"
else
_VERSION=$(GCCVERSION)
_ERR_FLAG="Version error!"
endif
CCFLAGS += -mcpu=ck804ef -Wpointer-arith -Wundef -Wall -Wundef \
-Wstrict-prototypes -pipe -fno-builtin \
-fstrict-volatile-bitfields -mhard-float
ASFLAGS = -mcpu=ck804ef -Wa,--defsym=ck804=1 -EL -mhard-float
# The git version of mcu
IS_INSIDE_WORK_TREE = $(shell git rev-parse --is-inside-work-tree 2>/dev/null)
ifeq ($(IS_INSIDE_WORK_TREE), true)
MCU_VERSION = "$(shell git describe --dirty --always --tags)"
else
MCU_VERSION = "Unknown"
endif
CCFLAGS += -DMCU_VERSION=\"$(MCU_VERSION)\"
ASFLAGS += -DMCU_VERSION=\"$(MCU_VERSION)\"
# The build time of mcu
BUILD_TIME = $(shell date +"%Y-%m-%d,\ %H:%M:%S")
CCFLAGS += -DBUILD_TIME=\"$(BUILD_TIME)\"
# The options used in linking as well as in any direct use of ld.
LDFLAGS = -EL
# The options used in archive as well as in any direct use of ar.
ARFLAGS = -rcsD
CCFLAGS += -ffunction-sections -nostdlib #-fdata-sections
LDFLAGS += --gc-sections
CCFLAGS += -DCONFIG_ARCH_GRUS
#---------------------------------------------------------------------------------#
INCLUDE_DIR += arch/soc/$(CONFIG_SOC_MODEL)/include
INCLUDE_DIR += boards/$(CONFIG_BOARD_VENDOR)/$(CONFIG_BOARD_MODEL)/include
INCLUDE_DIR += include/utility/libdsp
INCLUDE_DIR += include/utility/libc
INCLUDE_DIR += include/utility
INCLUDE_DIR += include/vui
INCLUDE_DIR += include
INCLUDE_DIR += lvp/common
#INCLUDE_DIR += lvp/kws
INCLUDE_DIR += base/include
INCLUDE_DIR += lvp/vui/kws
INCLUDE_DIR += lvp
INCLUDE_DIR += lvp/vui/denoise
LIBS += -ldriver_release_v1.0.5
ifeq ($(CONFIG_LVP_ENABLE_KEYWORD_RECOGNITION), y)
ifeq ($(CONFIG_LVP_ENABLE_CTC_AND_BEAMSEARCH_DECODER)$(CONFIG_LVP_ENABLE_BEAMSEARCH_DECODER), y)
LIBS += -lbeamsearch_ctc_decoder -lm
else
LIBS += -lctc_decoder
endif
endif
ifeq ($(CONFIG_DENOISE_ENABLE_GSC), y)
LIBS += -lgsc_earphone
endif
LIBS += -lcsky_CK804ef_dsp2_nn -lcsky_dsp -lcsky_dsp
LIBS += -lm -lc
LIB_DIR = lib
LIB_DIR += $(shell $(CC) -print-file-name=ck803)/hard-fp
LIB_DIR += $(shell $(CC) -print-file-name=ck803)/../../../../../csky-elfabiv2/lib/ck803/hard-fp/
# The directories in which header files reside.
# If not specified, only the current directory will be serached.
INCLUDE_FLAGS = $(addprefix -I , $(INCLUDE_DIR))
LIB_FLAGS = $(addprefix -L , $(LIB_DIR))
#---------------------------------------------------------------------------------#
ASFLAGS += $(INCLUDE_FLAGS)
CCFLAGS += $(INCLUDE_FLAGS)
LDFLAGS += $(LIB_FLAGS) $(LIBS)
#=================================================================================#
# Source List
-include arch/Makefile
-include utility/Makefile
# -include drivers/Makefile
-include boards/Makefile
-include lvp/Makefile
-include 3rdparty/Makefile
-include base/Makefile
-include app/Makefile
LIBS += -lgcc
ifdef CONFIG_MCU_COMPILE_MATH_LIB_FROM_SOURCE_CODE
$(ckdsp_objs):EXTRA_FLAGS := -mhard-float -D__FPU_PRESENT -fdata-sections -Wl,--gc-sections -DUNALIGNED_SUPPORT_DISABLE -DCSKY_SIMID
endif
lib_objs = $(boot_objs) $(dev_objs) $(utility_objs) $(common_objs) $(lvp_objs) $(kws_objs) $(app_objs) $(denoise_objs) $(gxdecoder_objs)
ifeq ($(CONFIG_USE_OPUS), y)
lib_objs += $(opus_objs)
INCLUDE_DIR += $(OPUS_CINCLUDES)
CCFLAGS += $(OPUS_CFLAGS)
CCFLAGS += -DUSE_OPUS
endif
ifeq ($(CONFIG_USE_AMR), y)
lib_objs += $(amr_objs)
CCFLAGS += $(AMR_CFLAGS)
CCFLAGS += -DUSE_AMR
endif
lib_objs += $(adpcm_objs)
CCFLAGS += -DUSE_ADPCM
INCLUDE_DIR += $(ADPCM_CINCLUDES)
mcu_objs = $(subst ",,$(lib_objs))
all_objs = $(mcu_objs) $(lvp_objs) $(base_objs)
all_deps = $(subst .o,.d,$(all_objs))
VERSION=0x42555858
CCFLAGS += -DRELEASE_VERSION=$(VERSION)
CCFLAGS += -DCONFIG_MTD_FLASH_SPI -DCONFIG_FLASH_SPI_QUAD -DCONFIG_FLASH_SPI_32BITS
CCFLAGS += -DCONFIG_FLASH_SPI_XIP
CCFLAGS += -DCONFIG_DW_AHB_DMA -DCONFIG_DW_UART_DMA
CCFLAGS += -DCONFIG_I2C_STATIC_ALLOC_MEM
$(adpcm_objs):CCFLAGS := $(CCFLAGS) -O2
#=================================================================================#
# Build Rules
.PHONY: clean help
ifeq (,$(wildcard $(CURDIR)/.config))# check .config
# Build .config
build: .config
else # .config is exit
# Build objects
build: prepare output/libmcu.a lib/libcsky_dsp.a output/mcu.elf output/mcu.info.txt output/mcu.dump.txt
ifneq ($(CONFIG_MCU_ENABLE_JTAG_DEBUG), y)
build: output/mcu.bin checkbin
endif # endif ifneq ($(CONFIG_MCU_ENABLE_JTAG_DEBUG), y)
endif # endif ifeq (,$(wildcard $(CURDIR)/.config))
.config:
@make menuconfig
prepare:
@echo [Preparing lvp ...]
@mkdir -p output
@mkdir -p tmp_objs
@$(AR) -x lib/libdriver_release_v1.0.5.a
@mv *.o tmp_objs/
@$(CC) $(CCFLAGS) $(EXTRA_FLAGS) -E -x assembler-with-cpp -P -o output/mcu.ld arch/soc/$(CONFIG_SOC_MODEL)/link.ld
ifdef ckdsp_objs
lib/libcsky_dsp.a: $(ckdsp_objs)
@rm -f $@
@echo [$(AR) archiving $@]
@$(AR) $(ARFLAGS) $@ $^
endif
output/libmcu.a: $(mcu_objs)
@rm -f $@
@echo [$(AR) archiving $@]
@$(AR) $(ARFLAGS) $@ $^
output/mcu.elf: output/mcu.ld $(all_objs)
@echo [$(LD) linking $@]
@$(LD) -o $@ -T $^ $(LDFLAGS)
@size $@
ifeq ($(VERSION), 0x42555858)
@echo -e "\033[33m ____________________________/Warning\_________________________________ \033[0m"
@echo -e "\033[33m / \ \033[0m"
@echo -e "\033[33m Here used defult Version $(VERSION) \033[0m"
@echo -e "\033[33m if you want to change it to 0x1234: $$ make VERSION=0x1234 \033[0m"
@echo -e "\033[33m \______________________________________________________________________/ \033[0m"
else
@echo -e "\033[36m _____________________________/Note\___________________________________ \033[0m"
@echo -e "\033[36m / \ \033[0m"
@echo -e "\033[36m Here set Version : $(VERSION) \033[0m"
@echo -e "\033[36m if you want to change it to 0x1234: $$ make VERSION=0x1234 \033[0m"
@echo -e "\033[36m \______________________________________________________________________/ \033[0m"
endif
#---------------------------------------------------------------------------------#
output/mcu.dump.txt: output/mcu.elf
@echo [$(OBJDUMP) disassemble $^]
@$(OBJDUMP) -Sa $^ > $@
output/mcu.info.txt: output/mcu.elf
@echo [$(READELF) dump sections $^]
@$(READELF) $^ > $@
checkbin:
@echo
@-ls -l output/* | awk '{ print $$9 ":\t" $$5 " Byte" }'
#---------------------------------------------------------------------------------#
ifneq ($(MAKECMDGOALS), )
NOT_INCLUDE_DEP = true
endif
ifneq ($(NOT_INCLUDE_DEP), true)
-include $(all_deps)
endif
#---------------------------------------------------------------------------------#
# Common Build Rules
ifneq (,$(wildcard $(CURDIR)/.config))
%.d:%.c
ifeq (${_ERR_FLAG},"Version error!")
@echo
@echo "________________________________/ERROR\\___________________________________"
@echo "|Now compiler version : |"
@echo "|${GCCVERSION}"
@echo "| |"
@echo "|Version error! |"
@echo "| |"
@echo "|The right version : |"
@echo "|csky-abiv2-elf-gcc (C-SKY Tools V3.10.15 Minilibc abiv2 B20190929) 6.3.0 |"
@echo "|________________________________________________________________________|"
@echo
@killall make
endif
@echo [$(CC) creating $@]
@$(CC) $(CCFLAGS) -M $< > $@.$$$$;\
sed 's,\(.*\)\.o[ :]*,$(shell dirname $@)/\1.o $@ : ,g' <$@.$$$$ > $@;\
$(RM) $@.$$$$
%.d:%.S
@echo [$(CC) creating $@]
@$(CC) $(CCFLAGS) -M $< > $@.$$$$;\
sed 's,\(.*\)\.o[ :]*,$(shell dirname $@)/\1.o $@ : ,g' <$@.$$$$ > $@;\
$(RM) $@.$$$$
%.o:%.c
@echo [$(CC) compiling $@]
@$(CC) $(CCFLAGS) $(EXTRA_FLAGS) -c $< -o $@
%.o:%.S
@echo [$(CC) assembling $@]
@$(CC) $(ASFLAGS) -c $< -o $@
endif
clean:
@find . -regex ".*[.][1-9][0-9][0-9][0-9][0-9]$$" | xargs rm -f
@find . -regex ".*[.][1-9][0-9][0-9][0-9]$$" | xargs rm -f
@rm -f $(all_objs) $(all_deps) $(snpu_objs) $(ckdsp_objs)
@rm -rf output
@rm -rf tmp_objs
@echo [Clean all]
distclean: clean
@find . -regex ".*[.][1-9][0-9][0-9][0-9][0-9]$$" | xargs rm -f
@find . -regex ".*[.][1-9][0-9][0-9][0-9]$$" | xargs rm -f
@-make -C $(SUBDIR) clean
@-find . \( -path "./utility/libc/csky" -o -path "./utility/libm/csky" \) -prune -o -name *.o | xargs rm
@-find . -name *.d | xargs rm
@-rm -f .config .config.old
@-rm -f include/autogenerated_config.h
@-rm -f include/autoconf.h
help:
@echo 'Generic Makefile for C/C++ Programs (GNU/linux makefile) version 0.1'
@echo 'Copyright (C) 2001-2021 NationalChip Co., Ltd'
@echo 'ALL RIGHTS RESERVED!'
@echo
@echo 'Usage: make [TARGET]'
@echo 'TARGETS:'
@echo ' all compile and create elf files(.elf)'
@echo ' clean clean all objects and the executable file.'
@echo ' help print this message.'
@echo
#---------------------------------------------------------------------------------#
# Grus flash bin 文件组成
#
# * -------------------------------------------
# * | | | |
# * | struct | struct | bin body |
# * | bin_header | stage_info | |
# * | | | |
# * -------------------------------------------
#
# #define BIN_HEADER_MAGIC 0x484E4942
# struct bin_header {
# unsigned int magic; // 'B' 'I' 'N' 'H'
# unsigned int medium_magic; // 0xaa55aa55 for nor; 0xbb55bb55 for nand
# unsigned int version; // CONFIG_SOFT_VERSTION
# };
#
# struct stage_info {
# unsigned int stage2_size;
# unsigned int stage1_size;
# unsigned int stage1_load_addr;
# };
#
# bin body : stage1 + stage2 header +stage2
#
BOOTLOADER_MAGIC_NOR='AA55AA55'
BIN_HEADER_MEDIUM_MAGIC=$(BOOTLOADER_MAGIC_NOR)
BIN_HEADER_MAGIC_PRE='0x484E4942'
BIN_HEADER_MAGIC=$(shell ./scripts/switch_endian.sh $(shell printf "%08x" $(BIN_HEADER_MAGIC_PRE)))
BIN_SOFT_VERSION=$(shell IFS=. read V1 V2 V3 V4 <<< $(CONFIG_SOFT_VERSTION);printf "%02x%02x%02x%02x" $$V4 $$V3 $$V2 $$V1)
STAGE2_XIP_TEXT_SIZE=$(shell csky-abiv2-elf-readelf -S output/mcu.elf |grep -E ".stage2_xip_text"| awk '{print "0x"$$7}' | xargs printf %d $$1)
STAGE2_SRAM_TEXT_SIZE=$(shell csky-abiv2-elf-readelf -S output/mcu.elf |grep -E ".stage2_sram_text"| awk '{print "0x"$$7}' | xargs printf %d $$1)
STAGE2_SRAM_DATA_SIZE=$(shell csky-abiv2-elf-readelf -S output/mcu.elf |grep -E ".stage2_sram_data"| awk '{print "0x"$$7}' | xargs printf %d $$1)
STAGE2_SIZE=$(shell ./scripts/switch_endian.sh $(shell printf %08x `expr ${STAGE2_XIP_TEXT_SIZE} + ${STAGE2_SRAM_TEXT_SIZE} + ${STAGE2_SRAM_DATA_SIZE}`))
STAGE1_SIZE_PRE=$(shell printf "0x%08x" $(shell grep "CONFIG_STAGE1_SRAM_SIZE" arch/soc/$(CONFIG_SOC_MODEL)/include/soc_config.h | head -n 1 | awk '{print $$3}'))
STAGE1_SIZE=$(shell ./scripts/switch_endian.sh $(shell printf "%08x" $(STAGE1_SIZE_PRE)))
STAGE1_LOAD_ADDR_PRE=$(shell printf "0x%08x" $(shell grep "CONFIG_STAGE1_DRAM_BASE" arch/soc/$(CONFIG_SOC_MODEL)/include/soc_config.h | head -n 1 | awk '{print $$3}'))
STAGE1_LOAD_ADDR=$(shell ./scripts/switch_endian.sh $(shell printf "%08x" $(STAGE1_LOAD_ADDR_PRE)))
MAGIC_NUM := 4
SUFFIX = ".bin"
BOOT_HEAD_NOR=$(BIN_HEADER_MAGIC)$(BIN_HEADER_MEDIUM_MAGIC)$(BIN_SOFT_VERSION)$(STAGE2_SIZE)$(STAGE1_SIZE)$(STAGE1_LOAD_ADDR)
BOOT_HEAD_LEN=24
ORIGIN_FILE = "$(ORIGIN_FILED)$(SUFFIX)"
SOC_STAGE1_SIZE=$(STAGE1_SIZE_PRE)
# 生成经过CRC校验的bin文件
# $1 name (spi_nor/spi_nand/......)
# $2 boot_head
# S3 header_len
# $4 stage1备份的数量,spi_nand备份4份
# $5 目标文件的名称
define CREATE_BIN
@gcc scripts/loader_write.c -o loader_write
@mkdir -p output
@sed '1i$2' output/TEMP_FILE1 > TEMP_FILE2
@xxd -r -c4 -p TEMP_FILE2 > tmp.bin
@./loader_write tmp.bin output/$5 $3 $(SOC_STAGE1_SIZE) $4 $6
@rm -rf loader_write tmp.bin
endef
define CLEAN_TMP_FILE
@rm -rf output/TEMP_FILE1 TEMP_FILE2 $@
endef
BOARD_NAME = $(shell cat include/autoconf.h | grep -E 'CONFIG_BOARD_MODEL' | awk '{str = $$3 ;print str}')
PROJECT_NAME = $(shell cat include/autoconf.h | grep -E 'CONFIG_PROJECT_NAME' | awk '{str = $$3 ;print str}')
SOFT_VERSTION = $(shell cat include/autoconf.h | grep -E 'CONFIG_SOFT_VERSTION' | awk '{str = $$3 ;print str}')
ZIP_TIME = $(shell date +"%Y%m%d_%H%M%S")
MCU_NOR_BIN = output/mcu_nor.bin
MCU_ALL_BIN = output/mcu_all.bin
CUSTOM_STORAGE_SPACE_LEN = $(shell echo $$(($(CONFIG_CUSTOM_STORAGE_SPACE_LEN) * 4096)))
RESOURCE_OFFSET = $(CONFIG_RESOURCE_BIN_ADDRESS_IN_FLASH)
MAX_SIZE_KB = 1020
output/mcu.bin: output/mcu.elf
@echo [$(OBJCOPY) dump $@]
@$(OBJCOPY) -O binary $< $@
@xxd -c4 -p $@ > output/TEMP_FILE1
ifeq ($(CONFIG_MCU_ENABLE_XIP), y)
@$(call CREATE_BIN,"spi_nor",$(BOOT_HEAD_NOR),$(BOOT_HEAD_LEN),1,"mcu_nor.bin", $(STAGE2_XIP_TEXT_SIZE))
@$(call CREATE_BIN,"main",$(BOOT_HEAD_NOR),$(BOOT_HEAD_LEN),0,"mcu_main.bin", $(STAGE2_XIP_TEXT_SIZE))
else
@$(call CREATE_BIN,"spi_nor",$(BOOT_HEAD_NOR),$(BOOT_HEAD_LEN),1,"mcu_nor.bin", 0)
@$(call CREATE_BIN,"main",$(BOOT_HEAD_NOR),$(BOOT_HEAD_LEN),0,"mcu_main.bin", 0)
endif
@cd output;xxd -i mcu_main.bin > mcu_main.h;cd -
ifeq ($(CONFIG_DL), y)
@echo
@readelf -s output/mcu.elf |grep -E "\<LD_MCU_END_IMAGE_OFFSET\>"|awk '{str = " %d 0x"$$2;print str}' | xargs printf |awk '{str = "if=output/mcu_nor.bin bs=1 count=" $$1 " skip=0 of=output/mcu_flash.bin" ;print str}' | xargs dd
@readelf -s output/mcu.elf |grep -E "\<LD_EXT_FLASH_IMAGE_SIZE\>"|awk '{str = " %d 0x"$$2;print str}' | xargs printf |awk '{str = "if=output/mcu_nor.bin bs=1 count=" $$1 " skip=524288 of=output/ext_flash.bin" ;print str}' | xargs dd
@echo
endif
ifeq ($(CONFIG_LVP_HAS_RESOURCE_BIN), y)
@$(eval CONFIG := $(shell grep -o 'CONFIG_LVP_KWS_VIVA_.*_V[0-9A-Za-z]*DOT[0-9A-Za-z]*DOT[0-9A-Za-z]*_[0-9]*_[0-9]*=y' .config | sed 's/CONFIG_LVP_KWS_//g' | sed 's/_[0-9]*_[0-9]*=y//g'))
@$(eval CONFIG_LOWER := $(shell echo $(CONFIG) | tr '[:upper:]' '[:lower:]'))
@$(if $(CONFIG_ENABLE_SWITCH_NPU_MODEL_RUN_IN_FLASH_OR_SRAM), \
$(eval MODEL_NAME := $(shell echo $(CONFIG_LOWER) | sed 's/_v[0-9a-z]*dot[0-9a-z]*dot[0-9a-z]*_v[0-9a-z]*dot[0-9a-z]*dot[0-9a-z]*$$//')), \
$(eval MODEL_NAME := $(shell echo $(CONFIG_LOWER) | sed 's/_v[0-9a-z]*dot[0-9a-z]*dot[0-9a-z]*$$//')))
@$(if $(CONFIG_ENABLE_SWITCH_NPU_MODEL_RUN_IN_FLASH_OR_SRAM), \
$(eval MODEL_VERSION := $(shell echo $(CONFIG_LOWER) | grep -o 'v[0-9a-z]*dot[0-9a-z]*dot[0-9a-z]*' | tail -n 2 | sed 's/dot/./g' | tr '\n' '_' | sed 's/_$$//')), \
$(eval MODEL_VERSION := $(shell echo $(CONFIG_LOWER) | grep -o 'v[0-9a-z]*dot[0-9a-z]*dot[0-9a-z]*' | tail -n 1 | sed 's/dot/./g')))
@$(eval RESOURCE_BIN := tools/resource/resource_$(MODEL_NAME)_$(MODEL_VERSION).bin)
@echo [Model Config: $(CONFIG)]
@echo [Model Name: $(MODEL_NAME)]
@echo [Model Version: $(MODEL_VERSION)]
@echo [RESOURCE_BIN: $(RESOURCE_BIN)]
@cp output/mcu_nor.bin output/mcu_no_tts.bin
@cp $(MCU_NOR_BIN) $(MCU_ALL_BIN)
@$(eval ZERO_FILL_SIZE := 0)
ifeq ($(CONFIG_CUSTOM_STORAGE_SPACE), y)
@$(eval ZERO_FILL_SIZE := $(CUSTOM_STORAGE_SPACE_LEN))
@dd if=/dev/zero of=output/temp_zero.bin bs=1 count=$(ZERO_FILL_SIZE)
@dd if=output/temp_zero.bin of=$(MCU_ALL_BIN) bs=1 seek=$(RESOURCE_OFFSET) conv=notrunc
@rm output/temp_zero.bin
endif
@$(eval RESOURCE_OFFSET_ADJUSTED := $(shell echo $$(($(RESOURCE_OFFSET) + $(ZERO_FILL_SIZE)))))
@dd if=$(RESOURCE_BIN) of=$(MCU_ALL_BIN) bs=1 seek=$(RESOURCE_OFFSET_ADJUSTED) conv=notrunc
@echo [Merger $(MCU_ALL_BIN)]
@if [ `stat -c%s $(MCU_ALL_BIN)` -gt $$(($(MAX_SIZE_KB) * 1024)) ]; then \
truncate -s $(MAX_SIZE_KB)K $(MCU_ALL_BIN); \
fi
@mv $(MCU_ALL_BIN) output/mcu_nor.bin
endif
@rm -f ./output/lvp.zip
@cp ./docs/lvp_zip_readme.md output/README.md
@cp ./docs/GX8003A_module_User\'s\ Guide.pdf output/
@cp .config output/.config
@cp ./scripts/download.sh output/download.sh
@cp ./tools/bootx/bootx output/bootx
ifeq ($(IS_INSIDE_WORK_TREE), true)
@git rev-parse HEAD >> output/README.md
@echo "branch info:" >> output/README.md
@git branch -v | awk '/\*/' >> output/README.md
endif
@echo "pc info:" >> output/README.md
@echo $$USER >> output/README.md
@pwd >> output/README.md
@echo "time:" >> output/README.md
@date >> output/README.md
@echo >> output/README.md
@md5sum output/mcu_nor.bin > output/mcu_nor.bin.md5
@zip -q -j ./output/lvp.zip ./output/mcu_nor.bin ./output/mcu.dump.txt ./output/mcu.info.txt ./output/mcu.ld ./.config ./output/README.md ./output/mcu_nor.bin.md5 ./output/download.sh
@zip -q -j ./output/[$(PROJECT_NAME)]$(BOARD_NAME)-$(ZIP_TIME)-V$(SOFT_VERSTION)-lvp.zip ./output/mcu_nor.bin ./output/mcu.dump.txt ./output/mcu.info.txt ./output/mcu.ld ./.config ./output/README.md ./output/mcu_nor.bin.md5 ./output/download.sh
@$(CLEAN_TMP_FILE)
output/mcu_win.bin: $(all_objs)
@echo [Preparing lvp ...]
@mkdir -p output
@$(CC) $(CCFLAGS) -E -x assembler-with-cpp -P -o output/mcu.ld arch/soc/$(CONFIG_SOC_MODEL)/link.ld
@echo [$(LD) linking $@ $(CONFIG_SOC_MODEL)]
@$(LD) -o output/mcu.elf -T output/mcu.ld $^ $(LDFLAGS)
create_bin.exe
@rm -rf output/mcu.bin output/tmp.bin