diff --git a/firmware/Makefile b/firmware/Makefile index 5e89d2ab..fe1faf1a 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -23,11 +23,6 @@ PATH_BOOTSTRAP=bootstrap PATH_APPLICATION=application PATH_BASEBAND=baseband -# TODO: Pass these (as #defines?) to Makefiles, use values in code. -PAD_BOOTSTRAP=0x10000 -PAD_HACKRF_FIRMWARE=65536 -PAD_BASEBAND=0x20000 - TARGET=portapack-h1-firmware TARGET_BOOTSTRAP=$(PATH_BOOTSTRAP)/bootstrap @@ -35,6 +30,8 @@ TARGET_HACKRF_FIRMWARE=hackrf_one_usb_ram TARGET_APPLICATION=$(PATH_APPLICATION)/build/application TARGET_BASEBAND=$(PATH_BASEBAND)/build/baseband +MAKE_SPI_IMAGE=tools/make_spi_image.py + DFU_HACKRF=hackrf_one_usb_ram.dfu LICENSE=../LICENSE @@ -56,19 +53,14 @@ program: $(TARGET).bin sleep 1s hackrf_spiflash -w $(TARGET).bin -$(TARGET).bin: $(TARGET_BOOTSTRAP)_pad.bin $(TARGET_HACKRF_FIRMWARE)_dfu_pad.bin $(TARGET_BASEBAND)_pad.bin $(TARGET_APPLICATION).bin - cat $(TARGET_BOOTSTRAP)_pad.bin $(TARGET_HACKRF_FIRMWARE)_dfu_pad.bin $(TARGET_BASEBAND)_pad.bin $(TARGET_APPLICATION).bin >$(TARGET).bin +$(TARGET).bin: $(MAKE_SPI_IMAGE) $(TARGET_BOOTSTRAP).bin $(TARGET_HACKRF_FIRMWARE).dfu $(TARGET_BASEBAND).bin $(TARGET_APPLICATION).bin + $(MAKE_SPI_IMAGE) $(TARGET_BOOTSTRAP).bin $(TARGET_HACKRF_FIRMWARE).dfu $(TARGET_BASEBAND).bin $(TARGET_APPLICATION).bin $(TARGET).bin -$(TARGET_BOOTSTRAP)_pad.bin: $(TARGET_BOOTSTRAP).elf - $(CP) -O binary --pad-to $(PAD_BOOTSTRAP) $(TARGET_BOOTSTRAP).elf $(TARGET_BOOTSTRAP)_pad.bin +$(TARGET_BOOTSTRAP).bin: $(TARGET_BOOTSTRAP).elf + $(CP) -O binary $(TARGET_BOOTSTRAP).elf $(TARGET_BOOTSTRAP).bin -$(TARGET_HACKRF_FIRMWARE)_dfu_pad.bin: $(TARGET_HACKRF_FIRMWARE).dfu - # TODO: Not confident this is reliable. It certainly won't work on Windows. - # Pad the .dfu with zeros, then truncate to the desired length. - head -c $(PAD_HACKRF_FIRMWARE) /dev/zero | cat $(TARGET_HACKRF_FIRMWARE).dfu - | head -c $(PAD_HACKRF_FIRMWARE) >$(TARGET_HACKRF_FIRMWARE)_dfu_pad.bin - -$(TARGET_BASEBAND)_pad.bin: $(TARGET_BASEBAND).elf - $(CP) -O binary --pad-to $(PAD_BASEBAND) $(TARGET_BASEBAND).elf $(TARGET_BASEBAND)_pad.bin +$(TARGET_BASEBAND).bin: $(TARGET_BASEBAND).elf + $(CP) -O binary $(TARGET_BASEBAND).elf $(TARGET_BASEBAND).bin $(TARGET_APPLICATION).bin: $(TARGET_APPLICATION).elf $(CP) -O binary $(TARGET_APPLICATION).elf $(TARGET_APPLICATION).bin @@ -84,8 +76,8 @@ $(TARGET_BOOTSTRAP).elf: always_check clean: rm -f $(TARGET).bin - rm -f $(TARGET_BOOTSTRAP)_pad.bin - rm -f $(TARGET_BASEBAND)_pad.bin + rm -f $(TARGET_BOOTSTRAP).bin + rm -f $(TARGET_BASEBAND).bin rm -f $(TARGET_APPLICATION).bin $(MAKE) -C $(PATH_BASEBAND) clean $(MAKE) -C $(PATH_APPLICATION) clean diff --git a/firmware/tools/make_spi_image.py b/firmware/tools/make_spi_image.py new file mode 100755 index 00000000..a1dc6b1c --- /dev/null +++ b/firmware/tools/make_spi_image.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python + +# +# Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc. +# +# This file is part of PortaPack. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +import sys + +usage_message = """ +PortaPack SPI flash image generator + +Usage: + Where paths refer to the .bin files for each component project. +""" + +def read_image(path): + f = open(path, 'rb') + data = f.read() + f.close() + return data + +def write_image(data, path): + f = open(path, 'wb') + f.write(data) + f.close() + +if len(sys.argv) != 6: + print(usage_message) + sys.exit(-1) + +input_paths = sys.argv[1:5] +output_path = sys.argv[5] +bootstrap_image, hackrf_image, baseband_image, application_image = map(read_image, input_paths) +spi_size = 1048576 + +images = ( + { + 'name': 'bootstrap', + 'data': bootstrap_image, + 'size': 0x10000, + }, + { + 'name': 'hackrf', + 'data': hackrf_image, + 'size': 0x10000, + }, + { + 'name': 'baseband', + 'data': baseband_image, + 'size': 0x20000, + }, + { + 'name': 'application', + 'data': application_image, + 'size': len(application_image), + } +) + +spi_image = [] +spi_image_default_byte = '\xff' + +for image in images: + if len(image['data']) > image['size']: + raise RuntimeError('data for image "%(name)s" is longer than 0x%(size)x bytes' % image) + pad_size = image['size'] - len(image['data']) + padded_data = image['data'] + (spi_image_default_byte * pad_size) + spi_image += padded_data + +spi_image = ''.join(spi_image) +if len(spi_image) > spi_size: + raise RuntimeError('SPI flash image size of %d exceeds device size of %d bytes' % (len(spi_image), spi_size)) + +write_image(spi_image, output_path)