2 # LWS-style images are composed like this
4 # [ OTA or Factory standard xpressif image ]
5 # [ 32-b LE len ] [ ROMFS ]
6 # [ 32-b LE len ] [ Image information JSON ]
11 ESPPORT ?= $(CONFIG_ESPTOOLPY_PORT)
13 jbi=$(COMPONENT_PATH)/../build/json-buildinfo
15 FAC=$(CONFIG_LWS_IS_FACTORY_APPLICATION)
20 DIRNAME:=$(shell basename $$(pwd) | tr -d '\n')
22 $(COMPONENT_PATH)/../build/pack.img: $(APP_BIN)
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
66 echo "Usage make F=<factory app dir> A=<app dir> manifest"
70 echo "Usage make F=<factory app dir> A=<app dir> manifest"
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
79 all: $(COMPONENT_PATH)/../build/pack.img
81 flash: $(COMPONENT_PATH)/../build/pack.img
83 flash_ota: $(COMPONENT_PATH)/../build/pack.img
84 DIRNAME=$$(basename $$(pwd) | tr -d '\n') ;\
85 $(IDF_PATH)/components/esptool_py/esptool/esptool.py \
88 --baud $(CONFIG_ESPTOOLPY_BAUD) \
89 write_flash 0x110000 $(COMPONENT_PATH)/../build/$$DIRNAME.bin
92 $(IDF_PATH)/components/esptool_py/esptool/esptool.py \
95 --baud $(CONFIG_ESPTOOLPY_BAUD) \
96 erase_region 0x110000 0x2f0000
104 echo "Usage make F=<factory app dir> A=<app dir> manifest"
108 echo "Usage make F=<factory app dir> A=<app dir> manifest"
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 ;\
115 FFILE=$(F)/build/$$(cat $$F/build/json-buildinfo | grep -- \"file\"\: |cut -d' ' -f3 |cut -d'"' -f2) ;\
116 echo " Uploading $$FFILE" ;\
118 echo " Uploading manifest" ;\
119 scp build/manifest.json $$UPL