origen_memory_image 0.5.2 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/config/boot.rb +1 -0
- data/config/version.rb +2 -3
- data/lib/origen_memory_image.rb +15 -2
- data/lib/origen_memory_image/base.rb +2 -1
- data/lib/origen_memory_image/binary.rb +69 -0
- data/lib/origen_memory_image/hex.rb +5 -1
- data/lib/origen_memory_image/intel_hex.rb +98 -0
- data/lib/origen_memory_image/s_record.rb +5 -1
- data/templates/web/index.md.erb +45 -0
- metadata +6 -8
- data/config/development.rb +0 -12
- data/config/environment.rb +0 -40
- data/config/users.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 90f929c547d4a00df7450faf892f6f4ebed1c56d18b64e9315d810dd7774f55c
|
4
|
+
data.tar.gz: e209715c41348a5975f549f27babdc1d4e2c0473f6e935fff12148d2f2e7a5f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2319ac1964ce679181d45b9b79343604a90aad3149d3015ab1e8daf3e1edaf2045bf41aaba40680f371131f6278a363187caf2407b60fd7508cb4ecdc3792cdc
|
7
|
+
data.tar.gz: c8dae0921e4490b7a108cfbbb0a1ef0d93585fe8191c8e61dd2ef3debf624bd6333771d2f7ee24de638cb265f33653729e8def0e7bcc6812eeac689470f89a90
|
data/config/boot.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "origen_memory_image"
|
data/config/version.rb
CHANGED
data/lib/origen_memory_image.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
require 'origen'
|
2
2
|
require_relative '../config/application.rb'
|
3
|
-
require_relative '../config/environment.rb'
|
4
3
|
|
5
4
|
module OrigenMemoryImage
|
5
|
+
autoload :Base, 'origen_memory_image/base'
|
6
|
+
autoload :SRecord, 'origen_memory_image/s_record'
|
7
|
+
autoload :Hex, 'origen_memory_image/hex'
|
8
|
+
autoload :Binary, 'origen_memory_image/binary'
|
9
|
+
autoload :IntelHex, 'origen_memory_image/intel_hex'
|
10
|
+
|
6
11
|
def self.new(file, options = {})
|
7
12
|
unless options[:source] == String
|
8
13
|
file = Origen.file_handler.clean_path_to(file)
|
@@ -16,11 +21,19 @@ module OrigenMemoryImage
|
|
16
21
|
if options[:source] == String
|
17
22
|
snippet = file.split("\n")
|
18
23
|
else
|
19
|
-
snippet = File.foreach(file.to_s).first(
|
24
|
+
snippet = File.foreach(file.to_s).first(10)
|
20
25
|
end
|
21
26
|
case
|
27
|
+
# Always do the binary first since the others won't be able to process
|
28
|
+
# a binary snippet
|
29
|
+
when options[:type] == :binary || (options[:source] != String && Binary.match?(file))
|
30
|
+
Binary
|
31
|
+
when options[:source] == String && Binary.match?(snippet, true)
|
32
|
+
Binary
|
22
33
|
when options[:type] == :srecord || SRecord.match?(snippet)
|
23
34
|
SRecord
|
35
|
+
when options[:type] == :intel_hex || IntelHex.match?(snippet)
|
36
|
+
IntelHex
|
24
37
|
when options[:type] == :hex || Hex.match?(snippet)
|
25
38
|
Hex
|
26
39
|
else
|
@@ -8,6 +8,7 @@ module OrigenMemoryImage
|
|
8
8
|
else
|
9
9
|
@file = file
|
10
10
|
end
|
11
|
+
@ljust_partial_data = options[:ljust_partial_data]
|
11
12
|
end
|
12
13
|
|
13
14
|
# Returns the code execution start address as an int
|
@@ -50,7 +51,7 @@ module OrigenMemoryImage
|
|
50
51
|
|
51
52
|
if options[:flip_endianness] || options[:endianness_change]
|
52
53
|
data.map do |v|
|
53
|
-
[v[0], flip_endianness(v[1],
|
54
|
+
[v[0], flip_endianness(v[1], options[:data_width_in_bytes])]
|
54
55
|
end
|
55
56
|
else
|
56
57
|
data
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module OrigenMemoryImage
|
2
|
+
class Binary < Base
|
3
|
+
def self.match?(file, snippet = false)
|
4
|
+
if snippet
|
5
|
+
file.all? { |l| l.strip =~ /^[01]*$/ }
|
6
|
+
else
|
7
|
+
# detect whether the data is mostly not alpha numeric
|
8
|
+
filedata = (File.read(file, 256) || '')
|
9
|
+
(filedata.gsub(/\s+/, '').gsub(/\w/, '').length.to_f / filedata.length.to_f) > 0.3
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Always returns 0 since binary files do not contain addresses
|
14
|
+
def start_address
|
15
|
+
0
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_test_file
|
19
|
+
data = [
|
20
|
+
0x1EE0021C, 0x22401BE0, 0x021C2243,
|
21
|
+
0x18E0021C, 0x5A780A43, 0x03E0034B,
|
22
|
+
0xF7215A78, 0x0A400020, 0x22E08442,
|
23
|
+
0x22D31FE0, 0x84421FD9, 0x1CE08442,
|
24
|
+
0x002B20D1, 0x03E0012A, 0x01D1002B,
|
25
|
+
0x1BD00223, 0x2340022A, 0x02D1002B,
|
26
|
+
0x15D103E0, 0x032A01D1, 0x78000018,
|
27
|
+
0x7C000018, 0x82000018, 0x88000018
|
28
|
+
]
|
29
|
+
data = data.map { |d| d.to_s(2).rjust(32, '0') }.join
|
30
|
+
File.open('examples/bin1.bin', 'wb') do |output|
|
31
|
+
output.write [data].pack('B*')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
# Returns an array containing all address/data from the given s-record
|
38
|
+
# No address manipulation is performed, that is left to the caller to apply
|
39
|
+
# any scrambling as required by the target system
|
40
|
+
def extract_addr_data(options = {})
|
41
|
+
options = {
|
42
|
+
data_width_in_bytes: 4
|
43
|
+
}.merge(options)
|
44
|
+
|
45
|
+
result = []
|
46
|
+
width = options[:data_width_in_bytes]
|
47
|
+
address = 0
|
48
|
+
|
49
|
+
if file
|
50
|
+
raw = File.binread(file)
|
51
|
+
bytes = raw.unpack('C*')
|
52
|
+
else
|
53
|
+
raw = lines.map(&:strip).join
|
54
|
+
bytes = raw.scan(/.{1,8}/).map { |s| s.to_i(2) }
|
55
|
+
end
|
56
|
+
|
57
|
+
bytes.each_slice(width) do |d|
|
58
|
+
v = 0
|
59
|
+
width.times do |i|
|
60
|
+
v |= d[i] << ((width - 1 - i) * 8) if d[i]
|
61
|
+
end
|
62
|
+
result << [address, v]
|
63
|
+
address += width
|
64
|
+
end
|
65
|
+
|
66
|
+
result
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -46,7 +46,11 @@ module OrigenMemoryImage
|
|
46
46
|
end
|
47
47
|
# If a partial word is left over
|
48
48
|
if (remainder = data.length % (2 * options[:data_width_in_bytes])) > 0
|
49
|
-
|
49
|
+
if @ljust_partial_data
|
50
|
+
result << [@address, data[data.length - remainder..data.length].ljust(options[:data_width_in_bytes] * 2, '0').to_i(16)]
|
51
|
+
else
|
52
|
+
result << [@address, data[data.length - remainder..data.length].to_i(16)]
|
53
|
+
end
|
50
54
|
end
|
51
55
|
end
|
52
56
|
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
module OrigenMemoryImage
|
2
|
+
class IntelHex < Base
|
3
|
+
def self.match?(snippet)
|
4
|
+
snippet.all? do |line|
|
5
|
+
line.empty? || line =~ /^:[0-9A-Fa-f]{6}0[0-5]/
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def start_address
|
10
|
+
@start_address ||= begin
|
11
|
+
addrs = []
|
12
|
+
lines.each do |line|
|
13
|
+
line = line.strip
|
14
|
+
if start_linear_address?(line)
|
15
|
+
addrs << decode(line)[:data].to_i(16)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
addrs.last || 0
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def decode(line)
|
25
|
+
d = {}
|
26
|
+
if line =~ /^:([0-9A-Fa-f]{2})([0-9A-Fa-f]{4})(\d\d)([0-9A-Fa-f]+)([0-9A-Fa-f]{2})$/
|
27
|
+
d[:byte_count] = Regexp.last_match(1).to_i(16)
|
28
|
+
d[:address] = Regexp.last_match(2).to_i(16)
|
29
|
+
d[:record_type] = Regexp.last_match(3).to_i(16)
|
30
|
+
d[:data] = Regexp.last_match(4)
|
31
|
+
d[:checksum] = Regexp.last_match(5).to_i(16)
|
32
|
+
else
|
33
|
+
fail "Invalid line encountered in Intel Hex formatted file: #{line}"
|
34
|
+
end
|
35
|
+
d
|
36
|
+
end
|
37
|
+
|
38
|
+
def data?(line)
|
39
|
+
!!(line =~ /^:[0-9A-Fa-f]{6}00/)
|
40
|
+
end
|
41
|
+
|
42
|
+
def extended_segment_address?(line)
|
43
|
+
!!(line =~ /^:[0-9A-Fa-f]{6}02/)
|
44
|
+
end
|
45
|
+
|
46
|
+
def extended_linear_address?(line)
|
47
|
+
!!(line =~ /^:[0-9A-Fa-f]{6}04/)
|
48
|
+
end
|
49
|
+
|
50
|
+
def start_linear_address?(line)
|
51
|
+
!!(line =~ /^:[0-9A-Fa-f]{6}05/)
|
52
|
+
end
|
53
|
+
|
54
|
+
def upper_addr
|
55
|
+
@upper_addr || 0
|
56
|
+
end
|
57
|
+
|
58
|
+
def segment_address
|
59
|
+
@segment_address || 0
|
60
|
+
end
|
61
|
+
|
62
|
+
# Returns an array containing all address/data from the given s-record
|
63
|
+
# No address manipulation is performed, that is left to the caller to apply
|
64
|
+
# any scrambling as required by the target system
|
65
|
+
def extract_addr_data(options = {})
|
66
|
+
options = {
|
67
|
+
data_width_in_bytes: 4
|
68
|
+
}.merge(options)
|
69
|
+
|
70
|
+
result = []
|
71
|
+
lines.each do |line|
|
72
|
+
line = line.strip
|
73
|
+
if extended_segment_address?(line)
|
74
|
+
@segment_address = decode(line)[:data].to_i(16) * 16
|
75
|
+
|
76
|
+
elsif extended_linear_address?(line)
|
77
|
+
@upper_addr = (decode(line)[:data].to_i(16)) << 16
|
78
|
+
|
79
|
+
elsif data?(line)
|
80
|
+
d = decode(line)
|
81
|
+
addr = d[:address] + segment_address + upper_addr
|
82
|
+
|
83
|
+
data = d[:data]
|
84
|
+
data_matcher = '\w\w' * options[:data_width_in_bytes]
|
85
|
+
data.scan(/#{data_matcher}/).each do |data_packet|
|
86
|
+
result << [addr, data_packet.to_i(16)]
|
87
|
+
addr += options[:data_width_in_bytes]
|
88
|
+
end
|
89
|
+
# If a partial word is left over
|
90
|
+
if (remainder = data.length % (2 * options[:data_width_in_bytes])) > 0
|
91
|
+
result << [addr, data[data.length - remainder..data.length].to_i(16)]
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
result
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -202,7 +202,11 @@ module OrigenMemoryImage
|
|
202
202
|
end
|
203
203
|
# If a partial word is left over
|
204
204
|
if (remainder = data.length % (2 * options[:data_width_in_bytes])) > 0
|
205
|
-
|
205
|
+
if @ljust_partial_data
|
206
|
+
result << [addr, data[data.length - remainder..data.length].ljust(options[:data_width_in_bytes] * 2, '0').to_i(16)]
|
207
|
+
else
|
208
|
+
result << [addr, data[data.length - remainder..data.length].to_i(16)]
|
209
|
+
end
|
206
210
|
end
|
207
211
|
end
|
208
212
|
end
|
data/templates/web/index.md.erb
CHANGED
@@ -58,6 +58,25 @@ my_srec = OrigenMemoryImage.new("source_files/test_atd.abs.S19")
|
|
58
58
|
my_hex = OrigenMemoryImage.new("source_files/math.hex")
|
59
59
|
~~~
|
60
60
|
|
61
|
+
By default any partial data words are right justified. Change this behavior to left justified like this:
|
62
|
+
|
63
|
+
~~~ruby
|
64
|
+
my_srec = OrigenMemoryImage.new("source_files/test_atd.abs.S19", ljust_partial_data: true)
|
65
|
+
my_hex = OrigenMemoryImage.new("source_files/math.hex", ljust_partial_data: true)
|
66
|
+
~~~
|
67
|
+
|
68
|
+
Partial data example:
|
69
|
+
|
70
|
+
~~~
|
71
|
+
0304FE
|
72
|
+
|
73
|
+
# Default interpretation into 32-bit word:
|
74
|
+
0x0003_04FE
|
75
|
+
|
76
|
+
# Left justified interpretation into 32-bit word:
|
77
|
+
0x0304_FE00
|
78
|
+
~~~
|
79
|
+
|
61
80
|
Memory images can also be created directly from a string:
|
62
81
|
|
63
82
|
~~~ruby
|
@@ -135,6 +154,32 @@ The data lines can be grouped into any size:
|
|
135
154
|
780000187C0000188200001888000018
|
136
155
|
~~~
|
137
156
|
|
157
|
+
#### Binary Files
|
158
|
+
|
159
|
+
A binary file:
|
160
|
+
|
161
|
+
~~~text
|
162
|
+
00001101000101010000111100010011
|
163
|
+
00001110000101000001000000010010
|
164
|
+
00000000000000000000010000010111
|
165
|
+
00000100000000110000010100000110
|
166
|
+
~~~
|
167
|
+
|
168
|
+
#### Intel Hex
|
169
|
+
|
170
|
+
Any valid Intel Hex file:
|
171
|
+
|
172
|
+
~~~text
|
173
|
+
:020000040022D8
|
174
|
+
:10010000214601360121470136007EFE09D2190140
|
175
|
+
:100110002146017E17C20001FF5F16002148011928
|
176
|
+
:020000040023D7
|
177
|
+
:10012000194E79234623965778239EDA3F01B2CAA7
|
178
|
+
:100130003F0156702B5E712B722B732146013421C7
|
179
|
+
:0400000500000000F7
|
180
|
+
:00000001FF
|
181
|
+
~~~
|
182
|
+
|
138
183
|
### How To Setup a Development Environment
|
139
184
|
|
140
185
|
[Clone the repository from Github](https://github.com/Origen-SDK/origen_memory_image).
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: origen_memory_image
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen McGinty
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: origen
|
@@ -46,14 +46,14 @@ extensions: []
|
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
48
|
- config/application.rb
|
49
|
+
- config/boot.rb
|
49
50
|
- config/commands.rb
|
50
|
-
- config/development.rb
|
51
|
-
- config/environment.rb
|
52
|
-
- config/users.rb
|
53
51
|
- config/version.rb
|
54
52
|
- lib/origen_memory_image.rb
|
55
53
|
- lib/origen_memory_image/base.rb
|
54
|
+
- lib/origen_memory_image/binary.rb
|
56
55
|
- lib/origen_memory_image/hex.rb
|
56
|
+
- lib/origen_memory_image/intel_hex.rb
|
57
57
|
- lib/origen_memory_image/s_record.rb
|
58
58
|
- templates/web/index.md.erb
|
59
59
|
- templates/web/layouts/_basic.html.erb
|
@@ -77,11 +77,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
77
|
- !ruby/object:Gem::Version
|
78
78
|
version: 1.8.11
|
79
79
|
requirements: []
|
80
|
-
|
81
|
-
rubygems_version: 2.2.2
|
80
|
+
rubygems_version: 3.1.4
|
82
81
|
signing_key:
|
83
82
|
specification_version: 4
|
84
83
|
summary: Provides a standard API for consuming memory image files in any format e.g.
|
85
84
|
s-record, hex
|
86
85
|
test_files: []
|
87
|
-
has_rdoc:
|
data/config/development.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
# This file is similar to environment.rb and will be loaded
|
2
|
-
# automatically at the start of each invocation of Origen.
|
3
|
-
#
|
4
|
-
# However the major difference is that it will not be loaded
|
5
|
-
# if the application is imported by a 3rd party app - in that
|
6
|
-
# case only environment.rb is loaded.
|
7
|
-
#
|
8
|
-
# Therefore this file should be used to load anything you need
|
9
|
-
# to setup a development environment for this app, normally
|
10
|
-
# this would be used to load some dummy classes to instantiate
|
11
|
-
# your objects so that they can be tested and/or interacted with
|
12
|
-
# in the console.
|
data/config/environment.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
# This file will be required by Origen before your target is loaded, you
|
2
|
-
# can use this to require all of your files, which is the easiest way
|
3
|
-
# to get started. As your experience grows you may wish to require only the
|
4
|
-
# minimum files required to allow the target to be initialized and let
|
5
|
-
# each class require its own dependencies.
|
6
|
-
#
|
7
|
-
# It is recommended that you keep all of your application logic in lib/
|
8
|
-
# The lib directory has already been added to the search path and so any files
|
9
|
-
# in there can be referenced from here with a relative path.
|
10
|
-
#
|
11
|
-
# Note that pattern files do not need to be referenced from here and these
|
12
|
-
# will be located automatically by origen.
|
13
|
-
#
|
14
|
-
# Examples
|
15
|
-
# --------
|
16
|
-
# This says load the file "lib/pioneer.rb" the first time anyone makes a
|
17
|
-
# reference to the class name 'Pioneer'.
|
18
|
-
#autoload :Pioneer, "pioneer"
|
19
|
-
#
|
20
|
-
# This is generally preferable to using require which will load the file
|
21
|
-
# regardless of whether it is needed by the current target or not:
|
22
|
-
#require "pioneer"
|
23
|
-
#
|
24
|
-
# Sometimes you have to use require however:-
|
25
|
-
# 1. When defining a test program interface:
|
26
|
-
#require "interfaces/j750"
|
27
|
-
# 2. If you want to extend a class defined by an imported plugin, in
|
28
|
-
# this case your must use required and supply a full path (to distinguish
|
29
|
-
# it from the one in the parent application):
|
30
|
-
#require "#{Origen.root}/c90_top_level/p2"
|
31
|
-
|
32
|
-
# Plugins should not use a wildcard import of the lib directory to help
|
33
|
-
# prevent long start up times, only require what is necessary to boot and
|
34
|
-
# use autoload for everything else.
|
35
|
-
module OrigenMemoryImage
|
36
|
-
autoload :Base, "origen_memory_image/base"
|
37
|
-
autoload :SRecord, "origen_memory_image/s_record"
|
38
|
-
autoload :Hex, "origen_memory_image/hex"
|
39
|
-
end
|
40
|
-
require "origen_memory_image"
|
data/config/users.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# This file defines the users associated with your project, it is basically the
|
2
|
-
# mailing list for release notes.
|
3
|
-
#
|
4
|
-
# You can split your users into "admin" and "user" groups, the main difference
|
5
|
-
# between the two is that admin users will get all tag emails, users will get
|
6
|
-
# emails on external/official releases only.
|
7
|
-
#
|
8
|
-
# Users are also prohibited from running the "origen tag" task, but this is
|
9
|
-
# really just to prevent a casual user from executing it inadvertently and is
|
10
|
-
# not intended to be a serious security gate.
|
11
|
-
module Origen
|
12
|
-
module Users
|
13
|
-
def users
|
14
|
-
@users ||= [
|
15
|
-
]
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|