|
- # Copyright 2022 John-Mark Gurney.
- #
- # Redistribution and use in source and binary forms, with or without
- # modification, are permitted provided that the following conditions
- # are met:
- # 1. Redistributions of source code must retain the above copyright
- # notice, this list of conditions and the following disclaimer.
- # 2. Redistributions in binary form must reproduce the above copyright
- # notice, this list of conditions and the following disclaimer in the
- # documentation and/or other materials provided with the distribution.
- #
- # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- # SUCH DAMAGE.
- #
-
- PROGS = rs485gw rs485hid
-
- SRCS.rs485gw = rs485gw.c
- SRCS.rs485gw+= $(SRCS.USB_CDC)
- SRCS.rs485gw+= $(SRCS.USB)
-
- SRCS.rs485hid = rs485hid.c
- SRCS.rs485hid+= $(SRCS.USB_HID)
- SRCS.rs485hid+= $(SRCS.USB)
- SRCS.rs485hid+= $(STROBE_SRCS)
- SRCS.rs485hid+= comms.c
- SRCS.rs485hid+= memdebug.c
- SRCS.rs485hid+= strobe_pki.c
-
- CFLAGS.rs485hid+= -DEXTERNAL_GET_DESCRIPTOR=1
- CFLAGS.rs485hid+= -I$(.OBJDIR) # for public_key.h
- SRCS.rs485hid+= usb_hid_base.c
-
- .if empty(HID_PRIV_KEY) && exists($(.CURDIR)/.hid_priv_key)
- HID_PRIV_KEY!= cat $(.CURDIR)/.hid_priv_key
- .endif
-
- .PHONY: hid_priv_key
- hid_priv_key:
- @LANG=C tr -c -d a-f0-9 < /dev/urandom | dd bs=1 of=$(.CURDIR)/.hid_priv_key count=64 2>/dev/null
- @echo 'Key created and put into .hid_priv_key.'
-
- # make this a phony target so it's always run
- # dependancies will only be made when it's updated
- .PHONY: $(.OBJDIR)/public_key.h
- $(.OBJDIR)/public_key.h:
- @if [ "$(HID_PRIV_KEY)" = "" ]; then echo 'Must provide HID_PRIV_KEY make variable or have a non-empty file ".hid_priv_key". This can be created by the command "$(MAKE) hid_priv_key".'; false; fi
-
- @echo 'static const uint8_t pubkey[] = {' $$(python3 -c 'import sys; import codecs; from syote_comms import X25519; print(", ".join(hex(x) for x in X25519.frombytes(codecs.decode(sys.argv[1], "hex")).getpub()))' $(HID_PRIV_KEY) ) "};" > public_key.h.tmp
- @echo 'static_assert(sizeof pubkey == 32);' >> public_key.h.tmp
-
- if [ "$$(cat public_key.h.tmp)" = "static uint8_t pubkey[] = { };" -o "$$(cat public_key.h.tmp)" = "" ]; then rm -f "$@"; false; fi
-
- (cmp public_key.h.tmp public_key.h >/dev/null 2>&1 && rm public_key.h.tmp) || mv public_key.h.tmp public_key.h
-
- strobe_pki.o: $(.OBJDIR)/public_key.h
-
- usb_hid_base.c: usb_hid.py
- PYTHONPATH=$(.CURDIR) python $(STM32)/usb/usb_gen.py $(.ALLSRC:[1]:T:R)
-
- .PATH: $(.CURDIR)/..
-
- CFLAGS += -g
-
- WITH_RS485FRAME = yes
- WITH_STM32F103 = yes
- WITH_USB_CDC = yes
- WITH_USB_HID = yes
-
- .include <../mk/boards.mk>
-
- EXTRA_DEPENDS+= $(STM32)/usb/usb_gen.py
-
- .include <../mk/mu.progs.mk>
-
- usb_hid_base.c: $(STM32)/usb/usb_gen.py
|