mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-07-26 16:28:06 +08:00
The bootloader boot-delay feature has been mechanically broken on every modern FMU board since the STM32F7/H7 transition. It has three independent bugs that prevent it from ever working: 1. Offset mismatch: BOOT_DELAY_ADDRESS is hardcoded to 0x1a0, but the NuttX vector table is 504 B (F76x) to 664 B (H743) long. The linker places _bootdelay_signature at ALIGN(32) past end of vectors (e.g. 0x2a0 on CubeOrange), never at 0x1a0. The bootloader reads random exception_common pointers in place of the magic and never matches BOOT_DELAY_SIGNATURE1/2. Verified on CubeOrange with objdump of cubepilot_cubeorange_default.elf. 2. Flash cache never flushes: fc_write() stores arbitrary writes in cache line 1 and only flushes on a very specific condition tied to the sequential firmware upload flow. A standalone write during PROTO_SET_DELAY is cached forever. fc_read() then returns the cached value, so the post-write verify lies and the bootloader reports success. Nothing ever reaches flash. 3. H7 write granularity: the STM32H7 flash controller requires a full 32-byte program cycle per write. Single 32-bit writes from flash_func_write_word() would not be accepted by the controller even if they reached it. The feature has been silently dead on every H7/F7 FMU board for years and no one noticed, which is strong evidence nothing actually depends on it. Rather than fix it (which would mean rewriting PROTO_SET_DELAY, the flash cache path, and the H7 flash programming path), remove it. Changes: - bl.c: PROTO_SET_DELAY case now immediately NACKs (goto cmd_bad) so clients that still send the command get a clear rejection instead of the previous silent fake-success. The opcode stays in the protocol enum for backwards compatibility. - bl.h: drop BOOT_DELAY_SIGNATURE1/2 and BOOT_DELAY_MAX. - stm/stm32_common/main.c, nxp/imxrt_common/main.c: drop the startup boot-delay sig check block. - image_toc.c: decouple find_toc() from BOOT_DELAY_ADDRESS. BOARD_IMAGE_TOC_OFFSET is now the required define when BOOTLOADER_USE_TOC is enabled. The body is wrapped in #ifdef BOOTLOADER_USE_TOC and falls back to a stub returning false when the TOC is not in use (no upstream board currently enables it). - Linker scripts: strip EXTERN(_bootdelay_signature) and the FILL/. += 8 block from all 142 affected .ld files across boards/. - hw_config.h: strip the #define BOOT_DELAY_ADDRESS and its comment block entry from all 48 affected boards. - Tools/px4_uploader.py, Tools/teensy_uploader.py: remove --boot-delay, set_boot_delay(), and SET_BOOT_DELAY client-side counterpart. Smoke-built on cubepilot_cubeorange_default and cubepilot_cubeorange_bootloader; no link errors, no unresolved symbols, flash usage unchanged. Tested: - New BL, new FW - Old BL, old FW - Old BL, new FW - New BL, old FW
133 lines
6.5 KiB
C
133 lines
6.5 KiB
C
/****************************************************************************
|
|
*
|
|
* Copyright (C) 2020 PX4 Development Team. All rights reserved.
|
|
*
|
|
* 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.
|
|
* 3. Neither the name PX4 nor the names of its contributors may be
|
|
* used to endorse or promote products derived from this software
|
|
* without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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
|
|
* COPYRIGHT OWNER 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.
|
|
*
|
|
****************************************************************************/
|
|
|
|
#pragma once
|
|
|
|
/****************************************************************************
|
|
* 10-8--2016:
|
|
* To simplify the ripple effect on the tools, we will be using
|
|
* /dev/serial/by-id/<asterisk>PX4<asterisk> to locate PX4 devices. Therefore
|
|
* moving forward all Bootloaders must contain the prefix "PX4 BL "
|
|
* in the USBDEVICESTRING
|
|
* This Change will be made in an upcoming BL release
|
|
****************************************************************************/
|
|
/*
|
|
* Define usage to configure a bootloader
|
|
*
|
|
*
|
|
* Constant example Usage
|
|
* APP_LOAD_ADDRESS 0x08004000 - The address in Linker Script, where the app fw is org-ed
|
|
* BOOTLOADER_DELAY 5000 - Ms to wait while under USB pwr or bootloader request
|
|
* BOARD_FMUV2
|
|
* INTERFACE_USB 1 - (Optional) Scan and use the USB interface for bootloading
|
|
* INTERFACE_USART 1 - (Optional) Scan and use the Serial interface for bootloading
|
|
* USBDEVICESTRING "PX4 BL FMU v2.x" - USB id string
|
|
* USBPRODUCTID 0x0011 - PID Should match defconfig
|
|
* BOARD_TYPE 9 - Must match .prototype boad_id
|
|
* _FLASH_KBYTES (*(uint16_t *)0x1fff7a22) - Run time flash size detection
|
|
* BOARD_FLASH_SECTORS ((_FLASH_KBYTES == 0x400) ? 11 : 23) - Run time determine the physical last sector
|
|
* BOARD_FLASH_SECTORS 11 - Hard coded zero based last sector
|
|
* BOARD_FLASH_SIZE (_FLASH_KBYTES*1024)- Total Flash size of device, determined at run time.
|
|
* (1024 * 1024) - Hard coded Total Flash of device - The bootloader and app reserved will be deducted
|
|
* programmatically
|
|
*
|
|
* BOARD_FIRST_FLASH_SECTOR_TO_ERASE 2 - Optional sectors index in the flash_sectors table (F4 only), to begin erasing.
|
|
* This is to allow sectors to be reserved for app fw usage. That will NOT be erased
|
|
* during a FW upgrade.
|
|
* The default is 0, and selects the first sector to be erased, as the 0th entry in the
|
|
* flash_sectors table. Which is the second physical sector of FLASH in the device.
|
|
* The first physical sector of FLASH is used by the bootloader, and is not defined
|
|
* in the table.
|
|
*
|
|
* APP_RESERVATION_SIZE (BOARD_FIRST_FLASH_SECTOR_TO_ERASE * 16 * 1024) - Number of bytes reserved by the APP FW. This number plus
|
|
* BOOTLOADER_RESERVATION_SIZE will be deducted from
|
|
* BOARD_FLASH_SIZE to determine the size of the App FW
|
|
* and hence the address space of FLASH to erase and program.
|
|
* USBMFGSTRING "PX4 AP" - Optional USB MFG string (default is '3D Robotics' if not defined.)
|
|
* SERIAL_BREAK_DETECT_DISABLED - Optional prevent break selection on Serial port from entering or staying in BL
|
|
*
|
|
* * Other defines are somewhat self explanatory.
|
|
*/
|
|
|
|
/* Boot device selection list*/
|
|
#define USB0_DEV 0x01
|
|
#define SERIAL0_DEV 0x02
|
|
#define SERIAL1_DEV 0x04
|
|
|
|
#define APP_LOAD_ADDRESS 0x08020000
|
|
#define BOOTLOADER_DELAY 5000
|
|
#define INTERFACE_USB 1
|
|
#define INTERFACE_USB_CONFIG "/dev/ttyACM0"
|
|
#define BOARD_VBUS MK_GPIO_INPUT(GPIO_OTGFS_VBUS)
|
|
|
|
//#define USE_VBUS_PULL_DOWN
|
|
#define INTERFACE_USART 1
|
|
#define INTERFACE_USART_CONFIG "/dev/ttyS4,57600"
|
|
#define BOARD_TYPE 1009
|
|
#define _FLASH_KBYTES (*(uint32_t *)0x1FF1E880)
|
|
#define BOARD_FLASH_SECTORS (15)
|
|
#define BOARD_FLASH_SIZE (_FLASH_KBYTES * 1024)
|
|
|
|
#define OSC_FREQ 16
|
|
|
|
#define BOARD_PIN_LED_ACTIVITY GPIO_nLED_BLUE // BLUE
|
|
#define BOARD_PIN_LED_BOOTLOADER GPIO_nLED_GREEN // GREEN
|
|
#define BOARD_LED_ON 0
|
|
#define BOARD_LED_OFF 1
|
|
|
|
#define SERIAL_BREAK_DETECT_DISABLED 1
|
|
|
|
#if !defined(ARCH_SN_MAX_LENGTH)
|
|
# define ARCH_SN_MAX_LENGTH 12
|
|
#endif
|
|
|
|
#if !defined(APP_RESERVATION_SIZE)
|
|
# define APP_RESERVATION_SIZE 0
|
|
#endif
|
|
|
|
#if !defined(BOARD_FIRST_FLASH_SECTOR_TO_ERASE)
|
|
# define BOARD_FIRST_FLASH_SECTOR_TO_ERASE 1
|
|
#endif
|
|
|
|
#if !defined(USB_DATA_ALIGN)
|
|
# define USB_DATA_ALIGN
|
|
#endif
|
|
|
|
#ifndef BOOT_DEVICES_SELECTION
|
|
# define BOOT_DEVICES_SELECTION USB0_DEV|SERIAL0_DEV|SERIAL1_DEV
|
|
#endif
|
|
|
|
#ifndef BOOT_DEVICES_FILTER_ONUSB
|
|
# define BOOT_DEVICES_FILTER_ONUSB USB0_DEV|SERIAL0_DEV|SERIAL1_DEV
|
|
#endif
|