Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
7a40aaed
Unverified
Commit
7a40aaed
authored
6 years ago
by
Francisco Acosta
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #9787 from cladmi/pr/openocd/flashbin
openocd.sh: allow flashing binary files without configuration
parents
749d8aed
bc7e53f3
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dist/tools/openocd/openocd.sh
+54
-2
54 additions, 2 deletions
dist/tools/openocd/openocd.sh
with
54 additions
and
2 deletions
dist/tools/openocd/openocd.sh
+
54
−
2
View file @
7a40aaed
#!/bin/sh
#!/bin/
ba
sh
#
# Unified OpenOCD script for RIOT
#
...
...
@@ -145,6 +145,43 @@ test_imagefile() {
fi
}
_has_bin_extension() {
# The regex need to be without quotes
local firmware=
$1
[[ "
${
firmware
}
" =~ ^.*
\.
bin
$
]]
}
# Return 0 if given file should be considered a binary
_is_binfile() {
local firmware="
$1
"
local firmware_type="
$2
"
[[ "
${
firmware_type
}
" = "
bin
" ]] || {
\
[[ -z "
${
firmware_type
}
" ]] && _has_bin_extension "
${
firmware
}
"; }
}
# Outputs bank info on different lines without the '{}'
_flash_list() {
# Openocd output for 'flash list' is
# ....
# {name nrf51 base 0 size 0 bus_width 1 chip_width 1} {name nrf51 base 268439552 size 0 bus_width 1 chip_width 1}
# ....
sh -c "
${
OPENOCD
}
\
${
OPENOCD_ADAPTER_INIT
}
\
-f
'${OPENOCD_CONFIG}'
\
-c
'flash list'
\
-c
'shutdown'
" 2>&1 | sed -n '/^{.*}
$/
{s/
\}
/
\}\n
/g;s/[{}]//g;p}'
}
# Print flash address for 'bank_num' num defaults to 1
# _flash_address [bank_num:1]
_flash_address() {
bank_num=
${
1
:-
1
}
# extract 'base' value and print as hexadecimal
# name nrf51 base 268439552 size 0 bus_width 1 chip_width 1
_flash_list | awk "
NR
==
${
bank_num
}
"'{printf "
0x
%08x\n
",
$4
}'
}
#
# now comes the actual actions
#
...
...
@@ -159,6 +196,21 @@ do_flash() {
exit
$RETVAL
fi
fi
# In case of binary file, IMAGE_OFFSET should include the flash base address
# This allows flashing normal binary files without env configuration
if _is_binfile "
${
IMAGE_FILE
}
" "
${
IMAGE_TYPE
}
"; then
# hardwritten to use the first bank
FLASH_ADDR=
$(
_flash_address 1
)
echo "
Binfile
detected, adding ROM base address
:
${
FLASH_ADDR
}
"
IMAGE_TYPE=bin
IMAGE_OFFSET=
$(
printf
"0x%08x
\n
"
"
$((${
IMAGE_OFFSET
}
+
${
FLASH_ADDR
}))
"
)
fi
if [ "
${
IMAGE_OFFSET
}
" != "
0
" ]; then
echo "
Flashing
with IMAGE_OFFSET
:
${
IMAGE_OFFSET
}
"
fi
# flash device
sh -c "
${
OPENOCD
}
\
${
OPENOCD_ADAPTER_INIT
}
\
...
...
@@ -173,7 +225,7 @@ do_flash() {
${
OPENOCD_PRE_FLASH_CMDS
}
\
-c
'flash write_image erase \"${IMAGE_FILE}\" ${IMAGE_OFFSET} ${IMAGE_TYPE}'
\
${
OPENOCD_PRE_VERIFY_CMDS
}
\
-c
'verify_image \"${IMAGE_FILE}\"'
\
-c
'verify_image \"${IMAGE_FILE}\"
${IMAGE_OFFSET}
'
\
-c
'reset run'
\
-c
'shutdown'
" &&
echo 'Done flashing'
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment