p2hex(1)
okay bestie, this is p2hex(1) β she converts code files into hex files and she is literally built for it π
β¨
πΈ NAME πΈ
p2hex β convert code files into hex files. no cap, that's the whole assignment π«Ά
β¨ SYNTAX β¨
p2hex [ option(s) ] <name(s)> [ further options/names ]
π¦ DESCRIPTION π¦
P2HEX is the tool that takes the contents of one or several code files generated by AS and turns them into HEX files. A HEX file is a common way to represent binary data so it stays human-readable and can travel over non-transparent data lines. generally speaking, every byte of code or data gets represented by two characters showing that byte in hexadecimal notation. A HEX file also carries extra info like addresses and checksums that make processing the data easier.
Unfortunately there is no universally accepted standard format for HEX files. Instead, every processor manufacturer cooked up their own format, and some of those became βindustry standards.β P2HEX supports all the formats that seem to have gained acceptance, plus some variations that are commonplace. π
Arguments to P2HEX can be either command line parameters or file name specifications. Any argument that starts with +, -, or / is treated as a command line parameter (and it may take an additional command line argument); any other argument is treated as a file name. Generally P2HEX needs at least two file names: an input code file and the name of the HEX output file. If multiple file names are given, P2HEX always takes the last name as the output fileβs name.
If an input file name does not have an extension, the extension .p is added automatically. Similarly, the extension .hex is added automatically to the target fileβs name. Special case alert π¨: when only one file name is given, P2HEX takes its name as the source (possibly extended with .p), and the same name as target (with .hex as an additional or replaced extension).
By default, P2HEX chooses the HEX format that is most common for the processor family a source file contains code for. But bestie, that means if the source file(s) contain(s) code for different processor families, the HEX file might become an undesirable mixture of formats π. Use the -F command-line parameter to force a certain format then.
π COMMAND-LINE PARAMETERS π
If a command-line parameter starts with a slash (/) or minus sign (-), it turns an option on; if it starts with a plus sign (+), it turns a specific option off. Numeric arguments to parameters can be written in decimal or hexadecimal notation. For hexadecimal notation, prefix the number with a dollar ($) sign. In the list below, every option is shown in the form needed to change the default behaviour, which might be a plus or minus sign depending on whether the option is on or off by default.
p2hex accepts the following command-line parameters:
-aβ TellP2HEXto use relative addressing in the output HEX file. By default, addresses in the HEX file are exactly the same absolute addresses as they were in the code file. That can create problems with some EPROM-burners if your code does not start at address0. In relative mode, the address filterβs start address (see the-rcommand line switch) is subtracted from all address specifications in the HEX file (with the exception of the entry address). Therefore, addresses in the HEX file again start at0. β¨-d < <start address>-<stop address> >β TellP2HEXthat items in the address range given by the argument should be regarded as data rather than code. This option only has meaning for the TI-DSK format, which can differentiate between code and data. It is principally obsolete sinceP2HEXcan now directly process data from theDATAsegment. It should not be used in new projects, since it may be removed in the near future. β οΈ-e <address>β Set an entry address or modify an existing one. Some HEX file formats can carry a special record for an entry address that tells a program loader where to jump after a program has been loaded. Normally this address is generated byASif the programβsENDstatement has a label as argument, but this option lets you change the entry point or add one if it was forgotten in the program itself. π―-F <Default|Moto|Intel|Intel16|Intel32|MOS|Tek|DSK|C>β Force a certain format for the output HEX file. By default,P2HEXchooses one depending on the target processor. UsingDefaultas the argument also sets this behaviour, which might be useful to revert toP2HEXβs default behaviour if the default has been changed (see the discussion of theP2HEXCMDvariable below for presetting parameters).Motostands for the Motorola S-Record format, which allows addresses from 16 to 32 bits in length and entry addresses. It bears its name due to the fact that every record starts with the letterS.Intelis the βstandardβ Intellec-MCS8-Format for a variety of Intel 8-Bit-CPUs that almost became a standard, but was originally limited to 16-bit addresses. In later editions, the addressing capability was extended to 20 (Intel16) and 32 bits (Intel32).MOSis a simple format introduced by the manufacturer MOS for their line of 65xx CPUs. It is limited to 16-bit addresses, just like theTekformat that was defined by Tektronix.DSKis the format Texas Instruments uses for their line of 16-bit fixed-point signal processors. In contrast to all other formats, it is word-oriented and can distinguish between data and code segments. The page also says: βAtmel is the simple Hex format defined by Atmel for the AVR RISC family.β Keeping that fact exactly as given, bestie π«Ά
-f <number>[,<further numbers>]β Add<number>to the list of record header IDs that allow a record from a source file to be written to the target file. A certain header ID marks code for a certain target processor family; thus, this filter allows you to distill code for a certain processor out of a source file that contains code for different processor families. Negation of this parameter removes certain header IDs fromP2HEXβs list. See the user manual ofASfor a list of all possible header ID values. IfP2HEXβs list of header IDs is empty, no filtering takes place, i.e. all records from a source file will make it into the target file. π§-i <0|1|2>β Change the terminating line for an Intel-HEX file. Normally an Intel-HEX file is terminated with the line:00000001FF, but there are sources that also mention:00000001or:0000000000as the last line. The numeric argument selects one of these opportunities, with the first one being the default. This parameter only has an effect if the target fileβs format is one of the Intel-HEX variants. π-l <length>β Set the maximum number of bytes per record, and therefore the maximum length of a line in the target file. Possible values are between2and254bytes, with16being the default. π-m <0..3>β Set one of the four Intel-Hex variants defined by Microchip for the PIC family of microcontrollers. The default is theINHX8(0)format, which contains all words in a Lobyte-Hibyte-ordering.INHX16M(1)does just the opposite, whereasINHX8L(2)andINHX8H(3)only store the lower resp. higher bytes of each word. This parameter only has an effect if the target fileβs format is one of the Intel-HEX variants. π₯-r < <start>-<stop> >β Set a certain address range to be filtered out of the input file(s). Code that lies outside this range does not appear in the output file. The default for the address filter is0-$7fff, which might create confusion in some cases. As a special option,<start>and<stop>may consist of just a single dollar sign ($) β escape this in UNIX shells! β or0xto signify the lowest resp. highest address that occurs in the input file(s). Using this option implicitly enables a second pass over all input files to find the minimum and maximum values before conversion starts, reducing the speed ofP2HEXslightly. π¦-sβ In Motorola S-Record format, forceP2HEXto write a termination record after each group of data records, which may be necessary in some cases (but creates problems most of the timeβ¦). π+5β Disable output of Motorola S5-records, which contain the number of data records that were sent and therefore allow an additional level of checking. However, they are not understood by all programs and therefore might be a source of trouble. π-M <1|2|3>β ForceP2HEXto use a minimum length for the address fields of Motorola S-records. For example, a value of2will effectively disable S1 records, and a value of3will force usage of S3 records. The default is1, which enables full automatic setting of the S record length. β-avrlen <2|3>β Set the address field length of Atmel AVR Hex files to either two or three bytes (the latter is the default). π-kβ InstructP2HEXto erase the program source files after conversion. Yes bestie, that is exactly what it says: erase the source files after conversion. π-avrlen <2|3>β okay yes, same flag again: set the width of the address field used for the Atmel hex file format. By default,3-byte addresses will be used. The page literally lists this twice, so we are keeping both. π«
π PRESETTING PARAMETERS π
Parameters do not necessarily have to be given in the command line itself. Before processing of command line parameters starts, P2HEX looks to see if the P2HEXCMD environment variable is defined. If it exists, its contents are treated as additional command line parameters whose syntax is absolutely equal to normal command line parameters.
There is an exception if the variableβs contents start with a @ sign; in such a case, the string after the @ sign is treated as the name of a file that contains the options. Such a file (also called a βkey fileβ) has the advantage that it allows the options to be written in different lines, and it does not have a size limit. Some operating systems (like MS-DOS) do have a length limit on command lines and environment variable contents, so the key file may be your only option if you have a lot of lengthy parameters for P2HEX. π
π RETURN CODES π
p2hex may return with the following codes:
0β no errors. πΈ1β incorrect command line parameters. π2β I/O-error. π3β An input file had an incorrect format. π¨
π EXAMPLES π
ok so bestie, real talk β here's how you actually use this thing. To convert a file file1.p fully into its HEX representation on a Unix platform, just hit it with:
p2hex -r \$-\$ file1
and it's done, slay π . That's the whole vibe.
Now if you also wanna force usage of the Motorola S-Record format (iconic format ngl), add -F Moto to the mix:
p2hex -r \$-\$ -F Moto file1
two flags, one gorgeous output file, no cap π
π NATIONAL LANGUAGE SUPPORT π
p2hex supports national languages in the same way as AS does β same system, same energy, no surprises π«Ά. If you wanna know the deets, go see the manual page for asl(1) for more information about this. iykyk β¨
π TIPS π
Calling P2HEX without any arguments will print a short help listing all command line parameters. literally so handy β when in doubt, just run it with nothing and let it yap at you π no flags, no stress, just a little menu of possibilities πΈ
π¦ SEE ALSO π¦
the whole friend group fr fr π go read them too, they're all part of the same little tool family π
β HISTORY β
ok storytime π β P2HEX originally appeared as an AS tool in 1992, written in Borland-Pascal (yes bestie, Pascal, we love a vintage moment π), and was ported to C and UNIX in 1996. glow-up of the century honestly, we stan a resilient icon π§β¨
π BUGS π
Command line interpreters of some operating systems reserve some characters for their own use, so it might be necessary to give command line parameters with certain tricks (e.g., with the help of escape characters). yeah. the shell is fighting you. it happens π just escape things properly and you'll be fine.
Also β and this is the big one, so listen up β P2HEX does not have so far an opportunity to filter records by target segment. Instead, records that contain data for any other segment than CODE are completely ignored. so like. anything not CODE? gone. vanished. not invited to the party π important to know before you go debugging something that was never actually broken fr fr.
π AUTHOR(S) π
Alfred Arnold (alfred@ccac.rwth-aachen.de)
a legend, a pioneer, the main character of this manpage honestly π«Άπ
aaaand that's a wrap on the whole p2hex(1) manual page bestie β footer, source/version line and date included, all officially delivered to you with love πΈπ go forth and convert your files, you absolute icon. periodt. β¨ππ¦
π¦ where this page comes from
- opensuse-leap 16.0: asl 1.42_bld232-bp160.1.12 Β· GPL-2.0-only OR GPL-3.0-only
- opensuse-leap 16.0: asl 1.42_bld232-bp160.1.12 Β· GPL-2.0-only OR GPL-3.0-only
- opensuse-leap 16.0: asl 1.42_bld232-bp160.1.12 Β· GPL-2.0-only OR GPL-3.0-only
- opensuse-leap 16.0: asl 1.42_bld232-bp160.1.12 Β· GPL-2.0-only OR GPL-3.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms