origen_memory_image 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/config/application.rb +87 -87
- data/config/boot.rb +1 -1
- data/config/commands.rb +62 -62
- data/config/version.rb +8 -8
- data/lib/origen_memory_image.rb +43 -40
- data/lib/origen_memory_image/base.rb +88 -88
- data/lib/origen_memory_image/binary.rb +69 -69
- data/lib/origen_memory_image/hex.rb +56 -56
- data/lib/origen_memory_image/intel_hex.rb +98 -0
- data/lib/origen_memory_image/s_record.rb +212 -212
- data/templates/web/index.md.erb +179 -164
- data/templates/web/layouts/_basic.html.erb +16 -16
- data/templates/web/partials/_navbar.html.erb +22 -22
- data/templates/web/release_notes.md.erb +5 -5
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e6d27769f59fa1a69c1852e52938f3aec79d207ffb13b72ed487e010c069e646
|
4
|
+
data.tar.gz: 294557f93e03076cd83b99a9a62448e1b750a2267821ab55639f3204363552ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b91848e556f07557ec2d73681694c138d3d4f2355487e89092f222ccbdb5df97ab2e88b084a9e0a34f86175d3848b316c9962ad3fa2d306d4db9d3a376aea8e
|
7
|
+
data.tar.gz: 47c5b9122afab890109b6b4fa6f307bcf87b3e65b46ea1e6a356b57e1ac12fdd8a0f0802753a7b7bbac1a305297f45497c08c576bec428ba2d402d825ccb1963
|
data/config/application.rb
CHANGED
@@ -1,87 +1,87 @@
|
|
1
|
-
class OrigenMemoryImageApplication < Origen::Application
|
2
|
-
|
3
|
-
# To share resources with the apps that import this plugin uncomment the following attribute:
|
4
|
-
#config.shared = {
|
5
|
-
# Add the dir/file of patterns that needs to be shared
|
6
|
-
# patterns: "pattern/shared",
|
7
|
-
# Add the file which includes all commands that needs the be shared with the app that imports
|
8
|
-
# this plugin in :command_launcher attribute
|
9
|
-
# command_launcher: "config/shared_commands.rb",
|
10
|
-
# Shared templates go in the :templates attribute
|
11
|
-
# templates: "templates/shared_templates",
|
12
|
-
# Shared programs go in the :programs attributes
|
13
|
-
# programs: "programs/shared"
|
14
|
-
#}
|
15
|
-
|
16
|
-
# This information is used in headers and email templates, set it specific
|
17
|
-
# to your application
|
18
|
-
config.name = "Origen Memory Image"
|
19
|
-
config.initials = "OrigenMemoryImage"
|
20
|
-
config.rc_url = "git@github.com:Origen-SDK/origen_memory_image.git"
|
21
|
-
config.release_externally = true
|
22
|
-
|
23
|
-
config.web_directory = "git@github.com:Origen-SDK/Origen-SDK.github.io.git/memory_image"
|
24
|
-
config.web_domain = "http://origen-sdk.org/memory_image"
|
25
|
-
|
26
|
-
# When false Origen will be less strict about checking for some common coding errors,
|
27
|
-
# it is recommended that you leave this to true for better feedback and easier debug.
|
28
|
-
# This will be the default setting in Origen v3.
|
29
|
-
config.strict_errors = true
|
30
|
-
|
31
|
-
# See: http://origen.freescale.net/origen/latest/guides/utilities/lint/
|
32
|
-
config.lint_test = {
|
33
|
-
# Require the lint tests to pass before allowing a release to proceed
|
34
|
-
run_on_tag: true,
|
35
|
-
# Auto correct violations where possible whenever 'origen lint' is run
|
36
|
-
auto_correct: true,
|
37
|
-
# Limit the testing for large legacy applications
|
38
|
-
#level: :easy,
|
39
|
-
# Run on these directories/files by default
|
40
|
-
#files: ["lib", "config/application.rb"],
|
41
|
-
}
|
42
|
-
|
43
|
-
config.semantically_version = true
|
44
|
-
|
45
|
-
# By default all generated output will end up in ./output.
|
46
|
-
# Here you can specify an alternative directory entirely, or make it dynamic such that
|
47
|
-
# the output ends up in a setup specific directory.
|
48
|
-
#config.output_directory do
|
49
|
-
# "#{Origen.root}/output/#{$dut.class}"
|
50
|
-
#end
|
51
|
-
|
52
|
-
# Similary for the reference files, generally you want to setup the reference directory
|
53
|
-
# structure to mirror that of your output directory structure.
|
54
|
-
#config.reference_directory do
|
55
|
-
# "#{Origen.root}/.ref/#{$dut.class}"
|
56
|
-
#end
|
57
|
-
|
58
|
-
# Run the tests before deploying to generate test coverage numbers
|
59
|
-
def before_deploy_site
|
60
|
-
Dir.chdir Origen.root do
|
61
|
-
#system "origen examples -c"
|
62
|
-
system "origen specs -c"
|
63
|
-
dir = "#{Origen.root}/web/output/coverage"
|
64
|
-
FileUtils.remove_dir(dir, true) if File.exists?(dir)
|
65
|
-
system "mv #{Origen.root}/coverage #{dir}"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
# This will automatically deploy your documentation after every tag
|
70
|
-
def after_release_email(tag, note, type, selector, options)
|
71
|
-
command = "origen web compile --remote --api"
|
72
|
-
Dir.chdir Origen.root do
|
73
|
-
system command
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
# Ensure that all tests pass before allowing a release to continue
|
78
|
-
def validate_release
|
79
|
-
if !system("origen specs") #|| !system("origen examples")
|
80
|
-
puts "Sorry but you can't release with failing tests, please fix them and try again."
|
81
|
-
exit 1
|
82
|
-
else
|
83
|
-
puts "All tests passing, proceeding with release process!"
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
1
|
+
class OrigenMemoryImageApplication < Origen::Application
|
2
|
+
|
3
|
+
# To share resources with the apps that import this plugin uncomment the following attribute:
|
4
|
+
#config.shared = {
|
5
|
+
# Add the dir/file of patterns that needs to be shared
|
6
|
+
# patterns: "pattern/shared",
|
7
|
+
# Add the file which includes all commands that needs the be shared with the app that imports
|
8
|
+
# this plugin in :command_launcher attribute
|
9
|
+
# command_launcher: "config/shared_commands.rb",
|
10
|
+
# Shared templates go in the :templates attribute
|
11
|
+
# templates: "templates/shared_templates",
|
12
|
+
# Shared programs go in the :programs attributes
|
13
|
+
# programs: "programs/shared"
|
14
|
+
#}
|
15
|
+
|
16
|
+
# This information is used in headers and email templates, set it specific
|
17
|
+
# to your application
|
18
|
+
config.name = "Origen Memory Image"
|
19
|
+
config.initials = "OrigenMemoryImage"
|
20
|
+
config.rc_url = "git@github.com:Origen-SDK/origen_memory_image.git"
|
21
|
+
config.release_externally = true
|
22
|
+
|
23
|
+
config.web_directory = "git@github.com:Origen-SDK/Origen-SDK.github.io.git/memory_image"
|
24
|
+
config.web_domain = "http://origen-sdk.org/memory_image"
|
25
|
+
|
26
|
+
# When false Origen will be less strict about checking for some common coding errors,
|
27
|
+
# it is recommended that you leave this to true for better feedback and easier debug.
|
28
|
+
# This will be the default setting in Origen v3.
|
29
|
+
config.strict_errors = true
|
30
|
+
|
31
|
+
# See: http://origen.freescale.net/origen/latest/guides/utilities/lint/
|
32
|
+
config.lint_test = {
|
33
|
+
# Require the lint tests to pass before allowing a release to proceed
|
34
|
+
run_on_tag: true,
|
35
|
+
# Auto correct violations where possible whenever 'origen lint' is run
|
36
|
+
auto_correct: true,
|
37
|
+
# Limit the testing for large legacy applications
|
38
|
+
#level: :easy,
|
39
|
+
# Run on these directories/files by default
|
40
|
+
#files: ["lib", "config/application.rb"],
|
41
|
+
}
|
42
|
+
|
43
|
+
config.semantically_version = true
|
44
|
+
|
45
|
+
# By default all generated output will end up in ./output.
|
46
|
+
# Here you can specify an alternative directory entirely, or make it dynamic such that
|
47
|
+
# the output ends up in a setup specific directory.
|
48
|
+
#config.output_directory do
|
49
|
+
# "#{Origen.root}/output/#{$dut.class}"
|
50
|
+
#end
|
51
|
+
|
52
|
+
# Similary for the reference files, generally you want to setup the reference directory
|
53
|
+
# structure to mirror that of your output directory structure.
|
54
|
+
#config.reference_directory do
|
55
|
+
# "#{Origen.root}/.ref/#{$dut.class}"
|
56
|
+
#end
|
57
|
+
|
58
|
+
# Run the tests before deploying to generate test coverage numbers
|
59
|
+
def before_deploy_site
|
60
|
+
Dir.chdir Origen.root do
|
61
|
+
#system "origen examples -c"
|
62
|
+
system "origen specs -c"
|
63
|
+
dir = "#{Origen.root}/web/output/coverage"
|
64
|
+
FileUtils.remove_dir(dir, true) if File.exists?(dir)
|
65
|
+
system "mv #{Origen.root}/coverage #{dir}"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# This will automatically deploy your documentation after every tag
|
70
|
+
def after_release_email(tag, note, type, selector, options)
|
71
|
+
command = "origen web compile --remote --api"
|
72
|
+
Dir.chdir Origen.root do
|
73
|
+
system command
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# Ensure that all tests pass before allowing a release to continue
|
78
|
+
def validate_release
|
79
|
+
if !system("origen specs") #|| !system("origen examples")
|
80
|
+
puts "Sorry but you can't release with failing tests, please fix them and try again."
|
81
|
+
exit 1
|
82
|
+
else
|
83
|
+
puts "All tests passing, proceeding with release process!"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
data/config/boot.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require "origen_memory_image"
|
1
|
+
require "origen_memory_image"
|
data/config/commands.rb
CHANGED
@@ -1,62 +1,62 @@
|
|
1
|
-
# This file should be used to extend the origen command line tool with tasks
|
2
|
-
# specific to your application.
|
3
|
-
#
|
4
|
-
# Also see the official docs on adding commands:
|
5
|
-
# http://origen-sdk.org/origen/guides/custom/commands/
|
6
|
-
|
7
|
-
# Map any command aliases here, for example to allow origen -x to refer to a
|
8
|
-
# command called execute you would add a reference as shown below:
|
9
|
-
|
10
|
-
aliases ={
|
11
|
-
# "-x" => "execute",
|
12
|
-
}
|
13
|
-
|
14
|
-
# The requested command is passed in here as @command, this checks it against
|
15
|
-
# the above alias table and should not be removed.
|
16
|
-
@command = aliases[@command] || @command
|
17
|
-
|
18
|
-
# Now branch to the specific task code
|
19
|
-
case @command
|
20
|
-
|
21
|
-
# Run the unit tests
|
22
|
-
when "specs"
|
23
|
-
require "rspec"
|
24
|
-
exit RSpec::Core::Runner.run(['spec'])
|
25
|
-
|
26
|
-
# Run the example-based (diff) tests
|
27
|
-
#when "examples"
|
28
|
-
# Origen.load_application
|
29
|
-
# status = 0
|
30
|
-
#
|
31
|
-
# # Compiler tests
|
32
|
-
# ARGV = %w(templates/example.txt.erb -t debug -r approved)
|
33
|
-
# load "origen/commands/compile.rb"
|
34
|
-
# # Pattern generator tests
|
35
|
-
# #ARGV = %w(some_pattern -t debug -r approved)
|
36
|
-
# #load "#{Origen.top}/lib/origen/commands/generate.rb"
|
37
|
-
#
|
38
|
-
# if Origen.app.stats.changed_files == 0 &&
|
39
|
-
# Origen.app.stats.new_files == 0 &&
|
40
|
-
# Origen.app.stats.changed_patterns == 0 &&
|
41
|
-
# Origen.app.stats.new_patterns == 0
|
42
|
-
#
|
43
|
-
# Origen.app.stats.report_pass
|
44
|
-
# else
|
45
|
-
# Origen.app.stats.report_fail
|
46
|
-
# status = 1
|
47
|
-
# end
|
48
|
-
# puts
|
49
|
-
# exit status # Exit with a 1 on the event of a failure per std unix result codes
|
50
|
-
|
51
|
-
# Always leave an else clause to allow control to fall back through to the
|
52
|
-
# Origen command handler.
|
53
|
-
# You probably want to also add the command details to the help shown via
|
54
|
-
# origen -h, you can do this be assigning the required text to @application_commands
|
55
|
-
# before handing control back to Origen. Un-comment the example below to get started.
|
56
|
-
else
|
57
|
-
@application_commands = <<-EOT
|
58
|
-
specs Run the specs (tests), -c will enable coverage
|
59
|
-
EOT
|
60
|
-
# examples Run the examples (tests), -c will enable coverage
|
61
|
-
|
62
|
-
end
|
1
|
+
# This file should be used to extend the origen command line tool with tasks
|
2
|
+
# specific to your application.
|
3
|
+
#
|
4
|
+
# Also see the official docs on adding commands:
|
5
|
+
# http://origen-sdk.org/origen/guides/custom/commands/
|
6
|
+
|
7
|
+
# Map any command aliases here, for example to allow origen -x to refer to a
|
8
|
+
# command called execute you would add a reference as shown below:
|
9
|
+
|
10
|
+
aliases ={
|
11
|
+
# "-x" => "execute",
|
12
|
+
}
|
13
|
+
|
14
|
+
# The requested command is passed in here as @command, this checks it against
|
15
|
+
# the above alias table and should not be removed.
|
16
|
+
@command = aliases[@command] || @command
|
17
|
+
|
18
|
+
# Now branch to the specific task code
|
19
|
+
case @command
|
20
|
+
|
21
|
+
# Run the unit tests
|
22
|
+
when "specs"
|
23
|
+
require "rspec"
|
24
|
+
exit RSpec::Core::Runner.run(['spec'])
|
25
|
+
|
26
|
+
# Run the example-based (diff) tests
|
27
|
+
#when "examples"
|
28
|
+
# Origen.load_application
|
29
|
+
# status = 0
|
30
|
+
#
|
31
|
+
# # Compiler tests
|
32
|
+
# ARGV = %w(templates/example.txt.erb -t debug -r approved)
|
33
|
+
# load "origen/commands/compile.rb"
|
34
|
+
# # Pattern generator tests
|
35
|
+
# #ARGV = %w(some_pattern -t debug -r approved)
|
36
|
+
# #load "#{Origen.top}/lib/origen/commands/generate.rb"
|
37
|
+
#
|
38
|
+
# if Origen.app.stats.changed_files == 0 &&
|
39
|
+
# Origen.app.stats.new_files == 0 &&
|
40
|
+
# Origen.app.stats.changed_patterns == 0 &&
|
41
|
+
# Origen.app.stats.new_patterns == 0
|
42
|
+
#
|
43
|
+
# Origen.app.stats.report_pass
|
44
|
+
# else
|
45
|
+
# Origen.app.stats.report_fail
|
46
|
+
# status = 1
|
47
|
+
# end
|
48
|
+
# puts
|
49
|
+
# exit status # Exit with a 1 on the event of a failure per std unix result codes
|
50
|
+
|
51
|
+
# Always leave an else clause to allow control to fall back through to the
|
52
|
+
# Origen command handler.
|
53
|
+
# You probably want to also add the command details to the help shown via
|
54
|
+
# origen -h, you can do this be assigning the required text to @application_commands
|
55
|
+
# before handing control back to Origen. Un-comment the example below to get started.
|
56
|
+
else
|
57
|
+
@application_commands = <<-EOT
|
58
|
+
specs Run the specs (tests), -c will enable coverage
|
59
|
+
EOT
|
60
|
+
# examples Run the examples (tests), -c will enable coverage
|
61
|
+
|
62
|
+
end
|
data/config/version.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
module OrigenMemoryImage
|
2
|
-
MAJOR = 0
|
3
|
-
MINOR =
|
4
|
-
BUGFIX = 0
|
5
|
-
DEV = nil
|
6
|
-
|
7
|
-
VERSION = [MAJOR, MINOR, BUGFIX].join(".") + (DEV ? ".pre#{DEV}" : '')
|
8
|
-
end
|
1
|
+
module OrigenMemoryImage
|
2
|
+
MAJOR = 0
|
3
|
+
MINOR = 8
|
4
|
+
BUGFIX = 0
|
5
|
+
DEV = nil
|
6
|
+
|
7
|
+
VERSION = [MAJOR, MINOR, BUGFIX].join(".") + (DEV ? ".pre#{DEV}" : '')
|
8
|
+
end
|
data/lib/origen_memory_image.rb
CHANGED
@@ -1,40 +1,43 @@
|
|
1
|
-
require 'origen'
|
2
|
-
require_relative '../config/application.rb'
|
3
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
#
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
1
|
+
require 'origen'
|
2
|
+
require_relative '../config/application.rb'
|
3
|
+
|
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
|
+
|
11
|
+
def self.new(file, options = {})
|
12
|
+
unless options[:source] == String
|
13
|
+
file = Origen.file_handler.clean_path_to(file)
|
14
|
+
end
|
15
|
+
find_type(file, options).new(file, options)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns the class of the image manager for the given file
|
19
|
+
def self.find_type(file, options = {})
|
20
|
+
# Read first 10 lines
|
21
|
+
if options[:source] == String
|
22
|
+
snippet = file.split("\n")
|
23
|
+
else
|
24
|
+
snippet = File.foreach(file.to_s).first(10)
|
25
|
+
end
|
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
|
33
|
+
when options[:type] == :srecord || SRecord.match?(snippet)
|
34
|
+
SRecord
|
35
|
+
when options[:type] == :intel_hex || IntelHex.match?(snippet)
|
36
|
+
IntelHex
|
37
|
+
when options[:type] == :hex || Hex.match?(snippet)
|
38
|
+
Hex
|
39
|
+
else
|
40
|
+
fail "Unknown format for image file: #{file}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -1,88 +1,88 @@
|
|
1
|
-
module OrigenMemoryImage
|
2
|
-
class Base
|
3
|
-
attr_reader :file, :source
|
4
|
-
|
5
|
-
def initialize(file, options = {})
|
6
|
-
if options[:source] == String
|
7
|
-
@source = file
|
8
|
-
else
|
9
|
-
@file = file
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
# Returns the code execution start address as an int
|
14
|
-
def start_address
|
15
|
-
fail "#{self.class} has not implemented the start_address method!"
|
16
|
-
end
|
17
|
-
|
18
|
-
# Returns the s-record as an array of addresses and data
|
19
|
-
#
|
20
|
-
# @param [hash] options, allows the selection of endianness swapping - ie the output will have the endianness changed
|
21
|
-
#
|
22
|
-
# The output is a 2D array, with each element being an array with element zero being the
|
23
|
-
# address of the data and element one being one word of data
|
24
|
-
# like this [[ADDR0, DATA0], [ADDR1, DATA1], [ADDR2, DATA2]...]
|
25
|
-
#
|
26
|
-
# The block header data and end of block value are not interpreted in any way and
|
27
|
-
# the checksum bits are disregarded
|
28
|
-
def to_a(options = {})
|
29
|
-
options = {
|
30
|
-
flip_endianness: false,
|
31
|
-
data_width_in_bytes: 4,
|
32
|
-
crop: []
|
33
|
-
}.merge(options)
|
34
|
-
data = extract_addr_data(options)
|
35
|
-
|
36
|
-
if options[:crop].count > 0
|
37
|
-
cropped_data = []
|
38
|
-
data.each do |addr, data|
|
39
|
-
case options[:crop].count
|
40
|
-
when 1
|
41
|
-
cropped_data.push([addr, data]) if addr >= options[:crop][0]
|
42
|
-
when 2
|
43
|
-
cropped_data.push([addr, data]) if addr >= options[:crop][0] && addr <= options[:crop][1]
|
44
|
-
else
|
45
|
-
fail 'crop option can only be array of size 1 or 2'
|
46
|
-
end
|
47
|
-
end
|
48
|
-
data = cropped_data
|
49
|
-
end
|
50
|
-
|
51
|
-
if options[:flip_endianness] || options[:endianness_change]
|
52
|
-
data.map do |v|
|
53
|
-
[v[0], flip_endianness(v[1], options[:data_width_in_bytes])]
|
54
|
-
end
|
55
|
-
else
|
56
|
-
data
|
57
|
-
end
|
58
|
-
end
|
59
|
-
alias_method :to_array, :to_a
|
60
|
-
|
61
|
-
# Reverse the endianness of the given data value, the width of it in bytes must
|
62
|
-
# be supplied as the second argument
|
63
|
-
#
|
64
|
-
# @example
|
65
|
-
# flip_endianness(0x12345678, 4) # => 0x78563412
|
66
|
-
def flip_endianness(data, width_in_bytes)
|
67
|
-
v = 0
|
68
|
-
width_in_bytes.times do |i|
|
69
|
-
# data[7:0] => data[15:8]
|
70
|
-
start = 8 * i
|
71
|
-
v += data[(start + 7)..start] << ((width_in_bytes - i - 1) * 8)
|
72
|
-
end
|
73
|
-
v
|
74
|
-
end
|
75
|
-
|
76
|
-
def file_name
|
77
|
-
file || 'From source string'
|
78
|
-
end
|
79
|
-
|
80
|
-
def lines
|
81
|
-
if file
|
82
|
-
File.readlines(file)
|
83
|
-
else
|
84
|
-
source.split("\n")
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
1
|
+
module OrigenMemoryImage
|
2
|
+
class Base
|
3
|
+
attr_reader :file, :source
|
4
|
+
|
5
|
+
def initialize(file, options = {})
|
6
|
+
if options[:source] == String
|
7
|
+
@source = file
|
8
|
+
else
|
9
|
+
@file = file
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Returns the code execution start address as an int
|
14
|
+
def start_address
|
15
|
+
fail "#{self.class} has not implemented the start_address method!"
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns the s-record as an array of addresses and data
|
19
|
+
#
|
20
|
+
# @param [hash] options, allows the selection of endianness swapping - ie the output will have the endianness changed
|
21
|
+
#
|
22
|
+
# The output is a 2D array, with each element being an array with element zero being the
|
23
|
+
# address of the data and element one being one word of data
|
24
|
+
# like this [[ADDR0, DATA0], [ADDR1, DATA1], [ADDR2, DATA2]...]
|
25
|
+
#
|
26
|
+
# The block header data and end of block value are not interpreted in any way and
|
27
|
+
# the checksum bits are disregarded
|
28
|
+
def to_a(options = {})
|
29
|
+
options = {
|
30
|
+
flip_endianness: false,
|
31
|
+
data_width_in_bytes: 4,
|
32
|
+
crop: []
|
33
|
+
}.merge(options)
|
34
|
+
data = extract_addr_data(options)
|
35
|
+
|
36
|
+
if options[:crop].count > 0
|
37
|
+
cropped_data = []
|
38
|
+
data.each do |addr, data|
|
39
|
+
case options[:crop].count
|
40
|
+
when 1
|
41
|
+
cropped_data.push([addr, data]) if addr >= options[:crop][0]
|
42
|
+
when 2
|
43
|
+
cropped_data.push([addr, data]) if addr >= options[:crop][0] && addr <= options[:crop][1]
|
44
|
+
else
|
45
|
+
fail 'crop option can only be array of size 1 or 2'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
data = cropped_data
|
49
|
+
end
|
50
|
+
|
51
|
+
if options[:flip_endianness] || options[:endianness_change]
|
52
|
+
data.map do |v|
|
53
|
+
[v[0], flip_endianness(v[1], options[:data_width_in_bytes])]
|
54
|
+
end
|
55
|
+
else
|
56
|
+
data
|
57
|
+
end
|
58
|
+
end
|
59
|
+
alias_method :to_array, :to_a
|
60
|
+
|
61
|
+
# Reverse the endianness of the given data value, the width of it in bytes must
|
62
|
+
# be supplied as the second argument
|
63
|
+
#
|
64
|
+
# @example
|
65
|
+
# flip_endianness(0x12345678, 4) # => 0x78563412
|
66
|
+
def flip_endianness(data, width_in_bytes)
|
67
|
+
v = 0
|
68
|
+
width_in_bytes.times do |i|
|
69
|
+
# data[7:0] => data[15:8]
|
70
|
+
start = 8 * i
|
71
|
+
v += data[(start + 7)..start] << ((width_in_bytes - i - 1) * 8)
|
72
|
+
end
|
73
|
+
v
|
74
|
+
end
|
75
|
+
|
76
|
+
def file_name
|
77
|
+
file || 'From source string'
|
78
|
+
end
|
79
|
+
|
80
|
+
def lines
|
81
|
+
if file
|
82
|
+
File.readlines(file)
|
83
|
+
else
|
84
|
+
source.split("\n")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|