Skip to content

Commit 495f144

Browse files
authored
Merge pull request #1215 from en-sc/en-sc/from_upstream
Merge up to a510d51 from upstream
2 parents 5de7310 + 309c25f commit 495f144

33 files changed

+980
-178
lines changed

.github/workflows/linux-build.yml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,34 @@ jobs:
99
env:
1010
CFLAGS: -m32
1111
CC: clang
12+
PKG_CONFIG_PATH: /opt/libjim32/lib/pkgconfig
1213
steps:
13-
- name: Checkout Code
14-
uses: actions/checkout@v4
1514
- name: Install required packages (apt-get)
1615
run: |
1716
sudo apt-get update
1817
sudo apt-get install clang gcc-multilib
18+
- name: Get 32-bit JIM TCL from cache
19+
id: cache-libjim32
20+
uses: actions/cache@v4
21+
with:
22+
path: /opt/libjim32
23+
key: libjim32
24+
- if: ${{ steps.cache-libjim32.outputs.cache-hit != 'true' }}
25+
name: Checkout JIM TCL
26+
uses: actions/checkout@v4
27+
with:
28+
repository: msteveb/jimtcl
29+
ref: 0.83
30+
path: jimtcl
31+
- if: ${{ steps.cache-libjim32.outputs.cache-hit != 'true' }}
32+
name: Build 32-bit JIM TCL from source
33+
run: |
34+
cd jimtcl
35+
./configure --prefix=/opt/libjim32 --with-ext=json --minimal --disable-ssl
36+
make -j`nproc`
37+
make install
38+
- name: Checkout Code
39+
uses: actions/checkout@v4
1940
- run: ./bootstrap
2041
- run: ./configure --enable-remote-bitbang --enable-jtag_vpi --disable-target64
2142
- run: make -j`nproc`
@@ -39,7 +60,7 @@ jobs:
3960
- name: Install required packages (apt-get)
4061
run: |
4162
sudo apt-get update
42-
sudo apt-get install libusb-1.0-0 libusb-1.0-0-dev
63+
sudo apt-get install libusb-1.0-0 libusb-1.0-0-dev libjim-dev
4364
- run: ./bootstrap
4465
- run: ./configure --enable-remote-bitbang --enable-jtag_vpi --enable-ftdi-cjtag --prefix /tmp/${{ env.NAME }}
4566
- run: make -j`nproc`

.github/workflows/spike-openocd-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- name: Install packages
3434
run: |
3535
sudo apt-get update
36-
sudo apt-get install -y device-tree-compiler build-essential
36+
sudo apt-get install -y device-tree-compiler build-essential libjim-dev
3737
3838
- name: Get revisions of dependencies
3939
run: |

bootstrap

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,21 @@ else
1515
exit 1
1616
fi
1717

18-
SKIP_SUBMODULE=0
18+
WITH_SUBMODULES=0
1919

2020
case "$#" in
2121
0) ;;
22-
1) if [ "$1" = "nosubmodule" ]; then
23-
SKIP_SUBMODULE=1
24-
else
22+
1) if [ "$1" = "with-submodules" ]; then
23+
WITH_SUBMODULES=1
24+
elif [ "$1" = "nosubmodule" ]; then
25+
WITH_SUBMODULES=0
26+
elif [ -n "$1" ]; then
2527
echo "$0: Illegal argument $1" >&2
26-
echo "USAGE: $0 [nosubmodule]" >&2
28+
echo "USAGE: $0 [with-submodules]" >&2
2729
exit 1
2830
fi;;
2931
*) echo "$0: Wrong number of command-line arguments." >&2
30-
echo "USAGE: $0 [nosubmodule]" >&2
32+
echo "USAGE: $0 [with-submodules]" >&2
3133
exit 1;;
3234
esac
3335

@@ -42,12 +44,12 @@ autoheader --warnings=all
4244
automake --warnings=all --gnu --add-missing --copy
4345
)
4446

45-
if [ "$SKIP_SUBMODULE" -ne 0 ]; then
46-
echo "Skipping submodule setup"
47-
else
47+
if [ "$WITH_SUBMODULES" -ne 0 ]; then
4848
echo "Setting up submodules"
4949
git submodule sync
5050
git submodule update --init
51+
else
52+
echo "Skipping submodule setup"
5153
fi
5254

5355
if [ -x src/jtag/drivers/libjaylink/autogen.sh ]; then

configure.ac

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,16 @@ AC_SEARCH_LIBS([openpty], [util])
5252

5353
AC_CHECK_HEADERS([sys/socket.h])
5454
AC_CHECK_HEADERS([elf.h])
55-
AC_EGREP_HEADER(Elf64_Ehdr, [elf.h], [
56-
AC_DEFINE([HAVE_ELF64], [1], [Define to 1 if the system has the type `Elf64_Ehdr'.])
57-
])
55+
56+
AC_CHECK_TYPE([Elf64_Ehdr],
57+
AC_DEFINE([HAVE_ELF64], [1], [Define to 1 if the system has the type 'Elf64_Ehdr'.]),
58+
[], [[#include <elf.h>]])
59+
60+
AC_MSG_CHECKING([for glibc])
61+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <features.h>]], [[int v = __GLIBC__;return 0;]])],
62+
[have_glibc=yes], [have_glibc=no])
63+
AC_MSG_RESULT($have_glibc)
64+
5865
AC_CHECK_HEADERS([fcntl.h])
5966
AC_CHECK_HEADERS([malloc.h])
6067
AC_CHECK_HEADERS([netdb.h])
@@ -164,6 +171,9 @@ m4_define([PCIE_ADAPTERS],
164171
m4_define([SERIAL_PORT_ADAPTERS],
165172
[[[buspirate], [Bus Pirate], [BUS_PIRATE]]])
166173

174+
m4_define([LINUXSPIDEV_ADAPTER],
175+
[[[linuxspidev], [Linux spidev driver], [LINUXSPIDEV]]])
176+
167177
# The word 'Adapter' in "Dummy Adapter" below must begin with a capital letter
168178
# because there is an M4 macro called 'adapter'.
169179
m4_define([DUMMY_ADAPTER],
@@ -258,7 +268,7 @@ AC_ARG_ENABLE([malloc_logging],
258268

259269
AC_MSG_CHECKING([whether to enable malloc free space logging]);
260270
AC_MSG_RESULT([$debug_malloc])
261-
AS_IF([test "x$debug_malloc" = "xyes"], [
271+
AS_IF([test "x$debug_malloc" = "xyes" -a "x$have_glibc" = "xyes"], [
262272
AC_DEFINE([_DEBUG_FREE_SPACE_],[1], [Include malloc free space in logging])
263273
])
264274

@@ -290,6 +300,7 @@ AC_ARG_ADAPTERS([
290300
LIBFTDI_ADAPTERS,
291301
LIBFTDI_USB1_ADAPTERS,
292302
LIBGPIOD_ADAPTERS,
303+
LINUXSPIDEV_ADAPTER,
293304
SERIAL_PORT_ADAPTERS,
294305
DUMMY_ADAPTER,
295306
PCIE_ADAPTERS,
@@ -389,8 +400,8 @@ AS_CASE([$host_os],
389400
])
390401

391402
AC_ARG_ENABLE([internal-jimtcl],
392-
AS_HELP_STRING([--disable-internal-jimtcl], [Disable building internal jimtcl]),
393-
[use_internal_jimtcl=$enableval], [use_internal_jimtcl=yes])
403+
AS_HELP_STRING([--enable-internal-jimtcl], [Enable building internal jimtcl (deprecated)]),
404+
[use_internal_jimtcl=$enableval], [use_internal_jimtcl=no])
394405

395406
AC_ARG_ENABLE([jimtcl-maintainer],
396407
AS_HELP_STRING([--enable-jimtcl-maintainer], [Enable maintainer mode when building internal jimtcl]),
@@ -727,6 +738,7 @@ PROCESS_ADAPTERS([LIBJAYLINK_ADAPTERS], ["x$use_internal_libjaylink" = "xyes" -o
727738
PROCESS_ADAPTERS([PCIE_ADAPTERS], ["x$is_linux" = "xyes"], [Linux build])
728739
PROCESS_ADAPTERS([SERIAL_PORT_ADAPTERS], ["x$can_build_buspirate" = "xyes"],
729740
[internal error: validation should happen beforehand])
741+
PROCESS_ADAPTERS([LINUXSPIDEV_ADAPTER], ["x$is_linux" = "xyes"], [Linux spidev])
730742
PROCESS_ADAPTERS([DUMMY_ADAPTER], [true], [unused])
731743

732744
AS_IF([test "x$enable_linuxgpiod" != "xno"], [
@@ -867,6 +879,10 @@ AS_IF([test "x$enable_jlink" != "xno"], [
867879
]])
868880
)
869881
882+
AS_IF([test "x$use_internal_jimtcl" = "xyes"], [
883+
AC_MSG_WARN([Using the internal jimtcl is deprecated and will not be possible in the future.])
884+
])
885+
870886
echo
871887
echo
872888
echo OpenOCD configuration summary
@@ -876,6 +892,7 @@ m4_foreach([adapter], [USB1_ADAPTERS,
876892
LIBFTDI_USB1_ADAPTERS,
877893
LIBGPIOD_ADAPTERS,
878894
LIBJAYLINK_ADAPTERS, PCIE_ADAPTERS, SERIAL_PORT_ADAPTERS,
895+
LINUXSPIDEV_ADAPTER,
879896
DUMMY_ADAPTER,
880897
OPTIONAL_LIBRARIES,
881898
COVERAGE],

doc/openocd.texi

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,9 @@ emulation model of target hardware.
614614
@item @b{xlnx_pcie_xvc}
615615
@* A JTAG driver exposing Xilinx Virtual Cable over PCI Express to OpenOCD as JTAG/SWD interface.
616616

617+
@item @b{linuxspidev}
618+
@* A SPI based SWD driver using Linux SPI devices.
619+
617620
@item @b{linuxgpiod}
618621
@* A bitbang JTAG driver using Linux GPIO through library libgpiod.
619622

@@ -3430,6 +3433,70 @@ See @file{interface/beaglebone-swd-native.cfg} for a sample configuration file.
34303433

34313434
@end deffn
34323435

3436+
@deffn {Interface Driver} {linuxspidev}
3437+
Linux provides userspace access to SPI through spidev. Full duplex SPI
3438+
transactions are used to simultaneously read and write to/from the target to
3439+
emulate the SWD transport.
3440+
3441+
@deffn {Config Command} {spidev path} path
3442+
Specifies the path to the spidev device.
3443+
@end deffn
3444+
3445+
@deffn {Config Command} {spidev mode} value
3446+
Set the mode of the spi port with optional bit flags (default=3).
3447+
See /usr/include/linux/spi/spidev.h for all of the SPI mode options.
3448+
@end deffn
3449+
3450+
@deffn {Config Command} {spidev queue_entries} value
3451+
Set the maximum number of queued transactions per spi exchange (default=64).
3452+
More queued transactions may offer greater performance when the target doesn't
3453+
need to wait. On the contrary higher numbers will reduce performance when the
3454+
target requests a wait as all queued transactions will need to be exchanged
3455+
before spidev can see the wait request.
3456+
@end deffn
3457+
3458+
See @file{tcl/interface/spidev_example.cfg} for a sample configuration file.
3459+
3460+
Electrical connections:
3461+
@example
3462+
+--------------+ +--------------+
3463+
| | 1K | |
3464+
| MOSI|---/\/\/\---+ | |
3465+
| Host | | | Target |
3466+
| MISO|------------+---|SWDIO |
3467+
| | | |
3468+
| SCK|----------------|SWDCLK |
3469+
| | | |
3470+
+--------------+ +--------------+
3471+
@end example
3472+
3473+
The 1K resistor works well with most MCUs up to 3 MHz. A lower resistance
3474+
could be used to achieve higher speeds granted that the target SWDIO pin has
3475+
enough drive strength to pull the signal high while being pulled low by this
3476+
resistor.
3477+
3478+
If you are having trouble here are some tips:
3479+
3480+
@itemize @bullet
3481+
3482+
@item @b{Make sure MISO and MOSI are tied together with a 1K resistor.}
3483+
MISO should be attached to the target.
3484+
3485+
@item @b{Make sure that your host and target are using the same I/O voltage}
3486+
(for example both are using 3.3 volts).
3487+
3488+
@item @b{Your host's SPI port may not idle low.}
3489+
This will lead to an additional clock edge being sent to the target, causing
3490+
the host and target being 1 clock off from each other. Try setting
3491+
SPI_MOSI_IDLE_LOW in spi_mode. Try using a different spi_mode (0 - 3).
3492+
3493+
@item @b{Your target may pull SWDIO and/or SWDCLK high.}
3494+
This will create an extra edge when the host releases control of the SPI port
3495+
at the end of a transaction. You'll need to confirm this with a scope or meter.
3496+
Try installing 10K resistors on SWDIO and SWDCLK to ground to stop this.
3497+
3498+
@end itemize
3499+
@end deffn
34333500

34343501
@deffn {Interface Driver} {linuxgpiod}
34353502
Linux provides userspace access to GPIO through libgpiod since Linux kernel

src/flash/nor/fespi.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -751,9 +751,9 @@ static int fespi_probe(struct flash_bank *bank)
751751
target_device->name, bank->base);
752752

753753
} else {
754-
LOG_DEBUG("Assuming FESPI as specified at address " TARGET_ADDR_FMT
755-
" with ctrl at " TARGET_ADDR_FMT, fespi_info->ctrl_base,
756-
bank->base);
754+
LOG_DEBUG("Assuming FESPI as specified at address " TARGET_ADDR_FMT
755+
" with ctrl at " TARGET_ADDR_FMT, fespi_info->ctrl_base,
756+
bank->base);
757757
}
758758

759759
/* read and decode flash ID; returns in SW mode */

src/flash/nor/kinetis.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,22 @@ static int kinetis_fill_fcf(struct flash_bank *bank, uint8_t *fcf)
14891489

14901490
kinetis_auto_probe(bank_iter);
14911491

1492-
assert(bank_iter->prot_blocks);
1492+
if (bank_iter->num_prot_blocks == 0) {
1493+
if (k_bank->flash_class == FC_PFLASH) {
1494+
LOG_ERROR("BUG: PFLASH bank %u has no protection blocks",
1495+
bank_idx);
1496+
} else {
1497+
LOG_DEBUG("skipping FLEX_NVM bank %u with no prot blocks (EE bkp only)",
1498+
bank_idx);
1499+
}
1500+
continue;
1501+
}
1502+
1503+
if (!bank_iter->prot_blocks) {
1504+
LOG_ERROR("BUG: bank %u has NULL protection blocks array",
1505+
bank_idx);
1506+
continue;
1507+
}
14931508

14941509
if (k_bank->flash_class == FC_PFLASH) {
14951510
for (unsigned int i = 0; i < bank_iter->num_prot_blocks; i++) {

src/flash/nor/kinetis_ke.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ static int kinetis_ke_write(struct flash_bank *bank, const uint8_t *buffer,
10051005

10061006
result = kinetis_ke_stop_watchdog(bank->target);
10071007
if (result != ERROR_OK)
1008-
return result;
1008+
return result;
10091009

10101010
result = kinetis_ke_prepare_flash(bank);
10111011
if (result != ERROR_OK)

src/flash/nor/niietcm4.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ static int niietcm4_uflash_page_erase(struct flash_bank *bank, int page_num, int
311311
/* status check */
312312
retval = niietcm4_uopstatus_check(bank);
313313
if (retval != ERROR_OK)
314-
return retval;
314+
return retval;
315315

316316
return retval;
317317
}
@@ -394,7 +394,7 @@ COMMAND_HANDLER(niietcm4_handle_uflash_read_byte_command)
394394
uint32_t uflash_data;
395395

396396
if (strcmp("info", CMD_ARGV[0]) == 0)
397-
uflash_cmd = UFMC_MAGIC_KEY | UFMC_READ_IFB;
397+
uflash_cmd = UFMC_MAGIC_KEY | UFMC_READ_IFB;
398398
else if (strcmp("main", CMD_ARGV[0]) == 0)
399399
uflash_cmd = UFMC_MAGIC_KEY | UFMC_READ;
400400
else
@@ -539,7 +539,7 @@ COMMAND_HANDLER(niietcm4_handle_uflash_erase_command)
539539
int mem_type;
540540

541541
if (strcmp("info", CMD_ARGV[0]) == 0)
542-
mem_type = 1;
542+
mem_type = 1;
543543
else if (strcmp("main", CMD_ARGV[0]) == 0)
544544
mem_type = 0;
545545
else

src/flash/nor/psoc4.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -384,15 +384,15 @@ static int psoc4_get_silicon_id(struct flash_bank *bank, uint32_t *silicon_id, u
384384
* bit 7..0 family ID (lowest 8 bits)
385385
*/
386386
if (silicon_id)
387-
*silicon_id = ((part0 & 0x0000ffff) << 16)
388-
| ((part0 & 0x00ff0000) >> 8)
389-
| (part1 & 0x000000ff);
387+
*silicon_id = ((part0 & 0x0000ffff) << 16)
388+
| ((part0 & 0x00ff0000) >> 8)
389+
| (part1 & 0x000000ff);
390390

391391
if (family_id)
392-
*family_id = part1 & 0x0fff;
392+
*family_id = part1 & 0x0fff;
393393

394394
if (protection)
395-
*protection = (part1 >> 12) & 0x0f;
395+
*protection = (part1 >> 12) & 0x0f;
396396

397397
return ERROR_OK;
398398
}

0 commit comments

Comments
 (0)