Add the hash of the code in executable file - stm32

I have an STM32 application which uses two blocks of memory. In 0th block, I have a boot code (which runs just after power-on) and in 7th block, I have an application code (which may or may not run depending on the authorization decision given by the boot code).
Those two codes are developed hence generated by two separate projects. They are flashed on the specific blocks (boot code to 0th block and application code to 7th block) of STM32 NOR memory using openocd tool by giving an offset value to the openocd's write_image command.
What I would like to do basically in the boot code is that I want to calculate the hash of the application code and compare it with the reference digest. If they are equal, I will give the hand to the application code. For that, after I generate the executable (can be in elf, hex or bin format) of the application code, I want to:
Create another file (in any format listed above) which has 128K byte size
Copy the content of the executable file to the recently created file from its beginning (0 offset)
Write the hash of the executable to the last 32 bytes of the recently created file
Fill the gap with 0xFF
Finally flash this executable file (if it is still) to the 7th block of the memory
Do you think that it is doable and feasible? If so:
Which format should I use to generate the executable?
Do I have something that I need to give specific attention to achieve this?
Lastly, do you think that it makes sense to do that or is there any other more standard way for this purpose?
Thanks a lot in advance.

You just need to add an additional step to your building sequence. After the linking extract the binary file from elf
Then write a program in your favourite programming language which will calculate something and append the result to that bin file

Related

INode File System, what is the extra space in a data block used for?

So, I am currently learning about the INode file system and am asked to write a simple file system using Inodes.
So far, I understand that there is an INode table that has a mapping from INode-> Data blocks through direct/indirect pointers.
Let's assume data gets written into a file, the data is stored into two blocks. Let's say each block is 512bytes, and the file takes one full block, and only 200 bytes of the second block. What happens with the rest of the space in that data block? Is it reserved for that file only or do other files use this block?
Depending on the file system, usually and most likely this area is now lost. I think the Reiser File System actually reclaimed this area, but I could be wrong.
Creating your own File System can be a challenging experience, but also an enjoyable experience. I have created a few myself and worked on another. If you are creating your own file system, you can have it do whatever you wish.
Look at the bottom of this page for a few that I am working on/with. The LeanFS in particular, uses Inodes as well. The SFS is a very simple file system. Each is well documented so that you can research and decide what you would like to do.

Generate executable larger than 4GB with TurboStudio

Thinapp has no problem generating virtual applications above 4GB.
Whenever I try something similar with TurboStudio it fails. Is there a way around it?
Okay, after several experiments I think I found an answer.
Spoon Studio (or Turbo Studio as it is now called) cannot create executables larger than 4GB. Checking the "Compress Payload" option reduces output size, but these captures perform usually a bit slower (due to the decompression required at runtime) and of course, there are always apps that will exceed the 4GB limit even with this option checked.
A workaround, however, is to divide the installation process in multiple captures (when possible) and use svm files.
For example, assume you are capturing a large application (Myapp) and some addons or plugins to it which together generate a capture larger than 4GB in size.
The solution would then be to first capture the application without any addons. Then install the plugins/addons and capture them separately. When you capture the plugins choose as Project Type "Component". At the end of this process you will have a captured application in executable "myapp.exe" and the plugins captured separately in "plugins.svm". It is possible to repeat this process several times, thus ending with "myapp.exe" and multiple SVMs, such as "plugins.svm", "plugins02.svm" etc.
In order to load the "plugins.svm" in "myapp.exe" without importing it as a component (which would defeat the purpose as it would still blow up the size beyond 4GB), go to Settings-->Process Configuration-->SVMs.
In the SVM search pattern you enter a text string to specify the SVMs to be loaded during startup of the application.
You can specify a single SVM by entering something like
#APPDIR#\plugins.svm
or multiple SMVs by entering something like
#APPDIR#\plugins.svm;#APPDIR#\plugins02.svm
or even use a wildcard by entering something like
#APPDIR#\*.svm
All of the above examples imply that the desired SVMs exist in the application's folder. Else, use a different path.
If multiple SVMs are specified in one search pattern through the use of the '*' wildcard, the SVMs are applied in reverse-alphabetical priority.
If SVMs are specified by name (not with a wildcard), then the SVMs specified first in the list will take precedence over SVMs specified later in the list.
You can also make specific svm files Required, by adding them to the "Required SVM name" list. In this case, the application won't start if it doesn't find the SVM file in the specified location and will instead give an error message that a required SVM was not located.
I hope this will be of help to people trying to capture large applications and hitting the 4GB limit with Turbo (Spoon) Studio.

Displaying EUnit code coverage in Emacs

I am using Rebar to build my erlang project and want to integrate it more tightly with Emacs. I found that if I add {cover_print_enabled, true}. to my rebar config file I get code coverage in the build output.
However there is also an option cover_export_enabled which outputs a binary file of some form. Is there an emacs plugin to parse that file and color code my code to show what code is covered by tests?
I really don't like having to switch to a browser to see code coverage.
As far as I know, there is no such plugin.
The exported cover data file can be read as follows:
Read one byte, giving the length of the next term; let's call it N.
Read N bytes in Erlang binary term format. This can be decoded with binary_to_term/1.
If the term from step 2 is of the form {'$size',X}, then read X bytes and decode as a term. (This happens when the binary representation of the term is longer than 255 bytes.)
Continue from step 1, until end of file.
Distel has an Emacs Lisp implementation of binary_to_term called erlext-read-obj in erlext.el.
I haven't looked into what to do with the terms in the file, once decoded, but hopefully this is enough to get someone started. Read lib/tools/src/cover.erl if in doubt.
Just added this feature to rebar.el in commit https://github.com/leoliu/rebar.el/commit/9ba8699ff6310721226b93341e62491ebfd0ee99
Leo

zipping a file created by a progress application

Is there a way to zip/compress (with progress code) a file that I am creating with a progress application. More words words words words words.
try OUTPUT THROUGH zip > VALUE(File).
and to unzip it INPUT THROUGH unzip -c VALUE(file ) BINARY NO-CONVERT.
You'll need an external library for that, and then call it from the ABL language. Look for the HLC (High Level Calls) in the reference manual.
The usual tool for "light" zipping is mzip.
Be aware that not all 64-bit platform versions can make HLC calls due to limitations in their AVM binary structure being 32 bit.

Can I assume an executable file as a snapshot image of an execution state?

I read some unix manual (http://pubs.opengroup.org/onlinepubs/009695399/functions/posix_spawn.html), and there was a mention about execution.
The new process image shall be constructed from a regular executable
file called the new process image file.
The expression process image caught my eyes.
I have been thought executable file is just a kind of sequence of command. Just as the word program means. But actually, I don't know the concept and structure of the executable file. And I felt executable file could be looks like an execution state image from the mention.
Could you explain me something about this? About the concept and structure of regular executable files in nowadays. In any OS.
Usually the executable file does not contain only instructions but also global data, readonly data and many more. I suggest you briefly look e.g. on the ELF format widely used in UNIX-like operating systems or PE format used in Windows.
The OS may also need for example to replace some addresses of functions (jump targets) with the real addresses of these functions in the memory, although this technique is probably not used anymore in common OSes. Anyway, there can be more work to do than just copy the file into memory and start executing from the first byte.