github.com/google/trillian-examples@v0.0.0-20240520080811-0d40d35cef0e/binary_transparency/firmware/devices/usbarmory/bootloader/Makefile (about)

     1  # http://github.com/usbarmory/tamago-example
     2  #
     3  # Copyright (c) F-Secure Corporation
     4  # https://foundry.f-secure.com
     5  #
     6  # Use of this source code is governed by the license
     7  # that can be found in the LICENSE file.
     8  
     9  BUILD_USER = $(shell whoami)
    10  BUILD_HOST = $(shell hostname)
    11  BUILD_DATE = $(shell /bin/date -u "+%Y-%m-%d %H:%M:%S")
    12  BUILD_TAGS = linkramsize,linkramstart,armory,console
    13  BUILD = ${BUILD_USER}@${BUILD_HOST} on ${BUILD_DATE}
    14  REV = $(shell git rev-parse --short HEAD 2> /dev/null)
    15  
    16  SHELL = /bin/bash
    17  START_KERNEL ?= 10753536
    18  LEN_KERNEL ?= 89246720
    19  START_PROOF ?= 10240512
    20  
    21  ifeq ("${CONSOLE}","on")
    22  	BUILD_TAGS := ${BUILD_TAGS},console
    23  endif
    24  
    25  APP := armory-boot
    26  GOENV := GO_EXTLINK_ENABLED=0 CGO_ENABLED=0 GOOS=tamago GOARM=7 GOARCH=arm
    27  TEXT_START := 0x90010000 # ramStart (defined in imx6/imx6ul/memory.go) + 0x10000
    28  GOFLAGS := -tags "${BUILD_TAGS}" -ldflags "-s -w -T $(TEXT_START) -E _rt0_arm_tamago -R 0x1000 -X 'main.Build=${BUILD}' -X 'main.Revision=${REV}' -X 'main.Boot=${BOOT}' -X 'main.StartKernel=${START_KERNEL}' -X 'main.StartProof=${START_PROOF}' -X 'main.PublicKeyStr=${PUBLIC_KEY}'"
    29  
    30  .PHONY: clean
    31  
    32  #### primary targets ####
    33  
    34  all: $(APP)
    35  
    36  imx: $(APP).imx
    37  
    38  imx_signed: $(APP)-signed.imx
    39  
    40  elf: $(APP)
    41  
    42  #### utilities ####
    43  
    44  check_env:
    45  	@if [ "${BOOT}" != "eMMC" ] && [ "${BOOT}" != "uSD" ]; then \
    46  		echo 'You need to set the BOOT variable to either eMMC or uSD to select boot media'; \
    47  		exit 1; \
    48  	fi
    49  
    50  check_tamago:
    51  	@if [ "${TAMAGO}" == "" ] || [ ! -f "${TAMAGO}" ]; then \
    52  		echo 'You need to set the TAMAGO variable to a compiled version of https://github.com/usbarmory/tamago-go'; \
    53  		exit 1; \
    54  	fi
    55  
    56  check_usbarmory_git:
    57  	@if [ "${USBARMORY_GIT}" == "" ]; then \
    58  		echo 'You need to set the USBARMORY_GIT variable to the path of a clone of'; \
    59  		echo '  https://github.com/usbarmory/usbarmory'; \
    60  		exit 1; \
    61  	fi
    62  
    63  check_hab_keys:
    64  	@if [ "${HAB_KEYS}" == "" ]; then \
    65  		echo 'You need to set the HAB_KEYS variable to the path of secure boot keys'; \
    66  		echo 'See https://github.com/usbarmory/usbarmory/wiki/Secure-boot-(Mk-II)'; \
    67  		exit 1; \
    68  	fi
    69  
    70  dcd:
    71  	echo $(GOMODCACHE)
    72  	echo $(TAMAGO_PKG)
    73  	cp -f $(TAMAGO_PKG)/board/usbarmory/mk2/imximage.cfg $(APP).dcd
    74  
    75  clean:
    76  	rm -f $(APP)
    77  	@rm -fr $(APP).bin $(APP).imx $(APP)-signed.imx $(APP).csf $(APP).dcd
    78  
    79  #### dependencies ####
    80  
    81  $(APP): check_tamago check_env
    82  	$(GOENV) $(TAMAGO) build $(GOFLAGS) -o ${APP}
    83  
    84  $(APP).dcd: check_tamago
    85  $(APP).dcd: TAMAGO_PKG=$(shell go list -f {{.Root}} github.com/usbarmory/tamago/bits)
    86  $(APP).dcd: dcd
    87  
    88  $(APP).bin: $(APP)
    89  	$(CROSS_COMPILE)objcopy -j .text -j .rodata -j .shstrtab -j .typelink \
    90  	    -j .itablink -j .gopclntab -j .go.buildinfo -j .noptrdata -j .data \
    91  	    -j .bss --set-section-flags .bss=alloc,load,contents \
    92  	    -j .noptrbss --set-section-flags .noptrbss=alloc,load,contents \
    93  	    $(APP) -O binary $(APP).bin
    94  
    95  $(APP).imx: $(APP).bin $(APP).dcd
    96  	mkimage -n $(APP).dcd -T imximage -e $(TEXT_START) -d $(APP).bin $(APP).imx
    97  	# Copy entry point from ELF file
    98  	dd if=$(APP) of=$(APP).imx bs=1 count=4 skip=24 seek=4 conv=notrunc
    99  
   100  #### secure boot ####
   101  
   102  $(APP)-signed.imx: check_usbarmory_git check_hab_keys $(APP).imx
   103  	${USBARMORY_GIT}/software/secure_boot/usbarmory_csftool \
   104  		--csf_key ${HAB_KEYS}/CSF_1_key.pem \
   105  		--csf_crt ${HAB_KEYS}/CSF_1_crt.pem \
   106  		--img_key ${HAB_KEYS}/IMG_1_key.pem \
   107  		--img_crt ${HAB_KEYS}/IMG_1_crt.pem \
   108  		--table   ${HAB_KEYS}/SRK_1_2_3_4_table.bin \
   109  		--index   1 \
   110  		--image   $(APP).imx \
   111  		--output  $(APP).csf && \
   112  	cat $(APP).imx $(APP).csf > $(APP)-signed.imx