use license macro in the spec file
[platform/upstream/libwebsockets.git] / scripts / esp32.mk
1 #
2 # LWS-style images are composed like this
3 #
4 # [ OTA or Factory standard xpressif image ]
5 # [ 32-b LE len ] [ ROMFS ]
6 # [ 32-b LE len ] [ Image information JSON ]
7 #
8
9 SHELL=/bin/bash
10
11 ESPPORT ?= $(CONFIG_ESPTOOLPY_PORT)
12
13 jbi=$(COMPONENT_PATH)/../build/json-buildinfo
14
15 FAC=$(CONFIG_LWS_IS_FACTORY_APPLICATION)
16 ifeq ($(FAC),)
17         FAC=0
18 endif
19 export FAC
20 DIRNAME:=$(shell basename $$(pwd) | tr -d '\n')
21
22 $(COMPONENT_PATH)/../build/pack.img: $(APP_BIN)
23         GNUSTAT=stat ;\
24         if [ `which gstat 2>/dev/null` ] ; then GNUSTAT=gstat ; fi ;\
25         DIRNAME=$$(basename $$(pwd) | tr -d '\n') ;\
26         genromfs -f $(COMPONENT_PATH)/../build/romfs.img -d $(COMPONENT_PATH)/../romfs-files ; \
27         RLEN=$$($$GNUSTAT -c %s $(COMPONENT_PATH)/../build/romfs.img) ;\
28         LEN=$$($$GNUSTAT -c %s $(COMPONENT_PATH)/../build/$$DIRNAME.bin) ;\
29         printf "             Original length: 0x%06x (%8d)\n" $$LEN $$LEN ; \
30         printf %02x $$(( $$RLEN % 256 )) | xxd -r -p >> $(COMPONENT_PATH)/../build/$$DIRNAME.bin ;\
31         printf %02x $$(( ( $$RLEN / 256 ) % 256 )) | xxd -r -p >> $(COMPONENT_PATH)/../build/$$DIRNAME.bin ;\
32         printf %02x $$(( ( $$RLEN / 65536 ) % 256 )) | xxd -r -p >> $(COMPONENT_PATH)/../build/$$DIRNAME.bin ;\
33         printf %02x $$(( ( $$RLEN / 16777216 ) % 256 )) | xxd -r -p >> $(COMPONENT_PATH)/../build/$$DIRNAME.bin ;\
34         cat $(COMPONENT_PATH)/../build/romfs.img >>$(COMPONENT_PATH)/../build/$$DIRNAME.bin ; \
35         LEN=$$($$GNUSTAT -c %s $(COMPONENT_PATH)/../build/$$DIRNAME.bin) ;\
36         UNIXTIME=$$(date +%s | tr -d '\n') ; \
37         echo -n -e "{\r\n \"schema\": \"lws1\",\r\n \"model\": \"$(CONFIG_LWS_MODEL_NAME)\",\r\n \"builder\": \"" > $(jbi) ;\
38         hostname | tr -d '\n' >> $(jbi) ;\
39         echo -n -e "\",\r\n \"app\": \"" >> $(jbi) ;\
40         echo -n $$DIRNAME >> $(jbi) ;\
41         echo -n -e "\",\r\n \"user\": \"" >> $(jbi) ;\
42         whoami | tr -d '\n' >>$(jbi) ;\
43         echo -n -e  "\",\r\n \"git\": \"" >> $(jbi) ;\
44         git describe --dirty --always | tr -d '\n' >> $(jbi) ;\
45         echo -n -e  "\",\r\n \"date\": \"" >> $(jbi) ;\
46         date | tr -d '\n' >> $(jbi) ;\
47         echo -n -e "\",\r\n \"unixtime\": \"" >> $(jbi) ;\
48         echo -n $$UNIXTIME >> $(jbi) ;\
49         echo -n -e "\",\r\n \"file\": \""$$DIRNAME-$$UNIXTIME.bin >> $(jbi) ;\
50         echo -n -e "\",\r\n \"factory\": \"$(FAC)" >> $(jbi) ;\
51         echo -n -e "\"\r\n}"  >> $(jbi) ;\
52         JLEN=$$($$GNUSTAT -c %s $(jbi)) ;\
53         printf %02x $$(( $$JLEN % 256 )) | xxd -r -p >> $(COMPONENT_PATH)/../build/$$DIRNAME.bin ;\
54         printf %02x $$(( ( $$JLEN / 256 ) % 256 )) | xxd -r -p >> $(COMPONENT_PATH)/../build/$$DIRNAME.bin ;\
55         printf %02x $$(( ( $$JLEN / 65536 ) % 256 )) | xxd -r -p >> $(COMPONENT_PATH)/../build/$$DIRNAME.bin ;\
56         printf %02x $$(( ( $$JLEN / 16777216 ) % 256 )) | xxd -r -p >> $(COMPONENT_PATH)/../build/$$DIRNAME.bin ;\
57         cat $(jbi) >> $(COMPONENT_PATH)/../build/$$DIRNAME.bin ;\
58         cp $(COMPONENT_PATH)/../build/$$DIRNAME.bin $(COMPONENT_PATH)/../build/pack.img ;\
59         LEN=$$($$GNUSTAT -c %s $(COMPONENT_PATH)/../build/$$DIRNAME.bin) ;\
60         cp $(COMPONENT_PATH)/../build/$$DIRNAME.bin $(COMPONENT_PATH)/../build/$$DIRNAME-$$UNIXTIME.bin ;\
61         printf "    After ROMFS + Build info: 0x%06x (%8d)\n" $$LEN $$LEN
62
63 .PHONY: manifest
64 manifest:
65 ifeq ($F,)
66         echo "Usage make F=<factory app dir> A=<app dir> manifest"
67         exit 1
68 endif
69 ifeq ($A,)
70         echo "Usage make F=<factory app dir> A=<app dir> manifest"
71         exit 1
72 endif
73         echo -n -e "{\r\n\"app\": " > build/manifest.json
74         cat $(A)/build/json-buildinfo >> build/manifest.json
75         echo -n -e ", \"factory\": " >> build/manifest.json
76         cat $(F)/build/json-buildinfo >> build/manifest.json
77         echo -n -e "\r\n}\r\n" >> build/manifest.json
78
79 all: $(COMPONENT_PATH)/../build/pack.img
80
81 flash: $(COMPONENT_PATH)/../build/pack.img
82
83 flash_ota: $(COMPONENT_PATH)/../build/pack.img
84         DIRNAME=$$(basename $$(pwd) | tr -d '\n') ;\
85         $(IDF_PATH)/components/esptool_py/esptool/esptool.py \
86                 --chip esp32 \
87                 --port $(ESPPORT) \
88                 --baud $(CONFIG_ESPTOOLPY_BAUD) \
89                 write_flash 0x110000 $(COMPONENT_PATH)/../build/$$DIRNAME.bin
90
91 erase_ota:
92         $(IDF_PATH)/components/esptool_py/esptool/esptool.py \
93                 --chip esp32 \
94                 --port $(ESPPORT) \
95                 --baud $(CONFIG_ESPTOOLPY_BAUD) \
96                 erase_region 0x110000 0x2f0000
97
98
99 export A
100 export F
101 .PHONY: upload
102 upload: manifest
103 ifeq ($F,)
104         echo "Usage make F=<factory app dir> A=<app dir> manifest"
105         exit 1
106 endif
107 ifeq ($A,)
108         echo "Usage make F=<factory app dir> A=<app dir> manifest"
109         exit 1
110 endif
111         UPL=$(CONFIG_LWS_OTA_SERVER_UPLOAD_USER)@$(CONFIG_LWS_OTA_SERVER_FQDN):$(CONFIG_LWS_OTA_SERVER_UPLOAD_PATH)/$(CONFIG_LWS_OTA_SERVER_BASE_URL)/$(CONFIG_LWS_MODEL_NAME)/ ;\
112         AFILE=$(A)/build/$$(cat $$A/build/json-buildinfo | grep -- \"file\"\: |cut -d' ' -f3 |cut -d'"' -f2) ;\
113         echo "  Uploading $$AFILE to " $$UPL ;\
114         scp $$AFILE $$UPL ;\
115         FFILE=$(F)/build/$$(cat $$F/build/json-buildinfo | grep -- \"file\"\: |cut -d' ' -f3 |cut -d'"' -f2) ;\
116         echo "  Uploading $$FFILE" ;\
117         scp  $$FFILE $$UPL ;\
118         echo "  Uploading manifest" ;\
119         scp build/manifest.json $$UPL