summaryrefslogtreecommitdiff
path: root/tools/kwboot.c
AgeCommit message (Collapse)Author
2023-04-13tools: kwboot: Add support for parsing SATA images with non-512 block sizePali Rohár
Currently kwboot expected that sector size for SATA image is always 512 bytes. If SATA image cannot be parsed with sector size of 512 bytes, try larger sector sizes which are power of two and up to the 32 kB. Maximal theoretical value is 32 kB because ATA IDENTIFY command returns sector size as 16-bit number. Signed-off-by: Pali Rohár <[email protected]>
2023-03-24tools: kwboot: Document information about NOR XIPPali Rohár
Signed-off-by: Pali Rohár <[email protected]> Reviewed-by: Stefan Roese <[email protected]>
2023-03-24tools: kwboot: Workaround A38x BootROM bug for images with a gapPali Rohár
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. Workaround this bug by completely removing a gap between header and data part of the UART image. Without gap, this BootROM bug is not triggered. This gap can be present in SDIO or SATA image types which have aligned start of the data part to the media sector size. With this workaround kwboot should be able to convert and send SDIO or SATA images for UART booting. Signed-off-by: Pali Rohár <[email protected]> Reviewed-by: Stefan Roese <[email protected]>
2023-03-24tools: kwboot: Fix sending very small imagesPali Rohár
Sending of very small images (smaller than 128 bytes = xmodem block size) cause out-of-bound memory read access. Fix this issue by ensuring that hdrsz when sending image is not larger than total size of the image. Issue was introduced in commit f8017c37799c ("tools: kwboot: Fix sending Kirkwood v0 images"). Special case when total image is smaller than header size aligned to multiply of xmodem size is already handled since that commit. Fixes: f8017c37799c ("tools: kwboot: Fix sending Kirkwood v0 images") Signed-off-by: Pali Rohár <[email protected]> Reviewed-by: Stefan Roese <[email protected]>
2023-03-24tools: kwboot: Fix inserting UART data checksum without -B optionPali Rohár
Commit 7665ed2fa04e ("tools: kwboot: Fix parsing UART image without data checksum") added fixup code to insert place for data checksum if UART image does not have it. Together with option -B (change baudrate), kwboot calculates this checksum. Without option -B, it inserts only place for checksum but does not calculate it. This commit fix above logic and calculate data checksum also when kwboot is used without -B option. Fixes: 7665ed2fa04e ("tools: kwboot: Fix parsing UART image without data checksum") Signed-off-by: Pali Rohár <[email protected]> Reviewed-by: Stefan Roese <[email protected]>
2023-03-24tools: kwboot: Fix invalid UART kwbimage v1 headerszPali Rohár
Ensure that UART aligned header size is always stored into kwbimage v1 header. It is needed for proper UART booting. Calculation of headersz field was broken in commit d656f5a0ee22 ("tools: kwboot: Calculate real used space in kwbimage header when calling kwboot_img_grow_hdr()") which introduced optimization of kwboot_img_grow_hdr() function. Fixes: d656f5a0ee22 ("tools: kwboot: Calculate real used space in kwbimage header when calling kwboot_img_grow_hdr()") Signed-off-by: Pali Rohár <[email protected]> Reviewed-by: Stefan Roese <[email protected]>
2023-03-01tools: kwboot: Show image type and error parsing reasonsPali Rohár
Show image type and version during parsing of kwbimage. And show reasons in error messages when parsing failed. This can help to debug issues with invalid images. Signed-off-by: Pali Rohár <[email protected]>
2023-03-01tools: kwboot: Fix patching of SPI/NOR XIP imagesPali Rohár
Marvell BootROM interprets execaddr of SPI/NOR XIP images as relative byte offset from the from the beginning of the flash device. So if data image offset and execute offset are not same then it is needed to adjust them also in DDR RAM. Fixes: f2c644e0b8bc ("tools: kwboot: Patch destination address to DDR area for SPI image") Signed-off-by: Pali Rohár <[email protected]>
2023-03-01tools: kwboot: Add check that kwbimage contains DDR init codePali Rohár
Some NOR images may be execute-in-place and do not contain DDR init code in its kwbimage header. Such images cannot be booted over UART as BootROM loads them to RAM. Add check that kwbimage contains DDR init code in its header (either as binary code header or as the simple register-value set). In some cases it is possible to load very small image into L2SRAM and when DDR init code is not required. So check for L2SRAM load address and skip DDR init code check in this case. Signed-off-by: Pali Rohár <[email protected]>
2023-03-01tools: kwboot: Validate optional kwbimage v1 headersPali Rohár
Before starting parsing of kwbimage, first validate that all optional v1 headers and correct. This prevents kwboot crashes on invalid input. Signed-off-by: Pali Rohár <[email protected]>
2023-03-01tools: kwboot: Fix parsing UART image without data checksumPali Rohár
The 32-bit data checksum in UART image is not checked by the BootROM and also Marvell tools do not generate it. So if data checksum stored in UART image does not match calculated checksum from the image then treat those checksum bytes as part of the executable image code (and not as the checksum) and for compatibility with the rest of the code manually insert data checksum into the in-memory image after the executable code, without overwriting it. This should allow to boot UART images generated by Marvell tools. Signed-off-by: Pali Rohár <[email protected]>
2023-03-01tools: kwboot: Add image type documentationPali Rohár
Add information of all available image types and where they should be stored. Storage location offsets where documented from the disassembly of the A385 BootROM image dump. Signed-off-by: Pali Rohár <[email protected]>
2023-03-01tools: kwboot: Add more documentation referencesPali Rohár
Add reference to Avanta Boot Flow documentation, BobCat2, AlleyCat3 and PONCat3 BootROM Firmware documentation and links to public Marvell tools: hdrparser.c and doimage.c Signed-off-by: Pali Rohár <[email protected]>
2023-03-01tools: kwboot: Fix parsing SATA kwbimagePali Rohár
Despite the official specification, Marvell BootROM does not interpret srcaddr from SATA image as number of sectors the beginning of the hard drive, but as number of sectors relative to the main header. To parse SATA kwbimage in the same way as Marvell BootROM, it is needed to interpret srcaddr as relative offset to the main header. This change fixes loading of SATA images via kwboot over UART. Fixes: 792e42355083 ("tools: kwboot: Patch source address in image header") Signed-off-by: Pali Rohár <[email protected]>
2023-03-01tools: kwboot: Fix parsing SDIO kwbimagePali Rohár
Despite the official specification, Marvell BootROM does not interpret srcaddr from SDIO image as offset in number of sectors (like for SATA image), but as offset in bytes (like for all other images except SATA). To parse SDIO kwbimage in the same way as Marvell BootROM, it is needed to interpret srcaddr in bytes. This change fixes loading of SDIO images via kwboot over UART. Fixes: 792e42355083 ("tools: kwboot: Patch source address in image header") Signed-off-by: Pali Rohár <[email protected]>
2022-09-13tools: kwboot: Change KWBOOT_MSG_RSP_TIMEO_AXP to 10msStefan Roese
Testing on the theadorable Armada XP platform has shown, thaz using the current value of 1000ms as response timeout does not result in reliable booting via kwboot. Using 10ms seems to be much better. So let's change this value to this 10ms instead. Signed-off-by: Stefan Roese <[email protected]> Acked-by: Pali Rohár <[email protected]>
2022-07-21treewide: Fix Marek's name and change my e-mail addressMarek Behún
Fix diacritics in some instances of my name and change my e-mail address to [email protected]. Add corresponding .mailmap entries. Signed-off-by: Marek Behún <[email protected]> Reviewed-by: Stefan Roese <[email protected]>
2022-04-21tools: kwboot: Replace fstat()+st_size by lseek()+SEEK_ENDPali Rohár
fstat()'s st_size works only for regular files. lseek() with SEEK_END works also for block or MTD devices. This replacement allows kwboot to load kwbimage from /dev/mtd0 for booting another device over /dev/ttyS0. Signed-off-by: Pali Rohár <[email protected]> Reviewed-by: Marek Behún <[email protected]>
2022-03-14tools: kwboot: Allow to mix positional arguments with option -bPali Rohár
Commit 9e6d71d2b55f ("tools: kwboot: Allow to use -b without image path as the last getopt() option") broke usage of kwboot with following arguments: kwboot -t -B 115200 /dev/ttyUSB0 -b u-boot-spl.kwb Fix parsing of option -b with optional argument again. Fixes: 9e6d71d2b55f ("tools: kwboot: Allow to use -b without image path as the last getopt() option") Signed-off-by: Pali Rohár <[email protected]> Reported-by: Tony Dinh <[email protected]> Tested-by: Tony Dinh <mibodhi at gmail.com> Reviewed-by: Stefan Roese <[email protected]>
2022-03-14tools: kwboot: Check if baudrate value is supported before sending imagePali Rohár
Call kwboot_open_tty() which baudrate value which was specified at the command line by option -B. This function returns error if baudrate is not supported by selected tty device. Initial baudrate for image transfer is always 115200, so call kwboot_tty_change_baudrate() with value 115200 immediately after kwboot_open_tty() if baudrate specified by option -B is different than 115200. This makes kwboot fail immediately, informing that baudrate is unsupported, instead of failing only after the first part of image is already sent. Signed-off-by: Pali Rohár <[email protected]> Reviewed-by: Stefan Roese <[email protected]>
2022-03-14tools: kwboot: Allow to specify custom baudrate only in supported operationsPali Rohár
Custom baudrate different than 115200 may be specified only when kwboot is not going to send boot/debug message pattern or when it is going to send boot message pattern with image file (in which case baudrate change happens after sending kwbimage header). BootROM detects boot/debug message pattern only at baudrate 115200. Signed-off-by: Pali Rohár <[email protected]> Reviewed-by: Stefan Roese <[email protected]>
2022-03-04tools: kwboot: Update references with public linksPali Rohár
Public documents about BootROM of some Marvell SoCs are available in the public Web Archive. Put this information into source code. Signed-off-by: Pali Rohár <[email protected]> Reviewed-by: Stefan Roese <[email protected]> Tested-by: Stefan Roese <[email protected]>
2022-03-04tools: kwboot: Update doc about AvantaPali Rohár
Testes proved that current kwboot version supports also Avanta SoCs. It looks like that Avanta SoCs are using same kwbimage format as Armada. Signed-off-by: Pali Rohár <[email protected]> Tested-by: Tony Dinh <[email protected]> Reviewed-by: Stefan Roese <[email protected]> Tested-by: Stefan Roese <[email protected]>
2022-03-04tools: kwboot: Update usagePali Rohár
Add all supported Armada SoCs and document -b and -d options in usage. Signed-off-by: Pali Rohár <[email protected]> Reviewed-by: Stefan Roese <[email protected]> Tested-by: Stefan Roese <[email protected]>
2022-03-04tools: kwboot: Add support for backspace key in mini terminalPali Rohár
Marvell BootROM recognize only '\b' byte as backspace. Use terminfo for retrieving current backspace sequence and replace any occurrence of backspace sequence by the '\b' byte. Reading terminfo database is possible via tigetstr() function from system library libtinfo.so.*. So link kwboot with -ltinfo. Normally terminfo functions are in <term.h> system header file. But this header file conflicts with U-Boot "termios_linux.h" header file. So declare terminfo functions manually. Signed-off-by: Pali Rohár <[email protected]> Reviewed-by: Stefan Roese <[email protected]> Tested-by: Stefan Roese <[email protected]>
2022-03-04tools: kwboot: Fix sending and processing debug message pattern (-d option)Pali Rohár
-d option is currently broken. In most cases BootROM does not detect this message pattern. For sending debug message pattern it is needed to do same steps as for boot message pattern. Implement sending debug message pattern via same separate thread like it is for boot message pattern. Checking if BootROM entered into UART debug mode is different than detecting UART boot mode. When in boot mode, BootROM sends xmodem NAK bytes. When in debug mode, BootROM activates console echo and reply back every written byte (extept \r\n which is interpreted as executing command and \b which is interpreting as removing the last sent byte). So in kwboot, check that BootROM send back at least 4 debug message patterns as a echo reply for debug message patterns which kwboot is sending in the loop. Then there is another observation, if host writes too many bytes (as command) then BootROM command line buffer may overflow after trying to execute such long command. To workaround this overflow, it is enough to remove bytes from the input line buffer by sending 3 \b bytes for every sent character. So do it. With this change, it is possbile to enter into the UART debug mode with kwboot -d option. Signed-off-by: Pali Rohár <[email protected]> Reviewed-by: Stefan Roese <[email protected]> Tested-by: Stefan Roese <[email protected]>
2022-03-04tools: kwboot: Use separate thread for sending boot message patternPali Rohár
After BootROM successfully detects boot message pattern on UART it waits until host stop sending data on UART. For example Armada 385 BootROM requires that host does not send anything on UART at least 24 ms. If host is still sending something then BootROM waits (possibly infinitely). BootROM successfully detects boot message pattern if it receives it in small period of time after power on. So to ensure that host put BootROM into UART boot mode, host must send continuous stream of boot message pattern with a small gap (for A385 at least 24 ms) after series of pattern. But this gap cannot be too often or too long to ensure that it does not cover whole BootROM time window when it is detecting for boot message pattern. Therefore it is needed to do following steps in cycle without any delay: 1. send series of boot message pattern over UART 2. wait until kernel transmit all data 3. sleep small period of time At the same time, host needs to monitor input queue, data received on the UART and checking if it contains NAK byte by which BootROM informs that xmodem transfer is ready. But it is not possible to wait until kernel transmit all data on UART and at the same time in the one process to also wait for input data. This is limitation of POSIX tty API and also by linux kernel that it does not provide asynchronous function for waiting until all data are transmitted. There is only synchronous variant tcdrain(). So to correctly implement this handshake on systems with linux kernel, it is needed to use tcdrain() in separate thread. Implement sending of boot message pattern in one thread and reading of reply in the main thread. Use pthread library for threads. This change makes UART booting on Armada 385 more reliable. It is possible to start kwboot and power on board after minute and kwboot correctly put board into UART boot mode. Old implementation without separate thread has an issue that it read just one byte from UART input queue and then it send 128 message pattern to the output queue. If some noise was on UART then kwboot was not able to read BootROM response as its input queue was just overflowed and kwboot was sending more data than receiving. This change basically fixed above issue too. Signed-off-by: Pali Rohár <[email protected]> Reviewed-by: Stefan Roese <[email protected]> Tested-by: Stefan Roese <[email protected]>
2022-03-04tools: kwboot: Cleanup bootmsg and debugmsg variablesPali Rohár
Function kwboot_debugmsg() is always called with kwboot_msg_debug as msg and function kwboot_bootmsg() with kwboot_msg_debug as msg. Function kwboot_bootmsg() is never called with NULL msg. Simplify, cleanup and remove dead code. No functional change. Signed-off-by: Pali Rohár <[email protected]> Reviewed-by: Stefan Roese <[email protected]> Tested-by: Stefan Roese <[email protected]>
2022-03-04tools: kwboot: Remove msg_req_delayPali Rohár
Variable msg_req_delay is set but never used. So completely remove it. Signed-off-by: Pali Rohár <[email protected]> Reviewed-by: Stefan Roese <[email protected]> Tested-by: Stefan Roese <[email protected]>
2022-03-04tools: kwboot: Check for return value of kwboot_tty_send() and tcflush()Pali Rohár
Failure of kwboot_tty_send() and tcflush() functions is fatal, it does not make sense to continue. So return error back to the caller like in other places where are called these functions. Signed-off-by: Pali Rohár <[email protected]> Reviewed-by: Stefan Roese <[email protected]> Tested-by: Stefan Roese <[email protected]>
2022-03-04tools: kwboot: Fix quitting terminalPali Rohár
Sometimes kwboot after quitting terminal prints error message: terminal: Bad address This is caused by trying to call write() syscall with count of (size_t)-1 bytes. When quit sequence is split into more read() calls then number of input bytes (nin) at the end of cycle can underflow and be negative. Fix it. Fixes: de7514046ea5 ("tools: kwboot: Fix detection of quit esc sequence") Signed-off-by: Pali Rohár <[email protected]> Reviewed-by: Stefan Roese <[email protected]>
2022-02-10tools: kwboot: Allow to use -b without image path as the last getopt() optionPali Rohár
Currently it is possible to call "kwboot -b -t /dev/ttyUSB0" but not to call "kwboot -b /dev/ttyUSB0". Fix it by not trying to process the last argv[], which is non-getopt() option (tty path) as the image path for -b. Fixes: c513fe47dca2 ("tools: kwboot: Allow to use option -b without image path") Reported-by: Marcel Ziswiler <[email protected]> Signed-off-by: Pali Rohár <[email protected]> Reviewed-by: Marcel Ziswiler <[email protected]> Tested-by: Marcel Ziswiler <[email protected]>
2022-02-10tools: kwboot: Fix detection of quit esc sequencePali Rohár
Quit esc sequence may be also in the middle of the read buffer. Fix the detection for that case. Signed-off-by: Pali Rohár <[email protected]> Reviewed-by: Stefan Roese <[email protected]>
2022-01-31tools: kwboot: Set debug flag to 1Pali Rohár
This should enable BootROM output on UART. (At least on A385 BootROM this is broken, BootROM ignores this debug flag and does not enable its output on UART if some valid image is available in SPI-NOR.) Signed-off-by: Pali Rohár <[email protected]> Signed-off-by: Marek Behún <[email protected]> Reviewed-by: Stefan Roese <[email protected]>
2022-01-31tools: kwboot: Fix usage of -D without -tPali Rohár
When -D is specified then both bootmsg and debugmsg are not set, but imgpath is set. Fix this check for valid and required parameters. Signed-off-by: Pali Rohár <[email protected]> Signed-off-by: Marek Behún <[email protected]> Reviewed-by: Stefan Roese <[email protected]>
2022-01-31tools: kwboot: Handle EINTR in kwboot_tty_recv()Pali Rohár
The select() and read() syscalls may be interrupted. Handle EINTR and retry them. Signed-off-by: Pali Rohár <[email protected]> Signed-off-by: Marek Behún <[email protected]> Reviewed-by: Stefan Roese <[email protected]>
2022-01-31tools: kwboot: Handle EINTR in kwboot_write()Pali Rohár
The write() syscall may be interrupted. Handle EINTR and retry it. Signed-off-by: Pali Rohár <[email protected]> Signed-off-by: Marek Behún <[email protected]> Reviewed-by: Stefan Roese <[email protected]>
2022-01-31tools: kwboot: Remove 2s delay before sending first xmodem packetPali Rohár
This delay is not needed anymore since kwboot already handles retrying logic for incomplete xmodem packets and also forces BootROM to flush its input queue. Removing it decreases total transfer time. Signed-off-by: Pali Rohár <[email protected]> Signed-off-by: Marek Behún <[email protected]> Reviewed-by: Stefan Roese <[email protected]>
2022-01-31tools: kwboot: Force BootROM to flush input queue after boot patternPali Rohár
Force the BootROM to flush its input queue after sending boot pattern. This ensures that after function kwboot_bootmsg() finishes, BootROM is able to start receiving xmodem packets without any specific delay or setup. Signed-off-by: Pali Rohár <[email protected]> Signed-off-by: Marek Behún <[email protected]> Reviewed-by: Stefan Roese <[email protected]>
2022-01-31tools: kwboot: Allow to use option -b without image pathPali Rohár
Allow option -b without image path parameter, to send boot pattern and wait for response but not send any image. This allows to use kwboot just for processing boot pattern and user can use any other xmodem tool for transferring the image itself (e.g. sx). Useful for debugging purposes. Signed-off-by: Pali Rohár <[email protected]> Signed-off-by: Marek Behún <[email protected]> Reviewed-by: Stefan Roese <[email protected]>
2022-01-31tools: kwboot: Show 'E' in progress output when error occursPali Rohár
When kwboot is unable to resend current xmodem packet, show an 'E' in the progress output instead of a '+'. This allows to distinguish between the state when kwboot is retrying sending the packet and when retry is not possible. Signed-off-by: Pali Rohár <[email protected]> Signed-off-by: Marek Behún <[email protected]> Reviewed-by: Stefan Roese <[email protected]>
2022-01-31tools: kwboot: Fix handling of repeated xmodem packetsPali Rohár
Unfortunately during some stages of xmodem transfer, A385 BootROM is not able to handle repeated xmodem packets. So if an error occurs during that stage, stop the transfer and return failure. Signed-off-by: Pali Rohár <[email protected]> Signed-off-by: Marek Behún <[email protected]> Reviewed-by: Stefan Roese <[email protected]>
2022-01-31tools: kwboot: Do not change received character in kwboot_xm_recv_reply()Pali Rohár
Marvell BootROM expects retransmission of previous xmodem packet only in the case when it sends NAK response to the host. Do not change non-xmodem response (possibly UART transfer error) to NAK in kwboot_xm_recv_reply() function. Allow caller to receive original response from device. Change argument 'nak_on_non_xm' to 'stop_on_non_xm'. Instead of changing non-xmodem character to NAK, stop processing on invalid character and return it. Signed-off-by: Pali Rohár <[email protected]> Signed-off-by: Marek Behún <[email protected]> Reviewed-by: Stefan Roese <[email protected]>
2022-01-31tools: kwboot: Remove code for handling CAN bytePali Rohár
It is unknown why handling of CAN byte was added into kwboot tool as Marvell BootROM does not support CAN byte. It never sends CAN byte to host and if host sends CAN byte BootROM handles it as an unknown byte. Remove code for handling and sending CAN bytes from the kwboot tool. Signed-off-by: Pali Rohár <[email protected]> Signed-off-by: Marek Behún <[email protected]> Reviewed-by: Stefan Roese <[email protected]>
2022-01-31tools: kwboot: Improve retrying logic for incomplete xmodem packetsPali Rohár
Sometimes if the first byte of xmodem packet (SOH) is incorrectly transmitted, BootROM sends NAK for every non-SOH received byte, which makes BootROM and the host kwboot tool out of sync. BootROM automatically re-synchronizes after 2s pause by dropping its input queue. So when attempting retransmit for 9th time or later, ignore NAK reply from BootROM and either wait for valid ACK or let kwboot timeout, which implies re-synchronization. This fixes retransmission of xmodem packets and allows kwboot to work also without "Waiting ... and flushing tty" code which is at the beginning of kwboot xmodem transfer. Signed-off-by: Pali Rohár <[email protected]> Signed-off-by: Marek Behún <[email protected]> Reviewed-by: Stefan Roese <[email protected]>
2022-01-31tools: kwboot: Wait blk_rsp_timeo when flushingPali Rohár
Use the blk_rsp_timeo variable when sleeping before flushing tty. Signed-off-by: Pali Rohár <[email protected]> Signed-off-by: Marek Behún <[email protected]> Reviewed-by: Stefan Roese <[email protected]>
2022-01-31tools: kwboot: Increase blk_rsp_timeo to 2sPali Rohár
Fix xmodem retry mechanism if some bytes from xmodem packet were lost and BootROM is still waiting for completing previous xmodem packet. It is required to wait at least 1.312s on A385, otherwise BootROM does not accept next xmodem packet if previous one was not completely transferred. 2s should be enough timeout cause that BootROM will drop incomplete xmodem packet and expects new packet. Signed-off-by: Pali Rohár <[email protected]> Signed-off-by: Marek Behún <[email protected]> Reviewed-by: Stefan Roese <[email protected]>
2022-01-14tools: kwbimage/kwboot: Check ext field for non-zero valuePali Rohár
Despite the official specification, BootROM does not look at the lowest bit of ext field but rather checks if ext field is non-zero. Moreover original Marvell doimage tool puts into the mhdr->ext field the number of extended headers, so basically it sets ext filed to non-zero value if some extended header is present. Fix U-Boot dumpimage and kwboot tools to parse correctly also kwbimage files created by Marvell doimage tool, in the same way as the BootROM is doing it when booting these images. Signed-off-by: Pali Rohár <[email protected]> Reviewed-by: Marek Behún <[email protected]> Reviewed-by: Stefan Roese <[email protected]>
2021-11-10tools: kwboot: Always print kwboot versionPali Rohár
It is useful to see kwboot version in the boot log output for debugging purposes. Signed-off-by: Pali Rohár <[email protected]> Reviewed-by: Stefan Roese <[email protected]>
2021-11-10tools: kwboot: Fix sending Kirkwood v0 imagesPali Rohár
Properly calculate and align image header size to xmodem block size. Kirkwood v0 images do not have stored total size of header in header structure itself like it is for v1 images. So kwbheader_size() calculates size by traversing image structure itself. Aligning is done in kwboot by putting zero padding bytes between the header and data part. Signed-off-by: Pali Rohár <[email protected]> Tested-by: Tony Dinh <[email protected]> Reviewed-by: Stefan Roese <[email protected]>