2012-05-27 11:44:51 +00:00
|
|
|
/*
|
2014-10-22 10:13:21 +00:00
|
|
|
* Boot a Marvell SoC, with Xmodem over UART0.
|
2022-03-02 10:49:26 +00:00
|
|
|
* supports Kirkwood, Dove, Avanta, Armada 370, Armada XP, Armada 375,
|
|
|
|
* Armada 38x and Armada 39x.
|
2012-05-27 11:44:51 +00:00
|
|
|
*
|
|
|
|
* (c) 2012 Daniel Stodden <daniel.stodden@gmail.com>
|
2021-09-24 21:07:14 +00:00
|
|
|
* (c) 2021 Pali Rohár <pali@kernel.org>
|
2022-06-01 15:17:06 +00:00
|
|
|
* (c) 2021 Marek Behún <kabel@kernel.org>
|
2012-05-27 11:44:51 +00:00
|
|
|
*
|
2022-03-02 10:49:27 +00:00
|
|
|
* References:
|
|
|
|
* - "88F6180, 88F6190, 88F6192, and 88F6281: Integrated Controller: Functional
|
|
|
|
* Specifications" December 2, 2008. Chapter 24.2 "BootROM Firmware".
|
|
|
|
* https://web.archive.org/web/20130730091033/https://www.marvell.com/embedded-processors/kirkwood/assets/FS_88F6180_9x_6281_OpenSource.pdf
|
|
|
|
* - "88AP510: High-Performance SoC with Integrated CPU, 2D/3D Graphics
|
|
|
|
* Processor, and High-Definition Video Decoder: Functional Specifications"
|
|
|
|
* August 3, 2011. Chapter 5 "BootROM Firmware"
|
|
|
|
* https://web.archive.org/web/20120130172443/https://www.marvell.com/application-processors/armada-500/assets/Armada-510-Functional-Spec.pdf
|
2023-01-08 12:34:24 +00:00
|
|
|
* - "88F6665, 88F6660, 88F6658, 88F6655, 88F6655F, 88F6650, 88F6650F, 88F6610,
|
|
|
|
* and 88F6610F Avanta LP Family Integrated Single/Dual CPU Ecosystem for
|
|
|
|
* Gateway (GW), Home Gateway Unit (HGU), and Single Family Unit (SFU)
|
|
|
|
* Functional Specifications" Doc. No. MV-S108952-00, Rev. A. November 7, 2013.
|
|
|
|
* Chapter 7 "Boot Flow"
|
|
|
|
* CONFIDENTIAL, no public documentation available
|
2022-03-02 10:49:27 +00:00
|
|
|
* - "88F6710, 88F6707, and 88F6W11: ARMADA(R) 370 SoC: Functional Specifications"
|
|
|
|
* May 26, 2014. Chapter 6 "BootROM Firmware".
|
|
|
|
* https://web.archive.org/web/20140617183701/https://www.marvell.com/embedded-processors/armada-300/assets/ARMADA370-FunctionalSpec-datasheet.pdf
|
|
|
|
* - "MV78230, MV78260, and MV78460: ARMADA(R) XP Family of Highly Integrated
|
|
|
|
* Multi-Core ARMv7 Based SoC Processors: Functional Specifications"
|
|
|
|
* May 29, 2014. Chapter 6 "BootROM Firmware".
|
|
|
|
* https://web.archive.org/web/20180829171131/https://www.marvell.com/embedded-processors/armada-xp/assets/ARMADA-XP-Functional-SpecDatasheet.pdf
|
2023-01-08 12:34:24 +00:00
|
|
|
* - "BobCat2 Control and Management Subsystem Functional Specifications"
|
|
|
|
* Doc. No. MV-S109400-00, Rev. A. December 4, 2014.
|
|
|
|
* Chapter 1.6 BootROM Firmware
|
|
|
|
* CONFIDENTIAL, no public documentation available
|
|
|
|
* - "AlleyCat3 and PONCat3 Highly Integrated 1/10 Gigabit Ethernet Switch
|
|
|
|
* Control and Management Subsystem: Functional Specifications"
|
|
|
|
* Doc. No. MV-S109693-00, Rev. A. May 20, 2014.
|
|
|
|
* Chapter 1.6 BootROM Firmware
|
|
|
|
* CONFIDENTIAL, no public documentation available
|
2022-03-02 10:49:27 +00:00
|
|
|
* - "ARMADA(R) 375 Value-Performance Dual Core CPU System on Chip: Functional
|
|
|
|
* Specifications" Doc. No. MV-S109377-00, Rev. A. September 18, 2013.
|
|
|
|
* Chapter 7 "Boot Sequence"
|
|
|
|
* CONFIDENTIAL, no public documentation available
|
|
|
|
* - "88F6810, 88F6811, 88F6821, 88F6W21, 88F6820, and 88F6828: ARMADA(R) 38x
|
|
|
|
* Family High-Performance Single/Dual CPU System on Chip: Functional
|
|
|
|
* Specifications" Doc. No. MV-S109094-00, Rev. C. August 2, 2015.
|
|
|
|
* Chapter 7 "Boot Flow"
|
|
|
|
* CONFIDENTIAL, no public documentation available
|
|
|
|
* - "88F6920, 88F6925 and 88F6928: ARMADA(R) 39x High-Performance Dual Core CPU
|
|
|
|
* System on Chip Functional Specifications" Doc. No. MV-S109896-00, Rev. B.
|
|
|
|
* December 22, 2015. Chapter 7 "Boot Flow"
|
|
|
|
* CONFIDENTIAL, no public documentation available
|
2023-01-08 12:34:24 +00:00
|
|
|
* - "Marvell boot image parser", Marvell U-Boot 2013.01, version 18.06. September 17, 2015.
|
|
|
|
* https://github.com/MarvellEmbeddedProcessors/u-boot-marvell/blob/u-boot-2013.01-armada-18.06/tools/marvell/doimage_mv/hdrparser.c
|
|
|
|
* - "Marvell doimage Tool", Marvell U-Boot 2013.01, version 18.06. August 30, 2015.
|
|
|
|
* https://github.com/MarvellEmbeddedProcessors/u-boot-marvell/blob/u-boot-2013.01-armada-18.06/tools/marvell/doimage_mv/doimage.c
|
2023-01-21 18:57:28 +00:00
|
|
|
*
|
|
|
|
* Storage location / offset of different image types:
|
|
|
|
* - IBR_HDR_SPI_ID (0x5A):
|
|
|
|
* SPI image can be stored at any 2 MB aligned offset in the first 16 MB of
|
|
|
|
* SPI-NOR or parallel-NOR. Despite the type name it really can be stored on
|
|
|
|
* parallel-NOR and cannot be stored on other SPI devices, like SPI-NAND.
|
|
|
|
* So it should have been named NOR image, not SPI image. This image type
|
2023-03-23 20:00:07 +00:00
|
|
|
* supports XIP - Execute In Place directly from NOR memory. Destination
|
|
|
|
* address of the XIP image is set to 0xFFFFFFFF and execute address to the
|
|
|
|
* absolute offset in bytes from the beginning of NOR memory.
|
2023-01-21 18:57:28 +00:00
|
|
|
*
|
|
|
|
* - IBR_HDR_NAND_ID (0x8B):
|
|
|
|
* NAND image can be stored either at any 2 MB aligned offset in the first
|
|
|
|
* 16 MB of SPI-NAND or at any blocksize aligned offset in the first 64 MB
|
|
|
|
* of parallel-NAND.
|
|
|
|
*
|
|
|
|
* - IBR_HDR_PEX_ID (0x9C):
|
|
|
|
* PEX image is used for booting from PCI Express device. Source address
|
|
|
|
* stored in image is ignored by BootROM. It is not the BootROM who parses
|
|
|
|
* or loads data part of the PEX image. BootROM just configures SoC to the
|
|
|
|
* PCIe endpoint mode and let the PCIe device on the other end of the PCIe
|
|
|
|
* link (which must be in Root Complex mode) to load kwbimage into SoC's
|
|
|
|
* memory and tell BootROM physical address.
|
|
|
|
*
|
|
|
|
* - IBR_HDR_UART_ID (0x69):
|
|
|
|
* UART image can be transfered via xmodem protocol over first UART.
|
2023-03-23 19:57:55 +00:00
|
|
|
* Unlike all other image types, header size stored in the image must be
|
|
|
|
* multiply of the 128 bytes (for all other image types it can be any size)
|
|
|
|
* and data part of the image does not have to contain 32-bit checksum
|
|
|
|
* (all other image types must have valid 32-bit checksum in its data part).
|
|
|
|
* And data size stored in the image is ignored. A38x BootROM determinates
|
|
|
|
* size of the data part implicitly by the end of the xmodem transfer.
|
|
|
|
* A38x BootROM has a bug which cause that BootROM loads data part of UART
|
|
|
|
* image into RAM target address increased by one byte when source address
|
|
|
|
* and header size stored in the image header are not same. So UART image
|
|
|
|
* should be constructed in a way that there is no gap between header and
|
|
|
|
* data part.
|
2023-01-21 18:57:28 +00:00
|
|
|
*
|
|
|
|
* - IBR_HDR_I2C_ID (0x4D):
|
|
|
|
* It is unknown for what kind of storage is used this image. It is not
|
|
|
|
* specified in any document from References section.
|
|
|
|
*
|
|
|
|
* - IBR_HDR_SATA_ID (0x78):
|
|
|
|
* SATA image can be stored at sector 1 (after the MBR table), sector 34
|
|
|
|
* (after the GPT table) or at any next sector which is aligned to 2 MB and
|
|
|
|
* is in the first 16 MB of SATA disk. Note that source address in SATA image
|
|
|
|
* is stored in sector unit and not in bytes like for any other images.
|
|
|
|
* Unfortunately sector size is disk specific, in most cases it is 512 bytes
|
|
|
|
* but there are also Native 4K SATA disks which have 4096 bytes long sectors.
|
|
|
|
*
|
|
|
|
* - IBR_HDR_SDIO_ID (0xAE):
|
|
|
|
* SDIO image can be stored on different medias:
|
|
|
|
* - SD(SC) card
|
|
|
|
* - SDHC/SDXC card
|
|
|
|
* - eMMC HW boot partition
|
|
|
|
* - eMMC user data partition / MMC card
|
|
|
|
* It cannot be stored on SDIO card despite the image name.
|
|
|
|
*
|
|
|
|
* For SD(SC)/SDHC/SDXC cards, image can be stored at the same locations as
|
|
|
|
* the SATA image (sector 1, sector 34 or any 2 MB aligned sector) but within
|
|
|
|
* the first 64 MB. SDHC and SDXC cards have fixed 512 bytes long sector size.
|
|
|
|
* Old SD(SC) cards unfortunately can have also different sector sizes, mostly
|
|
|
|
* 1024 bytes long sector sizes and also can be changed at runtime.
|
|
|
|
*
|
|
|
|
* For MMC-compatible devices, image can be stored at offset 0 or at offset
|
|
|
|
* 2 MB. If MMC device supports HW boot partitions then image must be stored
|
|
|
|
* on the HW partition as is configured in the EXT_CSC register (it can be
|
|
|
|
* either boot or user data).
|
|
|
|
*
|
|
|
|
* Note that source address for SDIO image is stored in byte unit, like for
|
|
|
|
* any other images (except SATA). Marvell Functional Specifications for
|
|
|
|
* A38x and A39x SoCs say that source address is in sector units, but this
|
|
|
|
* is purely incorrect information. A385 BootROM really expects source address
|
|
|
|
* for SDIO images in bytes and also Marvell tools generate SDIO image with
|
|
|
|
* source address in byte units.
|
2012-05-27 11:44:51 +00:00
|
|
|
*/
|
|
|
|
|
2016-01-07 13:12:04 +00:00
|
|
|
#include "kwbimage.h"
|
|
|
|
#include "mkimage.h"
|
2021-09-24 21:06:42 +00:00
|
|
|
#include "version.h"
|
2016-01-07 13:12:04 +00:00
|
|
|
|
2012-05-27 11:44:51 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdarg.h>
|
2016-01-07 13:12:04 +00:00
|
|
|
#include <image.h>
|
2012-05-27 11:44:51 +00:00
|
|
|
#include <libgen.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdint.h>
|
2021-09-24 21:06:52 +00:00
|
|
|
#include <time.h>
|
2012-05-27 11:44:51 +00:00
|
|
|
#include <sys/stat.h>
|
2022-03-02 10:49:21 +00:00
|
|
|
#include <pthread.h>
|
2012-05-27 11:44:51 +00:00
|
|
|
|
2021-09-24 21:07:06 +00:00
|
|
|
#ifdef __linux__
|
|
|
|
#include "termios_linux.h"
|
|
|
|
#else
|
|
|
|
#include <termios.h>
|
|
|
|
#endif
|
|
|
|
|
2022-03-02 10:49:23 +00:00
|
|
|
/*
|
|
|
|
* These functions are in <term.h> header file, but this header file conflicts
|
|
|
|
* with "termios_linux.h" header file. So declare these functions manually.
|
|
|
|
*/
|
|
|
|
extern int setupterm(const char *, int, int *);
|
|
|
|
extern char *tigetstr(const char *);
|
|
|
|
|
2012-05-27 11:44:51 +00:00
|
|
|
/*
|
|
|
|
* Marvell BootROM UART Sensing
|
|
|
|
*/
|
|
|
|
|
|
|
|
static unsigned char kwboot_msg_boot[] = {
|
|
|
|
0xBB, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77
|
|
|
|
};
|
|
|
|
|
2014-10-22 10:13:21 +00:00
|
|
|
static unsigned char kwboot_msg_debug[] = {
|
|
|
|
0xDD, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Defines known to work on Kirkwood */
|
2012-05-27 11:44:51 +00:00
|
|
|
#define KWBOOT_MSG_RSP_TIMEO 50 /* ms */
|
|
|
|
|
2014-10-22 10:13:21 +00:00
|
|
|
/* Defines known to work on Armada XP */
|
2022-08-19 07:43:59 +00:00
|
|
|
#define KWBOOT_MSG_RSP_TIMEO_AXP 10 /* ms */
|
2014-10-22 10:13:21 +00:00
|
|
|
|
2012-05-27 11:44:51 +00:00
|
|
|
/*
|
|
|
|
* Xmodem Transfers
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define SOH 1 /* sender start of block header */
|
|
|
|
#define EOT 4 /* sender end of block transfer */
|
|
|
|
#define ACK 6 /* target block ack */
|
|
|
|
#define NAK 21 /* target block negative ack */
|
|
|
|
|
2021-09-24 21:06:48 +00:00
|
|
|
#define KWBOOT_XM_BLKSZ 128 /* xmodem block size */
|
|
|
|
|
2012-05-27 11:44:51 +00:00
|
|
|
struct kwboot_block {
|
|
|
|
uint8_t soh;
|
|
|
|
uint8_t pnum;
|
|
|
|
uint8_t _pnum;
|
2021-09-24 21:06:48 +00:00
|
|
|
uint8_t data[KWBOOT_XM_BLKSZ];
|
2012-05-27 11:44:51 +00:00
|
|
|
uint8_t csum;
|
2021-07-23 09:14:14 +00:00
|
|
|
} __packed;
|
2012-05-27 11:44:51 +00:00
|
|
|
|
2022-01-25 17:13:00 +00:00
|
|
|
#define KWBOOT_BLK_RSP_TIMEO 2000 /* ms */
|
2021-09-24 21:06:52 +00:00
|
|
|
#define KWBOOT_HDR_RSP_TIMEO 10000 /* ms */
|
2012-05-27 11:44:51 +00:00
|
|
|
|
2021-10-27 18:57:02 +00:00
|
|
|
/* ARM code to change baudrate */
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
static unsigned char kwboot_baud_code[] = {
|
|
|
|
/* ; #define UART_BASE 0xd0012000 */
|
|
|
|
/* ; #define DLL 0x00 */
|
|
|
|
/* ; #define DLH 0x04 */
|
|
|
|
/* ; #define LCR 0x0c */
|
|
|
|
/* ; #define DLAB 0x80 */
|
|
|
|
/* ; #define LSR 0x14 */
|
|
|
|
/* ; #define TEMT 0x40 */
|
|
|
|
/* ; #define DIV_ROUND(a, b) ((a + b/2) / b) */
|
|
|
|
/* ; */
|
|
|
|
/* ; u32 set_baudrate(u32 old_b, u32 new_b) { */
|
|
|
|
/* ; while */
|
|
|
|
/* ; (!(readl(UART_BASE + LSR) & TEMT)); */
|
|
|
|
/* ; u32 lcr = readl(UART_BASE + LCR); */
|
|
|
|
/* ; writel(UART_BASE + LCR, lcr | DLAB); */
|
|
|
|
/* ; u8 old_dll = readl(UART_BASE + DLL); */
|
|
|
|
/* ; u8 old_dlh = readl(UART_BASE + DLH); */
|
|
|
|
/* ; u16 old_dl = old_dll | (old_dlh << 8); */
|
|
|
|
/* ; u32 clk = old_b * old_dl; */
|
|
|
|
/* ; u16 new_dl = DIV_ROUND(clk, new_b); */
|
|
|
|
/* ; u8 new_dll = new_dl & 0xff; */
|
|
|
|
/* ; u8 new_dlh = (new_dl >> 8) & 0xff; */
|
|
|
|
/* ; writel(UART_BASE + DLL, new_dll); */
|
|
|
|
/* ; writel(UART_BASE + DLH, new_dlh); */
|
|
|
|
/* ; writel(UART_BASE + LCR, lcr & ~DLAB); */
|
2021-10-27 18:57:00 +00:00
|
|
|
/* ; msleep(5); */
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
/* ; return 0; */
|
|
|
|
/* ; } */
|
|
|
|
|
|
|
|
/* ; r0 = UART_BASE */
|
2021-10-27 18:57:01 +00:00
|
|
|
0x0d, 0x02, 0xa0, 0xe3, /* mov r0, #0xd0000000 */
|
|
|
|
0x12, 0x0a, 0x80, 0xe3, /* orr r0, r0, #0x12000 */
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
|
|
|
|
/* ; Wait until Transmitter FIFO is Empty */
|
|
|
|
/* .Lloop_txempty: */
|
|
|
|
/* ; r1 = UART_BASE[LSR] & TEMT */
|
|
|
|
0x14, 0x10, 0x90, 0xe5, /* ldr r1, [r0, #0x14] */
|
|
|
|
0x40, 0x00, 0x11, 0xe3, /* tst r1, #0x40 */
|
|
|
|
0xfc, 0xff, 0xff, 0x0a, /* beq .Lloop_txempty */
|
|
|
|
|
|
|
|
/* ; Set Divisor Latch Access Bit */
|
|
|
|
/* ; UART_BASE[LCR] |= DLAB */
|
|
|
|
0x0c, 0x10, 0x90, 0xe5, /* ldr r1, [r0, #0x0c] */
|
|
|
|
0x80, 0x10, 0x81, 0xe3, /* orr r1, r1, #0x80 */
|
|
|
|
0x0c, 0x10, 0x80, 0xe5, /* str r1, [r0, #0x0c] */
|
|
|
|
|
|
|
|
/* ; Read current Divisor Latch */
|
|
|
|
/* ; r1 = UART_BASE[DLH]<<8 | UART_BASE[DLL] */
|
|
|
|
0x00, 0x10, 0x90, 0xe5, /* ldr r1, [r0, #0x00] */
|
|
|
|
0xff, 0x10, 0x01, 0xe2, /* and r1, r1, #0xff */
|
|
|
|
0x01, 0x20, 0xa0, 0xe1, /* mov r2, r1 */
|
|
|
|
0x04, 0x10, 0x90, 0xe5, /* ldr r1, [r0, #0x04] */
|
|
|
|
0xff, 0x10, 0x01, 0xe2, /* and r1, r1, #0xff */
|
|
|
|
0x41, 0x14, 0xa0, 0xe1, /* asr r1, r1, #8 */
|
|
|
|
0x02, 0x10, 0x81, 0xe1, /* orr r1, r1, r2 */
|
|
|
|
|
|
|
|
/* ; Read old baudrate value */
|
|
|
|
/* ; r2 = old_baudrate */
|
2021-11-01 13:00:02 +00:00
|
|
|
0x74, 0x20, 0x9f, 0xe5, /* ldr r2, old_baudrate */
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
|
|
|
|
/* ; Calculate base clock */
|
|
|
|
/* ; r1 = r2 * r1 */
|
|
|
|
0x92, 0x01, 0x01, 0xe0, /* mul r1, r2, r1 */
|
|
|
|
|
|
|
|
/* ; Read new baudrate value */
|
2021-10-27 18:57:00 +00:00
|
|
|
/* ; r2 = new_baudrate */
|
2021-11-01 13:00:02 +00:00
|
|
|
0x70, 0x20, 0x9f, 0xe5, /* ldr r2, new_baudrate */
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
|
|
|
|
/* ; Calculate new Divisor Latch */
|
|
|
|
/* ; r1 = DIV_ROUND(r1, r2) = */
|
|
|
|
/* ; = (r1 + r2/2) / r2 */
|
|
|
|
0xa2, 0x10, 0x81, 0xe0, /* add r1, r1, r2, lsr #1 */
|
|
|
|
0x02, 0x40, 0xa0, 0xe1, /* mov r4, r2 */
|
|
|
|
0xa1, 0x00, 0x54, 0xe1, /* cmp r4, r1, lsr #1 */
|
|
|
|
/* .Lloop_div1: */
|
|
|
|
0x84, 0x40, 0xa0, 0x91, /* movls r4, r4, lsl #1 */
|
|
|
|
0xa1, 0x00, 0x54, 0xe1, /* cmp r4, r1, lsr #1 */
|
|
|
|
0xfc, 0xff, 0xff, 0x9a, /* bls .Lloop_div1 */
|
|
|
|
0x00, 0x30, 0xa0, 0xe3, /* mov r3, #0 */
|
|
|
|
/* .Lloop_div2: */
|
|
|
|
0x04, 0x00, 0x51, 0xe1, /* cmp r1, r4 */
|
|
|
|
0x04, 0x10, 0x41, 0x20, /* subhs r1, r1, r4 */
|
|
|
|
0x03, 0x30, 0xa3, 0xe0, /* adc r3, r3, r3 */
|
|
|
|
0xa4, 0x40, 0xa0, 0xe1, /* mov r4, r4, lsr #1 */
|
|
|
|
0x02, 0x00, 0x54, 0xe1, /* cmp r4, r2 */
|
|
|
|
0xf9, 0xff, 0xff, 0x2a, /* bhs .Lloop_div2 */
|
|
|
|
0x03, 0x10, 0xa0, 0xe1, /* mov r1, r3 */
|
|
|
|
|
|
|
|
/* ; Set new Divisor Latch Low */
|
|
|
|
/* ; UART_BASE[DLL] = r1 & 0xff */
|
|
|
|
0x01, 0x20, 0xa0, 0xe1, /* mov r2, r1 */
|
|
|
|
0xff, 0x20, 0x02, 0xe2, /* and r2, r2, #0xff */
|
|
|
|
0x00, 0x20, 0x80, 0xe5, /* str r2, [r0, #0x00] */
|
|
|
|
|
|
|
|
/* ; Set new Divisor Latch High */
|
|
|
|
/* ; UART_BASE[DLH] = r1>>8 & 0xff */
|
|
|
|
0x41, 0x24, 0xa0, 0xe1, /* asr r2, r1, #8 */
|
|
|
|
0xff, 0x20, 0x02, 0xe2, /* and r2, r2, #0xff */
|
|
|
|
0x04, 0x20, 0x80, 0xe5, /* str r2, [r0, #0x04] */
|
|
|
|
|
|
|
|
/* ; Clear Divisor Latch Access Bit */
|
|
|
|
/* ; UART_BASE[LCR] &= ~DLAB */
|
|
|
|
0x0c, 0x10, 0x90, 0xe5, /* ldr r1, [r0, #0x0c] */
|
|
|
|
0x80, 0x10, 0xc1, 0xe3, /* bic r1, r1, #0x80 */
|
|
|
|
0x0c, 0x10, 0x80, 0xe5, /* str r1, [r0, #0x0c] */
|
|
|
|
|
2021-10-27 18:57:00 +00:00
|
|
|
/* ; Loop 0x2dc000 (2998272) cycles */
|
|
|
|
/* ; which is about 5ms on 1200 MHz CPU */
|
|
|
|
/* ; r1 = 0x2dc000 */
|
|
|
|
0xb7, 0x19, 0xa0, 0xe3, /* mov r1, #0x2dc000 */
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
/* .Lloop_sleep: */
|
|
|
|
0x01, 0x10, 0x41, 0xe2, /* sub r1, r1, #1 */
|
|
|
|
0x00, 0x00, 0x51, 0xe3, /* cmp r1, #0 */
|
|
|
|
0xfc, 0xff, 0xff, 0x1a, /* bne .Lloop_sleep */
|
|
|
|
|
2021-11-01 13:00:02 +00:00
|
|
|
/* ; Jump to the end of execution */
|
|
|
|
0x01, 0x00, 0x00, 0xea, /* b end */
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
|
|
|
|
/* ; Placeholder for old baudrate value */
|
|
|
|
/* old_baudrate: */
|
|
|
|
0x00, 0x00, 0x00, 0x00, /* .word 0 */
|
|
|
|
|
|
|
|
/* ; Placeholder for new baudrate value */
|
|
|
|
/* new_baudrate: */
|
|
|
|
0x00, 0x00, 0x00, 0x00, /* .word 0 */
|
2021-10-27 18:57:02 +00:00
|
|
|
|
|
|
|
/* end: */
|
|
|
|
};
|
|
|
|
|
2021-11-01 13:00:02 +00:00
|
|
|
/* ARM code from binary header executed by BootROM before changing baudrate */
|
2021-10-27 18:57:02 +00:00
|
|
|
static unsigned char kwboot_baud_code_binhdr_pre[] = {
|
2021-11-01 13:00:02 +00:00
|
|
|
/* ; #define UART_BASE 0xd0012000 */
|
|
|
|
/* ; #define THR 0x00 */
|
|
|
|
/* ; #define LSR 0x14 */
|
|
|
|
/* ; #define THRE 0x20 */
|
|
|
|
/* ; */
|
|
|
|
/* ; void send_preamble(void) { */
|
|
|
|
/* ; const u8 *str = "$baudratechange"; */
|
|
|
|
/* ; u8 c; */
|
|
|
|
/* ; do { */
|
|
|
|
/* ; while */
|
|
|
|
/* ; ((readl(UART_BASE + LSR) & THRE)); */
|
|
|
|
/* ; c = *str++; */
|
|
|
|
/* ; writel(UART_BASE + THR, c); */
|
|
|
|
/* ; } while (c); */
|
|
|
|
/* ; } */
|
|
|
|
|
|
|
|
/* ; Preserve registers for BootROM */
|
2021-10-27 18:57:02 +00:00
|
|
|
0xfe, 0x5f, 0x2d, 0xe9, /* push { r1 - r12, lr } */
|
2021-11-01 13:00:02 +00:00
|
|
|
|
|
|
|
/* ; r0 = UART_BASE */
|
|
|
|
0x0d, 0x02, 0xa0, 0xe3, /* mov r0, #0xd0000000 */
|
|
|
|
0x12, 0x0a, 0x80, 0xe3, /* orr r0, r0, #0x12000 */
|
|
|
|
|
|
|
|
/* ; r2 = address of preamble string */
|
|
|
|
0x00, 0x20, 0x8f, 0xe2, /* adr r2, .Lstr_preamble */
|
|
|
|
|
|
|
|
/* ; Skip preamble data section */
|
|
|
|
0x03, 0x00, 0x00, 0xea, /* b .Lloop_preamble */
|
|
|
|
|
|
|
|
/* ; Preamble string */
|
|
|
|
/* .Lstr_preamble: */
|
|
|
|
0x24, 0x62, 0x61, 0x75, /* .asciz "$baudratechange" */
|
|
|
|
0x64, 0x72, 0x61, 0x74,
|
|
|
|
0x65, 0x63, 0x68, 0x61,
|
|
|
|
0x6e, 0x67, 0x65, 0x00,
|
|
|
|
|
|
|
|
/* ; Send preamble string over UART */
|
|
|
|
/* .Lloop_preamble: */
|
|
|
|
/* */
|
|
|
|
/* ; Wait until Transmitter Holding is Empty */
|
|
|
|
/* .Lloop_thre: */
|
|
|
|
/* ; r1 = UART_BASE[LSR] & THRE */
|
|
|
|
0x14, 0x10, 0x90, 0xe5, /* ldr r1, [r0, #0x14] */
|
|
|
|
0x20, 0x00, 0x11, 0xe3, /* tst r1, #0x20 */
|
|
|
|
0xfc, 0xff, 0xff, 0x0a, /* beq .Lloop_thre */
|
|
|
|
|
|
|
|
/* ; Put character into Transmitter FIFO */
|
|
|
|
/* ; r1 = *r2++ */
|
|
|
|
0x01, 0x10, 0xd2, 0xe4, /* ldrb r1, [r2], #1 */
|
|
|
|
/* ; UART_BASE[THR] = r1 */
|
|
|
|
0x00, 0x10, 0x80, 0xe5, /* str r1, [r0, #0x0] */
|
|
|
|
|
|
|
|
/* ; Loop until end of preamble string */
|
|
|
|
0x00, 0x00, 0x51, 0xe3, /* cmp r1, #0 */
|
|
|
|
0xf8, 0xff, 0xff, 0x1a, /* bne .Lloop_preamble */
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
};
|
|
|
|
|
2021-11-01 13:00:02 +00:00
|
|
|
/* ARM code for returning from binary header back to BootROM */
|
2021-10-27 18:57:02 +00:00
|
|
|
static unsigned char kwboot_baud_code_binhdr_post[] = {
|
|
|
|
/* ; Return 0 - no error */
|
|
|
|
0x00, 0x00, 0xa0, 0xe3, /* mov r0, #0 */
|
|
|
|
0xfe, 0x9f, 0xbd, 0xe8, /* pop { r1 - r12, pc } */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ARM code for jumping to the original image exec_addr */
|
|
|
|
static unsigned char kwboot_baud_code_data_jump[] = {
|
|
|
|
0x04, 0xf0, 0x1f, 0xe5, /* ldr pc, exec_addr */
|
|
|
|
/* ; Placeholder for exec_addr */
|
|
|
|
/* exec_addr: */
|
|
|
|
0x00, 0x00, 0x00, 0x00, /* .word 0 */
|
|
|
|
};
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
|
|
|
|
static const char kwb_baud_magic[16] = "$baudratechange";
|
|
|
|
|
2012-05-27 11:44:51 +00:00
|
|
|
static int kwboot_verbose;
|
|
|
|
|
2014-10-22 10:13:21 +00:00
|
|
|
static int msg_rsp_timeo = KWBOOT_MSG_RSP_TIMEO;
|
2016-02-16 21:28:19 +00:00
|
|
|
static int blk_rsp_timeo = KWBOOT_BLK_RSP_TIMEO;
|
2014-10-22 10:13:21 +00:00
|
|
|
|
2021-09-24 21:06:41 +00:00
|
|
|
static ssize_t
|
|
|
|
kwboot_write(int fd, const char *buf, size_t len)
|
|
|
|
{
|
2022-01-25 17:13:10 +00:00
|
|
|
ssize_t tot = 0;
|
2021-09-24 21:06:41 +00:00
|
|
|
|
|
|
|
while (tot < len) {
|
|
|
|
ssize_t wr = write(fd, buf + tot, len - tot);
|
|
|
|
|
2022-01-25 17:13:10 +00:00
|
|
|
if (wr < 0 && errno == EINTR)
|
|
|
|
continue;
|
|
|
|
else if (wr < 0)
|
|
|
|
return wr;
|
2021-09-24 21:06:41 +00:00
|
|
|
|
|
|
|
tot += wr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return tot;
|
|
|
|
}
|
|
|
|
|
2012-05-27 11:44:51 +00:00
|
|
|
static void
|
|
|
|
kwboot_printv(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
if (kwboot_verbose) {
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vprintf(fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
__spinner(void)
|
|
|
|
{
|
|
|
|
const char seq[] = { '-', '\\', '|', '/' };
|
|
|
|
const int div = 8;
|
|
|
|
static int state, bs;
|
|
|
|
|
|
|
|
if (state % div == 0) {
|
|
|
|
fputc(bs, stdout);
|
|
|
|
fputc(seq[state / div % sizeof(seq)], stdout);
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
bs = '\b';
|
|
|
|
state++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
kwboot_spinner(void)
|
|
|
|
{
|
|
|
|
if (kwboot_verbose)
|
|
|
|
__spinner();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
__progress(int pct, char c)
|
|
|
|
{
|
|
|
|
const int width = 70;
|
|
|
|
static const char *nl = "";
|
|
|
|
static int pos;
|
|
|
|
|
|
|
|
if (pos % width == 0)
|
|
|
|
printf("%s%3d %% [", nl, pct);
|
|
|
|
|
|
|
|
fputc(c, stdout);
|
|
|
|
|
|
|
|
nl = "]\n";
|
2021-09-24 21:06:46 +00:00
|
|
|
pos = (pos + 1) % width;
|
2012-05-27 11:44:51 +00:00
|
|
|
|
|
|
|
if (pct == 100) {
|
2021-09-24 21:06:46 +00:00
|
|
|
while (pos && pos++ < width)
|
2012-05-27 11:44:51 +00:00
|
|
|
fputc(' ', stdout);
|
|
|
|
fputs(nl, stdout);
|
2021-09-24 21:06:46 +00:00
|
|
|
nl = "";
|
|
|
|
pos = 0;
|
2012-05-27 11:44:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
kwboot_progress(int _pct, char c)
|
|
|
|
{
|
|
|
|
static int pct;
|
|
|
|
|
|
|
|
if (_pct != -1)
|
|
|
|
pct = _pct;
|
|
|
|
|
|
|
|
if (kwboot_verbose)
|
|
|
|
__progress(pct, c);
|
2021-09-24 21:06:46 +00:00
|
|
|
|
|
|
|
if (pct == 100)
|
|
|
|
pct = 0;
|
2012-05-27 11:44:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
kwboot_tty_recv(int fd, void *buf, size_t len, int timeo)
|
|
|
|
{
|
|
|
|
int rc, nfds;
|
|
|
|
fd_set rfds;
|
|
|
|
struct timeval tv;
|
|
|
|
ssize_t n;
|
|
|
|
|
|
|
|
rc = -1;
|
|
|
|
|
|
|
|
FD_ZERO(&rfds);
|
|
|
|
FD_SET(fd, &rfds);
|
|
|
|
|
|
|
|
tv.tv_sec = 0;
|
|
|
|
tv.tv_usec = timeo * 1000;
|
|
|
|
if (tv.tv_usec > 1000000) {
|
|
|
|
tv.tv_sec += tv.tv_usec / 1000000;
|
|
|
|
tv.tv_usec %= 1000000;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
nfds = select(fd + 1, &rfds, NULL, NULL, &tv);
|
2022-01-25 17:13:11 +00:00
|
|
|
if (nfds < 0 && errno == EINTR)
|
|
|
|
continue;
|
|
|
|
else if (nfds < 0)
|
2012-05-27 11:44:51 +00:00
|
|
|
goto out;
|
2022-01-25 17:13:11 +00:00
|
|
|
else if (!nfds) {
|
2012-05-27 11:44:51 +00:00
|
|
|
errno = ETIMEDOUT;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
n = read(fd, buf, len);
|
2022-01-25 17:13:11 +00:00
|
|
|
if (n < 0 && errno == EINTR)
|
|
|
|
continue;
|
|
|
|
else if (n <= 0)
|
2012-05-27 11:44:51 +00:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
buf = (char *)buf + n;
|
|
|
|
len -= n;
|
|
|
|
} while (len > 0);
|
|
|
|
|
|
|
|
rc = 0;
|
|
|
|
out:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2021-10-27 18:56:59 +00:00
|
|
|
kwboot_tty_send(int fd, const void *buf, size_t len, int nodrain)
|
2012-05-27 11:44:51 +00:00
|
|
|
{
|
2014-10-22 10:13:21 +00:00
|
|
|
if (!buf)
|
|
|
|
return 0;
|
|
|
|
|
2021-09-24 21:06:41 +00:00
|
|
|
if (kwboot_write(fd, buf, len) < 0)
|
|
|
|
return -1;
|
2012-05-27 11:44:51 +00:00
|
|
|
|
2021-10-27 18:56:59 +00:00
|
|
|
if (nodrain)
|
|
|
|
return 0;
|
|
|
|
|
2021-09-24 21:06:41 +00:00
|
|
|
return tcdrain(fd);
|
2012-05-27 11:44:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
kwboot_tty_send_char(int fd, unsigned char c)
|
|
|
|
{
|
2021-10-27 18:56:59 +00:00
|
|
|
return kwboot_tty_send(fd, &c, 1, 0);
|
2012-05-27 11:44:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static speed_t
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
kwboot_tty_baudrate_to_speed(int baudrate)
|
2012-05-27 11:44:51 +00:00
|
|
|
{
|
|
|
|
switch (baudrate) {
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
#ifdef B4000000
|
|
|
|
case 4000000:
|
|
|
|
return B4000000;
|
|
|
|
#endif
|
|
|
|
#ifdef B3500000
|
|
|
|
case 3500000:
|
|
|
|
return B3500000;
|
|
|
|
#endif
|
|
|
|
#ifdef B3000000
|
|
|
|
case 3000000:
|
|
|
|
return B3000000;
|
|
|
|
#endif
|
|
|
|
#ifdef B2500000
|
|
|
|
case 2500000:
|
|
|
|
return B2500000;
|
|
|
|
#endif
|
|
|
|
#ifdef B2000000
|
|
|
|
case 2000000:
|
|
|
|
return B2000000;
|
|
|
|
#endif
|
|
|
|
#ifdef B1500000
|
|
|
|
case 1500000:
|
|
|
|
return B1500000;
|
|
|
|
#endif
|
|
|
|
#ifdef B1152000
|
|
|
|
case 1152000:
|
|
|
|
return B1152000;
|
|
|
|
#endif
|
|
|
|
#ifdef B1000000
|
|
|
|
case 1000000:
|
|
|
|
return B1000000;
|
|
|
|
#endif
|
|
|
|
#ifdef B921600
|
|
|
|
case 921600:
|
|
|
|
return B921600;
|
|
|
|
#endif
|
|
|
|
#ifdef B614400
|
|
|
|
case 614400:
|
|
|
|
return B614400;
|
|
|
|
#endif
|
|
|
|
#ifdef B576000
|
|
|
|
case 576000:
|
|
|
|
return B576000;
|
|
|
|
#endif
|
|
|
|
#ifdef B500000
|
|
|
|
case 500000:
|
|
|
|
return B500000;
|
|
|
|
#endif
|
|
|
|
#ifdef B460800
|
|
|
|
case 460800:
|
|
|
|
return B460800;
|
|
|
|
#endif
|
|
|
|
#ifdef B307200
|
|
|
|
case 307200:
|
|
|
|
return B307200;
|
|
|
|
#endif
|
|
|
|
#ifdef B230400
|
|
|
|
case 230400:
|
|
|
|
return B230400;
|
|
|
|
#endif
|
|
|
|
#ifdef B153600
|
|
|
|
case 153600:
|
|
|
|
return B153600;
|
|
|
|
#endif
|
|
|
|
#ifdef B115200
|
2012-05-27 11:44:51 +00:00
|
|
|
case 115200:
|
|
|
|
return B115200;
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
#endif
|
|
|
|
#ifdef B76800
|
|
|
|
case 76800:
|
|
|
|
return B76800;
|
|
|
|
#endif
|
|
|
|
#ifdef B57600
|
2012-05-27 11:44:51 +00:00
|
|
|
case 57600:
|
|
|
|
return B57600;
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
#endif
|
|
|
|
#ifdef B38400
|
2012-05-27 11:44:51 +00:00
|
|
|
case 38400:
|
|
|
|
return B38400;
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
#endif
|
|
|
|
#ifdef B19200
|
2012-05-27 11:44:51 +00:00
|
|
|
case 19200:
|
|
|
|
return B19200;
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
#endif
|
|
|
|
#ifdef B9600
|
2012-05-27 11:44:51 +00:00
|
|
|
case 9600:
|
|
|
|
return B9600;
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
#endif
|
|
|
|
#ifdef B4800
|
|
|
|
case 4800:
|
|
|
|
return B4800;
|
|
|
|
#endif
|
|
|
|
#ifdef B2400
|
|
|
|
case 2400:
|
|
|
|
return B2400;
|
|
|
|
#endif
|
|
|
|
#ifdef B1800
|
|
|
|
case 1800:
|
|
|
|
return B1800;
|
|
|
|
#endif
|
|
|
|
#ifdef B1200
|
|
|
|
case 1200:
|
|
|
|
return B1200;
|
|
|
|
#endif
|
|
|
|
#ifdef B600
|
|
|
|
case 600:
|
|
|
|
return B600;
|
|
|
|
#endif
|
|
|
|
#ifdef B300
|
|
|
|
case 300:
|
|
|
|
return B300;
|
|
|
|
#endif
|
|
|
|
#ifdef B200
|
|
|
|
case 200:
|
|
|
|
return B200;
|
|
|
|
#endif
|
|
|
|
#ifdef B150
|
|
|
|
case 150:
|
|
|
|
return B150;
|
|
|
|
#endif
|
|
|
|
#ifdef B134
|
|
|
|
case 134:
|
|
|
|
return B134;
|
|
|
|
#endif
|
|
|
|
#ifdef B110
|
|
|
|
case 110:
|
|
|
|
return B110;
|
|
|
|
#endif
|
|
|
|
#ifdef B75
|
|
|
|
case 75:
|
|
|
|
return B75;
|
|
|
|
#endif
|
|
|
|
#ifdef B50
|
|
|
|
case 50:
|
|
|
|
return B50;
|
|
|
|
#endif
|
|
|
|
default:
|
2021-09-24 21:07:06 +00:00
|
|
|
#ifdef BOTHER
|
|
|
|
return BOTHER;
|
|
|
|
#else
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
return B0;
|
2021-09-24 21:07:06 +00:00
|
|
|
#endif
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-24 21:07:07 +00:00
|
|
|
static int
|
|
|
|
_is_within_tolerance(int value, int reference, int tolerance)
|
|
|
|
{
|
|
|
|
return 100 * value >= reference * (100 - tolerance) &&
|
|
|
|
100 * value <= reference * (100 + tolerance);
|
|
|
|
}
|
|
|
|
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
static int
|
|
|
|
kwboot_tty_change_baudrate(int fd, int baudrate)
|
|
|
|
{
|
|
|
|
struct termios tio;
|
|
|
|
speed_t speed;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = tcgetattr(fd, &tio);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
speed = kwboot_tty_baudrate_to_speed(baudrate);
|
|
|
|
if (speed == B0) {
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
2012-05-27 11:44:51 +00:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:07:06 +00:00
|
|
|
#ifdef BOTHER
|
|
|
|
if (speed == BOTHER)
|
|
|
|
tio.c_ospeed = tio.c_ispeed = baudrate;
|
|
|
|
#endif
|
|
|
|
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
rc = cfsetospeed(&tio, speed);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
rc = cfsetispeed(&tio, speed);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
rc = tcsetattr(fd, TCSANOW, &tio);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2021-09-24 21:07:07 +00:00
|
|
|
rc = tcgetattr(fd, &tio);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
if (cfgetospeed(&tio) != speed || cfgetispeed(&tio) != speed)
|
|
|
|
goto baud_fail;
|
|
|
|
|
|
|
|
#ifdef BOTHER
|
|
|
|
/*
|
|
|
|
* Check whether set baudrate is within 3% tolerance.
|
|
|
|
* If BOTHER is defined, Linux always fills out c_ospeed / c_ispeed
|
|
|
|
* with real values.
|
|
|
|
*/
|
|
|
|
if (!_is_within_tolerance(tio.c_ospeed, baudrate, 3))
|
|
|
|
goto baud_fail;
|
|
|
|
|
|
|
|
if (!_is_within_tolerance(tio.c_ispeed, baudrate, 3))
|
|
|
|
goto baud_fail;
|
|
|
|
#endif
|
|
|
|
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
return 0;
|
2021-09-24 21:07:07 +00:00
|
|
|
|
|
|
|
baud_fail:
|
|
|
|
fprintf(stderr, "Could not set baudrate to requested value\n");
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
2012-05-27 11:44:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
kwboot_open_tty(const char *path, int baudrate)
|
2012-05-27 11:44:51 +00:00
|
|
|
{
|
2021-09-24 21:07:10 +00:00
|
|
|
int rc, fd, flags;
|
2012-05-27 11:44:51 +00:00
|
|
|
struct termios tio;
|
|
|
|
|
|
|
|
rc = -1;
|
|
|
|
|
2021-09-24 21:07:11 +00:00
|
|
|
fd = open(path, O_RDWR | O_NOCTTY | O_NDELAY);
|
2012-05-27 11:44:51 +00:00
|
|
|
if (fd < 0)
|
|
|
|
goto out;
|
|
|
|
|
2021-09-24 21:07:08 +00:00
|
|
|
rc = tcgetattr(fd, &tio);
|
|
|
|
if (rc)
|
|
|
|
goto out;
|
2012-05-27 11:44:51 +00:00
|
|
|
|
2021-09-24 21:07:08 +00:00
|
|
|
cfmakeraw(&tio);
|
2021-09-24 21:07:11 +00:00
|
|
|
tio.c_cflag |= CREAD | CLOCAL;
|
2021-10-25 13:12:53 +00:00
|
|
|
tio.c_cflag &= ~(CSTOPB | HUPCL | CRTSCTS);
|
2012-05-27 11:44:51 +00:00
|
|
|
tio.c_cc[VMIN] = 1;
|
2021-09-24 21:07:09 +00:00
|
|
|
tio.c_cc[VTIME] = 0;
|
2012-05-27 11:44:51 +00:00
|
|
|
|
|
|
|
rc = tcsetattr(fd, TCSANOW, &tio);
|
|
|
|
if (rc)
|
|
|
|
goto out;
|
|
|
|
|
2021-09-24 21:07:10 +00:00
|
|
|
flags = fcntl(fd, F_GETFL);
|
|
|
|
if (flags < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
rc = fcntl(fd, F_SETFL, flags & ~O_NDELAY);
|
|
|
|
if (rc)
|
|
|
|
goto out;
|
|
|
|
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
rc = kwboot_tty_change_baudrate(fd, baudrate);
|
|
|
|
if (rc)
|
|
|
|
goto out;
|
|
|
|
|
2012-05-27 11:44:51 +00:00
|
|
|
rc = fd;
|
|
|
|
out:
|
|
|
|
if (rc < 0) {
|
|
|
|
if (fd >= 0)
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2022-03-02 10:49:21 +00:00
|
|
|
static void *
|
|
|
|
kwboot_msg_write_handler(void *arg)
|
|
|
|
{
|
|
|
|
int tty = *(int *)((void **)arg)[0];
|
|
|
|
const void *msg = ((void **)arg)[1];
|
|
|
|
int rsp_timeo = msg_rsp_timeo;
|
|
|
|
int i, dummy_oldtype;
|
|
|
|
|
|
|
|
/* allow to cancel this thread at any time */
|
|
|
|
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &dummy_oldtype);
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
/* write 128 samples of message pattern into the output queue without waiting */
|
|
|
|
for (i = 0; i < 128; i++) {
|
|
|
|
if (kwboot_tty_send(tty, msg, 8, 1) < 0) {
|
|
|
|
perror("\nFailed to send message pattern");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* wait until output queue is transmitted and then make pause */
|
|
|
|
if (tcdrain(tty) < 0) {
|
|
|
|
perror("\nFailed to send message pattern");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
/* BootROM requires pause on UART after it detects message pattern */
|
|
|
|
usleep(rsp_timeo * 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
kwboot_msg_start_thread(pthread_t *thread, int *tty, void *msg)
|
|
|
|
{
|
|
|
|
void *arg[2];
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
arg[0] = tty;
|
|
|
|
arg[1] = msg;
|
|
|
|
rc = pthread_create(thread, NULL, kwboot_msg_write_handler, arg);
|
|
|
|
if (rc) {
|
|
|
|
errno = rc;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
kwboot_msg_stop_thread(pthread_t thread)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = pthread_cancel(thread);
|
|
|
|
if (rc) {
|
|
|
|
errno = rc;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = pthread_join(thread, NULL);
|
|
|
|
if (rc) {
|
|
|
|
errno = rc;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-05-27 11:44:51 +00:00
|
|
|
static int
|
2022-03-02 10:49:20 +00:00
|
|
|
kwboot_bootmsg(int tty)
|
2012-05-27 11:44:51 +00:00
|
|
|
{
|
2022-01-25 17:13:08 +00:00
|
|
|
struct kwboot_block block;
|
2022-03-02 10:49:21 +00:00
|
|
|
pthread_t write_thread;
|
|
|
|
int rc, err;
|
2012-05-27 11:44:51 +00:00
|
|
|
char c;
|
|
|
|
|
2022-03-02 10:49:21 +00:00
|
|
|
/* flush input and output queue */
|
|
|
|
tcflush(tty, TCIOFLUSH);
|
2012-05-27 11:44:51 +00:00
|
|
|
|
2022-03-02 10:49:21 +00:00
|
|
|
rc = kwboot_msg_start_thread(&write_thread, &tty, kwboot_msg_boot);
|
|
|
|
if (rc) {
|
|
|
|
perror("Failed to start write thread");
|
|
|
|
return rc;
|
|
|
|
}
|
2012-05-27 11:44:51 +00:00
|
|
|
|
2022-03-02 10:49:21 +00:00
|
|
|
kwboot_printv("Sending boot message. Please reboot the target...");
|
2012-05-27 11:44:51 +00:00
|
|
|
|
2022-03-02 10:49:21 +00:00
|
|
|
err = 0;
|
|
|
|
while (1) {
|
2012-05-27 11:44:51 +00:00
|
|
|
kwboot_spinner();
|
|
|
|
|
2022-03-02 10:49:21 +00:00
|
|
|
rc = kwboot_tty_recv(tty, &c, 1, msg_rsp_timeo);
|
|
|
|
if (rc && errno == ETIMEDOUT) {
|
|
|
|
continue;
|
|
|
|
} else if (rc) {
|
|
|
|
err = errno;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c == NAK)
|
|
|
|
break;
|
|
|
|
}
|
2012-05-27 11:44:51 +00:00
|
|
|
|
|
|
|
kwboot_printv("\n");
|
|
|
|
|
2022-03-02 10:49:21 +00:00
|
|
|
rc = kwboot_msg_stop_thread(write_thread);
|
|
|
|
if (rc) {
|
|
|
|
perror("Failed to stop write thread");
|
2022-01-25 17:13:08 +00:00
|
|
|
return rc;
|
2022-03-02 10:49:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
errno = err;
|
|
|
|
perror("Failed to read response for boot message pattern");
|
|
|
|
return -1;
|
|
|
|
}
|
2022-01-25 17:13:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* At this stage we have sent more boot message patterns and BootROM
|
|
|
|
* (at least on Armada XP and 385) started interpreting sent bytes as
|
|
|
|
* part of xmodem packets. If BootROM is expecting SOH byte as start of
|
|
|
|
* a xmodem packet and it receives byte 0xff, then it throws it away and
|
|
|
|
* sends a NAK reply to host. If BootROM does not receive any byte for
|
|
|
|
* 2s when expecting some continuation of the xmodem packet, it throws
|
|
|
|
* away the partially received xmodem data and sends NAK reply to host.
|
|
|
|
*
|
|
|
|
* Therefore for starting xmodem transfer we have two options: Either
|
|
|
|
* wait 2s or send 132 0xff bytes (which is the size of xmodem packet)
|
|
|
|
* to ensure that BootROM throws away any partially received data.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* flush output queue with remaining boot message patterns */
|
2022-03-02 10:49:18 +00:00
|
|
|
rc = tcflush(tty, TCOFLUSH);
|
|
|
|
if (rc) {
|
|
|
|
perror("Failed to flush output queue");
|
|
|
|
return rc;
|
|
|
|
}
|
2022-01-25 17:13:08 +00:00
|
|
|
|
|
|
|
/* send one xmodem packet with 0xff bytes to force BootROM to re-sync */
|
|
|
|
memset(&block, 0xff, sizeof(block));
|
2022-03-02 10:49:18 +00:00
|
|
|
rc = kwboot_tty_send(tty, &block, sizeof(block), 0);
|
|
|
|
if (rc) {
|
|
|
|
perror("Failed to send sync sequence");
|
|
|
|
return rc;
|
|
|
|
}
|
2022-01-25 17:13:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Sending 132 bytes via 115200B/8-N-1 takes 11.45 ms, reading 132 bytes
|
|
|
|
* takes 11.45 ms, so waiting for 30 ms should be enough.
|
|
|
|
*/
|
|
|
|
usleep(30 * 1000);
|
|
|
|
|
|
|
|
/* flush remaining NAK replies from input queue */
|
2022-03-02 10:49:18 +00:00
|
|
|
rc = tcflush(tty, TCIFLUSH);
|
|
|
|
if (rc) {
|
|
|
|
perror("Failed to flush input queue");
|
|
|
|
return rc;
|
|
|
|
}
|
2022-01-25 17:13:08 +00:00
|
|
|
|
|
|
|
return 0;
|
2012-05-27 11:44:51 +00:00
|
|
|
}
|
|
|
|
|
2014-10-22 10:13:21 +00:00
|
|
|
static int
|
2022-03-02 10:49:20 +00:00
|
|
|
kwboot_debugmsg(int tty)
|
2014-10-22 10:13:21 +00:00
|
|
|
{
|
2022-03-02 10:49:22 +00:00
|
|
|
unsigned char buf[8192];
|
|
|
|
pthread_t write_thread;
|
|
|
|
int rc, err, i, pos;
|
|
|
|
size_t off;
|
2014-10-22 10:13:21 +00:00
|
|
|
|
2022-03-02 10:49:22 +00:00
|
|
|
/* flush input and output queue */
|
|
|
|
tcflush(tty, TCIOFLUSH);
|
2014-10-22 10:13:21 +00:00
|
|
|
|
2022-03-02 10:49:22 +00:00
|
|
|
rc = kwboot_msg_start_thread(&write_thread, &tty, kwboot_msg_debug);
|
|
|
|
if (rc) {
|
|
|
|
perror("Failed to start write thread");
|
|
|
|
return rc;
|
|
|
|
}
|
2014-10-22 10:13:21 +00:00
|
|
|
|
2022-03-02 10:49:22 +00:00
|
|
|
kwboot_printv("Sending debug message. Please reboot the target...");
|
|
|
|
kwboot_spinner();
|
2014-10-22 10:13:21 +00:00
|
|
|
|
2022-03-02 10:49:22 +00:00
|
|
|
err = 0;
|
|
|
|
off = 0;
|
|
|
|
while (1) {
|
|
|
|
/* Read immediately all bytes in queue without waiting */
|
|
|
|
rc = read(tty, buf + off, sizeof(buf) - off);
|
|
|
|
if ((rc < 0 && errno == EINTR) || rc == 0) {
|
|
|
|
continue;
|
|
|
|
} else if (rc < 0) {
|
|
|
|
err = errno;
|
2022-03-02 10:49:18 +00:00
|
|
|
break;
|
2022-03-02 10:49:22 +00:00
|
|
|
}
|
|
|
|
off += rc - 1;
|
2014-10-22 10:13:21 +00:00
|
|
|
|
|
|
|
kwboot_spinner();
|
|
|
|
|
2022-03-02 10:49:22 +00:00
|
|
|
/*
|
|
|
|
* Check if we received at least 4 debug message patterns
|
|
|
|
* (console echo from BootROM) in cyclic buffer
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (pos = 0; pos < sizeof(kwboot_msg_debug); pos++)
|
|
|
|
if (buf[off] == kwboot_msg_debug[(pos + off) % sizeof(kwboot_msg_debug)])
|
|
|
|
break;
|
|
|
|
|
|
|
|
for (i = off; i >= 0; i--)
|
|
|
|
if (buf[i] != kwboot_msg_debug[(pos + i) % sizeof(kwboot_msg_debug)])
|
|
|
|
break;
|
|
|
|
|
|
|
|
off -= i;
|
|
|
|
|
|
|
|
if (off >= 4 * sizeof(kwboot_msg_debug))
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* If not move valid suffix from end of the buffer to the beginning of buffer */
|
|
|
|
memmove(buf, buf + i + 1, off);
|
|
|
|
}
|
2014-10-22 10:13:21 +00:00
|
|
|
|
|
|
|
kwboot_printv("\n");
|
|
|
|
|
2022-03-02 10:49:22 +00:00
|
|
|
rc = kwboot_msg_stop_thread(write_thread);
|
|
|
|
if (rc) {
|
|
|
|
perror("Failed to stop write thread");
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
errno = err;
|
|
|
|
perror("Failed to read response for debug message pattern");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* flush output queue with remaining debug message patterns */
|
|
|
|
rc = tcflush(tty, TCOFLUSH);
|
|
|
|
if (rc) {
|
|
|
|
perror("Failed to flush output queue");
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
kwboot_printv("Clearing input buffer...\n");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait until BootROM transmit all remaining echo characters.
|
|
|
|
* Experimentally it was measured that for Armada 385 BootROM
|
|
|
|
* it is required to wait at least 0.415s. So wait 0.5s.
|
|
|
|
*/
|
|
|
|
usleep(500 * 1000);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In off variable is stored number of characters received after the
|
|
|
|
* successful detection of echo reply. So these characters are console
|
|
|
|
* echo for other following debug message patterns. BootROM may have in
|
|
|
|
* its output queue other echo characters which were being transmitting
|
|
|
|
* before above sleep call. So read remaining number of echo characters
|
|
|
|
* sent by the BootROM now.
|
|
|
|
*/
|
|
|
|
while ((rc = kwboot_tty_recv(tty, &buf[0], 1, 0)) == 0)
|
|
|
|
off++;
|
|
|
|
if (errno != ETIMEDOUT) {
|
|
|
|
perror("Failed to read response");
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear every echo character set by the BootROM by backspace byte.
|
|
|
|
* This is required prior writing any command to the BootROM debug
|
|
|
|
* because BootROM command line buffer has limited size. If length
|
|
|
|
* of the command is larger than buffer size then it looks like
|
|
|
|
* that Armada 385 BootROM crashes after sending ENTER. So erase it.
|
|
|
|
* Experimentally it was measured that for Armada 385 BootROM it is
|
|
|
|
* required to send at least 3 backspace bytes for one echo character.
|
|
|
|
* This is unknown why. But lets do it.
|
|
|
|
*/
|
|
|
|
off *= 3;
|
|
|
|
memset(buf, '\x08', sizeof(buf));
|
|
|
|
while (off > sizeof(buf)) {
|
|
|
|
rc = kwboot_tty_send(tty, buf, sizeof(buf), 1);
|
|
|
|
if (rc) {
|
|
|
|
perror("Failed to send clear sequence");
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
off -= sizeof(buf);
|
|
|
|
}
|
|
|
|
rc = kwboot_tty_send(tty, buf, off, 0);
|
|
|
|
if (rc) {
|
|
|
|
perror("Failed to send clear sequence");
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
usleep(msg_rsp_timeo * 1000);
|
|
|
|
rc = tcflush(tty, TCIFLUSH);
|
|
|
|
if (rc) {
|
|
|
|
perror("Failed to flush input queue");
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2014-10-22 10:13:21 +00:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:06:44 +00:00
|
|
|
static size_t
|
2012-05-27 11:44:51 +00:00
|
|
|
kwboot_xm_makeblock(struct kwboot_block *block, const void *data,
|
|
|
|
size_t size, int pnum)
|
|
|
|
{
|
2021-09-24 21:06:45 +00:00
|
|
|
size_t i, n;
|
2012-05-27 11:44:51 +00:00
|
|
|
|
2014-10-22 10:13:21 +00:00
|
|
|
block->soh = SOH;
|
2012-05-27 11:44:51 +00:00
|
|
|
block->pnum = pnum;
|
|
|
|
block->_pnum = ~block->pnum;
|
|
|
|
|
2021-09-24 21:06:48 +00:00
|
|
|
n = size < KWBOOT_XM_BLKSZ ? size : KWBOOT_XM_BLKSZ;
|
2012-05-27 11:44:51 +00:00
|
|
|
memcpy(&block->data[0], data, n);
|
2021-09-24 21:06:48 +00:00
|
|
|
memset(&block->data[n], 0, KWBOOT_XM_BLKSZ - n);
|
2012-05-27 11:44:51 +00:00
|
|
|
|
|
|
|
block->csum = 0;
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
block->csum += block->data[i];
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2021-09-24 21:06:52 +00:00
|
|
|
static uint64_t
|
|
|
|
_now(void)
|
|
|
|
{
|
|
|
|
struct timespec ts;
|
|
|
|
|
|
|
|
if (clock_gettime(CLOCK_MONOTONIC, &ts)) {
|
|
|
|
static int err_print;
|
|
|
|
|
|
|
|
if (!err_print) {
|
|
|
|
perror("clock_gettime() does not work");
|
|
|
|
err_print = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this will just make the timeout not work */
|
|
|
|
return -1ULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ts.tv_sec * 1000ULL + (ts.tv_nsec + 500000) / 1000000;
|
|
|
|
}
|
|
|
|
|
2021-09-24 21:06:49 +00:00
|
|
|
static int
|
|
|
|
_is_xm_reply(char c)
|
|
|
|
{
|
2022-01-25 17:13:03 +00:00
|
|
|
return c == ACK || c == NAK;
|
2021-09-24 21:06:49 +00:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:06:54 +00:00
|
|
|
static int
|
|
|
|
_xm_reply_to_error(int c)
|
|
|
|
{
|
|
|
|
int rc = -1;
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case ACK:
|
|
|
|
rc = 0;
|
|
|
|
break;
|
|
|
|
case NAK:
|
|
|
|
errno = EBADMSG;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
errno = EPROTO;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2012-05-27 11:44:51 +00:00
|
|
|
static int
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
kwboot_baud_magic_handle(int fd, char c, int baudrate)
|
|
|
|
{
|
|
|
|
static size_t rcv_len;
|
|
|
|
|
|
|
|
if (rcv_len < sizeof(kwb_baud_magic)) {
|
|
|
|
/* try to recognize whole magic word */
|
|
|
|
if (c == kwb_baud_magic[rcv_len]) {
|
|
|
|
rcv_len++;
|
|
|
|
} else {
|
|
|
|
printf("%.*s%c", (int)rcv_len, kwb_baud_magic, c);
|
|
|
|
fflush(stdout);
|
|
|
|
rcv_len = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rcv_len == sizeof(kwb_baud_magic)) {
|
|
|
|
/* magic word received */
|
|
|
|
kwboot_printv("\nChanging baudrate to %d Bd\n", baudrate);
|
|
|
|
|
|
|
|
return kwboot_tty_change_baudrate(fd, baudrate) ? : 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2022-01-25 17:13:04 +00:00
|
|
|
kwboot_xm_recv_reply(int fd, char *c, int stop_on_non_xm,
|
2022-01-25 17:13:02 +00:00
|
|
|
int ignore_nak_reply,
|
2021-10-25 13:13:04 +00:00
|
|
|
int allow_non_xm, int *non_xm_print,
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
int baudrate, int *baud_changed)
|
2021-09-24 21:06:50 +00:00
|
|
|
{
|
2021-09-24 21:06:52 +00:00
|
|
|
int timeout = allow_non_xm ? KWBOOT_HDR_RSP_TIMEO : blk_rsp_timeo;
|
2021-09-24 21:06:53 +00:00
|
|
|
uint64_t recv_until = _now() + timeout;
|
2021-09-24 21:06:50 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
while (1) {
|
2021-09-24 21:06:52 +00:00
|
|
|
rc = kwboot_tty_recv(fd, c, 1, timeout);
|
2021-09-24 21:06:50 +00:00
|
|
|
if (rc) {
|
|
|
|
if (errno != ETIMEDOUT)
|
|
|
|
return rc;
|
2021-09-24 21:06:53 +00:00
|
|
|
else if (allow_non_xm && *non_xm_print)
|
2021-09-24 21:06:52 +00:00
|
|
|
return -1;
|
|
|
|
else
|
|
|
|
*c = NAK;
|
2021-09-24 21:06:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If received xmodem reply, end. */
|
2022-01-25 17:13:02 +00:00
|
|
|
if (_is_xm_reply(*c)) {
|
|
|
|
if (*c == NAK && ignore_nak_reply) {
|
|
|
|
timeout = recv_until - _now();
|
|
|
|
if (timeout >= 0)
|
|
|
|
continue;
|
|
|
|
}
|
2021-09-24 21:06:50 +00:00
|
|
|
break;
|
2022-01-25 17:13:02 +00:00
|
|
|
}
|
2021-09-24 21:06:50 +00:00
|
|
|
|
|
|
|
/*
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
* If receiving/printing non-xmodem text output is allowed and
|
|
|
|
* such a byte was received, we want to increase receiving time
|
|
|
|
* and either:
|
|
|
|
* - print the byte, if it is not part of baudrate change magic
|
|
|
|
* sequence while baudrate change was requested (-B option)
|
|
|
|
* - change baudrate
|
2021-09-24 21:06:53 +00:00
|
|
|
* Otherwise decrease timeout by time elapsed.
|
2021-09-24 21:06:50 +00:00
|
|
|
*/
|
|
|
|
if (allow_non_xm) {
|
2021-09-24 21:06:52 +00:00
|
|
|
recv_until = _now() + timeout;
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
|
|
|
|
if (baudrate && !*baud_changed) {
|
|
|
|
rc = kwboot_baud_magic_handle(fd, *c, baudrate);
|
|
|
|
if (rc == 1)
|
|
|
|
*baud_changed = 1;
|
|
|
|
else if (!rc)
|
|
|
|
*non_xm_print = 1;
|
|
|
|
else
|
|
|
|
return rc;
|
|
|
|
} else if (!baudrate || !*baud_changed) {
|
|
|
|
putchar(*c);
|
|
|
|
fflush(stdout);
|
|
|
|
*non_xm_print = 1;
|
|
|
|
}
|
2021-09-24 21:06:53 +00:00
|
|
|
} else {
|
2022-01-25 17:13:04 +00:00
|
|
|
if (stop_on_non_xm)
|
2021-10-25 13:13:04 +00:00
|
|
|
break;
|
2021-09-24 21:06:53 +00:00
|
|
|
timeout = recv_until - _now();
|
|
|
|
if (timeout < 0) {
|
|
|
|
errno = ETIMEDOUT;
|
|
|
|
return -1;
|
|
|
|
}
|
2021-09-24 21:06:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
kwboot_xm_sendblock(int fd, struct kwboot_block *block, int allow_non_xm,
|
2022-01-25 17:13:05 +00:00
|
|
|
int *done_print, int baudrate, int allow_retries)
|
2012-05-27 11:44:51 +00:00
|
|
|
{
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
int non_xm_print, baud_changed;
|
|
|
|
int rc, err, retries;
|
2012-05-27 11:44:51 +00:00
|
|
|
char c;
|
|
|
|
|
2021-09-24 21:06:50 +00:00
|
|
|
*done_print = 0;
|
2021-10-27 18:56:58 +00:00
|
|
|
non_xm_print = 0;
|
|
|
|
baud_changed = 0;
|
2021-09-24 21:06:50 +00:00
|
|
|
|
2021-10-25 13:13:03 +00:00
|
|
|
retries = 0;
|
2012-05-27 11:44:51 +00:00
|
|
|
do {
|
2021-10-27 18:56:59 +00:00
|
|
|
rc = kwboot_tty_send(fd, block, sizeof(*block), 1);
|
2012-05-27 11:44:51 +00:00
|
|
|
if (rc)
|
2022-01-25 17:13:03 +00:00
|
|
|
goto err;
|
2012-05-27 11:44:51 +00:00
|
|
|
|
2021-09-24 21:06:50 +00:00
|
|
|
if (allow_non_xm && !*done_print) {
|
|
|
|
kwboot_progress(100, '.');
|
|
|
|
kwboot_printv("Done\n");
|
|
|
|
*done_print = 1;
|
|
|
|
}
|
2014-10-22 10:13:21 +00:00
|
|
|
|
2021-10-25 13:13:04 +00:00
|
|
|
rc = kwboot_xm_recv_reply(fd, &c, retries < 3,
|
2022-01-25 17:13:02 +00:00
|
|
|
retries > 8,
|
2021-10-25 13:13:04 +00:00
|
|
|
allow_non_xm, &non_xm_print,
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
baudrate, &baud_changed);
|
2021-09-24 21:06:50 +00:00
|
|
|
if (rc)
|
2022-01-25 17:13:03 +00:00
|
|
|
goto err;
|
2012-05-27 11:44:51 +00:00
|
|
|
|
2022-01-25 17:13:06 +00:00
|
|
|
if (!allow_non_xm && c != ACK) {
|
|
|
|
if (c == NAK && allow_retries && retries + 1 < 16)
|
|
|
|
kwboot_progress(-1, '+');
|
|
|
|
else
|
|
|
|
kwboot_progress(-1, 'E');
|
|
|
|
}
|
2022-01-25 17:13:05 +00:00
|
|
|
} while (c == NAK && allow_retries && retries++ < 16);
|
2012-05-27 11:44:51 +00:00
|
|
|
|
2021-09-24 21:06:51 +00:00
|
|
|
if (non_xm_print)
|
|
|
|
kwboot_printv("\n");
|
|
|
|
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
if (allow_non_xm && baudrate && !baud_changed) {
|
|
|
|
fprintf(stderr, "Baudrate was not changed\n");
|
|
|
|
errno = EPROTO;
|
2022-01-25 17:13:03 +00:00
|
|
|
return -1;
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:06:54 +00:00
|
|
|
return _xm_reply_to_error(c);
|
2022-01-25 17:13:03 +00:00
|
|
|
err:
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
err = errno;
|
|
|
|
kwboot_printv("\n");
|
|
|
|
errno = err;
|
|
|
|
return rc;
|
2021-09-24 21:06:54 +00:00
|
|
|
}
|
2012-05-27 11:44:51 +00:00
|
|
|
|
2021-09-24 21:06:54 +00:00
|
|
|
static int
|
|
|
|
kwboot_xm_finish(int fd)
|
|
|
|
{
|
|
|
|
int rc, retries;
|
|
|
|
char c;
|
2012-05-27 11:44:51 +00:00
|
|
|
|
2021-09-24 21:06:54 +00:00
|
|
|
kwboot_printv("Finishing transfer\n");
|
|
|
|
|
2021-10-25 13:13:03 +00:00
|
|
|
retries = 0;
|
2021-09-24 21:06:54 +00:00
|
|
|
do {
|
|
|
|
rc = kwboot_tty_send_char(fd, EOT);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2021-10-25 13:13:04 +00:00
|
|
|
rc = kwboot_xm_recv_reply(fd, &c, retries < 3,
|
2022-01-25 17:13:02 +00:00
|
|
|
retries > 8,
|
2021-10-25 13:13:04 +00:00
|
|
|
0, NULL, 0, NULL);
|
2021-09-24 21:06:54 +00:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
2021-10-25 13:13:03 +00:00
|
|
|
} while (c == NAK && retries++ < 16);
|
2021-09-24 21:06:54 +00:00
|
|
|
|
|
|
|
return _xm_reply_to_error(c);
|
2012-05-27 11:44:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2021-09-24 21:06:48 +00:00
|
|
|
kwboot_xmodem_one(int tty, int *pnum, int header, const uint8_t *data,
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
size_t size, int baudrate)
|
2012-05-27 11:44:51 +00:00
|
|
|
{
|
2021-09-24 21:06:50 +00:00
|
|
|
int done_print = 0;
|
2021-09-24 21:06:48 +00:00
|
|
|
size_t sent, left;
|
|
|
|
int rc;
|
2012-05-27 11:44:51 +00:00
|
|
|
|
2021-09-24 21:06:48 +00:00
|
|
|
kwboot_printv("Sending boot image %s (%zu bytes)...\n",
|
|
|
|
header ? "header" : "data", size);
|
2012-05-27 11:44:51 +00:00
|
|
|
|
2021-09-24 21:06:48 +00:00
|
|
|
left = size;
|
|
|
|
sent = 0;
|
2012-05-27 11:44:51 +00:00
|
|
|
|
2021-09-24 21:06:48 +00:00
|
|
|
while (sent < size) {
|
2012-05-27 11:44:51 +00:00
|
|
|
struct kwboot_block block;
|
2021-09-24 21:06:50 +00:00
|
|
|
int last_block;
|
2021-09-24 21:06:48 +00:00
|
|
|
size_t blksz;
|
2012-05-27 11:44:51 +00:00
|
|
|
|
2021-09-24 21:06:48 +00:00
|
|
|
blksz = kwboot_xm_makeblock(&block, data, left, (*pnum)++);
|
|
|
|
data += blksz;
|
2012-05-27 11:44:51 +00:00
|
|
|
|
2021-09-24 21:06:50 +00:00
|
|
|
last_block = (left <= blksz);
|
|
|
|
|
2022-01-25 17:13:05 +00:00
|
|
|
/*
|
|
|
|
* Handling of repeated xmodem packets is completely broken in
|
|
|
|
* Armada 385 BootROM - it completely ignores xmodem packet
|
|
|
|
* numbers, they are only used for checksum verification.
|
|
|
|
* BootROM can handle a retry of the xmodem packet only during
|
|
|
|
* the transmission of kwbimage header and only if BootROM
|
|
|
|
* itself sent NAK response to previous attempt (it does it on
|
|
|
|
* checksum failure). During the transmission of kwbimage data
|
|
|
|
* part, BootROM always expects next xmodem packet, even if it
|
|
|
|
* sent NAK to previous attempt - there is absolutely no way to
|
|
|
|
* repair incorrectly transmitted xmodem packet during kwbimage
|
|
|
|
* data part upload. Also, if kwboot receives non-ACK/NAK
|
|
|
|
* response (meaning that original BootROM response was damaged
|
|
|
|
* on UART) there is no way to detect if BootROM accepted xmodem
|
|
|
|
* packet or not and no way to check if kwboot could repeat the
|
|
|
|
* packet or not.
|
|
|
|
*
|
|
|
|
* Stop transfer and return failure if kwboot receives unknown
|
|
|
|
* reply if non-xmodem reply is not allowed (for all xmodem
|
|
|
|
* packets except the last header packet) or when non-ACK reply
|
|
|
|
* is received during data part transfer.
|
|
|
|
*/
|
2021-09-24 21:06:50 +00:00
|
|
|
rc = kwboot_xm_sendblock(tty, &block, header && last_block,
|
2022-01-25 17:13:05 +00:00
|
|
|
&done_print, baudrate, header);
|
2012-05-27 11:44:51 +00:00
|
|
|
if (rc)
|
|
|
|
goto out;
|
|
|
|
|
2021-09-24 21:06:48 +00:00
|
|
|
sent += blksz;
|
|
|
|
left -= blksz;
|
|
|
|
|
2021-09-24 21:06:50 +00:00
|
|
|
if (!done_print)
|
|
|
|
kwboot_progress(sent * 100 / size, '.');
|
2021-09-24 21:06:48 +00:00
|
|
|
}
|
2012-05-27 11:44:51 +00:00
|
|
|
|
2021-09-24 21:06:50 +00:00
|
|
|
if (!done_print)
|
|
|
|
kwboot_printv("Done\n");
|
2012-05-27 11:44:51 +00:00
|
|
|
|
2021-09-24 21:06:48 +00:00
|
|
|
return 0;
|
2012-05-27 11:44:51 +00:00
|
|
|
out:
|
2021-09-24 21:06:47 +00:00
|
|
|
kwboot_printv("\n");
|
2012-05-27 11:44:51 +00:00
|
|
|
return rc;
|
2021-09-24 21:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
kwboot_xmodem(int tty, const void *_img, size_t size, int baudrate)
|
2021-09-24 21:06:48 +00:00
|
|
|
{
|
|
|
|
const uint8_t *img = _img;
|
|
|
|
int rc, pnum;
|
|
|
|
size_t hdrsz;
|
|
|
|
|
2021-09-24 21:07:01 +00:00
|
|
|
hdrsz = kwbheader_size(img);
|
2021-09-24 21:06:48 +00:00
|
|
|
|
2021-11-05 22:29:58 +00:00
|
|
|
/*
|
|
|
|
* If header size is not aligned to xmodem block size (which applies
|
|
|
|
* for all images in kwbimage v0 format) then we have to ensure that
|
|
|
|
* the last xmodem block of header contains beginning of the data
|
|
|
|
* followed by the header. So align header size to xmodem block size.
|
|
|
|
*/
|
|
|
|
hdrsz += (KWBOOT_XM_BLKSZ - hdrsz % KWBOOT_XM_BLKSZ) % KWBOOT_XM_BLKSZ;
|
2023-03-23 19:57:54 +00:00
|
|
|
if (hdrsz > size)
|
|
|
|
hdrsz = size;
|
2021-11-05 22:29:58 +00:00
|
|
|
|
2021-09-24 21:06:48 +00:00
|
|
|
pnum = 1;
|
|
|
|
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
rc = kwboot_xmodem_one(tty, &pnum, 1, img, hdrsz, baudrate);
|
2021-09-24 21:06:48 +00:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2021-11-05 22:29:58 +00:00
|
|
|
/*
|
|
|
|
* If we have already sent image data as a part of the last
|
|
|
|
* xmodem header block then we have nothing more to send.
|
|
|
|
*/
|
|
|
|
if (hdrsz < size) {
|
|
|
|
img += hdrsz;
|
|
|
|
size -= hdrsz;
|
|
|
|
rc = kwboot_xmodem_one(tty, &pnum, 0, img, size, 0);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
}
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
|
|
|
|
rc = kwboot_xm_finish(tty);
|
2021-09-24 21:06:48 +00:00
|
|
|
if (rc)
|
|
|
|
return rc;
|
2012-05-27 11:44:51 +00:00
|
|
|
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
if (baudrate) {
|
|
|
|
kwboot_printv("\nChanging baudrate back to 115200 Bd\n\n");
|
|
|
|
rc = kwboot_tty_change_baudrate(tty, 115200);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2012-05-27 11:44:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2022-03-02 10:49:23 +00:00
|
|
|
kwboot_term_pipe(int in, int out, const char *quit, int *s, const char *kbs, int *k)
|
2012-05-27 11:44:51 +00:00
|
|
|
{
|
2022-02-03 16:45:20 +00:00
|
|
|
char buf[128];
|
2022-03-02 10:49:23 +00:00
|
|
|
ssize_t nin, noff;
|
2012-05-27 11:44:51 +00:00
|
|
|
|
2022-02-03 16:45:20 +00:00
|
|
|
nin = read(in, buf, sizeof(buf));
|
2018-07-03 16:10:31 +00:00
|
|
|
if (nin <= 0)
|
2012-05-27 11:44:51 +00:00
|
|
|
return -1;
|
|
|
|
|
2022-03-02 10:49:23 +00:00
|
|
|
noff = 0;
|
|
|
|
|
|
|
|
if (quit || kbs) {
|
2012-05-27 11:44:51 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < nin; i++) {
|
2022-03-02 10:49:23 +00:00
|
|
|
if ((quit || kbs) &&
|
|
|
|
(!quit || buf[i] != quit[*s]) &&
|
|
|
|
(!kbs || buf[i] != kbs[*k])) {
|
|
|
|
const char *prefix;
|
|
|
|
int plen;
|
|
|
|
|
|
|
|
if (quit && kbs) {
|
|
|
|
prefix = (*s >= *k) ? quit : kbs;
|
|
|
|
plen = (*s >= *k) ? *s : *k;
|
|
|
|
} else if (quit) {
|
|
|
|
prefix = quit;
|
|
|
|
plen = *s;
|
|
|
|
} else {
|
|
|
|
prefix = kbs;
|
|
|
|
plen = *k;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (plen > i && kwboot_write(out, prefix, plen - i) < 0)
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (quit && buf[i] == quit[*s]) {
|
2012-05-27 11:44:51 +00:00
|
|
|
(*s)++;
|
2022-02-03 16:45:20 +00:00
|
|
|
if (!quit[*s]) {
|
2022-02-18 11:24:13 +00:00
|
|
|
nin = (i > *s) ? (i - *s) : 0;
|
2022-02-03 16:45:20 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-03-02 10:49:23 +00:00
|
|
|
} else if (quit) {
|
2021-09-24 21:06:41 +00:00
|
|
|
*s = 0;
|
2021-07-23 09:14:20 +00:00
|
|
|
}
|
2022-03-02 10:49:23 +00:00
|
|
|
|
|
|
|
if (kbs && buf[i] == kbs[*k]) {
|
|
|
|
(*k)++;
|
|
|
|
if (!kbs[*k]) {
|
|
|
|
if (i > *k + noff &&
|
|
|
|
kwboot_write(out, buf + noff, i - *k - noff) < 0)
|
|
|
|
return -1;
|
|
|
|
/*
|
|
|
|
* Replace backspace key by '\b' (0x08)
|
|
|
|
* byte which is the only recognized
|
|
|
|
* backspace byte by Marvell BootROM.
|
|
|
|
*/
|
|
|
|
if (write(out, "\x08", 1) < 0)
|
|
|
|
return -1;
|
|
|
|
noff = i + 1;
|
|
|
|
*k = 0;
|
|
|
|
}
|
|
|
|
} else if (kbs) {
|
|
|
|
*k = 0;
|
|
|
|
}
|
2012-05-27 11:44:51 +00:00
|
|
|
}
|
2022-02-03 16:45:20 +00:00
|
|
|
|
2022-03-02 10:49:23 +00:00
|
|
|
if (i == nin) {
|
|
|
|
i = 0;
|
|
|
|
if (quit && i < *s)
|
|
|
|
i = *s;
|
|
|
|
if (kbs && i < *k)
|
|
|
|
i = *k;
|
|
|
|
nin -= (nin > i) ? i : nin;
|
|
|
|
}
|
2012-05-27 11:44:51 +00:00
|
|
|
}
|
|
|
|
|
2022-03-02 10:49:23 +00:00
|
|
|
if (nin > noff && kwboot_write(out, buf + noff, nin - noff) < 0)
|
2021-09-24 21:06:41 +00:00
|
|
|
return -1;
|
2012-05-27 11:44:51 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
kwboot_terminal(int tty)
|
|
|
|
{
|
2022-03-02 10:49:23 +00:00
|
|
|
int rc, in, s, k;
|
|
|
|
const char *kbs = NULL;
|
2021-09-24 21:06:40 +00:00
|
|
|
const char *quit = "\34c";
|
2012-05-27 11:44:51 +00:00
|
|
|
struct termios otio, tio;
|
|
|
|
|
|
|
|
rc = -1;
|
|
|
|
|
|
|
|
in = STDIN_FILENO;
|
|
|
|
if (isatty(in)) {
|
|
|
|
rc = tcgetattr(in, &otio);
|
|
|
|
if (!rc) {
|
|
|
|
tio = otio;
|
|
|
|
cfmakeraw(&tio);
|
|
|
|
rc = tcsetattr(in, TCSANOW, &tio);
|
|
|
|
}
|
|
|
|
if (rc) {
|
|
|
|
perror("tcsetattr");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2022-03-02 10:49:23 +00:00
|
|
|
/*
|
|
|
|
* Get sequence for backspace key used by the current
|
|
|
|
* terminal. Every occurrence of this sequence will be
|
|
|
|
* replaced by '\b' byte which is the only recognized
|
|
|
|
* backspace byte by Marvell BootROM.
|
|
|
|
*
|
|
|
|
* Note that we cannot read this sequence from termios
|
|
|
|
* c_cc[VERASE] as VERASE is valid only when ICANON is
|
|
|
|
* set in termios c_lflag, which is not case for us.
|
|
|
|
*
|
|
|
|
* Also most terminals do not set termios c_cc[VERASE]
|
|
|
|
* as c_cc[VERASE] can specify only one-byte sequence
|
|
|
|
* and instead let applications to read (possible
|
|
|
|
* multi-byte) sequence for backspace key from "kbs"
|
|
|
|
* terminfo database based on $TERM env variable.
|
|
|
|
*
|
|
|
|
* So read "kbs" from terminfo database via tigetstr()
|
|
|
|
* call after successful setupterm(). Most terminals
|
|
|
|
* use byte 0x7F for backspace key, so replacement with
|
|
|
|
* '\b' is required.
|
|
|
|
*/
|
|
|
|
if (setupterm(NULL, STDOUT_FILENO, &rc) == 0) {
|
|
|
|
kbs = tigetstr("kbs");
|
|
|
|
if (kbs == (char *)-1)
|
|
|
|
kbs = NULL;
|
|
|
|
}
|
|
|
|
|
2012-05-27 11:44:51 +00:00
|
|
|
kwboot_printv("[Type Ctrl-%c + %c to quit]\r\n",
|
2021-09-24 21:07:11 +00:00
|
|
|
quit[0] | 0100, quit[1]);
|
2012-05-27 11:44:51 +00:00
|
|
|
} else
|
|
|
|
in = -1;
|
|
|
|
|
|
|
|
rc = 0;
|
|
|
|
s = 0;
|
2022-03-02 10:49:23 +00:00
|
|
|
k = 0;
|
2012-05-27 11:44:51 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
fd_set rfds;
|
|
|
|
int nfds = 0;
|
|
|
|
|
2021-10-25 13:12:52 +00:00
|
|
|
FD_ZERO(&rfds);
|
2012-05-27 11:44:51 +00:00
|
|
|
FD_SET(tty, &rfds);
|
|
|
|
nfds = nfds < tty ? tty : nfds;
|
|
|
|
|
|
|
|
if (in >= 0) {
|
|
|
|
FD_SET(in, &rfds);
|
|
|
|
nfds = nfds < in ? in : nfds;
|
|
|
|
}
|
|
|
|
|
|
|
|
nfds = select(nfds + 1, &rfds, NULL, NULL, NULL);
|
|
|
|
if (nfds < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (FD_ISSET(tty, &rfds)) {
|
2022-03-02 10:49:23 +00:00
|
|
|
rc = kwboot_term_pipe(tty, STDOUT_FILENO, NULL, NULL, NULL, NULL);
|
2012-05-27 11:44:51 +00:00
|
|
|
if (rc)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-09-24 21:06:39 +00:00
|
|
|
if (in >= 0 && FD_ISSET(in, &rfds)) {
|
2022-03-02 10:49:23 +00:00
|
|
|
rc = kwboot_term_pipe(in, tty, quit, &s, kbs, &k);
|
2012-05-27 11:44:51 +00:00
|
|
|
if (rc)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (quit[s] != 0);
|
|
|
|
|
2021-07-23 09:14:18 +00:00
|
|
|
if (in >= 0)
|
|
|
|
tcsetattr(in, TCSANOW, &otio);
|
2021-07-23 09:14:19 +00:00
|
|
|
printf("\n");
|
2012-05-27 11:44:51 +00:00
|
|
|
out:
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
2021-09-24 21:07:03 +00:00
|
|
|
kwboot_read_image(const char *path, size_t *size, size_t reserve)
|
2012-05-27 11:44:51 +00:00
|
|
|
{
|
2021-09-24 21:06:55 +00:00
|
|
|
int rc, fd;
|
2012-05-27 11:44:51 +00:00
|
|
|
void *img;
|
2022-04-06 13:18:59 +00:00
|
|
|
off_t len;
|
2021-09-24 21:07:03 +00:00
|
|
|
off_t tot;
|
2012-05-27 11:44:51 +00:00
|
|
|
|
|
|
|
rc = -1;
|
|
|
|
img = NULL;
|
|
|
|
|
|
|
|
fd = open(path, O_RDONLY);
|
|
|
|
if (fd < 0)
|
|
|
|
goto out;
|
|
|
|
|
2022-04-06 13:18:59 +00:00
|
|
|
len = lseek(fd, 0, SEEK_END);
|
|
|
|
if (len == (off_t)-1)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (lseek(fd, 0, SEEK_SET) == (off_t)-1)
|
2012-05-27 11:44:51 +00:00
|
|
|
goto out;
|
|
|
|
|
2022-04-06 13:18:59 +00:00
|
|
|
img = malloc(len + reserve);
|
2021-09-24 21:07:03 +00:00
|
|
|
if (!img)
|
2012-05-27 11:44:51 +00:00
|
|
|
goto out;
|
2021-09-24 21:07:03 +00:00
|
|
|
|
|
|
|
tot = 0;
|
2022-04-06 13:18:59 +00:00
|
|
|
while (tot < len) {
|
|
|
|
ssize_t rd = read(fd, img + tot, len - tot);
|
2021-09-24 21:07:03 +00:00
|
|
|
|
|
|
|
if (rd < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
tot += rd;
|
|
|
|
|
2022-04-06 13:18:59 +00:00
|
|
|
if (!rd && tot < len) {
|
2021-09-24 21:07:03 +00:00
|
|
|
errno = EIO;
|
|
|
|
goto out;
|
|
|
|
}
|
2012-05-27 11:44:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rc = 0;
|
2022-04-06 13:18:59 +00:00
|
|
|
*size = len;
|
2012-05-27 11:44:51 +00:00
|
|
|
out:
|
|
|
|
if (rc && img) {
|
2021-09-24 21:07:03 +00:00
|
|
|
free(img);
|
2012-05-27 11:44:51 +00:00
|
|
|
img = NULL;
|
|
|
|
}
|
|
|
|
if (fd >= 0)
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
return img;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint8_t
|
2021-09-24 21:07:01 +00:00
|
|
|
kwboot_hdr_csum8(const void *hdr)
|
2012-05-27 11:44:51 +00:00
|
|
|
{
|
2021-09-24 21:07:01 +00:00
|
|
|
const uint8_t *data = hdr;
|
|
|
|
uint8_t csum;
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
size = kwbheader_size_for_csum(hdr);
|
2012-05-27 11:44:51 +00:00
|
|
|
|
|
|
|
for (csum = 0; size-- > 0; data++)
|
|
|
|
csum += *data;
|
|
|
|
|
|
|
|
return csum;
|
|
|
|
}
|
|
|
|
|
2021-10-25 13:12:55 +00:00
|
|
|
static uint32_t *
|
|
|
|
kwboot_img_csum32_ptr(void *img)
|
|
|
|
{
|
|
|
|
struct main_hdr_v1 *hdr = img;
|
|
|
|
uint32_t datasz;
|
|
|
|
|
|
|
|
datasz = le32_to_cpu(hdr->blocksize) - sizeof(uint32_t);
|
|
|
|
|
|
|
|
return img + le32_to_cpu(hdr->srcaddr) + datasz;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t
|
|
|
|
kwboot_img_csum32(const void *img)
|
|
|
|
{
|
|
|
|
const struct main_hdr_v1 *hdr = img;
|
|
|
|
uint32_t datasz, csum = 0;
|
|
|
|
const uint32_t *data;
|
|
|
|
|
|
|
|
datasz = le32_to_cpu(hdr->blocksize) - sizeof(csum);
|
|
|
|
if (datasz % sizeof(uint32_t))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
data = img + le32_to_cpu(hdr->srcaddr);
|
|
|
|
while (datasz > 0) {
|
|
|
|
csum += le32_to_cpu(*data++);
|
|
|
|
datasz -= 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cpu_to_le32(csum);
|
|
|
|
}
|
|
|
|
|
2021-09-24 21:06:57 +00:00
|
|
|
static int
|
|
|
|
kwboot_img_is_secure(void *img)
|
|
|
|
{
|
|
|
|
struct opt_hdr_v1 *ohdr;
|
|
|
|
|
|
|
|
for_each_opt_hdr_v1 (ohdr, img)
|
|
|
|
if (ohdr->headertype == OPT_HDR_V1_SECURE_TYPE)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-01-08 12:46:14 +00:00
|
|
|
static int
|
|
|
|
kwboot_img_has_ddr_init(void *img)
|
|
|
|
{
|
|
|
|
const struct register_set_hdr_v1 *rhdr;
|
|
|
|
const struct main_hdr_v0 *hdr0;
|
|
|
|
struct opt_hdr_v1 *ohdr;
|
|
|
|
u32 ohdrsz;
|
|
|
|
int last;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* kwbimage v0 image headers contain DDR init code either in
|
|
|
|
* extension header or in binary code header.
|
|
|
|
*/
|
|
|
|
if (kwbimage_version(img) == 0) {
|
|
|
|
hdr0 = img;
|
|
|
|
return hdr0->ext || hdr0->bin;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* kwbimage v1 image headers contain DDR init code either in binary
|
|
|
|
* code header or in a register set list header with SDRAM_SETUP.
|
|
|
|
*/
|
|
|
|
for_each_opt_hdr_v1 (ohdr, img) {
|
|
|
|
if (ohdr->headertype == OPT_HDR_V1_BINARY_TYPE)
|
|
|
|
return 1;
|
|
|
|
if (ohdr->headertype == OPT_HDR_V1_REGISTER_TYPE) {
|
|
|
|
rhdr = (const struct register_set_hdr_v1 *)ohdr;
|
|
|
|
ohdrsz = opt_hdr_v1_size(ohdr);
|
|
|
|
if (ohdrsz >= sizeof(*ohdr) + sizeof(rhdr->data[0].last_entry)) {
|
|
|
|
ohdrsz -= sizeof(*ohdr) + sizeof(rhdr->data[0].last_entry);
|
|
|
|
last = ohdrsz / sizeof(rhdr->data[0].entry);
|
|
|
|
if (rhdr->data[last].last_entry.delay ==
|
|
|
|
REGISTER_SET_HDR_OPT_DELAY_SDRAM_SETUP)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
static void *
|
2021-10-25 13:12:56 +00:00
|
|
|
kwboot_img_grow_data_right(void *img, size_t *size, size_t grow)
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
{
|
|
|
|
struct main_hdr_v1 *hdr = img;
|
2021-10-25 13:12:56 +00:00
|
|
|
void *result;
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
|
2021-10-25 13:12:56 +00:00
|
|
|
/*
|
|
|
|
* 32-bit checksum comes after end of image code, so we will be putting
|
|
|
|
* new code there. So we get this pointer and then increase data size
|
|
|
|
* (since increasing data size changes kwboot_img_csum32_ptr() return
|
|
|
|
* value).
|
|
|
|
*/
|
|
|
|
result = kwboot_img_csum32_ptr(img);
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
hdr->blocksize = cpu_to_le32(le32_to_cpu(hdr->blocksize) + grow);
|
2021-10-25 13:12:56 +00:00
|
|
|
*size += grow;
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
|
2021-10-25 13:12:56 +00:00
|
|
|
return result;
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:07:03 +00:00
|
|
|
static void
|
|
|
|
kwboot_img_grow_hdr(void *img, size_t *size, size_t grow)
|
|
|
|
{
|
|
|
|
uint32_t hdrsz, datasz, srcaddr;
|
|
|
|
struct main_hdr_v1 *hdr = img;
|
2021-10-25 13:13:02 +00:00
|
|
|
struct opt_hdr_v1 *ohdr;
|
2021-09-24 21:07:03 +00:00
|
|
|
uint8_t *data;
|
|
|
|
|
|
|
|
srcaddr = le32_to_cpu(hdr->srcaddr);
|
|
|
|
|
2021-10-25 13:13:02 +00:00
|
|
|
/* calculate real used space in kwbimage header */
|
|
|
|
if (kwbimage_version(img) == 0) {
|
|
|
|
hdrsz = kwbheader_size(img);
|
|
|
|
} else {
|
|
|
|
hdrsz = sizeof(*hdr);
|
|
|
|
for_each_opt_hdr_v1 (ohdr, hdr)
|
|
|
|
hdrsz += opt_hdr_v1_size(ohdr);
|
|
|
|
}
|
|
|
|
|
2021-09-24 21:07:03 +00:00
|
|
|
data = (uint8_t *)img + srcaddr;
|
|
|
|
datasz = *size - srcaddr;
|
|
|
|
|
|
|
|
/* only move data if there is not enough space */
|
|
|
|
if (hdrsz + grow > srcaddr) {
|
|
|
|
size_t need = hdrsz + grow - srcaddr;
|
|
|
|
|
|
|
|
/* move data by enough bytes */
|
|
|
|
memmove(data + need, data, datasz);
|
|
|
|
|
|
|
|
hdr->srcaddr = cpu_to_le32(srcaddr + need);
|
|
|
|
*size += need;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kwbimage_version(img) == 1) {
|
|
|
|
hdrsz += grow;
|
2021-10-25 13:13:02 +00:00
|
|
|
if (hdrsz > kwbheader_size(img)) {
|
|
|
|
hdr->headersz_msb = hdrsz >> 16;
|
|
|
|
hdr->headersz_lsb = cpu_to_le16(hdrsz & 0xffff);
|
|
|
|
}
|
2021-09-24 21:07:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
static void *
|
|
|
|
kwboot_add_bin_ohdr_v1(void *img, size_t *size, uint32_t binsz)
|
|
|
|
{
|
|
|
|
struct main_hdr_v1 *hdr = img;
|
|
|
|
struct opt_hdr_v1 *ohdr;
|
2021-10-21 14:46:06 +00:00
|
|
|
uint32_t num_args;
|
|
|
|
uint32_t offset;
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
uint32_t ohdrsz;
|
2021-10-25 13:13:01 +00:00
|
|
|
uint8_t *prev_ext;
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
|
2022-01-12 17:20:52 +00:00
|
|
|
if (hdr->ext) {
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
for_each_opt_hdr_v1 (ohdr, img)
|
|
|
|
if (opt_hdr_v1_next(ohdr) == NULL)
|
|
|
|
break;
|
|
|
|
|
2021-10-25 13:13:01 +00:00
|
|
|
prev_ext = opt_hdr_v1_ext(ohdr);
|
|
|
|
ohdr = _opt_hdr_v1_next(ohdr);
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
} else {
|
|
|
|
ohdr = (void *)(hdr + 1);
|
2021-10-25 13:13:01 +00:00
|
|
|
prev_ext = &hdr->ext;
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
}
|
|
|
|
|
2021-10-21 14:46:06 +00:00
|
|
|
/*
|
|
|
|
* ARM executable code inside the BIN header on some mvebu platforms
|
|
|
|
* (e.g. A370, AXP) must always be aligned with the 128-bit boundary.
|
|
|
|
* This requirement can be met by inserting dummy arguments into
|
|
|
|
* BIN header, if needed.
|
|
|
|
*/
|
|
|
|
offset = &ohdr->data[4] - (char *)img;
|
|
|
|
num_args = ((16 - offset % 16) % 16) / sizeof(uint32_t);
|
|
|
|
|
|
|
|
ohdrsz = sizeof(*ohdr) + 4 + 4 * num_args + binsz + 4;
|
|
|
|
kwboot_img_grow_hdr(hdr, size, ohdrsz);
|
|
|
|
|
2022-01-12 17:20:52 +00:00
|
|
|
*prev_ext = 1;
|
2021-10-25 13:13:01 +00:00
|
|
|
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
ohdr->headertype = OPT_HDR_V1_BINARY_TYPE;
|
|
|
|
ohdr->headersz_msb = ohdrsz >> 16;
|
|
|
|
ohdr->headersz_lsb = cpu_to_le16(ohdrsz & 0xffff);
|
|
|
|
|
|
|
|
memset(&ohdr->data[0], 0, ohdrsz - sizeof(*ohdr));
|
2021-10-21 14:46:06 +00:00
|
|
|
*(uint32_t *)&ohdr->data[0] = cpu_to_le32(num_args);
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
|
2021-10-21 14:46:06 +00:00
|
|
|
return &ohdr->data[4 + 4 * num_args];
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2021-10-27 18:57:02 +00:00
|
|
|
_inject_baudrate_change_code(void *img, size_t *size, int for_data,
|
2021-10-25 13:12:56 +00:00
|
|
|
int old_baud, int new_baud)
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
{
|
2021-10-25 13:12:56 +00:00
|
|
|
struct main_hdr_v1 *hdr = img;
|
2021-10-27 18:57:02 +00:00
|
|
|
uint32_t orig_datasz;
|
|
|
|
uint32_t codesz;
|
2021-10-25 13:12:56 +00:00
|
|
|
uint8_t *code;
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
|
2021-10-27 18:57:02 +00:00
|
|
|
if (for_data) {
|
2021-10-25 13:12:56 +00:00
|
|
|
orig_datasz = le32_to_cpu(hdr->blocksize) - sizeof(uint32_t);
|
|
|
|
|
2021-10-27 18:57:02 +00:00
|
|
|
codesz = sizeof(kwboot_baud_code) +
|
|
|
|
sizeof(kwboot_baud_code_data_jump);
|
|
|
|
code = kwboot_img_grow_data_right(img, size, codesz);
|
2021-10-25 13:12:56 +00:00
|
|
|
} else {
|
2021-10-27 18:57:02 +00:00
|
|
|
codesz = sizeof(kwboot_baud_code_binhdr_pre) +
|
|
|
|
sizeof(kwboot_baud_code) +
|
|
|
|
sizeof(kwboot_baud_code_binhdr_post);
|
2021-10-25 13:12:56 +00:00
|
|
|
code = kwboot_add_bin_ohdr_v1(img, size, codesz);
|
2021-10-27 18:57:02 +00:00
|
|
|
|
|
|
|
codesz = sizeof(kwboot_baud_code_binhdr_pre);
|
|
|
|
memcpy(code, kwboot_baud_code_binhdr_pre, codesz);
|
|
|
|
code += codesz;
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
}
|
|
|
|
|
2021-10-27 18:57:02 +00:00
|
|
|
codesz = sizeof(kwboot_baud_code) - 2 * sizeof(uint32_t);
|
|
|
|
memcpy(code, kwboot_baud_code, codesz);
|
|
|
|
code += codesz;
|
|
|
|
*(uint32_t *)code = cpu_to_le32(old_baud);
|
|
|
|
code += sizeof(uint32_t);
|
|
|
|
*(uint32_t *)code = cpu_to_le32(new_baud);
|
|
|
|
code += sizeof(uint32_t);
|
|
|
|
|
|
|
|
if (for_data) {
|
|
|
|
codesz = sizeof(kwboot_baud_code_data_jump) - sizeof(uint32_t);
|
|
|
|
memcpy(code, kwboot_baud_code_data_jump, codesz);
|
|
|
|
code += codesz;
|
|
|
|
*(uint32_t *)code = hdr->execaddr;
|
|
|
|
code += sizeof(uint32_t);
|
|
|
|
hdr->execaddr = cpu_to_le32(le32_to_cpu(hdr->destaddr) + orig_datasz);
|
|
|
|
} else {
|
|
|
|
codesz = sizeof(kwboot_baud_code_binhdr_post);
|
|
|
|
memcpy(code, kwboot_baud_code_binhdr_post, codesz);
|
|
|
|
code += codesz;
|
|
|
|
}
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
}
|
|
|
|
|
2023-03-29 19:25:57 +00:00
|
|
|
static int
|
|
|
|
kwboot_img_guess_sata_blksz(void *img, uint32_t blkoff, uint32_t data_size, size_t total_size)
|
|
|
|
{
|
|
|
|
uint32_t sum, *ptr, *end;
|
|
|
|
int blksz;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try all possible sector sizes which are power of two,
|
|
|
|
* at least 512 bytes and up to the 32 kB.
|
|
|
|
*/
|
|
|
|
for (blksz = 512; blksz < 0x10000; blksz *= 2) {
|
|
|
|
if (blkoff * blksz > total_size ||
|
|
|
|
blkoff * blksz + data_size > total_size ||
|
|
|
|
data_size % 4)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate data checksum and if it matches
|
|
|
|
* then tried blksz should be correct.
|
|
|
|
*/
|
|
|
|
ptr = img + blkoff * blksz;
|
|
|
|
end = (void *)ptr + data_size - 4;
|
|
|
|
for (sum = 0; ptr < end; ptr++)
|
|
|
|
sum += *ptr;
|
|
|
|
|
|
|
|
if (sum == *end)
|
|
|
|
return blksz;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fallback to 512 bytes */
|
|
|
|
return 512;
|
|
|
|
}
|
|
|
|
|
2023-01-10 21:33:56 +00:00
|
|
|
static const char *
|
|
|
|
kwboot_img_type(uint8_t blockid)
|
|
|
|
{
|
|
|
|
switch (blockid) {
|
|
|
|
case IBR_HDR_I2C_ID: return "I2C";
|
|
|
|
case IBR_HDR_SPI_ID: return "SPI";
|
|
|
|
case IBR_HDR_NAND_ID: return "NAND";
|
|
|
|
case IBR_HDR_SATA_ID: return "SATA";
|
|
|
|
case IBR_HDR_PEX_ID: return "PEX";
|
|
|
|
case IBR_HDR_UART_ID: return "UART";
|
|
|
|
case IBR_HDR_SDIO_ID: return "SDIO";
|
|
|
|
default: return "unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-27 11:44:51 +00:00
|
|
|
static int
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
kwboot_img_patch(void *img, size_t *size, int baudrate)
|
2012-05-27 11:44:51 +00:00
|
|
|
{
|
2015-09-29 07:19:59 +00:00
|
|
|
struct main_hdr_v1 *hdr;
|
2023-01-08 12:42:07 +00:00
|
|
|
struct opt_hdr_v1 *ohdr;
|
2021-09-24 21:06:58 +00:00
|
|
|
uint32_t srcaddr;
|
2012-05-27 11:44:51 +00:00
|
|
|
uint8_t csum;
|
2021-09-24 21:07:04 +00:00
|
|
|
size_t hdrsz;
|
2015-09-29 07:19:59 +00:00
|
|
|
int image_ver;
|
2021-09-24 21:06:57 +00:00
|
|
|
int is_secure;
|
2012-05-27 11:44:51 +00:00
|
|
|
|
|
|
|
hdr = img;
|
|
|
|
|
2023-01-10 21:33:56 +00:00
|
|
|
if (*size < sizeof(struct main_hdr_v1)) {
|
|
|
|
fprintf(stderr, "Invalid image header size\n");
|
2021-09-24 21:07:12 +00:00
|
|
|
goto err;
|
2023-01-10 21:33:56 +00:00
|
|
|
}
|
2012-05-27 11:44:51 +00:00
|
|
|
|
2021-09-24 21:07:00 +00:00
|
|
|
image_ver = kwbimage_version(img);
|
2021-07-23 09:14:22 +00:00
|
|
|
if (image_ver != 0 && image_ver != 1) {
|
2015-09-29 07:19:59 +00:00
|
|
|
fprintf(stderr, "Invalid image header version\n");
|
2021-09-24 21:07:12 +00:00
|
|
|
goto err;
|
2015-09-29 07:19:59 +00:00
|
|
|
}
|
|
|
|
|
2021-09-24 21:07:01 +00:00
|
|
|
hdrsz = kwbheader_size(hdr);
|
2015-09-29 07:19:59 +00:00
|
|
|
|
2023-01-10 21:33:56 +00:00
|
|
|
if (*size < hdrsz) {
|
|
|
|
fprintf(stderr, "Invalid image header size\n");
|
2021-09-24 21:07:12 +00:00
|
|
|
goto err;
|
2023-01-10 21:33:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
kwboot_printv("Detected kwbimage v%d with %s boot signature\n", image_ver, kwboot_img_type(hdr->blockid));
|
2021-07-23 09:14:21 +00:00
|
|
|
|
2021-09-24 21:07:01 +00:00
|
|
|
csum = kwboot_hdr_csum8(hdr) - hdr->checksum;
|
2023-01-10 21:33:56 +00:00
|
|
|
if (csum != hdr->checksum) {
|
|
|
|
fprintf(stderr, "Image has invalid header checksum stored in image header\n");
|
2021-09-24 21:07:12 +00:00
|
|
|
goto err;
|
2023-01-10 21:33:56 +00:00
|
|
|
}
|
2012-05-27 11:44:51 +00:00
|
|
|
|
2021-09-24 21:06:58 +00:00
|
|
|
srcaddr = le32_to_cpu(hdr->srcaddr);
|
|
|
|
|
|
|
|
switch (hdr->blockid) {
|
|
|
|
case IBR_HDR_SATA_ID:
|
2023-03-29 19:25:57 +00:00
|
|
|
hdr->srcaddr = cpu_to_le32(srcaddr * kwboot_img_guess_sata_blksz(img, srcaddr, le32_to_cpu(hdr->blocksize), *size));
|
2021-09-24 21:06:58 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IBR_HDR_PEX_ID:
|
|
|
|
if (srcaddr == 0xFFFFFFFF)
|
|
|
|
hdr->srcaddr = cpu_to_le32(hdrsz);
|
|
|
|
break;
|
2021-09-24 21:06:59 +00:00
|
|
|
|
|
|
|
case IBR_HDR_SPI_ID:
|
|
|
|
if (hdr->destaddr == cpu_to_le32(0xFFFFFFFF)) {
|
|
|
|
kwboot_printv("Patching destination and execution addresses from SPI/NOR XIP area to DDR area 0x00800000\n");
|
2023-01-21 11:59:20 +00:00
|
|
|
hdr->destaddr = cpu_to_le32(0x00800000 + le32_to_cpu(hdr->srcaddr));
|
|
|
|
hdr->execaddr = cpu_to_le32(0x00800000 + le32_to_cpu(hdr->execaddr));
|
2021-09-24 21:06:59 +00:00
|
|
|
}
|
|
|
|
break;
|
2021-09-24 21:06:58 +00:00
|
|
|
}
|
|
|
|
|
2023-01-10 21:33:56 +00:00
|
|
|
if (hdrsz > le32_to_cpu(hdr->srcaddr)) {
|
|
|
|
fprintf(stderr, "Image has invalid data offset stored in image header\n");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*size < le32_to_cpu(hdr->srcaddr) + le32_to_cpu(hdr->blocksize)) {
|
|
|
|
fprintf(stderr, "Image has invalid data size stored in image header\n");
|
2021-09-24 21:07:12 +00:00
|
|
|
goto err;
|
2023-01-10 21:33:56 +00:00
|
|
|
}
|
2021-09-24 21:07:03 +00:00
|
|
|
|
2023-01-08 12:42:07 +00:00
|
|
|
for_each_opt_hdr_v1 (ohdr, hdr) {
|
|
|
|
if (!opt_hdr_v1_valid_size(ohdr, (const uint8_t *)hdr + hdrsz)) {
|
|
|
|
fprintf(stderr, "Invalid optional image header\n");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-08 12:38:27 +00:00
|
|
|
/*
|
|
|
|
* The 32-bit data checksum is optional for UART image. If it is not
|
|
|
|
* present (checksum detected as invalid) then grow data part of the
|
|
|
|
* image for the checksum, so it can be inserted there.
|
|
|
|
*/
|
|
|
|
if (kwboot_img_csum32(img) != *kwboot_img_csum32_ptr(img)) {
|
|
|
|
if (hdr->blockid != IBR_HDR_UART_ID) {
|
|
|
|
fprintf(stderr, "Image has invalid data checksum\n");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
kwboot_img_grow_data_right(img, size, sizeof(uint32_t));
|
2023-03-23 19:57:53 +00:00
|
|
|
/* Update the 32-bit data checksum */
|
|
|
|
*kwboot_img_csum32_ptr(img) = kwboot_img_csum32(img);
|
2023-01-08 12:38:27 +00:00
|
|
|
}
|
2021-10-25 13:12:55 +00:00
|
|
|
|
2023-01-08 12:46:14 +00:00
|
|
|
if (!kwboot_img_has_ddr_init(img) &&
|
|
|
|
(le32_to_cpu(hdr->destaddr) < 0x40000000 ||
|
|
|
|
le32_to_cpu(hdr->destaddr) + le32_to_cpu(hdr->blocksize) > 0x40034000)) {
|
|
|
|
fprintf(stderr, "Image does not contain DDR init code needed for UART booting\n");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2021-09-24 21:06:57 +00:00
|
|
|
is_secure = kwboot_img_is_secure(img);
|
2012-05-27 11:44:51 +00:00
|
|
|
|
2021-09-24 21:06:57 +00:00
|
|
|
if (hdr->blockid != IBR_HDR_UART_ID) {
|
|
|
|
if (is_secure) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Image has secure header with signature for non-UART booting\n");
|
2021-09-24 21:07:12 +00:00
|
|
|
goto err;
|
2021-09-24 21:06:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
kwboot_printv("Patching image boot signature to UART\n");
|
|
|
|
hdr->blockid = IBR_HDR_UART_ID;
|
|
|
|
}
|
2012-05-27 11:44:51 +00:00
|
|
|
|
2021-10-22 10:37:47 +00:00
|
|
|
if (!is_secure) {
|
2021-10-25 13:12:58 +00:00
|
|
|
if (image_ver == 1) {
|
|
|
|
/*
|
|
|
|
* Tell BootROM to send BootROM messages to UART port
|
|
|
|
* number 0 (used also for UART booting) with default
|
|
|
|
* baudrate (which should be 115200) and do not touch
|
|
|
|
* UART MPP configuration.
|
|
|
|
*/
|
2022-01-25 17:13:13 +00:00
|
|
|
hdr->flags |= 0x1;
|
2021-10-25 13:12:58 +00:00
|
|
|
hdr->options &= ~0x1F;
|
|
|
|
hdr->options |= MAIN_HDR_V1_OPT_BAUD_DEFAULT;
|
|
|
|
hdr->options |= 0 << 3;
|
|
|
|
}
|
2021-10-22 10:37:47 +00:00
|
|
|
if (image_ver == 0)
|
|
|
|
((struct main_hdr_v0 *)img)->nandeccmode = IBR_HDR_ECC_DISABLED;
|
|
|
|
hdr->nandpagesize = 0;
|
|
|
|
}
|
|
|
|
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
if (baudrate) {
|
|
|
|
if (image_ver == 0) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Cannot inject code for changing baudrate into v0 image header\n");
|
2021-09-24 21:07:12 +00:00
|
|
|
goto err;
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (is_secure) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Cannot inject code for changing baudrate into image with secure header\n");
|
2021-09-24 21:07:12 +00:00
|
|
|
goto err;
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First inject code that changes the baudrate from the default
|
|
|
|
* value of 115200 Bd to requested value. This code is inserted
|
|
|
|
* as a new opt hdr, so it is executed by BootROM after the
|
|
|
|
* header part is received.
|
|
|
|
*/
|
|
|
|
kwboot_printv("Injecting binary header code for changing baudrate to %d Bd\n",
|
|
|
|
baudrate);
|
2021-10-25 13:12:56 +00:00
|
|
|
_inject_baudrate_change_code(img, size, 0, 115200, baudrate);
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now inject code that changes the baudrate back to 115200 Bd.
|
2021-10-25 13:12:56 +00:00
|
|
|
* This code is appended after the data part of the image, and
|
|
|
|
* execaddr is changed so that it is executed before U-Boot
|
|
|
|
* proper.
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
*/
|
|
|
|
kwboot_printv("Injecting code for changing baudrate back\n");
|
2021-10-25 13:12:56 +00:00
|
|
|
_inject_baudrate_change_code(img, size, 1, baudrate, 115200);
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
|
2021-10-25 13:12:57 +00:00
|
|
|
/* Update the 32-bit data checksum */
|
|
|
|
*kwboot_img_csum32_ptr(img) = kwboot_img_csum32(img);
|
|
|
|
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
/* recompute header size */
|
|
|
|
hdrsz = kwbheader_size(hdr);
|
|
|
|
}
|
|
|
|
|
2021-09-24 21:07:03 +00:00
|
|
|
if (hdrsz % KWBOOT_XM_BLKSZ) {
|
2021-10-25 13:13:00 +00:00
|
|
|
size_t grow = KWBOOT_XM_BLKSZ - hdrsz % KWBOOT_XM_BLKSZ;
|
2021-09-24 21:07:03 +00:00
|
|
|
|
|
|
|
if (is_secure) {
|
|
|
|
fprintf(stderr, "Cannot align image with secure header\n");
|
2021-09-24 21:07:12 +00:00
|
|
|
goto err;
|
2021-09-24 21:07:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
kwboot_printv("Aligning image header to Xmodem block size\n");
|
2021-10-25 13:13:00 +00:00
|
|
|
kwboot_img_grow_hdr(img, size, grow);
|
2023-03-23 19:57:52 +00:00
|
|
|
hdrsz += grow;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* kwbimage v1 contains header size field and for UART type it
|
|
|
|
* must be set to the aligned xmodem header size because BootROM
|
|
|
|
* rounds header size down to xmodem block size.
|
|
|
|
*/
|
|
|
|
if (kwbimage_version(img) == 1) {
|
|
|
|
hdr->headersz_msb = hdrsz >> 16;
|
|
|
|
hdr->headersz_lsb = cpu_to_le16(hdrsz & 0xffff);
|
|
|
|
}
|
2021-09-24 21:07:03 +00:00
|
|
|
}
|
|
|
|
|
2023-03-23 19:57:55 +00:00
|
|
|
/* Header size and source address must be same for UART type due to A38x BootROM bug */
|
|
|
|
if (hdrsz != le32_to_cpu(hdr->srcaddr)) {
|
|
|
|
if (is_secure) {
|
|
|
|
fprintf(stderr, "Cannot align image with secure header\n");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
kwboot_printv("Removing gap between image header and data\n");
|
|
|
|
memmove(img + hdrsz, img + le32_to_cpu(hdr->srcaddr), le32_to_cpu(hdr->blocksize));
|
|
|
|
hdr->srcaddr = cpu_to_le32(hdrsz);
|
|
|
|
}
|
|
|
|
|
2021-09-24 21:07:01 +00:00
|
|
|
hdr->checksum = kwboot_hdr_csum8(hdr) - csum;
|
2012-05-27 11:44:51 +00:00
|
|
|
|
2021-09-24 21:07:03 +00:00
|
|
|
*size = le32_to_cpu(hdr->srcaddr) + le32_to_cpu(hdr->blocksize);
|
2021-09-24 21:07:12 +00:00
|
|
|
return 0;
|
|
|
|
err:
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
2012-05-27 11:44:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
kwboot_usage(FILE *stream, char *progname)
|
|
|
|
{
|
|
|
|
fprintf(stream,
|
2022-03-02 10:49:24 +00:00
|
|
|
"Usage: %s [OPTIONS] [-b <image> | -D <image> | -b | -d ] [-B <baud> ] [-t] <TTY>\n",
|
2014-10-22 10:13:21 +00:00
|
|
|
progname);
|
2012-05-27 11:44:51 +00:00
|
|
|
fprintf(stream, "\n");
|
2014-10-22 10:13:21 +00:00
|
|
|
fprintf(stream,
|
2022-03-02 10:49:26 +00:00
|
|
|
" -b <image>: boot <image> with preamble (Kirkwood, Avanta, Armada 370/XP/375/38x/39x)\n");
|
2014-10-22 10:13:21 +00:00
|
|
|
fprintf(stream,
|
|
|
|
" -D <image>: boot <image> without preamble (Dove)\n");
|
2022-03-02 10:49:24 +00:00
|
|
|
fprintf(stream, " -b: enter xmodem boot mode\n");
|
|
|
|
fprintf(stream, " -d: enter console debug mode\n");
|
2014-10-22 10:13:21 +00:00
|
|
|
fprintf(stream, " -a: use timings for Armada XP\n");
|
2015-05-29 11:25:04 +00:00
|
|
|
fprintf(stream, " -s <resp-timeo>: use specific response-timeout\n");
|
2016-02-16 21:28:19 +00:00
|
|
|
fprintf(stream,
|
|
|
|
" -o <block-timeo>: use specific xmodem block timeout\n");
|
2012-05-27 11:44:51 +00:00
|
|
|
fprintf(stream, "\n");
|
|
|
|
fprintf(stream, " -t: mini terminal\n");
|
|
|
|
fprintf(stream, "\n");
|
|
|
|
fprintf(stream, " -B <baud>: set baud rate\n");
|
|
|
|
fprintf(stream, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
const char *ttypath, *imgpath;
|
2021-09-24 21:06:55 +00:00
|
|
|
int rv, rc, tty, term;
|
2022-03-02 10:49:20 +00:00
|
|
|
int bootmsg;
|
|
|
|
int debugmsg;
|
2012-05-27 11:44:51 +00:00
|
|
|
void *img;
|
|
|
|
size_t size;
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
size_t after_img_rsv;
|
|
|
|
int baudrate;
|
2022-01-25 17:13:07 +00:00
|
|
|
int prev_optind;
|
|
|
|
int c;
|
2012-05-27 11:44:51 +00:00
|
|
|
|
|
|
|
rv = 1;
|
|
|
|
tty = -1;
|
2022-03-02 10:49:20 +00:00
|
|
|
bootmsg = 0;
|
|
|
|
debugmsg = 0;
|
2012-05-27 11:44:51 +00:00
|
|
|
imgpath = NULL;
|
|
|
|
img = NULL;
|
|
|
|
term = 0;
|
|
|
|
size = 0;
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
after_img_rsv = KWBOOT_XM_BLKSZ;
|
|
|
|
baudrate = 115200;
|
2012-05-27 11:44:51 +00:00
|
|
|
|
2021-11-05 22:30:42 +00:00
|
|
|
printf("kwboot version %s\n", PLAIN_VERSION);
|
|
|
|
|
2012-05-27 11:44:51 +00:00
|
|
|
kwboot_verbose = isatty(STDOUT_FILENO);
|
|
|
|
|
|
|
|
do {
|
2022-01-25 17:13:07 +00:00
|
|
|
prev_optind = optind;
|
|
|
|
c = getopt(argc, argv, "hbptaB:dD:q:s:o:");
|
2012-05-27 11:44:51 +00:00
|
|
|
if (c < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
case 'b':
|
2022-01-25 17:13:07 +00:00
|
|
|
if (imgpath || bootmsg || debugmsg)
|
|
|
|
goto usage;
|
2022-03-02 10:49:20 +00:00
|
|
|
bootmsg = 1;
|
2022-01-25 17:13:07 +00:00
|
|
|
if (prev_optind == optind)
|
|
|
|
goto usage;
|
2022-03-07 18:03:09 +00:00
|
|
|
/* Option -b could have optional argument which specify image path */
|
|
|
|
if (optind < argc && argv[optind] && argv[optind][0] != '-')
|
2022-01-25 17:13:07 +00:00
|
|
|
imgpath = argv[optind++];
|
2012-05-27 11:44:51 +00:00
|
|
|
break;
|
|
|
|
|
2014-10-22 10:13:21 +00:00
|
|
|
case 'D':
|
2022-01-25 17:13:07 +00:00
|
|
|
if (imgpath || bootmsg || debugmsg)
|
|
|
|
goto usage;
|
2022-03-02 10:49:20 +00:00
|
|
|
bootmsg = 0;
|
2014-10-22 10:13:21 +00:00
|
|
|
imgpath = optarg;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'd':
|
2022-01-25 17:13:07 +00:00
|
|
|
if (imgpath || bootmsg || debugmsg)
|
|
|
|
goto usage;
|
2022-03-02 10:49:20 +00:00
|
|
|
debugmsg = 1;
|
2014-10-22 10:13:21 +00:00
|
|
|
break;
|
|
|
|
|
2012-05-27 11:44:51 +00:00
|
|
|
case 'p':
|
2021-09-24 21:06:55 +00:00
|
|
|
/* nop, for backward compatibility */
|
2012-05-27 11:44:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 't':
|
|
|
|
term = 1;
|
|
|
|
break;
|
|
|
|
|
2014-10-22 10:13:21 +00:00
|
|
|
case 'a':
|
|
|
|
msg_rsp_timeo = KWBOOT_MSG_RSP_TIMEO_AXP;
|
|
|
|
break;
|
|
|
|
|
2015-05-29 11:25:04 +00:00
|
|
|
case 'q':
|
2022-03-02 10:49:19 +00:00
|
|
|
/* nop, for backward compatibility */
|
2015-05-29 11:25:04 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 's':
|
|
|
|
msg_rsp_timeo = atoi(optarg);
|
|
|
|
break;
|
|
|
|
|
2016-02-16 21:28:19 +00:00
|
|
|
case 'o':
|
|
|
|
blk_rsp_timeo = atoi(optarg);
|
|
|
|
break;
|
|
|
|
|
2012-05-27 11:44:51 +00:00
|
|
|
case 'B':
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
baudrate = atoi(optarg);
|
2012-05-27 11:44:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'h':
|
|
|
|
rv = 0;
|
|
|
|
default:
|
|
|
|
goto usage;
|
|
|
|
}
|
|
|
|
} while (1);
|
|
|
|
|
2022-01-25 17:13:12 +00:00
|
|
|
if (!bootmsg && !term && !debugmsg && !imgpath)
|
2012-05-27 11:44:51 +00:00
|
|
|
goto usage;
|
|
|
|
|
2022-03-07 18:03:09 +00:00
|
|
|
/*
|
|
|
|
* If there is no remaining argument but optional imgpath was parsed
|
|
|
|
* then it means that optional imgpath was eaten by getopt parser.
|
|
|
|
* Reassing imgpath to required ttypath argument.
|
|
|
|
*/
|
|
|
|
if (optind == argc && imgpath) {
|
|
|
|
ttypath = imgpath;
|
|
|
|
imgpath = NULL;
|
|
|
|
} else if (optind + 1 == argc) {
|
|
|
|
ttypath = argv[optind];
|
|
|
|
} else {
|
2022-01-25 17:13:07 +00:00
|
|
|
goto usage;
|
2022-03-07 18:03:09 +00:00
|
|
|
}
|
2022-01-25 17:13:07 +00:00
|
|
|
|
2022-03-07 18:03:07 +00:00
|
|
|
/* boot and debug message use baudrate 115200 */
|
|
|
|
if (((bootmsg && !imgpath) || debugmsg) && baudrate != 115200) {
|
|
|
|
fprintf(stderr, "Baudrate other than 115200 cannot be used for this operation.\n");
|
|
|
|
goto usage;
|
|
|
|
}
|
|
|
|
|
2022-03-07 18:03:08 +00:00
|
|
|
tty = kwboot_open_tty(ttypath, baudrate);
|
2012-05-27 11:44:51 +00:00
|
|
|
if (tty < 0) {
|
|
|
|
perror(ttypath);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2022-03-07 18:03:08 +00:00
|
|
|
/*
|
|
|
|
* initial baudrate for image transfer is always 115200,
|
|
|
|
* the change to different baudrate is done only after the header is sent
|
|
|
|
*/
|
|
|
|
if (imgpath && baudrate != 115200) {
|
|
|
|
rc = kwboot_tty_change_baudrate(tty, 115200);
|
|
|
|
if (rc) {
|
|
|
|
perror(ttypath);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
if (baudrate == 115200)
|
|
|
|
/* do not change baudrate during Xmodem to the same value */
|
|
|
|
baudrate = 0;
|
|
|
|
else
|
|
|
|
/* ensure we have enough space for baudrate change code */
|
2021-10-27 18:57:02 +00:00
|
|
|
after_img_rsv += sizeof(struct opt_hdr_v1) + 8 + 16 +
|
|
|
|
sizeof(kwboot_baud_code_binhdr_pre) +
|
|
|
|
sizeof(kwboot_baud_code) +
|
|
|
|
sizeof(kwboot_baud_code_binhdr_post) +
|
2021-10-25 13:12:54 +00:00
|
|
|
KWBOOT_XM_BLKSZ +
|
|
|
|
sizeof(kwboot_baud_code) +
|
2021-10-27 18:57:02 +00:00
|
|
|
sizeof(kwboot_baud_code_data_jump) +
|
2023-01-08 12:38:27 +00:00
|
|
|
sizeof(uint32_t) +
|
2021-10-25 13:12:54 +00:00
|
|
|
KWBOOT_XM_BLKSZ;
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
|
2012-05-27 11:44:51 +00:00
|
|
|
if (imgpath) {
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
img = kwboot_read_image(imgpath, &size, after_img_rsv);
|
2012-05-27 11:44:51 +00:00
|
|
|
if (!img) {
|
|
|
|
perror(imgpath);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
rc = kwboot_img_patch(img, &size, baudrate);
|
2012-05-27 11:44:51 +00:00
|
|
|
if (rc) {
|
|
|
|
fprintf(stderr, "%s: Invalid image.\n", imgpath);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-22 10:13:21 +00:00
|
|
|
if (debugmsg) {
|
2022-03-02 10:49:20 +00:00
|
|
|
rc = kwboot_debugmsg(tty);
|
2022-03-02 10:49:22 +00:00
|
|
|
if (rc)
|
2014-10-22 10:13:21 +00:00
|
|
|
goto out;
|
2018-07-03 16:10:30 +00:00
|
|
|
} else if (bootmsg) {
|
2022-03-02 10:49:20 +00:00
|
|
|
rc = kwboot_bootmsg(tty);
|
2022-03-02 10:49:21 +00:00
|
|
|
if (rc)
|
2012-05-27 11:44:51 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (img) {
|
tools: kwboot: Support higher baudrates when booting via UART
Add support for uploading the boot image (the data part only) at higher
baudrate than the standard one.
The kwboot utility already has -B option, but choosing other baudrate
than the standard one (115200 Bd) can only work for debug mode, not for
booting the device. The BootROM for kwboot supported platforms (Orion,
Kirkwood, Dove, Discovery, AXP, A37x, A38x, A39x) cannot change the
baudrate when uploading boot image via the Xmodem protocol, nor can it
be configured via strapping pins.
So instead we add this support by injecting baudrate changing code into
the kwbimage v1 header as a new optional binary extension. This code is
executed by BootROM after it receives the whole header. The code sends
the magic string "$baudratechange\0" just before changing the baudrate
to let kwboot know that it should also change it. This is because the
injected code is run as the last binary extension, and we do not want
to loose possible output from other possible binary extensions that
came before it (in most cases this is U-Boot SPL).
We also inject the code before the payload (the data part of the image),
to change the baudrate back to the standard value, in case the payload
does not reset UART.
This change improves boot time via UART significantly (depending on the
chosen baudrate), which is very useful when debugging.
Signed-off-by: Pali Rohár <pali@kernel.org>
[ major refactor ]
Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
2021-09-24 21:07:05 +00:00
|
|
|
rc = kwboot_xmodem(tty, img, size, baudrate);
|
2012-05-27 11:44:51 +00:00
|
|
|
if (rc) {
|
|
|
|
perror("xmodem");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (term) {
|
|
|
|
rc = kwboot_terminal(tty);
|
|
|
|
if (rc && !(errno == EINTR)) {
|
|
|
|
perror("terminal");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = 0;
|
|
|
|
out:
|
|
|
|
if (tty >= 0)
|
|
|
|
close(tty);
|
|
|
|
|
|
|
|
if (img)
|
2021-09-24 21:07:03 +00:00
|
|
|
free(img);
|
2012-05-27 11:44:51 +00:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
usage:
|
|
|
|
kwboot_usage(rv ? stderr : stdout, basename(argv[0]));
|
|
|
|
goto out;
|
|
|
|
}
|