Browse Source

Merge tag 'arc-updates-for-2018.07-rc2' of git://git.denx.de/u-boot-arc

Here we just add a tool for HSDK flashable images preparation
together with extensive documentation for HSDK board.

This will help real-life users to update U-Boot on the board.
tags/2020-06-01
Tom Rini 2 years ago
parent
commit
f58e779513
4 changed files with 287 additions and 0 deletions
  1. +121
    -0
      board/synopsys/hsdk/README
  2. +11
    -0
      board/synopsys/hsdk/config.mk
  3. +149
    -0
      board/synopsys/hsdk/headerize-hsdk.py
  4. +6
    -0
      include/configs/hsdk.h

+ 121
- 0
board/synopsys/hsdk/README View File

@@ -0,0 +1,121 @@
================================================================================
Useful notes on bulding and using of U-Boot on ARC HS Development Kit (AKA HSDK)
================================================================================

BOARD OVERVIEW

The DesignWare ARC HS Development Kit is a ready-to-use platform for rapid
software development on the ARC HS3x family of processors.

For more information please visit:
https://www.synopsys.com/dw/ipdir.php?ds=arc-hs-development-kit

User guide is availalble here:
https://github.com/foss-for-synopsys-dwc-arc-processors/ARC-Development-Systems-Forum/wiki/docs/ARC_HSDK_User_Guide.pdf

It has the following features useful for U-Boot:
* On-board 2-channel FTDI TTL-to-USB converter
- The first channel is used for serial debug port (which makes it possible
to use a serial connection on pretty much any host machine be it
Windows, Linux or Mac).
On Linux machine typucally FTDI serial port would be /dev/ttyUSB0.
There's no HW flow-control and baud-rate is 115200.

- The second channel is used for built-in Digilent USB JTAG probe.
That means no extra hardware is required to access ARC core from a
debugger on development host. Both proprietary MetaWare debugger and
open source OpenOCD + GDB client are supported.

- Also with help of this FTDI chip it is possible to reset entire
board with help of a special `rff-ftdi-reset` utility, see:
https://github.com/foss-for-synopsys-dwc-arc-processors/rff-ftdi-reset

* Micro SD-card slot
- U-Boot expects to see the very first partition on the card formatted as
FAT file-system and uses it for keeping its environment in `uboot.env`
file. Note uboot.env is not just a text file but it is auto-generated
file created by U-Boot on invocation of `saveenv` command.
It contains a checksum which makes this saved environment invalid in
case of maual modification.

- There might be more useful files on that first FAT partition like
Linux kernl image in form of uImage (with or without built-in
initramfs), device tree blob (.dtb) etc.

- Except FAT partition there might be others following the first FAT one
like Ext file-system with rootfs etc.

* 1 Gb Ethernet socket
- U-Boot might get payload from TFTP server. This might be uImage, rootfs
image and anything else.

* 2 MiB of SPI-flash
- SPI-flahs is used as a storage for image of an application auto-executed
by bootROM on power-on. Typically U-Boot gets programmed there but
there might be other uses. But note bootROM expects to find a special
header preceeding application image itself so before flashing anything
make sure required image is prepended. In case of U-Boot this is done
by invocation of `headerize-hsdk.py` with `make bsp-generate` command.


BUILDING U-BOOT

1. Configure U-Boot:
------------------------->8----------------------
make hsdk_defconfig
------------------------->8----------------------

2. To build Elf file (for example to be used with host debugger via JTAG
connection to the target board):
------------------------->8----------------------
make mdbtrick
------------------------->8----------------------

This will produce `u-boot` Elf file.

3. To build artifacts required for U-Boot update in n-board SPI-flash:
------------------------->8----------------------
make bsp-generate
------------------------->8----------------------

This will produce `u-boot.head` and `u-boot-update.scr` which should
be put on the first FAT partition of micro SD-card to be inserted in the
HSDK board.


EXECUTING U-BOOT

1. The HSDK board is supposed to auto-start U-Boot image stored in on-board
SPI-flash on power-on. For that make sure DIP-switches in the corner of
the board are in their default positions: BIM in 1:off, 2:on state
while both BMC and BCS should be in 1:on, 2:on state.

2. Though it is possible to load U-Boot as a simple Elf file via JTAG right
in DDR and start it from the debugger.

2.1. In case of proprietary MetaWare debugger run:
------------------------->8----------------------
mdb -digilent -run -cl u-boot
------------------------->8----------------------


UPDATION U-BOOT IMAGE IN ON-BOARD SPI-FLASH

1. Create `u-boot.head` and `u-boot-update.scr` as discribed above with
`make bsp-generate` command.

2. Copy `u-boot.head` and `u-boot-update.scr` to the first the first FAT
partition of micro SD-card.

3. Connect USB cable from the HSDK board to the developemnt host and
fire-up serial terminal.

3. Insert prepared micro SD-card in the HSDK board, press reset button
and stop auto-execution of existing `bootcmd` pressing any key in serial
terminal and enter the following command:
------------------------->8----------------------
mmc rescan && fatload mmc 0:1 ${loadaddr} u-boot-update.scr && source ${loadaddr}
------------------------->8----------------------
Wait before you see "u-boot update: OK" message.

4. Press RESET button and enjoy updated U-Boot version.

+ 11
- 0
board/synopsys/hsdk/config.mk View File

@@ -0,0 +1,11 @@
# SPDX-License-Identifier: GPL-2.0+
#
# Copyright (C) 2018 Synopsys, Inc. All rights reserved.

bsp-generate: u-boot u-boot.bin
$(Q)python3 $(srctree)/board/$(BOARDDIR)/headerize-hsdk.py \
--arc-id 0x52 --image $(srctree)/u-boot.bin \
--elf $(srctree)/u-boot
$(Q)mkimage -T script -C none -n 'uboot update script' \
-d $(srctree)/u-boot-update.txt \
$(srctree)/u-boot-update.scr &> /dev/null

+ 149
- 0
board/synopsys/hsdk/headerize-hsdk.py View File

@@ -0,0 +1,149 @@
# SPDX-License-Identifier: GPL-2.0+
#
# Copyright (C) 2018 Synopsys, Inc. All rights reserved.
# Author: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>

import os, getopt, sys, zlib
from elftools.elf.elffile import ELFFile


def usage(exit_code):
print("usage:")
print(sys.argv[0] + " --arc-id 0x52 --image u-boot.bin --elf u-boot")
sys.exit(exit_code)


def elf_get_entry(filename):
with open(filename, 'rb') as f:
elffile = ELFFile(f)
return elffile.header['e_entry']


def calc_check_sum(filename):
# u-boot.head check_sum for preloader - it is sum of all u-boot binary bytes
with open(filename, "rb") as file:
ba = bytearray(file.read())
return sum(ba) & 0xFF


def arg_verify(uboot_bin_filename, uboot_elf_filename, arc_id):
if arc_id not in [0x52, 0x53]:
print("unknown ARC ID: " + hex(arc_id))
sys.exit(2)

if not os.path.isfile(uboot_bin_filename):
print("uboot bin file not exists: " + uboot_bin_filename)
sys.exit(2)

if not os.path.isfile(uboot_elf_filename):
print("uboot elf file not exists: " + uboot_elf_filename)
sys.exit(2)


def main():
try:
opts, args = getopt.getopt(sys.argv[1:],
"ha:i:l:e:", ["help", "arc-id=", "image=", "elf="])
except getopt.GetoptError as err:
print(err)
usage(2)

# default filenames
uboot_elf_filename = "u-boot"
uboot_bin_filename = "u-boot.bin"
headerised_filename = "u-boot.head"
uboot_scrypt_file = "u-boot-update.txt"

# initial header values: place where preloader will store u-boot binary,
# should be equal to CONFIG_SYS_TEXT_BASE
image_copy_adr = 0x81000000

# initial constant header values, do not change these values
arc_id = 0x52 # 0x52 for 1st HSDK release (hardcoded in RTL)
magic1 = 0xdeadbeafaf # big endian byte order
flash_address = 0x0
flash_type = 0x0 # 0 - SPI flash, 1 - NOR flash
magic2 = [ # big endian byte order
0x20202a2020202020202020202a20202020207c5c2e20202020202e2f7c20202020207c2d,
0x2e5c2020202f2e2d7c20202020205c2020602d2d2d6020202f20202020202f205f202020,
0x205f20205c20202020207c205f60712070205f207c2020202020272e5f3d2f205c3d5f2e,
0x272020202020202020605c202f60202020202020202020202020206f2020202020202020]

for opt, arg in opts:
if opt in ('-h', "--help"): usage(0)
if opt in ('-a', "--arc-id"): arc_id = int(arg, 16)
if opt in ('-i', "--image"): uboot_bin_filename = arg
if opt in ('-e', "--elf"): uboot_elf_filename = arg

arg_verify(uboot_bin_filename, uboot_elf_filename, arc_id)

uboot_img_size = os.path.getsize(uboot_bin_filename)
jump_address = elf_get_entry(uboot_elf_filename)
check_sum = calc_check_sum(uboot_bin_filename)

# write header to file
with open(headerised_filename, "wb") as file:
file.write(arc_id.to_bytes(2, byteorder='little'))
file.write(uboot_img_size.to_bytes(4, byteorder='little'))
file.write(check_sum.to_bytes(1, byteorder='little'))
file.write(image_copy_adr.to_bytes(4, byteorder='little'))
file.write(magic1.to_bytes(5, byteorder='big'))
file.write(jump_address.to_bytes(4, byteorder='little'))
for i in range(12): file.write(0xFF.to_bytes(1, byteorder='little'))
for byte in magic2: file.write(byte.to_bytes(36, byteorder='big'))
for i in range(208 - len(magic2) * 36):
file.write(0xFF.to_bytes(1, byteorder='little'))
file.write(flash_address.to_bytes(4, byteorder='little'))
for i in range(11): file.write(0xFF.to_bytes(1, byteorder='little'))
file.write(flash_type.to_bytes(1, byteorder='little'))

# append u-boot image to header
with open(headerised_filename, "ab") as fo:
with open(uboot_bin_filename,'rb') as fi:
fo.write(fi.read())

# calc u-boot headerized image CRC32 (will be used by uboot update
# command for check)
headerised_image_crc = ""
with open(headerised_filename, "rb") as fi:
headerised_image_crc = hex(zlib.crc32(fi.read()) & 0xffffffff)

load_addr = 0x81000000
crc_store_adr = load_addr - 0x8
crc_calc_adr = crc_store_adr - 0x4
load_size = os.path.getsize(headerised_filename)
crc_calc_cmd = \
"crc32 " + hex(load_addr) + " " + hex(load_size) + " " + hex(crc_calc_adr)
crc_check_cmd = \
"mw.l " + hex(crc_store_adr) + " " + headerised_image_crc + " && " + \
crc_calc_cmd + " && " + \
"cmp.l " + hex(crc_store_adr) + " " + hex(crc_calc_adr) + " 1"

# make errase size to be allighned by 64K
if load_size & 0xFFFF == 0:
errase_size = load_size
else:
errase_size = load_size - (load_size & 0xFFFF) + 0x10000

# u-bood CMD to load u-bood with header to SPI flash
sf_load_image_cmd = \
"fatload mmc 0:1 " + hex(load_addr) + " " + headerised_filename + " && " + \
"sf probe 0:0 && " + \
crc_check_cmd + " && " + \
"sf protect unlock 0x0 " + hex(errase_size) + " && " + \
"sf erase 0x0 " + hex(errase_size) + " && " + \
"sf write " + hex(load_addr) + " 0x0 " + hex(load_size) + " && " + \
"sf protect lock 0x0 " + hex(errase_size)

update_uboot_cmd = sf_load_image_cmd + " && echo \"u-boot update: OK\""

with open(uboot_scrypt_file, "wb") as fo:
fo.write(update_uboot_cmd.encode('ascii'))


if __name__ == "__main__":
try:
main()
except Exception as err:
print(err)
sys.exit(2)

+ 6
- 0
include/configs/hsdk.h View File

@@ -62,6 +62,12 @@
#define CONFIG_ENV_SIZE SZ_16K

#define CONFIG_EXTRA_ENV_SETTINGS \
"upgrade=if mmc rescan && " \
"fatload mmc 0:1 ${loadaddr} u-boot-update.scr && " \
"iminfo ${loadaddr} && source ${loadaddr}; then; else echo " \
"\"Fail to upgrade.\n" \
"Do you have u-boot-update.scr and u-boot.head on first (FAT) SD card partition?\"" \
"; fi\0" \
"core_dccm_0=0x10\0" \
"core_dccm_1=0x6\0" \
"core_dccm_2=0x10\0" \


Loading…
Cancel
Save