1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-19 09:54:15 +01:00

EntireFlash: now works on all supported platforms

This commit is contained in:
Oleg Semyonov 2013-03-21 16:21:45 +02:00
parent 80db2ff79c
commit 5f24378a4f
3 changed files with 156 additions and 31 deletions

View File

@ -410,18 +410,16 @@ define EF_TEMPLATE
ef_$(1): ef_$(1)_bin
ef_$(1)_%: bl_$(1)_bin fw_$(1)_opfw
$(V1) $(MKDIR) -p $(BUILD_DIR)/ef_$(1)/dep
$(V1) $(MKDIR) -p $(BUILD_DIR)/ef_$(1)
$(V1) cd $(ROOT_DIR)/flight/targets/EntireFlash && \
$$(MAKE) -r --no-print-directory \
BOARD_NAME=$(1) \
BOARD_SHORT_NAME=$(3) \
BUILD_TYPE=ef \
TCHAIN_PREFIX="$(ARM_SDK_PREFIX)" \
DFU_CMD="$(DFUUTIL_DIR)/bin/dfu-util" \
\
TARGET=ef_$(1) \
TOPDIR=$(ROOT_DIR)/flight/targets/EntireFlash \
OUTDIR=$(BUILD_DIR)/ef_$(1) \
\
TARGET=ef_$(1) \
$$*
.PHONY: ef_$(1)_clean

View File

@ -1,8 +1,5 @@
#####
# Makefile for Entire Flash (EF) images
#
# The OpenPilot Team, http://www.openpilot.org, Copyright (C) 2012.
#
# Copyright (c) 2009-2013, The OpenPilot Team, http://www.openpilot.org
#
# 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
@ -17,33 +14,43 @@
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#####
#
WHEREAMI := $(dir $(lastword $(MAKEFILE_LIST)))
TOP := $(realpath $(WHEREAMI)/../../../)
include $(TOP)/make/firmware-defs.mk
include $(TOP)/make/boards/$(BOARD_NAME)/board-info.mk
ifndef OPENPILOT_IS_COOL
$(error Top level Makefile must be used to build this target)
endif
include $(ROOT_DIR)/make/boards/$(BOARD_NAME)/board-info.mk
# Paths
TOPDIR = .
ENTIRE_FLASH = $(PYTHON) "$(TOPDIR)/entire-flash.py"
ifeq ($(V), 1)
EF_VERBOSE := --verbose
else
EF_VERBOSE :=
endif
.PHONY: bin
bin: $(OUTDIR)/$(TARGET).bin
FW_PRE_PAD = $(shell echo $$[$(FW_BANK_BASE)-$(BL_BANK_BASE)-$(BL_BANK_SIZE)])
$(OUTDIR)/$(TARGET).fw_pre.pad:
$(V0) @echo $(MSG_PADDING) $@
$(V1) dd status=noxfer if=/dev/zero count=$(FW_PRE_PAD) bs=1 2>/dev/null | tr '\000' '\377' > $@
FW_POST_PAD = $(shell echo $$[$(FW_BANK_SIZE)-$(FW_DESC_SIZE)-$$(stat -c%s $(FW_BIN))])
$(OUTDIR)/$(TARGET).fw_post.pad:
$(V0) @echo $(MSG_PADDING) $@
$(V1) dd status=noxfer if=/dev/zero count=$(FW_POST_PAD) bs=1 2>/dev/null | tr '\000' '\377' > $@
BL_BIN = $(TOP)/build/bl_$(BOARD_NAME)/bl_$(BOARD_NAME).bin
FW_BIN = $(TOP)/build/fw_$(BOARD_NAME)/fw_$(BOARD_NAME).bin
BL_BIN = $(BUILD_DIR)/bl_$(BOARD_NAME)/bl_$(BOARD_NAME).bin
FW_BIN = $(BUILD_DIR)/fw_$(BOARD_NAME)/fw_$(BOARD_NAME).bin
FWINFO_BIN = $(FW_BIN).firmwareinfo.bin
$(OUTDIR)/$(TARGET).bin: $(BL_BIN) $(FW_BIN) $(OUTDIR)/$(TARGET).fw_pre.pad $(OUTDIR)/$(TARGET).fw_post.pad
$(V0) @echo $(MSG_FLASH_IMG) $@
$(V1) cat $(BL_BIN) $(OUTDIR)/$(TARGET).fw_pre.pad $(FW_BIN) $(OUTDIR)/$(TARGET).fw_post.pad $(FWINFO_BIN) > $@
$(OUTDIR)/$(TARGET).bin: $(BL_BIN) $(FW_BIN)
$(V0) @$(ECHO) $(MSG_FLASH_IMG) $@
$(V1) $(ENTIRE_FLASH) $(EF_VERBOSE) \
--bl-bank-base=$(BL_BANK_BASE) \
--bl-bank-size=$(BL_BANK_SIZE) \
--fw-bank-base=$(FW_BANK_BASE) \
--fw-bank-size=$(FW_BANK_SIZE) \
--fw-desc-size=$(FW_DESC_SIZE) \
--bl-bin-path="$(BL_BIN)" \
--fw-bin-path="$(FW_BIN)" \
--fwinfo-bin-path="$(FWINFO_BIN)" \
--outfile="$@"
.PHONY: dfu
dfu: $(OUTDIR)/$(TARGET).bin
@ -52,4 +59,3 @@ dfu: $(OUTDIR)/$(TARGET).bin
sudo $(DFU_CMD) -l && \
sudo $(DFU_CMD) -d 0483:df11 -c 1 -i 0 -a 0 -D $< -s $(BL_BANK_BASE) ; \
)

View File

@ -0,0 +1,121 @@
#!/usr/bin/env python
#
# Helper function to generate an entire flash image.
#
# (c) 2013, The OpenPilot Team, http://www.openpilot.org
# See also: The GNU Public License (GPL) Version 3
#
import optparse
import sys
def append(verbose, text, data):
"""Appends data to global image, updates global offset, prints details if verbose is set"""
global image, offset
if verbose:
print text, "0x%08x" % len(data), "@ 0x%08x" % offset, "%8d bytes" % len(data)
image += data
offset += len(data)
def create_entire_flash(args):
"""Generates entire flash image and prints it to stdout"""
global image, offset
assert args.bl_bank_base is not None
assert args.bl_bank_size is not None
assert args.fw_bank_base is not None
assert args.fw_bank_size is not None
assert args.fw_desc_size is not None
assert args.bl_bin_path is not None
assert args.fw_bin_path is not None
assert args.fwinfo_bin_path is not None
image = ""
offset = 0
pad = chr(0xff)
try:
bl_bin_file = open(args.bl_bin_path, "rb")
bl_bin = bl_bin_file.read()
bl_bin_file.close()
fw_bin_file = open(args.fw_bin_path, "rb")
fw_bin = fw_bin_file.read()
fw_bin_file.close()
fwinfo_bin_file = open(args.fwinfo_bin_path, "rb")
fwinfo_bin = fwinfo_bin_file.read()
fwinfo_bin_file.close()
pre_pad_size = args.fw_bank_base - args.bl_bank_base - args.bl_bank_size
post_pad_size = args.fw_bank_size - args.fw_desc_size - len(fw_bin)
append(args.verbose, "Bootloader image: ", bl_bin)
append(args.verbose, "Padding: ", pad * pre_pad_size)
append(args.verbose, "Firmware image: ", fw_bin)
append(args.verbose, "Padding: ", pad * post_pad_size)
append(args.verbose, "Firmware info blob: ", fwinfo_bin)
if args.verbose:
print "Entire flash image size:", offset, "bytes"
if args.outfile:
of = open(args.outfile, "wb")
of.write(image)
of.close()
except:
import traceback
traceback.print_exc()
return -2
return 0
def main():
"""Entire image data will be written to OUTFILE (if given) as concatenation of:
- bootloader + padding + firmware + padding + firmware info
"""
# Parse command line.
class RawDescriptionHelpFormatter(optparse.IndentedHelpFormatter):
"""optparse formatter function to pretty print raw epilog"""
def format_epilog(self, epilog):
if epilog:
return "\n" + epilog + "\n"
else:
return ""
parser = optparse.OptionParser(
formatter=RawDescriptionHelpFormatter(),
description = "Helper function to generate an entire flash image.",
epilog = main.__doc__);
parser.add_option('--bl-bank-base', type='long', action='store',
help='start of bootloader flash');
parser.add_option('--bl-bank-size', type='long', action='store',
help='should include BD_INFO region');
parser.add_option('--fw-bank-base', type='long', action='store',
help='start of firmware flash');
parser.add_option('--fw-bank-size', type='long', action='store',
help='should include FW_DESC_SIZE');
parser.add_option('--fw-desc-size', type='long', action='store',
help='firmware description area size');
parser.add_option('--bl-bin-path', action='store',
help='path to bootloader image');
parser.add_option('--fw-bin-path', action='store',
help='path to firmware image');
parser.add_option('--fwinfo-bin-path', action='store',
help='path to firmware info blob');
parser.add_option('--outfile', action='store',
help='name of entire flash output file');
parser.add_option('--verbose', action='store_true',
help='print addresses and sizes');
(args, positional_args) = parser.parse_args()
if (len(positional_args) != 0) or (len(sys.argv) == 1):
parser.error("incorrect number of arguments, try --help for help")
return create_entire_flash(args)
if __name__ == "__main__":
sys.exit(main())