Merge branch 'master' into from_upstream_histogram

Used histogram diff strategy, which was much better than the default.

Conflicts:
	doc/openocd.texi
	src/flash/nor/fespi.c
	src/jtag/drivers/libjaylink
	src/rtos/rtos.c
	src/target/riscv/batch.c
	src/target/riscv/encoding.h
	src/target/riscv/riscv-011.c
	src/target/riscv/riscv-013.c
	src/target/riscv/riscv.c
	src/target/riscv/riscv.h
	src/target/target.c
	tcl/target/gd32vf103.cfg

Change-Id: I1321f62ba719419e58f93b2195f2540bd62f50d2
This commit is contained in:
Tim Newsome 2020-10-15 12:32:45 -07:00
commit 7a933ea7ad
320 changed files with 8409 additions and 4844 deletions

92
.github/workflows/snapshot.yml vendored Normal file
View File

@ -0,0 +1,92 @@
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2020 by Tarek BOUCHKATI <tarek.bouchkati@gmail.com>
on: push
name: OpenOCD Snapshot
jobs:
package:
runs-on: [ubuntu-18.04]
env:
DL_DIR: ../downloads
BUILD_DIR: ../build
steps:
- name: Install needed packages
run: sudo apt-get install autotools-dev autoconf automake libtool pkg-config cmake texinfo texlive g++-mingw-w64-i686
- uses: actions/checkout@v1
- run: ./bootstrap
- name: Prepare libusb1
env:
LIBUSB1_VER: 1.0.23
run: |
mkdir -p $DL_DIR && cd $DL_DIR
wget "https://github.com/libusb/libusb/releases/download/v${LIBUSB1_VER}/libusb-${LIBUSB1_VER}.tar.bz2"
tar -xjf libusb-${LIBUSB1_VER}.tar.bz2
echo "::set-env name=LIBUSB1_SRC::$PWD/libusb-${LIBUSB1_VER}"
- name: Prepare hidapi
env:
HIDAPI_VER: 0.9.0
run: |
mkdir -p $DL_DIR && cd $DL_DIR
wget "https://github.com/libusb/hidapi/archive/hidapi-${HIDAPI_VER}.tar.gz"
tar -xzf hidapi-${HIDAPI_VER}.tar.gz
cd hidapi-hidapi-${HIDAPI_VER}
./bootstrap
echo "::set-env name=HIDAPI_SRC::$PWD"
- name: Prepare libftdi
env:
LIBFTDI_VER: 1.4
run: |
mkdir -p $DL_DIR && cd $DL_DIR
wget "http://www.intra2net.com/en/developer/libftdi/download/libftdi1-${LIBFTDI_VER}.tar.bz2"
tar -xjf libftdi1-${LIBFTDI_VER}.tar.bz2
echo "::set-env name=LIBFTDI_SRC::$PWD/libftdi1-${LIBFTDI_VER}"
- name: Package OpenOCD for windows
env:
MAKE_JOBS: 2
HOST: i686-w64-mingw32
LIBUSB1_CONFIG: --enable-shared --enable-static
HIDAPI_CONFIG: --enable-shared --disable-static --disable-testgui
LIBFTDI_CONFIG: "-DCMAKE_TOOLCHAIN_FILE='${{ env.LIBFTDI_SRC }}/cmake/Toolchain-i686-w64-mingw32.cmake' -DBUILD_TESTS:BOOL=off -DFTDIPP:BOOL=off -DPYTHON_BINDINGS:BOOL=off -DEXAMPLES:BOOL=off -DDOCUMENTATION:BOOL=off -DFTDI_EEPROM:BOOL=off"
run: |
# set snapshot tag
OPENOCD_TAG="`git tag --points-at HEAD`"
[ -z $OPENOCD_TAG ] && OPENOCD_TAG="`git rev-parse --short HEAD`"
# set env and call cross-build.sh
export OPENOCD_TAG=$OPENOCD_TAG
export OPENOCD_SRC=$PWD
export OPENOCD_CONFIG=""
mkdir -p $BUILD_DIR && cd $BUILD_DIR
bash $OPENOCD_SRC/contrib/cross-build.sh $HOST
# add missing dlls
cd $HOST-root/usr
cp `$HOST-gcc --print-file-name=libwinpthread-1.dll` ./bin/
cp `$HOST-gcc --print-file-name=libgcc_s_sjlj-1.dll` ./bin/
# prepare the artifact
ARTIFACT="openocd-${OPENOCD_TAG}-${HOST}.tar.gz"
tar -czf $ARTIFACT *
echo "::set-env name=ARTIFACT_NAME::$ARTIFACT"
echo "::set-env name=ARTIFACT_PATH::$PWD/$ARTIFACT"
- name: Publish OpenOCD packaged for windows
uses: actions/upload-artifact@v1
with:
name: ${{ env.ARTIFACT_NAME }}
path: ${{ env.ARTIFACT_PATH }}
- name: Get the upload URL for a release
id: get_release
if: startsWith(github.ref, 'refs/tags/')
uses: bruceadams/get-release@v1.2.0
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Release OpenOCD packaged for windows
if: startsWith(github.ref, 'refs/tags/')
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.get_release.outputs.upload_url }}
asset_path: ${{ env.ARTIFACT_PATH }}
asset_name: ${{ env.ARTIFACT_NAME }}
asset_content_type: application/gzip

6
README
View File

@ -284,11 +284,15 @@ libraries that OpenOCD depends on. Alternatively, you can specify
*_CFLAGS and *_LIBS environment variables directly, see "./configure *_CFLAGS and *_LIBS environment variables directly, see "./configure
--help" for the details. --help" for the details.
For a more or less complete script that does all this for you, see
contrib/cross-build.sh
Parallel Port Dongles Parallel Port Dongles
--------------------- ---------------------
If you want to access the parallel port using the PPDEV interface you If you want to access the parallel port using the PPDEV interface you
have to specify both --enable-parport AND --enable-parport-ppdev, since the have to specify both --enable-parport AND --enable-parport-ppdev, since
the later option is an option to the parport driver. the later option is an option to the parport driver.
The same is true for the --enable-parport-giveio option, you have to The same is true for the --enable-parport-giveio option, you have to

View File

@ -24,11 +24,12 @@ fi
# bootstrap the autotools # bootstrap the autotools
( (
set -x set -x
aclocal aclocal --warnings=all
# Apparently, not all versions of libtoolize support option --warnings=all .
${libtoolize} --automake --copy ${libtoolize} --automake --copy
autoconf autoconf --warnings=all
autoheader autoheader --warnings=all
automake --gnu --add-missing --copy automake --warnings=all --gnu --add-missing --copy
) )
if [ -n "$SKIP_SUBMODULE" ]; then if [ -n "$SKIP_SUBMODULE" ]; then

View File

@ -22,7 +22,7 @@ AH_BOTTOM([
#include <helper/replacements.h> #include <helper/replacements.h>
]) ])
AC_LANG_C AC_LANG([C])
AC_PROG_CC AC_PROG_CC
AC_PROG_CC_C99 AC_PROG_CC_C99
AM_PROG_CC_C_O AM_PROG_CC_C_O
@ -34,7 +34,7 @@ m4_defun([_LT_AC_LANG_CXX_CONFIG], [:])
m4_defun([_LT_AC_LANG_F77_CONFIG], [:]) m4_defun([_LT_AC_LANG_F77_CONFIG], [:])
m4_defun([_LT_AC_LANG_GCJ_CONFIG], [:]) m4_defun([_LT_AC_LANG_GCJ_CONFIG], [:])
AC_DISABLE_SHARED AC_DISABLE_SHARED
AC_PROG_LIBTOOL LT_INIT
AC_SUBST([LIBTOOL_DEPS]) AC_SUBST([LIBTOOL_DEPS])
dnl configure checks required for Jim files (these are obsolete w/ C99) dnl configure checks required for Jim files (these are obsolete w/ C99)
@ -128,7 +128,8 @@ m4_define([USB0_ADAPTERS],
[[armjtagew], [Olimex ARM-JTAG-EW Programmer], [ARMJTAGEW]]]) [[armjtagew], [Olimex ARM-JTAG-EW Programmer], [ARMJTAGEW]]])
m4_define([HIDAPI_ADAPTERS], m4_define([HIDAPI_ADAPTERS],
[[[cmsis_dap], [CMSIS-DAP Compliant Debugger], [CMSIS_DAP]]]) [[[cmsis_dap], [CMSIS-DAP Compliant Debugger], [CMSIS_DAP]],
[[nulink], [Nu-Link Programmer], [HLADAPTER_NULINK]]])
m4_define([HIDAPI_USB1_ADAPTERS], m4_define([HIDAPI_USB1_ADAPTERS],
[[[kitprog], [Cypress KitProg Programmer], [KITPROG]]]) [[[kitprog], [Cypress KitProg Programmer], [KITPROG]]])
@ -138,6 +139,9 @@ m4_define([LIBFTDI_ADAPTERS],
[[presto], [ASIX Presto Adapter], [PRESTO]], [[presto], [ASIX Presto Adapter], [PRESTO]],
[[openjtag], [OpenJTAG Adapter], [OPENJTAG]]]) [[openjtag], [OpenJTAG Adapter], [OPENJTAG]]])
m4_define([LIBGPIOD_ADAPTERS],
[[[linuxgpiod], [Linux GPIO bitbang through libgpiod], [LINUXGPIOD]]])
m4_define([LIBJAYLINK_ADAPTERS], m4_define([LIBJAYLINK_ADAPTERS],
[[[jlink], [SEGGER J-Link Programmer], [JLINK]]]) [[[jlink], [SEGGER J-Link Programmer], [JLINK]]])
@ -242,6 +246,7 @@ AC_ARG_ADAPTERS([
HIDAPI_ADAPTERS, HIDAPI_ADAPTERS,
HIDAPI_USB1_ADAPTERS, HIDAPI_USB1_ADAPTERS,
LIBFTDI_ADAPTERS, LIBFTDI_ADAPTERS,
LIBGPIOD_ADAPTERS,
LIBJAYLINK_ADAPTERS LIBJAYLINK_ADAPTERS
],[auto]) ],[auto])
@ -263,6 +268,10 @@ AC_ARG_ENABLE([jtag_vpi],
AS_HELP_STRING([--enable-jtag_vpi], [Enable building support for JTAG VPI]), AS_HELP_STRING([--enable-jtag_vpi], [Enable building support for JTAG VPI]),
[build_jtag_vpi=$enableval], [build_jtag_vpi=no]) [build_jtag_vpi=$enableval], [build_jtag_vpi=no])
AC_ARG_ENABLE([jtag_dpi],
AS_HELP_STRING([--enable-jtag_dpi], [Enable building support for JTAG DPI]),
[build_jtag_dpi=$enableval], [build_jtag_dpi=no])
AC_ARG_ENABLE([amtjtagaccel], AC_ARG_ENABLE([amtjtagaccel],
AS_HELP_STRING([--enable-amtjtagaccel], [Enable building the Amontec JTAG-Accelerator driver]), AS_HELP_STRING([--enable-amtjtagaccel], [Enable building the Amontec JTAG-Accelerator driver]),
[build_amtjtagaccel=$enableval], [build_amtjtagaccel=no]) [build_amtjtagaccel=$enableval], [build_amtjtagaccel=no])
@ -336,6 +345,10 @@ AS_CASE([$host_os],
AC_MSG_ERROR([sysfsgpio is only available on linux]) AC_MSG_ERROR([sysfsgpio is only available on linux])
]) ])
AS_IF([test "x$enable_linuxgpiod" = "xyes"], [
AC_MSG_ERROR([linuxgpiod is only available on linux])
])
AS_IF([test "x$build_xlnx_pcie_xvc" = "xyes"], [ AS_IF([test "x$build_xlnx_pcie_xvc" = "xyes"], [
AC_MSG_ERROR([xlnx_pcie_xvc is only available on linux]) AC_MSG_ERROR([xlnx_pcie_xvc is only available on linux])
]) ])
@ -561,6 +574,13 @@ AS_IF([test "x$build_jtag_vpi" = "xyes"], [
AC_DEFINE([BUILD_JTAG_VPI], [0], [0 if you don't want JTAG VPI.]) AC_DEFINE([BUILD_JTAG_VPI], [0], [0 if you don't want JTAG VPI.])
]) ])
AS_IF([test "x$build_jtag_dpi" = "xyes"], [
AC_DEFINE([BUILD_JTAG_DPI], [1], [1 if you want JTAG DPI.])
], [
AC_DEFINE([BUILD_JTAG_DPI], [0], [0 if you don't want JTAG DPI.])
])
AS_IF([test "x$build_amtjtagaccel" = "xyes"], [ AS_IF([test "x$build_amtjtagaccel" = "xyes"], [
AC_DEFINE([BUILD_AMTJTAGACCEL], [1], [1 if you want the Amontec JTAG-Accelerator driver.]) AC_DEFINE([BUILD_AMTJTAGACCEL], [1], [1 if you want the Amontec JTAG-Accelerator driver.])
], [ ], [
@ -631,6 +651,15 @@ PKG_CHECK_MODULES([LIBUSB1], [libusb-1.0], [
PKG_CHECK_MODULES([LIBUSB0], [libusb], [use_libusb0=yes], [use_libusb0=no]) PKG_CHECK_MODULES([LIBUSB0], [libusb], [use_libusb0=yes], [use_libusb0=no])
PKG_CHECK_MODULES([CAPSTONE], [capstone], [have_capstone=yes],
[have_capstone=no])
AS_IF([test "x$have_capstone" = "xyes"], [
AC_DEFINE([HAVE_CAPSTONE], [1], [1 if you have captone disassembly framework.])
], [
AC_DEFINE([HAVE_CAPSTONE], [0], [0 if you don't have captone disassembly framework.])
])
for hidapi_lib in hidapi hidapi-hidraw hidapi-libusb; do for hidapi_lib in hidapi hidapi-hidraw hidapi-libusb; do
PKG_CHECK_MODULES([HIDAPI],[$hidapi_lib],[ PKG_CHECK_MODULES([HIDAPI],[$hidapi_lib],[
use_hidapi=yes use_hidapi=yes
@ -644,6 +673,8 @@ PKG_CHECK_MODULES([LIBFTDI], [libftdi1], [use_libftdi=yes], [
PKG_CHECK_MODULES([LIBFTDI], [libftdi], [use_libftdi=yes], [use_libftdi=no]) PKG_CHECK_MODULES([LIBFTDI], [libftdi], [use_libftdi=yes], [use_libftdi=no])
]) ])
PKG_CHECK_MODULES([LIBGPIOD], [libgpiod], [use_libgpiod=yes], [use_libgpiod=no])
PKG_CHECK_MODULES([LIBJAYLINK], [libjaylink >= 0.2], PKG_CHECK_MODULES([LIBJAYLINK], [libjaylink >= 0.2],
[use_libjaylink=yes], [use_libjaylink=no]) [use_libjaylink=yes], [use_libjaylink=no])
@ -673,6 +704,7 @@ PROCESS_ADAPTERS([USB0_ADAPTERS], ["x$use_libusb0" = "xyes"], [libusb-0.1])
PROCESS_ADAPTERS([HIDAPI_ADAPTERS], ["x$use_hidapi" = "xyes"], [hidapi]) PROCESS_ADAPTERS([HIDAPI_ADAPTERS], ["x$use_hidapi" = "xyes"], [hidapi])
PROCESS_ADAPTERS([HIDAPI_USB1_ADAPTERS], ["x$use_hidapi" = "xyes" -a "x$use_libusb1" = "xyes"], [hidapi and libusb-1.x]) PROCESS_ADAPTERS([HIDAPI_USB1_ADAPTERS], ["x$use_hidapi" = "xyes" -a "x$use_libusb1" = "xyes"], [hidapi and libusb-1.x])
PROCESS_ADAPTERS([LIBFTDI_ADAPTERS], ["x$use_libftdi" = "xyes"], [libftdi]) PROCESS_ADAPTERS([LIBFTDI_ADAPTERS], ["x$use_libftdi" = "xyes"], [libftdi])
PROCESS_ADAPTERS([LIBGPIOD_ADAPTERS], ["x$use_libgpiod" = "xyes"], [libgpiod])
PROCESS_ADAPTERS([LIBJAYLINK_ADAPTERS], ["x$use_internal_libjaylink" = "xyes" -o "x$use_libjaylink" = "xyes"], [libjaylink-0.2]) PROCESS_ADAPTERS([LIBJAYLINK_ADAPTERS], ["x$use_internal_libjaylink" = "xyes" -o "x$use_libjaylink" = "xyes"], [libjaylink-0.2])
AS_IF([test "x$build_openjtag" = "xyes"], [ AS_IF([test "x$build_openjtag" = "xyes"], [
@ -682,12 +714,20 @@ AS_IF([test "x$build_openjtag" = "xyes"], [
]) ])
]) ])
AS_IF([test "x$enable_stlink" != "xno" -o "x$enable_ti_icdi" != "xno"], [ AS_IF([test "x$enable_linuxgpiod" != "xno"], [
build_bitbang=yes
])
AS_IF([test "x$enable_stlink" != "xno" -o "x$enable_ti_icdi" != "xno" -o "x$enable_nulink" != "xno"], [
AC_DEFINE([BUILD_HLADAPTER], [1], [1 if you want the High Level JTAG driver.]) AC_DEFINE([BUILD_HLADAPTER], [1], [1 if you want the High Level JTAG driver.])
AM_CONDITIONAL([HLADAPTER], [true])
], [ ], [
AC_DEFINE([BUILD_HLADAPTER], [0], [0 if you want the High Level JTAG driver.]) AC_DEFINE([BUILD_HLADAPTER], [0], [0 if you want the High Level JTAG driver.])
AM_CONDITIONAL([HLADAPTER], [false])
]) ])
AM_CONDITIONAL([HLADAPTER], [test "x$enable_stlink" != "xno" -o "x$enable_ti_icdi" != "xno"]) AM_CONDITIONAL([HLADAPTER_STLINK], [test "x$enable_stlink" != "xno"])
AM_CONDITIONAL([HLADAPTER_ICDI], [test "x$enable_ti_icdi" != "xno"])
AM_CONDITIONAL([HLADAPTER_NULINK], [test "x$enable_nulink" != "xno"])
AS_IF([test "x$enable_jlink" != "xno"], [ AS_IF([test "x$enable_jlink" != "xno"], [
AS_IF([test "x$use_internal_libjaylink" = "xyes"], [ AS_IF([test "x$use_internal_libjaylink" = "xyes"], [
@ -718,6 +758,7 @@ AM_CONDITIONAL([BCM2835GPIO], [test "x$build_bcm2835gpio" = "xyes"])
AM_CONDITIONAL([IMX_GPIO], [test "x$build_imx_gpio" = "xyes"]) AM_CONDITIONAL([IMX_GPIO], [test "x$build_imx_gpio" = "xyes"])
AM_CONDITIONAL([BITBANG], [test "x$build_bitbang" = "xyes"]) AM_CONDITIONAL([BITBANG], [test "x$build_bitbang" = "xyes"])
AM_CONDITIONAL([JTAG_VPI], [test "x$build_jtag_vpi" = "xyes" -o "x$build_jtag_vpi" = "xyes"]) AM_CONDITIONAL([JTAG_VPI], [test "x$build_jtag_vpi" = "xyes" -o "x$build_jtag_vpi" = "xyes"])
AM_CONDITIONAL([JTAG_DPI], [test "x$build_jtag_dpi" = "xyes" -o "x$build_jtag_dpi" = "xyes"])
AM_CONDITIONAL([USB_BLASTER_DRIVER], [test "x$enable_usb_blaster" != "xno" -o "x$enable_usb_blaster_2" != "xno"]) AM_CONDITIONAL([USB_BLASTER_DRIVER], [test "x$enable_usb_blaster" != "xno" -o "x$enable_usb_blaster_2" != "xno"])
AM_CONDITIONAL([AMTJTAGACCEL], [test "x$build_amtjtagaccel" = "xyes"]) AM_CONDITIONAL([AMTJTAGACCEL], [test "x$build_amtjtagaccel" = "xyes"])
AM_CONDITIONAL([GW16012], [test "x$build_gw16012" = "xyes"]) AM_CONDITIONAL([GW16012], [test "x$build_gw16012" = "xyes"])
@ -734,9 +775,11 @@ AM_CONDITIONAL([IS_WIN32], [test "x$is_win32" = "xyes"])
AM_CONDITIONAL([IS_DARWIN], [test "x$is_darwin" = "xyes"]) AM_CONDITIONAL([IS_DARWIN], [test "x$is_darwin" = "xyes"])
AM_CONDITIONAL([BITQ], [test "x$build_bitq" = "xyes"]) AM_CONDITIONAL([BITQ], [test "x$build_bitq" = "xyes"])
AM_CONDITIONAL([USE_LIBFTDI], [test "x$use_libftdi" = "xyes"]) AM_CONDITIONAL([USE_LIBFTDI], [test "x$use_libftdi" = "xyes"])
AM_CONDITIONAL([USE_LIBGPIOD], [test "x$use_libgpiod" = "xyes"])
AM_CONDITIONAL([USE_HIDAPI], [test "x$use_hidapi" = "xyes"]) AM_CONDITIONAL([USE_HIDAPI], [test "x$use_hidapi" = "xyes"])
AM_CONDITIONAL([USE_LIBJAYLINK], [test "x$use_libjaylink" = "xyes"]) AM_CONDITIONAL([USE_LIBJAYLINK], [test "x$use_libjaylink" = "xyes"])
AM_CONDITIONAL([RSHIM], [test "x$build_rshim" = "xyes"]) AM_CONDITIONAL([RSHIM], [test "x$build_rshim" = "xyes"])
AM_CONDITIONAL([HAVE_CAPSTONE], [test "x$have_capstone" = "xyes"])
AM_CONDITIONAL([MINIDRIVER], [test "x$build_minidriver" = "xyes"]) AM_CONDITIONAL([MINIDRIVER], [test "x$build_minidriver" = "xyes"])
AM_CONDITIONAL([MINIDRIVER_DUMMY], [test "x$build_minidriver_dummy" = "xyes"]) AM_CONDITIONAL([MINIDRIVER_DUMMY], [test "x$build_minidriver_dummy" = "xyes"])
@ -805,6 +848,7 @@ echo OpenOCD configuration summary
echo -------------------------------------------------- echo --------------------------------------------------
m4_foreach([adapter], [USB1_ADAPTERS, USB0_ADAPTERS, m4_foreach([adapter], [USB1_ADAPTERS, USB0_ADAPTERS,
HIDAPI_ADAPTERS, HIDAPI_USB1_ADAPTERS, LIBFTDI_ADAPTERS, HIDAPI_ADAPTERS, HIDAPI_USB1_ADAPTERS, LIBFTDI_ADAPTERS,
LIBGPIOD_ADAPTERS,
LIBJAYLINK_ADAPTERS, PCIE_ADAPTERS], LIBJAYLINK_ADAPTERS, PCIE_ADAPTERS],
[s=m4_format(["%-40s"], ADAPTER_DESC([adapter])) [s=m4_format(["%-40s"], ADAPTER_DESC([adapter]))
AS_CASE([$ADAPTER_VAR([adapter])], AS_CASE([$ADAPTER_VAR([adapter])],

View File

@ -3,6 +3,9 @@
# with the command "udevadm control --reload" # with the command "udevadm control --reload"
ACTION!="add|change", GOTO="openocd_rules_end" ACTION!="add|change", GOTO="openocd_rules_end"
SUBSYSTEM=="gpio", MODE="0660", GROUP="plugdev", TAG+="uaccess"
SUBSYSTEM!="usb|tty|hidraw", GOTO="openocd_rules_end" SUBSYSTEM!="usb|tty|hidraw", GOTO="openocd_rules_end"
# Please keep this list sorted by VID:PID # Please keep this list sorted by VID:PID
@ -52,6 +55,13 @@ ATTRS{idVendor}=="0403", ATTRS{idProduct}=="c141", MODE="660", GROUP="plugdev",
# Amontec JTAGkey and JTAGkey-tiny # Amontec JTAGkey and JTAGkey-tiny
ATTRS{idVendor}=="0403", ATTRS{idProduct}=="cff8", MODE="660", GROUP="plugdev", TAG+="uaccess" ATTRS{idVendor}=="0403", ATTRS{idProduct}=="cff8", MODE="660", GROUP="plugdev", TAG+="uaccess"
# Nuvoton NuLink
ATTRS{idVendor}=="0416", ATTRS{idProduct}=="511b", MODE="660", GROUP="plugdev", TAG+="uaccess"
ATTRS{idVendor}=="0416", ATTRS{idProduct}=="511c", MODE="660", GROUP="plugdev", TAG+="uaccess"
ATTRS{idVendor}=="0416", ATTRS{idProduct}=="511d", MODE="660", GROUP="plugdev", TAG+="uaccess"
ATTRS{idVendor}=="0416", ATTRS{idProduct}=="5200", MODE="660", GROUP="plugdev", TAG+="uaccess"
ATTRS{idVendor}=="0416", ATTRS{idProduct}=="5201", MODE="660", GROUP="plugdev", TAG+="uaccess"
# TI ICDI # TI ICDI
ATTRS{idVendor}=="0451", ATTRS{idProduct}=="c32a", MODE="660", GROUP="plugdev", TAG+="uaccess" ATTRS{idVendor}=="0451", ATTRS{idProduct}=="c32a", MODE="660", GROUP="plugdev", TAG+="uaccess"

View File

@ -62,7 +62,7 @@ Clearly some of that data would be valuable for interactive debugging.
+In any case, OpenOCD is not currently GUI-oriented. Accordingly, we now +In any case, OpenOCD is not currently GUI-oriented. Accordingly, we now
+expect any such graphics to come from postprocessing. +expect any such graphics to come from postprocessing.
measurments for RTOS event timings should also be easy to collect. measurements for RTOS event timings should also be easy to collect.
+Examples include context and message switch times, as well as times +Examples include context and message switch times, as well as times
for application interactions. for application interactions.
+ +

View File

@ -15,8 +15,8 @@
# #
# This script is probably more useful as a reference than as a complete build # This script is probably more useful as a reference than as a complete build
# tool but for some configurations it may be usable as-is. It only cross- # tool but for some configurations it may be usable as-is. It only cross-
# builds libusb-1.0 from source, but the script can be extended to build other # builds libusb-1.0, hidapi and libftdi from source, but the script can be
# prerequisities in a similar manner. # extended to build other prerequisites in a similar manner.
# #
# Usage: # Usage:
# export LIBUSB1_SRC=/path/to/libusb-1.0 # export LIBUSB1_SRC=/path/to/libusb-1.0
@ -36,17 +36,20 @@ WORK_DIR=$PWD
## Source code paths, customize as necessary ## Source code paths, customize as necessary
: ${OPENOCD_SRC:="`dirname "$0"`/.."} : ${OPENOCD_SRC:="`dirname "$0"`/.."}
: ${LIBUSB1_SRC:=/path/to/libusb} : ${LIBUSB1_SRC:=/path/to/libusb1}
: ${HIDAPI_SRC:=/path/to/hidapi} : ${HIDAPI_SRC:=/path/to/hidapi}
: ${LIBFTDI_SRC:=/path/to/libftdi}
OPENOCD_SRC=`readlink -m $OPENOCD_SRC` OPENOCD_SRC=`readlink -m $OPENOCD_SRC`
LIBUSB1_SRC=`readlink -m $LIBUSB1_SRC` LIBUSB1_SRC=`readlink -m $LIBUSB1_SRC`
HIDAPI_SRC=`readlink -m $HIDAPI_SRC` HIDAPI_SRC=`readlink -m $HIDAPI_SRC`
LIBFTDI_SRC=`readlink -m $LIBFTDI_SRC`
HOST_TRIPLET=$1 HOST_TRIPLET=$1
BUILD_DIR=$WORK_DIR/$HOST_TRIPLET-build BUILD_DIR=$WORK_DIR/$HOST_TRIPLET-build
LIBUSB1_BUILD_DIR=$BUILD_DIR/libusb1 LIBUSB1_BUILD_DIR=$BUILD_DIR/libusb1
HIDAPI_BUILD_DIR=$BUILD_DIR/hidapi HIDAPI_BUILD_DIR=$BUILD_DIR/hidapi
LIBFTDI_BUILD_DIR=$BUILD_DIR/libftdi
OPENOCD_BUILD_DIR=$BUILD_DIR/openocd OPENOCD_BUILD_DIR=$BUILD_DIR/openocd
## Root of host file tree ## Root of host file tree
@ -55,8 +58,12 @@ SYSROOT=$WORK_DIR/$HOST_TRIPLET-root
## Install location within host file tree ## Install location within host file tree
: ${PREFIX=/usr} : ${PREFIX=/usr}
## Make parallel jobs
: ${MAKE_JOBS:=1}
## OpenOCD-only install dir for packaging ## OpenOCD-only install dir for packaging
PACKAGE_DIR=$WORK_DIR/openocd_`git --git-dir=$OPENOCD_SRC/.git describe`_$HOST_TRIPLET : ${OPENOCD_TAG:=`git --git-dir=$OPENOCD_SRC/.git describe --tags`}
PACKAGE_DIR=$WORK_DIR/openocd_${OPENOCD_TAG}_${HOST_TRIPLET}
####### #######
@ -86,13 +93,15 @@ rm -rf $SYSROOT $BUILD_DIR
mkdir -p $SYSROOT mkdir -p $SYSROOT
# libusb-1.0 build & install into sysroot # libusb-1.0 build & install into sysroot
mkdir -p $LIBUSB1_BUILD_DIR if [ -d $LIBUSB1_SRC ] ; then
cd $LIBUSB1_BUILD_DIR mkdir -p $LIBUSB1_BUILD_DIR
$LIBUSB1_SRC/configure --build=`$LIBUSB1_SRC/config.guess` --host=$HOST_TRIPLET \ cd $LIBUSB1_BUILD_DIR
--with-sysroot=$SYSROOT --prefix=$PREFIX \ $LIBUSB1_SRC/configure --build=`$LIBUSB1_SRC/config.guess` --host=$HOST_TRIPLET \
$LIBUSB1_CONFIG --with-sysroot=$SYSROOT --prefix=$PREFIX \
make $LIBUSB1_CONFIG
make install DESTDIR=$SYSROOT make -j $MAKE_JOBS
make install DESTDIR=$SYSROOT
fi
# hidapi build & install into sysroot # hidapi build & install into sysroot
if [ -d $HIDAPI_SRC ] ; then if [ -d $HIDAPI_SRC ] ; then
@ -101,7 +110,22 @@ if [ -d $HIDAPI_SRC ] ; then
$HIDAPI_SRC/configure --build=`$HIDAPI_SRC/config.guess` --host=$HOST_TRIPLET \ $HIDAPI_SRC/configure --build=`$HIDAPI_SRC/config.guess` --host=$HOST_TRIPLET \
--with-sysroot=$SYSROOT --prefix=$PREFIX \ --with-sysroot=$SYSROOT --prefix=$PREFIX \
$HIDAPI_CONFIG $HIDAPI_CONFIG
make make -j $MAKE_JOBS
make install DESTDIR=$SYSROOT
fi
# libftdi build & install into sysroot
if [ -d $LIBFTDI_SRC ] ; then
mkdir -p $LIBFTDI_BUILD_DIR
cd $LIBFTDI_BUILD_DIR
# libftdi requires libusb1 static libraries, granted by:
# export LIBUSB1_CONFIG="--enable-static ..."
cmake $LIBFTDI_CONFIG \
-DLIBUSB_INCLUDE_DIR=${SYSROOT}${PREFIX}/include/libusb-1.0 \
-DLIBUSB_LIBRARIES=${SYSROOT}${PREFIX}/lib/libusb-1.0.a \
-DCMAKE_INSTALL_PREFIX=${PREFIX} \
-DPKG_CONFIG_EXECUTABLE=`which pkg-config` \
$LIBFTDI_SRC
make install DESTDIR=$SYSROOT make install DESTDIR=$SYSROOT
fi fi
@ -111,9 +135,10 @@ cd $OPENOCD_BUILD_DIR
$OPENOCD_SRC/configure --build=`$OPENOCD_SRC/config.guess` --host=$HOST_TRIPLET \ $OPENOCD_SRC/configure --build=`$OPENOCD_SRC/config.guess` --host=$HOST_TRIPLET \
--with-sysroot=$SYSROOT --prefix=$PREFIX \ --with-sysroot=$SYSROOT --prefix=$PREFIX \
$OPENOCD_CONFIG $OPENOCD_CONFIG
make make -j $MAKE_JOBS
make install DESTDIR=$SYSROOT make install-strip DESTDIR=$SYSROOT
# Separate OpenOCD install w/o dependencies. OpenOCD will have to be linked # Separate OpenOCD install w/o dependencies. OpenOCD will have to be linked
# statically or have dependencies packaged/installed separately. # statically or have dependencies packaged/installed separately.
make install DESTDIR=$PACKAGE_DIR make install-strip DESTDIR=$PACKAGE_DIR

View File

@ -325,7 +325,7 @@ static void show_timestamp(FILE *f, int c)
delayed = true; delayed = true;
break; break;
case 0xf: case 0xf:
label = ", packet and timetamp delayed"; label = ", packet and timestamp delayed";
delayed = true; delayed = true;
break; break;
} }

View File

@ -46,7 +46,7 @@
ARM_MODE_SVC = 0x13 /* Supervisor Interrupts Mode */ ARM_MODE_SVC = 0x13 /* Supervisor Interrupts Mode */
ARM_MODE_ABORT = 0x17 /* Abort Processing memory Faults Mode */ ARM_MODE_ABORT = 0x17 /* Abort Processing memory Faults Mode */
ARM_MODE_UNDEF = 0x1B /* Undefined Instructions Mode */ ARM_MODE_UNDEF = 0x1B /* Undefined Instructions Mode */
ARM_MODE_SYS = 0x1F /* System Running in Priviledged Operating Mode */ ARM_MODE_SYS = 0x1F /* System Running in Privileged Operating Mode */
ARM_MODE_MASK = 0x1F ARM_MODE_MASK = 0x1F
I_BIT = 0x80 /* disable IRQ when I bit is set */ I_BIT = 0x80 /* disable IRQ when I bit is set */

View File

@ -39,7 +39,7 @@ int dcc_wr(uint32 data)
do { do {
asm volatile ("mrc p14, 0, %0, C0, C0" : "=r" (dcc_reg) :); asm volatile ("mrc p14, 0, %0, C0, C0" : "=r" (dcc_reg) :);
/* operation controled by master, cancel operation /* operation controlled by master, cancel operation
upon reception of data for immediate response */ upon reception of data for immediate response */
if (dcc_reg&1) return -1; if (dcc_reg&1) return -1;
} while (dcc_reg&2); } while (dcc_reg&2);

View File

@ -101,5 +101,5 @@ int main (void)
} }
} }
return(0); /* we shall never get here, just to supress compiler warning */ return 0; /* we shall never get here, just to suppress compiler warning */
} }

View File

@ -21,7 +21,7 @@
/* command/response mask */ /* command/response mask */
#define OCL_CMD_MASK 0xFFFF0000L #define OCL_CMD_MASK 0xFFFF0000L
/* commads */ /* commands */
#define OCL_FLASH_BLOCK 0x0CFB0000L #define OCL_FLASH_BLOCK 0x0CFB0000L
#define OCL_ERASE_BLOCK 0x0CEB0000L #define OCL_ERASE_BLOCK 0x0CEB0000L
#define OCL_ERASE_ALL 0x0CEA0000L #define OCL_ERASE_ALL 0x0CEA0000L

View File

@ -108,7 +108,7 @@ extern "C"
/****************************************************************************** /******************************************************************************
* *
* Define for the clock frequencey input to the flash module in number of MHz * Define for the clock frequency input to the flash module in number of MHz
* *
******************************************************************************/ ******************************************************************************/
#define FLASH_MODULE_CLK_FREQ 48 #define FLASH_MODULE_CLK_FREQ 48
@ -279,7 +279,7 @@ static inline uint32_t flash_check_fsm_for_ready(void)
* This function will erase the specified flash sector. The function will * This function will erase the specified flash sector. The function will
* not return until the flash sector has been erased or an error condition * not return until the flash sector has been erased or an error condition
* occurred. If flash top sector is erased the function will program the * occurred. If flash top sector is erased the function will program the
* the device security data bytes with default values. The device security * device security data bytes with default values. The device security
* data located in the customer configuration area of the flash top sector, * data located in the customer configuration area of the flash top sector,
* must have valid values at all times. These values affect the configuration * must have valid values at all times. These values affect the configuration
* of the device during boot. * of the device during boot.
@ -305,7 +305,7 @@ extern uint32_t flash_sector_erase(uint32_t sector_address);
* *
* This function will erase all unprotected flash sectors. The function will * This function will erase all unprotected flash sectors. The function will
* not return until the flash sectors has been erased or an error condition * not return until the flash sectors has been erased or an error condition
* occurred. Since the flash top sector is erased the function will program the * occurred. Since the flash top sector is erased the function will program
* the device security data bytes with default values. The device security * the device security data bytes with default values. The device security
* data located in the customer configuration area of the flash top sector, * data located in the customer configuration area of the flash top sector,
* must have valid values at all times. These values affect the configuration * must have valid values at all times. These values affect the configuration

View File

@ -52,7 +52,7 @@ const uint32_t stack_pntr = (uint32_t)stack + sizeof(stack);
/****************************************************************************** /******************************************************************************
* *
* The following are constructs created by the linker indicating where the * The following are constructs created by the linker indicating where
* the "bss" and "ebss" segments reside in memory. * the "bss" and "ebss" segments reside in memory.
* *
******************************************************************************/ ******************************************************************************/

View File

@ -81,7 +81,7 @@ find_next_page_boundary:
/* If we have not reached the next page boundary after the target address, keep going */ /* If we have not reached the next page boundary after the target address, keep going */
bls find_next_page_boundary bls find_next_page_boundary
write_enable: write_enable:
/* Flush read/write fifo's */ /* Flush read/write fifos */
bl flush_fifo bl flush_fifo
/* Instruction byte 1 */ /* Instruction byte 1 */
@ -134,7 +134,7 @@ write_wait:
bl stop_tx /* Otherwise, end the command and keep going w/ the next page */ bl stop_tx /* Otherwise, end the command and keep going w/ the next page */
add r10, r4 /* Move up the end-of-page address by the page size*/ add r10, r4 /* Move up the end-of-page address by the page size*/
check_flash_busy: /* Wait for the flash to finish the previous page write */ check_flash_busy: /* Wait for the flash to finish the previous page write */
/* Flush read/write fifo's */ /* Flush read/write fifos */
bl flush_fifo bl flush_fifo
/* Instruction byte 1 */ /* Instruction byte 1 */
movs r8, #0x1 movs r8, #0x1

View File

@ -367,7 +367,7 @@ bool pcm_shutdown_device(uint32_t shutdown_mode)
uint32_t shutdown_mode_bits = (shutdown_mode == PCM_LPM45) ? uint32_t shutdown_mode_bits = (shutdown_mode == PCM_LPM45) ?
PCM_CTL0_LPMR_12 : PCM_CTL0_LPMR_10; PCM_CTL0_LPMR_12 : PCM_CTL0_LPMR_10;
/* If a power transition is occuring, return false */ /* If a power transition is occurring, return false */
if (BITBAND_PERI(PCM->CTL1, PCM_CTL1_PMR_BUSY_OFS)) if (BITBAND_PERI(PCM->CTL1, PCM_CTL1_PMR_BUSY_OFS))
return false; return false;

View File

@ -71,9 +71,9 @@ void (* const intr_vectors[])(void) __attribute__((section(".intvecs"))) = {
}; };
/* /*
* The following are constructs created by the linker, indicating where the * The following are constructs created by the linker, indicating where
* the "data" and "bss" segments reside in memory. The initializers for the * the "data" and "bss" segments reside in memory. The initializers for
* for the "data" segment resides immediately following the "text" segment. * the "data" segment resides immediately following the "text" segment.
*/ */
extern uint32_t __bss_start__; extern uint32_t __bss_start__;
extern uint32_t __bss_end__; extern uint32_t __bss_end__;

View File

@ -71,9 +71,9 @@ void (* const intr_vectors[])(void) __attribute__((section(".intvecs"))) = {
}; };
/* /*
* The following are constructs created by the linker, indicating where the * The following are constructs created by the linker, indicating where
* the "data" and "bss" segments reside in memory. The initializers for the * the "data" and "bss" segments reside in memory. The initializers for
* for the "data" segment resides immediately following the "text" segment. * the "data" segment resides immediately following the "text" segment.
*/ */
extern uint32_t __bss_start__; extern uint32_t __bss_start__;
extern uint32_t __bss_end__; extern uint32_t __bss_end__;

View File

@ -25,7 +25,7 @@
* Code limitations: * Code limitations:
* The workarea must have size multiple of 4 bytes, since R/W * The workarea must have size multiple of 4 bytes, since R/W
* operations are all at 32 bits. * operations are all at 32 bits.
* The workarea must be big enough to contain rp, wp and data, thus the minumum * The workarea must be big enough to contain rp, wp and data, thus the minimum
* workarea size is: min_wa_size = sizeof(rp, wp, data) = 4 + 4 + sizeof(data). * workarea size is: min_wa_size = sizeof(rp, wp, data) = 4 + 4 + sizeof(data).
* - for 0x450 devices: sizeof(data) = 32 bytes, thus min_wa_size = 40 bytes. * - for 0x450 devices: sizeof(data) = 32 bytes, thus min_wa_size = 40 bytes.
* - for 0x480 devices: sizeof(data) = 16 bytes, thus min_wa_size = 24 bytes. * - for 0x480 devices: sizeof(data) = 16 bytes, thus min_wa_size = 24 bytes.
@ -78,7 +78,7 @@ wait_fifo:
str r7, [r5, #STM32_FLASH_CR_OFFSET] str r7, [r5, #STM32_FLASH_CR_OFFSET]
mov r8, #4 mov r8, #4
udiv r8, r4, r8 /* number of words is size of write word devided by 4*/ udiv r8, r4, r8 /* number of words is size of write word divided by 4*/
write_flash: write_flash:
dsb dsb
ldr r7, [r6], #0x04 /* read one word from src, increment ptr */ ldr r7, [r6], #0x04 /* read one word from src, increment ptr */

View File

@ -51,7 +51,7 @@ busy:
tsteq r4, #0x100 /* write protection set */ tsteq r4, #0x100 /* write protection set */
bne exit bne exit
add r1, r1, #0x8 /* next 8 bytes */ add r1, r1, #0x8 /* next 8 bytes */
subs r3, r3, #1 /* decremment dword count */ subs r3, r3, #1 /* decrement dword count */
bne write bne write
exit: exit:
b exit b exit

View File

@ -48,7 +48,7 @@ busy:
strh r5, [r4, #0] strh r5, [r4, #0]
tst r3, #0x12 tst r3, #0x12
bne exit bne exit
subs r2, r2, #1 /* decremment word count */ subs r2, r2, #1 /* decrement word count */
bne write bne write
exit: exit:
bkpt #0 bkpt #0

View File

@ -125,7 +125,7 @@ if __name__ == "__main__":
show(ocd.send("capture { echo \"echo says hi!\" }")[:-1]) show(ocd.send("capture { echo \"echo says hi!\" }")[:-1])
show(ocd.send("capture \"halt\"")[:-1]) show(ocd.send("capture \"halt\"")[:-1])
# Read the first few words at the RAM region (put starting adress of RAM # Read the first few words at the RAM region (put starting address of RAM
# region into 'addr') # region into 'addr')
addr = 0x10000000 addr = 0x10000000

View File

@ -82,7 +82,7 @@ number will be zero (<code>z = 0</code>). For a <i>major releases</i>,
the minor version will @a also be zero (<code>y = 0, z = 0</code>). the minor version will @a also be zero (<code>y = 0, z = 0</code>).
After these required numeric components, release version strings After these required numeric components, release version strings
may contain tags such as as <em>-rc1</em> or <em>-rc2</em>. may contain tags such as <em>-rc1</em> or <em>-rc2</em>.
These 'rc' tags indicate "release candidate" versions of the package. These 'rc' tags indicate "release candidate" versions of the package.
Like major/minor/micro numbers, these are updated Like major/minor/micro numbers, these are updated
as part of the release process. as part of the release process.

View File

@ -23,7 +23,7 @@ In early 2008, Oyvind Harboe and Duane Ellis had talked about how to
create a reasonable GUI for OpenOCD - something that is non-invasive, create a reasonable GUI for OpenOCD - something that is non-invasive,
simple to use and maintain, and does not tie OpenOCD to many other simple to use and maintain, and does not tie OpenOCD to many other
packages. It would be wrong to "spider web" requirements into other packages. It would be wrong to "spider web" requirements into other
external external packages. That makes it difficult for developers to external packages. That makes it difficult for developers to
write new code and creates a support nightmare. write new code and creates a support nightmare.
In many ways, people had talked about the need for some type of In many ways, people had talked about the need for some type of
@ -67,7 +67,7 @@ write scripts internally to help things, or we can write "C" code that
interfaces well with TCL. interfaces well with TCL.
From there, the developers wanted to create an external front-end that From there, the developers wanted to create an external front-end that
would be @a very usable and that that @a any language could utilize, would be @a very usable and that @a any language could utilize,
allowing simple front-ends to be (a) cross-platform (b) language allowing simple front-ends to be (a) cross-platform (b) language
agnostic, and (c) easy to develop and use. agnostic, and (c) easy to develop and use.

View File

@ -52,7 +52,7 @@ OpenOCD project.
-# remove it entirely (git can retrieve the old version), or -# remove it entirely (git can retrieve the old version), or
-# use an @c \#if/\#endif block. -# use an @c \#if/\#endif block.
Finally, try to avoid lines of code that are longer than than 72-80 columns: Finally, try to avoid lines of code that are longer than 72-80 columns:
- long lines frequently indicate other style problems: - long lines frequently indicate other style problems:
- insufficient use of static functions, macros, or temporary variables - insufficient use of static functions, macros, or temporary variables

View File

@ -393,15 +393,15 @@ for (i = 0; i < count; i++)
} }
@endcode @endcode
Each time when OpenOCD fills data to CPU (via dongle, via dmseg), CPU takes it and proceeds in executing the handler. However, since handler is in a assembly loop, Each time when OpenOCD fills data to CPU (via dongle, via dmseg), CPU takes it and proceeds to execute the handler. However, since the handler is in an assembly loop,
CPU comes to next instruction which also fetches data from FASTDATA area. So it stalls. CPU comes to next instruction which also fetches data from FASTDATA area. So it stalls.
Then OpenOCD fills the data again, from it's (OpenOCD's) loop. And this game continues until all the data has been filled. Then OpenOCD fills the data again, from its (OpenOCD's) loop. And this game continues until all the data has been filled.
After the last data has been given to CPU it sees that it reached the end address, so it proceeds with next instruction. However, this instruction do not point into dmseg, so After the last data has been given to CPU it sees that it reached the end address, so it proceeds with next instruction. However, this instruction do not point into dmseg, so
CPU executes bunch of handler instructions (all prologue) and in the end jumps to MIPS32_PRACC_TEXT address. CPU executes bunch of handler instructions (all prologue) and in the end jumps to MIPS32_PRACC_TEXT address.
On it's side, OpenOCD checks in CPU has jumped back to MIPS32_PRACC_TEXT, which is the confirmation that it correctly executed all the rest of the handler in RAM, On its side, OpenOCD checks in CPU has jumped back to MIPS32_PRACC_TEXT, which is the confirmation that it correctly executed all the rest of the handler in RAM,
and that is not stuck somewhere in the RAM, or stalling on some access in dmseg - that would be an error : and that is not stuck somewhere in the RAM, or stalling on some access in dmesg - that would be an error:
@code @code
address = 0; address = 0;

View File

@ -505,6 +505,12 @@ Texas Instruments has an adapter called @b{ICDI}.
It is not to be confused with the FTDI based adapters that were originally fitted to their It is not to be confused with the FTDI based adapters that were originally fitted to their
evaluation boards. This is the adapter fitted to the Stellaris LaunchPad. evaluation boards. This is the adapter fitted to the Stellaris LaunchPad.
@section USB Nuvoton Nu-Link
Nuvoton has an adapter called @b{Nu-Link}.
It is available either as stand-alone dongle and embedded on development boards.
It supports SWD, serial port bridge and mass storage for firmware update.
Both Nu-Link v1 and v2 are supported.
@section USB CMSIS-DAP based @section USB CMSIS-DAP based
ARM has released a interface standard called CMSIS-DAP that simplifies connecting ARM has released a interface standard called CMSIS-DAP that simplifies connecting
debuggers to ARM Cortex based targets @url{http://www.keil.com/support/man/docs/dapdebug/dapdebug_introduction.htm}. debuggers to ARM Cortex based targets @url{http://www.keil.com/support/man/docs/dapdebug/dapdebug_introduction.htm}.
@ -609,8 +615,14 @@ produced, PDF schematics are easily found and it is easy to make.
@* A JTAG driver acting as a client for the JTAG VPI server interface. @* A JTAG driver acting as a client for the JTAG VPI server interface.
@* Link: @url{http://github.com/fjullien/jtag_vpi} @* Link: @url{http://github.com/fjullien/jtag_vpi}
@item @b{jtag_dpi}
@* A JTAG driver acting as a client for the SystemVerilog Direct Programming
Interface (DPI) for JTAG devices. DPI allows OpenOCD to connect to the JTAG
interface of a hardware model written in SystemVerilog, for example, on an
emulation model of target hardware.
@item @b{xlnx_pcie_xvc} @item @b{xlnx_pcie_xvc}
@* A JTAG driver exposing Xilinx Virtual Cable over PCI Express to OpenOCD as JTAG interface. @* A JTAG driver exposing Xilinx Virtual Cable over PCI Express to OpenOCD as JTAG/SWD interface.
@end itemize @end itemize
@ -712,8 +724,11 @@ Configuration files and scripts are searched for in
@item the current directory, @item the current directory,
@item any search dir specified on the command line using the @option{-s} option, @item any search dir specified on the command line using the @option{-s} option,
@item any search dir specified using the @command{add_script_search_dir} command, @item any search dir specified using the @command{add_script_search_dir} command,
@item @file{$HOME/.openocd} (not on Windows),
@item a directory in the @env{OPENOCD_SCRIPTS} environment variable (if set), @item a directory in the @env{OPENOCD_SCRIPTS} environment variable (if set),
@item @file{%APPDATA%/OpenOCD} (only on Windows),
@item @file{$HOME/Library/Preferences/org.openocd} (only on Darwin),
@item @file{$XDG_CONFIG_HOME/openocd} (@env{$XDG_CONFIG_HOME} defaults to @file{$HOME/.config}),
@item @file{$HOME/.openocd},
@item the site wide script library @file{$pkgdatadir/site} and @item the site wide script library @file{$pkgdatadir/site} and
@item the OpenOCD-supplied script library @file{$pkgdatadir/scripts}. @item the OpenOCD-supplied script library @file{$pkgdatadir/scripts}.
@end enumerate @end enumerate
@ -1020,7 +1035,7 @@ will help support users of any board using that chip.
@end quotation @end quotation
@item @item
You may may need to write some C code. You may need to write some C code.
It may be as simple as supporting a new FT2232 or parport It may be as simple as supporting a new FT2232 or parport
based adapter; a bit more involved, like a NAND or NOR flash based adapter; a bit more involved, like a NAND or NOR flash
controller driver; or a big piece of work like supporting controller driver; or a big piece of work like supporting
@ -3064,7 +3079,8 @@ This is a driver that supports multiple High Level Adapters.
This type of adapter does not expose some of the lower level api's This type of adapter does not expose some of the lower level api's
that OpenOCD would normally use to access the target. that OpenOCD would normally use to access the target.
Currently supported adapters include the STMicroelectronics ST-LINK and TI ICDI. Currently supported adapters include the STMicroelectronics ST-LINK, TI ICDI
and Nuvoton Nu-Link.
ST-LINK firmware version >= V2.J21.S4 recommended due to issues with earlier ST-LINK firmware version >= V2.J21.S4 recommended due to issues with earlier
versions of firmware where serial number is reset after first use. Suggest versions of firmware where serial number is reset after first use. Suggest
using ST firmware update utility to upgrade ST-LINK firmware even if current using ST firmware update utility to upgrade ST-LINK firmware even if current
@ -3078,7 +3094,7 @@ Currently Not Supported.
Specifies the serial number of the adapter. Specifies the serial number of the adapter.
@end deffn @end deffn
@deffn {Config Command} {hla_layout} (@option{stlink}|@option{icdi}) @deffn {Config Command} {hla_layout} (@option{stlink}|@option{icdi}|@option{nulink})
Specifies the adapter layout to use. Specifies the adapter layout to use.
@end deffn @end deffn
@ -3149,7 +3165,7 @@ version).
@deffn {Interface Driver} {xlnx_pcie_xvc} @deffn {Interface Driver} {xlnx_pcie_xvc}
This driver supports the Xilinx Virtual Cable (XVC) over PCI Express. This driver supports the Xilinx Virtual Cable (XVC) over PCI Express.
It is commonly found in Xilinx based PCI Express designs. It allows debugging It is commonly found in Xilinx based PCI Express designs. It allows debugging
fabric based JTAG devices such as Cortex-M1/M3 microcontrollers. Access to this is fabric based JTAG/SWD devices such as Cortex-M1/M3 microcontrollers. Access to this is
exposed via extended capability registers in the PCI Express configuration space. exposed via extended capability registers in the PCI Express configuration space.
For more information see Xilinx PG245 (Section on From_PCIE_to_JTAG mode). For more information see Xilinx PG245 (Section on From_PCIE_to_JTAG mode).
@ -3228,6 +3244,22 @@ This value is only used with the standard variant.
@end deffn @end deffn
@end deffn @end deffn
@deffn {Interface Driver} {jtag_dpi}
SystemVerilog Direct Programming Interface (DPI) compatible driver for
JTAG devices in emulation. The driver acts as a client for the SystemVerilog
DPI server interface.
@deffn {Config Command} {jtag_dpi_set_port} port
Specifies the TCP/IP port number of the SystemVerilog DPI server interface.
@end deffn
@deffn {Config Command} {jtag_dpi_set_address} address
Specifies the TCP/IP address of the SystemVerilog DPI server interface.
@end deffn
@end deffn
@section Transport Configuration @section Transport Configuration
@cindex Transport @cindex Transport
As noted earlier, depending on the version of OpenOCD you use, As noted earlier, depending on the version of OpenOCD you use,
@ -4637,7 +4669,8 @@ The value should normally correspond to a static mapping for the
@item @code{-rtos} @var{rtos_type} -- enable rtos support for target, @item @code{-rtos} @var{rtos_type} -- enable rtos support for target,
@var{rtos_type} can be one of @option{auto}, @option{eCos}, @var{rtos_type} can be one of @option{auto}, @option{eCos},
@option{ThreadX}, @option{FreeRTOS}, @option{linux}, @option{ChibiOS}, @option{ThreadX}, @option{FreeRTOS}, @option{linux}, @option{ChibiOS},
@option{embKernel}, @option{mqx}, @option{uCOS-III}, @option{nuttx} @option{embKernel}, @option{mqx}, @option{uCOS-III}, @option{nuttx},
@option{RIOT}
@xref{gdbrtossupport,,RTOS Support}. @xref{gdbrtossupport,,RTOS Support}.
@item @code{-defer-examine} -- skip target examination at initial JTAG chain @item @code{-defer-examine} -- skip target examination at initial JTAG chain
@ -5661,7 +5694,7 @@ at91samd bootloader 16384
@deffn Command {at91samd dsu_reset_deassert} @deffn Command {at91samd dsu_reset_deassert}
This command releases internal reset held by DSU This command releases internal reset held by DSU
and prepares reset vector catch in case of reset halt. and prepares reset vector catch in case of reset halt.
Command is used internally in event event reset-deassert-post. Command is used internally in event reset-deassert-post.
@end deffn @end deffn
@deffn Command {at91samd nvmuserrow} @deffn Command {at91samd nvmuserrow}
@ -5768,7 +5801,7 @@ The AT91SAM4L driver adds some additional commands:
@deffn Command {at91sam4l smap_reset_deassert} @deffn Command {at91sam4l smap_reset_deassert}
This command releases internal reset held by SMAP This command releases internal reset held by SMAP
and prepares reset vector catch in case of reset halt. and prepares reset vector catch in case of reset halt.
Command is used internally in event event reset-deassert-post. Command is used internally in event reset-deassert-post.
@end deffn @end deffn
@end deffn @end deffn
@ -5809,7 +5842,7 @@ processor to be halted.
@deffn Command {atsame5 dsu_reset_deassert} @deffn Command {atsame5 dsu_reset_deassert}
This command releases internal reset held by DSU This command releases internal reset held by DSU
and prepares reset vector catch in case of reset halt. and prepares reset vector catch in case of reset halt.
Command is used internally in event event reset-deassert-post. Command is used internally in event reset-deassert-post.
@end deffn @end deffn
@deffn Command {atsame5 userpage} @deffn Command {atsame5 userpage}
@ -8392,7 +8425,7 @@ and any buffered trace data is invalidated.
@itemize @itemize
@item @var{type} ... describing how data accesses are traced, @item @var{type} ... describing how data accesses are traced,
when they pass any ViewData filtering that that was set up. when they pass any ViewData filtering that was set up.
The value is one of The value is one of
@option{none} (save nothing), @option{none} (save nothing),
@option{data} (save data), @option{data} (save data),
@ -8740,7 +8773,7 @@ and any other core-specific commands that may be available.
@deffn Command {arm7_9 dbgrq} [@option{enable}|@option{disable}] @deffn Command {arm7_9 dbgrq} [@option{enable}|@option{disable}]
Displays the value of the flag controlling use of the Displays the value of the flag controlling use of the
the EmbeddedIce DBGRQ signal to force entry into debug mode, EmbeddedIce DBGRQ signal to force entry into debug mode,
instead of breakpoints. instead of breakpoints.
If a boolean parameter is provided, first assigns that flag. If a boolean parameter is provided, first assigns that flag.
@ -9341,6 +9374,12 @@ target code relies on. In a configuration file, the command would typically be c
However, normally it is not necessary to use the command at all. However, normally it is not necessary to use the command at all.
@end deffn @end deffn
@deffn Command {aarch64 disassemble} address [count]
@cindex disassemble
Disassembles @var{count} instructions starting at @var{address}.
If @var{count} is not specified, a single instruction is disassembled.
@end deffn
@deffn Command {aarch64 smp} [on|off] @deffn Command {aarch64 smp} [on|off]
Display, enable or disable SMP handling mode. The state of SMP handling influences the way targets in an SMP group Display, enable or disable SMP handling mode. The state of SMP handling influences the way targets in an SMP group
are handled by the run control. With SMP handling enabled, issuing halt or resume to one core will trigger are handled by the run control. With SMP handling enabled, issuing halt or resume to one core will trigger
@ -10430,18 +10469,31 @@ OpenOCD can communicate with GDB in two ways:
@item @item
A socket (TCP/IP) connection is typically started as follows: A socket (TCP/IP) connection is typically started as follows:
@example @example
target remote localhost:3333 target extended-remote localhost:3333
@end example @end example
This would cause GDB to connect to the gdbserver on the local pc using port 3333. This would cause GDB to connect to the gdbserver on the local pc using port 3333.
It is also possible to use the GDB extended remote protocol as follows: The extended remote protocol is a super-set of the remote protocol and should
be the preferred choice. More details are available in GDB documentation
@url{https://sourceware.org/gdb/onlinedocs/gdb/Connecting.html}
To speed-up typing, any GDB command can be abbreviated, including the extended
remote command above that becomes:
@example @example
target extended-remote localhost:3333 tar ext :3333
@end example @end example
@b{Note:} If any backward compatibility issue requires using the old remote
protocol in place of the extended remote one, the former protocol is still
available through the command:
@example
target remote localhost:3333
@end example
@item @item
A pipe connection is typically started as follows: A pipe connection is typically started as follows:
@example @example
target remote | openocd -c "gdb_port pipe; log_output openocd.log" target extended-remote | openocd -c "gdb_port pipe; log_output openocd.log"
@end example @end example
This would cause GDB to run OpenOCD and communicate using pipes (stdin/stdout). This would cause GDB to run OpenOCD and communicate using pipes (stdin/stdout).
Using this method has the advantage of GDB starting/stopping OpenOCD for the debug Using this method has the advantage of GDB starting/stopping OpenOCD for the debug
@ -10463,7 +10515,7 @@ Most programs would be written into flash (address 0) and run from there.
@example @example
$ arm-none-eabi-gdb example.elf $ arm-none-eabi-gdb example.elf
(gdb) target remote localhost:3333 (gdb) target extended-remote localhost:3333
Remote debugging using localhost:3333 Remote debugging using localhost:3333
... ...
(gdb) monitor reset halt (gdb) monitor reset halt
@ -10598,7 +10650,7 @@ set remote interrupt-on-connect off
If you switched gdb_memory_map off, you may want to setup GDB memory map If you switched gdb_memory_map off, you may want to setup GDB memory map
manually or issue @command{set mem inaccessible-by-default off} manually or issue @command{set mem inaccessible-by-default off}
Now you can issue GDB command @command{target remote ...} and inspect memory Now you can issue GDB command @command{target extended-remote ...} and inspect memory
of a running target. Do not use GDB commands @command{continue}, of a running target. Do not use GDB commands @command{continue},
@command{step} or @command{next} as they synchronize GDB with your target @command{step} or @command{next} as they synchronize GDB with your target
and GDB would require stopping the target to get the prompt back. and GDB would require stopping the target to get the prompt back.
@ -10636,6 +10688,7 @@ Currently supported rtos's include:
@item @option{mqx} @item @option{mqx}
@item @option{uCOS-III} @item @option{uCOS-III}
@item @option{nuttx} @item @option{nuttx}
@item @option{RIOT}
@item @option{hwthread} (This is not an actual RTOS. @xref{usingopenocdsmpwithgdb,,Using OpenOCD SMP with GDB}.) @item @option{hwthread} (This is not an actual RTOS. @xref{usingopenocdsmpwithgdb,,Using OpenOCD SMP with GDB}.)
@end itemize @end itemize
@ -10672,6 +10725,8 @@ _mqx_kernel_data, MQX_init_struct.
OSRunning, OSTCBCurPtr, OSTaskDbgListPtr, OSTaskQty OSRunning, OSTCBCurPtr, OSTaskDbgListPtr, OSTaskQty
@item nuttx symbols @item nuttx symbols
g_readytorun, g_tasklisttable g_readytorun, g_tasklisttable
@item RIOT symbols
sched_threads, sched_num_threads, sched_active_pid, max_threads, _tcb_name_offset
@end table @end table
For most RTOS supported the above symbols will be exported by default. However for For most RTOS supported the above symbols will be exported by default. However for

View File

@ -94,7 +94,7 @@ typedef int (*nand_driver_walker_t)(struct nand_flash_controller *c, void *);
* Walk the list of drivers, encapsulating the data structure type. * Walk the list of drivers, encapsulating the data structure type.
* Application state/context can be passed through the @c x pointer. * Application state/context can be passed through the @c x pointer.
* @param f The callback function to invoke for each function. * @param f The callback function to invoke for each function.
* @param x For use as private data storate, passed directly to @c f. * @param x For use as private data storage, passed directly to @c f.
* @returns ERROR_OK if successful, or the non-zero return value of @c f. * @returns ERROR_OK if successful, or the non-zero return value of @c f.
* This allows a walker to terminate the loop early. * This allows a walker to terminate the loop early.
*/ */

View File

@ -99,14 +99,11 @@ int nand_fileio_cleanup(struct nand_fileio_state *state)
if (state->file_opened) if (state->file_opened)
fileio_close(state->fileio); fileio_close(state->fileio);
if (state->oob) { free(state->oob);
free(state->oob); state->oob = NULL;
state->oob = NULL;
} free(state->page);
if (state->page) { state->page = NULL;
free(state->page);
state->page = NULL;
}
return ERROR_OK; return ERROR_OK;
} }
int nand_fileio_finish(struct nand_fileio_state *state) int nand_fileio_finish(struct nand_fileio_state *state)
@ -206,7 +203,7 @@ int nand_fileio_read(struct nand_device *nand, struct nand_fileio_state *s)
} else if (s->oob_format & NAND_OOB_SW_ECC_KW) { } else if (s->oob_format & NAND_OOB_SW_ECC_KW) {
/* /*
* In this case eccpos is not used as * In this case eccpos is not used as
* the ECC data is always stored contigously * the ECC data is always stored contiguously
* at the end of the OOB area. It consists * at the end of the OOB area. It consists
* of 10 bytes per 512-byte data block. * of 10 bytes per 512-byte data block.
*/ */

View File

@ -232,7 +232,7 @@ static int lpc3180_init(struct nand_device *nand)
/* FLASHCLK_CTRL = 0x05 (enable clock for SLC flash controller) */ /* FLASHCLK_CTRL = 0x05 (enable clock for SLC flash controller) */
target_write_u32(target, 0x400040c8, 0x05); target_write_u32(target, 0x400040c8, 0x05);
/* after reset set other registers of SLC so reset calling is here at the begining*/ /* after reset set other registers of SLC so reset calling is here at the beginning */
lpc3180_reset(nand); lpc3180_reset(nand);
/* SLC_CFG = 0x (Force nCE assert, DMA ECC enabled, ECC enabled, DMA burst enabled, /* SLC_CFG = 0x (Force nCE assert, DMA ECC enabled, ECC enabled, DMA burst enabled,

View File

@ -42,7 +42,7 @@ extern int nand_correct_data(struct nand_device *nand, u_char *dat,
* read/write data to the SLC controller. * read/write data to the SLC controller.
* - DMA descriptors will be put at start of working area, * - DMA descriptors will be put at start of working area,
* - Hardware generated ECC will be stored at ECC_OFFS * - Hardware generated ECC will be stored at ECC_OFFS
* - OOB wil be read/written from/to SPARE_OFFS * - OOB will be read/written from/to SPARE_OFFS
* - Actual page data will be read from/to DATA_OFFS * - Actual page data will be read from/to DATA_OFFS
* There are unused holes between the used areas. * There are unused holes between the used areas.
*/ */
@ -317,7 +317,7 @@ static int lpc32xx_init(struct nand_device *nand)
} }
/* after reset set other registers of SLC, /* after reset set other registers of SLC,
* so reset calling is here at the begining * so reset calling is here at the beginning
*/ */
retval = lpc32xx_reset(nand); retval = lpc32xx_reset(nand);
if (ERROR_OK != retval) if (ERROR_OK != retval)
@ -769,7 +769,7 @@ static int lpc32xx_make_dma_list(uint32_t target_mem_base, uint32_t page_size,
* 2. Copy generated ECC data from Register to Spare Area * 2. Copy generated ECC data from Register to Spare Area
* 3. X'fer next 256 bytes of data from Memory to Flash. * 3. X'fer next 256 bytes of data from Memory to Flash.
* 4. Copy generated ECC data from Register to Spare Area. * 4. Copy generated ECC data from Register to Spare Area.
* 5. X'fer 16 byets of Spare area from Memory to Flash. * 5. X'fer 16 bytes of Spare area from Memory to Flash.
* Read Operation Sequence for Small Block NAND * Read Operation Sequence for Small Block NAND
* ---------------------------------------------------------- * ----------------------------------------------------------
* 1. X'fer 256 bytes of data from Flash to Memory. * 1. X'fer 256 bytes of data from Flash to Memory.
@ -779,13 +779,13 @@ static int lpc32xx_make_dma_list(uint32_t target_mem_base, uint32_t page_size,
* 5. X'fer 16 bytes of Spare area from Flash to Memory. * 5. X'fer 16 bytes of Spare area from Flash to Memory.
* Write Operation Sequence for Large Block NAND * Write Operation Sequence for Large Block NAND
* ---------------------------------------------------------- * ----------------------------------------------------------
* 1. Steps(1-4) of Write Operations repeate for four times * 1. Steps(1-4) of Write Operations repeated for four times
* which generates 16 DMA descriptors to X'fer 2048 bytes of * which generates 16 DMA descriptors to X'fer 2048 bytes of
* data & 32 bytes of ECC data. * data & 32 bytes of ECC data.
* 2. X'fer 64 bytes of Spare area from Memory to Flash. * 2. X'fer 64 bytes of Spare area from Memory to Flash.
* Read Operation Sequence for Large Block NAND * Read Operation Sequence for Large Block NAND
* ---------------------------------------------------------- * ----------------------------------------------------------
* 1. Steps(1-4) of Read Operations repeate for four times * 1. Steps(1-4) of Read Operations repeated for four times
* which generates 16 DMA descriptors to X'fer 2048 bytes of * which generates 16 DMA descriptors to X'fer 2048 bytes of
* data & 32 bytes of ECC data. * data & 32 bytes of ECC data.
* 2. X'fer 64 bytes of Spare area from Flash to Memory. * 2. X'fer 64 bytes of Spare area from Flash to Memory.
@ -842,7 +842,7 @@ static int lpc32xx_make_dma_list(uint32_t target_mem_base, uint32_t page_size,
* 2. Copy generated ECC data from Register to Spare Area * 2. Copy generated ECC data from Register to Spare Area
* 3. X'fer next 256 bytes of data from Memory to Flash. * 3. X'fer next 256 bytes of data from Memory to Flash.
* 4. Copy generated ECC data from Register to Spare Area. * 4. Copy generated ECC data from Register to Spare Area.
* 5. X'fer 16 byets of Spare area from Memory to Flash. * 5. X'fer 16 bytes of Spare area from Memory to Flash.
* Read Operation Sequence for Small Block NAND * Read Operation Sequence for Small Block NAND
* ---------------------------------------------------------- * ----------------------------------------------------------
* 1. X'fer 256 bytes of data from Flash to Memory. * 1. X'fer 256 bytes of data from Flash to Memory.
@ -852,13 +852,13 @@ static int lpc32xx_make_dma_list(uint32_t target_mem_base, uint32_t page_size,
* 5. X'fer 16 bytes of Spare area from Flash to Memory. * 5. X'fer 16 bytes of Spare area from Flash to Memory.
* Write Operation Sequence for Large Block NAND * Write Operation Sequence for Large Block NAND
* ---------------------------------------------------------- * ----------------------------------------------------------
* 1. Steps(1-4) of Write Operations repeate for four times * 1. Steps(1-4) of Write Operations repeated for four times
* which generates 16 DMA descriptors to X'fer 2048 bytes of * which generates 16 DMA descriptors to X'fer 2048 bytes of
* data & 32 bytes of ECC data. * data & 32 bytes of ECC data.
* 2. X'fer 64 bytes of Spare area from Memory to Flash. * 2. X'fer 64 bytes of Spare area from Memory to Flash.
* Read Operation Sequence for Large Block NAND * Read Operation Sequence for Large Block NAND
* ---------------------------------------------------------- * ----------------------------------------------------------
* 1. Steps(1-4) of Read Operations repeate for four times * 1. Steps(1-4) of Read Operations repeated for four times
* which generates 16 DMA descriptors to X'fer 2048 bytes of * which generates 16 DMA descriptors to X'fer 2048 bytes of
* data & 32 bytes of ECC data. * data & 32 bytes of ECC data.
* 2. X'fer 64 bytes of Spare area from Flash to Memory. * 2. X'fer 64 bytes of Spare area from Flash to Memory.
@ -1044,7 +1044,7 @@ static int lpc32xx_write_page_slc(struct nand_device *nand,
target_mem_base = pworking_area->address; target_mem_base = pworking_area->address;
/* /*
* Skip writting page which has all 0xFF data as this will * Skip writing page which has all 0xFF data as this will
* generate 0x0 value. * generate 0x0 value.
*/ */
if (data && !oob) { if (data && !oob) {
@ -1102,7 +1102,7 @@ static int lpc32xx_write_page_slc(struct nand_device *nand,
return retval; return retval;
} }
/* Write first decriptor to DMA controller */ /* Write first descriptor to DMA controller */
retval = target_write_memory(target, 0x31000100, 4, retval = target_write_memory(target, 0x31000100, 4,
sizeof(dmac_ll_t) / 4, sizeof(dmac_ll_t) / 4,
(uint8_t *)dmalist); (uint8_t *)dmalist);
@ -1159,7 +1159,7 @@ static int lpc32xx_write_page_slc(struct nand_device *nand,
return retval; return retval;
} }
/* Write OOB decriptor to DMA controller */ /* Write OOB descriptor to DMA controller */
retval = target_write_memory(target, 0x31000100, 4, retval = target_write_memory(target, 0x31000100, 4,
sizeof(dmac_ll_t) / 4, sizeof(dmac_ll_t) / 4,
(uint8_t *)(&dmalist[nll-1])); (uint8_t *)(&dmalist[nll-1]));
@ -1487,7 +1487,7 @@ static int lpc32xx_read_page_slc(struct nand_device *nand,
return retval; return retval;
} }
/* Write first decriptor to DMA controller */ /* Write first descriptor to DMA controller */
retval = target_write_memory(target, 0x31000100, 4, retval = target_write_memory(target, 0x31000100, 4,
sizeof(dmac_ll_t) / 4, (uint8_t *)dmalist); sizeof(dmac_ll_t) / 4, (uint8_t *)dmalist);
if (ERROR_OK != retval) { if (ERROR_OK != retval) {

View File

@ -40,7 +40,7 @@ get_next_halfword_from_sram_buffer() not tested
static const char target_not_halted_err_msg[] = static const char target_not_halted_err_msg[] =
"target must be halted to use mx3 NAND flash controller"; "target must be halted to use mx3 NAND flash controller";
static const char data_block_size_err_msg[] = static const char data_block_size_err_msg[] =
"minimal granularity is one half-word, %" PRId32 " is incorrect"; "minimal granularity is one half-word, %" PRIu32 " is incorrect";
static const char sram_buffer_bounds_err_msg[] = static const char sram_buffer_bounds_err_msg[] =
"trying to access out of SRAM buffer bound (addr=0x%" PRIx32 ")"; "trying to access out of SRAM buffer bound (addr=0x%" PRIx32 ")";
static const char get_status_register_err_msg[] = "can't get NAND status"; static const char get_status_register_err_msg[] = "can't get NAND status";
@ -149,7 +149,7 @@ static int imx31_init(struct nand_device *nand)
uint32_t gpr_register_content; uint32_t gpr_register_content;
target_read_u32(target, MX3_GPR, &gpr_register_content); target_read_u32(target, MX3_GPR, &gpr_register_content);
if (gpr_register_content & 0x00000060) { if (gpr_register_content & 0x00000060) {
LOG_ERROR("pins mode overrided by GPR"); LOG_ERROR("pins mode overridden by GPR");
return ERROR_FAIL; return ERROR_FAIL;
} }
} }
@ -414,10 +414,10 @@ static int imx31_write_page(struct nand_device *nand, uint32_t page,
if (oob) { if (oob) {
if (mx3_nf_info->flags.hw_ecc_enabled) { if (mx3_nf_info->flags.hw_ecc_enabled) {
/* /*
* part of spare block will be overrided by hardware * part of spare block will be overridden by hardware
* ECC generator * ECC generator
*/ */
LOG_DEBUG("part of spare block will be overrided by hardware ECC generator"); LOG_DEBUG("part of spare block will be overridden by hardware ECC generator");
} }
target_write_buffer(target, MX3_NF_SPARE_BUFFER0, oob_size, oob); target_write_buffer(target, MX3_NF_SPARE_BUFFER0, oob_size, oob);
} }
@ -530,7 +530,7 @@ static int initialize_nf_controller(struct nand_device *nand)
struct mx3_nf_controller *mx3_nf_info = nand->controller_priv; struct mx3_nf_controller *mx3_nf_info = nand->controller_priv;
struct target *target = nand->target; struct target *target = nand->target;
/* /*
* resets NAND flash controller in zero time ? I dont know. * resets NAND flash controller in zero time ? I don't know.
*/ */
target_write_u16(target, MX3_NF_CFG1, MX3_NF_BIT_RESET_EN); target_write_u16(target, MX3_NF_CFG1, MX3_NF_BIT_RESET_EN);
{ {
@ -680,18 +680,18 @@ static int do_data_output(struct nand_device *nand)
target_read_u16 (target, MX3_NF_ECCSTATUS, &ecc_status); target_read_u16 (target, MX3_NF_ECCSTATUS, &ecc_status);
switch (ecc_status & 0x000c) { switch (ecc_status & 0x000c) {
case 1 << 2: case 1 << 2:
LOG_DEBUG("main area readed with 1 (correctable) error"); LOG_DEBUG("main area read with 1 (correctable) error");
break; break;
case 2 << 2: case 2 << 2:
LOG_DEBUG("main area readed with more than 1 (incorrectable) error"); LOG_DEBUG("main area read with more than 1 (incorrectable) error");
return ERROR_NAND_OPERATION_FAILED; return ERROR_NAND_OPERATION_FAILED;
} }
switch (ecc_status & 0x0003) { switch (ecc_status & 0x0003) {
case 1: case 1:
LOG_DEBUG("spare area readed with 1 (correctable) error"); LOG_DEBUG("spare area read with 1 (correctable) error");
break; break;
case 2: case 2:
LOG_DEBUG("main area readed with more than 1 (incorrectable) error"); LOG_DEBUG("main area read with more than 1 (incorrectable) error");
return ERROR_NAND_OPERATION_FAILED; return ERROR_NAND_OPERATION_FAILED;
} }
} }

View File

@ -65,7 +65,7 @@
static const char target_not_halted_err_msg[] = static const char target_not_halted_err_msg[] =
"target must be halted to use mxc NAND flash controller"; "target must be halted to use mxc NAND flash controller";
static const char data_block_size_err_msg[] = static const char data_block_size_err_msg[] =
"minimal granularity is one half-word, %" PRId32 " is incorrect"; "minimal granularity is one half-word, %" PRIu32 " is incorrect";
static const char sram_buffer_bounds_err_msg[] = static const char sram_buffer_bounds_err_msg[] =
"trying to access out of SRAM buffer bound (addr=0x%" PRIx32 ")"; "trying to access out of SRAM buffer bound (addr=0x%" PRIx32 ")";
static const char get_status_register_err_msg[] = "can't get NAND status"; static const char get_status_register_err_msg[] = "can't get NAND status";
@ -136,7 +136,7 @@ NAND_DEVICE_COMMAND_HANDLER(mxc_nand_device_command)
(nand->target->endianness == TARGET_LITTLE_ENDIAN); (nand->target->endianness == TARGET_LITTLE_ENDIAN);
/* /*
* should factory bad block indicator be swaped * should factory bad block indicator be swapped
* as a workaround for how the nfc handles pages. * as a workaround for how the nfc handles pages.
*/ */
if (CMD_ARGC > 4 && strcmp(CMD_ARGV[4], "biswap") == 0) { if (CMD_ARGC > 4 && strcmp(CMD_ARGV[4], "biswap") == 0) {
@ -181,7 +181,7 @@ static const struct command_registration mxc_sub_command_handlers[] = {
.name = "biswap", .name = "biswap",
.mode = COMMAND_EXEC, .mode = COMMAND_EXEC,
.handler = handle_mxc_biswap_command, .handler = handle_mxc_biswap_command,
.help = "Turns on/off bad block information swaping from main area, " .help = "Turns on/off bad block information swapping from main area, "
"without parameter query status.", "without parameter query status.",
.usage = "bank_id ['enable'|'disable']", .usage = "bank_id ['enable'|'disable']",
}, },
@ -400,7 +400,7 @@ static int mxc_command(struct nand_device *nand, uint8_t command)
mxc_nf_info->optype = MXC_NF_DATAOUT_PAGE; mxc_nf_info->optype = MXC_NF_DATAOUT_PAGE;
break; break;
default: default:
/* Ohter command use the default 'One page data out' FDO */ /* Other command use the default 'One page data out' FDO */
mxc_nf_info->optype = MXC_NF_DATAOUT_PAGE; mxc_nf_info->optype = MXC_NF_DATAOUT_PAGE;
break; break;
} }
@ -502,10 +502,10 @@ static int mxc_write_page(struct nand_device *nand, uint32_t page,
if (oob) { if (oob) {
if (mxc_nf_info->flags.hw_ecc_enabled) { if (mxc_nf_info->flags.hw_ecc_enabled) {
/* /*
* part of spare block will be overrided by hardware * part of spare block will be overridden by hardware
* ECC generator * ECC generator
*/ */
LOG_DEBUG("part of spare block will be overrided " LOG_DEBUG("part of spare block will be overridden "
"by hardware ECC generator"); "by hardware ECC generator");
} }
if (nfc_is_v1()) if (nfc_is_v1())
@ -710,7 +710,7 @@ static int initialize_nf_controller(struct nand_device *nand)
uint16_t work_mode = 0; uint16_t work_mode = 0;
uint16_t temp; uint16_t temp;
/* /*
* resets NAND flash controller in zero time ? I dont know. * resets NAND flash controller in zero time ? I don't know.
*/ */
target_write_u16(target, MXC_NF_CFG1, MXC_NF_BIT_RESET_EN); target_write_u16(target, MXC_NF_CFG1, MXC_NF_BIT_RESET_EN);
if (mxc_nf_info->mxc_version == MXC_VERSION_MX27) if (mxc_nf_info->mxc_version == MXC_VERSION_MX27)

View File

@ -124,7 +124,7 @@ COMMAND_HANDLER(handle_nand_info_command)
bad_state = " (block condition unknown)"; bad_state = " (block condition unknown)";
command_print(CMD, command_print(CMD,
"\t#%i: 0x%8.8" PRIx32 " (%" PRId32 "kB) %s%s", "\t#%i: 0x%8.8" PRIx32 " (%" PRIu32 "kB) %s%s",
j, j,
p->blocks[j].offset, p->blocks[j].offset,
p->blocks[j].size / 1024, p->blocks[j].size / 1024,

View File

@ -57,13 +57,12 @@ static int aduc702x_build_sector_list(struct flash_bank *bank)
{ {
/* aduc7026_struct flash_bank *aduc7026_info = bank->driver_priv; */ /* aduc7026_struct flash_bank *aduc7026_info = bank->driver_priv; */
int i = 0;
uint32_t offset = 0; uint32_t offset = 0;
/* sector size is 512 */ /* sector size is 512 */
bank->num_sectors = bank->size / 512; bank->num_sectors = bank->size / 512;
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors); bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
for (i = 0; i < bank->num_sectors; ++i) { for (unsigned int i = 0; i < bank->num_sectors; ++i) {
bank->sectors[i].offset = offset; bank->sectors[i].offset = offset;
bank->sectors[i].size = 512; bank->sectors[i].size = 512;
offset += bank->sectors[i].size; offset += bank->sectors[i].size;
@ -74,7 +73,8 @@ static int aduc702x_build_sector_list(struct flash_bank *bank)
return ERROR_OK; return ERROR_OK;
} }
static int aduc702x_erase(struct flash_bank *bank, int first, int last) static int aduc702x_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
/* int res; */ /* int res; */
int x; int x;

View File

@ -85,13 +85,12 @@ FLASH_BANK_COMMAND_HANDLER(aducm360_flash_bank_command)
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
static int aducm360_build_sector_list(struct flash_bank *bank) static int aducm360_build_sector_list(struct flash_bank *bank)
{ {
int i = 0;
uint32_t offset = 0; uint32_t offset = 0;
/* sector size is 512 */ /* sector size is 512 */
bank->num_sectors = bank->size / FLASH_SECTOR_SIZE; bank->num_sectors = bank->size / FLASH_SECTOR_SIZE;
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors); bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
for (i = 0; i < bank->num_sectors; ++i) { for (unsigned i = 0; i < bank->num_sectors; ++i) {
bank->sectors[i].offset = offset; bank->sectors[i].offset = offset;
bank->sectors[i].size = FLASH_SECTOR_SIZE; bank->sectors[i].size = FLASH_SECTOR_SIZE;
offset += bank->sectors[i].size; offset += bank->sectors[i].size;
@ -164,7 +163,8 @@ static int aducm360_page_erase(struct target *target, uint32_t padd)
} }
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
static int aducm360_erase(struct flash_bank *bank, int first, int last) static int aducm360_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
int res = ERROR_OK; int res = ERROR_OK;
int i; int i;
@ -285,7 +285,7 @@ static int aducm360_write_block_sync(
res = buf_get_u32(reg_params[4].value, 0, 32); res = buf_get_u32(reg_params[4].value, 0, 32);
if (res) { if (res) {
LOG_ERROR("aducm360 fast sync algorithm reports an error (%02X)", res); LOG_ERROR("aducm360 fast sync algorithm reports an error (%02" PRIX32 ")", res);
retval = ERROR_FAIL; retval = ERROR_FAIL;
break; break;
} }
@ -401,7 +401,7 @@ static int aducm360_write_block_async(
} else { } else {
res = buf_get_u32(reg_params[4].value, 0, 32); /*RESULT*/ res = buf_get_u32(reg_params[4].value, 0, 32); /*RESULT*/
if (res) { if (res) {
LOG_ERROR("aducm360 fast async algorithm reports an error (%02X)", res); LOG_ERROR("aducm360 fast async algorithm reports an error (%02" PRIX32 ")", res);
retval = ERROR_FAIL; retval = ERROR_FAIL;
} }
} }

View File

@ -92,7 +92,7 @@ static const uint32_t apollo_sram_size[] = {
struct ambiqmicro_flash_bank { struct ambiqmicro_flash_bank {
/* chip id register */ /* chip id register */
uint32_t probed; bool probed;
const char *target_name; const char *target_name;
uint8_t target_class; uint8_t target_class;
@ -156,7 +156,7 @@ FLASH_BANK_COMMAND_HANDLER(ambiqmicro_flash_bank_command)
ambiqmicro_info->target_name = "Unknown target"; ambiqmicro_info->target_name = "Unknown target";
/* part wasn't probed yet */ /* part wasn't probed yet */
ambiqmicro_info->probed = 0; ambiqmicro_info->probed = false;
return ERROR_OK; return ERROR_OK;
} }
@ -167,7 +167,7 @@ static int get_ambiqmicro_info(struct flash_bank *bank, char *buf, int buf_size)
int printed; int printed;
char *classname; char *classname;
if (ambiqmicro_info->probed == 0) { if (!ambiqmicro_info->probed) {
LOG_ERROR("Target not probed"); LOG_ERROR("Target not probed");
return ERROR_FLASH_BANK_NOT_PROBED; return ERROR_FLASH_BANK_NOT_PROBED;
} }
@ -212,7 +212,7 @@ static int ambiqmicro_read_part_info(struct flash_bank *bank)
/* Set PartNum to default device */ /* Set PartNum to default device */
PartNum = 0; PartNum = 0;
} }
LOG_DEBUG("Part number: 0x%x", PartNum); LOG_DEBUG("Part number: 0x%" PRIx32, PartNum);
/* /*
* Determine device class. * Determine device class.
@ -260,7 +260,7 @@ static int ambiqmicro_read_part_info(struct flash_bank *bank)
ambiqmicro_info->target_name = ambiqmicro_info->target_name =
ambiqmicroParts[0].partname; ambiqmicroParts[0].partname;
LOG_DEBUG("num_pages: %d, pagesize: %d, flash: %d, sram: %d", LOG_DEBUG("num_pages: %" PRIu32 ", pagesize: %" PRIu32 ", flash: %" PRIu32 ", sram: %" PRIu32,
ambiqmicro_info->num_pages, ambiqmicro_info->num_pages,
ambiqmicro_info->pagesize, ambiqmicro_info->pagesize,
ambiqmicro_info->flshsiz, ambiqmicro_info->flshsiz,
@ -280,7 +280,7 @@ static int ambiqmicro_protect_check(struct flash_bank *bank)
uint32_t i; uint32_t i;
if (ambiqmicro->probed == 0) { if (!ambiqmicro->probed) {
LOG_ERROR("Target not probed"); LOG_ERROR("Target not probed");
return ERROR_FLASH_BANK_NOT_PROBED; return ERROR_FLASH_BANK_NOT_PROBED;
} }
@ -304,7 +304,7 @@ static int check_flash_status(struct target *target, uint32_t address)
} }
/* target flash failed, unknown cause. */ /* target flash failed, unknown cause. */
if (retflash != 0) { if (retflash != 0) {
LOG_ERROR("Flash not happy: status(0x%x)", retflash); LOG_ERROR("Flash not happy: status(0x%" PRIx32 ")", retflash);
return ERROR_FLASH_OPERATION_FAILED; return ERROR_FLASH_OPERATION_FAILED;
} }
return ERROR_OK; return ERROR_OK;
@ -371,7 +371,7 @@ static int ambiqmicro_mass_erase(struct flash_bank *bank)
return ERROR_TARGET_NOT_HALTED; return ERROR_TARGET_NOT_HALTED;
} }
if (ambiqmicro_info->probed == 0) { if (!ambiqmicro_info->probed) {
LOG_ERROR("Target not probed"); LOG_ERROR("Target not probed");
return ERROR_FLASH_BANK_NOT_PROBED; return ERROR_FLASH_BANK_NOT_PROBED;
} }
@ -427,18 +427,19 @@ static int ambiqmicro_mass_erase(struct flash_bank *bank)
} }
static int ambiqmicro_erase(struct flash_bank *bank, int first, int last) static int ambiqmicro_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct ambiqmicro_flash_bank *ambiqmicro_info = bank->driver_priv; struct ambiqmicro_flash_bank *ambiqmicro_info = bank->driver_priv;
struct target *target = bank->target; struct target *target = bank->target;
uint32_t retval = ERROR_OK; int retval;
if (bank->target->state != TARGET_HALTED) { if (bank->target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted"); LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED; return ERROR_TARGET_NOT_HALTED;
} }
if (ambiqmicro_info->probed == 0) { if (!ambiqmicro_info->probed) {
LOG_ERROR("Target not probed"); LOG_ERROR("Target not probed");
return ERROR_FLASH_BANK_NOT_PROBED; return ERROR_FLASH_BANK_NOT_PROBED;
} }
@ -447,14 +448,14 @@ static int ambiqmicro_erase(struct flash_bank *bank, int first, int last)
* Check pages. * Check pages.
* Fix num_pages for the device. * Fix num_pages for the device.
*/ */
if ((first < 0) || (last < first) || (last >= (int)ambiqmicro_info->num_pages)) if ((last < first) || (last >= ambiqmicro_info->num_pages))
return ERROR_FLASH_SECTOR_INVALID; return ERROR_FLASH_SECTOR_INVALID;
/* /*
* Just Mass Erase if all pages are given. * Just Mass Erase if all pages are given.
* TODO: Fix num_pages for the device * TODO: Fix num_pages for the device
*/ */
if ((first == 0) && (last == ((int)ambiqmicro_info->num_pages-1))) if ((first == 0) && (last == (ambiqmicro_info->num_pages - 1)))
return ambiqmicro_mass_erase(bank); return ambiqmicro_mass_erase(bank);
/* /*
@ -502,7 +503,7 @@ static int ambiqmicro_erase(struct flash_bank *bank, int first, int last)
/* /*
* Erase the pages. * Erase the pages.
*/ */
LOG_INFO("Erasing pages %d to %d on bank %d", first, last, bank->bank_number); LOG_INFO("Erasing pages %u to %u on bank %u", first, last, bank->bank_number);
/* /*
* passed pc, addr = ROM function, handle breakpoints, not debugging. * passed pc, addr = ROM function, handle breakpoints, not debugging.
@ -512,7 +513,7 @@ static int ambiqmicro_erase(struct flash_bank *bank, int first, int last)
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
LOG_INFO("%d pages erased!", 1+(last-first)); LOG_INFO("%u pages erased!", 1+(last-first));
if (first == 0) { if (first == 0) {
/* /*
@ -527,7 +528,8 @@ static int ambiqmicro_erase(struct flash_bank *bank, int first, int last)
return retval; return retval;
} }
static int ambiqmicro_protect(struct flash_bank *bank, int set, int first, int last) static int ambiqmicro_protect(struct flash_bank *bank, int set,
unsigned int first, unsigned int last)
{ {
/* struct ambiqmicro_flash_bank *ambiqmicro_info = bank->driver_priv; /* struct ambiqmicro_flash_bank *ambiqmicro_info = bank->driver_priv;
* struct target *target = bank->target; */ * struct target *target = bank->target; */
@ -613,7 +615,7 @@ static int ambiqmicro_write_block(struct flash_bank *bank,
break; break;
} }
LOG_DEBUG("address = 0x%08x", address); LOG_DEBUG("address = 0x%08" PRIx32, address);
retval = ambiqmicro_exec_command(target, FLASH_PROGRAM_MAIN_FROM_SRAM, 0x1000000c); retval = ambiqmicro_exec_command(target, FLASH_PROGRAM_MAIN_FROM_SRAM, 0x1000000c);
CHECK_STATUS(retval, "error executing ambiqmicro flash write algorithm"); CHECK_STATUS(retval, "error executing ambiqmicro flash write algorithm");
@ -639,7 +641,7 @@ static int ambiqmicro_write_block(struct flash_bank *bank,
static int ambiqmicro_write(struct flash_bank *bank, const uint8_t *buffer, static int ambiqmicro_write(struct flash_bank *bank, const uint8_t *buffer,
uint32_t offset, uint32_t count) uint32_t offset, uint32_t count)
{ {
uint32_t retval; int retval;
/* try using a block write */ /* try using a block write */
retval = ambiqmicro_write_block(bank, buffer, offset, count); retval = ambiqmicro_write_block(bank, buffer, offset, count);
@ -652,12 +654,12 @@ static int ambiqmicro_write(struct flash_bank *bank, const uint8_t *buffer,
static int ambiqmicro_probe(struct flash_bank *bank) static int ambiqmicro_probe(struct flash_bank *bank)
{ {
struct ambiqmicro_flash_bank *ambiqmicro_info = bank->driver_priv; struct ambiqmicro_flash_bank *ambiqmicro_info = bank->driver_priv;
uint32_t retval; int retval;
/* If this is a ambiqmicro chip, it has flash; probe() is just /* If this is a ambiqmicro chip, it has flash; probe() is just
* to figure out how much is present. Only do it once. * to figure out how much is present. Only do it once.
*/ */
if (ambiqmicro_info->probed == 1) { if (ambiqmicro_info->probed) {
LOG_INFO("Target already probed"); LOG_INFO("Target already probed");
return ERROR_OK; return ERROR_OK;
} }
@ -670,16 +672,13 @@ static int ambiqmicro_probe(struct flash_bank *bank)
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
if (bank->sectors) { free(bank->sectors);
free(bank->sectors);
bank->sectors = NULL;
}
/* provide this for the benefit of the NOR flash framework */ /* provide this for the benefit of the NOR flash framework */
bank->size = ambiqmicro_info->pagesize * ambiqmicro_info->num_pages; bank->size = ambiqmicro_info->pagesize * ambiqmicro_info->num_pages;
bank->num_sectors = ambiqmicro_info->num_pages; bank->num_sectors = ambiqmicro_info->num_pages;
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors); bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
for (int i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].offset = i * ambiqmicro_info->pagesize; bank->sectors[i].offset = i * ambiqmicro_info->pagesize;
bank->sectors[i].size = ambiqmicro_info->pagesize; bank->sectors[i].size = ambiqmicro_info->pagesize;
bank->sectors[i].is_erased = -1; bank->sectors[i].is_erased = -1;
@ -689,7 +688,7 @@ static int ambiqmicro_probe(struct flash_bank *bank)
/* /*
* Part has been probed. * Part has been probed.
*/ */
ambiqmicro_info->probed = 1; ambiqmicro_info->probed = true;
return retval; return retval;
} }
@ -699,7 +698,7 @@ static int ambiqmicro_otp_program(struct flash_bank *bank,
{ {
struct target *target = NULL; struct target *target = NULL;
struct ambiqmicro_flash_bank *ambiqmicro_info = NULL; struct ambiqmicro_flash_bank *ambiqmicro_info = NULL;
uint32_t retval = ERROR_OK; int retval;
ambiqmicro_info = bank->driver_priv; ambiqmicro_info = bank->driver_priv;
target = bank->target; target = bank->target;
@ -709,7 +708,7 @@ static int ambiqmicro_otp_program(struct flash_bank *bank,
return ERROR_TARGET_NOT_HALTED; return ERROR_TARGET_NOT_HALTED;
} }
if (ambiqmicro_info->probed == 0) { if (!ambiqmicro_info->probed) {
LOG_ERROR("Target not probed"); LOG_ERROR("Target not probed");
return ERROR_FLASH_BANK_NOT_PROBED; return ERROR_FLASH_BANK_NOT_PROBED;
} }
@ -758,7 +757,7 @@ static int ambiqmicro_otp_program(struct flash_bank *bank,
/* /*
* Program OTP. * Program OTP.
*/ */
LOG_INFO("Programming OTP offset 0x%08x", offset); LOG_INFO("Programming OTP offset 0x%08" PRIx32, offset);
/* /*
* passed pc, addr = ROM function, handle breakpoints, not debugging. * passed pc, addr = ROM function, handle breakpoints, not debugging.
@ -775,19 +774,17 @@ static int ambiqmicro_otp_program(struct flash_bank *bank,
COMMAND_HANDLER(ambiqmicro_handle_mass_erase_command) COMMAND_HANDLER(ambiqmicro_handle_mass_erase_command)
{ {
int i;
if (CMD_ARGC < 1) if (CMD_ARGC < 1)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
struct flash_bank *bank; struct flash_bank *bank;
uint32_t retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank); int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
if (ERROR_OK != retval) if (ERROR_OK != retval)
return retval; return retval;
if (ambiqmicro_mass_erase(bank) == ERROR_OK) { if (ambiqmicro_mass_erase(bank) == ERROR_OK) {
/* set all sectors as erased */ /* set all sectors as erased */
for (i = 0; i < bank->num_sectors; i++) for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 1; bank->sectors[i].is_erased = 1;
command_print(CMD, "ambiqmicro mass erase complete"); command_print(CMD, "ambiqmicro mass erase complete");
@ -801,7 +798,7 @@ COMMAND_HANDLER(ambiqmicro_handle_page_erase_command)
{ {
struct flash_bank *bank; struct flash_bank *bank;
uint32_t first, last; uint32_t first, last;
uint32_t retval; int retval;
if (CMD_ARGC < 3) if (CMD_ARGC < 3)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
@ -829,7 +826,7 @@ COMMAND_HANDLER(ambiqmicro_handle_program_otp_command)
{ {
struct flash_bank *bank; struct flash_bank *bank;
uint32_t offset, count; uint32_t offset, count;
uint32_t retval; int retval;
if (CMD_ARGC < 3) if (CMD_ARGC < 3)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
@ -837,7 +834,7 @@ COMMAND_HANDLER(ambiqmicro_handle_program_otp_command)
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], offset); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], offset);
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], count); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], count);
command_print(CMD, "offset=0x%08x count=%d", offset, count); command_print(CMD, "offset=0x%08" PRIx32 " count=%" PRIu32, offset, count);
CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank); CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);

View File

@ -21,7 +21,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * * along with this program. If not, see <http://www.gnu.org/licenses/>. *
****************************************************************************/ ****************************************************************************/
/* Some of the the lower level code was based on code supplied by /* Some of the lower level code was based on code supplied by
* ATMEL under this copyright. */ * ATMEL under this copyright. */
/* BEGIN ATMEL COPYRIGHT */ /* BEGIN ATMEL COPYRIGHT */
@ -187,7 +187,7 @@ struct sam3_cfg {
*/ */
struct sam3_bank_private { struct sam3_bank_private {
int probed; bool probed;
/* DANGER: THERE ARE DRAGONS HERE.. */ /* DANGER: THERE ARE DRAGONS HERE.. */
/* NOTE: If you add more 'ghost' pointers */ /* NOTE: If you add more 'ghost' pointers */
/* be aware that you must *manually* update */ /* be aware that you must *manually* update */
@ -233,7 +233,7 @@ struct sam3_chip_details {
struct sam3_chip { struct sam3_chip {
struct sam3_chip *next; struct sam3_chip *next;
int probed; bool probed;
/* this is "initialized" from the global const structure */ /* this is "initialized" from the global const structure */
struct sam3_chip_details details; struct sam3_chip_details details;
@ -306,7 +306,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -322,7 +322,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 1, .bank_number = 1,
@ -357,7 +357,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -373,7 +373,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.present = 0, .present = 0,
.probed = 0, .probed = false,
.bank_number = 1, .bank_number = 1,
}, },
}, },
@ -399,7 +399,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -416,7 +416,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.present = 0, .present = 0,
.probed = 0, .probed = false,
.bank_number = 1, .bank_number = 1,
}, },
}, },
@ -448,7 +448,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
{ {
{ {
/* .bank[0] = { */ /* .bank[0] = { */
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -463,7 +463,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
}, },
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 1, .bank_number = 1,
@ -498,7 +498,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
{ {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -514,7 +514,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.present = 0, .present = 0,
.probed = 0, .probed = false,
.bank_number = 1, .bank_number = 1,
}, },
}, },
@ -540,7 +540,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
{ {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -556,7 +556,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.present = 0, .present = 0,
.probed = 0, .probed = false,
.bank_number = 1, .bank_number = 1,
}, },
@ -578,7 +578,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
{ {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -594,7 +594,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.present = 0, .present = 0,
.probed = 0, .probed = false,
.bank_number = 1, .bank_number = 1,
}, },
@ -611,7 +611,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
{ {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -627,7 +627,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.present = 0, .present = 0,
.probed = 0, .probed = false,
.bank_number = 1, .bank_number = 1,
}, },
@ -643,7 +643,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
{ {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -659,7 +659,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.present = 0, .present = 0,
.probed = 0, .probed = false,
.bank_number = 1, .bank_number = 1,
}, },
@ -675,7 +675,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
{ {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -691,7 +691,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.present = 0, .present = 0,
.probed = 0, .probed = false,
.bank_number = 1, .bank_number = 1,
}, },
@ -707,7 +707,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
{ {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -723,7 +723,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.present = 0, .present = 0,
.probed = 0, .probed = false,
.bank_number = 1, .bank_number = 1,
}, },
@ -739,7 +739,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
{ {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -754,7 +754,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
}, },
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 1, .bank_number = 1,
@ -779,7 +779,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
{ {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -794,7 +794,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
}, },
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 1, .bank_number = 1,
@ -819,7 +819,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
{ {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -834,7 +834,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
}, },
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 1, .bank_number = 1,
@ -859,7 +859,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
{ {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -875,7 +875,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.present = 0, .present = 0,
.probed = 0, .probed = false,
.bank_number = 1, .bank_number = 1,
}, },
@ -891,7 +891,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
{ {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -907,7 +907,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.present = 0, .present = 0,
.probed = 0, .probed = false,
.bank_number = 1, .bank_number = 1,
}, },
@ -923,7 +923,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
{ {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -939,7 +939,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.present = 0, .present = 0,
.probed = 0, .probed = false,
.bank_number = 1, .bank_number = 1,
}, },
@ -955,7 +955,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
{ {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -971,7 +971,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.present = 0, .present = 0,
.probed = 0, .probed = false,
.bank_number = 1, .bank_number = 1,
}, },
@ -987,7 +987,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
{ {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -1003,7 +1003,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.present = 0, .present = 0,
.probed = 0, .probed = false,
.bank_number = 1, .bank_number = 1,
}, },
@ -1019,7 +1019,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
{ {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -1035,7 +1035,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.present = 0, .present = 0,
.probed = 0, .probed = false,
.bank_number = 1, .bank_number = 1,
}, },
@ -1051,7 +1051,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
{ {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -1067,7 +1067,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.present = 0, .present = 0,
.probed = 0, .probed = false,
.bank_number = 1, .bank_number = 1,
}, },
@ -1101,7 +1101,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -1118,7 +1118,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.present = 0, .present = 0,
.probed = 0, .probed = false,
.bank_number = 1, .bank_number = 1,
}, },
}, },
@ -1150,7 +1150,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -1167,7 +1167,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.present = 0, .present = 0,
.probed = 0, .probed = false,
.bank_number = 1, .bank_number = 1,
}, },
}, },
@ -1199,7 +1199,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -1216,7 +1216,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.present = 0, .present = 0,
.probed = 0, .probed = false,
.bank_number = 1, .bank_number = 1,
}, },
}, },
@ -1248,7 +1248,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -1265,7 +1265,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.present = 0, .present = 0,
.probed = 0, .probed = false,
.bank_number = 1, .bank_number = 1,
}, },
}, },
@ -1297,7 +1297,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -1314,7 +1314,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.present = 0, .present = 0,
.probed = 0, .probed = false,
.bank_number = 1, .bank_number = 1,
}, },
}, },
@ -1346,7 +1346,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -1363,7 +1363,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.present = 0, .present = 0,
.probed = 0, .probed = false,
.bank_number = 1, .bank_number = 1,
}, },
}, },
@ -1395,7 +1395,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -1412,7 +1412,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.present = 0, .present = 0,
.probed = 0, .probed = false,
.bank_number = 1, .bank_number = 1,
}, },
}, },
@ -1444,7 +1444,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -1461,7 +1461,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.present = 0, .present = 0,
.probed = 0, .probed = false,
.bank_number = 1, .bank_number = 1,
}, },
}, },
@ -1493,7 +1493,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -1510,7 +1510,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.present = 0, .present = 0,
.probed = 0, .probed = false,
.bank_number = 1, .bank_number = 1,
}, },
}, },
@ -1527,7 +1527,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -1544,7 +1544,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.present = 0, .present = 0,
.probed = 0, .probed = false,
.bank_number = 1, .bank_number = 1,
}, },
}, },
@ -1561,7 +1561,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -1578,7 +1578,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.present = 0, .present = 0,
.probed = 0, .probed = false,
.bank_number = 1, .bank_number = 1,
}, },
}, },
@ -1595,7 +1595,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -1612,7 +1612,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.present = 0, .present = 0,
.probed = 0, .probed = false,
.bank_number = 1, .bank_number = 1,
}, },
}, },
@ -1629,7 +1629,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -1646,7 +1646,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.present = 0, .present = 0,
.probed = 0, .probed = false,
.bank_number = 1, .bank_number = 1,
}, },
}, },
@ -1680,7 +1680,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
{ {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -1695,7 +1695,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
}, },
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 1, .bank_number = 1,
@ -1721,7 +1721,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
{ {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -1736,7 +1736,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
}, },
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 1, .bank_number = 1,
@ -1780,7 +1780,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
{ {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -1795,7 +1795,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
}, },
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 1, .bank_number = 1,
@ -1822,7 +1822,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
{ {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -1837,7 +1837,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
}, },
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 1, .bank_number = 1,
@ -1863,7 +1863,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
{ {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -1878,7 +1878,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
}, },
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 1, .bank_number = 1,
@ -1904,7 +1904,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
{ {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -1919,11 +1919,11 @@ static const struct sam3_chip_details all_sam3_details[] = {
}, },
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 1, .bank_number = 1,
.base_address = FLASH_BANK1_BASE_512K_AX , .base_address = FLASH_BANK1_BASE_512K_AX,
.controller_address = 0x400e0c00, .controller_address = 0x400e0c00,
.flash_wait_states = 6, /* workaround silicon bug */ .flash_wait_states = 6, /* workaround silicon bug */
.present = 1, .present = 1,
@ -1945,7 +1945,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
{ {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -1960,7 +1960,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
}, },
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 1, .bank_number = 1,
@ -1986,7 +1986,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
{ {
/* .bank[0] = { */ /* .bank[0] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 0, .bank_number = 0,
@ -2001,7 +2001,7 @@ static const struct sam3_chip_details all_sam3_details[] = {
}, },
/* .bank[1] = { */ /* .bank[1] = { */
{ {
.probed = 0, .probed = false,
.pChip = NULL, .pChip = NULL,
.pBank = NULL, .pBank = NULL,
.bank_number = 1, .bank_number = 1,
@ -3051,7 +3051,7 @@ FLASH_BANK_COMMAND_HANDLER(sam3_flash_bank_command)
pChip->target = bank->target; pChip->target = bank->target;
/* assumption is this runs at 32khz */ /* assumption is this runs at 32khz */
pChip->cfg.slow_freq = 32768; pChip->cfg.slow_freq = 32768;
pChip->probed = 0; pChip->probed = false;
} }
switch (bank->base) { switch (bank->base) {
@ -3095,7 +3095,7 @@ FLASH_BANK_COMMAND_HANDLER(sam3_flash_bank_command)
} }
/** /**
* Remove all chips from the internal list without distingushing which one * Remove all chips from the internal list without distinguishing which one
* is owned by this bank. This simplification works only for one shot * is owned by this bank. This simplification works only for one shot
* deallocation like current flash_free_all_banks() * deallocation like current flash_free_all_banks()
*/ */
@ -3171,12 +3171,11 @@ static int sam3_GetDetails(struct sam3_bank_private *pPrivate)
static int _sam3_probe(struct flash_bank *bank, int noise) static int _sam3_probe(struct flash_bank *bank, int noise)
{ {
unsigned x;
int r; int r;
struct sam3_bank_private *pPrivate; struct sam3_bank_private *pPrivate;
LOG_DEBUG("Begin: Bank: %d, Noise: %d", bank->bank_number, noise); LOG_DEBUG("Begin: Bank: %u, Noise: %d", bank->bank_number, noise);
if (bank->target->state != TARGET_HALTED) { if (bank->target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted"); LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED; return ERROR_TARGET_NOT_HALTED;
@ -3201,7 +3200,7 @@ static int _sam3_probe(struct flash_bank *bank, int noise)
return r; return r;
/* update the flash bank size */ /* update the flash bank size */
for (x = 0; x < SAM3_MAX_FLASH_BANKS; x++) { for (unsigned int x = 0; x < SAM3_MAX_FLASH_BANKS; x++) {
if (bank->base == pPrivate->pChip->details.bank[x].base_address) { if (bank->base == pPrivate->pChip->details.bank[x].base_address) {
bank->size = pPrivate->pChip->details.bank[x].size_bytes; bank->size = pPrivate->pChip->details.bank[x].size_bytes;
break; break;
@ -3216,7 +3215,7 @@ static int _sam3_probe(struct flash_bank *bank, int noise)
} }
bank->num_sectors = pPrivate->nsectors; bank->num_sectors = pPrivate->nsectors;
for (x = 0; ((int)(x)) < bank->num_sectors; x++) { for (unsigned int x = 0; x < bank->num_sectors; x++) {
bank->sectors[x].size = pPrivate->sector_size; bank->sectors[x].size = pPrivate->sector_size;
bank->sectors[x].offset = x * (pPrivate->sector_size); bank->sectors[x].offset = x * (pPrivate->sector_size);
/* mark as unknown */ /* mark as unknown */
@ -3225,7 +3224,7 @@ static int _sam3_probe(struct flash_bank *bank, int noise)
} }
} }
pPrivate->probed = 1; pPrivate->probed = true;
r = sam3_protect_check(bank); r = sam3_protect_check(bank);
if (r != ERROR_OK) if (r != ERROR_OK)
@ -3252,7 +3251,8 @@ static int sam3_auto_probe(struct flash_bank *bank)
return _sam3_probe(bank, 0); return _sam3_probe(bank, 0);
} }
static int sam3_erase(struct flash_bank *bank, int first, int last) static int sam3_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct sam3_bank_private *pPrivate; struct sam3_bank_private *pPrivate;
int r; int r;
@ -3273,7 +3273,7 @@ static int sam3_erase(struct flash_bank *bank, int first, int last)
if (!(pPrivate->probed)) if (!(pPrivate->probed))
return ERROR_FLASH_BANK_NOT_PROBED; return ERROR_FLASH_BANK_NOT_PROBED;
if ((first == 0) && ((last + 1) == ((int)(pPrivate->nsectors)))) { if ((first == 0) && ((last + 1) == pPrivate->nsectors)) {
/* whole chip */ /* whole chip */
LOG_DEBUG("Here"); LOG_DEBUG("Here");
return FLASHD_EraseEntireBank(pPrivate); return FLASHD_EraseEntireBank(pPrivate);
@ -3282,7 +3282,8 @@ static int sam3_erase(struct flash_bank *bank, int first, int last)
return ERROR_OK; return ERROR_OK;
} }
static int sam3_protect(struct flash_bank *bank, int set, int first, int last) static int sam3_protect(struct flash_bank *bank, int set, unsigned int first,
unsigned int last)
{ {
struct sam3_bank_private *pPrivate; struct sam3_bank_private *pPrivate;
int r; int r;
@ -3298,9 +3299,9 @@ static int sam3_protect(struct flash_bank *bank, int set, int first, int last)
return ERROR_FLASH_BANK_NOT_PROBED; return ERROR_FLASH_BANK_NOT_PROBED;
if (set) if (set)
r = FLASHD_Lock(pPrivate, (unsigned)(first), (unsigned)(last)); r = FLASHD_Lock(pPrivate, first, last);
else else
r = FLASHD_Unlock(pPrivate, (unsigned)(first), (unsigned)(last)); r = FLASHD_Unlock(pPrivate, first, last);
LOG_DEBUG("End: r=%d", r); LOG_DEBUG("End: r=%d", r);
return r; return r;
@ -3397,7 +3398,7 @@ static int sam3_write(struct flash_bank *bank,
struct sam3_bank_private *pPrivate; struct sam3_bank_private *pPrivate;
uint8_t *pagebuffer; uint8_t *pagebuffer;
/* incase we bail further below, set this to null */ /* in case we bail further below, set this to null */
pagebuffer = NULL; pagebuffer = NULL;
/* ignore dumb requests */ /* ignore dumb requests */
@ -3529,8 +3530,7 @@ static int sam3_write(struct flash_bank *bank,
LOG_DEBUG("Done!"); LOG_DEBUG("Done!");
r = ERROR_OK; r = ERROR_OK;
done: done:
if (pagebuffer) free(pagebuffer);
free(pagebuffer);
return r; return r;
} }

File diff suppressed because it is too large Load Diff

View File

@ -125,7 +125,7 @@ struct sam4l_info {
uint32_t page_size; uint32_t page_size;
int num_pages; int num_pages;
int sector_size; int sector_size;
int pages_per_sector; unsigned int pages_per_sector;
bool probed; bool probed;
struct target *target; struct target *target;
@ -335,7 +335,7 @@ static int sam4l_probe(struct flash_bank *bank)
/* Fill out the sector information: all SAM4L sectors are the same size and /* Fill out the sector information: all SAM4L sectors are the same size and
* there is always a fixed number of them. */ * there is always a fixed number of them. */
for (int i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].size = chip->sector_size; bank->sectors[i].size = chip->sector_size;
bank->sectors[i].offset = i * chip->sector_size; bank->sectors[i].offset = i * chip->sector_size;
/* mark as unknown */ /* mark as unknown */
@ -346,7 +346,7 @@ static int sam4l_probe(struct flash_bank *bank)
/* Done */ /* Done */
chip->probed = true; chip->probed = true;
LOG_INFO("SAM4L MCU: %s (Rev %c) (%" PRIu32 "KB Flash with %d %" PRId32 "B pages, %" PRIu32 "KB RAM)", LOG_INFO("SAM4L MCU: %s (Rev %c) (%" PRIu32 "KB Flash with %d %" PRIu32 "B pages, %" PRIu32 "KB RAM)",
chip->details ? chip->details->name : "unknown", (char)('A' + (id & 0xF)), chip->details ? chip->details->name : "unknown", (char)('A' + (id & 0xF)),
chip->flash_kb, chip->num_pages, chip->page_size, chip->ram_kb); chip->flash_kb, chip->num_pages, chip->page_size, chip->ram_kb);
@ -375,13 +375,14 @@ static int sam4l_protect_check(struct flash_bank *bank)
return res; return res;
st >>= 16; /* There are 16 lock region bits in the upper half word */ st >>= 16; /* There are 16 lock region bits in the upper half word */
for (int i = 0; i < bank->num_sectors; i++) for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_protected = !!(st & (1<<i)); bank->sectors[i].is_protected = !!(st & (1<<i));
return ERROR_OK; return ERROR_OK;
} }
static int sam4l_protect(struct flash_bank *bank, int set, int first, int last) static int sam4l_protect(struct flash_bank *bank, int set, unsigned int first,
unsigned int last)
{ {
struct sam4l_info *chip = (struct sam4l_info *)bank->driver_priv; struct sam4l_info *chip = (struct sam4l_info *)bank->driver_priv;
@ -398,7 +399,7 @@ static int sam4l_protect(struct flash_bank *bank, int set, int first, int last)
/* Make sure the pages make sense. */ /* Make sure the pages make sense. */
if (first >= bank->num_sectors || last >= bank->num_sectors) { if (first >= bank->num_sectors || last >= bank->num_sectors) {
LOG_ERROR("Protect range %d - %d not valid (%d sectors total)", first, last, LOG_ERROR("Protect range %u - %u not valid (%u sectors total)", first, last,
bank->num_sectors); bank->num_sectors);
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -406,7 +407,7 @@ static int sam4l_protect(struct flash_bank *bank, int set, int first, int last)
/* Try to lock or unlock each sector in the range. This is done by locking /* Try to lock or unlock each sector in the range. This is done by locking
* a region containing one page in that sector, we arbitrarily choose the 0th * a region containing one page in that sector, we arbitrarily choose the 0th
* page in the sector. */ * page in the sector. */
for (int i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
int res; int res;
res = sam4l_flash_command(bank->target, res = sam4l_flash_command(bank->target,
@ -420,7 +421,8 @@ static int sam4l_protect(struct flash_bank *bank, int set, int first, int last)
return ERROR_OK; return ERROR_OK;
} }
static int sam4l_erase(struct flash_bank *bank, int first, int last) static int sam4l_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
int ret; int ret;
struct sam4l_info *chip = (struct sam4l_info *)bank->driver_priv; struct sam4l_info *chip = (struct sam4l_info *)bank->driver_priv;
@ -438,7 +440,7 @@ static int sam4l_erase(struct flash_bank *bank, int first, int last)
/* Make sure the pages make sense. */ /* Make sure the pages make sense. */
if (first >= bank->num_sectors || last >= bank->num_sectors) { if (first >= bank->num_sectors || last >= bank->num_sectors) {
LOG_ERROR("Erase range %d - %d not valid (%d sectors total)", first, last, LOG_ERROR("Erase range %u - %u not valid (%u sectors total)", first, last,
bank->num_sectors); bank->num_sectors);
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -453,19 +455,19 @@ static int sam4l_erase(struct flash_bank *bank, int first, int last)
return ret; return ret;
} }
} else { } else {
LOG_DEBUG("Erasing sectors %d through %d...\n", first, last); LOG_DEBUG("Erasing sectors %u through %u...\n", first, last);
/* For each sector... */ /* For each sector... */
for (int i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
/* For each page in that sector... */ /* For each page in that sector... */
for (int j = 0; j < chip->pages_per_sector; j++) { for (unsigned int j = 0; j < chip->pages_per_sector; j++) {
int pn = i * chip->pages_per_sector + j; unsigned int pn = i * chip->pages_per_sector + j;
bool is_erased = false; bool is_erased = false;
/* Issue the page erase */ /* Issue the page erase */
ret = sam4l_flash_command(bank->target, SAM4L_FCMD_EP, pn); ret = sam4l_flash_command(bank->target, SAM4L_FCMD_EP, pn);
if (ret != ERROR_OK) { if (ret != ERROR_OK) {
LOG_ERROR("Erasing page %d failed", pn); LOG_ERROR("Erasing page %u failed", pn);
return ret; return ret;
} }
@ -474,7 +476,7 @@ static int sam4l_erase(struct flash_bank *bank, int first, int last)
return ret; return ret;
if (!is_erased) { if (!is_erased) {
LOG_DEBUG("Page %d was not erased.", pn); LOG_DEBUG("Page %u was not erased.", pn);
return ERROR_FAIL; return ERROR_FAIL;
} }
} }

View File

@ -254,7 +254,7 @@ static void at91sam7_read_clock_info(struct flash_bank *bank)
at91sam7_info->mck_freq = tmp; at91sam7_info->mck_freq = tmp;
} }
/* Setup the timimg registers for nvbits or normal flash */ /* Setup the timing registers for nvbits or normal flash */
static void at91sam7_set_flash_mode(struct flash_bank *bank, int mode) static void at91sam7_set_flash_mode(struct flash_bank *bank, int mode)
{ {
uint32_t fmr, fmcn = 0, fws = 0; uint32_t fmr, fmcn = 0, fws = 0;
@ -377,7 +377,7 @@ static int at91sam7_read_part_info(struct flash_bank *bank)
/* re-calculate master clock frequency */ /* re-calculate master clock frequency */
at91sam7_read_clock_info(t_bank); at91sam7_read_clock_info(t_bank);
/* no timming */ /* no timing */
at91sam7_set_flash_mode(t_bank, FMR_TIMING_NONE); at91sam7_set_flash_mode(t_bank, FMR_TIMING_NONE);
/* check protect state */ /* check protect state */
@ -415,7 +415,7 @@ static int at91sam7_read_part_info(struct flash_bank *bank)
/* calculate master clock frequency */ /* calculate master clock frequency */
at91sam7_read_clock_info(t_bank); at91sam7_read_clock_info(t_bank);
/* no timming */ /* no timing */
at91sam7_set_flash_mode(t_bank, FMR_TIMING_NONE); at91sam7_set_flash_mode(t_bank, FMR_TIMING_NONE);
/* check protect state */ /* check protect state */
@ -623,7 +623,7 @@ static int at91sam7_read_part_info(struct flash_bank *bank)
/* calculate master clock frequency */ /* calculate master clock frequency */
at91sam7_read_clock_info(t_bank); at91sam7_read_clock_info(t_bank);
/* no timming */ /* no timing */
at91sam7_set_flash_mode(t_bank, FMR_TIMING_NONE); at91sam7_set_flash_mode(t_bank, FMR_TIMING_NONE);
/* check protect state */ /* check protect state */
@ -702,17 +702,15 @@ FLASH_BANK_COMMAND_HANDLER(at91sam7_flash_bank_command)
uint32_t bank_size; uint32_t bank_size;
uint32_t ext_freq = 0; uint32_t ext_freq = 0;
int chip_width; unsigned int chip_width;
int bus_width; unsigned int bus_width;
int banks_num; unsigned int banks_num;
int num_sectors; unsigned int num_sectors;
uint16_t pages_per_sector; uint16_t pages_per_sector;
uint16_t page_size; uint16_t page_size;
uint16_t num_nvmbits; uint16_t num_nvmbits;
int bnk, sec;
at91sam7_info = malloc(sizeof(struct at91sam7_flash_bank)); at91sam7_info = malloc(sizeof(struct at91sam7_flash_bank));
t_bank->driver_priv = at91sam7_info; t_bank->driver_priv = at91sam7_info;
@ -729,11 +727,11 @@ FLASH_BANK_COMMAND_HANDLER(at91sam7_flash_bank_command)
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], base_address); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], base_address);
COMMAND_PARSE_NUMBER(int, CMD_ARGV[3], chip_width); COMMAND_PARSE_NUMBER(uint, CMD_ARGV[3], chip_width);
COMMAND_PARSE_NUMBER(int, CMD_ARGV[4], bus_width); COMMAND_PARSE_NUMBER(uint, CMD_ARGV[4], bus_width);
COMMAND_PARSE_NUMBER(int, CMD_ARGV[8], banks_num); COMMAND_PARSE_NUMBER(uint, CMD_ARGV[8], banks_num);
COMMAND_PARSE_NUMBER(int, CMD_ARGV[9], num_sectors); COMMAND_PARSE_NUMBER(uint, CMD_ARGV[9], num_sectors);
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[10], pages_per_sector); COMMAND_PARSE_NUMBER(u16, CMD_ARGV[10], pages_per_sector);
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[11], page_size); COMMAND_PARSE_NUMBER(u16, CMD_ARGV[11], page_size);
COMMAND_PARSE_NUMBER(u16, CMD_ARGV[12], num_nvmbits); COMMAND_PARSE_NUMBER(u16, CMD_ARGV[12], num_nvmbits);
@ -754,7 +752,7 @@ FLASH_BANK_COMMAND_HANDLER(at91sam7_flash_bank_command)
/* calculate bank size */ /* calculate bank size */
bank_size = num_sectors * pages_per_sector * page_size; bank_size = num_sectors * pages_per_sector * page_size;
for (bnk = 0; bnk < banks_num; bnk++) { for (unsigned int bnk = 0; bnk < banks_num; bnk++) {
if (bnk > 0) { if (bnk > 0) {
if (!t_bank->next) { if (!t_bank->next) {
/* create a new bank element */ /* create a new bank element */
@ -780,7 +778,7 @@ FLASH_BANK_COMMAND_HANDLER(at91sam7_flash_bank_command)
/* allocate sectors */ /* allocate sectors */
t_bank->sectors = malloc(num_sectors * sizeof(struct flash_sector)); t_bank->sectors = malloc(num_sectors * sizeof(struct flash_sector));
for (sec = 0; sec < num_sectors; sec++) { for (unsigned int sec = 0; sec < num_sectors; sec++) {
t_bank->sectors[sec].offset = sec * pages_per_sector * page_size; t_bank->sectors[sec].offset = sec * pages_per_sector * page_size;
t_bank->sectors[sec].size = pages_per_sector * page_size; t_bank->sectors[sec].size = pages_per_sector * page_size;
t_bank->sectors[sec].is_erased = -1; t_bank->sectors[sec].is_erased = -1;
@ -801,10 +799,10 @@ FLASH_BANK_COMMAND_HANDLER(at91sam7_flash_bank_command)
return ERROR_OK; return ERROR_OK;
} }
static int at91sam7_erase(struct flash_bank *bank, int first, int last) static int at91sam7_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct at91sam7_flash_bank *at91sam7_info = bank->driver_priv; struct at91sam7_flash_bank *at91sam7_info = bank->driver_priv;
int sec;
uint32_t nbytes, pos; uint32_t nbytes, pos;
uint8_t *buffer; uint8_t *buffer;
uint8_t erase_all; uint8_t erase_all;
@ -817,7 +815,7 @@ static int at91sam7_erase(struct flash_bank *bank, int first, int last)
return ERROR_TARGET_NOT_HALTED; return ERROR_TARGET_NOT_HALTED;
} }
if ((first < 0) || (last < first) || (last >= bank->num_sectors)) if ((last < first) || (last >= bank->num_sectors))
return ERROR_FLASH_SECTOR_INVALID; return ERROR_FLASH_SECTOR_INVALID;
erase_all = 0; erase_all = 0;
@ -847,16 +845,16 @@ static int at91sam7_erase(struct flash_bank *bank, int first, int last)
} }
/* mark erased sectors */ /* mark erased sectors */
for (sec = first; sec <= last; sec++) for (unsigned int sec = first; sec <= last; sec++)
bank->sectors[sec].is_erased = 1; bank->sectors[sec].is_erased = 1;
return ERROR_OK; return ERROR_OK;
} }
static int at91sam7_protect(struct flash_bank *bank, int set, int first, int last) static int at91sam7_protect(struct flash_bank *bank, int set,
unsigned int first, unsigned int last)
{ {
uint32_t cmd; uint32_t cmd;
int sector;
uint32_t pagen; uint32_t pagen;
struct at91sam7_flash_bank *at91sam7_info = bank->driver_priv; struct at91sam7_flash_bank *at91sam7_info = bank->driver_priv;
@ -869,14 +867,14 @@ static int at91sam7_protect(struct flash_bank *bank, int set, int first, int las
return ERROR_TARGET_NOT_HALTED; return ERROR_TARGET_NOT_HALTED;
} }
if ((first < 0) || (last < first) || (last >= bank->num_sectors)) if ((last < first) || (last >= bank->num_sectors))
return ERROR_FLASH_SECTOR_INVALID; return ERROR_FLASH_SECTOR_INVALID;
/* Configure the flash controller timing */ /* Configure the flash controller timing */
at91sam7_read_clock_info(bank); at91sam7_read_clock_info(bank);
at91sam7_set_flash_mode(bank, FMR_TIMING_NVBITS); at91sam7_set_flash_mode(bank, FMR_TIMING_NVBITS);
for (sector = first; sector <= last; sector++) { for (unsigned int sector = first; sector <= last; sector++) {
if (set) if (set)
cmd = SLB; cmd = SLB;
else else
@ -956,7 +954,7 @@ static int at91sam7_write(struct flash_bank *bank, const uint8_t *buffer, uint32
/* Send Write Page command to Flash Controller */ /* Send Write Page command to Flash Controller */
if (at91sam7_flash_command(bank, WP, pagen) != ERROR_OK) if (at91sam7_flash_command(bank, WP, pagen) != ERROR_OK)
return ERROR_FLASH_OPERATION_FAILED; return ERROR_FLASH_OPERATION_FAILED;
LOG_DEBUG("Write flash bank:%i page number:%" PRIi32 "", bank->bank_number, pagen); LOG_DEBUG("Write flash bank:%u page number:%" PRIu32, bank->bank_number, pagen);
} }
return ERROR_OK; return ERROR_OK;
@ -1018,7 +1016,7 @@ static int get_at91sam7_info(struct flash_bank *bank, char *buf, int buf_size)
printed = snprintf(buf, printed = snprintf(buf,
buf_size, buf_size,
" Pagesize: %i bytes | Lockbits(%i): %i 0x%4.4x | Pages in lock region: %i\n", " Pagesize: %i bytes | Lockbits(%u): %i 0x%4.4x | Pages in lock region: %i\n",
at91sam7_info->pagesize, at91sam7_info->pagesize,
bank->num_sectors, bank->num_sectors,
at91sam7_info->num_lockbits_on, at91sam7_info->num_lockbits_on,

View File

@ -41,7 +41,7 @@
#define SAMD_NVMCTRL_CTRLA 0x00 /* NVM control A register */ #define SAMD_NVMCTRL_CTRLA 0x00 /* NVM control A register */
#define SAMD_NVMCTRL_CTRLB 0x04 /* NVM control B register */ #define SAMD_NVMCTRL_CTRLB 0x04 /* NVM control B register */
#define SAMD_NVMCTRL_PARAM 0x08 /* NVM parameters register */ #define SAMD_NVMCTRL_PARAM 0x08 /* NVM parameters register */
#define SAMD_NVMCTRL_INTFLAG 0x18 /* NVM Interupt Flag Status & Clear */ #define SAMD_NVMCTRL_INTFLAG 0x18 /* NVM Interrupt Flag Status & Clear */
#define SAMD_NVMCTRL_STATUS 0x18 /* NVM status register */ #define SAMD_NVMCTRL_STATUS 0x18 /* NVM status register */
#define SAMD_NVMCTRL_ADDR 0x1C /* NVM address register */ #define SAMD_NVMCTRL_ADDR 0x1C /* NVM address register */
#define SAMD_NVMCTRL_LOCK 0x20 /* NVM Lock section register */ #define SAMD_NVMCTRL_LOCK 0x20 /* NVM Lock section register */
@ -52,8 +52,8 @@
/* NVMCTRL commands. See Table 20-4 in 42129FSAM10/2013 */ /* NVMCTRL commands. See Table 20-4 in 42129FSAM10/2013 */
#define SAMD_NVM_CMD_ER 0x02 /* Erase Row */ #define SAMD_NVM_CMD_ER 0x02 /* Erase Row */
#define SAMD_NVM_CMD_WP 0x04 /* Write Page */ #define SAMD_NVM_CMD_WP 0x04 /* Write Page */
#define SAMD_NVM_CMD_EAR 0x05 /* Erase Auxilary Row */ #define SAMD_NVM_CMD_EAR 0x05 /* Erase Auxiliary Row */
#define SAMD_NVM_CMD_WAP 0x06 /* Write Auxilary Page */ #define SAMD_NVM_CMD_WAP 0x06 /* Write Auxiliary Page */
#define SAMD_NVM_CMD_LR 0x40 /* Lock Region */ #define SAMD_NVM_CMD_LR 0x40 /* Lock Region */
#define SAMD_NVM_CMD_UR 0x41 /* Unlock Region */ #define SAMD_NVM_CMD_UR 0x41 /* Unlock Region */
#define SAMD_NVM_CMD_SPRM 0x42 /* Set Power Reduction Mode */ #define SAMD_NVM_CMD_SPRM 0x42 /* Set Power Reduction Mode */
@ -398,7 +398,7 @@ static const struct samd_part *samd_find_part(uint32_t id)
static int samd_protect_check(struct flash_bank *bank) static int samd_protect_check(struct flash_bank *bank)
{ {
int res, prot_block; int res;
uint16_t lock; uint16_t lock;
res = target_read_u16(bank->target, res = target_read_u16(bank->target,
@ -407,7 +407,7 @@ static int samd_protect_check(struct flash_bank *bank)
return res; return res;
/* Lock bits are active-low */ /* Lock bits are active-low */
for (prot_block = 0; prot_block < bank->num_prot_blocks; prot_block++) for (unsigned int prot_block = 0; prot_block < bank->num_prot_blocks; prot_block++)
bank->prot_blocks[prot_block].is_protected = !(lock & (1u<<prot_block)); bank->prot_blocks[prot_block].is_protected = !(lock & (1u<<prot_block));
return ERROR_OK; return ERROR_OK;
@ -725,10 +725,10 @@ static int samd_modify_user_row(struct target *target, uint64_t value,
return samd_modify_user_row_masked(target, value << startb, mask); return samd_modify_user_row_masked(target, value << startb, mask);
} }
static int samd_protect(struct flash_bank *bank, int set, int first_prot_bl, int last_prot_bl) static int samd_protect(struct flash_bank *bank, int set,
unsigned int first, unsigned int last)
{ {
int res = ERROR_OK; int res = ERROR_OK;
int prot_block;
/* We can issue lock/unlock region commands with the target running but /* We can issue lock/unlock region commands with the target running but
* the settings won't persist unless we're able to modify the LOCK regions * the settings won't persist unless we're able to modify the LOCK regions
@ -738,7 +738,7 @@ static int samd_protect(struct flash_bank *bank, int set, int first_prot_bl, int
return ERROR_TARGET_NOT_HALTED; return ERROR_TARGET_NOT_HALTED;
} }
for (prot_block = first_prot_bl; prot_block <= last_prot_bl; prot_block++) { for (unsigned int prot_block = first; prot_block <= last; prot_block++) {
if (set != bank->prot_blocks[prot_block].is_protected) { if (set != bank->prot_blocks[prot_block].is_protected) {
/* Load an address that is within this protection block (we use offset 0) */ /* Load an address that is within this protection block (we use offset 0) */
res = target_write_u32(bank->target, res = target_write_u32(bank->target,
@ -763,7 +763,7 @@ static int samd_protect(struct flash_bank *bank, int set, int first_prot_bl, int
res = samd_modify_user_row(bank->target, res = samd_modify_user_row(bank->target,
set ? (uint64_t)0 : (uint64_t)UINT64_MAX, set ? (uint64_t)0 : (uint64_t)UINT64_MAX,
48 + first_prot_bl, 48 + last_prot_bl); 48 + first, 48 + last);
if (res != ERROR_OK) if (res != ERROR_OK)
LOG_WARNING("SAMD: protect settings were not made persistent!"); LOG_WARNING("SAMD: protect settings were not made persistent!");
@ -775,9 +775,10 @@ exit:
return res; return res;
} }
static int samd_erase(struct flash_bank *bank, int first_sect, int last_sect) static int samd_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
int res, s; int res;
struct samd_info *chip = (struct samd_info *)bank->driver_priv; struct samd_info *chip = (struct samd_info *)bank->driver_priv;
if (bank->target->state != TARGET_HALTED) { if (bank->target->state != TARGET_HALTED) {
@ -792,7 +793,7 @@ static int samd_erase(struct flash_bank *bank, int first_sect, int last_sect)
} }
/* For each sector to be erased */ /* For each sector to be erased */
for (s = first_sect; s <= last_sect; s++) { for (unsigned int s = first; s <= last; s++) {
res = samd_erase_row(bank->target, bank->sectors[s].offset); res = samd_erase_row(bank->target, bank->sectors[s].offset);
if (res != ERROR_OK) { if (res != ERROR_OK) {
LOG_ERROR("SAMD: failed to erase sector %d at 0x%08" PRIx32, s, bank->sectors[s].offset); LOG_ERROR("SAMD: failed to erase sector %d at 0x%08" PRIx32, s, bank->sectors[s].offset);
@ -914,9 +915,7 @@ static int samd_write(struct flash_bank *bank, const uint8_t *buffer,
} }
free_pb: free_pb:
if (pb) free(pb);
free(pb);
return res; return res;
} }

View File

@ -89,7 +89,7 @@ struct ath79_spi_ctx {
}; };
struct ath79_flash_bank { struct ath79_flash_bank {
int probed; bool probed;
int chipselect; int chipselect;
uint32_t io_base; uint32_t io_base;
const struct flash_device *dev; const struct flash_device *dev;
@ -275,7 +275,7 @@ static int ath79_spi_bitbang_chunk(struct flash_bank *bank,
*transferred = 0; *transferred = 0;
pracc_queue_init(&ctx); pracc_queue_init(&ctx);
LOG_DEBUG("ath79_spi_bitbang_bytes(%p, %08x, %p, %d)", LOG_DEBUG("ath79_spi_bitbang_bytes(%p, %08" PRIx32 ", %p, %d)",
target, ath79_info->io_base, data, len); target, ath79_info->io_base, data, len);
LOG_DEBUG("max code %d => max len %d. to_xfer %d", LOG_DEBUG("max code %d => max len %d. to_xfer %d",
@ -498,21 +498,21 @@ static int ath79_erase_sector(struct flash_bank *bank, int sector)
return wait_till_ready(bank, ATH79_MAX_TIMEOUT); return wait_till_ready(bank, ATH79_MAX_TIMEOUT);
} }
static int ath79_erase(struct flash_bank *bank, int first, int last) static int ath79_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
struct ath79_flash_bank *ath79_info = bank->driver_priv; struct ath79_flash_bank *ath79_info = bank->driver_priv;
int retval = ERROR_OK; int retval = ERROR_OK;
int sector;
LOG_DEBUG("%s: from sector %d to sector %d", __func__, first, last); LOG_DEBUG("%s: from sector %u to sector %u", __func__, first, last);
if (target->state != TARGET_HALTED) { if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted"); LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED; return ERROR_TARGET_NOT_HALTED;
} }
if ((first < 0) || (last < first) || (last >= bank->num_sectors)) { if ((last < first) || (last >= bank->num_sectors)) {
LOG_ERROR("Flash sector invalid"); LOG_ERROR("Flash sector invalid");
return ERROR_FLASH_SECTOR_INVALID; return ERROR_FLASH_SECTOR_INVALID;
} }
@ -525,14 +525,14 @@ static int ath79_erase(struct flash_bank *bank, int first, int last)
if (ath79_info->dev->erase_cmd == 0x00) if (ath79_info->dev->erase_cmd == 0x00)
return ERROR_FLASH_OPER_UNSUPPORTED; return ERROR_FLASH_OPER_UNSUPPORTED;
for (sector = first; sector <= last; sector++) { for (unsigned sector = first; sector <= last; sector++) {
if (bank->sectors[sector].is_protected) { if (bank->sectors[sector].is_protected) {
LOG_ERROR("Flash sector %d protected", sector); LOG_ERROR("Flash sector %u protected", sector);
return ERROR_FAIL; return ERROR_FAIL;
} }
} }
for (sector = first; sector <= last; sector++) { for (unsigned int sector = first; sector <= last; sector++) {
retval = ath79_erase_sector(bank, sector); retval = ath79_erase_sector(bank, sector);
if (retval != ERROR_OK) if (retval != ERROR_OK)
break; break;
@ -542,12 +542,10 @@ static int ath79_erase(struct flash_bank *bank, int first, int last)
return retval; return retval;
} }
static int ath79_protect(struct flash_bank *bank, int set, static int ath79_protect(struct flash_bank *bank, int set, unsigned int first,
int first, int last) unsigned int last)
{ {
int sector; for (unsigned int sector = first; sector <= last; sector++)
for (sector = first; sector <= last; sector++)
bank->sectors[sector].is_protected = set; bank->sectors[sector].is_protected = set;
return ERROR_OK; return ERROR_OK;
} }
@ -570,7 +568,7 @@ static int ath79_write_page(struct flash_bank *bank, const uint8_t *buffer,
ath79_info->dev->pagesize : SPIFLASH_DEF_PAGESIZE; ath79_info->dev->pagesize : SPIFLASH_DEF_PAGESIZE;
if (address & 0xff) { if (address & 0xff) {
LOG_ERROR("ath79_write_page: unaligned write address: %08x", LOG_ERROR("ath79_write_page: unaligned write address: %08" PRIx32,
address); address);
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -579,7 +577,7 @@ static int ath79_write_page(struct flash_bank *bank, const uint8_t *buffer,
return ERROR_FAIL; return ERROR_FAIL;
} }
if (len > ath79_info->dev->pagesize) { if (len > ath79_info->dev->pagesize) {
LOG_ERROR("ath79_write_page: len bigger than page size %d: %d", LOG_ERROR("ath79_write_page: len bigger than page size %" PRIu32 ": %" PRIu32,
pagesize, len); pagesize, len);
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -591,7 +589,7 @@ static int ath79_write_page(struct flash_bank *bank, const uint8_t *buffer,
if (i == len) /* all 0xff, no need to program. */ if (i == len) /* all 0xff, no need to program. */
return ERROR_OK; return ERROR_OK;
LOG_INFO("writing %d bytes to flash page @0x%08x", len, address); LOG_INFO("writing %" PRIu32 " bytes to flash page @0x%08" PRIx32, len, address);
memcpy(ath79_info->spi.page_buf, buffer, len); memcpy(ath79_info->spi.page_buf, buffer, len);
@ -648,7 +646,6 @@ static int ath79_write(struct flash_bank *bank, const uint8_t *buffer,
uint32_t offset, uint32_t count) uint32_t offset, uint32_t count)
{ {
struct target *target = bank->target; struct target *target = bank->target;
int sector;
LOG_DEBUG("%s: offset=0x%08" PRIx32 " count=0x%08" PRIx32, LOG_DEBUG("%s: offset=0x%08" PRIx32 " count=0x%08" PRIx32,
__func__, offset, count); __func__, offset, count);
@ -664,7 +661,7 @@ static int ath79_write(struct flash_bank *bank, const uint8_t *buffer,
} }
/* Check sector protection */ /* Check sector protection */
for (sector = 0; sector < bank->num_sectors; sector++) { for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
/* Start offset in or before this sector? */ /* Start offset in or before this sector? */
/* End offset in or behind this sector? */ /* End offset in or behind this sector? */
struct flash_sector *bs = &bank->sectors[sector]; struct flash_sector *bs = &bank->sectors[sector];
@ -672,7 +669,7 @@ static int ath79_write(struct flash_bank *bank, const uint8_t *buffer,
if ((offset < (bs->offset + bs->size)) && if ((offset < (bs->offset + bs->size)) &&
((offset + count - 1) >= bs->offset) && ((offset + count - 1) >= bs->offset) &&
bs->is_protected) { bs->is_protected) {
LOG_ERROR("Flash sector %d protected", sector); LOG_ERROR("Flash sector %u protected", sector);
return ERROR_FAIL; return ERROR_FAIL;
} }
} }
@ -695,12 +692,12 @@ static int ath79_read_buffer(struct flash_bank *bank, uint8_t *buffer,
__func__, address, len); __func__, address, len);
if (address & 0xff) { if (address & 0xff) {
LOG_ERROR("ath79_read_buffer: unaligned read address: %08x", LOG_ERROR("ath79_read_buffer: unaligned read address: %08" PRIx32,
address); address);
return ERROR_FAIL; return ERROR_FAIL;
} }
LOG_INFO("reading %d bytes from flash @0x%08x", len, address); LOG_INFO("reading %" PRIu32 " bytes from flash @0x%08" PRIx32, len, address);
/* bitbang command */ /* bitbang command */
ath79_spi_bitbang_prepare(bank); ath79_spi_bitbang_prepare(bank);
@ -780,7 +777,7 @@ static int ath79_probe(struct flash_bank *bank)
free(bank->sectors); free(bank->sectors);
free(ath79_info->spi.page_buf); free(ath79_info->spi.page_buf);
} }
ath79_info->probed = 0; ath79_info->probed = false;
for (target_device = target_devices; target_device->name; for (target_device = target_devices; target_device->name;
++target_device) ++target_device)
@ -845,7 +842,7 @@ static int ath79_probe(struct flash_bank *bank)
return ERROR_FAIL; return ERROR_FAIL;
} }
for (int sector = 0; sector < bank->num_sectors; sector++) { for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
sectors[sector].offset = sector * sectorsize; sectors[sector].offset = sector * sectorsize;
sectors[sector].size = sectorsize; sectors[sector].size = sectorsize;
sectors[sector].is_erased = 0; sectors[sector].is_erased = 0;
@ -853,7 +850,7 @@ static int ath79_probe(struct flash_bank *bank)
} }
bank->sectors = sectors; bank->sectors = sectors;
ath79_info->probed = 1; ath79_info->probed = true;
return ERROR_OK; return ERROR_OK;
} }

View File

@ -27,13 +27,14 @@
#include "imp.h" #include "imp.h"
#include "helper/binarybuffer.h" #include "helper/binarybuffer.h"
#include <helper/time_support.h>
#include <target/cortex_m.h> #include <target/cortex_m.h>
/* A note to prefixing. /* A note to prefixing.
* Definitions and functions ingerited from at91samd.c without * Definitions and functions inherited from at91samd.c without
* any change retained the original prefix samd_ so they eventualy * any change retained the original prefix samd_ so they eventually
* may go to samd_common.h and .c * may go to samd_common.h and .c
* As currently there are olny 3 short functions identical with * As currently there are only 3 short functions identical with
* the original source, no common file was created. */ * the original source, no common file was created. */
#define SAME5_PAGES_PER_BLOCK 16 #define SAME5_PAGES_PER_BLOCK 16
@ -230,7 +231,7 @@ static const struct samd_part *samd_find_part(uint32_t id)
static int same5_protect_check(struct flash_bank *bank) static int same5_protect_check(struct flash_bank *bank)
{ {
int res, prot_block; int res;
uint32_t lock; uint32_t lock;
res = target_read_u32(bank->target, res = target_read_u32(bank->target,
@ -239,7 +240,7 @@ static int same5_protect_check(struct flash_bank *bank)
return res; return res;
/* Lock bits are active-low */ /* Lock bits are active-low */
for (prot_block = 0; prot_block < bank->num_prot_blocks; prot_block++) for (unsigned int prot_block = 0; prot_block < bank->num_prot_blocks; prot_block++)
bank->prot_blocks[prot_block].is_protected = !(lock & (1u<<prot_block)); bank->prot_blocks[prot_block].is_protected = !(lock & (1u<<prot_block));
return ERROR_OK; return ERROR_OK;
@ -338,19 +339,28 @@ static int same5_probe(struct flash_bank *bank)
static int same5_wait_and_check_error(struct target *target) static int same5_wait_and_check_error(struct target *target)
{ {
int ret, ret2; int ret, ret2;
int rep_cnt = 100; /* Table 54-40 lists the maximum erase block time as 200 ms.
* Include some margin.
*/
int timeout_ms = 200 * 5;
int64_t ts_start = timeval_ms();
uint16_t intflag; uint16_t intflag;
do { do {
ret = target_read_u16(target, ret = target_read_u16(target,
SAMD_NVMCTRL + SAME5_NVMCTRL_INTFLAG, &intflag); SAMD_NVMCTRL + SAME5_NVMCTRL_INTFLAG, &intflag);
if (ret == ERROR_OK && intflag & SAME5_NVMCTRL_INTFLAG_DONE) if (ret != ERROR_OK) {
LOG_ERROR("SAM: error reading the NVMCTRL_INTFLAG register");
return ret;
}
if (intflag & SAME5_NVMCTRL_INTFLAG_DONE)
break; break;
} while (--rep_cnt); keep_alive();
} while (timeval_ms() - ts_start < timeout_ms);
if (ret != ERROR_OK) { if (!(intflag & SAME5_NVMCTRL_INTFLAG_DONE)) {
LOG_ERROR("Can't read NVM INTFLAG"); LOG_ERROR("SAM: NVM programming timed out");
return ret; ret = ERROR_FLASH_OPERATION_FAILED;
} }
#if 0 #if 0
if (intflag & SAME5_NVMCTRL_INTFLAG_ECCSE) if (intflag & SAME5_NVMCTRL_INTFLAG_ECCSE)
@ -559,10 +569,10 @@ static int same5_modify_user_row(struct target *target, uint32_t value,
buf_val, buf_mask, 0, 8); buf_val, buf_mask, 0, 8);
} }
static int same5_protect(struct flash_bank *bank, int set, int first_prot_bl, int last_prot_bl) static int same5_protect(struct flash_bank *bank, int set, unsigned int first,
unsigned int last)
{ {
int res = ERROR_OK; int res = ERROR_OK;
int prot_block;
/* We can issue lock/unlock region commands with the target running but /* We can issue lock/unlock region commands with the target running but
* the settings won't persist unless we're able to modify the LOCK regions * the settings won't persist unless we're able to modify the LOCK regions
@ -572,7 +582,7 @@ static int same5_protect(struct flash_bank *bank, int set, int first_prot_bl, in
return ERROR_TARGET_NOT_HALTED; return ERROR_TARGET_NOT_HALTED;
} }
for (prot_block = first_prot_bl; prot_block <= last_prot_bl; prot_block++) { for (unsigned int prot_block = first; prot_block <= last; prot_block++) {
if (set != bank->prot_blocks[prot_block].is_protected) { if (set != bank->prot_blocks[prot_block].is_protected) {
/* Load an address that is within this protection block (we use offset 0) */ /* Load an address that is within this protection block (we use offset 0) */
res = target_write_u32(bank->target, res = target_write_u32(bank->target,
@ -596,7 +606,7 @@ static int same5_protect(struct flash_bank *bank, int set, int first_prot_bl, in
const uint8_t unlock[4] = { 0xff, 0xff, 0xff, 0xff }; const uint8_t unlock[4] = { 0xff, 0xff, 0xff, 0xff };
uint8_t mask[4] = { 0, 0, 0, 0 }; uint8_t mask[4] = { 0, 0, 0, 0 };
buf_set_u32(mask, first_prot_bl, last_prot_bl + 1 - first_prot_bl, 0xffffffff); buf_set_u32(mask, first, last + 1 - first, 0xffffffff);
res = same5_modify_user_row_masked(bank->target, res = same5_modify_user_row_masked(bank->target,
set ? lock : unlock, mask, 8, 4); set ? lock : unlock, mask, 8, 4);
@ -611,9 +621,10 @@ exit:
return res; return res;
} }
static int same5_erase(struct flash_bank *bank, int first_sect, int last_sect) static int same5_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
int res, s; int res;
struct samd_info *chip = (struct samd_info *)bank->driver_priv; struct samd_info *chip = (struct samd_info *)bank->driver_priv;
if (bank->target->state != TARGET_HALTED) { if (bank->target->state != TARGET_HALTED) {
@ -626,7 +637,7 @@ static int same5_erase(struct flash_bank *bank, int first_sect, int last_sect)
return ERROR_FLASH_BANK_NOT_PROBED; return ERROR_FLASH_BANK_NOT_PROBED;
/* For each sector to be erased */ /* For each sector to be erased */
for (s = first_sect; s <= last_sect; s++) { for (unsigned int s = first; s <= last; s++) {
res = same5_erase_block(bank->target, bank->sectors[s].offset); res = same5_erase_block(bank->target, bank->sectors[s].offset);
if (res != ERROR_OK) { if (res != ERROR_OK) {
LOG_ERROR("SAM: failed to erase sector %d at 0x%08" PRIx32, s, bank->sectors[s].offset); LOG_ERROR("SAM: failed to erase sector %d at 0x%08" PRIx32, s, bank->sectors[s].offset);
@ -720,9 +731,7 @@ static int same5_write(struct flash_bank *bank, const uint8_t *buffer,
} }
free_pb: free_pb:
if (pb) free(pb);
free(pb);
return res; return res;
} }
@ -731,7 +740,7 @@ FLASH_BANK_COMMAND_HANDLER(same5_flash_bank_command)
{ {
if (bank->base != SAMD_FLASH) { if (bank->base != SAMD_FLASH) {
LOG_ERROR("Address " TARGET_ADDR_FMT " invalid bank address (try " LOG_ERROR("Address " TARGET_ADDR_FMT " invalid bank address (try "
"0x%08" PRIx32 "[same5] )", bank->base, SAMD_FLASH); "0x%08x[same5] )", bank->base, SAMD_FLASH);
return ERROR_FAIL; return ERROR_FAIL;
} }

View File

@ -25,7 +25,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * * along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/ ***************************************************************************/
/* Some of the the lower level code was based on code supplied by /* Some of the lower level code was based on code supplied by
* ATMEL under this copyright. */ * ATMEL under this copyright. */
/* BEGIN ATMEL COPYRIGHT */ /* BEGIN ATMEL COPYRIGHT */
@ -97,7 +97,7 @@
extern const struct flash_driver atsamv_flash; extern const struct flash_driver atsamv_flash;
struct samv_flash_bank { struct samv_flash_bank {
int probed; bool probed;
unsigned size_bytes; unsigned size_bytes;
unsigned gpnvm[SAMV_NUM_GPNVM_BITS]; unsigned gpnvm[SAMV_NUM_GPNVM_BITS];
}; };
@ -328,7 +328,7 @@ static int samv_protect_check(struct flash_bank *bank)
if (r != ERROR_OK) if (r != ERROR_OK)
return r; return r;
for (int x = 0; x < bank->num_sectors; x++) for (unsigned int x = 0; x < bank->num_sectors; x++)
bank->sectors[x].is_protected = (!!(v[x >> 5] & (1 << (x % 32)))); bank->sectors[x].is_protected = (!!(v[x >> 5] & (1 << (x % 32))));
return ERROR_OK; return ERROR_OK;
} }
@ -379,12 +379,12 @@ static int samv_probe(struct flash_bank *bank)
struct samv_flash_bank *samv_info = bank->driver_priv; struct samv_flash_bank *samv_info = bank->driver_priv;
samv_info->size_bytes = bank->size; samv_info->size_bytes = bank->size;
samv_info->probed = 1; samv_info->probed = true;
bank->base = SAMV_FLASH_BASE; bank->base = SAMV_FLASH_BASE;
bank->num_sectors = bank->size / SAMV_SECTOR_SIZE; bank->num_sectors = bank->size / SAMV_SECTOR_SIZE;
bank->sectors = calloc(bank->num_sectors, sizeof(struct flash_sector)); bank->sectors = calloc(bank->num_sectors, sizeof(struct flash_sector));
for (int s = 0; s < (int)bank->num_sectors; s++) { for (unsigned int s = 0; s < bank->num_sectors; s++) {
bank->sectors[s].size = SAMV_SECTOR_SIZE; bank->sectors[s].size = SAMV_SECTOR_SIZE;
bank->sectors[s].offset = s * SAMV_SECTOR_SIZE; bank->sectors[s].offset = s * SAMV_SECTOR_SIZE;
bank->sectors[s].is_erased = -1; bank->sectors[s].is_erased = -1;
@ -406,7 +406,8 @@ static int samv_auto_probe(struct flash_bank *bank)
return samv_probe(bank); return samv_probe(bank);
} }
static int samv_erase(struct flash_bank *bank, int first, int last) static int samv_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
const int page_count = 32; /* 32 pages equals 16 KB lock region */ const int page_count = 32; /* 32 pages equals 16 KB lock region */
@ -420,31 +421,31 @@ static int samv_erase(struct flash_bank *bank, int first, int last)
return r; return r;
/* easy case: we've been requested to erase the entire flash */ /* easy case: we've been requested to erase the entire flash */
if ((first == 0) && ((last + 1) == (int)(bank->num_sectors))) if ((first == 0) && ((last + 1) == bank->num_sectors))
return samv_efc_perform_command(bank->target, SAMV_EFC_FCMD_EA, 0, NULL); return samv_efc_perform_command(bank->target, SAMV_EFC_FCMD_EA, 0, NULL);
LOG_INFO("erasing lock regions %d-%d...", first, last); LOG_INFO("erasing lock regions %u-%u...", first, last);
for (int i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
uint32_t status; uint32_t status;
r = samv_erase_pages(bank->target, (i * page_count), page_count, &status); r = samv_erase_pages(bank->target, (i * page_count), page_count, &status);
LOG_INFO("erasing lock region %d", i); LOG_INFO("erasing lock region %u", i);
if (r != ERROR_OK) if (r != ERROR_OK)
LOG_ERROR("error performing erase page @ lock region number %d", LOG_ERROR("error performing erase page @ lock region number %u", i);
(unsigned int)(i));
if (status & (1 << 2)) { if (status & (1 << 2)) {
LOG_ERROR("lock region %d is locked", (unsigned int)(i)); LOG_ERROR("lock region %u is locked", i);
return ERROR_FAIL; return ERROR_FAIL;
} }
if (status & (1 << 1)) { if (status & (1 << 1)) {
LOG_ERROR("flash command error @lock region %d", (unsigned int)(i)); LOG_ERROR("flash command error @lock region %u", i);
return ERROR_FAIL; return ERROR_FAIL;
} }
} }
return ERROR_OK; return ERROR_OK;
} }
static int samv_protect(struct flash_bank *bank, int set, int first, int last) static int samv_protect(struct flash_bank *bank, int set, unsigned int first,
unsigned int last)
{ {
if (bank->target->state != TARGET_HALTED) { if (bank->target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted"); LOG_ERROR("Target not halted");
@ -453,9 +454,9 @@ static int samv_protect(struct flash_bank *bank, int set, int first, int last)
int r; int r;
if (set) if (set)
r = samv_flash_lock(bank->target, (unsigned)(first), (unsigned)(last)); r = samv_flash_lock(bank->target, first, last);
else else
r = samv_flash_unlock(bank->target, (unsigned)(first), (unsigned)(last)); r = samv_flash_unlock(bank->target, first, last);
return r; return r;
} }
@ -614,7 +615,7 @@ static int samv_get_info(struct flash_bank *bank, char *buf, int buf_size)
if (ERROR_OK != r) if (ERROR_OK != r)
return r; return r;
} }
snprintf(buf, buf_size, "Cortex-M7 detected with %d kB flash", snprintf(buf, buf_size, "Cortex-M7 detected with %" PRIu32 " kB flash",
bank->size / 1024); bank->size / 1024);
return ERROR_OK; return ERROR_OK;
} }
@ -660,7 +661,7 @@ COMMAND_HANDLER(samv_handle_gpnvm_command)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
} }
uint32_t v; unsigned v;
if (!strcmp("show", CMD_ARGV[0])) { if (!strcmp("show", CMD_ARGV[0])) {
if (who == -1) { if (who == -1) {
showall: showall:

View File

@ -218,7 +218,8 @@ FLASH_BANK_COMMAND_HANDLER(avrf_flash_bank_command)
return ERROR_OK; return ERROR_OK;
} }
static int avrf_erase(struct flash_bank *bank, int first, int last) static int avrf_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
struct avr_common *avr = target->arch_info; struct avr_common *avr = target->arch_info;
@ -263,7 +264,7 @@ static int avrf_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t o
} }
LOG_DEBUG("offset is 0x%08" PRIx32 "", offset); LOG_DEBUG("offset is 0x%08" PRIx32 "", offset);
LOG_DEBUG("count is %" PRId32 "", count); LOG_DEBUG("count is %" PRIu32 "", count);
if (ERROR_OK != avr_jtagprg_enterprogmode(avr)) if (ERROR_OK != avr_jtagprg_enterprogmode(avr))
return ERROR_FAIL; return ERROR_FAIL;
@ -332,10 +333,7 @@ static int avrf_probe(struct flash_bank *bank)
} }
if (avr_info != NULL) { if (avr_info != NULL) {
if (bank->sectors) { free(bank->sectors);
free(bank->sectors);
bank->sectors = NULL;
}
/* chip found */ /* chip found */
bank->base = 0x00000000; bank->base = 0x00000000;
@ -442,7 +440,7 @@ COMMAND_HANDLER(avrf_handle_mass_erase_command)
if (avrf_mass_erase(bank) == ERROR_OK) { if (avrf_mass_erase(bank) == ERROR_OK) {
/* set all sectors as erased */ /* set all sectors as erased */
for (int i = 0; i < bank->num_sectors; i++) for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 1; bank->sectors[i].is_erased = 1;
command_print(CMD, "avr mass erase complete"); command_print(CMD, "avr mass erase complete");

View File

@ -123,12 +123,13 @@ static inline int bluenrgx_write_flash_reg(struct flash_bank *bank, uint32_t reg
return target_write_u32(bank->target, bluenrgx_get_flash_reg(bank, reg_offset), value); return target_write_u32(bank->target, bluenrgx_get_flash_reg(bank, reg_offset), value);
} }
static int bluenrgx_erase(struct flash_bank *bank, int first, int last) static int bluenrgx_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
int retval = ERROR_OK; int retval = ERROR_OK;
struct bluenrgx_flash_bank *bluenrgx_info = bank->driver_priv; struct bluenrgx_flash_bank *bluenrgx_info = bank->driver_priv;
int num_sectors = (last - first + 1); unsigned int num_sectors = (last - first + 1);
int mass_erase = (num_sectors == bank->num_sectors); const bool mass_erase = (num_sectors == bank->num_sectors);
struct target *target = bank->target; struct target *target = bank->target;
uint32_t address, command; uint32_t address, command;
@ -181,9 +182,9 @@ static int bluenrgx_erase(struct flash_bank *bank, int first, int last)
} else { } else {
command = FLASH_CMD_ERASE_PAGE; command = FLASH_CMD_ERASE_PAGE;
for (int i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
address = bank->base+i*FLASH_PAGE_SIZE(bluenrgx_info); address = bank->base+i*FLASH_PAGE_SIZE(bluenrgx_info);
LOG_DEBUG("address = %08x, index = %d", address, i); LOG_DEBUG("address = %08" PRIx32 ", index = %u", address, i);
if (bluenrgx_write_flash_reg(bank, FLASH_REG_IRQRAW, 0x3f) != ERROR_OK) { if (bluenrgx_write_flash_reg(bank, FLASH_REG_IRQRAW, 0x3f) != ERROR_OK) {
LOG_ERROR("Register write failed"); LOG_ERROR("Register write failed");
@ -248,7 +249,7 @@ static int bluenrgx_write(struct flash_bank *bank, const uint8_t *buffer,
return ERROR_FLASH_BANK_NOT_PROBED; return ERROR_FLASH_BANK_NOT_PROBED;
if ((offset + count) > bank->size) { if ((offset + count) > bank->size) {
LOG_ERROR("Requested write past beyond of flash size: (offset+count) = %d, size=%d", LOG_ERROR("Requested write past beyond of flash size: (offset+count) = %" PRIu32 ", size=%" PRIu32,
(offset + count), (offset + count),
bank->size); bank->size);
return ERROR_FLASH_DST_OUT_OF_BANK; return ERROR_FLASH_DST_OUT_OF_BANK;
@ -311,8 +312,8 @@ static int bluenrgx_write(struct flash_bank *bank, const uint8_t *buffer,
LOG_DEBUG("source->address = " TARGET_ADDR_FMT, source->address); LOG_DEBUG("source->address = " TARGET_ADDR_FMT, source->address);
LOG_DEBUG("source->address+ source->size = " TARGET_ADDR_FMT, source->address+source->size); LOG_DEBUG("source->address+ source->size = " TARGET_ADDR_FMT, source->address+source->size);
LOG_DEBUG("write_algorithm_sp->address = " TARGET_ADDR_FMT, write_algorithm_sp->address); LOG_DEBUG("write_algorithm_sp->address = " TARGET_ADDR_FMT, write_algorithm_sp->address);
LOG_DEBUG("address = %08x", address); LOG_DEBUG("address = %08" PRIx32, address);
LOG_DEBUG("count = %08x", count); LOG_DEBUG("count = %08" PRIx32, count);
retval = target_run_flash_async_algorithm(target, retval = target_run_flash_async_algorithm(target,
buffer, buffer,
@ -399,7 +400,7 @@ static int bluenrgx_probe(struct flash_bank *bank)
bank->num_sectors = bank->size/FLASH_PAGE_SIZE(bluenrgx_info); bank->num_sectors = bank->size/FLASH_PAGE_SIZE(bluenrgx_info);
bank->sectors = realloc(bank->sectors, sizeof(struct flash_sector) * bank->num_sectors); bank->sectors = realloc(bank->sectors, sizeof(struct flash_sector) * bank->num_sectors);
for (int i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].offset = i * FLASH_PAGE_SIZE(bluenrgx_info); bank->sectors[i].offset = i * FLASH_PAGE_SIZE(bluenrgx_info);
bank->sectors[i].size = FLASH_PAGE_SIZE(bluenrgx_info); bank->sectors[i].size = FLASH_PAGE_SIZE(bluenrgx_info);
bank->sectors[i].is_erased = -1; bank->sectors[i].is_erased = -1;

View File

@ -264,7 +264,8 @@ FLASH_BANK_COMMAND_HANDLER(cc26xx_flash_bank_command)
return ERROR_OK; return ERROR_OK;
} }
static int cc26xx_erase(struct flash_bank *bank, int first, int last) static int cc26xx_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
struct cc26xx_bank *cc26xx_bank = bank->driver_priv; struct cc26xx_bank *cc26xx_bank = bank->driver_priv;
@ -526,7 +527,7 @@ static int cc26xx_info(struct flash_bank *bank, char *buf, int buf_size)
} }
printed = snprintf(buf, buf_size, printed = snprintf(buf, buf_size,
"%s device: ICEPick ID 0x%08x, USER ID 0x%08x\n", "%s device: ICEPick ID 0x%08" PRIx32 ", USER ID 0x%08" PRIx32 "\n",
device, cc26xx_bank->icepick_id, cc26xx_bank->user_id); device, cc26xx_bank->icepick_id, cc26xx_bank->user_id);
if (printed >= buf_size) if (printed >= buf_size)

View File

@ -106,7 +106,8 @@ FLASH_BANK_COMMAND_HANDLER(cc3220sf_flash_bank_command)
return ERROR_OK; return ERROR_OK;
} }
static int cc3220sf_erase(struct flash_bank *bank, int first, int last) static int cc3220sf_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
bool done; bool done;
@ -129,7 +130,7 @@ static int cc3220sf_erase(struct flash_bank *bank, int first, int last)
} }
/* Erase requested sectors one by one */ /* Erase requested sectors one by one */
for (int i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
/* Determine address of sector to erase */ /* Determine address of sector to erase */
address = FLASH_BASE_ADDR + i * FLASH_SECTOR_SIZE; address = FLASH_BASE_ADDR + i * FLASH_SECTOR_SIZE;
@ -431,16 +432,13 @@ static int cc3220sf_probe(struct flash_bank *bank)
uint32_t base; uint32_t base;
uint32_t size; uint32_t size;
int num_sectors; unsigned int num_sectors;
base = FLASH_BASE_ADDR; base = FLASH_BASE_ADDR;
size = FLASH_NUM_SECTORS * FLASH_SECTOR_SIZE; size = FLASH_NUM_SECTORS * FLASH_SECTOR_SIZE;
num_sectors = FLASH_NUM_SECTORS; num_sectors = FLASH_NUM_SECTORS;
if (NULL != bank->sectors) { free(bank->sectors);
free(bank->sectors);
bank->sectors = NULL;
}
bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors); bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors);
if (NULL == bank->sectors) if (NULL == bank->sectors)
@ -452,7 +450,7 @@ static int cc3220sf_probe(struct flash_bank *bank)
bank->write_end_alignment = 0; bank->write_end_alignment = 0;
bank->num_sectors = num_sectors; bank->num_sectors = num_sectors;
for (int i = 0; i < num_sectors; i++) { for (unsigned int i = 0; i < num_sectors; i++) {
bank->sectors[i].offset = i * FLASH_SECTOR_SIZE; bank->sectors[i].offset = i * FLASH_SECTOR_SIZE;
bank->sectors[i].size = FLASH_SECTOR_SIZE; bank->sectors[i].size = FLASH_SECTOR_SIZE;
bank->sectors[i].is_erased = -1; bank->sectors[i].is_erased = -1;

View File

@ -162,10 +162,10 @@ static void cfi_command(struct flash_bank *bank, uint8_t cmd, uint8_t *cmd_buf)
cmd_buf[i] = 0; cmd_buf[i] = 0;
if (cfi_info->endianness == TARGET_LITTLE_ENDIAN) { if (cfi_info->endianness == TARGET_LITTLE_ENDIAN) {
for (int i = bank->bus_width; i > 0; i--) for (unsigned int i = bank->bus_width; i > 0; i--)
*cmd_buf++ = (i & (bank->chip_width - 1)) ? 0x0 : cmd; *cmd_buf++ = (i & (bank->chip_width - 1)) ? 0x0 : cmd;
} else { } else {
for (int i = 1; i <= bank->bus_width; i++) for (unsigned int i = 1; i <= bank->bus_width; i++)
*cmd_buf++ = (i & (bank->chip_width - 1)) ? 0x0 : cmd; *cmd_buf++ = (i & (bank->chip_width - 1)) ? 0x0 : cmd;
} }
} }
@ -217,13 +217,13 @@ static int cfi_get_u8(struct flash_bank *bank, int sector, uint32_t offset, uint
return retval; return retval;
if (cfi_info->endianness == TARGET_LITTLE_ENDIAN) { if (cfi_info->endianness == TARGET_LITTLE_ENDIAN) {
for (int i = 0; i < bank->bus_width / bank->chip_width; i++) for (unsigned int i = 0; i < bank->bus_width / bank->chip_width; i++)
data[0] |= data[i]; data[0] |= data[i];
*val = data[0]; *val = data[0];
} else { } else {
uint8_t value = 0; uint8_t value = 0;
for (int i = 0; i < bank->bus_width / bank->chip_width; i++) for (unsigned int i = 0; i < bank->bus_width / bank->chip_width; i++)
value |= data[bank->bus_width - 1 - i]; value |= data[bank->bus_width - 1 - i];
*val = value; *val = value;
@ -423,8 +423,7 @@ static int cfi_read_intel_pri_ext(struct flash_bank *bank)
struct cfi_flash_bank *cfi_info = bank->driver_priv; struct cfi_flash_bank *cfi_info = bank->driver_priv;
struct cfi_intel_pri_ext *pri_ext; struct cfi_intel_pri_ext *pri_ext;
if (cfi_info->pri_ext) free(cfi_info->pri_ext);
free(cfi_info->pri_ext);
pri_ext = malloc(sizeof(struct cfi_intel_pri_ext)); pri_ext = malloc(sizeof(struct cfi_intel_pri_ext));
if (pri_ext == NULL) { if (pri_ext == NULL) {
@ -520,8 +519,7 @@ static int cfi_read_spansion_pri_ext(struct flash_bank *bank)
struct cfi_flash_bank *cfi_info = bank->driver_priv; struct cfi_flash_bank *cfi_info = bank->driver_priv;
struct cfi_spansion_pri_ext *pri_ext; struct cfi_spansion_pri_ext *pri_ext;
if (cfi_info->pri_ext) free(cfi_info->pri_ext);
free(cfi_info->pri_ext);
pri_ext = malloc(sizeof(struct cfi_spansion_pri_ext)); pri_ext = malloc(sizeof(struct cfi_spansion_pri_ext));
if (pri_ext == NULL) { if (pri_ext == NULL) {
@ -623,8 +621,7 @@ static int cfi_read_atmel_pri_ext(struct flash_bank *bank)
struct cfi_flash_bank *cfi_info = bank->driver_priv; struct cfi_flash_bank *cfi_info = bank->driver_priv;
struct cfi_spansion_pri_ext *pri_ext; struct cfi_spansion_pri_ext *pri_ext;
if (cfi_info->pri_ext) free(cfi_info->pri_ext);
free(cfi_info->pri_ext);
pri_ext = malloc(sizeof(struct cfi_spansion_pri_ext)); pri_ext = malloc(sizeof(struct cfi_spansion_pri_ext));
if (pri_ext == NULL) { if (pri_ext == NULL) {
@ -814,7 +811,7 @@ static int cfi_intel_info(struct flash_bank *bank, char *buf, int buf_size)
int cfi_flash_bank_cmd(struct flash_bank *bank, unsigned int argc, const char **argv) int cfi_flash_bank_cmd(struct flash_bank *bank, unsigned int argc, const char **argv)
{ {
struct cfi_flash_bank *cfi_info; struct cfi_flash_bank *cfi_info;
int bus_swap = 0; bool bus_swap = false;
if (argc < 6) if (argc < 6)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
@ -841,20 +838,20 @@ int cfi_flash_bank_cmd(struct flash_bank *bank, unsigned int argc, const char **
cfi_info->pri_ext = NULL; cfi_info->pri_ext = NULL;
bank->driver_priv = cfi_info; bank->driver_priv = cfi_info;
cfi_info->x16_as_x8 = 0; cfi_info->x16_as_x8 = false;
cfi_info->jedec_probe = 0; cfi_info->jedec_probe = false;
cfi_info->not_cfi = 0; cfi_info->not_cfi = false;
cfi_info->data_swap = 0; cfi_info->data_swap = false;
for (unsigned i = 6; i < argc; i++) { for (unsigned i = 6; i < argc; i++) {
if (strcmp(argv[i], "x16_as_x8") == 0) if (strcmp(argv[i], "x16_as_x8") == 0)
cfi_info->x16_as_x8 = 1; cfi_info->x16_as_x8 = true;
else if (strcmp(argv[i], "data_swap") == 0) else if (strcmp(argv[i], "data_swap") == 0)
cfi_info->data_swap = 1; cfi_info->data_swap = true;
else if (strcmp(argv[i], "bus_swap") == 0) else if (strcmp(argv[i], "bus_swap") == 0)
bus_swap = 1; bus_swap = true;
else if (strcmp(argv[i], "jedec_probe") == 0) else if (strcmp(argv[i], "jedec_probe") == 0)
cfi_info->jedec_probe = 1; cfi_info->jedec_probe = true;
} }
if (bus_swap) if (bus_swap)
@ -877,14 +874,15 @@ FLASH_BANK_COMMAND_HANDLER(cfi_flash_bank_command)
return cfi_flash_bank_cmd(bank, CMD_ARGC, CMD_ARGV); return cfi_flash_bank_cmd(bank, CMD_ARGC, CMD_ARGV);
} }
static int cfi_intel_erase(struct flash_bank *bank, int first, int last) static int cfi_intel_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
int retval; int retval;
struct cfi_flash_bank *cfi_info = bank->driver_priv; struct cfi_flash_bank *cfi_info = bank->driver_priv;
cfi_intel_clear_status_register(bank); cfi_intel_clear_status_register(bank);
for (int i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
retval = cfi_send_command(bank, 0x20, cfi_flash_address(bank, i, 0x0)); retval = cfi_send_command(bank, 0x20, cfi_flash_address(bank, i, 0x0));
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
@ -905,7 +903,7 @@ static int cfi_intel_erase(struct flash_bank *bank, int first, int last)
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
LOG_ERROR("couldn't erase block %i of flash bank at base " LOG_ERROR("couldn't erase block %u of flash bank at base "
TARGET_ADDR_FMT, i, bank->base); TARGET_ADDR_FMT, i, bank->base);
return ERROR_FLASH_OPERATION_FAILED; return ERROR_FLASH_OPERATION_FAILED;
} }
@ -931,13 +929,14 @@ int cfi_spansion_unlock_seq(struct flash_bank *bank)
return ERROR_OK; return ERROR_OK;
} }
static int cfi_spansion_erase(struct flash_bank *bank, int first, int last) static int cfi_spansion_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
int retval; int retval;
struct cfi_flash_bank *cfi_info = bank->driver_priv; struct cfi_flash_bank *cfi_info = bank->driver_priv;
struct cfi_spansion_pri_ext *pri_ext = cfi_info->pri_ext; struct cfi_spansion_pri_ext *pri_ext = cfi_info->pri_ext;
for (int i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
retval = cfi_spansion_unlock_seq(bank); retval = cfi_spansion_unlock_seq(bank);
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
@ -970,7 +969,8 @@ static int cfi_spansion_erase(struct flash_bank *bank, int first, int last)
return cfi_send_command(bank, 0xf0, cfi_flash_address(bank, 0, 0x0)); return cfi_send_command(bank, 0xf0, cfi_flash_address(bank, 0, 0x0));
} }
int cfi_erase(struct flash_bank *bank, int first, int last) int cfi_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct cfi_flash_bank *cfi_info = bank->driver_priv; struct cfi_flash_bank *cfi_info = bank->driver_priv;
@ -979,7 +979,7 @@ int cfi_erase(struct flash_bank *bank, int first, int last)
return ERROR_TARGET_NOT_HALTED; return ERROR_TARGET_NOT_HALTED;
} }
if ((first < 0) || (last < first) || (last >= bank->num_sectors)) if ((last < first) || (last >= bank->num_sectors))
return ERROR_FLASH_SECTOR_INVALID; return ERROR_FLASH_SECTOR_INVALID;
if (cfi_info->qry[0] != 'Q') if (cfi_info->qry[0] != 'Q')
@ -999,7 +999,8 @@ int cfi_erase(struct flash_bank *bank, int first, int last)
return ERROR_OK; return ERROR_OK;
} }
static int cfi_intel_protect(struct flash_bank *bank, int set, int first, int last) static int cfi_intel_protect(struct flash_bank *bank, int set,
unsigned int first, unsigned int last)
{ {
int retval; int retval;
struct cfi_flash_bank *cfi_info = bank->driver_priv; struct cfi_flash_bank *cfi_info = bank->driver_priv;
@ -1016,7 +1017,7 @@ static int cfi_intel_protect(struct flash_bank *bank, int set, int first, int la
cfi_intel_clear_status_register(bank); cfi_intel_clear_status_register(bank);
for (int i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
retval = cfi_send_command(bank, 0x60, cfi_flash_address(bank, i, 0x0)); retval = cfi_send_command(bank, 0x60, cfi_flash_address(bank, i, 0x0));
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
@ -1087,7 +1088,7 @@ static int cfi_intel_protect(struct flash_bank *bank, int set, int first, int la
* 3. re-protect what should be protected. * 3. re-protect what should be protected.
* *
*/ */
for (int i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
if (bank->sectors[i].is_protected == 1) { if (bank->sectors[i].is_protected == 1) {
cfi_intel_clear_status_register(bank); cfi_intel_clear_status_register(bank);
@ -1110,7 +1111,8 @@ static int cfi_intel_protect(struct flash_bank *bank, int set, int first, int la
return cfi_send_command(bank, 0xff, cfi_flash_address(bank, 0, 0x0)); return cfi_send_command(bank, 0xff, cfi_flash_address(bank, 0, 0x0));
} }
int cfi_protect(struct flash_bank *bank, int set, int first, int last) int cfi_protect(struct flash_bank *bank, int set, unsigned int first,
unsigned int last)
{ {
struct cfi_flash_bank *cfi_info = bank->driver_priv; struct cfi_flash_bank *cfi_info = bank->driver_priv;
@ -1146,7 +1148,7 @@ static uint32_t cfi_command_val(struct flash_bank *bank, uint8_t cmd)
case 4: case 4:
return target_buffer_get_u32(target, buf); return target_buffer_get_u32(target, buf);
default: default:
LOG_ERROR("Unsupported bank buswidth %d, can't do block memory writes", LOG_ERROR("Unsupported bank buswidth %u, can't do block memory writes",
bank->bus_width); bank->bus_width);
return 0; return 0;
} }
@ -1173,7 +1175,7 @@ static int cfi_intel_write_block(struct flash_bank *bank, const uint8_t *buffer,
* r6: error test pattern * r6: error test pattern
*/ */
/* see contib/loaders/flash/armv4_5_cfi_intel_32.s for src */ /* see contrib/loaders/flash/armv4_5_cfi_intel_32.s for src */
static const uint32_t word_32_code[] = { static const uint32_t word_32_code[] = {
0xe4904004, /* loop: ldr r4, [r0], #4 */ 0xe4904004, /* loop: ldr r4, [r0], #4 */
0xe5813000, /* str r3, [r1] */ 0xe5813000, /* str r3, [r1] */
@ -1191,7 +1193,7 @@ static int cfi_intel_write_block(struct flash_bank *bank, const uint8_t *buffer,
0xeafffffe /* done: b -2 */ 0xeafffffe /* done: b -2 */
}; };
/* see contib/loaders/flash/armv4_5_cfi_intel_16.s for src */ /* see contrib/loaders/flash/armv4_5_cfi_intel_16.s for src */
static const uint32_t word_16_code[] = { static const uint32_t word_16_code[] = {
0xe0d040b2, /* loop: ldrh r4, [r0], #2 */ 0xe0d040b2, /* loop: ldrh r4, [r0], #2 */
0xe1c130b0, /* strh r3, [r1] */ 0xe1c130b0, /* strh r3, [r1] */
@ -1209,7 +1211,7 @@ static int cfi_intel_write_block(struct flash_bank *bank, const uint8_t *buffer,
0xeafffffe /* done: b -2 */ 0xeafffffe /* done: b -2 */
}; };
/* see contib/loaders/flash/armv4_5_cfi_intel_8.s for src */ /* see contrib/loaders/flash/armv4_5_cfi_intel_8.s for src */
static const uint32_t word_8_code[] = { static const uint32_t word_8_code[] = {
0xe4d04001, /* loop: ldrb r4, [r0], #1 */ 0xe4d04001, /* loop: ldrb r4, [r0], #1 */
0xe5c13000, /* strb r3, [r1] */ 0xe5c13000, /* strb r3, [r1] */
@ -1244,7 +1246,7 @@ static int cfi_intel_write_block(struct flash_bank *bank, const uint8_t *buffer,
cfi_intel_clear_status_register(bank); cfi_intel_clear_status_register(bank);
/* If we are setting up the write_algorith, we need target_code_src /* If we are setting up the write_algorithm, we need target_code_src
* if not we only need target_code_size. */ * if not we only need target_code_size. */
/* However, we don't want to create multiple code paths, so we /* However, we don't want to create multiple code paths, so we
@ -1266,7 +1268,7 @@ static int cfi_intel_write_block(struct flash_bank *bank, const uint8_t *buffer,
target_code_size = sizeof(word_32_code); target_code_size = sizeof(word_32_code);
break; break;
default: default:
LOG_ERROR("Unsupported bank buswidth %d, can't do block memory writes", LOG_ERROR("Unsupported bank buswidth %u, can't do block memory writes",
bank->bus_width); bank->bus_width);
return ERROR_TARGET_RESOURCE_NOT_AVAILABLE; return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
} }
@ -1359,7 +1361,7 @@ static int cfi_intel_write_block(struct flash_bank *bank, const uint8_t *buffer,
if (retval != ERROR_OK) { if (retval != ERROR_OK) {
cfi_intel_clear_status_register(bank); cfi_intel_clear_status_register(bank);
LOG_ERROR( LOG_ERROR(
"Execution of flash algorythm failed. Can't fall back. Please report."); "Execution of flash algorithm failed. Can't fall back. Please report.");
retval = ERROR_FLASH_OPERATION_FAILED; retval = ERROR_FLASH_OPERATION_FAILED;
/* retval = ERROR_TARGET_RESOURCE_NOT_AVAILABLE; */ /* retval = ERROR_TARGET_RESOURCE_NOT_AVAILABLE; */
/* FIXME To allow fall back or recovery, we must save the actual status /* FIXME To allow fall back or recovery, we must save the actual status
@ -1502,7 +1504,7 @@ static int cfi_spansion_write_block_mips(struct flash_bank *bank, const uint8_t
} }
break; break;
default: default:
LOG_ERROR("Unsupported bank buswidth %d, can't do block memory writes", LOG_ERROR("Unsupported bank buswidth %u, can't do block memory writes",
bank->bus_width); bank->bus_width);
return ERROR_TARGET_RESOURCE_NOT_AVAILABLE; return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
} }
@ -1648,7 +1650,7 @@ static int cfi_spansion_write_block(struct flash_bank *bank, const uint8_t *buff
* R10 = unlock2_addr * R10 = unlock2_addr
* R11 = unlock2_cmd */ * R11 = unlock2_cmd */
/* see contib/loaders/flash/armv4_5_cfi_span_32.s for src */ /* see contrib/loaders/flash/armv4_5_cfi_span_32.s for src */
static const uint32_t armv4_5_word_32_code[] = { static const uint32_t armv4_5_word_32_code[] = {
/* 00008100 <sp_32_code>: */ /* 00008100 <sp_32_code>: */
0xe4905004, /* ldr r5, [r0], #4 */ 0xe4905004, /* ldr r5, [r0], #4 */
@ -1680,7 +1682,7 @@ static int cfi_spansion_write_block(struct flash_bank *bank, const uint8_t *buff
0xeafffffe /* b 8154 <sp_32_done> */ 0xeafffffe /* b 8154 <sp_32_done> */
}; };
/* see contib/loaders/flash/armv4_5_cfi_span_16.s for src */ /* see contrib/loaders/flash/armv4_5_cfi_span_16.s for src */
static const uint32_t armv4_5_word_16_code[] = { static const uint32_t armv4_5_word_16_code[] = {
/* 00008158 <sp_16_code>: */ /* 00008158 <sp_16_code>: */
0xe0d050b2, /* ldrh r5, [r0], #2 */ 0xe0d050b2, /* ldrh r5, [r0], #2 */
@ -1881,7 +1883,7 @@ static int cfi_spansion_write_block(struct flash_bank *bank, const uint8_t *buff
target_code_size = sizeof(armv4_5_word_32_code); target_code_size = sizeof(armv4_5_word_32_code);
break; break;
default: default:
LOG_ERROR("Unsupported bank buswidth %d, can't do block memory writes", LOG_ERROR("Unsupported bank buswidth %u, can't do block memory writes",
bank->bus_width); bank->bus_width);
return ERROR_TARGET_RESOURCE_NOT_AVAILABLE; return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
} }
@ -2050,7 +2052,7 @@ static int cfi_intel_write_words(struct flash_bank *bank, const uint8_t *word,
/* Check for valid size */ /* Check for valid size */
if (wordcount > bufferwsize) { if (wordcount > bufferwsize) {
LOG_ERROR("Number of data words %" PRId32 " exceeds available buffersize %" PRId32, LOG_ERROR("Number of data words %" PRIu32 " exceeds available buffersize %" PRIu32,
wordcount, buffersize); wordcount, buffersize);
return ERROR_FLASH_OPERATION_FAILED; return ERROR_FLASH_OPERATION_FAILED;
} }
@ -2165,8 +2167,8 @@ static int cfi_spansion_write_words(struct flash_bank *bank, const uint8_t *word
/* Check for valid size */ /* Check for valid size */
if (wordcount > bufferwsize) { if (wordcount > bufferwsize) {
LOG_ERROR("Number of data words %" PRId32 " exceeds available buffersize %" LOG_ERROR("Number of data words %" PRIu32 " exceeds available buffersize %"
PRId32, wordcount, buffersize); PRIu32, wordcount, buffersize);
return ERROR_FLASH_OPERATION_FAILED; return ERROR_FLASH_OPERATION_FAILED;
} }
@ -2286,7 +2288,7 @@ static int cfi_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, u
return retval; return retval;
/* take only bytes we need */ /* take only bytes we need */
for (int i = align; (i < bank->bus_width) && (count > 0); i++, count--) for (unsigned int i = align; (i < bank->bus_width) && (count > 0); i++, count--)
*buffer++ = current_word[i]; *buffer++ = current_word[i];
read_p += bank->bus_width; read_p += bank->bus_width;
@ -2312,7 +2314,7 @@ static int cfi_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset, u
return retval; return retval;
/* take only bytes we need */ /* take only bytes we need */
for (int i = 0; (i < bank->bus_width) && (count > 0); i++, count--) for (unsigned int i = 0; (i < bank->bus_width) && (count > 0); i++, count--)
*buffer++ = current_word[i]; *buffer++ = current_word[i];
} }
@ -2355,9 +2357,7 @@ static int cfi_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t of
return retval; return retval;
/* replace only bytes that must be written */ /* replace only bytes that must be written */
for (int i = align; for (unsigned int i = align; (i < bank->bus_width) && (count > 0); i++, count--)
(i < bank->bus_width) && (count > 0);
i++, count--)
if (cfi_info->data_swap) if (cfi_info->data_swap)
/* data bytes are swapped (reverse endianness) */ /* data bytes are swapped (reverse endianness) */
current_word[bank->bus_width - i] = *buffer++; current_word[bank->bus_width - i] = *buffer++;
@ -2403,7 +2403,7 @@ static int cfi_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t of
break; break;
} }
if (retval == ERROR_OK) { if (retval == ERROR_OK) {
/* Increment pointers and decrease count on succesful block write */ /* Increment pointers and decrease count on successful block write */
buffer += blk_count; buffer += blk_count;
write_p += blk_count; write_p += blk_count;
count -= blk_count; count -= blk_count;
@ -2440,7 +2440,7 @@ static int cfi_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t of
} }
/* try the slow way? */ /* try the slow way? */
if (fallback) { if (fallback) {
for (int i = 0; i < bank->bus_width; i++) for (unsigned int i = 0; i < bank->bus_width; i++)
current_word[i] = *buffer++; current_word[i] = *buffer++;
retval = cfi_write_word(bank, current_word, write_p); retval = cfi_write_word(bank, current_word, write_p);
@ -2467,7 +2467,7 @@ static int cfi_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t of
/* handle unaligned tail bytes */ /* handle unaligned tail bytes */
if (count > 0) { if (count > 0) {
LOG_INFO("Fixup %" PRId32 " unaligned tail bytes", count); LOG_INFO("Fixup %" PRIu32 " unaligned tail bytes", count);
/* read a complete word from flash */ /* read a complete word from flash */
retval = cfi_target_read_memory(bank, write_p, 1, current_word); retval = cfi_target_read_memory(bank, write_p, 1, current_word);
@ -2475,7 +2475,7 @@ static int cfi_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t of
return retval; return retval;
/* replace only bytes that must be written */ /* replace only bytes that must be written */
for (int i = 0; (i < bank->bus_width) && (count > 0); i++, count--) for (unsigned int i = 0; (i < bank->bus_width) && (count > 0); i++, count--)
if (cfi_info->data_swap) if (cfi_info->data_swap)
/* data bytes are swapped (reverse endianness) */ /* data bytes are swapped (reverse endianness) */
current_word[bank->bus_width - i] = *buffer++; current_word[bank->bus_width - i] = *buffer++;
@ -2576,7 +2576,7 @@ int cfi_probe(struct flash_bank *bank)
{ {
struct cfi_flash_bank *cfi_info = bank->driver_priv; struct cfi_flash_bank *cfi_info = bank->driver_priv;
struct target *target = bank->target; struct target *target = bank->target;
int num_sectors = 0; unsigned int num_sectors = 0;
int sector = 0; int sector = 0;
uint32_t unlock1 = 0x555; uint32_t unlock1 = 0x555;
uint32_t unlock2 = 0x2aa; uint32_t unlock2 = 0x2aa;
@ -2590,14 +2590,12 @@ int cfi_probe(struct flash_bank *bank)
cfi_info->probed = false; cfi_info->probed = false;
cfi_info->num_erase_regions = 0; cfi_info->num_erase_regions = 0;
if (bank->sectors) {
free(bank->sectors); free(bank->sectors);
bank->sectors = NULL; bank->sectors = NULL;
}
if (cfi_info->erase_region_info) { free(cfi_info->erase_region_info);
free(cfi_info->erase_region_info); cfi_info->erase_region_info = NULL;
cfi_info->erase_region_info = NULL;
}
/* JEDEC standard JESD21C uses 0x5555 and 0x2aaa as unlock addresses, /* JEDEC standard JESD21C uses 0x5555 and 0x2aaa as unlock addresses,
* while CFI compatible AMD/Spansion flashes use 0x555 and 0x2aa * while CFI compatible AMD/Spansion flashes use 0x555 and 0x2aa
@ -2640,7 +2638,7 @@ int cfi_probe(struct flash_bank *bank)
cfi_info->device_id = target_buffer_get_u32(target, value_buf1); cfi_info->device_id = target_buffer_get_u32(target, value_buf1);
break; break;
default: default:
LOG_ERROR("Unsupported bank chipwidth %d, can't probe memory", LOG_ERROR("Unsupported bank chipwidth %u, can't probe memory",
bank->chip_width); bank->chip_width);
return ERROR_FLASH_OPERATION_FAILED; return ERROR_FLASH_OPERATION_FAILED;
} }
@ -2658,7 +2656,7 @@ int cfi_probe(struct flash_bank *bank)
/* query only if this is a CFI compatible flash, /* query only if this is a CFI compatible flash,
* otherwise the relevant info has already been filled in * otherwise the relevant info has already been filled in
*/ */
if (cfi_info->not_cfi == 0) { if (!cfi_info->not_cfi) {
/* enter CFI query mode /* enter CFI query mode
* according to JEDEC Standard No. 68.01, * according to JEDEC Standard No. 68.01,
* a single bus sequence with address = 0x55, data = 0x98 should put * a single bus sequence with address = 0x55, data = 0x98 should put
@ -2792,7 +2790,7 @@ int cfi_probe(struct flash_bank *bank)
*for *for
*all *all
*CFI *CFI
*flashs *flashes
**/ **/
cfi_read_0002_pri_ext(bank); cfi_read_0002_pri_ext(bank);
break; break;
@ -2928,7 +2926,7 @@ static int cfi_intel_protect_check(struct flash_bank *bank)
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
for (int i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
uint8_t block_status; uint8_t block_status;
retval = cfi_get_u8(bank, i, 0x2, &block_status); retval = cfi_get_u8(bank, i, 0x2, &block_status);
if (retval != ERROR_OK) if (retval != ERROR_OK)
@ -2957,7 +2955,7 @@ static int cfi_spansion_protect_check(struct flash_bank *bank)
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
for (int i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
uint8_t block_status; uint8_t block_status;
retval = cfi_get_u8(bank, i, 0x2, &block_status); retval = cfi_get_u8(bank, i, 0x2, &block_status);
if (retval != ERROR_OK) if (retval != ERROR_OK)
@ -3008,7 +3006,7 @@ int cfi_get_info(struct flash_bank *bank, char *buf, int buf_size)
return ERROR_OK; return ERROR_OK;
} }
if (cfi_info->not_cfi == 0) if (!cfi_info->not_cfi)
printed = snprintf(buf, buf_size, "\nCFI flash: "); printed = snprintf(buf, buf_size, "\nCFI flash: ");
else else
printed = snprintf(buf, buf_size, "\nnon-CFI flash: "); printed = snprintf(buf, buf_size, "\nnon-CFI flash: ");

View File

@ -23,13 +23,13 @@
#define CFI_STATUS_POLL_MASK_DQ6_DQ7 0xC0 /* DQ6..DQ7 */ #define CFI_STATUS_POLL_MASK_DQ6_DQ7 0xC0 /* DQ6..DQ7 */
struct cfi_flash_bank { struct cfi_flash_bank {
int x16_as_x8; bool x16_as_x8;
int jedec_probe; bool jedec_probe;
int not_cfi; bool not_cfi;
int probed; bool probed;
enum target_endianness endianness; enum target_endianness endianness;
int data_swap; bool data_swap;
uint16_t manufacturer; uint16_t manufacturer;
uint16_t device_id; uint16_t device_id;
@ -154,8 +154,9 @@ struct cfi_fixup {
const void *param; const void *param;
}; };
int cfi_erase(struct flash_bank *bank, int first, int last); int cfi_erase(struct flash_bank *bank, unsigned int first, unsigned int last);
int cfi_protect(struct flash_bank *bank, int set, int first, int last); int cfi_protect(struct flash_bank *bank, int set, unsigned int first,
unsigned int last);
int cfi_probe(struct flash_bank *bank); int cfi_probe(struct flash_bank *bank);
int cfi_auto_probe(struct flash_bank *bank); int cfi_auto_probe(struct flash_bank *bank);
int cfi_protect_check(struct flash_bank *bank); int cfi_protect_check(struct flash_bank *bank);

View File

@ -37,21 +37,23 @@
static struct flash_bank *flash_banks; static struct flash_bank *flash_banks;
int flash_driver_erase(struct flash_bank *bank, int first, int last) int flash_driver_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
int retval; int retval;
retval = bank->driver->erase(bank, first, last); retval = bank->driver->erase(bank, first, last);
if (retval != ERROR_OK) if (retval != ERROR_OK)
LOG_ERROR("failed erasing sectors %d to %d", first, last); LOG_ERROR("failed erasing sectors %u to %u", first, last);
return retval; return retval;
} }
int flash_driver_protect(struct flash_bank *bank, int set, int first, int last) int flash_driver_protect(struct flash_bank *bank, int set, unsigned int first,
unsigned int last)
{ {
int retval; int retval;
int num_blocks; unsigned int num_blocks;
if (bank->num_prot_blocks) if (bank->num_prot_blocks)
num_blocks = bank->num_prot_blocks; num_blocks = bank->num_prot_blocks;
@ -60,7 +62,7 @@ int flash_driver_protect(struct flash_bank *bank, int set, int first, int last)
/* callers may not supply illegal parameters ... */ /* callers may not supply illegal parameters ... */
if (first < 0 || first > last || last >= num_blocks) { if (first > last || last >= num_blocks) {
LOG_ERROR("illegal protection block range"); LOG_ERROR("illegal protection block range");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -86,7 +88,7 @@ int flash_driver_protect(struct flash_bank *bank, int set, int first, int last)
*/ */
retval = bank->driver->protect(bank, set, first, last); retval = bank->driver->protect(bank, set, first, last);
if (retval != ERROR_OK) if (retval != ERROR_OK)
LOG_ERROR("failed setting protection for blocks %d to %d", first, last); LOG_ERROR("failed setting protection for blocks %u to %u", first, last);
return retval; return retval;
} }
@ -157,10 +159,10 @@ struct flash_bank *flash_bank_list(void)
return flash_banks; return flash_banks;
} }
struct flash_bank *get_flash_bank_by_num_noprobe(int num) struct flash_bank *get_flash_bank_by_num_noprobe(unsigned int num)
{ {
struct flash_bank *p; struct flash_bank *p;
int i = 0; unsigned int i = 0;
for (p = flash_banks; p; p = p->next) { for (p = flash_banks; p; p = p->next) {
if (i++ == num) if (i++ == num)
@ -170,10 +172,10 @@ struct flash_bank *get_flash_bank_by_num_noprobe(int num)
return NULL; return NULL;
} }
int flash_get_bank_count(void) unsigned int flash_get_bank_count(void)
{ {
struct flash_bank *p; struct flash_bank *p;
int i = 0; unsigned int i = 0;
for (p = flash_banks; p; p = p->next) for (p = flash_banks; p; p = p->next)
i++; i++;
return i; return i;
@ -249,7 +251,7 @@ int get_flash_bank_by_name(const char *name, struct flash_bank **bank_result)
return ERROR_OK; return ERROR_OK;
} }
int get_flash_bank_by_num(int num, struct flash_bank **bank) int get_flash_bank_by_num(unsigned int num, struct flash_bank **bank)
{ {
struct flash_bank *p = get_flash_bank_by_num_noprobe(num); struct flash_bank *p = get_flash_bank_by_num_noprobe(num);
int retval; int retval;
@ -306,7 +308,6 @@ static int default_flash_mem_blank_check(struct flash_bank *bank)
{ {
struct target *target = bank->target; struct target *target = bank->target;
const int buffer_size = 1024; const int buffer_size = 1024;
int i;
uint32_t nBytes; uint32_t nBytes;
int retval = ERROR_OK; int retval = ERROR_OK;
@ -317,7 +318,7 @@ static int default_flash_mem_blank_check(struct flash_bank *bank)
uint8_t *buffer = malloc(buffer_size); uint8_t *buffer = malloc(buffer_size);
for (i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
uint32_t j; uint32_t j;
bank->sectors[i].is_erased = 1; bank->sectors[i].is_erased = 1;
@ -353,7 +354,6 @@ done:
int default_flash_blank_check(struct flash_bank *bank) int default_flash_blank_check(struct flash_bank *bank)
{ {
struct target *target = bank->target; struct target *target = bank->target;
int i;
int retval; int retval;
if (bank->target->state != TARGET_HALTED) { if (bank->target->state != TARGET_HALTED) {
@ -366,14 +366,14 @@ int default_flash_blank_check(struct flash_bank *bank)
if (block_array == NULL) if (block_array == NULL)
return default_flash_mem_blank_check(bank); return default_flash_mem_blank_check(bank);
for (i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
block_array[i].address = bank->base + bank->sectors[i].offset; block_array[i].address = bank->base + bank->sectors[i].offset;
block_array[i].size = bank->sectors[i].size; block_array[i].size = bank->sectors[i].size;
block_array[i].result = UINT32_MAX; /* erase state unknown */ block_array[i].result = UINT32_MAX; /* erase state unknown */
} }
bool fast_check = true; bool fast_check = true;
for (i = 0; i < bank->num_sectors; ) { for (unsigned int i = 0; i < bank->num_sectors; ) {
retval = target_blank_check_memory(target, retval = target_blank_check_memory(target,
block_array + i, bank->num_sectors - i, block_array + i, bank->num_sectors - i,
bank->erased_value); bank->erased_value);
@ -388,7 +388,7 @@ int default_flash_blank_check(struct flash_bank *bank)
} }
if (fast_check) { if (fast_check) {
for (i = 0; i < bank->num_sectors; i++) for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = block_array[i].result; bank->sectors[i].is_erased = block_array[i].result;
retval = ERROR_OK; retval = ERROR_OK;
} else { } else {
@ -418,7 +418,8 @@ int default_flash_blank_check(struct flash_bank *bank)
static int flash_iterate_address_range_inner(struct target *target, static int flash_iterate_address_range_inner(struct target *target,
char *pad_reason, target_addr_t addr, uint32_t length, char *pad_reason, target_addr_t addr, uint32_t length,
bool iterate_protect_blocks, bool iterate_protect_blocks,
int (*callback)(struct flash_bank *bank, int first, int last)) int (*callback)(struct flash_bank *bank, unsigned int first,
unsigned int last))
{ {
struct flash_bank *c; struct flash_bank *c;
struct flash_sector *block_array; struct flash_sector *block_array;
@ -547,7 +548,8 @@ static int flash_iterate_address_range_inner(struct target *target,
static int flash_iterate_address_range(struct target *target, static int flash_iterate_address_range(struct target *target,
char *pad_reason, target_addr_t addr, uint32_t length, char *pad_reason, target_addr_t addr, uint32_t length,
bool iterate_protect_blocks, bool iterate_protect_blocks,
int (*callback)(struct flash_bank *bank, int first, int last)) int (*callback)(struct flash_bank *bank, unsigned int first,
unsigned int last))
{ {
struct flash_bank *c; struct flash_bank *c;
int retval = ERROR_OK; int retval = ERROR_OK;
@ -585,7 +587,8 @@ int flash_erase_address_range(struct target *target,
addr, length, false, &flash_driver_erase); addr, length, false, &flash_driver_erase);
} }
static int flash_driver_unprotect(struct flash_bank *bank, int first, int last) static int flash_driver_unprotect(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
return flash_driver_protect(bank, 0, first, last); return flash_driver_protect(bank, 0, first, last);
} }
@ -627,8 +630,7 @@ target_addr_t flash_write_align_start(struct flash_bank *bank, target_addr_t add
if (bank->write_start_alignment == FLASH_WRITE_ALIGN_SECTOR) { if (bank->write_start_alignment == FLASH_WRITE_ALIGN_SECTOR) {
uint32_t offset = addr - bank->base; uint32_t offset = addr - bank->base;
uint32_t aligned = 0; uint32_t aligned = 0;
int sect; for (unsigned int sect = 0; sect < bank->num_sectors; sect++) {
for (sect = 0; sect < bank->num_sectors; sect++) {
if (bank->sectors[sect].offset > offset) if (bank->sectors[sect].offset > offset)
break; break;
@ -652,8 +654,7 @@ target_addr_t flash_write_align_end(struct flash_bank *bank, target_addr_t addr)
if (bank->write_end_alignment == FLASH_WRITE_ALIGN_SECTOR) { if (bank->write_end_alignment == FLASH_WRITE_ALIGN_SECTOR) {
uint32_t offset = addr - bank->base; uint32_t offset = addr - bank->base;
uint32_t aligned = 0; uint32_t aligned = 0;
int sect; for (unsigned int sect = 0; sect < bank->num_sectors; sect++) {
for (sect = 0; sect < bank->num_sectors; sect++) {
aligned = bank->sectors[sect].offset + bank->sectors[sect].size - 1; aligned = bank->sectors[sect].offset + bank->sectors[sect].size - 1;
if (aligned >= offset) if (aligned >= offset)
break; break;
@ -676,7 +677,7 @@ static bool flash_write_check_gap(struct flash_bank *bank,
return false; return false;
if (bank->minimal_write_gap == FLASH_WRITE_GAP_SECTOR) { if (bank->minimal_write_gap == FLASH_WRITE_GAP_SECTOR) {
int sect; unsigned int sect;
uint32_t offset1 = addr1 - bank->base; uint32_t offset1 = addr1 - bank->base;
/* find the sector following the one containing addr1 */ /* find the sector following the one containing addr1 */
for (sect = 0; sect < bank->num_sectors; sect++) { for (sect = 0; sect < bank->num_sectors; sect++) {
@ -697,7 +698,7 @@ static bool flash_write_check_gap(struct flash_bank *bank,
int flash_write_unlock(struct target *target, struct image *image, int flash_write_unlock(struct target *target, struct image *image,
uint32_t *written, int erase, bool unlock) uint32_t *written, bool erase, bool unlock)
{ {
int retval = ERROR_OK; int retval = ERROR_OK;
@ -824,7 +825,7 @@ int flash_write_unlock(struct target *target, struct image *image,
LOG_WARNING("Section start address " TARGET_ADDR_FMT LOG_WARNING("Section start address " TARGET_ADDR_FMT
" breaks the required alignment of flash bank %s", " breaks the required alignment of flash bank %s",
run_address, c->name); run_address, c->name);
LOG_WARNING("Padding %d bytes from " TARGET_ADDR_FMT, LOG_WARNING("Padding %" PRIu32 " bytes from " TARGET_ADDR_FMT,
padding_at_start, aligned_start); padding_at_start, aligned_start);
run_address -= padding_at_start; run_address -= padding_at_start;
@ -847,12 +848,11 @@ int flash_write_unlock(struct target *target, struct image *image,
/* If we're applying any sector automagic, then pad this /* If we're applying any sector automagic, then pad this
* (maybe-combined) segment to the end of its last sector. * (maybe-combined) segment to the end of its last sector.
*/ */
int sector;
uint32_t offset_start = run_address - c->base; uint32_t offset_start = run_address - c->base;
uint32_t offset_end = offset_start + run_size; uint32_t offset_end = offset_start + run_size;
uint32_t end = offset_end, delta; uint32_t end = offset_end, delta;
for (sector = 0; sector < c->num_sectors; sector++) { for (unsigned int sector = 0; sector < c->num_sectors; sector++) {
end = c->sectors[sector].offset end = c->sectors[sector].offset
+ c->sectors[sector].size; + c->sectors[sector].size;
if (offset_end <= end) if (offset_end <= end)
@ -955,20 +955,19 @@ done:
} }
int flash_write(struct target *target, struct image *image, int flash_write(struct target *target, struct image *image,
uint32_t *written, int erase) uint32_t *written, bool erase)
{ {
return flash_write_unlock(target, image, written, erase, false); return flash_write_unlock(target, image, written, erase, false);
} }
struct flash_sector *alloc_block_array(uint32_t offset, uint32_t size, int num_blocks) struct flash_sector *alloc_block_array(uint32_t offset, uint32_t size,
unsigned int num_blocks)
{ {
int i;
struct flash_sector *array = calloc(num_blocks, sizeof(struct flash_sector)); struct flash_sector *array = calloc(num_blocks, sizeof(struct flash_sector));
if (array == NULL) if (array == NULL)
return NULL; return NULL;
for (i = 0; i < num_blocks; i++) { for (unsigned int i = 0; i < num_blocks; i++) {
array[i].offset = offset; array[i].offset = offset;
array[i].size = size; array[i].size = size;
array[i].is_erased = -1; array[i].is_erased = -1;

View File

@ -93,12 +93,12 @@ struct flash_bank {
const struct flash_driver *driver; /**< Driver for this bank. */ const struct flash_driver *driver; /**< Driver for this bank. */
void *driver_priv; /**< Private driver storage pointer */ void *driver_priv; /**< Private driver storage pointer */
int bank_number; /**< The 'bank' (or chip number) of this instance. */ unsigned int bank_number; /**< The 'bank' (or chip number) of this instance. */
target_addr_t base; /**< The base address of this bank */ target_addr_t base; /**< The base address of this bank */
uint32_t size; /**< The size of this chip bank, in bytes */ uint32_t size; /**< The size of this chip bank, in bytes */
int chip_width; /**< Width of the chip in bytes (1,2,4 bytes) */ unsigned int chip_width; /**< Width of the chip in bytes (1,2,4 bytes) */
int bus_width; /**< Maximum bus width, in bytes (1,2,4 bytes) */ unsigned int bus_width; /**< Maximum bus width, in bytes (1,2,4 bytes) */
/** Erased value. Defaults to 0xFF. */ /** Erased value. Defaults to 0xFF. */
uint8_t erased_value; uint8_t erased_value;
@ -124,7 +124,7 @@ struct flash_bank {
* be set initially to 0, and the flash driver must set this to * be set initially to 0, and the flash driver must set this to
* some non-zero value during "probe()" or "auto_probe()". * some non-zero value during "probe()" or "auto_probe()".
*/ */
int num_sectors; unsigned int num_sectors;
/** Array of sectors, allocated and initialized by the flash driver */ /** Array of sectors, allocated and initialized by the flash driver */
struct flash_sector *sectors; struct flash_sector *sectors;
@ -134,7 +134,7 @@ struct flash_bank {
* Driver probe can set protection blocks array to work with * Driver probe can set protection blocks array to work with
* protection granularity different than sector size. * protection granularity different than sector size.
*/ */
int num_prot_blocks; unsigned int num_prot_blocks;
/** Array of protection blocks, allocated and initialized by the flash driver */ /** Array of protection blocks, allocated and initialized by the flash driver */
struct flash_sector *prot_blocks; struct flash_sector *prot_blocks;
@ -179,12 +179,12 @@ target_addr_t flash_write_align_end(struct flash_bank *bank, target_addr_t addr)
* @param target The target with the flash to be programmed. * @param target The target with the flash to be programmed.
* @param image The image that will be programmed to flash. * @param image The image that will be programmed to flash.
* @param written On return, contains the number of bytes written. * @param written On return, contains the number of bytes written.
* @param erase If non-zero, indicates the flash driver should first * @param erase Indicates whether the flash driver should first
* erase the corresponding banks or sectors before programming. * erase the corresponding banks or sectors before programming.
* @returns ERROR_OK if successful; otherwise, an error code. * @returns ERROR_OK if successful; otherwise, an error code.
*/ */
int flash_write(struct target *target, int flash_write(struct target *target,
struct image *image, uint32_t *written, int erase); struct image *image, uint32_t *written, bool erase);
/** /**
* Forces targets to re-examine their erase/protection state. * Forces targets to re-examine their erase/protection state.
@ -193,7 +193,7 @@ int flash_write(struct target *target,
void flash_set_dirty(void); void flash_set_dirty(void);
/** @returns The number of flash banks currently defined. */ /** @returns The number of flash banks currently defined. */
int flash_get_bank_count(void); unsigned int flash_get_bank_count(void);
/** Deallocates bank->driver_priv */ /** Deallocates bank->driver_priv */
void default_flash_free_driver_priv(struct flash_bank *bank); void default_flash_free_driver_priv(struct flash_bank *bank);
@ -240,7 +240,7 @@ struct flash_bank *get_flash_bank_by_name_noprobe(const char *name);
* @param bank returned bank if fn returns ERROR_OK * @param bank returned bank if fn returns ERROR_OK
* @returns ERROR_OK if successful * @returns ERROR_OK if successful
*/ */
int get_flash_bank_by_num(int num, struct flash_bank **bank); int get_flash_bank_by_num(unsigned int num, struct flash_bank **bank);
/** /**
* Retrieves @a bank from a command argument, reporting errors parsing * Retrieves @a bank from a command argument, reporting errors parsing
* the bank identifier or retrieving the specified bank. The bank * the bank identifier or retrieving the specified bank. The bank
@ -248,7 +248,7 @@ int get_flash_bank_by_num(int num, struct flash_bank **bank);
* @a instance is driver-specific. * @a instance is driver-specific.
* @param name_index The index to the string in args containing the * @param name_index The index to the string in args containing the
* bank identifier. * bank identifier.
* @param bank On output, contians a pointer to the bank or NULL. * @param bank On output, contains a pointer to the bank or NULL.
* @returns ERROR_OK on success, or an error indicating the problem. * @returns ERROR_OK on success, or an error indicating the problem.
*/ */
COMMAND_HELPER(flash_command_get_bank, unsigned name_index, COMMAND_HELPER(flash_command_get_bank, unsigned name_index,
@ -258,7 +258,7 @@ COMMAND_HELPER(flash_command_get_bank, unsigned name_index,
* @param num The flash bank number. * @param num The flash bank number.
* @returns A struct flash_bank for flash bank @a num, or NULL. * @returns A struct flash_bank for flash bank @a num, or NULL.
*/ */
struct flash_bank *get_flash_bank_by_num_noprobe(int num); struct flash_bank *get_flash_bank_by_num_noprobe(unsigned int num);
/** /**
* Returns the flash bank located at a specified address. * Returns the flash bank located at a specified address.
* @param target The target, presumed to contain one or more banks. * @param target The target, presumed to contain one or more banks.
@ -275,6 +275,7 @@ int get_flash_bank_by_addr(struct target *target, target_addr_t addr, bool check
* @param num_blocks Number of blocks in array. * @param num_blocks Number of blocks in array.
* @returns A struct flash_sector pointer or NULL when allocation failed. * @returns A struct flash_sector pointer or NULL when allocation failed.
*/ */
struct flash_sector *alloc_block_array(uint32_t offset, uint32_t size, int num_blocks); struct flash_sector *alloc_block_array(uint32_t offset, uint32_t size,
unsigned int num_blocks);
#endif /* OPENOCD_FLASH_NOR_CORE_H */ #endif /* OPENOCD_FLASH_NOR_CORE_H */

View File

@ -104,7 +104,8 @@ struct flash_driver {
* @param last The number of the last sector to erase, typically N-1. * @param last The number of the last sector to erase, typically N-1.
* @returns ERROR_OK if successful; otherwise, an error code. * @returns ERROR_OK if successful; otherwise, an error code.
*/ */
int (*erase)(struct flash_bank *bank, int first, int last); int (*erase)(struct flash_bank *bank, unsigned int first,
unsigned int last);
/** /**
* Bank/sector protection routine (target-specific). * Bank/sector protection routine (target-specific).
@ -119,11 +120,12 @@ struct flash_driver {
* *
* @param bank The bank to protect or unprotect. * @param bank The bank to protect or unprotect.
* @param set If non-zero, enable protection; if 0, disable it. * @param set If non-zero, enable protection; if 0, disable it.
* @param first The first sector to (un)protect, typicaly 0. * @param first The first sector to (un)protect, typically 0.
* @param last The last sector to (un)project, typically N-1. * @param last The last sector to (un)project, typically N-1.
* @returns ERROR_OK if successful; otherwise, an error code. * @returns ERROR_OK if successful; otherwise, an error code.
*/ */
int (*protect)(struct flash_bank *bank, int set, int first, int last); int (*protect)(struct flash_bank *bank, int set, unsigned int first,
unsigned int last);
/** /**
* Program data into the flash. Note CPU address will be * Program data into the flash. Note CPU address will be
@ -200,14 +202,14 @@ struct flash_driver {
int (*info)(struct flash_bank *bank, char *buf, int buf_size); int (*info)(struct flash_bank *bank, char *buf, int buf_size);
/** /**
* A more gentle flavor of filash_driver_s::probe, performing * A more gentle flavor of flash_driver_s::probe, performing
* setup with less noise. Generally, driver routines should test * setup with less noise. Generally, driver routines should test
* to see if the bank has already been probed; if it has, the * to see if the bank has already been probed; if it has, the
* driver probably should not perform its probe a second time. * driver probably should not perform its probe a second time.
* *
* This callback is often called from the inside of other * This callback is often called from the inside of other
* routines (e.g. GDB flash downloads) to autoprobe the flash as * routines (e.g. GDB flash downloads) to autoprobe the flash as
* it is programing the flash. * it is programming the flash.
* *
* @param bank - the bank to probe * @param bank - the bank to probe
* @returns ERROR_OK if successful; otherwise, an error code. * @returns ERROR_OK if successful; otherwise, an error code.

View File

@ -48,9 +48,8 @@ static int dsp5680xx_build_sector_list(struct flash_bank *bank)
uint32_t offset = HFM_FLASH_BASE_ADDR; uint32_t offset = HFM_FLASH_BASE_ADDR;
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors); bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
int i;
for (i = 0; i < bank->num_sectors; ++i) { for (unsigned int i = 0; i < bank->num_sectors; ++i) {
bank->sectors[i].offset = i * HFM_SECTOR_SIZE; bank->sectors[i].offset = i * HFM_SECTOR_SIZE;
bank->sectors[i].size = HFM_SECTOR_SIZE; bank->sectors[i].size = HFM_SECTOR_SIZE;
offset += bank->sectors[i].size; offset += bank->sectors[i].size;
@ -108,7 +107,7 @@ static int dsp5680xx_flash_protect_check(struct flash_bank *bank)
} }
/** /**
* Protection funcionality is not implemented. * Protection functionality is not implemented.
* The current implementation applies/removes security on the chip. * The current implementation applies/removes security on the chip.
* The chip is effectively secured/unsecured after the first reset * The chip is effectively secured/unsecured after the first reset
* following the execution of this function. * following the execution of this function.
@ -120,8 +119,8 @@ static int dsp5680xx_flash_protect_check(struct flash_bank *bank)
* *
* @return * @return
*/ */
static int dsp5680xx_flash_protect(struct flash_bank *bank, int set, int first, static int dsp5680xx_flash_protect(struct flash_bank *bank, int set,
int last) unsigned int first, unsigned int last)
{ {
/** /**
* This applies security to flash module after next reset, it does * This applies security to flash module after next reset, it does
@ -204,7 +203,8 @@ static int dsp5680xx_probe(struct flash_bank *bank)
* *
* @return * @return
*/ */
static int dsp5680xx_flash_erase(struct flash_bank *bank, int first, int last) static int dsp5680xx_flash_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
int retval; int retval;
@ -212,14 +212,14 @@ static int dsp5680xx_flash_erase(struct flash_bank *bank, int first, int last)
if ((!(first | last)) || ((first == 0) && (last == (HFM_SECTOR_COUNT - 1)))) if ((!(first | last)) || ((first == 0) && (last == (HFM_SECTOR_COUNT - 1))))
last = HFM_SECTOR_COUNT - 1; last = HFM_SECTOR_COUNT - 1;
if (retval == ERROR_OK) if (retval == ERROR_OK)
for (int i = first; i <= last; i++) for (unsigned int i = first; i <= last; i++)
bank->sectors[i].is_erased = 1; bank->sectors[i].is_erased = 1;
else else
/** /**
* If an error occurred unknown status * If an error occurred unknown status
*is set even though some sector could have been correctly erased. *is set even though some sector could have been correctly erased.
*/ */
for (int i = first; i <= last; i++) for (unsigned int i = first; i <= last; i++)
bank->sectors[i].is_erased = -1; bank->sectors[i].is_erased = -1;
return retval; return retval;
} }

View File

@ -467,7 +467,8 @@ static int efm32x_erase_page(struct flash_bank *bank, uint32_t addr)
EFM32_MSC_STATUS_BUSY_MASK, 0); EFM32_MSC_STATUS_BUSY_MASK, 0);
} }
static int efm32x_erase(struct flash_bank *bank, int first, int last) static int efm32x_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
int ret = 0; int ret = 0;
@ -484,7 +485,7 @@ static int efm32x_erase(struct flash_bank *bank, int first, int last)
return ret; return ret;
} }
for (int i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
ret = efm32x_erase_page(bank, bank->sectors[i].offset); ret = efm32x_erase_page(bank, bank->sectors[i].offset);
if (ERROR_OK != ret) if (ERROR_OK != ret)
LOG_ERROR("Failed to erase page %d", i); LOG_ERROR("Failed to erase page %d", i);
@ -614,7 +615,8 @@ static int efm32x_set_page_lock(struct flash_bank *bank, size_t page, int set)
return ERROR_OK; return ERROR_OK;
} }
static int efm32x_protect(struct flash_bank *bank, int set, int first, int last) static int efm32x_protect(struct flash_bank *bank, int set, unsigned int first,
unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
int ret = 0; int ret = 0;
@ -629,7 +631,7 @@ static int efm32x_protect(struct flash_bank *bank, int set, int first, int last)
return ERROR_TARGET_NOT_HALTED; return ERROR_TARGET_NOT_HALTED;
} }
for (int i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
ret = efm32x_set_page_lock(bank, i, set); ret = efm32x_set_page_lock(bank, i, set);
if (ERROR_OK != ret) { if (ERROR_OK != ret) {
LOG_ERROR("Failed to set lock on page %d", i); LOG_ERROR("Failed to set lock on page %d", i);
@ -949,9 +951,7 @@ reset_pg_and_lock:
retval = retval2; retval = retval2;
cleanup: cleanup:
if (new_buffer) free(new_buffer);
free(new_buffer);
return retval; return retval;
} }
@ -985,10 +985,8 @@ static int efm32x_probe(struct flash_bank *bank)
assert(num_pages > 0); assert(num_pages > 0);
if (bank->sectors) { free(bank->sectors);
free(bank->sectors); bank->sectors = NULL;
bank->sectors = NULL;
}
bank->base = base_address; bank->base = base_address;
bank->size = (num_pages * efm32_mcu_info.page_size); bank->size = (num_pages * efm32_mcu_info.page_size);
@ -1040,7 +1038,7 @@ static int efm32x_protect_check(struct flash_bank *bank)
assert(NULL != bank->sectors); assert(NULL != bank->sectors);
for (int i = 0; i < bank->num_sectors; i++) for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_protected = efm32x_get_page_lock(bank, i); bank->sectors[i].is_protected = efm32x_get_page_lock(bank, i);
return ERROR_OK; return ERROR_OK;

View File

@ -87,7 +87,7 @@ struct em357_options {
struct em357_flash_bank { struct em357_flash_bank {
struct em357_options option_bytes; struct em357_options option_bytes;
int ppage_size; int ppage_size;
int probed; bool probed;
}; };
static int em357_mass_erase(struct flash_bank *bank); static int em357_mass_erase(struct flash_bank *bank);
@ -104,7 +104,7 @@ FLASH_BANK_COMMAND_HANDLER(em357_flash_bank_command)
em357_info = malloc(sizeof(struct em357_flash_bank)); em357_info = malloc(sizeof(struct em357_flash_bank));
bank->driver_priv = em357_info; bank->driver_priv = em357_info;
em357_info->probed = 0; em357_info->probed = false;
return ERROR_OK; return ERROR_OK;
} }
@ -343,10 +343,10 @@ static int em357_protect_check(struct flash_bank *bank)
return ERROR_OK; return ERROR_OK;
} }
static int em357_erase(struct flash_bank *bank, int first, int last) static int em357_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
int i;
if (bank->target->state != TARGET_HALTED) { if (bank->target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted"); LOG_ERROR("Target not halted");
@ -367,7 +367,7 @@ static int em357_erase(struct flash_bank *bank, int first, int last)
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
for (i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
retval = target_write_u32(target, EM357_FLASH_CR, FLASH_PER); retval = target_write_u32(target, EM357_FLASH_CR, FLASH_PER);
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
@ -393,12 +393,13 @@ static int em357_erase(struct flash_bank *bank, int first, int last)
return ERROR_OK; return ERROR_OK;
} }
static int em357_protect(struct flash_bank *bank, int set, int first, int last) static int em357_protect(struct flash_bank *bank, int set, unsigned int first,
unsigned int last)
{ {
struct em357_flash_bank *em357_info = NULL; struct em357_flash_bank *em357_info = NULL;
struct target *target = bank->target; struct target *target = bank->target;
uint16_t prot_reg[4] = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF}; uint16_t prot_reg[4] = {0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF};
int i, reg, bit; int reg, bit;
int status; int status;
uint32_t protection; uint32_t protection;
@ -431,7 +432,7 @@ static int em357_protect(struct flash_bank *bank, int set, int first, int last)
prot_reg[1] = (uint16_t)(protection >> 8); prot_reg[1] = (uint16_t)(protection >> 8);
prot_reg[2] = (uint16_t)(protection >> 16); prot_reg[2] = (uint16_t)(protection >> 16);
for (i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
reg = (i / em357_info->ppage_size) / 8; reg = (i / em357_info->ppage_size) / 8;
bit = (i / em357_info->ppage_size) - (reg * 8); bit = (i / em357_info->ppage_size) - (reg * 8);
@ -465,7 +466,7 @@ static int em357_write_block(struct flash_bank *bank, const uint8_t *buffer,
struct armv7m_algorithm armv7m_info; struct armv7m_algorithm armv7m_info;
int retval = ERROR_OK; int retval = ERROR_OK;
/* see contib/loaders/flash/stm32x.s for src, the same is used here except for /* see contrib/loaders/flash/stm32x.s for src, the same is used here except for
* a modified *_FLASH_BASE */ * a modified *_FLASH_BASE */
static const uint8_t em357_flash_write_code[] = { static const uint8_t em357_flash_write_code[] = {
@ -679,7 +680,7 @@ static int em357_probe(struct flash_bank *bank)
int page_size; int page_size;
uint32_t base_address = 0x08000000; uint32_t base_address = 0x08000000;
em357_info->probed = 0; em357_info->probed = false;
switch (bank->size) { switch (bank->size) {
case 0x10000: case 0x10000:
@ -723,10 +724,7 @@ static int em357_probe(struct flash_bank *bank)
LOG_INFO("flash size = %dkbytes", num_pages*page_size/1024); LOG_INFO("flash size = %dkbytes", num_pages*page_size/1024);
if (bank->sectors) { free(bank->sectors);
free(bank->sectors);
bank->sectors = NULL;
}
bank->base = base_address; bank->base = base_address;
bank->size = (num_pages * page_size); bank->size = (num_pages * page_size);
@ -740,7 +738,7 @@ static int em357_probe(struct flash_bank *bank)
bank->sectors[i].is_protected = 1; bank->sectors[i].is_protected = 1;
} }
em357_info->probed = 1; em357_info->probed = true;
return ERROR_OK; return ERROR_OK;
} }
@ -870,8 +868,6 @@ static int em357_mass_erase(struct flash_bank *bank)
COMMAND_HANDLER(em357_handle_mass_erase_command) COMMAND_HANDLER(em357_handle_mass_erase_command)
{ {
int i;
if (CMD_ARGC < 1) if (CMD_ARGC < 1)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
@ -883,7 +879,7 @@ COMMAND_HANDLER(em357_handle_mass_erase_command)
retval = em357_mass_erase(bank); retval = em357_mass_erase(bank);
if (retval == ERROR_OK) { if (retval == ERROR_OK) {
/* set all sectors as erased */ /* set all sectors as erased */
for (i = 0; i < bank->num_sectors; i++) for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 1; bank->sectors[i].is_erased = 1;
command_print(CMD, "em357 mass erase complete"); command_print(CMD, "em357 mass erase complete");

View File

@ -252,7 +252,8 @@ static int esirisc_flash_recall(struct flash_bank *bank)
return esirisc_flash_control(bank, CONTROL_R); return esirisc_flash_control(bank, CONTROL_R);
} }
static int esirisc_flash_erase(struct flash_bank *bank, int first, int last) static int esirisc_flash_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct esirisc_flash_bank *esirisc_info = bank->driver_priv; struct esirisc_flash_bank *esirisc_info = bank->driver_priv;
struct target *target = bank->target; struct target *target = bank->target;
@ -263,7 +264,7 @@ static int esirisc_flash_erase(struct flash_bank *bank, int first, int last)
(void)esirisc_flash_disable_protect(bank); (void)esirisc_flash_disable_protect(bank);
for (int page = first; page < last; ++page) { for (unsigned int page = first; page < last; ++page) {
uint32_t address = page * FLASH_PAGE_SIZE; uint32_t address = page * FLASH_PAGE_SIZE;
target_write_u32(target, esirisc_info->cfg + ADDRESS, address); target_write_u32(target, esirisc_info->cfg + ADDRESS, address);
@ -493,7 +494,7 @@ static int esirisc_flash_info(struct flash_bank *bank, char *buf, int buf_size)
struct esirisc_flash_bank *esirisc_info = bank->driver_priv; struct esirisc_flash_bank *esirisc_info = bank->driver_priv;
snprintf(buf, buf_size, snprintf(buf, buf_size,
"%4s cfg at 0x%" PRIx32 ", clock %" PRId32 ", wait_states %" PRId32, "%4s cfg at 0x%" PRIx32 ", clock %" PRIu32 ", wait_states %" PRIu32,
"", /* align with first line */ "", /* align with first line */
esirisc_info->cfg, esirisc_info->cfg,
esirisc_info->clock, esirisc_info->clock,

View File

@ -56,11 +56,10 @@ FLASH_BANK_COMMAND_HANDLER(faux_flash_bank_command)
bank->driver_priv = info; bank->driver_priv = info;
/* Use 0x10000 as a fixed sector size. */ /* Use 0x10000 as a fixed sector size. */
int i = 0;
uint32_t offset = 0; uint32_t offset = 0;
bank->num_sectors = bank->size/sectorSize; bank->num_sectors = bank->size/sectorSize;
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors); bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
for (i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].offset = offset; bank->sectors[i].offset = offset;
bank->sectors[i].size = sectorSize; bank->sectors[i].size = sectorSize;
offset += bank->sectors[i].size; offset += bank->sectors[i].size;
@ -78,7 +77,8 @@ FLASH_BANK_COMMAND_HANDLER(faux_flash_bank_command)
return ERROR_OK; return ERROR_OK;
} }
static int faux_erase(struct flash_bank *bank, int first, int last) static int faux_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct faux_flash_bank *info = bank->driver_priv; struct faux_flash_bank *info = bank->driver_priv;
memset(info->memory + first*sectorSize, 0xff, sectorSize*(last-first + 1)); memset(info->memory + first*sectorSize, 0xff, sectorSize*(last-first + 1));

View File

@ -122,7 +122,7 @@
struct fespi_flash_bank { struct fespi_flash_bank {
int probed; bool probed;
target_addr_t ctrl_base; target_addr_t ctrl_base;
const struct flash_device *dev; const struct flash_device *dev;
}; };
@ -136,9 +136,9 @@ struct fespi_target {
/* TODO !!! What is the right naming convention here? */ /* TODO !!! What is the right naming convention here? */
static const struct fespi_target target_devices[] = { static const struct fespi_target target_devices[] = {
/* name, tap_idcode, ctrl_base */ /* name, tap_idcode, ctrl_base */
{ "Freedom E310-G000 SPI Flash", 0x10e31913 , 0x10014000 }, { "Freedom E310-G000 SPI Flash", 0x10e31913, 0x10014000 },
{ "Freedom E310-G002 SPI Flash", 0x20000913 , 0x10014000 }, { "Freedom E310-G002 SPI Flash", 0x20000913, 0x10014000 },
{ NULL, 0, 0 } { NULL, 0, 0 }
}; };
FLASH_BANK_COMMAND_HANDLER(fespi_flash_bank_command) FLASH_BANK_COMMAND_HANDLER(fespi_flash_bank_command)
@ -157,7 +157,7 @@ FLASH_BANK_COMMAND_HANDLER(fespi_flash_bank_command)
} }
bank->driver_priv = fespi_info; bank->driver_priv = fespi_info;
fespi_info->probed = 0; fespi_info->probed = false;
fespi_info->ctrl_base = 0; fespi_info->ctrl_base = 0;
if (CMD_ARGC >= 7) { if (CMD_ARGC >= 7) {
COMMAND_PARSE_ADDRESS(CMD_ARGV[6], fespi_info->ctrl_base); COMMAND_PARSE_ADDRESS(CMD_ARGV[6], fespi_info->ctrl_base);
@ -189,7 +189,7 @@ static int fespi_write_reg(struct flash_bank *bank, target_addr_t address, uint3
int result = target_write_u32(target, fespi_info->ctrl_base + address, value); int result = target_write_u32(target, fespi_info->ctrl_base + address, value);
if (result != ERROR_OK) { if (result != ERROR_OK) {
LOG_ERROR("fespi_write_reg() error writing 0x%x to " TARGET_ADDR_FMT, LOG_ERROR("fespi_write_reg() error writing 0x%" PRIx32 " to " TARGET_ADDR_FMT,
value, fespi_info->ctrl_base + address); value, fespi_info->ctrl_base + address);
return result; return result;
} }
@ -274,7 +274,7 @@ static int fespi_rx(struct flash_bank *bank, uint8_t *out)
break; break;
int64_t now = timeval_ms(); int64_t now = timeval_ms();
if (now - start > 1000) { if (now - start > 1000) {
LOG_ERROR("rxfifo didn't go positive (value=0x%x).", value); LOG_ERROR("rxfifo didn't go positive (value=0x%" PRIx32 ").", value);
return ERROR_TARGET_TIMEOUT; return ERROR_TARGET_TIMEOUT;
} }
} }
@ -364,21 +364,21 @@ static int fespi_erase_sector(struct flash_bank *bank, int sector)
return ERROR_OK; return ERROR_OK;
} }
static int fespi_erase(struct flash_bank *bank, int first, int last) static int fespi_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
struct fespi_flash_bank *fespi_info = bank->driver_priv; struct fespi_flash_bank *fespi_info = bank->driver_priv;
int retval = ERROR_OK; int retval = ERROR_OK;
int sector;
LOG_DEBUG("%s: from sector %d to sector %d", __func__, first, last); LOG_DEBUG("%s: from sector %u to sector %u", __func__, first, last);
if (target->state != TARGET_HALTED) { if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted"); LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED; return ERROR_TARGET_NOT_HALTED;
} }
if ((first < 0) || (last < first) || (last >= bank->num_sectors)) { if ((last < first) || (last >= bank->num_sectors)) {
LOG_ERROR("Flash sector invalid"); LOG_ERROR("Flash sector invalid");
return ERROR_FLASH_SECTOR_INVALID; return ERROR_FLASH_SECTOR_INVALID;
} }
@ -388,9 +388,9 @@ static int fespi_erase(struct flash_bank *bank, int first, int last)
return ERROR_FLASH_BANK_NOT_PROBED; return ERROR_FLASH_BANK_NOT_PROBED;
} }
for (sector = first; sector <= last; sector++) { for (unsigned int sector = first; sector <= last; sector++) {
if (bank->sectors[sector].is_protected) { if (bank->sectors[sector].is_protected) {
LOG_ERROR("Flash sector %d protected", sector); LOG_ERROR("Flash sector %u protected", sector);
return ERROR_FAIL; return ERROR_FAIL;
} }
} }
@ -415,7 +415,7 @@ static int fespi_erase(struct flash_bank *bank, int first, int last)
if (retval != ERROR_OK) if (retval != ERROR_OK)
goto done; goto done;
for (sector = first; sector <= last; sector++) { for (unsigned int sector = first; sector <= last; sector++) {
retval = fespi_erase_sector(bank, sector); retval = fespi_erase_sector(bank, sector);
if (retval != ERROR_OK) if (retval != ERROR_OK)
goto done; goto done;
@ -430,11 +430,9 @@ done:
} }
static int fespi_protect(struct flash_bank *bank, int set, static int fespi_protect(struct flash_bank *bank, int set,
int first, int last) unsigned int first, unsigned int last)
{ {
int sector; for (unsigned int sector = first; sector <= last; sector++)
for (sector = first; sector <= last; sector++)
bank->sectors[sector].is_protected = set; bank->sectors[sector].is_protected = set;
return ERROR_OK; return ERROR_OK;
} }
@ -514,14 +512,14 @@ static int fespi_write(struct flash_bank *bank, const uint8_t *buffer,
} }
/* Check sector protection */ /* Check sector protection */
for (sector = 0; sector < bank->num_sectors; sector++) { for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
/* Start offset in or before this sector? */ /* Start offset in or before this sector? */
/* End offset in or behind this sector? */ /* End offset in or behind this sector? */
if ((offset < if ((offset <
(bank->sectors[sector].offset + bank->sectors[sector].size)) (bank->sectors[sector].offset + bank->sectors[sector].size))
&& ((offset + count - 1) >= bank->sectors[sector].offset) && ((offset + count - 1) >= bank->sectors[sector].offset)
&& bank->sectors[sector].is_protected) { && bank->sectors[sector].is_protected) {
LOG_ERROR("Flash sector %d protected", sector); LOG_ERROR("Flash sector %u protected", sector);
return ERROR_FAIL; return ERROR_FAIL;
} }
} }
@ -747,7 +745,7 @@ static int fespi_probe(struct flash_bank *bank)
if (fespi_info->probed) if (fespi_info->probed)
free(bank->sectors); free(bank->sectors);
fespi_info->probed = 0; fespi_info->probed = false;
if (fespi_info->ctrl_base == 0) { if (fespi_info->ctrl_base == 0) {
for (target_device = target_devices ; target_device->name ; ++target_device) for (target_device = target_devices ; target_device->name ; ++target_device)
@ -820,7 +818,7 @@ static int fespi_probe(struct flash_bank *bank)
return ERROR_FAIL; return ERROR_FAIL;
} }
for (int sector = 0; sector < bank->num_sectors; sector++) { for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
sectors[sector].offset = sector * sectorsize; sectors[sector].offset = sector * sectorsize;
sectors[sector].size = sectorsize; sectors[sector].size = sectorsize;
sectors[sector].is_erased = -1; sectors[sector].is_erased = -1;
@ -828,7 +826,7 @@ static int fespi_probe(struct flash_bank *bank)
} }
bank->sectors = sectors; bank->sectors = sectors;
fespi_info->probed = 1; fespi_info->probed = true;
return ERROR_OK; return ERROR_OK;
} }

View File

@ -61,7 +61,7 @@ enum fm3_flash_type {
struct fm3_flash_bank { struct fm3_flash_bank {
enum fm3_variant variant; enum fm3_variant variant;
enum fm3_flash_type flashtype; enum fm3_flash_type flashtype;
int probed; bool probed;
}; };
FLASH_BANK_COMMAND_HANDLER(fm3_flash_bank_command) FLASH_BANK_COMMAND_HANDLER(fm3_flash_bank_command)
@ -132,7 +132,7 @@ FLASH_BANK_COMMAND_HANDLER(fm3_flash_bank_command)
return ERROR_FLASH_BANK_INVALID; return ERROR_FLASH_BANK_INVALID;
} }
fm3_info->probed = 0; fm3_info->probed = false;
return ERROR_OK; return ERROR_OK;
} }
@ -201,13 +201,14 @@ static int fm3_busy_wait(struct target *target, uint32_t offset, int timeout_ms)
return retval; return retval;
} }
static int fm3_erase(struct flash_bank *bank, int first, int last) static int fm3_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct fm3_flash_bank *fm3_info = bank->driver_priv; struct fm3_flash_bank *fm3_info = bank->driver_priv;
struct target *target = bank->target; struct target *target = bank->target;
int retval = ERROR_OK; int retval = ERROR_OK;
uint32_t u32DummyRead; uint32_t u32DummyRead;
int sector, odd; int odd;
uint32_t u32FlashType; uint32_t u32FlashType;
uint32_t u32FlashSeqAddress1; uint32_t u32FlashSeqAddress1;
uint32_t u32FlashSeqAddress2; uint32_t u32FlashSeqAddress2;
@ -260,7 +261,7 @@ static int fm3_erase(struct flash_bank *bank, int first, int last)
0x00, 0xBE, /* BKPT #0 */ 0x00, 0xBE, /* BKPT #0 */
}; };
LOG_INFO("Fujitsu MB9[A/B]FXXX: Sector Erase ... (%d to %d)", first, last); LOG_INFO("Fujitsu MB9[A/B]FXXX: Sector Erase ... (%u to %u)", first, last);
/* disable HW watchdog */ /* disable HW watchdog */
retval = target_write_u32(target, 0x40011C00, 0x1ACCE551); retval = target_write_u32(target, 0x40011C00, 0x1ACCE551);
@ -275,7 +276,7 @@ static int fm3_erase(struct flash_bank *bank, int first, int last)
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
/* FASZR = 0x01, Enables CPU Programming Mode (16-bit Flash acccess) */ /* FASZR = 0x01, Enables CPU Programming Mode (16-bit Flash access) */
retval = target_write_u32(target, 0x40000000, 0x0001); retval = target_write_u32(target, 0x40000000, 0x0001);
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
@ -304,7 +305,7 @@ static int fm3_erase(struct flash_bank *bank, int first, int last)
init_reg_param(&reg_params[2], "r2", 32, PARAM_OUT); /* offset */ init_reg_param(&reg_params[2], "r2", 32, PARAM_OUT); /* offset */
/* write code buffer and use Flash sector erase code within fm3 */ /* write code buffer and use Flash sector erase code within fm3 */
for (sector = first ; sector <= last ; sector++) { for (unsigned int sector = first ; sector <= last ; sector++) {
uint32_t offset = bank->sectors[sector].offset; uint32_t offset = bank->sectors[sector].offset;
for (odd = 0; odd < 2 ; odd++) { for (odd = 0; odd < 2 ; odd++) {
@ -335,7 +336,7 @@ static int fm3_erase(struct flash_bank *bank, int first, int last)
destroy_reg_param(&reg_params[1]); destroy_reg_param(&reg_params[1]);
destroy_reg_param(&reg_params[2]); destroy_reg_param(&reg_params[2]);
/* FASZR = 0x02, Enables CPU Run Mode (32-bit Flash acccess) */ /* FASZR = 0x02, Enables CPU Run Mode (32-bit Flash access) */
retval = target_write_u32(target, 0x40000000, 0x0002); retval = target_write_u32(target, 0x40000000, 0x0002);
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
@ -656,7 +657,7 @@ static int fm3_probe(struct flash_bank *bank)
*/ */
num_pages = 10; /* max number of Flash pages for malloc */ num_pages = 10; /* max number of Flash pages for malloc */
fm3_info->probed = 0; fm3_info->probed = false;
bank->sectors = malloc(sizeof(struct flash_sector) * num_pages); bank->sectors = malloc(sizeof(struct flash_sector) * num_pages);
bank->base = 0x00000000; bank->base = 0x00000000;
@ -796,7 +797,7 @@ static int fm3_probe(struct flash_bank *bank)
bank->sectors[9].is_protected = -1; bank->sectors[9].is_protected = -1;
} }
fm3_info->probed = 1; fm3_info->probed = true;
return ERROR_OK; return ERROR_OK;
} }
@ -943,8 +944,6 @@ static int fm3_chip_erase(struct flash_bank *bank)
COMMAND_HANDLER(fm3_handle_chip_erase_command) COMMAND_HANDLER(fm3_handle_chip_erase_command)
{ {
int i;
if (CMD_ARGC < 1) if (CMD_ARGC < 1)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
@ -955,7 +954,7 @@ COMMAND_HANDLER(fm3_handle_chip_erase_command)
if (fm3_chip_erase(bank) == ERROR_OK) { if (fm3_chip_erase(bank) == ERROR_OK) {
/* set all sectors as erased */ /* set all sectors as erased */
for (i = 0; i < bank->num_sectors; i++) for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 1; bank->sectors[i].is_erased = 1;
command_print(CMD, "fm3 chip erase complete"); command_print(CMD, "fm3 chip erase complete");

View File

@ -98,14 +98,15 @@ static int fm4_enter_flash_cpu_rom_mode(struct target *target)
return ERROR_OK; return ERROR_OK;
} }
static int fm4_flash_erase(struct flash_bank *bank, int first, int last) static int fm4_flash_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
struct working_area *workarea; struct working_area *workarea;
struct reg_param reg_params[4]; struct reg_param reg_params[4];
struct armv7m_algorithm armv7m_algo; struct armv7m_algorithm armv7m_algo;
unsigned i; unsigned i;
int retval, sector; int retval;
const uint8_t erase_sector_code[] = { const uint8_t erase_sector_code[] = {
#include "../../../contrib/loaders/flash/fm4/erase.inc" #include "../../../contrib/loaders/flash/fm4/erase.inc"
}; };
@ -115,7 +116,7 @@ static int fm4_flash_erase(struct flash_bank *bank, int first, int last)
return ERROR_TARGET_NOT_HALTED; return ERROR_TARGET_NOT_HALTED;
} }
LOG_DEBUG("Spansion FM4 erase sectors %d to %d", first, last); LOG_DEBUG("Spansion FM4 erase sectors %u to %u", first, last);
retval = fm4_disable_hw_watchdog(target); retval = fm4_disable_hw_watchdog(target);
if (retval != ERROR_OK) if (retval != ERROR_OK)
@ -145,7 +146,7 @@ static int fm4_flash_erase(struct flash_bank *bank, int first, int last)
init_reg_param(&reg_params[2], "r2", 32, PARAM_OUT); init_reg_param(&reg_params[2], "r2", 32, PARAM_OUT);
init_reg_param(&reg_params[3], "r3", 32, PARAM_IN); init_reg_param(&reg_params[3], "r3", 32, PARAM_IN);
for (sector = first; sector <= last; sector++) { for (unsigned int sector = first; sector <= last; sector++) {
uint32_t addr = bank->base + bank->sectors[sector].offset; uint32_t addr = bank->base + bank->sectors[sector].offset;
uint32_t result; uint32_t result;
@ -171,7 +172,7 @@ static int fm4_flash_erase(struct flash_bank *bank, int first, int last)
retval = ERROR_FLASH_OPERATION_FAILED; retval = ERROR_FLASH_OPERATION_FAILED;
goto err_run_ret; goto err_run_ret;
} else if (result != 0) { } else if (result != 0) {
LOG_ERROR("Unexpected error %d from flash sector erase programming algorithm", result); LOG_ERROR("Unexpected error %" PRIu32 " from flash sector erase programming algorithm", result);
retval = ERROR_FLASH_OPERATION_FAILED; retval = ERROR_FLASH_OPERATION_FAILED;
goto err_run_ret; goto err_run_ret;
} else } else
@ -212,7 +213,7 @@ static int fm4_flash_write(struct flash_bank *bank, const uint8_t *buffer,
#include "../../../contrib/loaders/flash/fm4/write.inc" #include "../../../contrib/loaders/flash/fm4/write.inc"
}; };
LOG_DEBUG("Spansion FM4 write at 0x%08" PRIx32 " (%" PRId32 " bytes)", LOG_DEBUG("Spansion FM4 write at 0x%08" PRIx32 " (%" PRIu32 " bytes)",
offset, byte_count); offset, byte_count);
if (offset & 0x1) { if (offset & 0x1) {
@ -221,7 +222,7 @@ static int fm4_flash_write(struct flash_bank *bank, const uint8_t *buffer,
return ERROR_FLASH_DST_BREAKS_ALIGNMENT; return ERROR_FLASH_DST_BREAKS_ALIGNMENT;
} }
if (byte_count & 0x1) { if (byte_count & 0x1) {
LOG_WARNING("length %" PRId32 " is not 2-byte aligned, rounding up", LOG_WARNING("length %" PRIu32 " is not 2-byte aligned, rounding up",
byte_count); byte_count);
} }
@ -272,7 +273,7 @@ static int fm4_flash_write(struct flash_bank *bank, const uint8_t *buffer,
uint32_t halfwords = MIN(halfword_count, data_workarea->size / 2); uint32_t halfwords = MIN(halfword_count, data_workarea->size / 2);
uint32_t addr = bank->base + offset; uint32_t addr = bank->base + offset;
LOG_DEBUG("copying %" PRId32 " bytes to SRAM " TARGET_ADDR_FMT, LOG_DEBUG("copying %" PRIu32 " bytes to SRAM " TARGET_ADDR_FMT,
MIN(halfwords * 2, byte_count), data_workarea->address); MIN(halfwords * 2, byte_count), data_workarea->address);
retval = target_write_buffer(target, data_workarea->address, retval = target_write_buffer(target, data_workarea->address,
@ -283,7 +284,7 @@ static int fm4_flash_write(struct flash_bank *bank, const uint8_t *buffer,
goto err_write_data; goto err_write_data;
} }
LOG_DEBUG("writing 0x%08" PRIx32 "-0x%08" PRIx32 " (%" PRId32 "x)", LOG_DEBUG("writing 0x%08" PRIx32 "-0x%08" PRIx32 " (%" PRIu32 "x)",
addr, addr + halfwords * 2 - 1, halfwords); addr, addr + halfwords * 2 - 1, halfwords);
buf_set_u32(reg_params[0].value, 0, 32, (addr & ~0xffff) | 0xAA8); buf_set_u32(reg_params[0].value, 0, 32, (addr & ~0xffff) | 0xAA8);
@ -311,7 +312,7 @@ static int fm4_flash_write(struct flash_bank *bank, const uint8_t *buffer,
retval = ERROR_FLASH_OPERATION_FAILED; retval = ERROR_FLASH_OPERATION_FAILED;
goto err_run_ret; goto err_run_ret;
} else if (result != 0) { } else if (result != 0) {
LOG_ERROR("Unexpected error %d from flash write " LOG_ERROR("Unexpected error %" PRIu32 " from flash write "
"programming algorithm", result); "programming algorithm", result);
retval = ERROR_FLASH_OPERATION_FAILED; retval = ERROR_FLASH_OPERATION_FAILED;
goto err_run_ret; goto err_run_ret;
@ -347,7 +348,6 @@ static int mb9bf_probe(struct flash_bank *bank)
{ {
struct fm4_flash_bank *fm4_bank = bank->driver_priv; struct fm4_flash_bank *fm4_bank = bank->driver_priv;
uint32_t flash_addr = bank->base; uint32_t flash_addr = bank->base;
int i;
switch (fm4_bank->variant) { switch (fm4_bank->variant) {
case mb9bfx64: case mb9bfx64:
@ -369,10 +369,10 @@ static int mb9bf_probe(struct flash_bank *bank)
return ERROR_FLASH_OPER_UNSUPPORTED; return ERROR_FLASH_OPER_UNSUPPORTED;
} }
LOG_DEBUG("%d sectors", bank->num_sectors); LOG_DEBUG("%u sectors", bank->num_sectors);
bank->sectors = calloc(bank->num_sectors, bank->sectors = calloc(bank->num_sectors,
sizeof(struct flash_sector)); sizeof(struct flash_sector));
for (i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
if (i < 4) if (i < 4)
bank->sectors[i].size = 8 * 1024; bank->sectors[i].size = 8 * 1024;
else if (i == 4) else if (i == 4)
@ -409,7 +409,8 @@ static int s6e2cc_probe(struct flash_bank *bank)
struct fm4_flash_bank *fm4_bank = bank->driver_priv; struct fm4_flash_bank *fm4_bank = bank->driver_priv;
uint32_t u32_value; uint32_t u32_value;
uint32_t flash_addr = bank->base; uint32_t flash_addr = bank->base;
int i, retval, num_sectors, num_extra_sectors; int retval;
unsigned int i, num_extra_sectors, num_sectors;
retval = target_read_u32(target, DFCTRLR, &u32_value); retval = target_read_u32(target, DFCTRLR, &u32_value);
if (retval != ERROR_OK) if (retval != ERROR_OK)
@ -435,7 +436,7 @@ static int s6e2cc_probe(struct flash_bank *bank)
num_extra_sectors = (fm4_bank->macro_nr == 0) ? 1 : 4; num_extra_sectors = (fm4_bank->macro_nr == 0) ? 1 : 4;
bank->num_sectors = num_sectors + num_extra_sectors; bank->num_sectors = num_sectors + num_extra_sectors;
LOG_DEBUG("%d sectors", bank->num_sectors); LOG_DEBUG("%u sectors", bank->num_sectors);
bank->sectors = calloc(bank->num_sectors, bank->sectors = calloc(bank->num_sectors,
sizeof(struct flash_sector)); sizeof(struct flash_sector));
for (i = 0; i < num_sectors; i++) { for (i = 0; i < num_sectors; i++) {
@ -466,12 +467,11 @@ static int s6e2cc_probe(struct flash_bank *bank)
static int s6e2dh_probe(struct flash_bank *bank) static int s6e2dh_probe(struct flash_bank *bank)
{ {
uint32_t flash_addr = bank->base; uint32_t flash_addr = bank->base;
int i;
bank->num_sectors = 10; bank->num_sectors = 10;
bank->sectors = calloc(bank->num_sectors, bank->sectors = calloc(bank->num_sectors,
sizeof(struct flash_sector)); sizeof(struct flash_sector));
for (i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
if (i < 4) if (i < 4)
bank->sectors[i].size = 8 * 1024; bank->sectors[i].size = 8 * 1024;
else if (i == 4) else if (i == 4)

View File

@ -18,6 +18,8 @@
#ifndef OPENOCD_FLASH_NOR_IMP_H #ifndef OPENOCD_FLASH_NOR_IMP_H
#define OPENOCD_FLASH_NOR_IMP_H #define OPENOCD_FLASH_NOR_IMP_H
#include <stdbool.h>
/* this is an internal header */ /* this is an internal header */
#include "core.h" #include "core.h"
#include "driver.h" #include "driver.h"
@ -35,8 +37,10 @@ void flash_bank_add(struct flash_bank *bank);
*/ */
struct flash_bank *flash_bank_list(void); struct flash_bank *flash_bank_list(void);
int flash_driver_erase(struct flash_bank *bank, int first, int last); int flash_driver_erase(struct flash_bank *bank, unsigned int first,
int flash_driver_protect(struct flash_bank *bank, int set, int first, int last); unsigned int last);
int flash_driver_protect(struct flash_bank *bank, int set, unsigned int first,
unsigned int last);
int flash_driver_write(struct flash_bank *bank, int flash_driver_write(struct flash_bank *bank,
uint8_t *buffer, uint32_t offset, uint32_t count); uint8_t *buffer, uint32_t offset, uint32_t count);
int flash_driver_read(struct flash_bank *bank, int flash_driver_read(struct flash_bank *bank,
@ -44,6 +48,6 @@ int flash_driver_read(struct flash_bank *bank,
/* write (optional verify) an image to flash memory of the given target */ /* write (optional verify) an image to flash memory of the given target */
int flash_write_unlock(struct target *target, struct image *image, int flash_write_unlock(struct target *target, struct image *image,
uint32_t *written, int erase, bool unlock); uint32_t *written, bool erase, bool unlock);
#endif /* OPENOCD_FLASH_NOR_IMP_H */ #endif /* OPENOCD_FLASH_NOR_IMP_H */

View File

@ -30,7 +30,7 @@
struct jtagspi_flash_bank { struct jtagspi_flash_bank {
struct jtag_tap *tap; struct jtag_tap *tap;
const struct flash_device *dev; const struct flash_device *dev;
int probed; bool probed;
uint32_t ir; uint32_t ir;
}; };
@ -49,7 +49,7 @@ FLASH_BANK_COMMAND_HANDLER(jtagspi_flash_bank_command)
bank->driver_priv = info; bank->driver_priv = info;
info->tap = NULL; info->tap = NULL;
info->probed = 0; info->probed = false;
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[6], info->ir); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[6], info->ir);
return ERROR_OK; return ERROR_OK;
@ -170,7 +170,7 @@ static int jtagspi_probe(struct flash_bank *bank)
if (info->probed) if (info->probed)
free(bank->sectors); free(bank->sectors);
info->probed = 0; info->probed = false;
if (bank->target->tap == NULL) { if (bank->target->tap == NULL) {
LOG_ERROR("Target has no JTAG tap"); LOG_ERROR("Target has no JTAG tap");
@ -216,7 +216,7 @@ static int jtagspi_probe(struct flash_bank *bank)
return ERROR_FAIL; return ERROR_FAIL;
} }
for (int sector = 0; sector < bank->num_sectors; sector++) { for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
sectors[sector].offset = sector * sectorsize; sectors[sector].offset = sector * sectorsize;
sectors[sector].size = sectorsize; sectors[sector].size = sectorsize;
sectors[sector].is_erased = -1; sectors[sector].is_erased = -1;
@ -224,7 +224,7 @@ static int jtagspi_probe(struct flash_bank *bank)
} }
bank->sectors = sectors; bank->sectors = sectors;
info->probed = 1; info->probed = true;
return ERROR_OK; return ERROR_OK;
} }
@ -299,7 +299,7 @@ static int jtagspi_bulk_erase(struct flash_bank *bank)
return retval; return retval;
} }
static int jtagspi_sector_erase(struct flash_bank *bank, int sector) static int jtagspi_sector_erase(struct flash_bank *bank, unsigned int sector)
{ {
struct jtagspi_flash_bank *info = bank->driver_priv; struct jtagspi_flash_bank *info = bank->driver_priv;
int retval; int retval;
@ -310,19 +310,19 @@ static int jtagspi_sector_erase(struct flash_bank *bank, int sector)
return retval; return retval;
jtagspi_cmd(bank, info->dev->erase_cmd, &bank->sectors[sector].offset, NULL, 0); jtagspi_cmd(bank, info->dev->erase_cmd, &bank->sectors[sector].offset, NULL, 0);
retval = jtagspi_wait(bank, JTAGSPI_MAX_TIMEOUT); retval = jtagspi_wait(bank, JTAGSPI_MAX_TIMEOUT);
LOG_INFO("sector %d took %" PRId64 " ms", sector, timeval_ms() - t0); LOG_INFO("sector %u took %" PRId64 " ms", sector, timeval_ms() - t0);
return retval; return retval;
} }
static int jtagspi_erase(struct flash_bank *bank, int first, int last) static int jtagspi_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
int sector;
struct jtagspi_flash_bank *info = bank->driver_priv; struct jtagspi_flash_bank *info = bank->driver_priv;
int retval = ERROR_OK; int retval = ERROR_OK;
LOG_DEBUG("erase from sector %d to sector %d", first, last); LOG_DEBUG("erase from sector %u to sector %u", first, last);
if ((first < 0) || (last < first) || (last >= bank->num_sectors)) { if ((last < first) || (last >= bank->num_sectors)) {
LOG_ERROR("Flash sector invalid"); LOG_ERROR("Flash sector invalid");
return ERROR_FLASH_SECTOR_INVALID; return ERROR_FLASH_SECTOR_INVALID;
} }
@ -332,9 +332,9 @@ static int jtagspi_erase(struct flash_bank *bank, int first, int last)
return ERROR_FLASH_BANK_NOT_PROBED; return ERROR_FLASH_BANK_NOT_PROBED;
} }
for (sector = first; sector <= last; sector++) { for (unsigned int sector = first; sector <= last; sector++) {
if (bank->sectors[sector].is_protected) { if (bank->sectors[sector].is_protected) {
LOG_ERROR("Flash sector %d protected", sector); LOG_ERROR("Flash sector %u protected", sector);
return ERROR_FAIL; return ERROR_FAIL;
} }
} }
@ -352,7 +352,7 @@ static int jtagspi_erase(struct flash_bank *bank, int first, int last)
if (info->dev->erase_cmd == 0x00) if (info->dev->erase_cmd == 0x00)
return ERROR_FLASH_OPER_UNSUPPORTED; return ERROR_FLASH_OPER_UNSUPPORTED;
for (sector = first; sector <= last; sector++) { for (unsigned int sector = first; sector <= last; sector++) {
retval = jtagspi_sector_erase(bank, sector); retval = jtagspi_sector_erase(bank, sector);
if (retval != ERROR_OK) { if (retval != ERROR_OK) {
LOG_ERROR("Sector erase failed."); LOG_ERROR("Sector erase failed.");
@ -363,11 +363,10 @@ static int jtagspi_erase(struct flash_bank *bank, int first, int last)
return retval; return retval;
} }
static int jtagspi_protect(struct flash_bank *bank, int set, int first, int last) static int jtagspi_protect(struct flash_bank *bank, int set, unsigned int first,
unsigned int last)
{ {
int sector; for (unsigned int sector = first; sector <= last; sector++)
for (sector = first; sector <= last; sector++)
bank->sectors[sector].is_protected = set; bank->sectors[sector].is_protected = set;
return ERROR_OK; return ERROR_OK;
} }

View File

@ -79,7 +79,7 @@
* *
*/ */
/* Addressess */ /* Addresses */
#define FCF_ADDRESS 0x00000400 #define FCF_ADDRESS 0x00000400
#define FCF_FPROT 0x8 #define FCF_FPROT 0x8
#define FCF_FSEC 0xc #define FCF_FSEC 0xc
@ -389,7 +389,6 @@ static const struct kinetis_type kinetis_types_old[] = {
static bool allow_fcf_writes; static bool allow_fcf_writes;
static uint8_t fcf_fopt = 0xff; static uint8_t fcf_fopt = 0xff;
static bool fcf_fopt_configured;
static bool create_banks; static bool create_banks;
@ -507,7 +506,7 @@ COMMAND_HANDLER(kinetis_mdm_halt)
} }
} }
LOG_DEBUG("MDM: halt succeded after %d attempts.", tries); LOG_DEBUG("MDM: halt succeeded after %d attempts.", tries);
target_poll(target); target_poll(target);
/* enable polling in case kinetis_check_flash_security_status disabled it */ /* enable polling in case kinetis_check_flash_security_status disabled it */
@ -1250,7 +1249,7 @@ static int kinetis_write_block(struct flash_bank *bank, const uint8_t *buffer,
uint32_t offset, uint32_t wcount) uint32_t offset, uint32_t wcount)
{ {
struct target *target = bank->target; struct target *target = bank->target;
uint32_t buffer_size = 2048; /* Default minimum value */ uint32_t buffer_size;
struct working_area *write_algorithm; struct working_area *write_algorithm;
struct working_area *source; struct working_area *source;
struct kinetis_flash_bank *k_bank = bank->driver_priv; struct kinetis_flash_bank *k_bank = bank->driver_priv;
@ -1261,10 +1260,6 @@ static int kinetis_write_block(struct flash_bank *bank, const uint8_t *buffer,
int retval; int retval;
uint8_t fstat; uint8_t fstat;
/* Increase buffer_size if needed */
if (buffer_size < (target->working_area_size/2))
buffer_size = (target->working_area_size/2);
/* allocate working area with flash programming code */ /* allocate working area with flash programming code */
if (target_alloc_working_area(target, sizeof(kinetis_flash_write_code), if (target_alloc_working_area(target, sizeof(kinetis_flash_write_code),
&write_algorithm) != ERROR_OK) { &write_algorithm) != ERROR_OK) {
@ -1277,16 +1272,19 @@ static int kinetis_write_block(struct flash_bank *bank, const uint8_t *buffer,
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
/* memory buffer */ /* memory buffer, size *must* be multiple of word */
while (target_alloc_working_area(target, buffer_size, &source) != ERROR_OK) { buffer_size = target_get_working_area_avail(target) & ~(sizeof(uint32_t) - 1);
buffer_size /= 4; if (buffer_size < 256) {
if (buffer_size <= 256) { LOG_WARNING("large enough working area not available, can't do block memory writes");
/* free working area, write algorithm already allocated */ return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
target_free_working_area(target, write_algorithm); } else if (buffer_size > 16384) {
/* probably won't benefit from more than 16k ... */
buffer_size = 16384;
}
LOG_WARNING("No large enough working area available, can't do block memory writes"); if (target_alloc_working_area(target, buffer_size, &source) != ERROR_OK) {
return ERROR_TARGET_RESOURCE_NOT_AVAILABLE; LOG_ERROR("allocating working area failed");
} return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
} }
armv7m_info.common_magic = ARMV7M_COMMON_MAGIC; armv7m_info.common_magic = ARMV7M_COMMON_MAGIC;
@ -1338,7 +1336,8 @@ static int kinetis_write_block(struct flash_bank *bank, const uint8_t *buffer,
return retval; return retval;
} }
static int kinetis_protect(struct flash_bank *bank, int set, int first, int last) static int kinetis_protect(struct flash_bank *bank, int set, unsigned int first,
unsigned int last)
{ {
if (allow_fcf_writes) { if (allow_fcf_writes) {
LOG_ERROR("Protection setting is possible with 'kinetis fcf_source protection' only!"); LOG_ERROR("Protection setting is possible with 'kinetis fcf_source protection' only!");
@ -1350,7 +1349,7 @@ static int kinetis_protect(struct flash_bank *bank, int set, int first, int last
return ERROR_FLASH_BANK_INVALID; return ERROR_FLASH_BANK_INVALID;
} }
for (int i = first; i < bank->num_prot_blocks && i <= last; i++) for (unsigned int i = first; i < bank->num_prot_blocks && i <= last; i++)
bank->prot_blocks[i].is_protected = set; bank->prot_blocks[i].is_protected = set;
LOG_INFO("Protection bits will be written at the next FCF sector erase or write."); LOG_INFO("Protection bits will be written at the next FCF sector erase or write.");
@ -1392,7 +1391,7 @@ static int kinetis_protect_check(struct flash_bank *bank)
} }
b = k_bank->protection_block; b = k_bank->protection_block;
for (int i = 0; i < bank->num_prot_blocks; i++) { for (unsigned int i = 0; i < bank->num_prot_blocks; i++) {
if ((fprot >> b) & 1) if ((fprot >> b) & 1)
bank->prot_blocks[i].is_protected = 0; bank->prot_blocks[i].is_protected = 0;
else else
@ -1430,7 +1429,7 @@ static int kinetis_fill_fcf(struct flash_bank *bank, uint8_t *fcf)
bank_iter = k_bank->bank; bank_iter = k_bank->bank;
if (bank_iter == NULL) { if (bank_iter == NULL) {
LOG_WARNING("Missing bank %u configuration, FCF protection flags may be incomplette", bank_idx); LOG_WARNING("Missing bank %u configuration, FCF protection flags may be incomplete", bank_idx);
continue; continue;
} }
@ -1439,7 +1438,7 @@ static int kinetis_fill_fcf(struct flash_bank *bank, uint8_t *fcf)
assert(bank_iter->prot_blocks); assert(bank_iter->prot_blocks);
if (k_bank->flash_class == FC_PFLASH) { if (k_bank->flash_class == FC_PFLASH) {
for (int i = 0; i < bank_iter->num_prot_blocks; i++) { for (unsigned int i = 0; i < bank_iter->num_prot_blocks; i++) {
if (bank_iter->prot_blocks[i].is_protected == 1) if (bank_iter->prot_blocks[i].is_protected == 1)
fprot &= ~pflash_bit; fprot &= ~pflash_bit;
@ -1447,7 +1446,7 @@ static int kinetis_fill_fcf(struct flash_bank *bank, uint8_t *fcf)
} }
} else if (k_bank->flash_class == FC_FLEX_NVM) { } else if (k_bank->flash_class == FC_FLEX_NVM) {
for (int i = 0; i < bank_iter->num_prot_blocks; i++) { for (unsigned int i = 0; i < bank_iter->num_prot_blocks; i++) {
if (bank_iter->prot_blocks[i].is_protected == 1) if (bank_iter->prot_blocks[i].is_protected == 1)
fdprot &= ~dflash_bit; fdprot &= ~dflash_bit;
@ -1616,7 +1615,8 @@ static void kinetis_invalidate_flash_cache(struct kinetis_chip *k_chip)
} }
static int kinetis_erase(struct flash_bank *bank, int first, int last) static int kinetis_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
int result; int result;
struct kinetis_flash_bank *k_bank = bank->driver_priv; struct kinetis_flash_bank *k_bank = bank->driver_priv;
@ -1639,18 +1639,16 @@ static int kinetis_erase(struct flash_bank *bank, int first, int last)
* requested erase is PFlash or NVM and encompasses the entire * requested erase is PFlash or NVM and encompasses the entire
* block. Should be quicker. * block. Should be quicker.
*/ */
for (int i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
/* set command and sector address */ /* set command and sector address */
result = kinetis_ftfx_command(bank->target, FTFx_CMD_SECTERASE, k_bank->prog_base + bank->sectors[i].offset, result = kinetis_ftfx_command(bank->target, FTFx_CMD_SECTERASE, k_bank->prog_base + bank->sectors[i].offset,
0, 0, 0, 0, 0, 0, 0, 0, NULL); 0, 0, 0, 0, 0, 0, 0, 0, NULL);
if (result != ERROR_OK) { if (result != ERROR_OK) {
LOG_WARNING("erase sector %d failed", i); LOG_WARNING("erase sector %u failed", i);
return ERROR_FLASH_OPERATION_FAILED; return ERROR_FLASH_OPERATION_FAILED;
} }
bank->sectors[i].is_erased = 1;
if (k_bank->prog_base == 0 if (k_bank->prog_base == 0
&& bank->sectors[i].offset <= FCF_ADDRESS && bank->sectors[i].offset <= FCF_ADDRESS
&& bank->sectors[i].offset + bank->sectors[i].size > FCF_ADDRESS + FCF_SIZE) { && bank->sectors[i].offset + bank->sectors[i].size > FCF_ADDRESS + FCF_SIZE) {
@ -1664,7 +1662,8 @@ static int kinetis_erase(struct flash_bank *bank, int first, int last)
result = kinetis_write_inner(bank, fcf_buffer, FCF_ADDRESS, FCF_SIZE); result = kinetis_write_inner(bank, fcf_buffer, FCF_ADDRESS, FCF_SIZE);
if (result != ERROR_OK) if (result != ERROR_OK)
LOG_WARNING("Flash Configuration Field write failed"); LOG_WARNING("Flash Configuration Field write failed");
bank->sectors[i].is_erased = 0; else
LOG_DEBUG("Generated FCF written");
} }
} }
} }
@ -1908,6 +1907,7 @@ static int kinetis_write(struct flash_bank *bank, const uint8_t *buffer,
int result; int result;
bool set_fcf = false; bool set_fcf = false;
bool fcf_in_data_valid = false; bool fcf_in_data_valid = false;
bool fcf_differs = false;
int sect = 0; int sect = 0;
struct kinetis_flash_bank *k_bank = bank->driver_priv; struct kinetis_flash_bank *k_bank = bank->driver_priv;
struct kinetis_chip *k_chip = k_bank->k_chip; struct kinetis_chip *k_chip = k_bank->k_chip;
@ -1940,31 +1940,45 @@ static int kinetis_write(struct flash_bank *bank, const uint8_t *buffer,
&& offset + count >= FCF_ADDRESS + FCF_SIZE; && offset + count >= FCF_ADDRESS + FCF_SIZE;
if (fcf_in_data_valid) { if (fcf_in_data_valid) {
memcpy(fcf_in_data, buffer + FCF_ADDRESS - offset, FCF_SIZE); memcpy(fcf_in_data, buffer + FCF_ADDRESS - offset, FCF_SIZE);
if (memcmp(fcf_in_data + FCF_FPROT, fcf_buffer, 4)) { if (memcmp(fcf_in_data, fcf_buffer, 8)) {
fcf_in_data_valid = false; fcf_differs = true;
LOG_INFO("Flash protection requested in programmed file differs from current setting."); LOG_INFO("Setting of backdoor key is not supported in mode 'kinetis fcf_source protection'.");
}
if (memcmp(fcf_in_data + FCF_FPROT, fcf_buffer + FCF_FPROT, 4)) {
fcf_differs = true;
LOG_INFO("Flash protection requested in the programmed file differs from current setting.");
} }
if (fcf_in_data[FCF_FDPROT] != fcf_buffer[FCF_FDPROT]) { if (fcf_in_data[FCF_FDPROT] != fcf_buffer[FCF_FDPROT]) {
fcf_in_data_valid = false; fcf_differs = true;
LOG_INFO("Data flash protection requested in programmed file differs from current setting."); LOG_INFO("Data flash protection requested in the programmed file differs from current setting.");
} }
if ((fcf_in_data[FCF_FSEC] & 3) != 2) { if ((fcf_in_data[FCF_FSEC] & 3) != 2) {
fcf_in_data_valid = false; fcf_in_data_valid = false;
LOG_INFO("Device security requested in programmed file!"); LOG_INFO("Device security requested in the programmed file! Write denied.");
} else if (k_chip->flash_support & FS_ECC } else if (fcf_in_data[FCF_FSEC] != fcf_buffer[FCF_FSEC]) {
&& fcf_in_data[FCF_FSEC] != fcf_buffer[FCF_FSEC]) { fcf_differs = true;
fcf_in_data_valid = false;
LOG_INFO("Strange unsecure mode 0x%02" PRIx8 LOG_INFO("Strange unsecure mode 0x%02" PRIx8
"requested in programmed file!", " requested in the programmed file, set FSEC = 0x%02" PRIx8
fcf_in_data[FCF_FSEC]); " in the startup code!",
fcf_in_data[FCF_FSEC], fcf_buffer[FCF_FSEC]);
} }
if ((k_chip->flash_support & FS_ECC || fcf_fopt_configured) if (fcf_in_data[FCF_FOPT] != fcf_buffer[FCF_FOPT]) {
&& fcf_in_data[FCF_FOPT] != fcf_fopt) { fcf_differs = true;
fcf_in_data_valid = false; LOG_INFO("FOPT requested in the programmed file differs from current setting, set 'kinetis fopt 0x%02"
LOG_INFO("FOPT requested in programmed file differs from current setting."); PRIx8 "'.", fcf_in_data[FCF_FOPT]);
}
/* If the device has ECC flash, then we cannot re-program FCF */
if (fcf_differs) {
if (k_chip->flash_support & FS_ECC) {
fcf_in_data_valid = false;
LOG_INFO("Cannot re-program FCF. Expect verify errors at FCF (0x400-0x40f).");
} else {
LOG_INFO("Trying to re-program FCF.");
if (!(k_chip->flash_support & FS_PROGRAM_LONGWORD))
LOG_INFO("Flash re-programming may fail on this device!");
}
} }
if (!fcf_in_data_valid)
LOG_INFO("Expect verify errors at FCF (0x408-0x40f).");
} }
} }
@ -2564,7 +2578,7 @@ static int kinetis_probe_chip(struct kinetis_chip *k_chip)
else else
k_chip->pflash_size = k_chip->fcfg2_maxaddr0_shifted * num_blocks / 2; k_chip->pflash_size = k_chip->fcfg2_maxaddr0_shifted * num_blocks / 2;
if (k_chip->pflash_size != 2048<<10) if (k_chip->pflash_size != 2048<<10)
LOG_WARNING("SIM_FCFG1 PFSIZE = 0xf: please check if pflash is %u KB", k_chip->pflash_size>>10); LOG_WARNING("SIM_FCFG1 PFSIZE = 0xf: please check if pflash is %" PRIu32 " KB", k_chip->pflash_size>>10);
break; break;
default: default:
@ -2654,7 +2668,7 @@ static int kinetis_probe(struct flash_bank *bank)
k_bank->protection_block = bank->num_prot_blocks * k_bank->bank_number; k_bank->protection_block = bank->num_prot_blocks * k_bank->bank_number;
size_k = bank->size / 1024; size_k = bank->size / 1024;
LOG_DEBUG("Kinetis bank %u: %" PRIu32 "k PFlash, FTFx base 0x%08" PRIx32 ", sect %u", LOG_DEBUG("Kinetis bank %u: %" PRIu32 "k PFlash, FTFx base 0x%08" PRIx32 ", sect %" PRIu32,
k_bank->bank_number, size_k, k_bank->prog_base, k_bank->sector_size); k_bank->bank_number, size_k, k_bank->prog_base, k_bank->sector_size);
} else if (k_bank->bank_number < num_blocks) { } else if (k_bank->bank_number < num_blocks) {
@ -2689,16 +2703,16 @@ static int kinetis_probe(struct flash_bank *bank)
if (bank->size > limit) { if (bank->size > limit) {
bank->size = limit; bank->size = limit;
LOG_DEBUG("FlexNVM bank %d limited to 0x%08" PRIx32 " due to active EEPROM backup", LOG_DEBUG("FlexNVM bank %u limited to 0x%08" PRIx32 " due to active EEPROM backup",
k_bank->bank_number, limit); k_bank->bank_number, limit);
} }
size_k = bank->size / 1024; size_k = bank->size / 1024;
LOG_DEBUG("Kinetis bank %u: %" PRIu32 "k FlexNVM, FTFx base 0x%08" PRIx32 ", sect %u", LOG_DEBUG("Kinetis bank %u: %" PRIu32 "k FlexNVM, FTFx base 0x%08" PRIx32 ", sect %" PRIu32,
k_bank->bank_number, size_k, k_bank->prog_base, k_bank->sector_size); k_bank->bank_number, size_k, k_bank->prog_base, k_bank->sector_size);
} else { } else {
LOG_ERROR("Cannot determine parameters for bank %d, only %d banks on device", LOG_ERROR("Cannot determine parameters for bank %u, only %u banks on device",
k_bank->bank_number, num_blocks); k_bank->bank_number, num_blocks);
return ERROR_FLASH_BANK_INVALID; return ERROR_FLASH_BANK_INVALID;
} }
@ -2722,17 +2736,14 @@ static int kinetis_probe(struct flash_bank *bank)
" please report to OpenOCD mailing list", fcfg2_maxaddr1); " please report to OpenOCD mailing list", fcfg2_maxaddr1);
} }
if (bank->sectors) { free(bank->sectors);
free(bank->sectors); bank->sectors = NULL;
bank->sectors = NULL;
} free(bank->prot_blocks);
if (bank->prot_blocks) { bank->prot_blocks = NULL;
free(bank->prot_blocks);
bank->prot_blocks = NULL;
}
if (k_bank->sector_size == 0) { if (k_bank->sector_size == 0) {
LOG_ERROR("Unknown sector size for bank %d", bank->bank_number); LOG_ERROR("Unknown sector size for bank %u", bank->bank_number);
return ERROR_FLASH_BANK_INVALID; return ERROR_FLASH_BANK_INVALID;
} }
@ -2827,7 +2838,7 @@ static int kinetis_blank_check(struct flash_bank *bank)
if (block_dirty) { if (block_dirty) {
/* the whole bank is not erased, check sector-by-sector */ /* the whole bank is not erased, check sector-by-sector */
for (int i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
/* normal margin */ /* normal margin */
result = kinetis_ftfx_command(bank->target, FTFx_CMD_SECTSTAT, result = kinetis_ftfx_command(bank->target, FTFx_CMD_SECTSTAT,
k_bank->prog_base + bank->sectors[i].offset, k_bank->prog_base + bank->sectors[i].offset,
@ -2836,14 +2847,14 @@ static int kinetis_blank_check(struct flash_bank *bank)
if (result == ERROR_OK) { if (result == ERROR_OK) {
bank->sectors[i].is_erased = !(ftfx_fstat & 0x01); bank->sectors[i].is_erased = !(ftfx_fstat & 0x01);
} else { } else {
LOG_DEBUG("Ignoring errored PFlash sector blank-check"); LOG_DEBUG("Ignoring error on PFlash sector blank-check");
kinetis_ftfx_clear_error(bank->target); kinetis_ftfx_clear_error(bank->target);
bank->sectors[i].is_erased = -1; bank->sectors[i].is_erased = -1;
} }
} }
} else { } else {
/* the whole bank is erased, update all sectors */ /* the whole bank is erased, update all sectors */
for (int i = 0; i < bank->num_sectors; i++) for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 1; bank->sectors[i].is_erased = 1;
} }
} else { } else {
@ -3034,7 +3045,6 @@ COMMAND_HANDLER(kinetis_fopt_handler)
if (CMD_ARGC == 1) { if (CMD_ARGC == 1) {
fcf_fopt = (uint8_t)strtoul(CMD_ARGV[0], NULL, 0); fcf_fopt = (uint8_t)strtoul(CMD_ARGV[0], NULL, 0);
fcf_fopt_configured = true;
} else { } else {
command_print(CMD, "FCF_FOPT 0x%02" PRIx8, fcf_fopt); command_print(CMD, "FCF_FOPT 0x%02" PRIx8, fcf_fopt);
} }

View File

@ -764,7 +764,8 @@ static int kinetis_ke_write_words(struct flash_bank *bank, const uint8_t *buffer
return retval; return retval;
} }
static int kinetis_ke_protect(struct flash_bank *bank, int set, int first, int last) static int kinetis_ke_protect(struct flash_bank *bank, int set,
unsigned int first, unsigned int last)
{ {
LOG_WARNING("kinetis_ke_protect not supported yet"); LOG_WARNING("kinetis_ke_protect not supported yet");
/* FIXME: TODO */ /* FIXME: TODO */
@ -809,7 +810,7 @@ static int kinetis_ke_protect_check(struct flash_bank *bank)
if (fpopen && fpldis && fphdis) { if (fpopen && fpldis && fphdis) {
LOG_WARNING("No flash protection found."); LOG_WARNING("No flash protection found.");
for (uint32_t i = 0; i < (uint32_t) bank->num_sectors; i++) for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_protected = 0; bank->sectors[i].is_protected = 0;
kinfo->protection_size = 0; kinfo->protection_size = 0;
@ -840,7 +841,7 @@ static int kinetis_ke_protect_check(struct flash_bank *bank)
/* hprot_from indicates from where the upper region is protected */ /* hprot_from indicates from where the upper region is protected */
hprot_from = (0x8000 - hprot_size) / kinfo->sector_size; hprot_from = (0x8000 - hprot_size) / kinfo->sector_size;
for (uint32_t i = 0; i < (uint32_t) bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
/* Check if the sector is in the lower region */ /* Check if the sector is in the lower region */
if (bank->sectors[i].offset < 0x4000) { if (bank->sectors[i].offset < 0x4000) {
@ -964,9 +965,10 @@ COMMAND_HANDLER(kinetis_ke_securing_test)
return kinetis_ke_ftmrx_command(bank, 2, FCCOBIX, FCCOBHI, FCCOBLO, &fstat); return kinetis_ke_ftmrx_command(bank, 2, FCCOBIX, FCCOBHI, FCCOBLO, &fstat);
} }
static int kinetis_ke_erase(struct flash_bank *bank, int first, int last) static int kinetis_ke_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
int result, i; int result;
uint8_t FCCOBIX[2], FCCOBHI[2], FCCOBLO[2], fstat; uint8_t FCCOBIX[2], FCCOBHI[2], FCCOBLO[2], fstat;
bool fcf_erased = false; bool fcf_erased = false;
@ -982,7 +984,7 @@ static int kinetis_ke_erase(struct flash_bank *bank, int first, int last)
if (result != ERROR_OK) if (result != ERROR_OK)
return result; return result;
for (i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
FCCOBIX[0] = 0; FCCOBIX[0] = 0;
FCCOBHI[0] = FTMRX_CMD_ERASESECTOR; FCCOBHI[0] = FTMRX_CMD_ERASESECTOR;
FCCOBLO[0] = (bank->base + bank->sectors[i].offset) >> 16; FCCOBLO[0] = (bank->base + bank->sectors[i].offset) >> 16;
@ -994,7 +996,7 @@ static int kinetis_ke_erase(struct flash_bank *bank, int first, int last)
result = kinetis_ke_ftmrx_command(bank, 2, FCCOBIX, FCCOBHI, FCCOBLO, &fstat); result = kinetis_ke_ftmrx_command(bank, 2, FCCOBIX, FCCOBHI, FCCOBLO, &fstat);
if (result != ERROR_OK) { if (result != ERROR_OK) {
LOG_WARNING("erase sector %d failed", i); LOG_WARNING("erase sector %u failed", i);
return ERROR_FLASH_OPERATION_FAILED; return ERROR_FLASH_OPERATION_FAILED;
} }
@ -1066,7 +1068,7 @@ static int kinetis_ke_write(struct flash_bank *bank, const uint8_t *buffer,
static int kinetis_ke_probe(struct flash_bank *bank) static int kinetis_ke_probe(struct flash_bank *bank)
{ {
int result, i; int result;
uint32_t offset = 0; uint32_t offset = 0;
struct target *target = bank->target; struct target *target = bank->target;
struct kinetis_ke_flash_bank *kinfo = bank->driver_priv; struct kinetis_ke_flash_bank *kinfo = bank->driver_priv;
@ -1143,15 +1145,12 @@ static int kinetis_ke_probe(struct flash_bank *bank)
break; break;
} }
if (bank->sectors) { free(bank->sectors);
free(bank->sectors);
bank->sectors = NULL;
}
assert(bank->num_sectors > 0); assert(bank->num_sectors > 0);
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors); bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
for (i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].offset = offset; bank->sectors[i].offset = offset;
bank->sectors[i].size = kinfo->sector_size; bank->sectors[i].size = kinfo->sector_size;
offset += kinfo->sector_size; offset += kinfo->sector_size;
@ -1207,9 +1206,7 @@ static int kinetis_ke_blank_check(struct flash_bank *bank)
if (fstat & (FTMRX_FSTAT_MGSTAT0_MASK | FTMRX_FSTAT_MGSTAT1_MASK)) { if (fstat & (FTMRX_FSTAT_MGSTAT0_MASK | FTMRX_FSTAT_MGSTAT1_MASK)) {
/* the whole bank is not erased, check sector-by-sector */ /* the whole bank is not erased, check sector-by-sector */
int i; for (unsigned int i = 0; i < bank->num_sectors; i++) {
for (i = 0; i < bank->num_sectors; i++) {
FCCOBIX[0] = 0; FCCOBIX[0] = 0;
FCCOBHI[0] = FTMRX_CMD_SECTIONERASED; FCCOBHI[0] = FTMRX_CMD_SECTIONERASED;
FCCOBLO[0] = (bank->base + bank->sectors[i].offset) >> 16; FCCOBLO[0] = (bank->base + bank->sectors[i].offset) >> 16;
@ -1229,14 +1226,13 @@ static int kinetis_ke_blank_check(struct flash_bank *bank)
if (result == ERROR_OK) { if (result == ERROR_OK) {
bank->sectors[i].is_erased = !(fstat & (FTMRX_FSTAT_MGSTAT0_MASK | FTMRX_FSTAT_MGSTAT1_MASK)); bank->sectors[i].is_erased = !(fstat & (FTMRX_FSTAT_MGSTAT0_MASK | FTMRX_FSTAT_MGSTAT1_MASK));
} else { } else {
LOG_DEBUG("Ignoring errored PFlash sector blank-check"); LOG_DEBUG("Ignoring error on PFlash sector blank-check");
bank->sectors[i].is_erased = -1; bank->sectors[i].is_erased = -1;
} }
} }
} else { } else {
/* the whole bank is erased, update all sectors */ /* the whole bank is erased, update all sectors */
int i; for (unsigned int i = 0; i < bank->num_sectors; i++)
for (i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 1; bank->sectors[i].is_erased = 1;
} }

View File

@ -432,7 +432,7 @@ static int lpc2000_build_sector_list(struct flash_bank *bank)
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors); bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
for (int i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
if (i < 8) { if (i < 8) {
bank->sectors[i].offset = offset; bank->sectors[i].offset = offset;
bank->sectors[i].size = 4 * 1024; bank->sectors[i].size = 4 * 1024;
@ -494,7 +494,7 @@ static int lpc2000_build_sector_list(struct flash_bank *bank)
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors); bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
for (int i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].offset = offset; bank->sectors[i].offset = offset;
/* sectors 0-15 are 4kB-sized, 16 and above are 32kB-sized for LPC17xx/LPC40xx devices */ /* sectors 0-15 are 4kB-sized, 16 and above are 32kB-sized for LPC17xx/LPC40xx devices */
bank->sectors[i].size = (i < 16) ? 4 * 1024 : 32 * 1024; bank->sectors[i].size = (i < 16) ? 4 * 1024 : 32 * 1024;
@ -524,7 +524,7 @@ static int lpc2000_build_sector_list(struct flash_bank *bank)
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors); bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
for (int i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].offset = offset; bank->sectors[i].offset = offset;
/* sectors 0-7 are 8kB-sized, 8 and above are 64kB-sized for LPC43xx devices */ /* sectors 0-7 are 8kB-sized, 8 and above are 64kB-sized for LPC43xx devices */
bank->sectors[i].size = (i < 8) ? 8 * 1024 : 64 * 1024; bank->sectors[i].size = (i < 8) ? 8 * 1024 : 64 * 1024;
@ -568,7 +568,7 @@ static int lpc2000_build_sector_list(struct flash_bank *bank)
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors); bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
for (int i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].offset = offset; bank->sectors[i].offset = offset;
/* all sectors are 1kB-sized for LPC8xx devices */ /* all sectors are 1kB-sized for LPC8xx devices */
bank->sectors[i].size = 1 * 1024; bank->sectors[i].size = 1 * 1024;
@ -599,7 +599,7 @@ static int lpc2000_build_sector_list(struct flash_bank *bank)
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors); bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
for (int i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].offset = offset; bank->sectors[i].offset = offset;
bank->sectors[i].size = (i < LPC11xx_REG_SECTORS ? 4 : 32) * 1024; bank->sectors[i].size = (i < LPC11xx_REG_SECTORS ? 4 : 32) * 1024;
offset += bank->sectors[i].size; offset += bank->sectors[i].size;
@ -629,7 +629,7 @@ static int lpc2000_build_sector_list(struct flash_bank *bank)
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors); bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
for (int i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].offset = offset; bank->sectors[i].offset = offset;
/* all sectors are 4kB-sized */ /* all sectors are 4kB-sized */
bank->sectors[i].size = 4 * 1024; bank->sectors[i].size = 4 * 1024;
@ -657,7 +657,7 @@ static int lpc2000_build_sector_list(struct flash_bank *bank)
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors); bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
for (int i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].offset = offset; bank->sectors[i].offset = offset;
/* all sectors are 32kB-sized */ /* all sectors are 32kB-sized */
bank->sectors[i].size = 32 * 1024; bank->sectors[i].size = 32 * 1024;
@ -863,9 +863,10 @@ static int lpc2000_iap_call(struct flash_bank *bank, struct working_area *iap_wo
return status_code; return status_code;
} }
static int lpc2000_iap_blank_check(struct flash_bank *bank, int first, int last) static int lpc2000_iap_blank_check(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
if ((first < 0) || (last >= bank->num_sectors)) if (last >= bank->num_sectors)
return ERROR_FLASH_SECTOR_INVALID; return ERROR_FLASH_SECTOR_INVALID;
uint32_t param_table[5] = {0}; uint32_t param_table[5] = {0};
@ -881,7 +882,7 @@ static int lpc2000_iap_blank_check(struct flash_bank *bank, int first, int last)
if (lpc2000_info->variant == lpc4300) if (lpc2000_info->variant == lpc4300)
param_table[2] = lpc2000_info->lpc4300_bank; param_table[2] = lpc2000_info->lpc4300_bank;
for (int i = first; i <= last && retval == ERROR_OK; i++) { for (unsigned int i = first; i <= last && retval == ERROR_OK; i++) {
/* check single sector */ /* check single sector */
param_table[0] = param_table[1] = i; param_table[0] = param_table[1] = i;
int status_code = lpc2000_iap_call(bank, iap_working_area, 53, param_table, result_table); int status_code = lpc2000_iap_call(bank, iap_working_area, 53, param_table, result_table);
@ -978,7 +979,8 @@ FLASH_BANK_COMMAND_HANDLER(lpc2000_flash_bank_command)
return ERROR_OK; return ERROR_OK;
} }
static int lpc2000_erase(struct flash_bank *bank, int first, int last) static int lpc2000_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
if (bank->target->state != TARGET_HALTED) { if (bank->target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted"); LOG_ERROR("Target not halted");
@ -1078,7 +1080,7 @@ static int lpc2000_write(struct flash_bank *bank, const uint8_t *buffer, uint32_
int first_sector = 0; int first_sector = 0;
int last_sector = 0; int last_sector = 0;
for (int i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
if (offset >= bank->sectors[i].offset) if (offset >= bank->sectors[i].offset)
first_sector = i; first_sector = i;
if (offset + DIV_ROUND_UP(count, dst_min_alignment) * dst_min_alignment > bank->sectors[i].offset) if (offset + DIV_ROUND_UP(count, dst_min_alignment) * dst_min_alignment > bank->sectors[i].offset)
@ -1168,7 +1170,7 @@ static int lpc2000_write(struct flash_bank *bank, const uint8_t *buffer, uint32_
break; break;
} }
/* Exit if error occured */ /* Exit if error occurred */
if (retval != ERROR_OK) if (retval != ERROR_OK)
break; break;
@ -1210,7 +1212,7 @@ static int lpc2000_write(struct flash_bank *bank, const uint8_t *buffer, uint32_
break; break;
} }
/* Exit if error occured */ /* Exit if error occurred */
if (retval != ERROR_OK) if (retval != ERROR_OK)
break; break;
@ -1554,7 +1556,7 @@ static int get_lpc2000_info(struct flash_bank *bank, char *buf, int buf_size)
{ {
struct lpc2000_flash_bank *lpc2000_info = bank->driver_priv; struct lpc2000_flash_bank *lpc2000_info = bank->driver_priv;
snprintf(buf, buf_size, "lpc2000 flash driver variant: %i, clk: %" PRIi32 "kHz", lpc2000_info->variant, snprintf(buf, buf_size, "lpc2000 flash driver variant: %i, clk: %" PRIu32 "kHz", lpc2000_info->variant,
lpc2000_info->cclk); lpc2000_info->cclk);
return ERROR_OK; return ERROR_OK;

View File

@ -232,17 +232,17 @@ static uint32_t lpc288x_system_ready(struct flash_bank *bank)
return ERROR_OK; return ERROR_OK;
} }
static int lpc288x_erase(struct flash_bank *bank, int first, int last) static int lpc288x_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
uint32_t status; uint32_t status;
int sector;
struct target *target = bank->target; struct target *target = bank->target;
status = lpc288x_system_ready(bank); /* probed? halted? */ status = lpc288x_system_ready(bank); /* probed? halted? */
if (status != ERROR_OK) if (status != ERROR_OK)
return status; return status;
if ((first < 0) || (last < first) || (last >= bank->num_sectors)) { if ((last < first) || (last >= bank->num_sectors)) {
LOG_INFO("Bad sector range"); LOG_INFO("Bad sector range");
return ERROR_FLASH_SECTOR_INVALID; return ERROR_FLASH_SECTOR_INVALID;
} }
@ -250,7 +250,7 @@ static int lpc288x_erase(struct flash_bank *bank, int first, int last)
/* Configure the flash controller timing */ /* Configure the flash controller timing */
lpc288x_set_flash_clk(bank); lpc288x_set_flash_clk(bank);
for (sector = first; sector <= last; sector++) { for (unsigned int sector = first; sector <= last; sector++) {
if (lpc288x_wait_status_busy(bank, 1000) != ERROR_OK) if (lpc288x_wait_status_busy(bank, 1000) != ERROR_OK)
return ERROR_FLASH_OPERATION_FAILED; return ERROR_FLASH_OPERATION_FAILED;
@ -272,7 +272,6 @@ static int lpc288x_write(struct flash_bank *bank, const uint8_t *buffer, uint32_
struct target *target = bank->target; struct target *target = bank->target;
uint32_t bytes_remaining = count; uint32_t bytes_remaining = count;
uint32_t first_sector, last_sector, sector, page; uint32_t first_sector, last_sector, sector, page;
int i;
/* probed? halted? */ /* probed? halted? */
status = lpc288x_system_ready(bank); status = lpc288x_system_ready(bank);
@ -283,7 +282,7 @@ static int lpc288x_write(struct flash_bank *bank, const uint8_t *buffer, uint32_
first_sector = last_sector = 0xffffffff; first_sector = last_sector = 0xffffffff;
/* validate the write range... */ /* validate the write range... */
for (i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
if ((offset >= bank->sectors[i].offset) && if ((offset >= bank->sectors[i].offset) &&
(offset < (bank->sectors[i].offset + bank->sectors[i].size)) && (offset < (bank->sectors[i].offset + bank->sectors[i].size)) &&
(first_sector == 0xffffffff)) { (first_sector == 0xffffffff)) {
@ -379,9 +378,10 @@ static int lpc288x_probe(struct flash_bank *bank)
return ERROR_OK; return ERROR_OK;
} }
static int lpc288x_protect(struct flash_bank *bank, int set, int first, int last) static int lpc288x_protect(struct flash_bank *bank, int set, unsigned int first,
unsigned int last)
{ {
int lockregion, status; int status;
uint32_t value; uint32_t value;
struct target *target = bank->target; struct target *target = bank->target;
@ -390,18 +390,18 @@ static int lpc288x_protect(struct flash_bank *bank, int set, int first, int last
if (status != ERROR_OK) if (status != ERROR_OK)
return status; return status;
if ((first < 0) || (last < first) || (last >= bank->num_sectors)) if ((last < first) || (last >= bank->num_sectors))
return ERROR_FLASH_SECTOR_INVALID; return ERROR_FLASH_SECTOR_INVALID;
/* Configure the flash controller timing */ /* Configure the flash controller timing */
lpc288x_set_flash_clk(bank); lpc288x_set_flash_clk(bank);
for (lockregion = first; lockregion <= last; lockregion++) { for (unsigned int lockregion = first; lockregion <= last; lockregion++) {
if (set) { if (set) {
/* write an odd value to base addy to protect... */ /* write an odd value to base address to protect... */
value = 0x01; value = 0x01;
} else { } else {
/* write an even value to base addy to unprotect... */ /* write an even value to base address to unprotect... */
value = 0x00; value = 0x00;
} }
target_write_u32(target, bank->sectors[lockregion].offset, value); target_write_u32(target, bank->sectors[lockregion].offset, value);

View File

@ -49,8 +49,8 @@
#define FTCTR 0x2020000C /* Flash test control */ #define FTCTR 0x2020000C /* Flash test control */
#define FBWST 0x20200010 /* Flash bridge wait-state */ #define FBWST 0x20200010 /* Flash bridge wait-state */
#define FCRA 0x2020001C /* Flash clock divider */ #define FCRA 0x2020001C /* Flash clock divider */
#define FMSSTART 0x20200020 /* Flash Built-In Selft Test start address */ #define FMSSTART 0x20200020 /* Flash Built-In Self Test start address */
#define FMSSTOP 0x20200024 /* Flash Built-In Selft Test stop address */ #define FMSSTOP 0x20200024 /* Flash Built-In Self Test stop address */
#define FMS16 0x20200028 /* Flash 16-bit signature */ #define FMS16 0x20200028 /* Flash 16-bit signature */
#define FMSW0 0x2020002C /* Flash 128-bit signature Word 0 */ #define FMSW0 0x2020002C /* Flash 128-bit signature Word 0 */
#define FMSW1 0x20200030 /* Flash 128-bit signature Word 1 */ #define FMSW1 0x20200030 /* Flash 128-bit signature Word 1 */
@ -160,7 +160,7 @@ struct lpc2900_flash_bank {
/** /**
* Maximum contiguous block of internal SRAM (bytes). * Maximum contiguous block of internal SRAM (bytes).
* Autodetected by the driver. Not the total amount of SRAM, only the * Autodetected by the driver. Not the total amount of SRAM, only
* the largest \em contiguous block! * the largest \em contiguous block!
*/ */
uint32_t max_ram_block; uint32_t max_ram_block;
@ -174,7 +174,7 @@ static uint32_t lpc2900_read_security_status(struct flash_bank *bank);
static uint32_t lpc2900_run_bist128(struct flash_bank *bank, static uint32_t lpc2900_run_bist128(struct flash_bank *bank,
uint32_t addr_from, uint32_t addr_to, uint32_t addr_from, uint32_t addr_to,
uint32_t signature[4]); uint32_t signature[4]);
static uint32_t lpc2900_address2sector(struct flash_bank *bank, uint32_t offset); static unsigned int lpc2900_address2sector(struct flash_bank *bank, uint32_t offset);
static uint32_t lpc2900_calc_tr(uint32_t clock_var, uint32_t time_var); static uint32_t lpc2900_calc_tr(uint32_t clock_var, uint32_t time_var);
/*********************** Helper functions **************************/ /*********************** Helper functions **************************/
@ -283,9 +283,9 @@ static uint32_t lpc2900_read_security_status(struct flash_bank *bank)
* Anything else is undefined (is_protected = -1). This is treated as * Anything else is undefined (is_protected = -1). This is treated as
* a protected sector! * a protected sector!
*/ */
int sector; for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
int index_t; unsigned int index_t;
for (sector = 0; sector < bank->num_sectors; sector++) {
/* Convert logical sector number to physical sector number */ /* Convert logical sector number to physical sector number */
if (sector <= 4) if (sector <= 4)
index_t = sector + 11; index_t = sector + 11;
@ -356,14 +356,13 @@ static uint32_t lpc2900_run_bist128(struct flash_bank *bank,
* @param bank Pointer to the flash bank descriptor * @param bank Pointer to the flash bank descriptor
* @param offset Offset address relative to bank start * @param offset Offset address relative to bank start
*/ */
static uint32_t lpc2900_address2sector(struct flash_bank *bank, static unsigned int lpc2900_address2sector(struct flash_bank *bank,
uint32_t offset) uint32_t offset)
{ {
uint32_t address = bank->base + offset; uint32_t address = bank->base + offset;
/* Run through all sectors of this bank */ /* Run through all sectors of this bank */
int sector; for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
for (sector = 0; sector < bank->num_sectors; sector++) {
/* Return immediately if address is within the current sector */ /* Return immediately if address is within the current sector */
if (address < (bank->sectors[sector].offset + bank->sectors[sector].size)) if (address < (bank->sectors[sector].offset + bank->sectors[sector].size))
return sector; return sector;
@ -728,9 +727,9 @@ COMMAND_HANDLER(lpc2900_handle_secure_sector_command)
lpc2900_info->risky = 0; lpc2900_info->risky = 0;
/* Read sector range, and do a sanity check. */ /* Read sector range, and do a sanity check. */
int first, last; unsigned int first, last;
COMMAND_PARSE_NUMBER(int, CMD_ARGV[1], first); COMMAND_PARSE_NUMBER(uint, CMD_ARGV[1], first);
COMMAND_PARSE_NUMBER(int, CMD_ARGV[2], last); COMMAND_PARSE_NUMBER(uint, CMD_ARGV[2], last);
if ((first >= bank->num_sectors) || if ((first >= bank->num_sectors) ||
(last >= bank->num_sectors) || (last >= bank->num_sectors) ||
(first > last)) { (first > last)) {
@ -739,12 +738,11 @@ COMMAND_HANDLER(lpc2900_handle_secure_sector_command)
} }
uint8_t page[FLASH_PAGE_SIZE]; uint8_t page[FLASH_PAGE_SIZE];
int sector;
/* Sectors in page 6 */ /* Sectors in page 6 */
if ((first <= 4) || (last >= 8)) { if ((first <= 4) || (last >= 8)) {
memset(&page, 0xff, FLASH_PAGE_SIZE); memset(&page, 0xff, FLASH_PAGE_SIZE);
for (sector = first; sector <= last; sector++) { for (unsigned int sector = first; sector <= last; sector++) {
if (sector <= 4) if (sector <= 4)
memset(&page[0xB0 + 16*sector], 0, 16); memset(&page[0xB0 + 16*sector], 0, 16);
else if (sector >= 8) else if (sector >= 8)
@ -761,7 +759,7 @@ COMMAND_HANDLER(lpc2900_handle_secure_sector_command)
/* Sectors in page 7 */ /* Sectors in page 7 */
if ((first <= 7) && (last >= 5)) { if ((first <= 7) && (last >= 5)) {
memset(&page, 0xff, FLASH_PAGE_SIZE); memset(&page, 0xff, FLASH_PAGE_SIZE);
for (sector = first; sector <= last; sector++) { for (unsigned int sector = first; sector <= last; sector++) {
if ((sector >= 5) && (sector <= 7)) if ((sector >= 5) && (sector <= 7))
memset(&page[0x00 + 16*(sector - 5)], 0, 16); memset(&page[0x00 + 16*(sector - 5)], 0, 16);
} }
@ -945,11 +943,12 @@ FLASH_BANK_COMMAND_HANDLER(lpc2900_flash_bank_command)
* @param first First sector to be erased * @param first First sector to be erased
* @param last Last sector (including) to be erased * @param last Last sector (including) to be erased
*/ */
static int lpc2900_erase(struct flash_bank *bank, int first, int last) static int lpc2900_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
uint32_t status; uint32_t status;
int sector; unsigned int last_unsecured_sector;
int last_unsecured_sector; bool has_unsecured_sector;
struct target *target = bank->target; struct target *target = bank->target;
struct lpc2900_flash_bank *lpc2900_info = bank->driver_priv; struct lpc2900_flash_bank *lpc2900_info = bank->driver_priv;
@ -959,7 +958,7 @@ static int lpc2900_erase(struct flash_bank *bank, int first, int last)
return status; return status;
/* Sanity check on sector range */ /* Sanity check on sector range */
if ((first < 0) || (last < first) || (last >= bank->num_sectors)) { if ((last < first) || (last >= bank->num_sectors)) {
LOG_INFO("Bad sector range"); LOG_INFO("Bad sector range");
return ERROR_FLASH_SECTOR_INVALID; return ERROR_FLASH_SECTOR_INVALID;
} }
@ -974,16 +973,19 @@ static int lpc2900_erase(struct flash_bank *bank, int first, int last)
* a special way. * a special way.
*/ */
last_unsecured_sector = -1; last_unsecured_sector = -1;
for (sector = first; sector <= last; sector++) { has_unsecured_sector = false;
if (!bank->sectors[sector].is_protected) for (unsigned int sector = first; sector <= last; sector++) {
if (!bank->sectors[sector].is_protected) {
last_unsecured_sector = sector; last_unsecured_sector = sector;
has_unsecured_sector = true;
}
} }
/* Exit now, in case of the rare constellation where all sectors in range /* Exit now, in case of the rare constellation where all sectors in range
* are secured. This is regarded a success, since erasing/programming of * are secured. This is regarded a success, since erasing/programming of
* secured sectors shall be handled transparently. * secured sectors shall be handled transparently.
*/ */
if (last_unsecured_sector == -1) if (!has_unsecured_sector)
return ERROR_OK; return ERROR_OK;
/* Enable flash block and set the correct CRA clock of 66 kHz */ /* Enable flash block and set the correct CRA clock of 66 kHz */
@ -998,7 +1000,7 @@ static int lpc2900_erase(struct flash_bank *bank, int first, int last)
FLASH_ERASE_TIME)); FLASH_ERASE_TIME));
/* Sectors are marked for erasure, then erased all together */ /* Sectors are marked for erasure, then erased all together */
for (sector = first; sector <= last_unsecured_sector; sector++) { for (unsigned int sector = first; sector <= last_unsecured_sector; sector++) {
/* Only mark sectors that aren't secured. Any attempt to erase a group /* Only mark sectors that aren't secured. Any attempt to erase a group
* of sectors will fail if any single one of them is secured! * of sectors will fail if any single one of them is secured!
*/ */
@ -1059,7 +1061,6 @@ static int lpc2900_write(struct flash_bank *bank, const uint8_t *buffer,
uint32_t num_bytes; uint32_t num_bytes;
struct target *target = bank->target; struct target *target = bank->target;
struct lpc2900_flash_bank *lpc2900_info = bank->driver_priv; struct lpc2900_flash_bank *lpc2900_info = bank->driver_priv;
int sector;
int retval; int retval;
static const uint32_t write_target_code[] = { static const uint32_t write_target_code[] = {
@ -1111,7 +1112,7 @@ static int lpc2900_write(struct flash_bank *bank, const uint8_t *buffer,
lpc2900_read_security_status(bank); lpc2900_read_security_status(bank);
/* Unprotect all involved sectors */ /* Unprotect all involved sectors */
for (sector = 0; sector < bank->num_sectors; sector++) { for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
/* Start address in or before this sector? /* Start address in or before this sector?
* End address in or behind this sector? */ * End address in or behind this sector? */
if (((bank->base + offset) < if (((bank->base + offset) <
@ -1179,7 +1180,7 @@ static int lpc2900_write(struct flash_bank *bank, const uint8_t *buffer,
while (count != 0) { while (count != 0) {
uint32_t this_npages; uint32_t this_npages;
const uint8_t *this_buffer; const uint8_t *this_buffer;
int start_sector = lpc2900_address2sector(bank, offset); unsigned int start_sector = lpc2900_address2sector(bank, offset);
/* First page / last page / rest */ /* First page / last page / rest */
if (offset % FLASH_PAGE_SIZE) { if (offset % FLASH_PAGE_SIZE) {
@ -1208,7 +1209,7 @@ static int lpc2900_write(struct flash_bank *bank, const uint8_t *buffer,
this_buffer = buffer; this_buffer = buffer;
/* Make sure we stop at the next secured sector */ /* Make sure we stop at the next secured sector */
sector = start_sector + 1; unsigned int sector = start_sector + 1;
while (sector < bank->num_sectors) { while (sector < bank->num_sectors) {
/* Secured? */ /* Secured? */
if (bank->sectors[sector].is_protected) { if (bank->sectors[sector].is_protected) {
@ -1230,7 +1231,7 @@ static int lpc2900_write(struct flash_bank *bank, const uint8_t *buffer,
/* Skip the current sector if it is secured */ /* Skip the current sector if it is secured */
if (bank->sectors[start_sector].is_protected) { if (bank->sectors[start_sector].is_protected) {
LOG_DEBUG("Skip secured sector %d", LOG_DEBUG("Skip secured sector %u",
start_sector); start_sector);
/* Stop if this is the last sector */ /* Stop if this is the last sector */
@ -1371,7 +1372,6 @@ static int lpc2900_probe(struct flash_bank *bank)
{ {
struct lpc2900_flash_bank *lpc2900_info = bank->driver_priv; struct lpc2900_flash_bank *lpc2900_info = bank->driver_priv;
struct target *target = bank->target; struct target *target = bank->target;
int i = 0;
uint32_t offset; uint32_t offset;
@ -1467,8 +1467,8 @@ static int lpc2900_probe(struct flash_bank *bank)
} }
/* Show detected device */ /* Show detected device */
LOG_INFO("Flash bank %d: Device %s, %" PRIu32 LOG_INFO("Flash bank %u: Device %s, %" PRIu32
" KiB in %d sectors", " KiB in %u sectors",
bank->bank_number, bank->bank_number,
lpc2900_info->target_name, bank->size / KiB, lpc2900_info->target_name, bank->size / KiB,
bank->num_sectors); bank->num_sectors);
@ -1487,7 +1487,7 @@ static int lpc2900_probe(struct flash_bank *bank)
bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors); bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors);
offset = 0; offset = 0;
for (i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].offset = offset; bank->sectors[i].offset = offset;
bank->sectors[i].is_erased = -1; bank->sectors[i].is_erased = -1;
bank->sectors[i].is_protected = -1; bank->sectors[i].is_protected = -1;
@ -1501,7 +1501,7 @@ static int lpc2900_probe(struct flash_bank *bank)
* that has more than 19 sectors. Politely ask for a fix then. * that has more than 19 sectors. Politely ask for a fix then.
*/ */
bank->sectors[i].size = 0; bank->sectors[i].size = 0;
LOG_ERROR("Never heard about sector %d", i); LOG_ERROR("Never heard about sector %u", i);
} }
offset += bank->sectors[i].size; offset += bank->sectors[i].size;
@ -1535,11 +1535,10 @@ static int lpc2900_erase_check(struct flash_bank *bank)
return status; return status;
} }
/* Use the BIST (Built-In Selft Test) to generate a signature of each flash /* Use the BIST (Built-In Self Test) to generate a signature of each flash
* sector. Compare against the expected signature of an empty sector. * sector. Compare against the expected signature of an empty sector.
*/ */
int sector; for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
for (sector = 0; sector < bank->num_sectors; sector++) {
uint32_t signature[4]; uint32_t signature[4];
status = lpc2900_run_bist128(bank, bank->sectors[sector].offset, status = lpc2900_run_bist128(bank, bank->sectors[sector].offset,
bank->sectors[sector].offset + (bank->sectors[sector].size - 1), signature); bank->sectors[sector].offset + (bank->sectors[sector].size - 1), signature);

View File

@ -47,7 +47,7 @@
#define SPIFI_INIT_STACK_SIZE 512 #define SPIFI_INIT_STACK_SIZE 512
struct lpcspifi_flash_bank { struct lpcspifi_flash_bank {
int probed; bool probed;
uint32_t ssp_base; uint32_t ssp_base;
uint32_t io_base; uint32_t io_base;
uint32_t ioconfig_base; uint32_t ioconfig_base;
@ -72,7 +72,7 @@ FLASH_BANK_COMMAND_HANDLER(lpcspifi_flash_bank_command)
} }
bank->driver_priv = lpcspifi_info; bank->driver_priv = lpcspifi_info;
lpcspifi_info->probed = 0; lpcspifi_info->probed = false;
return ERROR_OK; return ERROR_OK;
} }
@ -216,7 +216,7 @@ static int lpcspifi_set_hw_mode(struct flash_bank *bank)
/* Run the algorithm */ /* Run the algorithm */
LOG_DEBUG("Running SPIFI init algorithm"); LOG_DEBUG("Running SPIFI init algorithm");
retval = target_run_algorithm(target, 0 , NULL, 2, reg_params, retval = target_run_algorithm(target, 0, NULL, 2, reg_params,
spifi_init_algorithm->address, spifi_init_algorithm->address,
spifi_init_algorithm->address + sizeof(spifi_init_code) - 2, spifi_init_algorithm->address + sizeof(spifi_init_code) - 2,
1000, &armv7m_info); 1000, &armv7m_info);
@ -414,7 +414,8 @@ static int lpcspifi_bulk_erase(struct flash_bank *bank)
return retval; return retval;
} }
static int lpcspifi_erase(struct flash_bank *bank, int first, int last) static int lpcspifi_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
struct lpcspifi_flash_bank *lpcspifi_info = bank->driver_priv; struct lpcspifi_flash_bank *lpcspifi_info = bank->driver_priv;
@ -422,16 +423,15 @@ static int lpcspifi_erase(struct flash_bank *bank, int first, int last)
struct armv7m_algorithm armv7m_info; struct armv7m_algorithm armv7m_info;
struct working_area *erase_algorithm; struct working_area *erase_algorithm;
int retval = ERROR_OK; int retval = ERROR_OK;
int sector;
LOG_DEBUG("erase from sector %d to sector %d", first, last); LOG_DEBUG("erase from sector %u to sector %u", first, last);
if (target->state != TARGET_HALTED) { if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted"); LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED; return ERROR_TARGET_NOT_HALTED;
} }
if ((first < 0) || (last < first) || (last >= bank->num_sectors)) { if ((last < first) || (last >= bank->num_sectors)) {
LOG_ERROR("Flash sector invalid"); LOG_ERROR("Flash sector invalid");
return ERROR_FLASH_SECTOR_INVALID; return ERROR_FLASH_SECTOR_INVALID;
} }
@ -441,9 +441,9 @@ static int lpcspifi_erase(struct flash_bank *bank, int first, int last)
return ERROR_FLASH_BANK_NOT_PROBED; return ERROR_FLASH_BANK_NOT_PROBED;
} }
for (sector = first; sector <= last; sector++) { for (unsigned int sector = first; sector <= last; sector++) {
if (bank->sectors[sector].is_protected) { if (bank->sectors[sector].is_protected) {
LOG_ERROR("Flash sector %d protected", sector); LOG_ERROR("Flash sector %u protected", sector);
return ERROR_FAIL; return ERROR_FAIL;
} }
} }
@ -550,7 +550,7 @@ static int lpcspifi_erase(struct flash_bank *bank, int first, int last)
buf_set_u32(reg_params[3].value, 0, 32, bank->sectors[first].size); buf_set_u32(reg_params[3].value, 0, 32, bank->sectors[first].size);
/* Run the algorithm */ /* Run the algorithm */
retval = target_run_algorithm(target, 0 , NULL, 4, reg_params, retval = target_run_algorithm(target, 0, NULL, 4, reg_params,
erase_algorithm->address, erase_algorithm->address,
erase_algorithm->address + sizeof(lpcspifi_flash_erase_code) - 4, erase_algorithm->address + sizeof(lpcspifi_flash_erase_code) - 4,
3000*(last - first + 1), &armv7m_info); 3000*(last - first + 1), &armv7m_info);
@ -571,11 +571,9 @@ static int lpcspifi_erase(struct flash_bank *bank, int first, int last)
} }
static int lpcspifi_protect(struct flash_bank *bank, int set, static int lpcspifi_protect(struct flash_bank *bank, int set,
int first, int last) unsigned int first, unsigned int last)
{ {
int sector; for (unsigned int sector = first; sector <= last; sector++)
for (sector = first; sector <= last; sector++)
bank->sectors[sector].is_protected = set; bank->sectors[sector].is_protected = set;
return ERROR_OK; return ERROR_OK;
} }
@ -590,7 +588,6 @@ static int lpcspifi_write(struct flash_bank *bank, const uint8_t *buffer,
struct reg_param reg_params[5]; struct reg_param reg_params[5];
struct armv7m_algorithm armv7m_info; struct armv7m_algorithm armv7m_info;
struct working_area *write_algorithm; struct working_area *write_algorithm;
int sector;
int retval = ERROR_OK; int retval = ERROR_OK;
LOG_DEBUG("offset=0x%08" PRIx32 " count=0x%08" PRIx32, LOG_DEBUG("offset=0x%08" PRIx32 " count=0x%08" PRIx32,
@ -607,14 +604,14 @@ static int lpcspifi_write(struct flash_bank *bank, const uint8_t *buffer,
} }
/* Check sector protection */ /* Check sector protection */
for (sector = 0; sector < bank->num_sectors; sector++) { for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
/* Start offset in or before this sector? */ /* Start offset in or before this sector? */
/* End offset in or behind this sector? */ /* End offset in or behind this sector? */
if ((offset < if ((offset <
(bank->sectors[sector].offset + bank->sectors[sector].size)) (bank->sectors[sector].offset + bank->sectors[sector].size))
&& ((offset + count - 1) >= bank->sectors[sector].offset) && ((offset + count - 1) >= bank->sectors[sector].offset)
&& bank->sectors[sector].is_protected) { && bank->sectors[sector].is_protected) {
LOG_ERROR("Flash sector %d protected", sector); LOG_ERROR("Flash sector %u protected", sector);
return ERROR_FAIL; return ERROR_FAIL;
} }
} }
@ -852,7 +849,7 @@ static int lpcspifi_probe(struct flash_bank *bank)
/* If we've already probed, we should be fine to skip this time. */ /* If we've already probed, we should be fine to skip this time. */
if (lpcspifi_info->probed) if (lpcspifi_info->probed)
return ERROR_OK; return ERROR_OK;
lpcspifi_info->probed = 0; lpcspifi_info->probed = false;
lpcspifi_info->ssp_base = 0x40083000; lpcspifi_info->ssp_base = 0x40083000;
lpcspifi_info->io_base = 0x400F4000; lpcspifi_info->io_base = 0x400F4000;
@ -902,7 +899,7 @@ static int lpcspifi_probe(struct flash_bank *bank)
return ERROR_FAIL; return ERROR_FAIL;
} }
for (int sector = 0; sector < bank->num_sectors; sector++) { for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
sectors[sector].offset = sector * sectorsize; sectors[sector].offset = sector * sectorsize;
sectors[sector].size = sectorsize; sectors[sector].size = sectorsize;
sectors[sector].is_erased = -1; sectors[sector].is_erased = -1;
@ -911,7 +908,7 @@ static int lpcspifi_probe(struct flash_bank *bank)
bank->sectors = sectors; bank->sectors = sectors;
lpcspifi_info->probed = 1; lpcspifi_info->probed = true;
return ERROR_OK; return ERROR_OK;
} }

View File

@ -70,17 +70,17 @@
static int max32xxx_mass_erase(struct flash_bank *bank); static int max32xxx_mass_erase(struct flash_bank *bank);
struct max32xxx_flash_bank { struct max32xxx_flash_bank {
int probed; bool probed;
int max326xx; int max326xx;
unsigned int flash_size; unsigned int flash_size;
unsigned int flc_base; unsigned int flc_base;
unsigned int sector_size; unsigned int sector_size;
unsigned int clkdiv_value; unsigned int clkdiv_value;
unsigned int int_state; uint32_t int_state;
unsigned int burst_size_bits; unsigned int burst_size_bits;
}; };
/* see contib/loaders/flash/max32xxx/max32xxx.s for src */ /* see contrib/loaders/flash/max32xxx/max32xxx.s for src */
static const uint8_t write_code[] = { static const uint8_t write_code[] = {
#include "../../contrib/loaders/flash/max32xxx/max32xxx.inc" #include "../../contrib/loaders/flash/max32xxx/max32xxx.inc"
}; };
@ -98,13 +98,13 @@ FLASH_BANK_COMMAND_HANDLER(max32xxx_flash_bank_command)
} }
info = calloc(sizeof(struct max32xxx_flash_bank), 1); info = calloc(sizeof(struct max32xxx_flash_bank), 1);
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], info->flash_size); COMMAND_PARSE_NUMBER(uint, CMD_ARGV[2], info->flash_size);
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[6], info->flc_base); COMMAND_PARSE_NUMBER(uint, CMD_ARGV[6], info->flc_base);
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[7], info->sector_size); COMMAND_PARSE_NUMBER(uint, CMD_ARGV[7], info->sector_size);
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[8], info->clkdiv_value); COMMAND_PARSE_NUMBER(uint, CMD_ARGV[8], info->clkdiv_value);
if (CMD_ARGC > 9) if (CMD_ARGC > 9)
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[9], info->burst_size_bits); COMMAND_PARSE_NUMBER(uint, CMD_ARGV[9], info->burst_size_bits);
else else
info->burst_size_bits = 32; info->burst_size_bits = 32;
@ -118,7 +118,7 @@ static int get_info(struct flash_bank *bank, char *buf, int buf_size)
int printed; int printed;
struct max32xxx_flash_bank *info = bank->driver_priv; struct max32xxx_flash_bank *info = bank->driver_priv;
if (info->probed == 0) if (!info->probed)
return ERROR_FLASH_BANK_NOT_PROBED; return ERROR_FLASH_BANK_NOT_PROBED;
printed = snprintf(buf, buf_size, "\nMaxim Integrated max32xxx flash driver\n"); printed = snprintf(buf, buf_size, "\nMaxim Integrated max32xxx flash driver\n");
@ -209,21 +209,20 @@ static int max32xxx_protect_check(struct flash_bank *bank)
{ {
struct max32xxx_flash_bank *info = bank->driver_priv; struct max32xxx_flash_bank *info = bank->driver_priv;
struct target *target = bank->target; struct target *target = bank->target;
int i;
uint32_t temp_reg; uint32_t temp_reg;
if (info->probed == 0) if (!info->probed)
return ERROR_FLASH_BANK_NOT_PROBED; return ERROR_FLASH_BANK_NOT_PROBED;
if (!info->max326xx) { if (!info->max326xx) {
for (i = 0; i < bank->num_sectors; i++) for (unsigned i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_protected = -1; bank->sectors[i].is_protected = -1;
return ERROR_FLASH_OPER_UNSUPPORTED; return ERROR_FLASH_OPER_UNSUPPORTED;
} }
/* Check the protection */ /* Check the protection */
for (i = 0; i < bank->num_sectors; i++) { for (unsigned i = 0; i < bank->num_sectors; i++) {
if (i%32 == 0) if (i%32 == 0)
target_read_u32(target, info->flc_base + FLSH_PROT + ((i/32)*4), &temp_reg); target_read_u32(target, info->flc_base + FLSH_PROT + ((i/32)*4), &temp_reg);
@ -235,9 +234,9 @@ static int max32xxx_protect_check(struct flash_bank *bank)
return ERROR_OK; return ERROR_OK;
} }
static int max32xxx_erase(struct flash_bank *bank, int first, int last) static int max32xxx_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
int banknr;
uint32_t flsh_cn, flsh_int; uint32_t flsh_cn, flsh_int;
struct max32xxx_flash_bank *info = bank->driver_priv; struct max32xxx_flash_bank *info = bank->driver_priv;
struct target *target = bank->target; struct target *target = bank->target;
@ -249,10 +248,10 @@ static int max32xxx_erase(struct flash_bank *bank, int first, int last)
return ERROR_TARGET_NOT_HALTED; return ERROR_TARGET_NOT_HALTED;
} }
if (info->probed == 0) if (!info->probed)
return ERROR_FLASH_BANK_NOT_PROBED; return ERROR_FLASH_BANK_NOT_PROBED;
if ((first < 0) || (last < first) || (last >= bank->num_sectors)) if ((last < first) || (last >= bank->num_sectors))
return ERROR_FLASH_SECTOR_INVALID; return ERROR_FLASH_SECTOR_INVALID;
if ((first == 0) && (last == (bank->num_sectors - 1))) if ((first == 0) && (last == (bank->num_sectors - 1)))
@ -265,11 +264,11 @@ static int max32xxx_erase(struct flash_bank *bank, int first, int last)
return retval; return retval;
int erased = 0; int erased = 0;
for (banknr = first; banknr <= last; banknr++) { for (unsigned int banknr = first; banknr <= last; banknr++) {
/* Check the protection */ /* Check the protection */
if (bank->sectors[banknr].is_protected == 1) { if (bank->sectors[banknr].is_protected == 1) {
LOG_WARNING("Flash sector %d is protected", banknr); LOG_WARNING("Flash sector %u is protected", banknr);
continue; continue;
} else } else
erased = 1; erased = 1;
@ -311,7 +310,7 @@ static int max32xxx_erase(struct flash_bank *bank, int first, int last)
} }
if (!erased) { if (!erased) {
LOG_ERROR("All pages protected %d to %d", first, last); LOG_ERROR("All pages protected %u to %u", first, last);
max32xxx_flash_op_post(bank); max32xxx_flash_op_post(bank);
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -322,11 +321,11 @@ static int max32xxx_erase(struct flash_bank *bank, int first, int last)
return ERROR_OK; return ERROR_OK;
} }
static int max32xxx_protect(struct flash_bank *bank, int set, int first, int last) static int max32xxx_protect(struct flash_bank *bank, int set,
unsigned int first, unsigned int last)
{ {
struct max32xxx_flash_bank *info = bank->driver_priv; struct max32xxx_flash_bank *info = bank->driver_priv;
struct target *target = bank->target; struct target *target = bank->target;
int page;
uint32_t temp_reg; uint32_t temp_reg;
if (bank->target->state != TARGET_HALTED) { if (bank->target->state != TARGET_HALTED) {
@ -334,17 +333,17 @@ static int max32xxx_protect(struct flash_bank *bank, int set, int first, int las
return ERROR_TARGET_NOT_HALTED; return ERROR_TARGET_NOT_HALTED;
} }
if (info->probed == 0) if (!info->probed)
return ERROR_FLASH_BANK_NOT_PROBED; return ERROR_FLASH_BANK_NOT_PROBED;
if (!info->max326xx) if (!info->max326xx)
return ERROR_FLASH_OPER_UNSUPPORTED; return ERROR_FLASH_OPER_UNSUPPORTED;
if ((first < 0) || (last < first) || (last >= bank->num_sectors)) if ((last < first) || (last >= bank->num_sectors))
return ERROR_FLASH_SECTOR_INVALID; return ERROR_FLASH_SECTOR_INVALID;
/* Setup the protection on the pages given */ /* Setup the protection on the pages given */
for (page = first; page <= last; page++) { for (unsigned int page = first; page <= last; page++) {
if (set) { if (set) {
/* Set the write/erase bit for this page */ /* Set the write/erase bit for this page */
target_read_u32(target, info->flc_base + FLSH_PROT + (page/32), &temp_reg); target_read_u32(target, info->flc_base + FLSH_PROT + (page/32), &temp_reg);
@ -460,7 +459,7 @@ static int max32xxx_write(struct flash_bank *bank, const uint8_t *buffer,
LOG_DEBUG("bank=%p buffer=%p offset=%08" PRIx32 " count=%08" PRIx32 "", LOG_DEBUG("bank=%p buffer=%p offset=%08" PRIx32 " count=%08" PRIx32 "",
bank, buffer, offset, count); bank, buffer, offset, count);
if (info->probed == 0) if (!info->probed)
return ERROR_FLASH_BANK_NOT_PROBED; return ERROR_FLASH_BANK_NOT_PROBED;
if (offset & 0x3) { if (offset & 0x3) {
@ -523,7 +522,7 @@ static int max32xxx_write(struct flash_bank *bank, const uint8_t *buffer,
} while ((--retry > 0) && (flsh_cn & FLSH_CN_PEND)); } while ((--retry > 0) && (flsh_cn & FLSH_CN_PEND));
if (retry <= 0) { if (retry <= 0) {
LOG_ERROR("Timed out waiting for flash write @ 0x%08x", address); LOG_ERROR("Timed out waiting for flash write @ 0x%08" PRIx32, address);
return ERROR_FLASH_OPERATION_FAILED; return ERROR_FLASH_OPERATION_FAILED;
} }
@ -544,7 +543,7 @@ static int max32xxx_write(struct flash_bank *bank, const uint8_t *buffer,
while (remaining >= 16) { while (remaining >= 16) {
if ((address & 0xFFF) == 0) if ((address & 0xFFF) == 0)
LOG_DEBUG("Writing @ 0x%08x", address); LOG_DEBUG("Writing @ 0x%08" PRIx32, address);
target_write_buffer(target, info->flc_base + FLSH_DATA0, 16, buffer); target_write_buffer(target, info->flc_base + FLSH_DATA0, 16, buffer);
flsh_cn |= 0x00000001; flsh_cn |= 0x00000001;
@ -557,7 +556,7 @@ static int max32xxx_write(struct flash_bank *bank, const uint8_t *buffer,
} while ((--retry > 0) && (flsh_cn & FLSH_CN_PEND)); } while ((--retry > 0) && (flsh_cn & FLSH_CN_PEND));
if (retry <= 0) { if (retry <= 0) {
LOG_ERROR("Timed out waiting for flash write @ 0x%08x", address); LOG_ERROR("Timed out waiting for flash write @ 0x%08" PRIx32, address);
return ERROR_FLASH_OPERATION_FAILED; return ERROR_FLASH_OPERATION_FAILED;
} }
@ -588,7 +587,7 @@ static int max32xxx_write(struct flash_bank *bank, const uint8_t *buffer,
} while ((--retry > 0) && (flsh_cn & FLSH_CN_PEND)); } while ((--retry > 0) && (flsh_cn & FLSH_CN_PEND));
if (retry <= 0) { if (retry <= 0) {
LOG_ERROR("Timed out waiting for flash write @ 0x%08x", address); LOG_ERROR("Timed out waiting for flash write @ 0x%08" PRIx32, address);
return ERROR_FLASH_OPERATION_FAILED; return ERROR_FLASH_OPERATION_FAILED;
} }
@ -626,7 +625,7 @@ static int max32xxx_write(struct flash_bank *bank, const uint8_t *buffer,
} while ((--retry > 0) && (flsh_cn & FLSH_CN_PEND)); } while ((--retry > 0) && (flsh_cn & FLSH_CN_PEND));
if (retry <= 0) { if (retry <= 0) {
LOG_ERROR("Timed out waiting for flash write @ 0x%08x", address); LOG_ERROR("Timed out waiting for flash write @ 0x%08" PRIx32, address);
return ERROR_FLASH_OPERATION_FAILED; return ERROR_FLASH_OPERATION_FAILED;
} }
} }
@ -634,7 +633,7 @@ static int max32xxx_write(struct flash_bank *bank, const uint8_t *buffer,
/* Check access violations */ /* Check access violations */
target_read_u32(target, info->flc_base + FLSH_INT, &flsh_int); target_read_u32(target, info->flc_base + FLSH_INT, &flsh_int);
if (flsh_int & FLSH_INT_AF) { if (flsh_int & FLSH_INT_AF) {
LOG_ERROR("Flash Error writing 0x%x bytes at 0x%08x", count, offset); LOG_ERROR("Flash Error writing 0x%" PRIx32 " bytes at 0x%08" PRIx32, count, offset);
max32xxx_flash_op_post(bank); max32xxx_flash_op_post(bank);
return ERROR_FLASH_OPERATION_FAILED; return ERROR_FLASH_OPERATION_FAILED;
} }
@ -652,17 +651,14 @@ static int max32xxx_probe(struct flash_bank *bank)
uint32_t arm_id[2]; uint32_t arm_id[2];
uint16_t arm_pid; uint16_t arm_pid;
if (bank->sectors) { free(bank->sectors);
free(bank->sectors);
bank->sectors = NULL;
}
/* provide this for the benefit of the NOR flash framework */ /* provide this for the benefit of the NOR flash framework */
bank->size = info->flash_size; bank->size = info->flash_size;
bank->num_sectors = info->flash_size / info->sector_size; bank->num_sectors = info->flash_size / info->sector_size;
bank->sectors = calloc(bank->num_sectors, sizeof(struct flash_sector)); bank->sectors = calloc(bank->num_sectors, sizeof(struct flash_sector));
for (int i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].offset = i * info->sector_size; bank->sectors[i].offset = i * info->sector_size;
bank->sectors[i].size = info->sector_size; bank->sectors[i].size = info->sector_size;
bank->sectors[i].is_erased = -1; bank->sectors[i].is_erased = -1;
@ -679,7 +675,7 @@ static int max32xxx_probe(struct flash_bank *bank)
if ((arm_pid == ARM_PID_DEFAULT_CM3) || arm_pid == ARM_PID_DEFAULT_CM4) { if ((arm_pid == ARM_PID_DEFAULT_CM3) || arm_pid == ARM_PID_DEFAULT_CM4) {
uint32_t max326xx_id; uint32_t max326xx_id;
target_read_u32(target, MAX326XX_ID_REG, &max326xx_id); target_read_u32(target, MAX326XX_ID_REG, &max326xx_id);
LOG_DEBUG("max326xx_id = 0x%x", max326xx_id); LOG_DEBUG("max326xx_id = 0x%" PRIx32, max326xx_id);
max326xx_id = ((max326xx_id & 0xFF000000) >> 24); max326xx_id = ((max326xx_id & 0xFF000000) >> 24);
if (max326xx_id == MAX326XX_ID) if (max326xx_id == MAX326XX_ID)
info->max326xx = 1; info->max326xx = 1;
@ -690,7 +686,7 @@ static int max32xxx_probe(struct flash_bank *bank)
if (max32xxx_protect_check(bank) == ERROR_FLASH_OPER_UNSUPPORTED) if (max32xxx_protect_check(bank) == ERROR_FLASH_OPER_UNSUPPORTED)
LOG_WARNING("Flash protection not supported on this device"); LOG_WARNING("Flash protection not supported on this device");
info->probed = 1; info->probed = true;
return ERROR_OK; return ERROR_OK;
} }
@ -709,13 +705,13 @@ static int max32xxx_mass_erase(struct flash_bank *bank)
return ERROR_TARGET_NOT_HALTED; return ERROR_TARGET_NOT_HALTED;
} }
if (info->probed == 0) if (!info->probed)
return ERROR_FLASH_BANK_NOT_PROBED; return ERROR_FLASH_BANK_NOT_PROBED;
int not_protected = 0; int not_protected = 0;
for (int i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
if (bank->sectors[i].is_protected == 1) if (bank->sectors[i].is_protected == 1)
LOG_WARNING("Flash sector %d is protected", i); LOG_WARNING("Flash sector %u is protected", i);
else else
not_protected = 1; not_protected = 1;
} }
@ -767,7 +763,6 @@ static int max32xxx_mass_erase(struct flash_bank *bank)
COMMAND_HANDLER(max32xxx_handle_mass_erase_command) COMMAND_HANDLER(max32xxx_handle_mass_erase_command)
{ {
int i;
struct flash_bank *bank; struct flash_bank *bank;
int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank); int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank);
@ -781,7 +776,7 @@ COMMAND_HANDLER(max32xxx_handle_mass_erase_command)
if (max32xxx_mass_erase(bank) == ERROR_OK) { if (max32xxx_mass_erase(bank) == ERROR_OK) {
/* set all sectors as erased */ /* set all sectors as erased */
for (i = 0; i < bank->num_sectors; i++) for (unsigned i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 1; bank->sectors[i].is_erased = 1;
command_print(CMD, "max32xxx mass erase complete"); command_print(CMD, "max32xxx mass erase complete");
@ -908,7 +903,6 @@ COMMAND_HANDLER(max32xxx_handle_protection_check_command)
struct flash_bank *bank; struct flash_bank *bank;
int retval; int retval;
struct max32xxx_flash_bank *info; struct max32xxx_flash_bank *info;
int i;
if (CMD_ARGC < 1) { if (CMD_ARGC < 1) {
command_print(CMD, "max32xxx protection_check <bank>"); command_print(CMD, "max32xxx protection_check <bank>");
@ -928,7 +922,7 @@ COMMAND_HANDLER(max32xxx_handle_protection_check_command)
} }
LOG_WARNING("s:<sector number> a:<address> p:<protection bit>"); LOG_WARNING("s:<sector number> a:<address> p:<protection bit>");
for (i = 0; i < bank->num_sectors; i += 4) { for (unsigned i = 0; i < bank->num_sectors; i += 4) {
LOG_WARNING("s:%03d a:0x%06x p:%d | s:%03d a:0x%06x p:%d | s:%03d a:0x%06x p:%d | s:%03d a:0x%06x p:%d", LOG_WARNING("s:%03d a:0x%06x p:%d | s:%03d a:0x%06x p:%d | s:%03d a:0x%06x p:%d | s:%03d a:0x%06x p:%d",
(i+0), (i+0)*info->sector_size, bank->sectors[(i+0)].is_protected, (i+0), (i+0)*info->sector_size, bank->sectors[(i+0)].is_protected,
(i+1), (i+1)*info->sector_size, bank->sectors[(i+1)].is_protected, (i+1), (i+1)*info->sector_size, bank->sectors[(i+1)].is_protected,

View File

@ -62,7 +62,7 @@
#define KEY 0x8AAA5551 #define KEY 0x8AAA5551
struct mdr_flash_bank { struct mdr_flash_bank {
int probed; bool probed;
unsigned int mem_type; unsigned int mem_type;
unsigned int page_count; unsigned int page_count;
unsigned int sec_count; unsigned int sec_count;
@ -79,7 +79,7 @@ FLASH_BANK_COMMAND_HANDLER(mdr_flash_bank_command)
mdr_info = malloc(sizeof(struct mdr_flash_bank)); mdr_info = malloc(sizeof(struct mdr_flash_bank));
bank->driver_priv = mdr_info; bank->driver_priv = mdr_info;
mdr_info->probed = 0; mdr_info->probed = false;
COMMAND_PARSE_NUMBER(uint, CMD_ARGV[6], mdr_info->mem_type); COMMAND_PARSE_NUMBER(uint, CMD_ARGV[6], mdr_info->mem_type);
COMMAND_PARSE_NUMBER(uint, CMD_ARGV[7], mdr_info->page_count); COMMAND_PARSE_NUMBER(uint, CMD_ARGV[7], mdr_info->page_count);
COMMAND_PARSE_NUMBER(uint, CMD_ARGV[8], mdr_info->sec_count); COMMAND_PARSE_NUMBER(uint, CMD_ARGV[8], mdr_info->sec_count);
@ -124,11 +124,12 @@ static int mdr_mass_erase(struct flash_bank *bank)
return retval; return retval;
} }
static int mdr_erase(struct flash_bank *bank, int first, int last) static int mdr_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
struct mdr_flash_bank *mdr_info = bank->driver_priv; struct mdr_flash_bank *mdr_info = bank->driver_priv;
int i, retval, retval2; int retval, retval2;
unsigned int j; unsigned int j;
uint32_t flash_cmd, cur_per_clock; uint32_t flash_cmd, cur_per_clock;
@ -173,7 +174,7 @@ static int mdr_erase(struct flash_bank *bank, int first, int last)
} }
unsigned int page_size = bank->size / mdr_info->page_count; unsigned int page_size = bank->size / mdr_info->page_count;
for (i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
for (j = 0; j < mdr_info->sec_count; j++) { for (j = 0; j < mdr_info->sec_count; j++) {
retval = target_write_u32(target, FLASH_ADR, (i * page_size) | (j << 2)); retval = target_write_u32(target, FLASH_ADR, (i * page_size) | (j << 2));
if (retval != ERROR_OK) if (retval != ERROR_OK)
@ -457,8 +458,7 @@ reset_pg_and_lock:
retval = retval2; retval = retval2;
free_buffer: free_buffer:
if (new_buffer) free(new_buffer);
free(new_buffer);
/* read some bytes bytes to flush buffer in flash accelerator. /* read some bytes bytes to flush buffer in flash accelerator.
* See errata for 1986VE1T and 1986VE3. Error 0007 */ * See errata for 1986VE1T and 1986VE3. Error 0007 */
@ -572,10 +572,7 @@ static int mdr_probe(struct flash_bank *bank)
page_count = mdr_info->page_count; page_count = mdr_info->page_count;
page_size = bank->size / page_count; page_size = bank->size / page_count;
if (bank->sectors) { free(bank->sectors);
free(bank->sectors);
bank->sectors = NULL;
}
bank->num_sectors = page_count; bank->num_sectors = page_count;
bank->sectors = malloc(sizeof(struct flash_sector) * page_count); bank->sectors = malloc(sizeof(struct flash_sector) * page_count);
@ -587,7 +584,7 @@ static int mdr_probe(struct flash_bank *bank)
bank->sectors[i].is_protected = 0; bank->sectors[i].is_protected = 0;
} }
mdr_info->probed = 1; mdr_info->probed = true;
return ERROR_OK; return ERROR_OK;
} }

View File

@ -73,7 +73,7 @@
#define DINCNT 0x20 #define DINCNT 0x20
struct mrvlqspi_flash_bank { struct mrvlqspi_flash_bank {
int probed; bool probed;
uint32_t reg_base; uint32_t reg_base;
uint32_t bank_num; uint32_t bank_num;
const struct flash_device *dev; const struct flash_device *dev;
@ -328,7 +328,7 @@ static int mrvlqspi_flash_busy_status(struct flash_bank *bank, int timeout)
uint8_t val; uint8_t val;
int retval; int retval;
/* Flush read/write fifo's */ /* Flush read/write fifos */
retval = mrvlqspi_fifo_flush(bank, FIFO_FLUSH_TIMEOUT); retval = mrvlqspi_fifo_flush(bank, FIFO_FLUSH_TIMEOUT);
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
@ -379,7 +379,7 @@ static int mrvlqspi_set_write_status(struct flash_bank *bank, bool mode)
int retval; int retval;
uint32_t instr; uint32_t instr;
/* Flush read/write fifo's */ /* Flush read/write fifos */
retval = mrvlqspi_fifo_flush(bank, FIFO_FLUSH_TIMEOUT); retval = mrvlqspi_fifo_flush(bank, FIFO_FLUSH_TIMEOUT);
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
@ -417,7 +417,7 @@ static int mrvlqspi_read_id(struct flash_bank *bank, uint32_t *id)
LOG_DEBUG("Getting ID"); LOG_DEBUG("Getting ID");
/* Flush read/write fifo's */ /* Flush read/write fifos */
retval = mrvlqspi_fifo_flush(bank, FIFO_FLUSH_TIMEOUT); retval = mrvlqspi_fifo_flush(bank, FIFO_FLUSH_TIMEOUT);
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
@ -527,21 +527,21 @@ static int mrvlqspi_bulk_erase(struct flash_bank *bank)
return mrvlqspi_flash_busy_status(bank, CHIP_ERASE_TIMEOUT); return mrvlqspi_flash_busy_status(bank, CHIP_ERASE_TIMEOUT);
} }
static int mrvlqspi_flash_erase(struct flash_bank *bank, int first, int last) static int mrvlqspi_flash_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
struct mrvlqspi_flash_bank *mrvlqspi_info = bank->driver_priv; struct mrvlqspi_flash_bank *mrvlqspi_info = bank->driver_priv;
int retval = ERROR_OK; int retval = ERROR_OK;
int sector;
LOG_DEBUG("erase from sector %d to sector %d", first, last); LOG_DEBUG("erase from sector %u to sector %u", first, last);
if (target->state != TARGET_HALTED) { if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted"); LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED; return ERROR_TARGET_NOT_HALTED;
} }
if ((first < 0) || (last < first) || (last >= bank->num_sectors)) { if ((last < first) || (last >= bank->num_sectors)) {
LOG_ERROR("Flash sector invalid"); LOG_ERROR("Flash sector invalid");
return ERROR_FLASH_SECTOR_INVALID; return ERROR_FLASH_SECTOR_INVALID;
} }
@ -551,9 +551,9 @@ static int mrvlqspi_flash_erase(struct flash_bank *bank, int first, int last)
return ERROR_FLASH_BANK_NOT_PROBED; return ERROR_FLASH_BANK_NOT_PROBED;
} }
for (sector = first; sector <= last; sector++) { for (unsigned int sector = first; sector <= last; sector++) {
if (bank->sectors[sector].is_protected) { if (bank->sectors[sector].is_protected) {
LOG_ERROR("Flash sector %d protected", sector); LOG_ERROR("Flash sector %u protected", sector);
return ERROR_FAIL; return ERROR_FAIL;
} }
} }
@ -576,7 +576,7 @@ static int mrvlqspi_flash_erase(struct flash_bank *bank, int first, int last)
if (mrvlqspi_info->dev->erase_cmd == 0x00) if (mrvlqspi_info->dev->erase_cmd == 0x00)
return ERROR_FLASH_OPER_UNSUPPORTED; return ERROR_FLASH_OPER_UNSUPPORTED;
for (sector = first; sector <= last; sector++) { for (unsigned int sector = first; sector <= last; sector++) {
retval = mrvlqspi_block_erase(bank, retval = mrvlqspi_block_erase(bank,
sector * mrvlqspi_info->dev->sectorsize); sector * mrvlqspi_info->dev->sectorsize);
if (retval != ERROR_OK) if (retval != ERROR_OK)
@ -597,7 +597,6 @@ static int mrvlqspi_flash_write(struct flash_bank *bank, const uint8_t *buffer,
struct reg_param reg_params[6]; struct reg_param reg_params[6];
struct armv7m_algorithm armv7m_info; struct armv7m_algorithm armv7m_info;
struct working_area *write_algorithm; struct working_area *write_algorithm;
int sector;
LOG_DEBUG("offset=0x%08" PRIx32 " count=0x%08" PRIx32, LOG_DEBUG("offset=0x%08" PRIx32 " count=0x%08" PRIx32,
offset, count); offset, count);
@ -613,14 +612,14 @@ static int mrvlqspi_flash_write(struct flash_bank *bank, const uint8_t *buffer,
} }
/* Check sector protection */ /* Check sector protection */
for (sector = 0; sector < bank->num_sectors; sector++) { for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
/* Start offset in or before this sector? */ /* Start offset in or before this sector? */
/* End offset in or behind this sector? */ /* End offset in or behind this sector? */
if ((offset < if ((offset <
(bank->sectors[sector].offset + bank->sectors[sector].size)) (bank->sectors[sector].offset + bank->sectors[sector].size))
&& ((offset + count - 1) >= bank->sectors[sector].offset) && ((offset + count - 1) >= bank->sectors[sector].offset)
&& bank->sectors[sector].is_protected) { && bank->sectors[sector].is_protected) {
LOG_ERROR("Flash sector %d protected", sector); LOG_ERROR("Flash sector %u protected", sector);
return ERROR_FAIL; return ERROR_FAIL;
} }
} }
@ -780,7 +779,7 @@ int mrvlqspi_flash_read(struct flash_bank *bank, uint8_t *buffer,
return ERROR_FLASH_BANK_NOT_PROBED; return ERROR_FLASH_BANK_NOT_PROBED;
} }
/* Flush read/write fifo's */ /* Flush read/write fifos */
retval = mrvlqspi_fifo_flush(bank, FIFO_FLUSH_TIMEOUT); retval = mrvlqspi_fifo_flush(bank, FIFO_FLUSH_TIMEOUT);
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
@ -845,7 +844,7 @@ static int mrvlqspi_probe(struct flash_bank *bank)
return ERROR_TARGET_NOT_HALTED; return ERROR_TARGET_NOT_HALTED;
} }
mrvlqspi_info->probed = 0; mrvlqspi_info->probed = false;
mrvlqspi_info->bank_num = bank->bank_number; mrvlqspi_info->bank_num = bank->bank_number;
/* Read flash JEDEC ID */ /* Read flash JEDEC ID */
@ -888,7 +887,7 @@ static int mrvlqspi_probe(struct flash_bank *bank)
return ERROR_FAIL; return ERROR_FAIL;
} }
for (int sector = 0; sector < bank->num_sectors; sector++) { for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
sectors[sector].offset = sector * sectorsize; sectors[sector].offset = sector * sectorsize;
sectors[sector].size = sectorsize; sectors[sector].size = sectorsize;
sectors[sector].is_erased = -1; sectors[sector].is_erased = -1;
@ -896,7 +895,7 @@ static int mrvlqspi_probe(struct flash_bank *bank)
} }
bank->sectors = sectors; bank->sectors = sectors;
mrvlqspi_info->probed = 1; mrvlqspi_info->probed = true;
return ERROR_OK; return ERROR_OK;
} }
@ -948,7 +947,7 @@ FLASH_BANK_COMMAND_HANDLER(mrvlqspi_flash_bank_command)
/* Get QSPI controller register map base address */ /* Get QSPI controller register map base address */
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[6], mrvlqspi_info->reg_base); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[6], mrvlqspi_info->reg_base);
bank->driver_priv = mrvlqspi_info; bank->driver_priv = mrvlqspi_info;
mrvlqspi_info->probed = 0; mrvlqspi_info->probed = false;
return ERROR_OK; return ERROR_OK;
} }

View File

@ -320,7 +320,7 @@ static int msp432_init(struct flash_bank *bank)
/* Explicit device type check failed. Report this. */ /* Explicit device type check failed. Report this. */
LOG_WARNING( LOG_WARNING(
"msp432: Unrecognized MSP432P4 Device ID and Hardware " "msp432: Unrecognized MSP432P4 Device ID and Hardware "
"Rev (%04X, %02X)", msp432_bank->device_id, "Rev (%04" PRIX32 ", %02" PRIX32 ")", msp432_bank->device_id,
msp432_bank->hardware_rev); msp432_bank->hardware_rev);
} else if (MSP432P401X_DEPR == msp432_bank->device_type) { } else if (MSP432P401X_DEPR == msp432_bank->device_type) {
LOG_WARNING( LOG_WARNING(
@ -330,7 +330,7 @@ static int msp432_init(struct flash_bank *bank)
/* Explicit device type check failed. Report this. */ /* Explicit device type check failed. Report this. */
LOG_WARNING( LOG_WARNING(
"msp432: Unrecognized MSP432E4 DID0 and DID1 values " "msp432: Unrecognized MSP432E4 DID0 and DID1 values "
"(%08X, %08X)", msp432_bank->device_id, "(%08" PRIX32 ", %08" PRIX32 ")", msp432_bank->device_id,
msp432_bank->hardware_rev); msp432_bank->hardware_rev);
} }
@ -590,7 +590,8 @@ FLASH_BANK_COMMAND_HANDLER(msp432_flash_bank_command)
return ERROR_OK; return ERROR_OK;
} }
static int msp432_erase(struct flash_bank *bank, int first, int last) static int msp432_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
struct msp432_bank *msp432_bank = bank->driver_priv; struct msp432_bank *msp432_bank = bank->driver_priv;
@ -628,7 +629,7 @@ static int msp432_erase(struct flash_bank *bank, int first, int last)
} }
/* Erase requested sectors one by one */ /* Erase requested sectors one by one */
for (int i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
/* Skip TVL (read-only) sector of the info bank */ /* Skip TVL (read-only) sector of the info bank */
if (is_info && 1 == i) if (is_info && 1 == i)
@ -809,7 +810,7 @@ static int msp432_probe(struct flash_bank *bank)
uint32_t sector_length; uint32_t sector_length;
uint32_t size; uint32_t size;
int num_sectors; unsigned int num_sectors;
bool is_main = FLASH_BASE == bank->base; bool is_main = FLASH_BASE == bank->base;
bool is_info = P4_FLASH_INFO_BASE == bank->base; bool is_info = P4_FLASH_INFO_BASE == bank->base;
@ -901,10 +902,8 @@ static int msp432_probe(struct flash_bank *bank)
} }
} }
if (NULL != bank->sectors) { free(bank->sectors);
free(bank->sectors); bank->sectors = NULL;
bank->sectors = NULL;
}
if (num_sectors > 0) { if (num_sectors > 0) {
bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors); bank->sectors = malloc(sizeof(struct flash_sector) * num_sectors);
@ -918,7 +917,7 @@ static int msp432_probe(struct flash_bank *bank)
bank->num_sectors = num_sectors; bank->num_sectors = num_sectors;
msp432_bank->sector_length = sector_length; msp432_bank->sector_length = sector_length;
for (int i = 0; i < num_sectors; i++) { for (unsigned int i = 0; i < num_sectors; i++) {
bank->sectors[i].offset = i * sector_length; bank->sectors[i].offset = i * sector_length;
bank->sectors[i].size = sector_length; bank->sectors[i].size = sector_length;
bank->sectors[i].is_erased = -1; bank->sectors[i].is_erased = -1;
@ -1013,14 +1012,14 @@ static int msp432_info(struct flash_bank *bank, char *buf, int buf_size)
break; break;
case MSP432E4X_GUESS: case MSP432E4X_GUESS:
printed = snprintf(buf, buf_size, printed = snprintf(buf, buf_size,
"Unrecognized MSP432E4 DID0 and DID1 IDs (%08X, %08X)", "Unrecognized MSP432E4 DID0 and DID1 IDs (%08" PRIX32 ", %08" PRIX32 ")",
msp432_bank->device_id, msp432_bank->hardware_rev); msp432_bank->device_id, msp432_bank->hardware_rev);
break; break;
case MSP432P401X_GUESS: case MSP432P401X_GUESS:
case MSP432P411X_GUESS: case MSP432P411X_GUESS:
default: default:
printed = snprintf(buf, buf_size, printed = snprintf(buf, buf_size,
"Unrecognized MSP432P4 Device ID and Hardware Rev (%04X, %02X)", "Unrecognized MSP432P4 Device ID and Hardware Rev (%04" PRIX32 ", %02" PRIX32 ")",
msp432_bank->device_id, msp432_bank->hardware_rev); msp432_bank->device_id, msp432_bank->hardware_rev);
break; break;
} }
@ -1045,7 +1044,7 @@ static void msp432_flash_free_driver_priv(struct flash_bank *bank)
/* A single private struct is shared between main and info banks */ /* A single private struct is shared between main and info banks */
/* Only free it on the call for main bank */ /* Only free it on the call for main bank */
if (is_main && (NULL != bank->driver_priv)) if (is_main)
free(bank->driver_priv); free(bank->driver_priv);
/* Forget about the private struct on both main and info banks */ /* Forget about the private struct on both main and info banks */

View File

@ -65,8 +65,8 @@
#define FCIS_OP_ERROR (1<<1) /* Flag operation error */ #define FCIS_OP_ERROR (1<<1) /* Flag operation error */
/*---- FCIC: CLear status register */ /*---- FCIC: CLear status register */
#define FCIC_CLR_OPCMLT (1<<0) /* Cleare completion flag in register FCIS */ #define FCIC_CLR_OPCMLT (1<<0) /* Clear completion flag in register FCIS */
#define FCIC_CLR_OPERROR (1<<1) /* Cleare error flag in register FCIS */ #define FCIC_CLR_OPERROR (1<<1) /* Clear error flag in register FCIS */
/*-- USERFLASH ---------------------------------------------------------------*/ /*-- USERFLASH ---------------------------------------------------------------*/
#define USERFLASH_PAGE_SIZE 256 #define USERFLASH_PAGE_SIZE 256
@ -95,8 +95,8 @@
#define UFCIS_OP_ERROR (1<<1) /* Flag operation error */ #define UFCIS_OP_ERROR (1<<1) /* Flag operation error */
/*---- UFCIC: CLear status register */ /*---- UFCIC: CLear status register */
#define UFCIC_CLR_OPCMLT (1<<0) /* Cleared completion flag in register FCIS */ #define UFCIC_CLR_OPCMLT (1<<0) /* Clear completion flag in register FCIS */
#define UFCIC_CLR_OPERROR (1<<1) /* Cleared error flag in register FCIS */ #define UFCIC_CLR_OPERROR (1<<1) /* Clear error flag in register FCIS */
/*---- In info userflash address space */ /*---- In info userflash address space */
#define INFOWORD0_ADDR 0x00 #define INFOWORD0_ADDR 0x00
@ -330,7 +330,8 @@ static int niietcm4_uflash_page_erase(struct flash_bank *bank, int page_num, int
/** /**
* Enable or disable protection of userflash pages * Enable or disable protection of userflash pages
*/ */
static int niietcm4_uflash_protect(struct flash_bank *bank, int mem_type, int set, int first, int last) static int niietcm4_uflash_protect(struct flash_bank *bank, int mem_type,
int set, unsigned int first, unsigned int last)
{ {
int retval; int retval;
if (mem_type == INFO_MEM_TYPE) { if (mem_type == INFO_MEM_TYPE) {
@ -359,7 +360,7 @@ static int niietcm4_uflash_protect(struct flash_bank *bank, int mem_type, int se
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
/* modify dump */ /* modify dump */
for (int i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
uint32_t reg_num = i/8; uint32_t reg_num = i/8;
uint32_t bit_num = i%8; uint32_t bit_num = i%8;
if (set) if (set)
@ -410,7 +411,7 @@ COMMAND_HANDLER(niietcm4_handle_uflash_read_byte_command)
else else
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
COMMAND_PARSE_NUMBER(uint, CMD_ARGV[1], uflash_addr); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], uflash_addr);
retval = target_write_u32(target, UFMA, uflash_addr); retval = target_write_u32(target, UFMA, uflash_addr);
if (retval != ERROR_OK) if (retval != ERROR_OK)
@ -426,8 +427,8 @@ COMMAND_HANDLER(niietcm4_handle_uflash_read_byte_command)
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
command_print(CMD, "Read userflash %s region:\n" command_print(CMD, "Read userflash %s region:\n"
"address = 0x%04x,\n" "address = 0x%04" PRIx32 ",\n"
"value = 0x%02x.", CMD_ARGV[0], uflash_addr, uflash_data); "value = 0x%02" PRIx32 ".", CMD_ARGV[0], uflash_addr, uflash_data);
return retval; return retval;
} }
@ -462,14 +463,14 @@ COMMAND_HANDLER(niietcm4_handle_uflash_write_byte_command)
else else
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
COMMAND_PARSE_NUMBER(uint, CMD_ARGV[1], uflash_addr); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], uflash_addr);
COMMAND_PARSE_NUMBER(uint, CMD_ARGV[2], uflash_data); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], uflash_data);
int page_num = uflash_addr/USERFLASH_PAGE_SIZE; int page_num = uflash_addr/USERFLASH_PAGE_SIZE;
command_print(CMD, "Write userflash %s region:\n" command_print(CMD, "Write userflash %s region:\n"
"address = 0x%04x,\n" "address = 0x%04" PRIx32 ",\n"
"value = 0x%02x.\n" "value = 0x%02" PRIx32 ".\n"
"Please wait ... ", CMD_ARGV[0], uflash_addr, uflash_data); "Please wait ... ", CMD_ARGV[0], uflash_addr, uflash_data);
/* dump */ /* dump */
uint32_t uflash_dump[USERFLASH_PAGE_SIZE]; uint32_t uflash_dump[USERFLASH_PAGE_SIZE];
@ -563,7 +564,7 @@ COMMAND_HANDLER(niietcm4_handle_uflash_erase_command)
return retval; return retval;
} }
command_print(CMD, "Erase %s userflash pages %d through %d done!", CMD_ARGV[0], first, last); command_print(CMD, "Erase %s userflash pages %u through %u done!", CMD_ARGV[0], first, last);
return retval; return retval;
} }
@ -693,11 +694,11 @@ COMMAND_HANDLER(niietcm4_handle_uflash_protect_command)
int set; int set;
if (strcmp("on", CMD_ARGV[3]) == 0) { if (strcmp("on", CMD_ARGV[3]) == 0) {
command_print(CMD, "Try to enable %s userflash sectors %d through %d protection. Please wait ... ", command_print(CMD, "Try to enable %s userflash sectors %u through %u protection. Please wait ... ",
CMD_ARGV[0], first, last); CMD_ARGV[0], first, last);
set = 1; set = 1;
} else if (strcmp("off", CMD_ARGV[3]) == 0) { } else if (strcmp("off", CMD_ARGV[3]) == 0) {
command_print(CMD, "Try to disable %s userflash sectors %d through %d protection. Please wait ... ", command_print(CMD, "Try to disable %s userflash sectors %u through %u protection. Please wait ... ",
CMD_ARGV[0], first, last); CMD_ARGV[0], first, last);
set = 0; set = 0;
} else } else
@ -802,7 +803,7 @@ COMMAND_HANDLER(niietcm4_handle_extmem_cfg_command)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
uint32_t pin; uint32_t pin;
COMMAND_PARSE_NUMBER(uint, CMD_ARGV[1], pin); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], pin);
if (pin > 15) if (pin > 15)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
@ -1111,7 +1112,7 @@ static int niietcm4_protect_check(struct flash_bank *bank)
} else { } else {
uflash_addr = BF_LOCK_ADDR; uflash_addr = BF_LOCK_ADDR;
uflash_cmd = UFMC_MAGIC_KEY | UFMC_READ_IFB; uflash_cmd = UFMC_MAGIC_KEY | UFMC_READ_IFB;
for (int i = 0; i < bank->num_sectors/8; i++) { for (unsigned int i = 0; i < bank->num_sectors/8; i++) {
retval = target_write_u32(target, UFMA, uflash_addr); retval = target_write_u32(target, UFMA, uflash_addr);
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
@ -1163,7 +1164,8 @@ static int niietcm4_mass_erase(struct flash_bank *bank)
return retval; return retval;
} }
static int niietcm4_erase(struct flash_bank *bank, int first, int last) static int niietcm4_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
struct niietcm4_flash_bank *niietcm4_info = bank->driver_priv; struct niietcm4_flash_bank *niietcm4_info = bank->driver_priv;
@ -1188,7 +1190,7 @@ static int niietcm4_erase(struct flash_bank *bank, int first, int last)
/* erasing pages */ /* erasing pages */
unsigned int page_size = bank->size / bank->num_sectors; unsigned int page_size = bank->size / bank->num_sectors;
for (int i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
/* current page addr */ /* current page addr */
flash_addr = i*page_size; flash_addr = i*page_size;
retval = target_write_u32(target, FMA, flash_addr); retval = target_write_u32(target, FMA, flash_addr);
@ -1211,7 +1213,8 @@ static int niietcm4_erase(struct flash_bank *bank, int first, int last)
return retval; return retval;
} }
static int niietcm4_protect(struct flash_bank *bank, int set, int first, int last) static int niietcm4_protect(struct flash_bank *bank, int set,
unsigned int first, unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
struct niietcm4_flash_bank *niietcm4_info = bank->driver_priv; struct niietcm4_flash_bank *niietcm4_info = bank->driver_priv;
@ -1223,7 +1226,7 @@ static int niietcm4_protect(struct flash_bank *bank, int set, int first, int las
return ERROR_TARGET_NOT_HALTED; return ERROR_TARGET_NOT_HALTED;
} }
LOG_INFO("Plese wait ..."); /* it`s quite a long process */ LOG_INFO("Please wait ..."); /* it`s quite a long process */
/* chose between main bootflash and info bootflash */ /* chose between main bootflash and info bootflash */
if (niietcm4_info->bflash_info_remap) { if (niietcm4_info->bflash_info_remap) {
/* dump */ /* dump */
@ -1251,7 +1254,7 @@ static int niietcm4_protect(struct flash_bank *bank, int set, int first, int las
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
/* modify dump */ /* modify dump */
for (int i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
uint32_t reg_num = i/8; uint32_t reg_num = i/8;
uint32_t bit_num = i%8; uint32_t bit_num = i%8;
if (set) if (set)
@ -1413,7 +1416,7 @@ static int niietcm4_write(struct flash_bank *bank, const uint8_t *buffer,
/* if block write failed (no sufficient working area), /* if block write failed (no sufficient working area),
* we use normal (slow) single halfword accesses */ * we use normal (slow) single halfword accesses */
LOG_WARNING("Can't use block writes, falling back to single memory accesses"); LOG_WARNING("Can't use block writes, falling back to single memory accesses");
LOG_INFO("Plese wait ..."); /* it`s quite a long process */ LOG_INFO("Please wait ..."); /* it`s quite a long process */
/* chose between main bootflash and info bootflash */ /* chose between main bootflash and info bootflash */
if (niietcm4_info->bflash_info_remap) if (niietcm4_info->bflash_info_remap)
@ -1424,7 +1427,7 @@ static int niietcm4_write(struct flash_bank *bank, const uint8_t *buffer,
/* write 16 bytes per try */ /* write 16 bytes per try */
for (unsigned int i = 0; i < count; i += 16) { for (unsigned int i = 0; i < count; i += 16) {
/* current addr */ /* current addr */
LOG_INFO("%d byte of %d", i, count); LOG_INFO("%u byte of %" PRIu32, i, count);
flash_addr = offset + i; flash_addr = offset + i;
retval = target_write_u32(target, FMA, flash_addr); retval = target_write_u32(target, FMA, flash_addr);
if (retval != ERROR_OK) if (retval != ERROR_OK)
@ -1466,9 +1469,7 @@ static int niietcm4_write(struct flash_bank *bank, const uint8_t *buffer,
} }
free_buffer: free_buffer:
if (new_buffer) free(new_buffer);
free(new_buffer);
return retval; return retval;
} }
@ -1585,41 +1586,41 @@ static int niietcm4_probe_k1921vk01t(struct flash_bank *bank)
char info_bootflash_addr_str[64]; char info_bootflash_addr_str[64];
if (niietcm4_info->bflash_info_remap) if (niietcm4_info->bflash_info_remap)
snprintf(info_bootflash_addr_str, sizeof(info_bootflash_addr_str), snprintf(info_bootflash_addr_str, sizeof(info_bootflash_addr_str),
TARGET_ADDR_FMT " base adress", bank->base); TARGET_ADDR_FMT " base address", bank->base);
else else
snprintf(info_bootflash_addr_str, sizeof(info_bootflash_addr_str), snprintf(info_bootflash_addr_str, sizeof(info_bootflash_addr_str),
"not mapped to global adress space"); "not mapped to global address space");
snprintf(niietcm4_info->chip_brief, snprintf(niietcm4_info->chip_brief,
sizeof(niietcm4_info->chip_brief), sizeof(niietcm4_info->chip_brief),
"\n" "\n"
"MEMORY CONFIGURATION\n" "MEMORY CONFIGURATION\n"
"Bootflash :\n" "Bootflash :\n"
" %d kB total\n" " %" PRIu32 " kB total\n"
" %d pages %d kB each\n" " %" PRIu32 " pages %" PRIu32 " kB each\n"
" 0x%08x base adress\n" " 0x%08" PRIx32 " base address\n"
"%s" "%s"
"Info bootflash :\n" "Info bootflash :\n"
" %d kB total\n" " %" PRIu32 " kB total\n"
" %d pages %d kB each\n" " %" PRIu32 " pages %" PRIu32 " kB each\n"
" %s\n" " %s\n"
"%s" "%s"
"Userflash :\n" "Userflash :\n"
" %d kB total\n" " %" PRIu32 " kB total\n"
" %d pages %d B each\n" " %" PRIu32 " pages %" PRIu32 " B each\n"
" %d bit cells\n" " %" PRIu32 " bit cells\n"
" not maped to global adress space\n" " not mapped to global address space\n"
"Info userflash :\n" "Info userflash :\n"
" %d B total\n" " %" PRIu32 " B total\n"
" %d pages of %d B each\n" " %" PRIu32 " pages of %" PRIu32 " B each\n"
" %d bit cells\n" " %" PRIu32 " bit cells\n"
" not maped to global adress space\n" " not mapped to global address space\n"
"RAM :\n" "RAM :\n"
" 192 kB total\n" " 192 kB total\n"
" 0x20000000 base adress\n" " 0x20000000 base address\n"
"External memory :\n" "External memory :\n"
" 8/16 bit address space\n" " 8/16 bit address space\n"
" 0x%08x base adress\n" " 0x%08" PRIx32 " base address\n"
"\n" "\n"
"INFOWORD STATUS\n" "INFOWORD STATUS\n"
"Bootflash info region remap :\n" "Bootflash info region remap :\n"
@ -1627,9 +1628,9 @@ static int niietcm4_probe_k1921vk01t(struct flash_bank *bank)
"External memory boot port :\n" "External memory boot port :\n"
" %s\n" " %s\n"
"External memory boot pin :\n" "External memory boot pin :\n"
" %d\n" " %" PRIu32 "\n"
"External memory interface alternative function :\n" "External memory interface alternative function :\n"
" %d\n" " %" PRIu32 "\n"
"Option boot from external memory :\n" "Option boot from external memory :\n"
" %s\n", " %s\n",
bflash_size/1024, bflash_size/1024,
@ -1656,7 +1657,7 @@ static int niietcm4_probe_k1921vk01t(struct flash_bank *bank)
niietcm4_info->extmem_boot_pin, niietcm4_info->extmem_boot_pin,
niietcm4_info->extmem_boot_altfunc, niietcm4_info->extmem_boot_altfunc,
niietcm4_info->extmem_boot ? "enable" : "disable"); niietcm4_info->extmem_boot ? "enable" : "disable");
} else{ } else {
bank->size = 0x100000; bank->size = 0x100000;
bank->num_sectors = 128; bank->num_sectors = 128;
@ -1678,10 +1679,9 @@ static int niietcm4_probe(struct flash_bank *bank)
struct niietcm4_flash_bank *niietcm4_info = bank->driver_priv; struct niietcm4_flash_bank *niietcm4_info = bank->driver_priv;
struct target *target = bank->target; struct target *target = bank->target;
if (bank->sectors) { free(bank->sectors);
free(bank->sectors); bank->sectors = NULL;
bank->sectors = NULL;
}
uint32_t retval; uint32_t retval;
uint32_t chipid; uint32_t chipid;

View File

@ -483,11 +483,11 @@ void cfi_fixup_non_cfi(struct flash_bank *bank)
break; break;
} }
/* only fixup jedec flashs found in table */ /* only fixup jedec flashes found in table */
if (!non_cfi->mfr) if (!non_cfi->mfr)
return; return;
cfi_info->not_cfi = 1; cfi_info->not_cfi = true;
/* fill in defaults for non-critical data */ /* fill in defaults for non-critical data */
cfi_info->vcc_min = 0x0; cfi_info->vcc_min = 0x0;

View File

@ -89,7 +89,7 @@ enum nrf5_ficr_registers {
enum nrf5_uicr_registers { enum nrf5_uicr_registers {
NRF5_UICR_BASE = 0x10001000, /* User Information NRF5_UICR_BASE = 0x10001000, /* User Information
* Configuration Regsters */ * Configuration Registers */
#define NRF5_UICR_REG(offset) (NRF5_UICR_BASE + offset) #define NRF5_UICR_REG(offset) (NRF5_UICR_BASE + offset)
@ -256,7 +256,7 @@ static const struct nrf5_device_spec nrf5_known_devices_table[] = {
NRF51_DEVICE_DEF(0x007A, "51422", "CEAA", "C0", 256), NRF51_DEVICE_DEF(0x007A, "51422", "CEAA", "C0", 256),
NRF51_DEVICE_DEF(0x0088, "51422", "CFAC", "A0", 256), NRF51_DEVICE_DEF(0x0088, "51422", "CFAC", "A0", 256),
/* The driver fully autodects nRF52 series devices by FICR INFO, /* The driver fully autodetects nRF52 series devices by FICR INFO,
* no need for nRF52xxx HWIDs in this table */ * no need for nRF52xxx HWIDs in this table */
#if 0 #if 0
/* nRF52810 Devices */ /* nRF52810 Devices */
@ -451,7 +451,7 @@ static int nrf5_protect_check_bprot(struct flash_bank *bank)
uint32_t bprot_reg = 0; uint32_t bprot_reg = 0;
int res; int res;
for (int i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
unsigned int bit = i % 32; unsigned int bit = i % 32;
if (bit == 0) { if (bit == 0) {
unsigned int n_reg = i / 32; unsigned int n_reg = i / 32;
@ -505,14 +505,15 @@ static int nrf5_protect_check(struct flash_bank *bank)
} }
} }
for (int i = 0; i < bank->num_sectors; i++) for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_protected = bank->sectors[i].is_protected =
clenr0 != 0xFFFFFFFF && bank->sectors[i].offset < clenr0; clenr0 != 0xFFFFFFFF && bank->sectors[i].offset < clenr0;
return ERROR_OK; return ERROR_OK;
} }
static int nrf5_protect(struct flash_bank *bank, int set, int first, int last) static int nrf5_protect(struct flash_bank *bank, int set, unsigned int first,
unsigned int last)
{ {
int res; int res;
uint32_t clenr0, ppfc; uint32_t clenr0, ppfc;
@ -532,7 +533,7 @@ static int nrf5_protect(struct flash_bank *bank, int set, int first, int last)
} }
if (first != 0) { if (first != 0) {
LOG_ERROR("Code region 0 must start at the begining of the bank"); LOG_ERROR("Code region 0 must start at the beginning of the bank");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -1026,7 +1027,8 @@ error:
return res; return res;
} }
static int nrf5_erase(struct flash_bank *bank, int first, int last) static int nrf5_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
int res; int res;
struct nrf5_info *chip; struct nrf5_info *chip;
@ -1036,7 +1038,7 @@ static int nrf5_erase(struct flash_bank *bank, int first, int last)
return res; return res;
/* For each sector to be erased */ /* For each sector to be erased */
for (int s = first; s <= last && res == ERROR_OK; s++) for (unsigned int s = first; s <= last && res == ERROR_OK; s++)
res = nrf5_erase_page(bank, chip, &bank->sectors[s]); res = nrf5_erase_page(bank, chip, &bank->sectors[s]);
return res; return res;
@ -1360,7 +1362,7 @@ const struct flash_driver nrf5_flash = {
}; };
/* We need to retain the flash-driver name as well as the commands /* We need to retain the flash-driver name as well as the commands
* for backwards compatability */ * for backwards compatibility */
const struct flash_driver nrf51_flash = { const struct flash_driver nrf51_flash = {
.name = "nrf51", .name = "nrf51",
.commands = nrf5_command_handlers, .commands = nrf5_command_handlers,

View File

@ -1433,7 +1433,7 @@ static int numicro_protect_check(struct flash_bank *bank)
{ {
struct target *target = bank->target; struct target *target = bank->target;
uint32_t set, config[2]; uint32_t set, config[2];
int i, retval = ERROR_OK; int retval = ERROR_OK;
if (target->state != TARGET_HALTED) { if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted"); LOG_ERROR("Target not halted");
@ -1467,25 +1467,26 @@ static int numicro_protect_check(struct flash_bank *bank)
set = 0; set = 0;
} }
for (i = 0; i < bank->num_sectors; i++) for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_protected = set; bank->sectors[i].is_protected = set;
return ERROR_OK; return ERROR_OK;
} }
static int numicro_erase(struct flash_bank *bank, int first, int last) static int numicro_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
uint32_t timeout, status; uint32_t timeout, status;
int i, retval = ERROR_OK; int retval = ERROR_OK;
if (target->state != TARGET_HALTED) { if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted"); LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED; return ERROR_TARGET_NOT_HALTED;
} }
LOG_INFO("Nuvoton NuMicro: Sector Erase ... (%d to %d)", first, last); LOG_INFO("Nuvoton NuMicro: Sector Erase ... (%u to %u)", first, last);
retval = numicro_init_isp(target); retval = numicro_init_isp(target);
if (retval != ERROR_OK) if (retval != ERROR_OK)
@ -1495,8 +1496,8 @@ static int numicro_erase(struct flash_bank *bank, int first, int last)
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
for (i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
LOG_DEBUG("erasing sector %d at address " TARGET_ADDR_FMT, i, LOG_DEBUG("erasing sector %u at address " TARGET_ADDR_FMT, i,
bank->base + bank->sectors[i].offset); bank->base + bank->sectors[i].offset);
retval = target_write_u32(target, NUMICRO_FLASH_ISPADR, bank->base + bank->sectors[i].offset); retval = target_write_u32(target, NUMICRO_FLASH_ISPADR, bank->base + bank->sectors[i].offset);
if (retval != ERROR_OK) if (retval != ERROR_OK)
@ -1582,7 +1583,7 @@ static int numicro_write(struct flash_bank *bank, const uint8_t *buffer,
/* program command */ /* program command */
for (uint32_t i = 0; i < count; i += 4) { for (uint32_t i = 0; i < count; i += 4) {
LOG_DEBUG("write longword @ %08X", offset + i); LOG_DEBUG("write longword @ %08" PRIX32, offset + i);
retval = target_write_u32(target, NUMICRO_FLASH_ISPADR, bank->base + offset + i); retval = target_write_u32(target, NUMICRO_FLASH_ISPADR, bank->base + offset + i);
if (retval != ERROR_OK) if (retval != ERROR_OK)

View File

@ -51,7 +51,8 @@ FLASH_BANK_COMMAND_HANDLER(ocl_flash_bank_command)
return ERROR_OK; return ERROR_OK;
} }
static int ocl_erase(struct flash_bank *bank, int first, int last) static int ocl_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct ocl_priv *ocl = bank->driver_priv; struct ocl_priv *ocl = bank->driver_priv;
int retval; int retval;
@ -207,7 +208,6 @@ static int ocl_probe(struct flash_bank *bank)
int retval; int retval;
uint32_t dcc_buffer[1]; uint32_t dcc_buffer[1];
int sectsize; int sectsize;
int i;
/* purge pending data in DCC */ /* purge pending data in DCC */
embeddedice_receive(ocl->jtag_info, dcc_buffer, 1); embeddedice_receive(ocl->jtag_info, dcc_buffer, 1);
@ -276,7 +276,7 @@ static int ocl_probe(struct flash_bank *bank)
return ERROR_FLASH_BANK_INVALID; return ERROR_FLASH_BANK_INVALID;
} }
sectsize = bank->size / bank->num_sectors; sectsize = bank->size / bank->num_sectors;
for (i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].offset = i * sectsize; bank->sectors[i].offset = i * sectsize;
bank->sectors[i].size = sectsize; bank->sectors[i].size = sectsize;
bank->sectors[i].is_erased = -1; bank->sectors[i].is_erased = -1;

View File

@ -22,7 +22,7 @@
/* command/response mask */ /* command/response mask */
#define OCL_CMD_MASK 0xFFFF0000L #define OCL_CMD_MASK 0xFFFF0000L
/* commads */ /* commands */
#define OCL_FLASH_BLOCK 0x0CFB0000L #define OCL_FLASH_BLOCK 0x0CFB0000L
#define OCL_ERASE_BLOCK 0x0CEB0000L #define OCL_ERASE_BLOCK 0x0CEB0000L
#define OCL_ERASE_ALL 0x0CEA0000L #define OCL_ERASE_ALL 0x0CEA0000L

View File

@ -95,7 +95,7 @@
#define MX_17x_27x 2 /* PIC32mx17x/27x */ #define MX_17x_27x 2 /* PIC32mx17x/27x */
struct pic32mx_flash_bank { struct pic32mx_flash_bank {
int probed; bool probed;
int dev_type; /* Default 0. 1 for Pic32MX1XX/2XX variant */ int dev_type; /* Default 0. 1 for Pic32MX1XX/2XX variant */
}; };
@ -211,7 +211,7 @@ FLASH_BANK_COMMAND_HANDLER(pic32mx_flash_bank_command)
pic32mx_info = malloc(sizeof(struct pic32mx_flash_bank)); pic32mx_info = malloc(sizeof(struct pic32mx_flash_bank));
bank->driver_priv = pic32mx_info; bank->driver_priv = pic32mx_info;
pic32mx_info->probed = 0; pic32mx_info->probed = false;
pic32mx_info->dev_type = 0; pic32mx_info->dev_type = 0;
return ERROR_OK; return ERROR_OK;
@ -271,8 +271,7 @@ static int pic32mx_protect_check(struct flash_bank *bank)
uint32_t config0_address; uint32_t config0_address;
uint32_t devcfg0; uint32_t devcfg0;
int s; unsigned int s, num_pages;
int num_pages;
if (target->state != TARGET_HALTED) { if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted"); LOG_ERROR("Target not halted");
@ -321,10 +320,10 @@ static int pic32mx_protect_check(struct flash_bank *bank)
return ERROR_OK; return ERROR_OK;
} }
static int pic32mx_erase(struct flash_bank *bank, int first, int last) static int pic32mx_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
int i;
uint32_t status; uint32_t status;
if (bank->target->state != TARGET_HALTED) { if (bank->target->state != TARGET_HALTED) {
@ -345,7 +344,7 @@ static int pic32mx_erase(struct flash_bank *bank, int first, int last)
return ERROR_OK; return ERROR_OK;
} }
for (i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
target_write_u32(target, PIC32MX_NVMADDR, Virt2Phys(bank->base + bank->sectors[i].offset)); target_write_u32(target, PIC32MX_NVMADDR, Virt2Phys(bank->base + bank->sectors[i].offset));
status = pic32mx_nvm_exec(bank, NVMCON_OP_PAGE_ERASE, 10); status = pic32mx_nvm_exec(bank, NVMCON_OP_PAGE_ERASE, 10);
@ -360,7 +359,8 @@ static int pic32mx_erase(struct flash_bank *bank, int first, int last)
return ERROR_OK; return ERROR_OK;
} }
static int pic32mx_protect(struct flash_bank *bank, int set, int first, int last) static int pic32mx_protect(struct flash_bank *bank, int set, unsigned int first,
unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
@ -372,7 +372,7 @@ static int pic32mx_protect(struct flash_bank *bank, int set, int first, int last
return ERROR_OK; return ERROR_OK;
} }
/* see contib/loaders/flash/pic32mx.s for src */ /* see contrib/loaders/flash/pic32mx.s for src */
static uint32_t pic32mx_flash_write_code[] = { static uint32_t pic32mx_flash_write_code[] = {
/* write: */ /* write: */
@ -591,8 +591,7 @@ static int pic32mx_write_block(struct flash_bank *bank, const uint8_t *buffer,
destroy_reg_param(&reg_params[1]); destroy_reg_param(&reg_params[1]);
destroy_reg_param(&reg_params[2]); destroy_reg_param(&reg_params[2]);
if (new_buffer != NULL) free(new_buffer);
free(new_buffer);
return retval; return retval;
} }
@ -700,7 +699,7 @@ static int pic32mx_probe(struct flash_bank *bank)
uint32_t device_id; uint32_t device_id;
int page_size; int page_size;
pic32mx_info->probed = 0; pic32mx_info->probed = false;
device_id = ejtag_info->idcode; device_id = ejtag_info->idcode;
LOG_INFO("device id = 0x%08" PRIx32 " (manuf 0x%03x dev 0x%04x, ver 0x%02x)", LOG_INFO("device id = 0x%08" PRIx32 " (manuf 0x%03x dev 0x%04x, ver 0x%02x)",
@ -772,12 +771,9 @@ static int pic32mx_probe(struct flash_bank *bank)
} }
} }
LOG_INFO("flash size = %" PRId32 "kbytes", num_pages / 1024); LOG_INFO("flash size = %" PRIu32 "kbytes", num_pages / 1024);
if (bank->sectors) { free(bank->sectors);
free(bank->sectors);
bank->sectors = NULL;
}
/* calculate numbers of pages */ /* calculate numbers of pages */
num_pages /= page_size; num_pages /= page_size;
@ -792,7 +788,7 @@ static int pic32mx_probe(struct flash_bank *bank)
bank->sectors[i].is_protected = 1; bank->sectors[i].is_protected = 1;
} }
pic32mx_info->probed = 1; pic32mx_info->probed = true;
return ERROR_OK; return ERROR_OK;
} }
@ -817,7 +813,7 @@ static int pic32mx_info(struct flash_bank *bank, char *buf, int buf_size)
if (((device_id >> 1) & 0x7ff) != PIC32MX_MANUF_ID) { if (((device_id >> 1) & 0x7ff) != PIC32MX_MANUF_ID) {
snprintf(buf, buf_size, snprintf(buf, buf_size,
"Cannot identify target as a PIC32MX family (manufacturer 0x%03d != 0x%03d)\n", "Cannot identify target as a PIC32MX family (manufacturer 0x%03x != 0x%03x)\n",
(unsigned)((device_id >> 1) & 0x7ff), (unsigned)((device_id >> 1) & 0x7ff),
PIC32MX_MANUF_ID); PIC32MX_MANUF_ID);
return ERROR_FLASH_OPERATION_FAILED; return ERROR_FLASH_OPERATION_FAILED;
@ -920,7 +916,7 @@ COMMAND_HANDLER(pic32mx_handle_unlock_command)
mchip_cmd = MCHP_STATUS; mchip_cmd = MCHP_STATUS;
mips_ejtag_drscan_8(ejtag_info, &mchip_cmd); mips_ejtag_drscan_8(ejtag_info, &mchip_cmd);
if (timeout-- == 0) { if (timeout-- == 0) {
LOG_DEBUG("timeout waiting for unlock: 0x%" PRIx32 "", mchip_cmd); LOG_DEBUG("timeout waiting for unlock: 0x%" PRIx8 "", mchip_cmd);
break; break;
} }
alive_sleep(1); alive_sleep(1);

View File

@ -35,7 +35,7 @@
#include <target/algorithm.h> #include <target/algorithm.h>
#include <target/armv7m.h> #include <target/armv7m.h>
/* device documets: /* device documents:
PSoC(R) 4: PSoC 4200 Family Datasheet PSoC(R) 4: PSoC 4200 Family Datasheet
Document Number: 001-87197 Rev. *B Revised August 29, 2013 Document Number: 001-87197 Rev. *B Revised August 29, 2013
@ -157,7 +157,7 @@ const struct psoc4_chip_family psoc4_families[] = {
struct psoc4_flash_bank { struct psoc4_flash_bank {
uint32_t row_size; uint32_t row_size;
uint32_t user_bank_size; uint32_t user_bank_size;
int num_macros; unsigned int num_macros;
bool probed; bool probed;
uint8_t cmd_program_row; uint8_t cmd_program_row;
uint16_t family_id; uint16_t family_id;
@ -392,7 +392,7 @@ static int psoc4_get_silicon_id(struct flash_bank *bank, uint32_t *silicon_id, u
/* build ID as Cypress sw does: /* build ID as Cypress sw does:
* bit 31..16 silicon ID * bit 31..16 silicon ID
* bit 15..8 revision ID (so far 0x11 for all devices) * bit 15..8 revision ID (so far 0x11 for all devices)
* bit 7..0 family ID (lowes 8 bits) * bit 7..0 family ID (lowest 8 bits)
*/ */
if (silicon_id) if (silicon_id)
*silicon_id = ((part0 & 0x0000ffff) << 16) *silicon_id = ((part0 & 0x0000ffff) << 16)
@ -496,16 +496,15 @@ static int psoc4_protect_check(struct flash_bank *bank)
uint32_t prot_addr = PSOC4_SFLASH_MACRO0; uint32_t prot_addr = PSOC4_SFLASH_MACRO0;
int retval; int retval;
int s = 0;
int m, i;
uint8_t bf[PSOC4_ROWS_PER_MACRO/8]; uint8_t bf[PSOC4_ROWS_PER_MACRO/8];
unsigned int s = 0;
for (m = 0; m < psoc4_info->num_macros; m++, prot_addr += PSOC4_SFLASH_MACRO_SIZE) { for (unsigned int m = 0; m < psoc4_info->num_macros; m++, prot_addr += PSOC4_SFLASH_MACRO_SIZE) {
retval = target_read_memory(target, prot_addr, 4, PSOC4_ROWS_PER_MACRO/32, bf); retval = target_read_memory(target, prot_addr, 4, PSOC4_ROWS_PER_MACRO/32, bf);
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
for (i = 0; i < PSOC4_ROWS_PER_MACRO && s < bank->num_sectors; i++, s++) for (unsigned int i = 0; i < PSOC4_ROWS_PER_MACRO && s < bank->num_sectors; i++, s++)
bank->sectors[s].is_protected = bf[i/8] & (1 << (i%8)) ? 1 : 0; bank->sectors[s].is_protected = bf[i/8] & (1 << (i%8)) ? 1 : 0;
} }
@ -515,7 +514,6 @@ static int psoc4_protect_check(struct flash_bank *bank)
static int psoc4_mass_erase(struct flash_bank *bank) static int psoc4_mass_erase(struct flash_bank *bank)
{ {
int i;
int retval = psoc4_flash_prepare(bank); int retval = psoc4_flash_prepare(bank);
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
@ -528,14 +526,15 @@ static int psoc4_mass_erase(struct flash_bank *bank)
if (retval == ERROR_OK) if (retval == ERROR_OK)
/* set all sectors as erased */ /* set all sectors as erased */
for (i = 0; i < bank->num_sectors; i++) for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 1; bank->sectors[i].is_erased = 1;
return retval; return retval;
} }
static int psoc4_erase(struct flash_bank *bank, int first, int last) static int psoc4_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct psoc4_flash_bank *psoc4_info = bank->driver_priv; struct psoc4_flash_bank *psoc4_info = bank->driver_priv;
if (psoc4_info->cmd_program_row == PSOC4_CMD_WRITE_ROW) { if (psoc4_info->cmd_program_row == PSOC4_CMD_WRITE_ROW) {
@ -552,7 +551,8 @@ static int psoc4_erase(struct flash_bank *bank, int first, int last)
} }
static int psoc4_protect(struct flash_bank *bank, int set, int first, int last) static int psoc4_protect(struct flash_bank *bank, int set, unsigned int first,
unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
struct psoc4_flash_bank *psoc4_info = bank->driver_priv; struct psoc4_flash_bank *psoc4_info = bank->driver_priv;
@ -567,8 +567,8 @@ static int psoc4_protect(struct flash_bank *bank, int set, int first, int last)
uint32_t *sysrq_buffer = NULL; uint32_t *sysrq_buffer = NULL;
const int param_sz = 8; const int param_sz = 8;
int chip_prot = PSOC4_CHIP_PROT_OPEN; int chip_prot = PSOC4_CHIP_PROT_OPEN;
int i, m, sect; unsigned int i;
int num_bits = bank->num_sectors; unsigned int num_bits = bank->num_sectors;
if (num_bits > PSOC4_ROWS_PER_MACRO) if (num_bits > PSOC4_ROWS_PER_MACRO)
num_bits = PSOC4_ROWS_PER_MACRO; num_bits = PSOC4_ROWS_PER_MACRO;
@ -584,7 +584,7 @@ static int psoc4_protect(struct flash_bank *bank, int set, int first, int last)
for (i = first; i <= last && i < bank->num_sectors; i++) for (i = first; i <= last && i < bank->num_sectors; i++)
bank->sectors[i].is_protected = set; bank->sectors[i].is_protected = set;
for (m = 0, sect = 0; m < psoc4_info->num_macros; m++) { for (unsigned int m = 0, sect = 0; m < psoc4_info->num_macros; m++) {
uint8_t *p = (uint8_t *)(sysrq_buffer + 2); uint8_t *p = (uint8_t *)(sysrq_buffer + 2);
memset(p, 0, prot_sz); memset(p, 0, prot_sz);
for (i = 0; i < num_bits && sect < bank->num_sectors; i++, sect++) { for (i = 0; i < num_bits && sect < bank->num_sectors; i++, sect++) {
@ -610,8 +610,7 @@ static int psoc4_protect(struct flash_bank *bank, int set, int first, int last)
break; break;
} }
if (sysrq_buffer) free(sysrq_buffer);
free(sysrq_buffer);
psoc4_protect_check(bank); psoc4_protect_check(bank);
return retval; return retval;
@ -714,9 +713,7 @@ static int psoc4_write(struct flash_bank *bank, const uint8_t *buffer,
cleanup: cleanup:
jtag_poll_set_enabled(save_poll); jtag_poll_set_enabled(save_poll);
if (sysrq_buffer) free(sysrq_buffer);
free(sysrq_buffer);
return retval; return retval;
} }
@ -827,9 +824,7 @@ static int psoc4_probe(struct flash_bank *bank)
} }
} }
if (bank->sectors) { free(bank->sectors);
free(bank->sectors);
}
psoc4_info->family_id = family_id; psoc4_info->family_id = family_id;
psoc4_info->num_macros = num_macros; psoc4_info->num_macros = num_macros;

View File

@ -47,7 +47,7 @@
#define PANTHER_DEVICE_ID 0x4008001C #define PANTHER_DEVICE_ID 0x4008001C
/* NVL is not actually mapped to the Cortex-M address space /* NVL is not actually mapped to the Cortex-M address space
* As we need a base addess different from other banks in the device * As we need a base address different from other banks in the device
* we use the address of NVL programming data in Cypress images */ * we use the address of NVL programming data in Cypress images */
#define NVL_META_BASE 0x90000000 #define NVL_META_BASE 0x90000000
@ -657,7 +657,8 @@ static int psoc5lp_nvl_read(struct flash_bank *bank,
return ERROR_OK; return ERROR_OK;
} }
static int psoc5lp_nvl_erase(struct flash_bank *bank, int first, int last) static int psoc5lp_nvl_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
LOG_WARNING("There is no erase operation for NV Latches"); LOG_WARNING("There is no erase operation for NV Latches");
return ERROR_FLASH_OPER_UNSUPPORTED; return ERROR_FLASH_OPER_UNSUPPORTED;
@ -665,9 +666,7 @@ static int psoc5lp_nvl_erase(struct flash_bank *bank, int first, int last)
static int psoc5lp_nvl_erase_check(struct flash_bank *bank) static int psoc5lp_nvl_erase_check(struct flash_bank *bank)
{ {
int i; for (unsigned int i = 0; i < bank->num_sectors; i++)
for (i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 0; bank->sectors[i].is_erased = 0;
return ERROR_OK; return ERROR_OK;
@ -861,11 +860,12 @@ struct psoc5lp_eeprom_flash_bank {
const struct psoc5lp_device *device; const struct psoc5lp_device *device;
}; };
static int psoc5lp_eeprom_erase(struct flash_bank *bank, int first, int last) static int psoc5lp_eeprom_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
int i, retval; int retval;
for (i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
retval = psoc5lp_spc_erase_sector(bank->target, retval = psoc5lp_spc_erase_sector(bank->target,
SPC_ARRAY_EEPROM, i); SPC_ARRAY_EEPROM, i);
if (retval != ERROR_OK) if (retval != ERROR_OK)
@ -919,7 +919,7 @@ static int psoc5lp_eeprom_write(struct flash_bank *bank,
memset(buf + byte_count, bank->default_padded_value, memset(buf + byte_count, bank->default_padded_value,
EEPROM_ROW_SIZE - byte_count); EEPROM_ROW_SIZE - byte_count);
LOG_DEBUG("Padding %d bytes", EEPROM_ROW_SIZE - byte_count); LOG_DEBUG("Padding %" PRIu32 " bytes", EEPROM_ROW_SIZE - byte_count);
retval = psoc5lp_spc_load_row(target, SPC_ARRAY_EEPROM, retval = psoc5lp_spc_load_row(target, SPC_ARRAY_EEPROM,
buf, EEPROM_ROW_SIZE); buf, EEPROM_ROW_SIZE);
if (retval != ERROR_OK) if (retval != ERROR_OK)
@ -951,7 +951,7 @@ static int psoc5lp_eeprom_probe(struct flash_bank *bank)
struct psoc5lp_eeprom_flash_bank *psoc_eeprom_bank = bank->driver_priv; struct psoc5lp_eeprom_flash_bank *psoc_eeprom_bank = bank->driver_priv;
uint32_t flash_addr = bank->base; uint32_t flash_addr = bank->base;
uint32_t val; uint32_t val;
int i, retval; int retval;
if (psoc_eeprom_bank->probed) if (psoc_eeprom_bank->probed)
return ERROR_OK; return ERROR_OK;
@ -979,7 +979,7 @@ static int psoc5lp_eeprom_probe(struct flash_bank *bank)
bank->num_sectors = DIV_ROUND_UP(bank->size, EEPROM_SECTOR_SIZE); bank->num_sectors = DIV_ROUND_UP(bank->size, EEPROM_SECTOR_SIZE);
bank->sectors = calloc(bank->num_sectors, bank->sectors = calloc(bank->num_sectors,
sizeof(struct flash_sector)); sizeof(struct flash_sector));
for (i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].size = EEPROM_SECTOR_SIZE; bank->sectors[i].size = EEPROM_SECTOR_SIZE;
bank->sectors[i].offset = flash_addr - bank->base; bank->sectors[i].offset = flash_addr - bank->base;
bank->sectors[i].is_erased = -1; bank->sectors[i].is_erased = -1;
@ -1064,27 +1064,28 @@ struct psoc5lp_flash_bank {
* are used for driver private flash operations */ * are used for driver private flash operations */
}; };
static int psoc5lp_erase(struct flash_bank *bank, int first, int last) static int psoc5lp_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct psoc5lp_flash_bank *psoc_bank = bank->driver_priv; struct psoc5lp_flash_bank *psoc_bank = bank->driver_priv;
int i, retval; int retval;
if (!psoc_bank->ecc_enabled) { if (!psoc_bank->ecc_enabled) {
/* Silently avoid erasing sectors twice */ /* Silently avoid erasing sectors twice */
if (last >= first + bank->num_sectors / 2) { if (last >= first + bank->num_sectors / 2) {
LOG_DEBUG("Skipping duplicate erase of sectors %d to %d", LOG_DEBUG("Skipping duplicate erase of sectors %u to %u",
first + bank->num_sectors / 2, last); first + bank->num_sectors / 2, last);
last = first + (bank->num_sectors / 2) - 1; last = first + (bank->num_sectors / 2) - 1;
} }
/* Check for any remaining ECC sectors */ /* Check for any remaining ECC sectors */
if (last >= bank->num_sectors / 2) { if (last >= bank->num_sectors / 2) {
LOG_WARNING("Skipping erase of ECC region sectors %d to %d", LOG_WARNING("Skipping erase of ECC region sectors %u to %u",
bank->num_sectors / 2, last); bank->num_sectors / 2, last);
last = (bank->num_sectors / 2) - 1; last = (bank->num_sectors / 2) - 1;
} }
} }
for (i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
retval = psoc5lp_spc_erase_sector(bank->target, retval = psoc5lp_spc_erase_sector(bank->target,
i / SECTORS_PER_BLOCK, i % SECTORS_PER_BLOCK); i / SECTORS_PER_BLOCK, i % SECTORS_PER_BLOCK);
if (retval != ERROR_OK) if (retval != ERROR_OK)
@ -1099,14 +1100,14 @@ static int psoc5lp_erase_check(struct flash_bank *bank)
{ {
struct psoc5lp_flash_bank *psoc_bank = bank->driver_priv; struct psoc5lp_flash_bank *psoc_bank = bank->driver_priv;
struct target *target = bank->target; struct target *target = bank->target;
int i, retval; int retval;
if (target->state != TARGET_HALTED) { if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted"); LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED; return ERROR_TARGET_NOT_HALTED;
} }
int num_sectors = bank->num_sectors; unsigned int num_sectors = bank->num_sectors;
if (psoc_bank->ecc_enabled) if (psoc_bank->ecc_enabled)
num_sectors *= 2; /* count both std and ecc sector always */ num_sectors *= 2; /* count both std and ecc sector always */
@ -1115,14 +1116,14 @@ static int psoc5lp_erase_check(struct flash_bank *bank)
if (block_array == NULL) if (block_array == NULL)
return ERROR_FAIL; return ERROR_FAIL;
for (i = 0; i < num_sectors; i++) { for (unsigned int i = 0; i < num_sectors; i++) {
block_array[i].address = bank->base + bank->sectors[i].offset; block_array[i].address = bank->base + bank->sectors[i].offset;
block_array[i].size = bank->sectors[i].size; block_array[i].size = bank->sectors[i].size;
block_array[i].result = UINT32_MAX; /* erase state unknown */ block_array[i].result = UINT32_MAX; /* erase state unknown */
} }
bool fast_check = true; bool fast_check = true;
for (i = 0; i < num_sectors; ) { for (unsigned int i = 0; i < num_sectors; ) {
retval = armv7m_blank_check_memory(target, retval = armv7m_blank_check_memory(target,
block_array + i, num_sectors - i, block_array + i, num_sectors - i,
bank->erased_value); bank->erased_value);
@ -1138,14 +1139,14 @@ static int psoc5lp_erase_check(struct flash_bank *bank)
if (fast_check) { if (fast_check) {
if (psoc_bank->ecc_enabled) { if (psoc_bank->ecc_enabled) {
for (i = 0; i < bank->num_sectors; i++) for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = bank->sectors[i].is_erased =
(block_array[i].result != 1) (block_array[i].result != 1)
? block_array[i].result ? block_array[i].result
: block_array[i + bank->num_sectors].result; : block_array[i + bank->num_sectors].result;
/* if std sector is erased, use status of ecc sector */ /* if std sector is erased, use status of ecc sector */
} else { } else {
for (i = 0; i < num_sectors; i++) for (unsigned int i = 0; i < num_sectors; i++)
bank->sectors[i].is_erased = block_array[i].result; bank->sectors[i].is_erased = block_array[i].result;
} }
retval = ERROR_OK; retval = ERROR_OK;
@ -1350,7 +1351,7 @@ static int psoc5lp_protect_check(struct flash_bank *bank)
struct psoc5lp_flash_bank *psoc_bank = bank->driver_priv; struct psoc5lp_flash_bank *psoc_bank = bank->driver_priv;
uint8_t row_data[ROW_SIZE]; uint8_t row_data[ROW_SIZE];
const unsigned protection_bytes_per_sector = ROWS_PER_SECTOR * 2 / 8; const unsigned protection_bytes_per_sector = ROWS_PER_SECTOR * 2 / 8;
unsigned i, j, k, num_sectors; unsigned i, k, num_sectors;
int retval; int retval;
if (bank->target->state != TARGET_HALTED) { if (bank->target->state != TARGET_HALTED) {
@ -1370,7 +1371,7 @@ static int psoc5lp_protect_check(struct flash_bank *bank)
else else
num_sectors = SECTORS_PER_BLOCK; num_sectors = SECTORS_PER_BLOCK;
for (j = 0; j < num_sectors; j++) { for (unsigned int j = 0; j < num_sectors; j++) {
int sector_nr = i * SECTORS_PER_BLOCK + j; int sector_nr = i * SECTORS_PER_BLOCK + j;
struct flash_sector *sector = &bank->sectors[sector_nr]; struct flash_sector *sector = &bank->sectors[sector_nr];
struct flash_sector *ecc_sector; struct flash_sector *ecc_sector;
@ -1416,7 +1417,7 @@ static int psoc5lp_probe(struct flash_bank *bank)
struct psoc5lp_flash_bank *psoc_bank = bank->driver_priv; struct psoc5lp_flash_bank *psoc_bank = bank->driver_priv;
uint32_t flash_addr = bank->base; uint32_t flash_addr = bank->base;
uint8_t nvl[4], temp[2]; uint8_t nvl[4], temp[2];
int i, retval; int retval;
if (target->state != TARGET_HALTED) { if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted"); LOG_ERROR("Target not halted");
@ -1447,7 +1448,7 @@ static int psoc5lp_probe(struct flash_bank *bank)
bank->sectors = calloc(bank->num_sectors * 2, bank->sectors = calloc(bank->num_sectors * 2,
sizeof(struct flash_sector)); sizeof(struct flash_sector));
for (i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].size = SECTOR_SIZE; bank->sectors[i].size = SECTOR_SIZE;
bank->sectors[i].offset = flash_addr - bank->base; bank->sectors[i].offset = flash_addr - bank->base;
bank->sectors[i].is_erased = -1; bank->sectors[i].is_erased = -1;
@ -1456,7 +1457,7 @@ static int psoc5lp_probe(struct flash_bank *bank)
flash_addr += bank->sectors[i].size; flash_addr += bank->sectors[i].size;
} }
flash_addr = 0x48000000; flash_addr = 0x48000000;
for (i = bank->num_sectors; i < bank->num_sectors * 2; i++) { for (unsigned int i = bank->num_sectors; i < bank->num_sectors * 2; i++) {
bank->sectors[i].size = ROWS_PER_SECTOR * ROW_ECC_SIZE; bank->sectors[i].size = ROWS_PER_SECTOR * ROW_ECC_SIZE;
bank->sectors[i].offset = flash_addr - bank->base; bank->sectors[i].offset = flash_addr - bank->base;
bank->sectors[i].is_erased = -1; bank->sectors[i].is_erased = -1;

View File

@ -325,7 +325,7 @@ static int ipc_acquire(struct target *target, char ipc_id)
* @brief Invokes SROM API functions which are responsible for Flash operations * @brief Invokes SROM API functions which are responsible for Flash operations
* *
* @param target current target * @param target current target
* @param req_and_params requect id of the function to invoke * @param req_and_params request id of the function to invoke
* @param working_area address of memory buffer in target's memory space for SROM API parameters * @param working_area address of memory buffer in target's memory space for SROM API parameters
* @param data_out pointer to variable which will be populated with execution status * @param data_out pointer to variable which will be populated with execution status
* @return ERROR_OK in case of success, ERROR_XXX code otherwise * @return ERROR_OK in case of success, ERROR_XXX code otherwise
@ -378,7 +378,7 @@ static int call_sromapi(struct target *target,
bool is_success = (*data_out & SROMAPI_STATUS_MSK) == SROMAPI_STAT_SUCCESS; bool is_success = (*data_out & SROMAPI_STATUS_MSK) == SROMAPI_STAT_SUCCESS;
if (!is_success) { if (!is_success) {
LOG_ERROR("SROM API execution failed. Status: 0x%08X", (uint32_t)*data_out); LOG_ERROR("SROM API execution failed. Status: 0x%08" PRIX32, *data_out);
return ERROR_TARGET_FAILURE; return ERROR_TARGET_FAILURE;
} }
@ -450,7 +450,7 @@ static int psoc6_protect_check(struct flash_bank *bank)
break; break;
} }
for (int i = 0; i < bank->num_sectors; i++) for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_protected = is_protected; bank->sectors[i].is_protected = is_protected;
return ERROR_OK; return ERROR_OK;
@ -460,7 +460,8 @@ static int psoc6_protect_check(struct flash_bank *bank)
* @brief Dummy function, Life Cycle transition is not currently supported * @brief Dummy function, Life Cycle transition is not currently supported
* @return ERROR_OK always * @return ERROR_OK always
*************************************************************************************************/ *************************************************************************************************/
static int psoc6_protect(struct flash_bank *bank, int set, int first, int last) static int psoc6_protect(struct flash_bank *bank, int set, unsigned int first,
unsigned int last)
{ {
(void)bank; (void)bank;
(void)set; (void)set;
@ -474,7 +475,7 @@ static int psoc6_protect(struct flash_bank *bank, int set, int first, int last)
/** *********************************************************************************************** /** ***********************************************************************************************
* @brief Translates Protection status to string * @brief Translates Protection status to string
* @param protection protection value * @param protection protection value
* @return pointer to const string describintg protection status * @return pointer to const string describing protection status
*************************************************************************************************/ *************************************************************************************************/
static const char *protection_to_str(uint8_t protection) static const char *protection_to_str(uint8_t protection)
{ {
@ -512,9 +513,9 @@ static int psoc6_get_info(struct flash_bank *bank, char *buf, int buf_size)
return hr; return hr;
snprintf(buf, buf_size, snprintf(buf, buf_size,
"PSoC6 Silicon ID: 0x%08X\n" "PSoC6 Silicon ID: 0x%08" PRIX32 "\n"
"Protection: %s\n" "Protection: %s\n"
"Main Flash size: %d kB\n" "Main Flash size: %" PRIu32 " kB\n"
"Work Flash size: 32 kB\n", "Work Flash size: 32 kB\n",
psoc6_info->silicon_id, psoc6_info->silicon_id,
protection_to_str(psoc6_info->protection), protection_to_str(psoc6_info->protection),
@ -573,7 +574,7 @@ static int psoc6_probe(struct flash_bank *bank)
int hr = ERROR_OK; int hr = ERROR_OK;
/* Retrieve data from SPCIF_GEOMATRY */ /* Retrieve data from SPCIF_GEOMETRY */
uint32_t geom; uint32_t geom;
target_read_u32(target, PSOC6_SPCIF_GEOMETRY, &geom); target_read_u32(target, PSOC6_SPCIF_GEOMETRY, &geom);
uint32_t row_sz_lg2 = (geom & 0xF0) >> 4; uint32_t row_sz_lg2 = (geom & 0xF0) >> 4;
@ -584,10 +585,8 @@ static int psoc6_probe(struct flash_bank *bank)
/* Calculate size of Main Flash*/ /* Calculate size of Main Flash*/
uint32_t flash_sz_bytes = bank_cnt * row_cnt * row_sz; uint32_t flash_sz_bytes = bank_cnt * row_cnt * row_sz;
if (bank->sectors) { free(bank->sectors);
free(bank->sectors); bank->sectors = NULL;
bank->sectors = NULL;
}
size_t bank_size = 0; size_t bank_size = 0;
@ -609,7 +608,7 @@ static int psoc6_probe(struct flash_bank *bank)
return ERROR_FLASH_BANK_INVALID; return ERROR_FLASH_BANK_INVALID;
} }
size_t num_sectors = bank_size / row_sz; unsigned int num_sectors = bank_size / row_sz;
bank->size = bank_size; bank->size = bank_size;
bank->chip_width = 4; bank->chip_width = 4;
bank->bus_width = 4; bank->bus_width = 4;
@ -618,7 +617,7 @@ static int psoc6_probe(struct flash_bank *bank)
bank->num_sectors = num_sectors; bank->num_sectors = num_sectors;
bank->sectors = calloc(num_sectors, sizeof(struct flash_sector)); bank->sectors = calloc(num_sectors, sizeof(struct flash_sector));
for (size_t i = 0; i < num_sectors; i++) { for (unsigned int i = 0; i < num_sectors; i++) {
bank->sectors[i].size = row_sz; bank->sectors[i].size = row_sz;
bank->sectors[i].offset = i * row_sz; bank->sectors[i].offset = i * row_sz;
bank->sectors[i].is_erased = -1; bank->sectors[i].is_erased = -1;
@ -661,7 +660,7 @@ static int psoc6_erase_sector(struct flash_bank *bank, struct working_area *wa,
{ {
struct target *target = bank->target; struct target *target = bank->target;
LOG_DEBUG("Erasing SECTOR @%08X", addr); LOG_DEBUG("Erasing SECTOR @%08" PRIX32, addr);
int hr = target_write_u32(target, wa->address, SROMAPI_ERASESECTOR_REQ); int hr = target_write_u32(target, wa->address, SROMAPI_ERASESECTOR_REQ);
if (hr != ERROR_OK) if (hr != ERROR_OK)
@ -674,7 +673,7 @@ static int psoc6_erase_sector(struct flash_bank *bank, struct working_area *wa,
uint32_t data_out; uint32_t data_out;
hr = call_sromapi(target, SROMAPI_ERASESECTOR_REQ, wa->address, &data_out); hr = call_sromapi(target, SROMAPI_ERASESECTOR_REQ, wa->address, &data_out);
if (hr != ERROR_OK) if (hr != ERROR_OK)
LOG_ERROR("SECTOR @%08X not erased!", addr); LOG_ERROR("SECTOR @%08" PRIX32 " not erased!", addr);
return hr; return hr;
} }
@ -690,7 +689,7 @@ static int psoc6_erase_row(struct flash_bank *bank, struct working_area *wa, uin
{ {
struct target *target = bank->target; struct target *target = bank->target;
LOG_DEBUG("Erasing ROW @%08X", addr); LOG_DEBUG("Erasing ROW @%08" PRIX32, addr);
int hr = target_write_u32(target, wa->address, SROMAPI_ERASEROW_REQ); int hr = target_write_u32(target, wa->address, SROMAPI_ERASEROW_REQ);
if (hr != ERROR_OK) if (hr != ERROR_OK)
@ -703,7 +702,7 @@ static int psoc6_erase_row(struct flash_bank *bank, struct working_area *wa, uin
uint32_t data_out; uint32_t data_out;
hr = call_sromapi(target, SROMAPI_ERASEROW_REQ, wa->address, &data_out); hr = call_sromapi(target, SROMAPI_ERASEROW_REQ, wa->address, &data_out);
if (hr != ERROR_OK) if (hr != ERROR_OK)
LOG_ERROR("ROW @%08X not erased!", addr); LOG_ERROR("ROW @%08" PRIX32 " not erased!", addr);
return hr; return hr;
} }
@ -717,7 +716,8 @@ static int psoc6_erase_row(struct flash_bank *bank, struct working_area *wa, uin
* @param last last sector to erase * @param last last sector to erase
* @return ERROR_OK in case of success, ERROR_XXX code otherwise * @return ERROR_OK in case of success, ERROR_XXX code otherwise
*************************************************************************************************/ *************************************************************************************************/
static int psoc6_erase(struct flash_bank *bank, int first, int last) static int psoc6_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
struct psoc6_target_info *psoc6_info = bank->driver_priv; struct psoc6_target_info *psoc6_info = bank->driver_priv;
@ -740,7 +740,7 @@ static int psoc6_erase(struct flash_bank *bank, int first, int last)
goto exit; goto exit;
/* Number of rows in single sector */ /* Number of rows in single sector */
const int rows_in_sector = sector_size / psoc6_info->row_sz; const unsigned int rows_in_sector = sector_size / psoc6_info->row_sz;
while (last >= first) { while (last >= first) {
/* Erase Sector if we are on sector boundary and erase size covers whole sector */ /* Erase Sector if we are on sector boundary and erase size covers whole sector */
@ -750,7 +750,7 @@ static int psoc6_erase(struct flash_bank *bank, int first, int last)
if (hr != ERROR_OK) if (hr != ERROR_OK)
goto exit_free_wa; goto exit_free_wa;
for (int i = first; i < first + rows_in_sector; i++) for (unsigned int i = first; i < first + rows_in_sector; i++)
bank->sectors[i].is_erased = 1; bank->sectors[i].is_erased = 1;
first += rows_in_sector; first += rows_in_sector;
@ -792,7 +792,7 @@ static int psoc6_program_row(struct flash_bank *bank,
uint32_t data_out; uint32_t data_out;
int hr = ERROR_OK; int hr = ERROR_OK;
LOG_DEBUG("Programming ROW @%08X", addr); LOG_DEBUG("Programming ROW @%08" PRIX32, addr);
hr = target_alloc_working_area(target, psoc6_info->row_sz + 32, &wa); hr = target_alloc_working_area(target, psoc6_info->row_sz + 32, &wa);
if (hr != ERROR_OK) if (hr != ERROR_OK)
@ -833,7 +833,7 @@ exit:
* @brief Performs Program operation * @brief Performs Program operation
* @param bank current flash bank * @param bank current flash bank
* @param buffer pointer to the buffer with data * @param buffer pointer to the buffer with data
* @param offset starting offset in falsh bank * @param offset starting offset in flash bank
* @param count number of bytes in buffer * @param count number of bytes in buffer
* @return ERROR_OK in case of success, ERROR_XXX code otherwise * @return ERROR_OK in case of success, ERROR_XXX code otherwise
*************************************************************************************************/ *************************************************************************************************/
@ -863,7 +863,7 @@ static int psoc6_program(struct flash_bank *bank,
hr = psoc6_program_row(bank, aligned_addr, page_buf, is_sflash); hr = psoc6_program_row(bank, aligned_addr, page_buf, is_sflash);
if (hr != ERROR_OK) { if (hr != ERROR_OK) {
LOG_ERROR("Failed to program Flash at address 0x%08X", aligned_addr); LOG_ERROR("Failed to program Flash at address 0x%08" PRIX32, aligned_addr);
goto exit; goto exit;
} }
@ -954,16 +954,16 @@ int handle_reset_halt(struct target *target)
const struct armv7m_common *cm = target_to_armv7m(target); const struct armv7m_common *cm = target_to_armv7m(target);
/* PSoC6 reboots immediatelly after issuing SYSRESETREQ / VECTRESET /* PSoC6 reboots immediately after issuing SYSRESETREQ / VECTRESET
* this disables SWD/JTAG pins momentarily and may break communication * this disables SWD/JTAG pins momentarily and may break communication
* Ignoring return value of mem_ap_write_atomic_u32 seems to be ok here */ * Ignoring return value of mem_ap_write_atomic_u32 seems to be ok here */
if (is_cm0) { if (is_cm0) {
/* Reset the CM0 by asserting SYSRESETREQ. This will also reset CM4 */ /* Reset the CM0 by asserting SYSRESETREQ. This will also reset CM4 */
LOG_INFO("psoc6.cm0: bkpt @0x%08X, issuing SYSRESETREQ", reset_addr); LOG_INFO("psoc6.cm0: bkpt @0x%08" PRIX32 ", issuing SYSRESETREQ", reset_addr);
mem_ap_write_atomic_u32(cm->debug_ap, NVIC_AIRCR, mem_ap_write_atomic_u32(cm->debug_ap, NVIC_AIRCR,
AIRCR_VECTKEY | AIRCR_SYSRESETREQ); AIRCR_VECTKEY | AIRCR_SYSRESETREQ);
} else { } else {
LOG_INFO("psoc6.cm4: bkpt @0x%08X, issuing VECTRESET", reset_addr); LOG_INFO("psoc6.cm4: bkpt @0x%08" PRIX32 ", issuing VECTRESET", reset_addr);
mem_ap_write_atomic_u32(cm->debug_ap, NVIC_AIRCR, mem_ap_write_atomic_u32(cm->debug_ap, NVIC_AIRCR,
AIRCR_VECTKEY | AIRCR_VECTRESET); AIRCR_VECTKEY | AIRCR_VECTRESET);
} }

View File

@ -451,8 +451,8 @@ static int rpchf_spansion_write_words(struct flash_bank *bank, const uint8_t *wo
/* Check for valid size */ /* Check for valid size */
if (wordcount > bufferwsize) { if (wordcount > bufferwsize) {
LOG_ERROR("Number of data words %" PRId32 " exceeds available buffersize %" LOG_ERROR("Number of data words %" PRIu32 " exceeds available buffersize %"
PRId32, wordcount, buffersize); PRIu32, wordcount, buffersize);
return ERROR_FLASH_OPERATION_FAILED; return ERROR_FLASH_OPERATION_FAILED;
} }
@ -497,7 +497,6 @@ static int rpchf_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t
int align; /* number of unaligned bytes */ int align; /* number of unaligned bytes */
uint8_t current_word[CFI_MAX_BUS_WIDTH * 4]; /* word (bus_width size) currently being uint8_t current_word[CFI_MAX_BUS_WIDTH * 4]; /* word (bus_width size) currently being
*programmed */ *programmed */
int i;
int retval; int retval;
if (bank->target->state != TARGET_HALTED) { if (bank->target->state != TARGET_HALTED) {
@ -523,14 +522,13 @@ static int rpchf_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t
return retval; return retval;
/* replace only bytes that must be written */ /* replace only bytes that must be written */
for (i = align; for (unsigned int i = align; (i < bank->bus_width) && (count > 0); i++, count--) {
(i < bank->bus_width) && (count > 0);
i++, count--)
if (cfi_info->data_swap) if (cfi_info->data_swap)
/* data bytes are swapped (reverse endianness) */ /* data bytes are swapped (reverse endianness) */
current_word[bank->bus_width - i] = *buffer++; current_word[bank->bus_width - i] = *buffer++;
else else
current_word[i] = *buffer++; current_word[i] = *buffer++;
}
retval = cfi_write_word(bank, current_word, write_p); retval = cfi_write_word(bank, current_word, write_p);
if (retval != ERROR_OK) if (retval != ERROR_OK)
@ -547,12 +545,12 @@ static int rpchf_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t
/* fall back to memory writes */ /* fall back to memory writes */
while (count >= (uint32_t)bank->bus_width) { while (count >= (uint32_t)bank->bus_width) {
int fallback; bool fallback;
if ((write_p & 0xff) == 0) { if ((write_p & 0xff) == 0) {
LOG_INFO("Programming at 0x%08" PRIx32 ", count 0x%08" LOG_INFO("Programming at 0x%08" PRIx32 ", count 0x%08"
PRIx32 " bytes remaining", write_p, count); PRIx32 " bytes remaining", write_p, count);
} }
fallback = 1; fallback = true;
if ((bufferwsize > 0) && (count >= buffersize) && if ((bufferwsize > 0) && (count >= buffersize) &&
!(write_p & buffermask)) { !(write_p & buffermask)) {
retval = rpchf_write_words(bank, buffer, bufferwsize, write_p); retval = rpchf_write_words(bank, buffer, bufferwsize, write_p);
@ -560,13 +558,13 @@ static int rpchf_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t
buffer += buffersize; buffer += buffersize;
write_p += buffersize; write_p += buffersize;
count -= buffersize; count -= buffersize;
fallback = 0; fallback = false;
} else if (retval != ERROR_FLASH_OPER_UNSUPPORTED) } else if (retval != ERROR_FLASH_OPER_UNSUPPORTED)
return retval; return retval;
} }
/* try the slow way? */ /* try the slow way? */
if (fallback) { if (fallback) {
for (i = 0; i < bank->bus_width; i++) for (unsigned int i = 0; i < bank->bus_width; i++)
current_word[i] = *buffer++; current_word[i] = *buffer++;
retval = cfi_write_word(bank, current_word, write_p); retval = cfi_write_word(bank, current_word, write_p);
@ -585,7 +583,7 @@ static int rpchf_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t
/* handle unaligned tail bytes */ /* handle unaligned tail bytes */
if (count > 0) { if (count > 0) {
LOG_INFO("Fixup %" PRId32 " unaligned tail bytes", count); LOG_INFO("Fixup %" PRIu32 " unaligned tail bytes", count);
/* read a complete word from flash */ /* read a complete word from flash */
retval = cfi_target_read_memory(bank, write_p, 1, current_word); retval = cfi_target_read_memory(bank, write_p, 1, current_word);
@ -593,7 +591,7 @@ static int rpchf_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t
return retval; return retval;
/* replace only bytes that must be written */ /* replace only bytes that must be written */
for (i = 0; (i < bank->bus_width) && (count > 0); i++, count--) for (unsigned int i = 0; (i < bank->bus_width) && (count > 0); i++, count--)
if (cfi_info->data_swap) if (cfi_info->data_swap)
/* data bytes are swapped (reverse endianness) */ /* data bytes are swapped (reverse endianness) */
current_word[bank->bus_width - i] = *buffer++; current_word[bank->bus_width - i] = *buffer++;
@ -614,7 +612,7 @@ static int rpchf_read(struct flash_bank *bank, uint8_t *buffer, uint32_t offset,
struct cfi_flash_bank *cfi_info = bank->driver_priv; struct cfi_flash_bank *cfi_info = bank->driver_priv;
struct target *target = bank->target; struct target *target = bank->target;
LOG_DEBUG("reading buffer of %" PRIi32 " byte at 0x%8.8" PRIx32, LOG_DEBUG("reading buffer of %" PRIu32 " byte at 0x%8.8" PRIx32,
count, offset); count, offset);
if (bank->target->state != TARGET_HALTED) { if (bank->target->state != TARGET_HALTED) {

View File

@ -77,7 +77,7 @@
struct sh_qspi_flash_bank { struct sh_qspi_flash_bank {
const struct flash_device *dev; const struct flash_device *dev;
uint32_t io_base; uint32_t io_base;
int probed; bool probed;
struct working_area *io_algorithm; struct working_area *io_algorithm;
struct working_area *source; struct working_area *source;
unsigned int buffer_size; unsigned int buffer_size;
@ -437,21 +437,21 @@ static int sh_qspi_erase_sector(struct flash_bank *bank, int sector)
return wait_till_ready(bank, 3000); return wait_till_ready(bank, 3000);
} }
static int sh_qspi_erase(struct flash_bank *bank, int first, int last) static int sh_qspi_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
struct sh_qspi_flash_bank *info = bank->driver_priv; struct sh_qspi_flash_bank *info = bank->driver_priv;
int retval = ERROR_OK; int retval = ERROR_OK;
int sector;
LOG_DEBUG("%s: from sector %d to sector %d", __func__, first, last); LOG_DEBUG("%s: from sector %u to sector %u", __func__, first, last);
if (target->state != TARGET_HALTED) { if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted"); LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED; return ERROR_TARGET_NOT_HALTED;
} }
if ((first < 0) || (last < first) || (last >= bank->num_sectors)) { if ((last < first) || (last >= bank->num_sectors)) {
LOG_ERROR("Flash sector invalid"); LOG_ERROR("Flash sector invalid");
return ERROR_FLASH_SECTOR_INVALID; return ERROR_FLASH_SECTOR_INVALID;
} }
@ -464,14 +464,14 @@ static int sh_qspi_erase(struct flash_bank *bank, int first, int last)
if (info->dev->erase_cmd == 0x00) if (info->dev->erase_cmd == 0x00)
return ERROR_FLASH_OPER_UNSUPPORTED; return ERROR_FLASH_OPER_UNSUPPORTED;
for (sector = first; sector <= last; sector++) { for (unsigned int sector = first; sector <= last; sector++) {
if (bank->sectors[sector].is_protected) { if (bank->sectors[sector].is_protected) {
LOG_ERROR("Flash sector %d protected", sector); LOG_ERROR("Flash sector %u protected", sector);
return ERROR_FAIL; return ERROR_FAIL;
} }
} }
for (sector = first; sector <= last; sector++) { for (unsigned int sector = first; sector <= last; sector++) {
retval = sh_qspi_erase_sector(bank, sector); retval = sh_qspi_erase_sector(bank, sector);
if (retval != ERROR_OK) if (retval != ERROR_OK)
break; break;
@ -493,7 +493,6 @@ static int sh_qspi_write(struct flash_bank *bank, const uint8_t *buffer,
uint32_t chunk; uint32_t chunk;
bool addr4b = !!(info->dev->size_in_bytes > (1UL << 24)); bool addr4b = !!(info->dev->size_in_bytes > (1UL << 24));
int ret = ERROR_OK; int ret = ERROR_OK;
int sector;
LOG_DEBUG("%s: offset=0x%08" PRIx32 " count=0x%08" PRIx32, LOG_DEBUG("%s: offset=0x%08" PRIx32 " count=0x%08" PRIx32,
__func__, offset, count); __func__, offset, count);
@ -509,13 +508,13 @@ static int sh_qspi_write(struct flash_bank *bank, const uint8_t *buffer,
} }
if (offset & 0xff) { if (offset & 0xff) {
LOG_ERROR("sh_qspi_write_page: unaligned write address: %08x", LOG_ERROR("sh_qspi_write_page: unaligned write address: %08" PRIx32,
offset); offset);
return ERROR_FAIL; return ERROR_FAIL;
} }
/* Check sector protection */ /* Check sector protection */
for (sector = 0; sector < bank->num_sectors; sector++) { for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
/* Start offset in or before this sector? */ /* Start offset in or before this sector? */
/* End offset in or behind this sector? */ /* End offset in or behind this sector? */
struct flash_sector *bs = &bank->sectors[sector]; struct flash_sector *bs = &bank->sectors[sector];
@ -523,7 +522,7 @@ static int sh_qspi_write(struct flash_bank *bank, const uint8_t *buffer,
if ((offset < (bs->offset + bs->size)) && if ((offset < (bs->offset + bs->size)) &&
((offset + count - 1) >= bs->offset) && ((offset + count - 1) >= bs->offset) &&
bs->is_protected) { bs->is_protected) {
LOG_ERROR("Flash sector %d protected", sector); LOG_ERROR("Flash sector %u protected", sector);
return ERROR_FAIL; return ERROR_FAIL;
} }
} }
@ -685,11 +684,9 @@ static int read_flash_id(struct flash_bank *bank, uint32_t *id)
} }
static int sh_qspi_protect(struct flash_bank *bank, int set, static int sh_qspi_protect(struct flash_bank *bank, int set,
int first, int last) unsigned int first, unsigned int last)
{ {
int sector; for (unsigned int sector = first; sector <= last; sector++)
for (sector = first; sector <= last; sector++)
bank->sectors[sector].is_protected = set; bank->sectors[sector].is_protected = set;
return ERROR_OK; return ERROR_OK;
@ -758,7 +755,7 @@ static int sh_qspi_probe(struct flash_bank *bank)
if (info->probed) if (info->probed)
free(bank->sectors); free(bank->sectors);
info->probed = 0; info->probed = false;
for (target_device = target_devices; target_device->name; for (target_device = target_devices; target_device->name;
++target_device) ++target_device)
@ -820,7 +817,7 @@ static int sh_qspi_probe(struct flash_bank *bank)
return ERROR_FAIL; return ERROR_FAIL;
} }
for (int sector = 0; sector < bank->num_sectors; sector++) { for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
sectors[sector].offset = sector * sectorsize; sectors[sector].offset = sector * sectorsize;
sectors[sector].size = sectorsize; sectors[sector].size = sectorsize;
sectors[sector].is_erased = 0; sectors[sector].is_erased = 0;
@ -828,7 +825,7 @@ static int sh_qspi_probe(struct flash_bank *bank)
} }
bank->sectors = sectors; bank->sectors = sectors;
info->probed = 1; info->probed = true;
return ERROR_OK; return ERROR_OK;
} }

View File

@ -250,7 +250,7 @@ static int sim3x_erase_page(struct flash_bank *bank, uint32_t addr)
if (ret != ERROR_OK) if (ret != ERROR_OK)
return ret; return ret;
/* Write the inital unlock value to KEY */ /* Write the initial unlock value to KEY */
ret = target_write_u32(target, FLASHCTRL0_KEY, ret = target_write_u32(target, FLASHCTRL0_KEY,
FLASHCTRL0_KEY_INITIAL_UNLOCK); FLASHCTRL0_KEY_INITIAL_UNLOCK);
if (ret != ERROR_OK) if (ret != ERROR_OK)
@ -277,9 +277,10 @@ static int sim3x_erase_page(struct flash_bank *bank, uint32_t addr)
return ERROR_FAIL; return ERROR_FAIL;
} }
static int sim3x_flash_erase(struct flash_bank *bank, int first, int last) static int sim3x_flash_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
int ret, i; int ret;
uint32_t temp; uint32_t temp;
struct sim3x_info *sim3x_info; struct sim3x_info *sim3x_info;
struct target *target; struct target *target;
@ -302,7 +303,7 @@ static int sim3x_flash_erase(struct flash_bank *bank, int first, int last)
} }
/* erase pages */ /* erase pages */
for (i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
ret = sim3x_erase_page(bank, bank->sectors[i].offset); ret = sim3x_erase_page(bank, bank->sectors[i].offset);
if (ret != ERROR_OK) if (ret != ERROR_OK)
return ret; return ret;
@ -311,7 +312,7 @@ static int sim3x_flash_erase(struct flash_bank *bank, int first, int last)
target = bank->target; target = bank->target;
/* Wait until busy */ /* Wait until busy */
for (i = 0; i < FLASH_BUSY_TIMEOUT; i++) { for (unsigned int i = 0; i < FLASH_BUSY_TIMEOUT; i++) {
ret = target_read_u32(target, FLASHCTRL0_CONFIG_ALL, &temp); ret = target_read_u32(target, FLASHCTRL0_CONFIG_ALL, &temp);
if (ret != ERROR_OK) if (ret != ERROR_OK)
return ret; return ret;
@ -489,7 +490,7 @@ static int sim3x_flash_write(struct flash_bank *bank, const uint8_t *buffer, uin
sim3x_info = bank->driver_priv; sim3x_info = bank->driver_priv;
if (sim3x_info->flash_locked) { if (sim3x_info->flash_locked) {
LOG_ERROR("Falsh is locked"); LOG_ERROR("Flash is locked");
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -547,7 +548,7 @@ static int sim3x_flash_lock_check(struct flash_bank *bank)
static int sim3x_flash_protect_check(struct flash_bank *bank) static int sim3x_flash_protect_check(struct flash_bank *bank)
{ {
int ret, i; int ret;
struct sim3x_info *sim3x_info; struct sim3x_info *sim3x_info;
/* Check if target is halted */ /* Check if target is halted */
@ -562,13 +563,14 @@ static int sim3x_flash_protect_check(struct flash_bank *bank)
sim3x_info = bank->driver_priv; sim3x_info = bank->driver_priv;
for (i = 0; i < bank->num_sectors; i++) for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_protected = sim3x_info->flash_locked; bank->sectors[i].is_protected = sim3x_info->flash_locked;
return ERROR_OK; return ERROR_OK;
} }
static int sim3x_flash_protect(struct flash_bank *bank, int set, int first, int last) static int sim3x_flash_protect(struct flash_bank *bank, int set,
unsigned int first, unsigned int last)
{ {
int ret; int ret;
uint8_t lock_word[4]; uint8_t lock_word[4];
@ -799,10 +801,7 @@ static int sim3x_probe(struct flash_bank *bank)
if (ret != ERROR_OK) if (ret != ERROR_OK)
return ret; return ret;
if (bank->sectors) { free(bank->sectors);
free(bank->sectors);
bank->sectors = NULL;
}
bank->base = FLASH_BASE_ADDRESS; bank->base = FLASH_BASE_ADDRESS;
bank->size = sim3x_info->flash_size_kb * SIM3X_FLASH_PAGE_SIZE; bank->size = sim3x_info->flash_size_kb * SIM3X_FLASH_PAGE_SIZE;
@ -1030,7 +1029,7 @@ COMMAND_HANDLER(sim3x_lock)
ret = target_read_u32(target, CPUID, &val); ret = target_read_u32(target, CPUID, &val);
/* if correct value is read, then it will continue */ /* if correct value is read, then it will continue */
if (ret != ERROR_OK || (val & CPUID_CHECK_VALUE_MASK) != CPUID_CHECK_VALUE) { if (ret != ERROR_OK || (val & CPUID_CHECK_VALUE_MASK) != CPUID_CHECK_VALUE) {
/* if correct value is'n read, then it will check SIM3X_AP_INIT_STAT register */ /* if correct value isn't read, then it will check SIM3X_AP_INIT_STAT register */
ret = ap_read_register(dap, SIM3X_AP_INIT_STAT, &val); ret = ap_read_register(dap, SIM3X_AP_INIT_STAT, &val);
if (ret != ERROR_OK) if (ret != ERROR_OK)
return ret; return ret;

View File

@ -88,6 +88,8 @@ const struct flash_device flash_devices[] = {
FLASH_ID("mac 25r1635f", 0x03, 0x00, 0x02, 0xd8, 0xc7, 0x001528c2, 0x100, 0x10000, 0x200000), FLASH_ID("mac 25r1635f", 0x03, 0x00, 0x02, 0xd8, 0xc7, 0x001528c2, 0x100, 0x10000, 0x200000),
FLASH_ID("mac 25r3235f", 0x03, 0x00, 0x02, 0xd8, 0xc7, 0x001628c2, 0x100, 0x10000, 0x400000), FLASH_ID("mac 25r3235f", 0x03, 0x00, 0x02, 0xd8, 0xc7, 0x001628c2, 0x100, 0x10000, 0x400000),
FLASH_ID("mac 25r6435f", 0x03, 0x00, 0x02, 0xd8, 0xc7, 0x001728c2, 0x100, 0x10000, 0x800000), FLASH_ID("mac 25r6435f", 0x03, 0x00, 0x02, 0xd8, 0xc7, 0x001728c2, 0x100, 0x10000, 0x800000),
FLASH_ID("mac 25u1635e", 0x03, 0xeb, 0x02, 0x20, 0xc7, 0x003525c2, 0x100, 0x1000, 0x100000),
FLASH_ID("micron n25q032", 0x03, 0xeb, 0x02, 0xd8, 0xc7, 0x0016ba20, 0x100, 0x10000, 0x400000),
FLASH_ID("micron n25q064", 0x03, 0xeb, 0x02, 0xd8, 0xc7, 0x0017ba20, 0x100, 0x10000, 0x800000), FLASH_ID("micron n25q064", 0x03, 0xeb, 0x02, 0xd8, 0xc7, 0x0017ba20, 0x100, 0x10000, 0x800000),
FLASH_ID("micron n25q128", 0x03, 0xeb, 0x02, 0xd8, 0xc7, 0x0018ba20, 0x100, 0x10000, 0x1000000), FLASH_ID("micron n25q128", 0x03, 0xeb, 0x02, 0xd8, 0xc7, 0x0018ba20, 0x100, 0x10000, 0x1000000),
FLASH_ID("micron n25q256 3v", 0x13, 0xec, 0x12, 0xdc, 0xc7, 0x0019ba20, 0x100, 0x10000, 0x2000000), FLASH_ID("micron n25q256 3v", 0x13, 0xec, 0x12, 0xdc, 0xc7, 0x0019ba20, 0x100, 0x10000, 0x2000000),

View File

@ -487,7 +487,7 @@ static int get_stellaris_info(struct flash_bank *bank, char *buf, int buf_size)
if (stellaris_info->did1 == 0) if (stellaris_info->did1 == 0)
return ERROR_FLASH_BANK_NOT_PROBED; return ERROR_FLASH_BANK_NOT_PROBED;
/* Read main and master clock freqency register */ /* Read main and master clock frequency register */
stellaris_read_clock_info(bank); stellaris_read_clock_info(bank);
printed = snprintf(buf, printed = snprintf(buf,
@ -533,7 +533,7 @@ static int get_stellaris_info(struct flash_bank *bank, char *buf, int buf_size)
* chip identification and status * * chip identification and status *
***************************************************************************/ ***************************************************************************/
/* Set the flash timimg register to match current clocking */ /* Set the flash timing register to match current clocking */
static void stellaris_set_flash_timing(struct flash_bank *bank) static void stellaris_set_flash_timing(struct flash_bank *bank)
{ {
struct stellaris_flash_bank *stellaris_info = bank->driver_priv; struct stellaris_flash_bank *stellaris_info = bank->driver_priv;
@ -803,12 +803,11 @@ static int stellaris_protect_check(struct flash_bank *bank)
stellaris->num_pages; stellaris->num_pages;
uint32_t fmppe_addr; uint32_t fmppe_addr;
int status = ERROR_OK; int status = ERROR_OK;
unsigned i;
if (stellaris->did1 == 0) if (stellaris->did1 == 0)
return ERROR_FLASH_BANK_NOT_PROBED; return ERROR_FLASH_BANK_NOT_PROBED;
for (i = 0; i < (unsigned) bank->num_sectors; i++) for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_protected = -1; bank->sectors[i].is_protected = -1;
/* Read each Flash Memory Protection Program Enable (FMPPE) register /* Read each Flash Memory Protection Program Enable (FMPPE) register
@ -828,7 +827,7 @@ static int stellaris_protect_check(struct flash_bank *bank)
uint32_t fmppe; uint32_t fmppe;
target_read_u32(target, fmppe_addr, &fmppe); target_read_u32(target, fmppe_addr, &fmppe);
for (i = 0; i < 32 && lockbitnum + i < lockbitcnt; i++) { for (unsigned int i = 0; i < 32 && lockbitnum + i < lockbitcnt; i++) {
bool protect = !(fmppe & (1 << i)); bool protect = !(fmppe & (1 << i));
if (bits_per_page) { if (bits_per_page) {
bank->sectors[page++].is_protected = protect; bank->sectors[page++].is_protected = protect;
@ -844,9 +843,9 @@ static int stellaris_protect_check(struct flash_bank *bank)
return status; return status;
} }
static int stellaris_erase(struct flash_bank *bank, int first, int last) static int stellaris_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
int banknr;
uint32_t flash_fmc, flash_cris; uint32_t flash_fmc, flash_cris;
struct stellaris_flash_bank *stellaris_info = bank->driver_priv; struct stellaris_flash_bank *stellaris_info = bank->driver_priv;
struct target *target = bank->target; struct target *target = bank->target;
@ -859,10 +858,10 @@ static int stellaris_erase(struct flash_bank *bank, int first, int last)
if (stellaris_info->did1 == 0) if (stellaris_info->did1 == 0)
return ERROR_FLASH_BANK_NOT_PROBED; return ERROR_FLASH_BANK_NOT_PROBED;
if ((first < 0) || (last < first) || (last >= (int)stellaris_info->num_pages)) if ((last < first) || (last >= stellaris_info->num_pages))
return ERROR_FLASH_SECTOR_INVALID; return ERROR_FLASH_SECTOR_INVALID;
if ((first == 0) && (last == ((int)stellaris_info->num_pages-1))) if ((first == 0) && (last == (stellaris_info->num_pages - 1)))
return stellaris_mass_erase(bank); return stellaris_mass_erase(bank);
/* Refresh flash controller timing */ /* Refresh flash controller timing */
@ -877,7 +876,7 @@ static int stellaris_erase(struct flash_bank *bank, int first, int last)
* it might want to process those IRQs. * it might want to process those IRQs.
*/ */
for (banknr = first; banknr <= last; banknr++) { for (unsigned int banknr = first; banknr <= last; banknr++) {
/* Address is first word in page */ /* Address is first word in page */
target_write_u32(target, FLASH_FMA, banknr * stellaris_info->pagesize); target_write_u32(target, FLASH_FMA, banknr * stellaris_info->pagesize);
/* Write erase command */ /* Write erase command */
@ -887,7 +886,7 @@ static int stellaris_erase(struct flash_bank *bank, int first, int last)
target_read_u32(target, FLASH_FMC, &flash_fmc); target_read_u32(target, FLASH_FMC, &flash_fmc);
} while (flash_fmc & FMC_ERASE); } while (flash_fmc & FMC_ERASE);
/* Check acess violations */ /* Check access violations */
target_read_u32(target, FLASH_CRIS, &flash_cris); target_read_u32(target, FLASH_CRIS, &flash_cris);
if (flash_cris & (AMASK)) { if (flash_cris & (AMASK)) {
LOG_WARNING("Error erasing flash page %i, flash_cris 0x%" PRIx32 "", LOG_WARNING("Error erasing flash page %i, flash_cris 0x%" PRIx32 "",
@ -902,7 +901,8 @@ static int stellaris_erase(struct flash_bank *bank, int first, int last)
return ERROR_OK; return ERROR_OK;
} }
static int stellaris_protect(struct flash_bank *bank, int set, int first, int last) static int stellaris_protect(struct flash_bank *bank, int set,
unsigned int first, unsigned int last)
{ {
struct stellaris_flash_bank *stellaris = bank->driver_priv; struct stellaris_flash_bank *stellaris = bank->driver_priv;
struct target *target = bank->target; struct target *target = bank->target;
@ -952,7 +952,7 @@ static int stellaris_protect(struct flash_bank *bank, int set, int first, int la
else else
fmppe_addr = SCB_BASE | FMPPE; fmppe_addr = SCB_BASE | FMPPE;
int page = 0; unsigned int page = 0;
unsigned int lockbitnum, lockbitcnt = flash_sizek / 2; unsigned int lockbitnum, lockbitcnt = flash_sizek / 2;
/* Every lock bit always corresponds to a 2k region */ /* Every lock bit always corresponds to a 2k region */
for (lockbitnum = 0; lockbitnum < lockbitcnt; lockbitnum += 32) { for (lockbitnum = 0; lockbitnum < lockbitcnt; lockbitnum += 32) {
@ -998,7 +998,7 @@ static int stellaris_protect(struct flash_bank *bank, int set, int first, int la
return ERROR_OK; return ERROR_OK;
} }
/* see contib/loaders/flash/stellaris.s for src */ /* see contrib/loaders/flash/stellaris.s for src */
static const uint8_t stellaris_write_code[] = { static const uint8_t stellaris_write_code[] = {
/* write: */ /* write: */
@ -1170,7 +1170,7 @@ static int stellaris_write(struct flash_bank *bank, const uint8_t *buffer,
if (retval == ERROR_TARGET_RESOURCE_NOT_AVAILABLE) { if (retval == ERROR_TARGET_RESOURCE_NOT_AVAILABLE) {
LOG_DEBUG("writing flash word-at-a-time"); LOG_DEBUG("writing flash word-at-a-time");
} else if (retval == ERROR_FLASH_OPERATION_FAILED) { } else if (retval == ERROR_FLASH_OPERATION_FAILED) {
/* if an error occured, we examine the reason, and quit */ /* if an error occurred, we examine the reason, and quit */
target_read_u32(target, FLASH_CRIS, &flash_cris); target_read_u32(target, FLASH_CRIS, &flash_cris);
LOG_ERROR("flash writing failed with CRIS: 0x%" PRIx32 "", flash_cris); LOG_ERROR("flash writing failed with CRIS: 0x%" PRIx32 "", flash_cris);
@ -1250,16 +1250,13 @@ static int stellaris_probe(struct flash_bank *bank)
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
if (bank->sectors) { free(bank->sectors);
free(bank->sectors);
bank->sectors = NULL;
}
/* provide this for the benefit of the NOR flash framework */ /* provide this for the benefit of the NOR flash framework */
bank->size = stellaris_info->num_pages * stellaris_info->pagesize; bank->size = stellaris_info->num_pages * stellaris_info->pagesize;
bank->num_sectors = stellaris_info->num_pages; bank->num_sectors = stellaris_info->num_pages;
bank->sectors = calloc(bank->num_sectors, sizeof(struct flash_sector)); bank->sectors = calloc(bank->num_sectors, sizeof(struct flash_sector));
for (int i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].offset = i * stellaris_info->pagesize; bank->sectors[i].offset = i * stellaris_info->pagesize;
bank->sectors[i].size = stellaris_info->pagesize; bank->sectors[i].size = stellaris_info->pagesize;
bank->sectors[i].is_erased = -1; bank->sectors[i].is_erased = -1;
@ -1321,8 +1318,6 @@ static int stellaris_mass_erase(struct flash_bank *bank)
COMMAND_HANDLER(stellaris_handle_mass_erase_command) COMMAND_HANDLER(stellaris_handle_mass_erase_command)
{ {
int i;
if (CMD_ARGC < 1) if (CMD_ARGC < 1)
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
@ -1333,7 +1328,7 @@ COMMAND_HANDLER(stellaris_handle_mass_erase_command)
if (stellaris_mass_erase(bank) == ERROR_OK) { if (stellaris_mass_erase(bank) == ERROR_OK) {
/* set all sectors as erased */ /* set all sectors as erased */
for (i = 0; i < bank->num_sectors; i++) for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 1; bank->sectors[i].is_erased = 1;
command_print(CMD, "stellaris mass erase complete"); command_print(CMD, "stellaris mass erase complete");

View File

@ -359,13 +359,14 @@ static int stm32x_protect_check(struct flash_bank *bank)
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
for (int i = 0; i < bank->num_prot_blocks; i++) for (unsigned int i = 0; i < bank->num_prot_blocks; i++)
bank->prot_blocks[i].is_protected = (protection & (1 << i)) ? 0 : 1; bank->prot_blocks[i].is_protected = (protection & (1 << i)) ? 0 : 1;
return ERROR_OK; return ERROR_OK;
} }
static int stm32x_erase(struct flash_bank *bank, int first, int last) static int stm32x_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
@ -385,7 +386,7 @@ static int stm32x_erase(struct flash_bank *bank, int first, int last)
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
for (int i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
retval = target_write_u32(target, stm32x_get_flash_reg(bank, STM32_FLASH_CR), FLASH_PER); retval = target_write_u32(target, stm32x_get_flash_reg(bank, STM32_FLASH_CR), FLASH_PER);
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
@ -412,7 +413,8 @@ static int stm32x_erase(struct flash_bank *bank, int first, int last)
return ERROR_OK; return ERROR_OK;
} }
static int stm32x_protect(struct flash_bank *bank, int set, int first, int last) static int stm32x_protect(struct flash_bank *bank, int set, unsigned int first,
unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
struct stm32x_flash_bank *stm32x_info = bank->driver_priv; struct stm32x_flash_bank *stm32x_info = bank->driver_priv;
@ -432,7 +434,7 @@ static int stm32x_protect(struct flash_bank *bank, int set, int first, int last)
return retval; return retval;
} }
for (int i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
if (set) if (set)
stm32x_info->option_bytes.protection &= ~(1 << i); stm32x_info->option_bytes.protection &= ~(1 << i);
else else
@ -615,9 +617,7 @@ reset_pg_and_lock:
retval = retval2; retval = retval2;
cleanup: cleanup:
if (new_buffer) free(new_buffer);
free(new_buffer);
return retval; return retval;
} }
@ -870,15 +870,11 @@ static int stm32x_probe(struct flash_bank *bank)
/* check that calculation result makes sense */ /* check that calculation result makes sense */
assert(num_pages > 0); assert(num_pages > 0);
if (bank->sectors) { free(bank->sectors);
free(bank->sectors); bank->sectors = NULL;
bank->sectors = NULL;
}
if (bank->prot_blocks) { free(bank->prot_blocks);
free(bank->prot_blocks); bank->prot_blocks = NULL;
bank->prot_blocks = NULL;
}
bank->base = base_address; bank->base = base_address;
bank->size = (num_pages * page_size); bank->size = (num_pages * page_size);
@ -1499,7 +1495,7 @@ COMMAND_HANDLER(stm32x_handle_mass_erase_command)
retval = stm32x_mass_erase(bank); retval = stm32x_mass_erase(bank);
if (retval == ERROR_OK) { if (retval == ERROR_OK) {
/* set all sectors as erased */ /* set all sectors as erased */
for (int i = 0; i < bank->num_sectors; i++) for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 1; bank->sectors[i].is_erased = 1;
command_print(CMD, "stm32x mass erase complete"); command_print(CMD, "stm32x mass erase complete");

View File

@ -55,7 +55,7 @@
* can be very different. * can be very different.
* *
* To reduce testing complexity and dangers of regressions, * To reduce testing complexity and dangers of regressions,
* a seperate file is used for stm32fx2x. * a separate file is used for stm32fx2x.
* *
* Sector sizes in kiBytes: * Sector sizes in kiBytes:
* 1 MiByte part with 4 x 16, 1 x 64, 7 x 128. * 1 MiByte part with 4 x 16, 1 x 64, 7 x 128.
@ -204,7 +204,7 @@ struct stm32x_flash_bank {
bool has_extra_options; /* F42x/43x/469/479/7xx */ bool has_extra_options; /* F42x/43x/469/479/7xx */
bool has_boot_addr; /* F7xx */ bool has_boot_addr; /* F7xx */
bool has_optcr2_pcrop; /* F72x/73x */ bool has_optcr2_pcrop; /* F72x/73x */
int protection_bits; /* F413/423 */ unsigned int protection_bits; /* F413/423 */
uint32_t user_bank_size; uint32_t user_bank_size;
}; };
@ -230,7 +230,7 @@ static int stm32x_otp_disable(struct flash_bank *bank)
{ {
struct stm32x_flash_bank *stm32x_info = bank->driver_priv; struct stm32x_flash_bank *stm32x_info = bank->driver_priv;
LOG_INFO("OTP memory bank #%d is disabled for write commands.", LOG_INFO("OTP memory bank #%u is disabled for write commands.",
bank->bank_number); bank->bank_number);
stm32x_info->otp_unlocked = false; stm32x_info->otp_unlocked = false;
return ERROR_OK; return ERROR_OK;
@ -241,11 +241,11 @@ static int stm32x_otp_enable(struct flash_bank *bank)
struct stm32x_flash_bank *stm32x_info = bank->driver_priv; struct stm32x_flash_bank *stm32x_info = bank->driver_priv;
if (!stm32x_info->otp_unlocked) { if (!stm32x_info->otp_unlocked) {
LOG_INFO("OTP memory bank #%d is is enabled for write commands.", LOG_INFO("OTP memory bank #%u is is enabled for write commands.",
bank->bank_number); bank->bank_number);
stm32x_info->otp_unlocked = true; stm32x_info->otp_unlocked = true;
} else { } else {
LOG_WARNING("OTP memory bank #%d is is already enabled for write commands.", LOG_WARNING("OTP memory bank #%u is is already enabled for write commands.",
bank->bank_number); bank->bank_number);
} }
return ERROR_OK; return ERROR_OK;
@ -292,7 +292,7 @@ static int stm32x_wait_status_busy(struct flash_bank *bank, int timeout)
retval = stm32x_get_flash_status(bank, &status); retval = stm32x_get_flash_status(bank, &status);
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
LOG_DEBUG("status: 0x%" PRIx32 "", status); LOG_DEBUG("status: 0x%" PRIx32, status);
if ((status & FLASH_BSY) == 0) if ((status & FLASH_BSY) == 0)
break; break;
if (timeout-- <= 0) { if (timeout-- <= 0) {
@ -349,7 +349,7 @@ static int stm32x_unlock_reg(struct target *target)
return retval; return retval;
if (ctrl & FLASH_LOCK) { if (ctrl & FLASH_LOCK) {
LOG_ERROR("flash not unlocked STM32_FLASH_CR: %" PRIx32, ctrl); LOG_ERROR("flash not unlocked STM32_FLASH_CR: 0x%" PRIx32, ctrl);
return ERROR_TARGET_FAILURE; return ERROR_TARGET_FAILURE;
} }
@ -381,7 +381,7 @@ static int stm32x_unlock_option_reg(struct target *target)
return retval; return retval;
if (ctrl & OPTCR_LOCK) { if (ctrl & OPTCR_LOCK) {
LOG_ERROR("options not unlocked STM32_FLASH_OPTCR: %" PRIx32, ctrl); LOG_ERROR("options not unlocked STM32_FLASH_OPTCR: 0x%" PRIx32, ctrl);
return ERROR_TARGET_FAILURE; return ERROR_TARGET_FAILURE;
} }
@ -419,7 +419,7 @@ static int stm32x_read_options(struct flash_bank *bank)
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
/* FLASH_OPTCR1 has quite diffent meanings ... */ /* FLASH_OPTCR1 has quite different meanings ... */
if (stm32x_info->has_boot_addr) { if (stm32x_info->has_boot_addr) {
/* for F7xx it contains boot0 and boot1 */ /* for F7xx it contains boot0 and boot1 */
stm32x_info->option_bytes.boot_addr = optiondata; stm32x_info->option_bytes.boot_addr = optiondata;
@ -522,13 +522,13 @@ static int stm32x_otp_read_protect(struct flash_bank *bank)
{ {
struct target *target = bank->target; struct target *target = bank->target;
uint32_t lock_base; uint32_t lock_base;
int i, retval; int retval;
uint8_t lock; uint8_t lock;
lock_base = stm32x_otp_is_f7(bank) ? STM32F7_OTP_LOCK_BASE lock_base = stm32x_otp_is_f7(bank) ? STM32F7_OTP_LOCK_BASE
: STM32F2_OTP_LOCK_BASE; : STM32F2_OTP_LOCK_BASE;
for (i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
retval = target_read_u8(target, lock_base + i, &lock); retval = target_read_u8(target, lock_base + i, &lock);
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
@ -538,14 +538,15 @@ static int stm32x_otp_read_protect(struct flash_bank *bank)
return ERROR_OK; return ERROR_OK;
} }
static int stm32x_otp_protect(struct flash_bank *bank, int first, int last) static int stm32x_otp_protect(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
uint32_t lock_base; uint32_t lock_base;
int i, retval; int i, retval;
uint8_t lock; uint8_t lock;
assert((0 <= first) && (first <= last) && (last < bank->num_sectors)); assert((first <= last) && (last < bank->num_sectors));
lock_base = stm32x_otp_is_f7(bank) ? STM32F7_OTP_LOCK_BASE lock_base = stm32x_otp_is_f7(bank) ? STM32F7_OTP_LOCK_BASE
: STM32F2_OTP_LOCK_BASE; : STM32F2_OTP_LOCK_BASE;
@ -570,7 +571,7 @@ static int stm32x_protect_check(struct flash_bank *bank)
{ {
struct stm32x_flash_bank *stm32x_info = bank->driver_priv; struct stm32x_flash_bank *stm32x_info = bank->driver_priv;
struct flash_sector *prot_blocks; struct flash_sector *prot_blocks;
int num_prot_blocks; unsigned int num_prot_blocks;
int retval; int retval;
/* if it's the OTP bank, look at the lock bits there */ /* if it's the OTP bank, look at the lock bits there */
@ -592,25 +593,25 @@ static int stm32x_protect_check(struct flash_bank *bank)
prot_blocks = bank->sectors; prot_blocks = bank->sectors;
} }
for (int i = 0; i < num_prot_blocks; i++) for (unsigned int i = 0; i < num_prot_blocks; i++)
prot_blocks[i].is_protected = prot_blocks[i].is_protected =
~(stm32x_info->option_bytes.protection >> i) & 1; ~(stm32x_info->option_bytes.protection >> i) & 1;
return ERROR_OK; return ERROR_OK;
} }
static int stm32x_erase(struct flash_bank *bank, int first, int last) static int stm32x_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct stm32x_flash_bank *stm32x_info = bank->driver_priv; struct stm32x_flash_bank *stm32x_info = bank->driver_priv;
struct target *target = bank->target; struct target *target = bank->target;
int i;
if (stm32x_is_otp(bank)) { if (stm32x_is_otp(bank)) {
LOG_ERROR("Cannot erase OTP memory"); LOG_ERROR("Cannot erase OTP memory");
return ERROR_FAIL; return ERROR_FAIL;
} }
assert((0 <= first) && (first <= last) && (last < bank->num_sectors)); assert((first <= last) && (last < bank->num_sectors));
if (bank->target->state != TARGET_HALTED) { if (bank->target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted"); LOG_ERROR("Target not halted");
@ -633,7 +634,7 @@ static int stm32x_erase(struct flash_bank *bank, int first, int last)
4. Wait for the BSY bit to be cleared 4. Wait for the BSY bit to be cleared
*/ */
for (i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
unsigned int snb; unsigned int snb;
if (stm32x_info->has_large_mem && i >= 12) if (stm32x_info->has_large_mem && i >= 12)
snb = (i - 12) | 0x10; snb = (i - 12) | 0x10;
@ -659,7 +660,8 @@ static int stm32x_erase(struct flash_bank *bank, int first, int last)
return ERROR_OK; return ERROR_OK;
} }
static int stm32x_protect(struct flash_bank *bank, int set, int first, int last) static int stm32x_protect(struct flash_bank *bank, int set, unsigned int first,
unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
struct stm32x_flash_bank *stm32x_info = bank->driver_priv; struct stm32x_flash_bank *stm32x_info = bank->driver_priv;
@ -683,7 +685,7 @@ static int stm32x_protect(struct flash_bank *bank, int set, int first, int last)
return retval; return retval;
} }
for (int i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
if (set) if (set)
stm32x_info->option_bytes.protection &= ~(1 << i); stm32x_info->option_bytes.protection &= ~(1 << i);
else else
@ -776,7 +778,7 @@ static int stm32x_write_block(struct flash_bank *bank, const uint8_t *buffer,
LOG_ERROR("flash memory write protected"); LOG_ERROR("flash memory write protected");
if (error != 0) { if (error != 0) {
LOG_ERROR("flash write failed = %08" PRIx32, error); LOG_ERROR("flash write failed = 0x%08" PRIx32, error);
/* Clear but report errors */ /* Clear but report errors */
target_write_u32(target, STM32_FLASH_SR, error); target_write_u32(target, STM32_FLASH_SR, error);
retval = ERROR_FAIL; retval = ERROR_FAIL;
@ -894,18 +896,18 @@ static int stm32x_write(struct flash_bank *bank, const uint8_t *buffer,
return target_write_u32(target, STM32_FLASH_CR, FLASH_LOCK); return target_write_u32(target, STM32_FLASH_CR, FLASH_LOCK);
} }
static void setup_sector(struct flash_bank *bank, int i, int size) static void setup_sector(struct flash_bank *bank, unsigned int i,
unsigned int size)
{ {
assert(i < bank->num_sectors); assert(i < bank->num_sectors);
bank->sectors[i].offset = bank->size; bank->sectors[i].offset = bank->size;
bank->sectors[i].size = size; bank->sectors[i].size = size;
bank->size += bank->sectors[i].size; bank->size += bank->sectors[i].size;
LOG_DEBUG("sector %d: %dkBytes", i, size >> 10); LOG_DEBUG("sector %u: %ukBytes", i, size >> 10);
} }
static uint16_t sector_size_in_kb(int i, uint16_t max_sector_size_in_kb) static uint16_t sector_size_in_kb(unsigned int i, uint16_t max_sector_size_in_kb)
{ {
assert(i >= 0);
if (i < 4) if (i < 4)
return max_sector_size_in_kb / 8; return max_sector_size_in_kb / 8;
if (i == 4) if (i == 4)
@ -913,13 +915,13 @@ static uint16_t sector_size_in_kb(int i, uint16_t max_sector_size_in_kb)
return max_sector_size_in_kb; return max_sector_size_in_kb;
} }
static int calculate_number_of_sectors(struct flash_bank *bank, static unsigned int calculate_number_of_sectors(struct flash_bank *bank,
uint16_t flash_size_in_kb, uint16_t flash_size_in_kb,
uint16_t max_sector_size_in_kb) uint16_t max_sector_size_in_kb)
{ {
struct stm32x_flash_bank *stm32x_info = bank->driver_priv; struct stm32x_flash_bank *stm32x_info = bank->driver_priv;
uint16_t remaining_flash_size_in_kb = flash_size_in_kb; uint16_t remaining_flash_size_in_kb = flash_size_in_kb;
int nr_sectors; unsigned int nr_sectors;
/* Dual Bank Flash has two identically-arranged banks of sectors. */ /* Dual Bank Flash has two identically-arranged banks of sectors. */
if (stm32x_info->has_large_mem) if (stm32x_info->has_large_mem)
@ -940,11 +942,11 @@ static int calculate_number_of_sectors(struct flash_bank *bank,
return stm32x_info->has_large_mem ? nr_sectors*2 : nr_sectors; return stm32x_info->has_large_mem ? nr_sectors*2 : nr_sectors;
} }
static void setup_bank(struct flash_bank *bank, int start, static void setup_bank(struct flash_bank *bank, unsigned int start,
uint16_t flash_size_in_kb, uint16_t max_sector_size_in_kb) uint16_t flash_size_in_kb, uint16_t max_sector_size_in_kb)
{ {
uint16_t remaining_flash_size_in_kb = flash_size_in_kb; uint16_t remaining_flash_size_in_kb = flash_size_in_kb;
int sector_index = 0; unsigned int sector_index = 0;
while (remaining_flash_size_in_kb > 0) { while (remaining_flash_size_in_kb > 0) {
uint16_t size_in_kb = sector_size_in_kb(sector_index, max_sector_size_in_kb); uint16_t size_in_kb = sector_size_in_kb(sector_index, max_sector_size_in_kb);
if (size_in_kb > remaining_flash_size_in_kb) { if (size_in_kb > remaining_flash_size_in_kb) {
@ -993,7 +995,7 @@ static int stm32x_probe(struct flash_bank *bank)
{ {
struct target *target = bank->target; struct target *target = bank->target;
struct stm32x_flash_bank *stm32x_info = bank->driver_priv; struct stm32x_flash_bank *stm32x_info = bank->driver_priv;
int i, num_prot_blocks, num_sectors; unsigned int num_prot_blocks, num_sectors;
uint16_t flash_size_in_kb; uint16_t flash_size_in_kb;
uint16_t otp_size_in_b; uint16_t otp_size_in_b;
uint16_t otp_sector_size; uint16_t otp_sector_size;
@ -1011,19 +1013,15 @@ static int stm32x_probe(struct flash_bank *bank)
stm32x_info->protection_bits = 12; /* max. number of nWRPi bits (in FLASH_OPTCR !!!) */ stm32x_info->protection_bits = 12; /* max. number of nWRPi bits (in FLASH_OPTCR !!!) */
num_prot_blocks = 0; num_prot_blocks = 0;
if (bank->sectors) { free(bank->sectors);
free(bank->sectors); bank->num_sectors = 0;
bank->num_sectors = 0; bank->sectors = NULL;
bank->sectors = NULL;
}
if (bank->prot_blocks) { free(bank->prot_blocks);
free(bank->prot_blocks); bank->num_prot_blocks = 0;
bank->num_prot_blocks = 0; bank->prot_blocks = NULL;
bank->prot_blocks = NULL;
}
/* if explicitely called out as OTP bank, short circuit probe */ /* if explicitly called out as OTP bank, short circuit probe */
if (stm32x_is_otp(bank)) { if (stm32x_is_otp(bank)) {
if (stm32x_otp_is_f7(bank)) { if (stm32x_otp_is_f7(bank)) {
otp_size_in_b = STM32F7_OTP_SIZE; otp_size_in_b = STM32F7_OTP_SIZE;
@ -1034,7 +1032,7 @@ static int stm32x_probe(struct flash_bank *bank)
} }
num_sectors = otp_size_in_b / otp_sector_size; num_sectors = otp_size_in_b / otp_sector_size;
LOG_INFO("flash size = %d bytes", otp_size_in_b); LOG_INFO("flash size = %" PRIu16 " bytes", otp_size_in_b);
assert(num_sectors > 0); assert(num_sectors > 0);
@ -1046,7 +1044,7 @@ static int stm32x_probe(struct flash_bank *bank)
else else
bank->size = STM32F2_OTP_SIZE; bank->size = STM32F2_OTP_SIZE;
for (i = 0; i < num_sectors; i++) { for (unsigned int i = 0; i < num_sectors; i++) {
bank->sectors[i].offset = i * otp_sector_size; bank->sectors[i].offset = i * otp_sector_size;
bank->sectors[i].size = otp_sector_size; bank->sectors[i].size = otp_sector_size;
bank->sectors[i].is_erased = 1; bank->sectors[i].is_erased = 1;
@ -1061,7 +1059,7 @@ static int stm32x_probe(struct flash_bank *bank)
int retval = stm32x_get_device_id(bank, &device_id); int retval = stm32x_get_device_id(bank, &device_id);
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
LOG_INFO("device id = 0x%08" PRIx32 "", device_id); LOG_INFO("device id = 0x%08" PRIx32, device_id);
device_id &= 0xfff; /* only bits 0-11 are used further on */ device_id &= 0xfff; /* only bits 0-11 are used further on */
/* set max flash size depending on family, id taken from AN2606 */ /* set max flash size depending on family, id taken from AN2606 */
@ -1134,7 +1132,7 @@ static int stm32x_probe(struct flash_bank *bank)
/* failed reading flash size or flash size invalid (early silicon), /* failed reading flash size or flash size invalid (early silicon),
* default to max target family */ * default to max target family */
if (retval != ERROR_OK || flash_size_in_kb == 0xffff || flash_size_in_kb == 0) { if (retval != ERROR_OK || flash_size_in_kb == 0xffff || flash_size_in_kb == 0) {
LOG_WARNING("STM32 flash size failed, probe inaccurate - assuming %dk flash", LOG_WARNING("STM32 flash size failed, probe inaccurate - assuming %" PRIu16 "k flash",
max_flash_size_in_kb); max_flash_size_in_kb);
flash_size_in_kb = max_flash_size_in_kb; flash_size_in_kb = max_flash_size_in_kb;
} }
@ -1146,7 +1144,7 @@ static int stm32x_probe(struct flash_bank *bank)
flash_size_in_kb = stm32x_info->user_bank_size / 1024; flash_size_in_kb = stm32x_info->user_bank_size / 1024;
} }
LOG_INFO("flash size = %d kbytes", flash_size_in_kb); LOG_INFO("flash size = %" PRIu16 " kbytes", flash_size_in_kb);
/* did we assign flash size? */ /* did we assign flash size? */
assert(flash_size_in_kb != 0xffff); assert(flash_size_in_kb != 0xffff);
@ -1161,10 +1159,10 @@ static int stm32x_probe(struct flash_bank *bank)
} }
if ((flash_size_in_kb > 1024) || (optiondata & OPTCR_DB1M)) { if ((flash_size_in_kb > 1024) || (optiondata & OPTCR_DB1M)) {
stm32x_info->has_large_mem = true; stm32x_info->has_large_mem = true;
LOG_INFO("Dual Bank %d kiB STM32F42x/43x/469/479 found", flash_size_in_kb); LOG_INFO("Dual Bank %" PRIu16 " kiB STM32F42x/43x/469/479 found", flash_size_in_kb);
} else { } else {
stm32x_info->has_large_mem = false; stm32x_info->has_large_mem = false;
LOG_INFO("Single Bank %d kiB STM32F42x/43x/469/479 found", flash_size_in_kb); LOG_INFO("Single Bank %" PRIu16 " kiB STM32F42x/43x/469/479 found", flash_size_in_kb);
} }
} }
@ -1178,27 +1176,27 @@ static int stm32x_probe(struct flash_bank *bank)
} }
if (optiondata & OPTCR_NDBANK) { if (optiondata & OPTCR_NDBANK) {
stm32x_info->has_large_mem = false; stm32x_info->has_large_mem = false;
LOG_INFO("Single Bank %d kiB STM32F76x/77x found", flash_size_in_kb); LOG_INFO("Single Bank %" PRIu16 " kiB STM32F76x/77x found", flash_size_in_kb);
} else { } else {
stm32x_info->has_large_mem = true; stm32x_info->has_large_mem = true;
max_sector_size_in_kb >>= 1; /* sector size divided by 2 in dual-bank mode */ max_sector_size_in_kb >>= 1; /* sector size divided by 2 in dual-bank mode */
LOG_INFO("Dual Bank %d kiB STM32F76x/77x found", flash_size_in_kb); LOG_INFO("Dual Bank %" PRIu16 " kiB STM32F76x/77x found", flash_size_in_kb);
} }
} }
/* calculate numbers of pages */ /* calculate numbers of pages */
int num_pages = calculate_number_of_sectors( unsigned int num_pages = calculate_number_of_sectors(
bank, flash_size_in_kb, max_sector_size_in_kb); bank, flash_size_in_kb, max_sector_size_in_kb);
bank->base = base_address; bank->base = base_address;
bank->num_sectors = num_pages; bank->num_sectors = num_pages;
bank->sectors = calloc(num_pages, sizeof(struct flash_sector)); bank->sectors = calloc(num_pages, sizeof(struct flash_sector));
for (i = 0; i < num_pages; i++) { for (unsigned int i = 0; i < num_pages; i++) {
bank->sectors[i].is_erased = -1; bank->sectors[i].is_erased = -1;
bank->sectors[i].is_protected = 0; bank->sectors[i].is_protected = 0;
} }
bank->size = 0; bank->size = 0;
LOG_DEBUG("allocated %d sectors", num_pages); LOG_DEBUG("allocated %u sectors", num_pages);
/* F76x/77x in dual bank mode */ /* F76x/77x in dual bank mode */
if ((device_id == 0x451) && stm32x_info->has_large_mem) if ((device_id == 0x451) && stm32x_info->has_large_mem)
@ -1206,9 +1204,9 @@ static int stm32x_probe(struct flash_bank *bank)
if (num_prot_blocks) { if (num_prot_blocks) {
bank->prot_blocks = malloc(sizeof(struct flash_sector) * num_prot_blocks); bank->prot_blocks = malloc(sizeof(struct flash_sector) * num_prot_blocks);
for (i = 0; i < num_prot_blocks; i++) for (unsigned int i = 0; i < num_prot_blocks; i++)
bank->prot_blocks[i].is_protected = 0; bank->prot_blocks[i].is_protected = 0;
LOG_DEBUG("allocated %d prot blocks", num_prot_blocks); LOG_DEBUG("allocated %u prot blocks", num_prot_blocks);
} }
if (stm32x_info->has_large_mem) { if (stm32x_info->has_large_mem) {
@ -1219,7 +1217,7 @@ static int stm32x_probe(struct flash_bank *bank)
/* F767x/F77x in dual mode, one protection bit refers to two adjacent sectors */ /* F767x/F77x in dual mode, one protection bit refers to two adjacent sectors */
if (device_id == 0x451) { if (device_id == 0x451) {
for (i = 0; i < num_prot_blocks; i++) { for (unsigned int i = 0; i < num_prot_blocks; i++) {
bank->prot_blocks[i].offset = bank->sectors[i << 1].offset; bank->prot_blocks[i].offset = bank->sectors[i << 1].offset;
bank->prot_blocks[i].size = bank->sectors[i << 1].size bank->prot_blocks[i].size = bank->sectors[i << 1].size
+ bank->sectors[(i << 1) + 1].size; + bank->sectors[(i << 1) + 1].size;
@ -1231,7 +1229,7 @@ static int stm32x_probe(struct flash_bank *bank)
/* F413/F423, sectors 14 and 15 share one common protection bit */ /* F413/F423, sectors 14 and 15 share one common protection bit */
if (device_id == 0x463) { if (device_id == 0x463) {
for (i = 0; i < num_prot_blocks; i++) { for (unsigned int i = 0; i < num_prot_blocks; i++) {
bank->prot_blocks[i].offset = bank->sectors[i].offset; bank->prot_blocks[i].offset = bank->sectors[i].offset;
bank->prot_blocks[i].size = bank->sectors[i].size; bank->prot_blocks[i].size = bank->sectors[i].size;
} }
@ -1425,7 +1423,7 @@ static int get_stm32x_info(struct flash_bank *bank, char *buf, int buf_size)
if (rev_str != NULL) if (rev_str != NULL)
snprintf(buf, buf_size, "%s - Rev: %s", device_str, rev_str); snprintf(buf, buf_size, "%s - Rev: %s", device_str, rev_str);
else else
snprintf(buf, buf_size, "%s - Rev: unknown (0x%04x)", device_str, rev_id); snprintf(buf, buf_size, "%s - Rev: unknown (0x%04" PRIx16 ")", device_str, rev_id);
return ERROR_OK; return ERROR_OK;
} }
@ -1559,8 +1557,6 @@ static int stm32x_mass_erase(struct flash_bank *bank)
COMMAND_HANDLER(stm32x_handle_mass_erase_command) COMMAND_HANDLER(stm32x_handle_mass_erase_command)
{ {
int i;
if (CMD_ARGC < 1) { if (CMD_ARGC < 1) {
command_print(CMD, "stm32x mass_erase <bank>"); command_print(CMD, "stm32x mass_erase <bank>");
return ERROR_COMMAND_SYNTAX_ERROR; return ERROR_COMMAND_SYNTAX_ERROR;
@ -1574,7 +1570,7 @@ COMMAND_HANDLER(stm32x_handle_mass_erase_command)
retval = stm32x_mass_erase(bank); retval = stm32x_mass_erase(bank);
if (retval == ERROR_OK) { if (retval == ERROR_OK) {
/* set all sectors as erased */ /* set all sectors as erased */
for (i = 0; i < bank->num_sectors; i++) for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 1; bank->sectors[i].is_erased = 1;
command_print(CMD, "stm32x mass erase complete"); command_print(CMD, "stm32x mass erase complete");
@ -1609,20 +1605,20 @@ COMMAND_HANDLER(stm32f2x_handle_options_read_command)
if (stm32x_info->has_boot_addr) { if (stm32x_info->has_boot_addr) {
uint32_t boot_addr = stm32x_info->option_bytes.boot_addr; uint32_t boot_addr = stm32x_info->option_bytes.boot_addr;
command_print(CMD, "stm32f2x user_options 0x%03X," command_print(CMD, "stm32f2x user_options 0x%03" PRIX16 ","
" boot_add0 0x%04X, boot_add1 0x%04X", " boot_add0 0x%04" PRIX32 ", boot_add1 0x%04" PRIX32,
stm32x_info->option_bytes.user_options, stm32x_info->option_bytes.user_options,
boot_addr & 0xffff, (boot_addr & 0xffff0000) >> 16); boot_addr & 0xffff, (boot_addr & 0xffff0000) >> 16);
if (stm32x_info->has_optcr2_pcrop) { if (stm32x_info->has_optcr2_pcrop) {
command_print(CMD, "stm32f2x optcr2_pcrop 0x%08X", command_print(CMD, "stm32f2x optcr2_pcrop 0x%08" PRIX32,
stm32x_info->option_bytes.optcr2_pcrop); stm32x_info->option_bytes.optcr2_pcrop);
} }
} else { } else {
command_print(CMD, "stm32f2x user_options 0x%03X", command_print(CMD, "stm32f2x user_options 0x%03" PRIX16,
stm32x_info->option_bytes.user_options); stm32x_info->option_bytes.user_options);
} }
} else { } else {
command_print(CMD, "stm32f2x user_options 0x%02X", command_print(CMD, "stm32f2x user_options 0x%02" PRIX16,
stm32x_info->option_bytes.user_options); stm32x_info->option_bytes.user_options);
} }
@ -1752,7 +1748,7 @@ COMMAND_HANDLER(stm32x_handle_otp_command)
stm32x_otp_disable(bank); stm32x_otp_disable(bank);
} else if (strcmp(CMD_ARGV[1], "show") == 0) { } else if (strcmp(CMD_ARGV[1], "show") == 0) {
command_print(CMD, command_print(CMD,
"OTP memory bank #%d is %s for write commands.", "OTP memory bank #%u is %s for write commands.",
bank->bank_number, bank->bank_number,
stm32x_is_otp_unlocked(bank) ? "enabled" : "disabled"); stm32x_is_otp_unlocked(bank) ? "enabled" : "disabled");
} else { } else {

View File

@ -147,7 +147,11 @@ static const struct stm32h7x_rev stm32_480_revs[] = {
{ 0x1000, "A"}, { 0x1000, "A"},
}; };
static uint32_t stm32x_compute_flash_cr_450(uint32_t cmd, int snb) static const struct stm32h7x_rev stm32_483_revs[] = {
{ 0x1000, "A" }, { 0x1001, "Z" },
};
static uint32_t stm32x_compute_flash_cr_450_483(uint32_t cmd, int snb)
{ {
return cmd | (snb << 8); return cmd | (snb << 8);
} }
@ -177,7 +181,7 @@ static const struct stm32h7x_part_info stm32h7x_parts[] = {
.fsize_addr = 0x1FF1E880, .fsize_addr = 0x1FF1E880,
.wps_group_size = 1, .wps_group_size = 1,
.wps_mask = 0xFF, .wps_mask = 0xFF,
.compute_flash_cr = stm32x_compute_flash_cr_450, .compute_flash_cr = stm32x_compute_flash_cr_450_483,
}, },
{ {
.id = 0x480, .id = 0x480,
@ -194,6 +198,21 @@ static const struct stm32h7x_part_info stm32h7x_parts[] = {
.wps_mask = 0xFFFFFFFF, .wps_mask = 0xFFFFFFFF,
.compute_flash_cr = stm32x_compute_flash_cr_480, .compute_flash_cr = stm32x_compute_flash_cr_480,
}, },
{
.id = 0x483,
.revs = stm32_483_revs,
.num_revs = ARRAY_SIZE(stm32_483_revs),
.device_str = "STM32H72x/73x",
.page_size_kb = 128,
.block_size = 32,
.max_flash_size_kb = 1024,
.max_bank_size_kb = 1024,
.has_dual_bank = false,
.fsize_addr = 0x1FF1E880,
.wps_group_size = 1,
.wps_mask = 0xFF,
.compute_flash_cr = stm32x_compute_flash_cr_450_483,
},
}; };
/* flash bank stm32x <base> <size> 0 0 <target#> */ /* flash bank stm32x <base> <size> 0 0 <target#> */
@ -262,7 +281,7 @@ static int stm32x_wait_flash_op_queue(struct flash_bank *bank, int timeout)
break; break;
if (timeout-- <= 0) { if (timeout-- <= 0) {
LOG_ERROR("wait_flash_op_queue, time out expired, status: 0x%" PRIx32 "", status); LOG_ERROR("wait_flash_op_queue, time out expired, status: 0x%" PRIx32, status);
return ERROR_FAIL; return ERROR_FAIL;
} }
alive_sleep(1); alive_sleep(1);
@ -311,7 +330,7 @@ static int stm32x_unlock_reg(struct flash_bank *bank)
return retval; return retval;
if (ctrl & FLASH_LOCK) { if (ctrl & FLASH_LOCK) {
LOG_ERROR("flash not unlocked STM32_FLASH_CRx: %" PRIx32, ctrl); LOG_ERROR("flash not unlocked STM32_FLASH_CRx: 0x%" PRIx32, ctrl);
return ERROR_TARGET_FAILURE; return ERROR_TARGET_FAILURE;
} }
return ERROR_OK; return ERROR_OK;
@ -342,7 +361,7 @@ static int stm32x_unlock_option_reg(struct flash_bank *bank)
return retval; return retval;
if (ctrl & OPT_LOCK) { if (ctrl & OPT_LOCK) {
LOG_ERROR("options not unlocked STM32_FLASH_OPTCR: %" PRIx32, ctrl); LOG_ERROR("options not unlocked STM32_FLASH_OPTCR: 0x%" PRIx32, ctrl);
return ERROR_TARGET_FAILURE; return ERROR_TARGET_FAILURE;
} }
@ -396,7 +415,7 @@ static int stm32x_write_option(struct flash_bank *bank, uint32_t reg_offset, uin
break; break;
if (timeout-- <= 0) { if (timeout-- <= 0) {
LOG_ERROR("waiting for OBL launch, time out expired, OPTSR: 0x%" PRIx32 "", status); LOG_ERROR("waiting for OBL launch, time out expired, OPTSR: 0x%" PRIx32, status);
retval = ERROR_FAIL; retval = ERROR_FAIL;
goto flash_options_lock; goto flash_options_lock;
} }
@ -441,13 +460,14 @@ static int stm32x_protect_check(struct flash_bank *bank)
return retval; return retval;
} }
for (int i = 0; i < bank->num_prot_blocks; i++) for (unsigned int i = 0; i < bank->num_prot_blocks; i++)
bank->prot_blocks[i].is_protected = protection & (1 << i) ? 0 : 1; bank->prot_blocks[i].is_protected = protection & (1 << i) ? 0 : 1;
return ERROR_OK; return ERROR_OK;
} }
static int stm32x_erase(struct flash_bank *bank, int first, int last) static int stm32x_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct stm32h7x_flash_bank *stm32x_info = bank->driver_priv; struct stm32h7x_flash_bank *stm32x_info = bank->driver_priv;
int retval, retval2; int retval, retval2;
@ -472,24 +492,24 @@ static int stm32x_erase(struct flash_bank *bank, int first, int last)
3. Set the STRT bit in the FLASH_CR register 3. Set the STRT bit in the FLASH_CR register
4. Wait for flash operations completion 4. Wait for flash operations completion
*/ */
for (int i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
LOG_DEBUG("erase sector %d", i); LOG_DEBUG("erase sector %u", i);
retval = stm32x_write_flash_reg(bank, FLASH_CR, retval = stm32x_write_flash_reg(bank, FLASH_CR,
stm32x_info->part_info->compute_flash_cr(FLASH_SER | FLASH_PSIZE_64, i)); stm32x_info->part_info->compute_flash_cr(FLASH_SER | FLASH_PSIZE_64, i));
if (retval != ERROR_OK) { if (retval != ERROR_OK) {
LOG_ERROR("Error erase sector %d", i); LOG_ERROR("Error erase sector %u", i);
goto flash_lock; goto flash_lock;
} }
retval = stm32x_write_flash_reg(bank, FLASH_CR, retval = stm32x_write_flash_reg(bank, FLASH_CR,
stm32x_info->part_info->compute_flash_cr(FLASH_SER | FLASH_PSIZE_64 | FLASH_START, i)); stm32x_info->part_info->compute_flash_cr(FLASH_SER | FLASH_PSIZE_64 | FLASH_START, i));
if (retval != ERROR_OK) { if (retval != ERROR_OK) {
LOG_ERROR("Error erase sector %d", i); LOG_ERROR("Error erase sector %u", i);
goto flash_lock; goto flash_lock;
} }
retval = stm32x_wait_flash_op_queue(bank, FLASH_ERASE_TIMEOUT); retval = stm32x_wait_flash_op_queue(bank, FLASH_ERASE_TIMEOUT);
if (retval != ERROR_OK) { if (retval != ERROR_OK) {
LOG_ERROR("erase time-out or operation error sector %d", i); LOG_ERROR("erase time-out or operation error sector %u", i);
goto flash_lock; goto flash_lock;
} }
bank->sectors[i].is_erased = 1; bank->sectors[i].is_erased = 1;
@ -503,7 +523,8 @@ flash_lock:
return (retval == ERROR_OK) ? retval2 : retval; return (retval == ERROR_OK) ? retval2 : retval;
} }
static int stm32x_protect(struct flash_bank *bank, int set, int first, int last) static int stm32x_protect(struct flash_bank *bank, int set, unsigned int first,
unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
uint32_t protection; uint32_t protection;
@ -520,7 +541,7 @@ static int stm32x_protect(struct flash_bank *bank, int set, int first, int last)
return retval; return retval;
} }
for (int i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
if (set) if (set)
protection &= ~(1 << i); protection &= ~(1 << i);
else else
@ -624,7 +645,7 @@ static int stm32x_write_block(struct flash_bank *bank, const uint8_t *buffer,
LOG_ERROR("flash memory write protected"); LOG_ERROR("flash memory write protected");
if ((flash_sr & FLASH_ERROR) != 0) { if ((flash_sr & FLASH_ERROR) != 0) {
LOG_ERROR("flash write failed, FLASH_SR = %08" PRIx32, flash_sr); LOG_ERROR("flash write failed, FLASH_SR = 0x%08" PRIx32, flash_sr);
/* Clear error + EOP flags but report errors */ /* Clear error + EOP flags but report errors */
stm32x_write_flash_reg(bank, FLASH_CCR, flash_sr); stm32x_write_flash_reg(bank, FLASH_CCR, flash_sr);
retval = ERROR_FAIL; retval = ERROR_FAIL;
@ -745,7 +766,7 @@ static int stm32x_probe(struct flash_bank *bank)
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
LOG_DEBUG("device id = 0x%08" PRIx32 "", stm32x_info->idcode); LOG_DEBUG("device id = 0x%08" PRIx32, stm32x_info->idcode);
device_id = stm32x_info->idcode & 0xfff; device_id = stm32x_info->idcode & 0xfff;
@ -766,7 +787,7 @@ static int stm32x_probe(struct flash_bank *bank)
else if (bank->base == FLASH_BANK1_ADDRESS) else if (bank->base == FLASH_BANK1_ADDRESS)
stm32x_info->flash_regs_base = FLASH_REG_BASE_B1; stm32x_info->flash_regs_base = FLASH_REG_BASE_B1;
else { else {
LOG_WARNING("Flash register base not defined for bank %d", bank->bank_number); LOG_WARNING("Flash register base not defined for bank %u", bank->bank_number);
return ERROR_FAIL; return ERROR_FAIL;
} }
LOG_DEBUG("flash_regs_base: 0x%" PRIx32, stm32x_info->flash_regs_base); LOG_DEBUG("flash_regs_base: 0x%" PRIx32, stm32x_info->flash_regs_base);
@ -777,7 +798,7 @@ static int stm32x_probe(struct flash_bank *bank)
/* read error when device has invalid value, set max flash size */ /* read error when device has invalid value, set max flash size */
flash_size_in_kb = stm32x_info->part_info->max_flash_size_kb; flash_size_in_kb = stm32x_info->part_info->max_flash_size_kb;
} else } else
LOG_INFO("flash size probed value %d", flash_size_in_kb); LOG_INFO("flash size probed value %" PRIu16, flash_size_in_kb);
@ -802,6 +823,8 @@ static int stm32x_probe(struct flash_bank *bank)
/* flash size is 2M or 1M */ /* flash size is 2M or 1M */
flash_size_in_kb /= 2; flash_size_in_kb /= 2;
break; break;
case 0x483:
break;
default: default:
LOG_ERROR("unsupported device"); LOG_ERROR("unsupported device");
return ERROR_FAIL; return ERROR_FAIL;
@ -828,8 +851,8 @@ static int stm32x_probe(struct flash_bank *bank)
} }
} }
LOG_INFO("Bank (%d) size is %d kb, base address is 0x%" PRIx32, LOG_INFO("Bank (%u) size is %" PRIu16 " kb, base address is " TARGET_ADDR_FMT,
bank->bank_number, flash_size_in_kb, (uint32_t) bank->base); bank->bank_number, flash_size_in_kb, bank->base);
/* if the user sets the size manually then ignore the probed value /* if the user sets the size manually then ignore the probed value
* this allows us to work around devices that have an invalid flash size register value */ * this allows us to work around devices that have an invalid flash size register value */
@ -851,8 +874,7 @@ static int stm32x_probe(struct flash_bank *bank)
bank->num_sectors = flash_size_in_kb / stm32x_info->part_info->page_size_kb; bank->num_sectors = flash_size_in_kb / stm32x_info->part_info->page_size_kb;
assert(bank->num_sectors > 0); assert(bank->num_sectors > 0);
if (bank->sectors) free(bank->sectors);
free(bank->sectors);
bank->sectors = alloc_block_array(0, stm32x_info->part_info->page_size_kb * 1024, bank->sectors = alloc_block_array(0, stm32x_info->part_info->page_size_kb * 1024,
bank->num_sectors); bank->num_sectors);
@ -869,8 +891,7 @@ static int stm32x_probe(struct flash_bank *bank)
bank->num_prot_blocks = bank->num_sectors / wpsn; bank->num_prot_blocks = bank->num_sectors / wpsn;
assert(bank->num_prot_blocks > 0); assert(bank->num_prot_blocks > 0);
if (bank->prot_blocks) free(bank->prot_blocks);
free(bank->prot_blocks);
bank->prot_blocks = alloc_block_array(0, stm32x_info->part_info->page_size_kb * wpsn * 1024, bank->prot_blocks = alloc_block_array(0, stm32x_info->part_info->page_size_kb * wpsn * 1024,
bank->num_prot_blocks); bank->num_prot_blocks);
@ -880,7 +901,7 @@ static int stm32x_probe(struct flash_bank *bank)
return ERROR_FAIL; return ERROR_FAIL;
} }
stm32x_info->probed = 1; stm32x_info->probed = true;
return ERROR_OK; return ERROR_OK;
} }
@ -921,7 +942,7 @@ static int stm32x_get_info(struct flash_bank *bank, char *buf, int buf_size)
stm32x_info->part_info->device_str, rev_str); stm32x_info->part_info->device_str, rev_str);
} else { } else {
snprintf(buf, buf_size, snprintf(buf, buf_size,
"%s - Rev: unknown (0x%04x)", "%s - Rev: unknown (0x%04" PRIx16 ")",
stm32x_info->part_info->device_str, rev_id); stm32x_info->part_info->device_str, rev_id);
} }
} else { } else {
@ -1068,7 +1089,7 @@ COMMAND_HANDLER(stm32x_handle_mass_erase_command)
retval = stm32x_mass_erase(bank); retval = stm32x_mass_erase(bank);
if (retval == ERROR_OK) { if (retval == ERROR_OK) {
/* set all sectors as erased */ /* set all sectors as erased */
for (int i = 0; i < bank->num_sectors; i++) for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 1; bank->sectors[i].is_erased = 1;
command_print(CMD, "stm32h7x mass erase complete"); command_print(CMD, "stm32h7x mass erase complete");
@ -1098,7 +1119,7 @@ COMMAND_HANDLER(stm32x_handle_option_read_command)
if (ERROR_OK != retval) if (ERROR_OK != retval)
return retval; return retval;
command_print(CMD, "Option Register: <0x%" PRIx32 "> = 0x%" PRIx32 "", command_print(CMD, "Option Register: <0x%" PRIx32 "> = 0x%" PRIx32,
stm32x_get_flash_reg(bank, reg_offset), value); stm32x_get_flash_reg(bank, reg_offset), value);
return retval; return retval;

View File

@ -129,7 +129,7 @@ struct stm32l4_part_info {
struct stm32l4_flash_bank { struct stm32l4_flash_bank {
bool probed; bool probed;
uint32_t idcode; uint32_t idcode;
int bank1_sectors; unsigned int bank1_sectors;
bool dual_bank_mode; bool dual_bank_mode;
int hole_sectors; int hole_sectors;
uint32_t user_bank_size; uint32_t user_bank_size;
@ -534,7 +534,7 @@ static int stm32l4_protect_check(struct flash_bank *bank)
stm32l4_read_flash_reg(bank, STM32_FLASH_WRP2AR, &wrp2ar); stm32l4_read_flash_reg(bank, STM32_FLASH_WRP2AR, &wrp2ar);
stm32l4_read_flash_reg(bank, STM32_FLASH_WRP2BR, &wrp2br); stm32l4_read_flash_reg(bank, STM32_FLASH_WRP2BR, &wrp2br);
} else { } else {
/* prevent unintialized errors */ /* prevent uninitialized errors */
wrp2ar = 0; wrp2ar = 0;
wrp2br = 0; wrp2br = 0;
} }
@ -548,7 +548,7 @@ static int stm32l4_protect_check(struct flash_bank *bank)
const uint8_t wrp2b_start = wrp2br & stm32l4_info->wrpxxr_mask; const uint8_t wrp2b_start = wrp2br & stm32l4_info->wrpxxr_mask;
const uint8_t wrp2b_end = (wrp2br >> 16) & stm32l4_info->wrpxxr_mask; const uint8_t wrp2b_end = (wrp2br >> 16) & stm32l4_info->wrpxxr_mask;
for (int i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
if (i < stm32l4_info->bank1_sectors) { if (i < stm32l4_info->bank1_sectors) {
if (((i >= wrp1a_start) && if (((i >= wrp1a_start) &&
(i <= wrp1a_end)) || (i <= wrp1a_end)) ||
@ -573,13 +573,13 @@ static int stm32l4_protect_check(struct flash_bank *bank)
return ERROR_OK; return ERROR_OK;
} }
static int stm32l4_erase(struct flash_bank *bank, int first, int last) static int stm32l4_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct stm32l4_flash_bank *stm32l4_info = bank->driver_priv; struct stm32l4_flash_bank *stm32l4_info = bank->driver_priv;
int i;
int retval, retval2; int retval, retval2;
assert((0 <= first) && (first <= last) && (last < bank->num_sectors)); assert((first <= last) && (last < bank->num_sectors));
if (bank->target->state != TARGET_HALTED) { if (bank->target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted"); LOG_ERROR("Target not halted");
@ -601,7 +601,7 @@ static int stm32l4_erase(struct flash_bank *bank, int first, int last)
4. Wait for the BSY bit to be cleared 4. Wait for the BSY bit to be cleared
*/ */
for (i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
uint32_t erase_flags; uint32_t erase_flags;
erase_flags = FLASH_PER | FLASH_STRT; erase_flags = FLASH_PER | FLASH_STRT;
@ -631,7 +631,8 @@ err_lock:
return retval2; return retval2;
} }
static int stm32l4_protect(struct flash_bank *bank, int set, int first, int last) static int stm32l4_protect(struct flash_bank *bank, int set, unsigned int first,
unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
struct stm32l4_flash_bank *stm32l4_info = bank->driver_priv; struct stm32l4_flash_bank *stm32l4_info = bank->driver_priv;
@ -1014,7 +1015,7 @@ static int stm32l4_probe(struct flash_bank *bank)
const int gap_size_kb = stm32l4_info->hole_sectors * page_size_kb; const int gap_size_kb = stm32l4_info->hole_sectors * page_size_kb;
if (gap_size_kb != 0) { if (gap_size_kb != 0) {
LOG_INFO("gap detected from 0x%08" PRIx32 " to 0x%08" PRIx32, LOG_INFO("gap detected from 0x%08x to 0x%08x",
STM32_FLASH_BANK_BASE + stm32l4_info->bank1_sectors STM32_FLASH_BANK_BASE + stm32l4_info->bank1_sectors
* page_size_kb * 1024, * page_size_kb * 1024,
STM32_FLASH_BANK_BASE + (stm32l4_info->bank1_sectors STM32_FLASH_BANK_BASE + (stm32l4_info->bank1_sectors
@ -1039,10 +1040,7 @@ static int stm32l4_probe(struct flash_bank *bank)
assert((stm32l4_info->wrpxxr_mask & 0xFFFF0000) == 0); assert((stm32l4_info->wrpxxr_mask & 0xFFFF0000) == 0);
LOG_DEBUG("WRPxxR mask 0x%04" PRIx16, (uint16_t)stm32l4_info->wrpxxr_mask); LOG_DEBUG("WRPxxR mask 0x%04" PRIx16, (uint16_t)stm32l4_info->wrpxxr_mask);
if (bank->sectors) { free(bank->sectors);
free(bank->sectors);
bank->sectors = NULL;
}
bank->size = (flash_size_kb + gap_size_kb) * 1024; bank->size = (flash_size_kb + gap_size_kb) * 1024;
bank->base = STM32_FLASH_BANK_BASE; bank->base = STM32_FLASH_BANK_BASE;
@ -1053,7 +1051,7 @@ static int stm32l4_probe(struct flash_bank *bank)
return ERROR_FAIL; return ERROR_FAIL;
} }
for (int i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
bank->sectors[i].offset = i * page_size_kb * 1024; bank->sectors[i].offset = i * page_size_kb * 1024;
/* in dual bank configuration, if there is a gap between banks /* in dual bank configuration, if there is a gap between banks
* we fix up the sector offset to consider this gap */ * we fix up the sector offset to consider this gap */
@ -1169,7 +1167,7 @@ COMMAND_HANDLER(stm32l4_handle_mass_erase_command)
retval = stm32l4_mass_erase(bank); retval = stm32l4_mass_erase(bank);
if (retval == ERROR_OK) { if (retval == ERROR_OK) {
/* set all sectors as erased */ /* set all sectors as erased */
for (int i = 0; i < bank->num_sectors; i++) for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 1; bank->sectors[i].is_erased = 1;
command_print(CMD, "stm32l4x mass erase complete"); command_print(CMD, "stm32l4x mass erase complete");

View File

@ -319,7 +319,7 @@ COMMAND_HANDLER(stm32lx_handle_mass_erase_command)
retval = stm32lx_mass_erase(bank); retval = stm32lx_mass_erase(bank);
if (retval == ERROR_OK) { if (retval == ERROR_OK) {
/* set all sectors as erased */ /* set all sectors as erased */
for (int i = 0; i < bank->num_sectors; i++) for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_erased = 1; bank->sectors[i].is_erased = 1;
command_print(CMD, "stm32lx mass erase complete"); command_print(CMD, "stm32lx mass erase complete");
@ -387,7 +387,7 @@ static int stm32lx_protect_check(struct flash_bank *bank)
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
for (int i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
if (wrpr & (1 << i)) if (wrpr & (1 << i))
bank->sectors[i].is_protected = 1; bank->sectors[i].is_protected = 1;
else else
@ -396,7 +396,8 @@ static int stm32lx_protect_check(struct flash_bank *bank)
return ERROR_OK; return ERROR_OK;
} }
static int stm32lx_erase(struct flash_bank *bank, int first, int last) static int stm32lx_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
int retval; int retval;
@ -413,7 +414,7 @@ static int stm32lx_erase(struct flash_bank *bank, int first, int last)
/* /*
* Loop over the selected sectors and erase them * Loop over the selected sectors and erase them
*/ */
for (int i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
retval = stm32lx_erase_sector(bank, i); retval = stm32lx_erase_sector(bank, i);
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
@ -445,7 +446,7 @@ static int stm32lx_write_half_pages(struct flash_bank *bank, const uint8_t *buff
/* Make sure we're performing a half-page aligned write. */ /* Make sure we're performing a half-page aligned write. */
if (count % hp_nb) { if (count % hp_nb) {
LOG_ERROR("The byte count must be %" PRIu32 "B-aligned but count is %" PRIi32 "B)", hp_nb, count); LOG_ERROR("The byte count must be %" PRIu32 "B-aligned but count is %" PRIu32 "B)", hp_nb, count);
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -628,7 +629,7 @@ static int stm32lx_write(struct flash_bank *bank, const uint8_t *buffer,
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
/* first we need to write any unaligned head bytes upto /* first we need to write any unaligned head bytes up to
* the next 128 byte page */ * the next 128 byte page */
if (offset % hp_nb) if (offset % hp_nb)
@ -819,7 +820,7 @@ static int stm32lx_probe(struct flash_bank *bank)
bank->base, base_address, second_bank_base); bank->base, base_address, second_bank_base);
return ERROR_FAIL; return ERROR_FAIL;
} }
LOG_INFO("STM32L flash has dual banks. Bank (%d) size is %dkb, base address is 0x%" PRIx32, LOG_INFO("STM32L flash has dual banks. Bank (%u) size is %dkb, base address is 0x%" PRIx32,
bank->bank_number, flash_size_in_kb, base_address); bank->bank_number, flash_size_in_kb, base_address);
} else { } else {
LOG_INFO("STM32L flash size is %dkb, base address is 0x%" PRIx32, flash_size_in_kb, base_address); LOG_INFO("STM32L flash size is %dkb, base address is 0x%" PRIx32, flash_size_in_kb, base_address);
@ -833,12 +834,9 @@ static int stm32lx_probe(struct flash_bank *bank)
} }
/* calculate numbers of sectors (4kB per sector) */ /* calculate numbers of sectors (4kB per sector) */
int num_sectors = (flash_size_in_kb * 1024) / FLASH_SECTOR_SIZE; unsigned int num_sectors = (flash_size_in_kb * 1024) / FLASH_SECTOR_SIZE;
if (bank->sectors) { free(bank->sectors);
free(bank->sectors);
bank->sectors = NULL;
}
bank->size = flash_size_in_kb * 1024; bank->size = flash_size_in_kb * 1024;
bank->base = base_address; bank->base = base_address;
@ -849,7 +847,7 @@ static int stm32lx_probe(struct flash_bank *bank)
return ERROR_FAIL; return ERROR_FAIL;
} }
for (int i = 0; i < num_sectors; i++) { for (unsigned int i = 0; i < num_sectors; i++) {
bank->sectors[i].offset = i * FLASH_SECTOR_SIZE; bank->sectors[i].offset = i * FLASH_SECTOR_SIZE;
bank->sectors[i].size = FLASH_SECTOR_SIZE; bank->sectors[i].size = FLASH_SECTOR_SIZE;
bank->sectors[i].is_erased = -1; bank->sectors[i].is_erased = -1;

View File

@ -115,7 +115,7 @@
#define SMI_MAX_TIMEOUT (3000) #define SMI_MAX_TIMEOUT (3000)
struct stmsmi_flash_bank { struct stmsmi_flash_bank {
int probed; bool probed;
uint32_t io_base; uint32_t io_base;
uint32_t bank_num; uint32_t bank_num;
const struct flash_device *dev; const struct flash_device *dev;
@ -151,7 +151,7 @@ FLASH_BANK_COMMAND_HANDLER(stmsmi_flash_bank_command)
} }
bank->driver_priv = stmsmi_info; bank->driver_priv = stmsmi_info;
stmsmi_info->probed = 0; stmsmi_info->probed = false;
return ERROR_OK; return ERROR_OK;
} }
@ -313,22 +313,22 @@ static int smi_erase_sector(struct flash_bank *bank, int sector)
return ERROR_OK; return ERROR_OK;
} }
static int stmsmi_erase(struct flash_bank *bank, int first, int last) static int stmsmi_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
struct stmsmi_flash_bank *stmsmi_info = bank->driver_priv; struct stmsmi_flash_bank *stmsmi_info = bank->driver_priv;
uint32_t io_base = stmsmi_info->io_base; uint32_t io_base = stmsmi_info->io_base;
int retval = ERROR_OK; int retval = ERROR_OK;
int sector;
LOG_DEBUG("%s: from sector %d to sector %d", __func__, first, last); LOG_DEBUG("%s: from sector %u to sector %u", __func__, first, last);
if (target->state != TARGET_HALTED) { if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted"); LOG_ERROR("Target not halted");
return ERROR_TARGET_NOT_HALTED; return ERROR_TARGET_NOT_HALTED;
} }
if ((first < 0) || (last < first) || (last >= bank->num_sectors)) { if ((last < first) || (last >= bank->num_sectors)) {
LOG_ERROR("Flash sector invalid"); LOG_ERROR("Flash sector invalid");
return ERROR_FLASH_SECTOR_INVALID; return ERROR_FLASH_SECTOR_INVALID;
} }
@ -338,9 +338,9 @@ static int stmsmi_erase(struct flash_bank *bank, int first, int last)
return ERROR_FLASH_BANK_NOT_PROBED; return ERROR_FLASH_BANK_NOT_PROBED;
} }
for (sector = first; sector <= last; sector++) { for (unsigned int sector = first; sector <= last; sector++) {
if (bank->sectors[sector].is_protected) { if (bank->sectors[sector].is_protected) {
LOG_ERROR("Flash sector %d protected", sector); LOG_ERROR("Flash sector %u protected", sector);
return ERROR_FAIL; return ERROR_FAIL;
} }
} }
@ -348,7 +348,7 @@ static int stmsmi_erase(struct flash_bank *bank, int first, int last)
if (stmsmi_info->dev->erase_cmd == 0x00) if (stmsmi_info->dev->erase_cmd == 0x00)
return ERROR_FLASH_OPER_UNSUPPORTED; return ERROR_FLASH_OPER_UNSUPPORTED;
for (sector = first; sector <= last; sector++) { for (unsigned int sector = first; sector <= last; sector++) {
retval = smi_erase_sector(bank, sector); retval = smi_erase_sector(bank, sector);
if (retval != ERROR_OK) if (retval != ERROR_OK)
break; break;
@ -361,11 +361,9 @@ static int stmsmi_erase(struct flash_bank *bank, int first, int last)
} }
static int stmsmi_protect(struct flash_bank *bank, int set, static int stmsmi_protect(struct flash_bank *bank, int set,
int first, int last) unsigned int first, unsigned int last)
{ {
int sector; for (unsigned int sector = first; sector <= last; sector++)
for (sector = first; sector <= last; sector++)
bank->sectors[sector].is_protected = set; bank->sectors[sector].is_protected = set;
return ERROR_OK; return ERROR_OK;
} }
@ -402,7 +400,6 @@ static int stmsmi_write(struct flash_bank *bank, const uint8_t *buffer,
struct stmsmi_flash_bank *stmsmi_info = bank->driver_priv; struct stmsmi_flash_bank *stmsmi_info = bank->driver_priv;
uint32_t io_base = stmsmi_info->io_base; uint32_t io_base = stmsmi_info->io_base;
uint32_t cur_count, page_size, page_offset; uint32_t cur_count, page_size, page_offset;
int sector;
int retval = ERROR_OK; int retval = ERROR_OK;
LOG_DEBUG("%s: offset=0x%08" PRIx32 " count=0x%08" PRIx32, LOG_DEBUG("%s: offset=0x%08" PRIx32 " count=0x%08" PRIx32,
@ -419,14 +416,14 @@ static int stmsmi_write(struct flash_bank *bank, const uint8_t *buffer,
} }
/* Check sector protection */ /* Check sector protection */
for (sector = 0; sector < bank->num_sectors; sector++) { for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
/* Start offset in or before this sector? */ /* Start offset in or before this sector? */
/* End offset in or behind this sector? */ /* End offset in or behind this sector? */
if ((offset < if ((offset <
(bank->sectors[sector].offset + bank->sectors[sector].size)) (bank->sectors[sector].offset + bank->sectors[sector].size))
&& ((offset + count - 1) >= bank->sectors[sector].offset) && ((offset + count - 1) >= bank->sectors[sector].offset)
&& bank->sectors[sector].is_protected) { && bank->sectors[sector].is_protected) {
LOG_ERROR("Flash sector %d protected", sector); LOG_ERROR("Flash sector %u protected", sector);
return ERROR_FAIL; return ERROR_FAIL;
} }
} }
@ -534,7 +531,7 @@ static int stmsmi_probe(struct flash_bank *bank)
if (stmsmi_info->probed) if (stmsmi_info->probed)
free(bank->sectors); free(bank->sectors);
stmsmi_info->probed = 0; stmsmi_info->probed = false;
for (target_device = target_devices ; target_device->name ; ++target_device) for (target_device = target_devices ; target_device->name ; ++target_device)
if (target_device->tap_idcode == target->tap->idcode) if (target_device->tap_idcode == target->tap->idcode)
@ -609,7 +606,7 @@ static int stmsmi_probe(struct flash_bank *bank)
return ERROR_FAIL; return ERROR_FAIL;
} }
for (int sector = 0; sector < bank->num_sectors; sector++) { for (unsigned int sector = 0; sector < bank->num_sectors; sector++) {
sectors[sector].offset = sector * sectorsize; sectors[sector].offset = sector * sectorsize;
sectors[sector].size = sectorsize; sectors[sector].size = sectorsize;
sectors[sector].is_erased = -1; sectors[sector].is_erased = -1;
@ -617,7 +614,7 @@ static int stmsmi_probe(struct flash_bank *bank)
} }
bank->sectors = sectors; bank->sectors = sectors;
stmsmi_info->probed = 1; stmsmi_info->probed = true;
return ERROR_OK; return ERROR_OK;
} }

View File

@ -138,7 +138,7 @@ static int str7x_build_block_list(struct flash_bank *bank)
struct str7x_flash_bank *str7x_info = bank->driver_priv; struct str7x_flash_bank *str7x_info = bank->driver_priv;
int i; int i;
int num_sectors; unsigned int num_sectors;
int b0_sectors = 0, b1_sectors = 0; int b0_sectors = 0, b1_sectors = 0;
switch (bank->size) { switch (bank->size) {
@ -306,7 +306,6 @@ static int str7x_protect_check(struct flash_bank *bank)
struct str7x_flash_bank *str7x_info = bank->driver_priv; struct str7x_flash_bank *str7x_info = bank->driver_priv;
struct target *target = bank->target; struct target *target = bank->target;
int i;
uint32_t flash_flags; uint32_t flash_flags;
if (bank->target->state != TARGET_HALTED) { if (bank->target->state != TARGET_HALTED) {
@ -319,7 +318,7 @@ static int str7x_protect_check(struct flash_bank *bank)
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
for (i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
if (flash_flags & str7x_info->sector_bits[i]) if (flash_flags & str7x_info->sector_bits[i])
bank->sectors[i].is_protected = 0; bank->sectors[i].is_protected = 0;
else else
@ -329,12 +328,12 @@ static int str7x_protect_check(struct flash_bank *bank)
return ERROR_OK; return ERROR_OK;
} }
static int str7x_erase(struct flash_bank *bank, int first, int last) static int str7x_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct str7x_flash_bank *str7x_info = bank->driver_priv; struct str7x_flash_bank *str7x_info = bank->driver_priv;
struct target *target = bank->target; struct target *target = bank->target;
int i;
uint32_t cmd; uint32_t cmd;
uint32_t sectors = 0; uint32_t sectors = 0;
int err; int err;
@ -344,7 +343,7 @@ static int str7x_erase(struct flash_bank *bank, int first, int last)
return ERROR_TARGET_NOT_HALTED; return ERROR_TARGET_NOT_HALTED;
} }
for (i = first; i <= last; i++) for (unsigned int i = first; i <= last; i++)
sectors |= str7x_info->sector_bits[i]; sectors |= str7x_info->sector_bits[i];
LOG_DEBUG("sectors: 0x%" PRIx32 "", sectors); LOG_DEBUG("sectors: 0x%" PRIx32 "", sectors);
@ -377,17 +376,17 @@ static int str7x_erase(struct flash_bank *bank, int first, int last)
if (err != ERROR_OK) if (err != ERROR_OK)
return err; return err;
for (i = first; i <= last; i++) for (unsigned int i = first; i <= last; i++)
bank->sectors[i].is_erased = 1; bank->sectors[i].is_erased = 1;
return ERROR_OK; return ERROR_OK;
} }
static int str7x_protect(struct flash_bank *bank, int set, int first, int last) static int str7x_protect(struct flash_bank *bank, int set, unsigned int first,
unsigned int last)
{ {
struct str7x_flash_bank *str7x_info = bank->driver_priv; struct str7x_flash_bank *str7x_info = bank->driver_priv;
struct target *target = bank->target; struct target *target = bank->target;
int i;
uint32_t cmd; uint32_t cmd;
uint32_t protect_blocks; uint32_t protect_blocks;
@ -399,7 +398,7 @@ static int str7x_protect(struct flash_bank *bank, int set, int first, int last)
protect_blocks = 0xFFFFFFFF; protect_blocks = 0xFFFFFFFF;
if (set) { if (set) {
for (i = first; i <= last; i++) for (unsigned int i = first; i <= last; i++)
protect_blocks &= ~(str7x_info->sector_bits[i]); protect_blocks &= ~(str7x_info->sector_bits[i]);
} }
@ -453,7 +452,7 @@ static int str7x_write_block(struct flash_bank *bank, const uint8_t *buffer,
struct arm_algorithm arm_algo; struct arm_algorithm arm_algo;
int retval = ERROR_OK; int retval = ERROR_OK;
/* see contib/loaders/flash/str7x.s for src */ /* see contrib/loaders/flash/str7x.s for src */
static const uint32_t str7x_flash_write_code[] = { static const uint32_t str7x_flash_write_code[] = {
/* write: */ /* write: */
@ -568,7 +567,6 @@ static int str7x_write(struct flash_bank *bank, const uint8_t *buffer,
uint32_t cmd; uint32_t cmd;
int retval; int retval;
uint32_t check_address = offset; uint32_t check_address = offset;
int i;
if (bank->target->state != TARGET_HALTED) { if (bank->target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted"); LOG_ERROR("Target not halted");
@ -580,7 +578,7 @@ static int str7x_write(struct flash_bank *bank, const uint8_t *buffer,
return ERROR_FLASH_DST_BREAKS_ALIGNMENT; return ERROR_FLASH_DST_BREAKS_ALIGNMENT;
} }
for (i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
uint32_t sec_start = bank->sectors[i].offset; uint32_t sec_start = bank->sectors[i].offset;
uint32_t sec_end = sec_start + bank->sectors[i].size; uint32_t sec_end = sec_start + bank->sectors[i].size;

View File

@ -68,7 +68,7 @@ static int str9x_build_block_list(struct flash_bank *bank)
struct str9x_flash_bank *str9x_info = bank->driver_priv; struct str9x_flash_bank *str9x_info = bank->driver_priv;
int i; int i;
int num_sectors; unsigned int num_sectors;
int b0_sectors = 0, b1_sectors = 0; int b0_sectors = 0, b1_sectors = 0;
uint32_t offset = 0; uint32_t offset = 0;
@ -164,7 +164,6 @@ static int str9x_protect_check(struct flash_bank *bank)
struct str9x_flash_bank *str9x_info = bank->driver_priv; struct str9x_flash_bank *str9x_info = bank->driver_priv;
struct target *target = bank->target; struct target *target = bank->target;
int i;
uint32_t adr; uint32_t adr;
uint32_t status = 0; uint32_t status = 0;
uint16_t hstatus = 0; uint16_t hstatus = 0;
@ -211,7 +210,7 @@ static int str9x_protect_check(struct flash_bank *bank)
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
for (i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
if (status & str9x_info->sector_bits[i]) if (status & str9x_info->sector_bits[i])
bank->sectors[i].is_protected = 1; bank->sectors[i].is_protected = 1;
else else
@ -221,10 +220,10 @@ static int str9x_protect_check(struct flash_bank *bank)
return ERROR_OK; return ERROR_OK;
} }
static int str9x_erase(struct flash_bank *bank, int first, int last) static int str9x_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
int i;
uint32_t adr; uint32_t adr;
uint8_t status; uint8_t status;
uint8_t erase_cmd; uint8_t erase_cmd;
@ -250,7 +249,7 @@ static int str9x_erase(struct flash_bank *bank, int first, int last)
/* this is so the compiler can *know* */ /* this is so the compiler can *know* */
assert(total_timeout > 0); assert(total_timeout > 0);
for (i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
int retval; int retval;
adr = bank->base + bank->sectors[i].offset; adr = bank->base + bank->sectors[i].offset;
@ -301,17 +300,16 @@ static int str9x_erase(struct flash_bank *bank, int first, int last)
break; break;
} }
for (i = first; i <= last; i++) for (unsigned int i = first; i <= last; i++)
bank->sectors[i].is_erased = 1; bank->sectors[i].is_erased = 1;
return ERROR_OK; return ERROR_OK;
} }
static int str9x_protect(struct flash_bank *bank, static int str9x_protect(struct flash_bank *bank, int set, unsigned int first,
int set, int first, int last) unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
int i;
uint32_t adr; uint32_t adr;
uint8_t status; uint8_t status;
@ -320,7 +318,7 @@ static int str9x_protect(struct flash_bank *bank,
return ERROR_TARGET_NOT_HALTED; return ERROR_TARGET_NOT_HALTED;
} }
for (i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
/* Level One Protection */ /* Level One Protection */
adr = bank->base + bank->sectors[i].offset; adr = bank->base + bank->sectors[i].offset;
@ -356,7 +354,7 @@ static int str9x_write_block(struct flash_bank *bank,
struct arm_algorithm arm_algo; struct arm_algorithm arm_algo;
int retval = ERROR_OK; int retval = ERROR_OK;
/* see contib/loaders/flash/str9x.s for src */ /* see contrib/loaders/flash/str9x.s for src */
static const uint32_t str9x_flash_write_code[] = { static const uint32_t str9x_flash_write_code[] = {
/* write: */ /* write: */
@ -468,7 +466,6 @@ static int str9x_write(struct flash_bank *bank,
int retval; int retval;
uint32_t check_address = offset; uint32_t check_address = offset;
uint32_t bank_adr; uint32_t bank_adr;
int i;
if (bank->target->state != TARGET_HALTED) { if (bank->target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted"); LOG_ERROR("Target not halted");
@ -480,7 +477,7 @@ static int str9x_write(struct flash_bank *bank,
return ERROR_FLASH_DST_BREAKS_ALIGNMENT; return ERROR_FLASH_DST_BREAKS_ALIGNMENT;
} }
for (i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
uint32_t sec_start = bank->sectors[i].offset; uint32_t sec_start = bank->sectors[i].offset;
uint32_t sec_end = sec_start + bank->sectors[i].size; uint32_t sec_end = sec_start + bank->sectors[i].size;

View File

@ -74,7 +74,8 @@ struct str9xpec_flash_controller {
uint8_t options[8]; uint8_t options[8];
}; };
static int str9xpec_erase_area(struct flash_bank *bank, int first, int last); static int str9xpec_erase_area(struct flash_bank *bank, unsigned int first,
unsigned int last);
static int str9xpec_set_address(struct flash_bank *bank, uint8_t sector); static int str9xpec_set_address(struct flash_bank *bank, uint8_t sector);
static int str9xpec_write_options(struct flash_bank *bank); static int str9xpec_write_options(struct flash_bank *bank);
@ -210,7 +211,7 @@ static int str9xpec_build_block_list(struct flash_bank *bank)
struct str9xpec_flash_controller *str9xpec_info = bank->driver_priv; struct str9xpec_flash_controller *str9xpec_info = bank->driver_priv;
int i; int i;
int num_sectors; unsigned int num_sectors;
int b0_sectors = 0, b1_sectors = 0; int b0_sectors = 0, b1_sectors = 0;
uint32_t offset = 0; uint32_t offset = 0;
int b1_size = 0x2000; int b1_size = 0x2000;
@ -303,12 +304,12 @@ FLASH_BANK_COMMAND_HANDLER(str9xpec_flash_bank_command)
return ERROR_OK; return ERROR_OK;
} }
static int str9xpec_blank_check(struct flash_bank *bank, int first, int last) static int str9xpec_blank_check(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct scan_field field; struct scan_field field;
uint8_t status; uint8_t status;
struct jtag_tap *tap; struct jtag_tap *tap;
int i;
uint8_t *buffer = NULL; uint8_t *buffer = NULL;
struct str9xpec_flash_controller *str9xpec_info = bank->driver_priv; struct str9xpec_flash_controller *str9xpec_info = bank->driver_priv;
@ -323,9 +324,9 @@ static int str9xpec_blank_check(struct flash_bank *bank, int first, int last)
buffer = calloc(DIV_ROUND_UP(64, 8), 1); buffer = calloc(DIV_ROUND_UP(64, 8), 1);
LOG_DEBUG("blank check: first_bank: %i, last_bank: %i", first, last); LOG_DEBUG("blank check: first_bank: %u, last_bank: %u", first, last);
for (i = first; i <= last; i++) for (unsigned int i = first; i <= last; i++)
buf_set_u32(buffer, str9xpec_info->sector_bits[i], 1, 1); buf_set_u32(buffer, str9xpec_info->sector_bits[i], 1, 1);
/* execute ISC_BLANK_CHECK command */ /* execute ISC_BLANK_CHECK command */
@ -348,7 +349,7 @@ static int str9xpec_blank_check(struct flash_bank *bank, int first, int last)
status = str9xpec_isc_status(tap); status = str9xpec_isc_status(tap);
for (i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
if (buf_get_u32(buffer, str9xpec_info->sector_bits[i], 1)) if (buf_get_u32(buffer, str9xpec_info->sector_bits[i], 1))
bank->sectors[i].is_erased = 0; bank->sectors[i].is_erased = 0;
else else
@ -367,13 +368,12 @@ static int str9xpec_blank_check(struct flash_bank *bank, int first, int last)
static int str9xpec_protect_check(struct flash_bank *bank) static int str9xpec_protect_check(struct flash_bank *bank)
{ {
uint8_t status; uint8_t status;
int i;
struct str9xpec_flash_controller *str9xpec_info = bank->driver_priv; struct str9xpec_flash_controller *str9xpec_info = bank->driver_priv;
status = str9xpec_read_config(bank); status = str9xpec_read_config(bank);
for (i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
if (buf_get_u32(str9xpec_info->options, str9xpec_info->sector_bits[i], 1)) if (buf_get_u32(str9xpec_info->options, str9xpec_info->sector_bits[i], 1))
bank->sectors[i].is_protected = 1; bank->sectors[i].is_protected = 1;
else else
@ -385,12 +385,12 @@ static int str9xpec_protect_check(struct flash_bank *bank)
return ERROR_OK; return ERROR_OK;
} }
static int str9xpec_erase_area(struct flash_bank *bank, int first, int last) static int str9xpec_erase_area(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct scan_field field; struct scan_field field;
uint8_t status; uint8_t status;
struct jtag_tap *tap; struct jtag_tap *tap;
int i;
uint8_t *buffer = NULL; uint8_t *buffer = NULL;
struct str9xpec_flash_controller *str9xpec_info = bank->driver_priv; struct str9xpec_flash_controller *str9xpec_info = bank->driver_priv;
@ -405,17 +405,17 @@ static int str9xpec_erase_area(struct flash_bank *bank, int first, int last)
buffer = calloc(DIV_ROUND_UP(64, 8), 1); buffer = calloc(DIV_ROUND_UP(64, 8), 1);
LOG_DEBUG("erase: first_bank: %i, last_bank: %i", first, last); LOG_DEBUG("erase: first_bank: %u, last_bank: %u", first, last);
/* last bank: 0xFF signals a full erase (unlock complete device) */ /* last bank: 0xFF signals a full erase (unlock complete device) */
/* last bank: 0xFE signals a option byte erase */ /* last bank: 0xFE signals a option byte erase */
if (last == 0xFF) { if (last == 0xFF) {
for (i = 0; i < 64; i++) for (unsigned int i = 0; i < 64; i++)
buf_set_u32(buffer, i, 1, 1); buf_set_u32(buffer, i, 1, 1);
} else if (last == 0xFE) } else if (last == 0xFE)
buf_set_u32(buffer, 49, 1, 1); buf_set_u32(buffer, 49, 1, 1);
else { else {
for (i = first; i <= last; i++) for (unsigned int i = first; i <= last; i++)
buf_set_u32(buffer, str9xpec_info->sector_bits[i], 1, 1); buf_set_u32(buffer, str9xpec_info->sector_bits[i], 1, 1);
} }
@ -444,7 +444,8 @@ static int str9xpec_erase_area(struct flash_bank *bank, int first, int last)
return status; return status;
} }
static int str9xpec_erase(struct flash_bank *bank, int first, int last) static int str9xpec_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
int status; int status;
@ -504,10 +505,10 @@ static int str9xpec_unlock_device(struct flash_bank *bank)
return status; return status;
} }
static int str9xpec_protect(struct flash_bank *bank, int set, int first, int last) static int str9xpec_protect(struct flash_bank *bank, int set,
unsigned int first, unsigned int last)
{ {
uint8_t status; uint8_t status;
int i;
struct str9xpec_flash_controller *str9xpec_info = bank->driver_priv; struct str9xpec_flash_controller *str9xpec_info = bank->driver_priv;
@ -516,7 +517,7 @@ static int str9xpec_protect(struct flash_bank *bank, int set, int first, int las
if ((status & ISC_STATUS_ERROR) != STR9XPEC_ISC_SUCCESS) if ((status & ISC_STATUS_ERROR) != STR9XPEC_ISC_SUCCESS)
return ERROR_FLASH_OPERATION_FAILED; return ERROR_FLASH_OPERATION_FAILED;
LOG_DEBUG("protect: first_bank: %i, last_bank: %i", first, last); LOG_DEBUG("protect: first_bank: %u, last_bank: %u", first, last);
/* last bank: 0xFF signals a full device protect */ /* last bank: 0xFF signals a full device protect */
if (last == 0xFF) { if (last == 0xFF) {
@ -527,7 +528,7 @@ static int str9xpec_protect(struct flash_bank *bank, int set, int first, int las
status = str9xpec_unlock_device(bank); status = str9xpec_unlock_device(bank);
} }
} else { } else {
for (i = first; i <= last; i++) { for (unsigned int i = first; i <= last; i++) {
if (set) if (set)
buf_set_u32(str9xpec_info->options, str9xpec_info->sector_bits[i], 1, 1); buf_set_u32(str9xpec_info->options, str9xpec_info->sector_bits[i], 1, 1);
else else
@ -575,9 +576,8 @@ static int str9xpec_write(struct flash_bank *bank, const uint8_t *buffer,
struct jtag_tap *tap; struct jtag_tap *tap;
struct scan_field field; struct scan_field field;
uint8_t *scanbuf; uint8_t *scanbuf;
int i; unsigned int first_sector = 0;
int first_sector = 0; unsigned int last_sector = 0;
int last_sector = 0;
tap = str9xpec_info->tap; tap = str9xpec_info->tap;
@ -592,7 +592,7 @@ static int str9xpec_write(struct flash_bank *bank, const uint8_t *buffer,
return ERROR_FLASH_DST_BREAKS_ALIGNMENT; return ERROR_FLASH_DST_BREAKS_ALIGNMENT;
} }
for (i = 0; i < bank->num_sectors; i++) { for (unsigned int i = 0; i < bank->num_sectors; i++) {
uint32_t sec_start = bank->sectors[i].offset; uint32_t sec_start = bank->sectors[i].offset;
uint32_t sec_end = sec_start + bank->sectors[i].size; uint32_t sec_end = sec_start + bank->sectors[i].size;
@ -621,7 +621,7 @@ static int str9xpec_write(struct flash_bank *bank, const uint8_t *buffer,
LOG_DEBUG("ISC_PROGRAM"); LOG_DEBUG("ISC_PROGRAM");
for (i = first_sector; i <= last_sector; i++) { for (unsigned int i = first_sector; i <= last_sector; i++) {
str9xpec_set_address(bank, str9xpec_info->sector_bits[i]); str9xpec_set_address(bank, str9xpec_info->sector_bits[i]);
dwords_remaining = dwords_remaining < (bank->sectors[i].size/8) dwords_remaining = dwords_remaining < (bank->sectors[i].size/8)

View File

@ -38,11 +38,11 @@
#define SWM050_SYSCTL_CFG_0 0x400F0000 #define SWM050_SYSCTL_CFG_0 0x400F0000
#define SWM050_SYSCTL_DBLF 0x400F0008 #define SWM050_SYSCTL_DBLF 0x400F0008
static int swm050_erase(struct flash_bank *bank, int first, int last) static int swm050_erase(struct flash_bank *bank, unsigned int first,
unsigned int last)
{ {
struct target *target = bank->target; struct target *target = bank->target;
int retval, curr_page; int retval;
uint32_t curr_addr;
if (target->state != TARGET_HALTED) { if (target->state != TARGET_HALTED) {
LOG_ERROR("Target not halted"); LOG_ERROR("Target not halted");
@ -54,8 +54,8 @@ static int swm050_erase(struct flash_bank *bank, int first, int last)
if (retval != ERROR_OK) if (retval != ERROR_OK)
return retval; return retval;
for (curr_page = first; curr_page <= last; curr_page++) { for (unsigned int curr_page = first; curr_page <= last; curr_page++) {
curr_addr = bank->base + (SWM050_FLASH_PAGE_SIZE * curr_page); uint32_t curr_addr = bank->base + (SWM050_FLASH_PAGE_SIZE * curr_page);
/* Perform write */ /* Perform write */
retval = target_write_u32(target, curr_addr, SWM050_FLASH_KEY); retval = target_write_u32(target, curr_addr, SWM050_FLASH_KEY);
if (retval != ERROR_OK) if (retval != ERROR_OK)
@ -156,10 +156,7 @@ COMMAND_HANDLER(swm050_handle_mass_erase_command)
FLASH_BANK_COMMAND_HANDLER(swm050_flash_bank_command) FLASH_BANK_COMMAND_HANDLER(swm050_flash_bank_command)
{ {
if (bank->sectors) { free(bank->sectors);
free(bank->sectors);
bank->sectors = NULL;
}
bank->write_start_alignment = 4; bank->write_start_alignment = 4;
bank->write_end_alignment = 4; bank->write_end_alignment = 4;
bank->size = SWM050_FLASH_PAGE_SIZE * SWM050_FLASH_PAGES; bank->size = SWM050_FLASH_PAGE_SIZE * SWM050_FLASH_PAGES;
@ -169,7 +166,7 @@ FLASH_BANK_COMMAND_HANDLER(swm050_flash_bank_command)
if (!bank->sectors) if (!bank->sectors)
return ERROR_FAIL; return ERROR_FAIL;
for (int i = 0; i < bank->num_sectors; i++) for (unsigned int i = 0; i < bank->num_sectors; i++)
bank->sectors[i].is_protected = 0; bank->sectors[i].is_protected = 0;
return ERROR_OK; return ERROR_OK;

View File

@ -112,8 +112,8 @@ COMMAND_HANDLER(handle_flash_info_command)
LOG_INFO("Flash protection check is not implemented."); LOG_INFO("Flash protection check is not implemented.");
command_print(CMD, command_print(CMD,
"#%d : %s at " TARGET_ADDR_FMT ", size 0x%8.8" PRIx32 "#%u : %s at " TARGET_ADDR_FMT ", size 0x%8.8" PRIx32
", buswidth %i, chipwidth %i", ", buswidth %u, chipwidth %u",
p->bank_number, p->bank_number,
p->driver->name, p->driver->name,
p->base, p->base,
@ -141,7 +141,7 @@ COMMAND_HANDLER(handle_flash_info_command)
protect_state = "protection state unknown"; protect_state = "protection state unknown";
command_print(CMD, command_print(CMD,
"\t#%3i: 0x%8.8" PRIx32 " (0x%" PRIx32 " %" PRIi32 "kB) %s", "\t#%3i: 0x%8.8" PRIx32 " (0x%" PRIx32 " %" PRIu32 "kB) %s",
j, j,
block_array[j].offset, block_array[j].offset,
block_array[j].size, block_array[j].size,
@ -199,7 +199,6 @@ COMMAND_HANDLER(handle_flash_erase_check_command)
if (ERROR_OK != retval) if (ERROR_OK != retval)
return retval; return retval;
int j;
retval = p->driver->erase_check(p); retval = p->driver->erase_check(p);
if (retval == ERROR_OK) if (retval == ERROR_OK)
command_print(CMD, "successfully checked erase state"); command_print(CMD, "successfully checked erase state");
@ -211,7 +210,7 @@ COMMAND_HANDLER(handle_flash_erase_check_command)
p->base); p->base);
} }
for (j = 0; j < p->num_sectors; j++) { for (unsigned int j = 0; j < p->num_sectors; j++) {
char *erase_state; char *erase_state;
if (p->sectors[j].is_erased == 0) if (p->sectors[j].is_erased == 0)
@ -223,7 +222,7 @@ COMMAND_HANDLER(handle_flash_erase_check_command)
blank = false; blank = false;
command_print(CMD, command_print(CMD,
"\t#%3i: 0x%8.8" PRIx32 " (0x%" PRIx32 " %" PRIi32 "kB) %s", "\t#%3i: 0x%8.8" PRIx32 " (0x%" PRIx32 " %" PRIu32 "kB) %s",
j, j,
p->sectors[j].offset, p->sectors[j].offset,
p->sectors[j].size, p->sectors[j].size,
@ -289,8 +288,7 @@ COMMAND_HANDLER(handle_flash_erase_address_command)
retval = flash_erase_address_range(target, do_pad, address, length); retval = flash_erase_address_range(target, do_pad, address, length);
if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK)) { if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK)) {
command_print(CMD, "erased address " TARGET_ADDR_FMT " (length %" command_print(CMD, "erased address " TARGET_ADDR_FMT " (length %" PRIu32 ")"
PRIi32 ")"
" in %fs (%0.3f KiB/s)", address, length, " in %fs (%0.3f KiB/s)", address, length,
duration_elapsed(&bench), duration_kbps(&bench, length)); duration_elapsed(&bench), duration_kbps(&bench, length));
} }
@ -325,9 +323,9 @@ COMMAND_HANDLER(handle_flash_erase_command)
return ERROR_FAIL; return ERROR_FAIL;
} }
if (!(last <= (uint32_t)(p->num_sectors - 1))) { if (!(last <= (p->num_sectors - 1))) {
command_print(CMD, "ERROR: " command_print(CMD, "ERROR: "
"last sector must be <= %" PRIu32, "last sector must be <= %u",
p->num_sectors - 1); p->num_sectors - 1);
return ERROR_FAIL; return ERROR_FAIL;
} }
@ -339,7 +337,7 @@ COMMAND_HANDLER(handle_flash_erase_command)
if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK)) { if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK)) {
command_print(CMD, "erased sectors %" PRIu32 " " command_print(CMD, "erased sectors %" PRIu32 " "
"through %" PRIu32 " on flash bank %d " "through %" PRIu32 " on flash bank %u "
"in %fs", first, last, p->bank_number, duration_elapsed(&bench)); "in %fs", first, last, p->bank_number, duration_elapsed(&bench));
} }
@ -385,7 +383,7 @@ COMMAND_HANDLER(handle_flash_protect_command)
if (!(last <= (uint32_t)(num_blocks - 1))) { if (!(last <= (uint32_t)(num_blocks - 1))) {
command_print(CMD, "ERROR: " command_print(CMD, "ERROR: "
"last %s must be <= %" PRIu32, "last %s must be <= %d",
(p->num_prot_blocks) ? "block" : "sector", (p->num_prot_blocks) ? "block" : "sector",
num_blocks - 1); num_blocks - 1);
return ERROR_FAIL; return ERROR_FAIL;
@ -542,7 +540,7 @@ COMMAND_HANDLER(handle_flash_fill_command)
LOG_WARNING("Start address " TARGET_ADDR_FMT LOG_WARNING("Start address " TARGET_ADDR_FMT
" breaks the required alignment of flash bank %s", " breaks the required alignment of flash bank %s",
address, bank->name); address, bank->name);
LOG_WARNING("Padding %" PRId32 " bytes from " TARGET_ADDR_FMT, LOG_WARNING("Padding %" PRIu32 " bytes from " TARGET_ADDR_FMT,
padding_at_start, aligned_start); padding_at_start, aligned_start);
} }
@ -572,7 +570,7 @@ COMMAND_HANDLER(handle_flash_fill_command)
if (padding_at_end) { if (padding_at_end) {
memset(ptr, bank->default_padded_value, padding_at_end); memset(ptr, bank->default_padded_value, padding_at_end);
LOG_INFO("Padding at " TARGET_ADDR_FMT " with %" PRId32 LOG_INFO("Padding at " TARGET_ADDR_FMT " with %" PRIu32
" bytes (bank write end alignment)", " bytes (bank write end alignment)",
end_addr + 1, padding_at_end); end_addr + 1, padding_at_end);
} }
@ -761,7 +759,7 @@ COMMAND_HANDLER(handle_flash_write_bank_command)
LOG_WARNING("Start offset 0x%08" PRIx32 LOG_WARNING("Start offset 0x%08" PRIx32
" breaks the required alignment of flash bank %s", " breaks the required alignment of flash bank %s",
offset, bank->name); offset, bank->name);
LOG_WARNING("Padding %" PRId32 " bytes from " TARGET_ADDR_FMT, LOG_WARNING("Padding %" PRIu32 " bytes from " TARGET_ADDR_FMT,
padding_at_start, aligned_start); padding_at_start, aligned_start);
} }
@ -783,7 +781,7 @@ COMMAND_HANDLER(handle_flash_write_bank_command)
if (padding_at_end) { if (padding_at_end) {
memset(ptr, bank->default_padded_value, padding_at_end); memset(ptr, bank->default_padded_value, padding_at_end);
LOG_INFO("Padding at " TARGET_ADDR_FMT " with %" PRId32 LOG_INFO("Padding at " TARGET_ADDR_FMT " with %" PRIu32
" bytes (bank write end alignment)", " bytes (bank write end alignment)",
end_addr + 1, padding_at_end); end_addr + 1, padding_at_end);
} }
@ -990,7 +988,7 @@ COMMAND_HANDLER(handle_flash_verify_bank_command)
for (t = 0; t < length; t++) { for (t = 0; t < length; t++) {
if (buffer_flash[t] == buffer_file[t]) if (buffer_flash[t] == buffer_file[t])
continue; continue;
command_print(CMD, "diff %d address 0x%08x. Was 0x%02x instead of 0x%02x", command_print(CMD, "diff %d address 0x%08" PRIx32 ". Was 0x%02x instead of 0x%02x",
diffs, t + offset, buffer_flash[t], buffer_file[t]); diffs, t + offset, buffer_flash[t], buffer_file[t]);
if (diffs++ >= 127) { if (diffs++ >= 127) {
command_print(CMD, "More than 128 errors, the rest are not printed."); command_print(CMD, "More than 128 errors, the rest are not printed.");
@ -1008,11 +1006,10 @@ COMMAND_HANDLER(handle_flash_verify_bank_command)
void flash_set_dirty(void) void flash_set_dirty(void)
{ {
struct flash_bank *c; struct flash_bank *c;
int i;
/* set all flash to require erasing */ /* set all flash to require erasing */
for (c = flash_bank_list(); c; c = c->next) { for (c = flash_bank_list(); c; c = c->next) {
for (i = 0; i < c->num_sectors; i++) for (unsigned int i = 0; i < c->num_sectors; i++)
c->sectors[i].is_erased = 0; c->sectors[i].is_erased = 0;
} }
} }
@ -1244,8 +1241,8 @@ COMMAND_HANDLER(handle_flash_bank_command)
c->driver = driver; c->driver = driver;
COMMAND_PARSE_NUMBER(target_addr, CMD_ARGV[1], c->base); COMMAND_PARSE_NUMBER(target_addr, CMD_ARGV[1], c->base);
COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], c->size); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], c->size);
COMMAND_PARSE_NUMBER(int, CMD_ARGV[3], c->chip_width); COMMAND_PARSE_NUMBER(uint, CMD_ARGV[3], c->chip_width);
COMMAND_PARSE_NUMBER(int, CMD_ARGV[4], c->bus_width); COMMAND_PARSE_NUMBER(uint, CMD_ARGV[4], c->bus_width);
c->default_padded_value = c->erased_value = 0xff; c->default_padded_value = c->erased_value = 0xff;
c->minimal_write_gap = FLASH_WRITE_GAP_SECTOR; c->minimal_write_gap = FLASH_WRITE_GAP_SECTOR;

Some files were not shown because too many files have changed in this diff Show More