Top 3 Alternatives To Ihex
I haven't seen an answer for this in the bootloader subjects so I will ask it. When you use a bootloader to download an intel hex file, does all of the hex file get downloaded to the flash? I am going to be sending my hex file to the bootloader from my pc using a serial connection. The intel hex file has the byte count, address, record type, data, and checksum. For instance a line of hex code like below::100000000C94CA140C94EB140C94EF1F0C94EB1486 doesn't all go into flash itself does it?
Doesn't 0C get loaded to address 0000 94 get loaded to address 0001 CA get loaded to address 0002 14 get loaded to address 0003 etc. Does the first 8 nibbels after the: just help me to write the bootloader so it knows what to do with the actual data? For instance the first 8 nibbles tell me that there is a byte count of 16 bytes at starting location 0000 with a record type of (00)data. Does only the data section itself of the above line(intel hex) get loaded to Flash and not the other information(byte count, address, record type)?
Quote: doesn't all go into flash itself does it? No if you are sending Intel Hex you have to decode this.
You take the 4 digit address to know which SPM page to put it in. You check the record type is 01 and ignore (or possibly act upon) others. You convert the data payload in 2 digit pairs from ASCII to single bytes that are put in the SPM page buffer. You know from the line length how many data pairs to process. You use the 2 digit Checksum at the end of the line to make sure you have received and read the entire line OK.
IHex is nice for bootloaders in that almost every terminal program has a 'send ASCII file' function and it's nice because it has the address info 'in band' so it does not need to be handled separately. It's also nice in that there's a definite 'end of data' record so you know when to stop (this is one of the non-01 record that you probably do want to recognize). The downsides are that the transfer involves more than 2 times the amount of data being programmed (actually more like 2.5 times) and also that the bootloader is bloated by requiring an iHex decoder built in. The alternative is to do a hex2bin on the file on the PC (avr-objcopy can easily do this) then send the resultant binary by some binary transfer mechanism (often X/Y/Z modem or perhaps Kermit). Again most terminals can do this kid of transfer. However X modem has no mechanism to pass the file length so if it's not an exact multiple of 128 (usually) byte packets then knowing the end can be tricky. Y and Z modem are better in this sense.
You are still faced with how to pass the destination address for the binary separately which is why 'protocols' like AV109 exist to have other record types for passing this kind of info 'out of band' but then a normal terminal program cannot do that knid of protocol. So your choice really as to how you want to engineer the world's 10 millionth AVR bootloader! (BTW see the Bootloader FAQ in the Tutorial Forum). Thanks for the info. I am writing a progam in C# on the pc which will take my hex file and trim each line of the hex file. I will send the page number and address first to my bootloader on the microcontroller then send the data section which will be placed in flash. From the hex file I will be able to count the bytes sent that way I know when to increment the page.
I could also do this on my microcontroller side but I can decrease the size of my bootloader my doing this on the PC side. On my microcontroller side I am using the AVR library bootloader functions which I can use to accomplish this task. Not sure exactly what you mean. If I convert the hex file to binary file wouldn't I still need to trim out the unnecessary info in the hex file like the address, byte count, etc.?
The info would still be there. I am sending it through the COM port which everything is in binary. Haha Yeah I know thats not what you mean but somewhere I am losing you. Plus I am not sure how I would use an image of that file with the AVC library functions which after looking at I seen to understand pretty well.
However, I would really like to know what you mean because I am lost about how to upload an image file without being a problem when it comes to dividing info up into pages in Flash. Uint8t flashimage256. 1024; to cater for even the biggest AVR. You can read a whole.hex file in, decode it all, then step through flashimage in chunks that are SPMPAGESIZE in size and if they are not 0xFF send the SPM page address and then SPMPAGESIZE bytes to be programmed.
BTW in a decent build environment you don't need to write Intel Hex decode yourself - you just link with and use the facilities of libbfd then your program can instantly read just about any binary encoding ever thought of (Intel Hex, Motorola SRec, ELF format, COFF format etc). :0E00000023C0FECFFDCFFCCFFBCFFACFF9CF50:10000E00F8CFF7CFF6CFF5CFF4CFF3CFF2CFF1CFC6:10001E00F0CFEFCFEECFEDCFECCFEBCFEACFE9CFF6.:1004AE00BA93AA930895182E862F612D192E972F81:1004BE00712D1B2EBF2FF12D1A2EAE2FE12D08956B:00000001FF - these records are indeed in order - the first has 14 bytes; the rest 16 - the flash likes to be written in pages to avoid complications - whatever the flash page size, these Intel HEX records will span every page boundary - depending on the toolchain and the version and the build options, there may be sections of the.HEX that are not. Quote: By creating an internal '.BIN' representation and then outputting in.HEX Or do it inside you PC Tx program (my flashmiage array above) and then just send pages to be program that are SPMPAGESIZE in length.
By the way sreccat from the Srecord package can also read/write iHex files and 'clean them up' to be properly ordered/padded if you want. (saves writing your own tool to do the same).
Sreccat also has clever tricks like being able to checksum a range of the input file and embed a CRC into the output.hex and so on. The point I'm trying to make is that if I'm creating a bootloader, I'm going to try to make things easy for the bootloader.
Generally, code space in the bootloader section is at a premium. The 'stuff' that the bootloader will process is given to it by e.g. A PC program, or say a file on an SD card. Let that preparation process do the hard work so that the 'stuff' is in the desired format and chunk size and whatever. Then the bootloader just needs to verify that the 'chunk' is correct-perhaps a checksum or CRC if serial comms, put the chunk into the page buffer, and output the page buffer when full. If you don't believe that think about how you will handle the fragment I posted where.HEX records span flash page boundaries.
Hex Editing: First Steps Hex-a-What? The hexadecimal notation is almost universally used in computing – and not without a reason. There are sixteen hex digits – 0 to 9, and A to F (which correspond to decimal values 10 to 15), and each hex digit represents exactly four bits.
Exactly two hex digits represent a byte, which can have a value from 00 to FF (that is from 0 to 255 decimal). In order to find a hex value of a multi-byte object, you would concatenate its bytes, for example, bytes 58 A4 1B FE constitute a four-byte value 58A41BFE (or FE1BA458 if the computer uses the reverse ). But why hexadecimal? Can't we just use good old decimal numbers? Well, they would be fine for a decimal computer, but most contemporary computers are binary and work on bits and bytes. A decimal digit represents approximately 3.3 bits, and this makes arithmetic too complicated.
Let's assume we have two bytes with decimal values 243 and 78. What will be the value of the two-byte word?
Top 3 Alternatives To Ihexohm
No, this method works with hexadecimal digits only. To find the decimal value of the word we must compute 243.256+78, which equals to 62286. Does not look very obvious, does it?
Imagine finding a value of an eight-byte long variable and you will see why the decimal notation is not the best choice for binary computers. Do I really need to know this? Yes, you should have some understanding of hexadecimal notation; in fact, there is not much else to know. Hex byte is the only kind of object a computer handles, and hex bytes are used to represent anything. For example, a hex byte 50 may represent the capital letter P, the processor command 'push eax', the decimal number 80, a color component with 31% brightness, or a zillion of other things. The obvious question is 'How can I tell what does the byte represent?'
Well, sometimes you can tell that easily, sometimes – not that easily, and in many cases you can't tell that at all. It is usually easy to recognize a character string, but in other cases you will have to guess. Fortunately, it is not as bad as it sounds, and you will quickly pick up a few tricks.
But for now it is enough to understand that 1) any computer data is just an array of hex bytes, and 2) a hex editor is a program that shows the true contents of a file, and lets you edit the data you normally can't. Main Edit Window It is time to try out our new knowledge and see what hex data looks like. Install if you haven't done it yet. Right-click any binary file in the Windows Explorer window and select Edit with FlexHEX. You will see the binary contents in the FlexHEX main edit window: You can see four distinct panes marked with different colors. The leftmost one is the Address pane; each number in the pane shows the address of the first byte of the corresponding line.
The only exception is the line on which the input caret is - it shows the address of the current byte, not the first one. The addresses are shown as hexadecimal numbers but if you point the mouse cursor to an address, the decimal value will appear in the Quick View popup window. The next is the Hex pane, which displays the file contents as an array of hex bytes. The light green ANSI pane shows the file contents as characters, and the rightmost UNICODE pane shows two-byte UNICODE characters.
Note that all three data panes show different representations of the same data. If you change data in any data pane, the other two will change accordingly. You can switch between the panes by pressing the Tab or Shift-Tab key, or just by pointing the mouse cursor and pressing the left mouse button. Inspecting Data Hex numbers may be good for computers, but how can one convert a hex number to a more human-friendly decimal value? First, select the number either with your mouse, or by using the arrows key while holding down the Shift key.
Second, move the mouse cursor to the selected area, and FlexHEX will display all the valid representations in the Quick View popup window. Sometimes there is no valid representation at all. For example, if you select five bytes, there will be no Quick View window because FlexHEX knows no object five bytes long. However any 1, 2, 4, 8, or 16 byte long field has at least one valid representation.
In general, when the mouse cursor changes to the arrow-with-question-mark shape, this means that FlexHEX has something to show you and the Quick View window is ready to appear. Editing Data Now that we know the basics let's go straight to hex editing. Start FlexHEX and you will see the main editing window with an automatically created new empty file. It has zero length but can be extended - the light gray boxes mark the positions where you can enter new data. Enter the hex bytes 4D 61 72 79 20 starting from the position 0, where the input caret initially was: Now press the Tab key to switch to the green ANSI pane and type in had a little lamb. It is easy to see that every byte in the Hex pane corresponds to some character in the ANSI pane. When you enter a hex value, the corresponding character appears in the ANSI pane and vice versa.
Don't be afraid to make a mistake – FlexHEX has unlimited Undo/Redo list. If you did something wrong, just press Ctrl-Z to undo the action. Editing Existing File A simple but rather typical task is to go to some address and replace some bytes. As an example we will change the byte string EB 1F 5F FB to 01 00 00 00 at the address 52E1C. The first step is to find the data to be modified. Select the Navigation / Go To command or just press Ctrl-G and enter the address: Don't forget to pay attention to the Dec/Hex selector.
FlexHEX is smart enough to recognize a hexadecimal number if it contains hex digits A to F, but if the number consists of decimal digits only, make sure you have selected the correct number radix. Now press the Go To button and you are there: We have found the data, but before typing in the new values check the Insertion Mode indicator in the.
If it displays OVERWRITE, the newly entered data will replace the data at the current position marked by the blinking input caret. The INSERT mode works differently. The existing data starting from the current position are shifted below, making place for the data you are entering. Note that this will change the position of all data objects below the insertion point. Many files get corrupted if their data have been shifted, so be careful and pay attention to the shift indicator in the. If the current mode is INSERT, press the Insert key to switch to the OVERWRITE mode.
Now type in the new hex data: You may have noticed that a new Modified tab has appeared in the Navigation panel. Click the tab to open the pane: This pane lists all modified areas in the file.
Click the area starting or ending address to jump there; to select the whole area, click the size field. Changing Typed Values Sometimes you need to make modification to a typed object, not just to a sequence of hex bytes. With FlexHEX, it is no more complicated than simple hex editing. Select the object (usually 1, 2, 4, 8, or 16 bytes long), right-click and select the Edit Selected As command from the menu: Select the appropriate representation and enter the new value.
Happy Hex Editing!