1150 Commits

Author SHA1 Message Date
Marius Greuel
8b147b4bcd Merge main branch 2023-01-09 19:27:38 +01:00
Joerg Wunsch
a8931a4eb1 Post-release 7.1 changes 2023-01-08 22:40:45 +01:00
Joerg Wunsch
2e0be1e1ae This is AVRDUDE release 7.1 2023-01-08 22:28:14 +01:00
mcuee
e226add045 Merge pull request #1268 from mariusgreuel/pr-update-actions
Update GitHub actions
2023-01-06 13:10:14 +08:00
Stefan Rueger
1b8a4d48ab Update NEWS 2023-01-05 17:40:07 +00:00
Stefan Rueger
5642cecb82 Merge pull request #1269 from mariusgreuel/pr-update-windows-hidapi
Update to latest MSVC fork of hidapi to include bug fixes
2023-01-05 17:39:02 +00:00
Marius Greuel
6e1f14bc7a Update to latest MSVC fork of hidapi to include bug fixes 2023-01-05 18:21:01 +01:00
Stefan Rueger
7250d3fea3 Update NEWS 2023-01-05 16:55:05 +00:00
Stefan Rueger
4c1192e884 Merge pull request #1266 from stefanrueger/avrcache
Silence page erase in cache code
2023-01-05 16:44:05 +00:00
Stefan Rueger
653d66b014 Ensure full words are loaded, low-byte first, for ISP programming (#1265) 2023-01-05 16:43:35 +00:00
Stefan Rueger
5328b798e4 Merge pull request #1264 from mariusgreuel/pr-msvc-readline-plan-b
Add readline library replacement for MSVC
2023-01-05 16:42:54 +00:00
Marius Greuel
739d3f85c3 GitHub actions: Use latest versions to remove warning 'Node.js 12 actions are deprecated' 2023-01-05 16:25:08 +01:00
Marius Greuel
0b9999610c Add x86 targets to Visual Studio settings file 2023-01-05 16:23:53 +01:00
Stefan Rueger
cf64837391 Silence page erase in cache code 2023-01-04 19:04:16 +00:00
Stefan Rueger
fdcfb543fc Improve guessBootloaderStart() for modern AVR 2023-01-04 18:52:51 +00:00
Marius Greuel
c2a90f41f0 Set MSVC readline version to 0x0502, some cleanup 2023-01-04 18:02:01 +01:00
Marius Greuel
7b3cfd2724 Add readline library replacement for MSVC 2023-01-04 08:02:48 +01:00
Stefan Rueger
8b0c9988fc Update NEWS 2023-01-03 23:16:27 +00:00
Stefan Rueger
2ca87126e5 Merge pull request #1260 from stefanrueger/avrintel
Clean up avrdude.conf.in fixing a couple of bugs
2023-01-03 20:50:41 +00:00
Stefan Rueger
b5e4ea62b9 Remove butterfly_page_erase() function
... as it raises expectations but
  - Wrongly claims to page erase eeprom but doesn't
  - Prints errors messages for all other memory types only
2023-01-03 20:46:36 +00:00
Stefan Rueger
eeb92b3c52 Change libreadline version from which it's OK to run from a pipeline 2023-01-03 16:31:50 +00:00
Joerg Wunsch
b6da4c167e Add a commented-out example for enabling parport 2023-01-03 13:53:03 +01:00
Stefan Rueger
1d6f23cae7 Update avrintel.[ch] fixing boot section sizes 2023-01-03 00:21:55 +00:00
Stefan Rueger
872af44fcd Fix boot section size of AT90SPWM2 and related parts 2023-01-03 00:19:38 +00:00
Stefan Rueger
f8635451a2 Change avdude.conf.in into canonical form
avrdude -p*/s -c*/s outputs how avrdude understands the programmers
and parts defined in avrdude.conf.in that syntax (the canonical
form). This commit ensures that avrdude.conf.in is in canonical
form, typically removing assignments that are redundant owing to
inheritance.

Also changes a couple of comments and one programmer description
string to be more expressive.
2023-01-03 00:06:37 +00:00
Stefan Rueger
5eddc33864 Set pin number or pin list rather than adding them
Pin definitions in config_gram.y fail to clear existing pin
definitions when setting them for the second time, eg, through
inheritance, For example,

programmer parent "ft2232h"
    id                     = "tigard";
    reset                  = 5; # BD5 (GPIOL1)
;

would add pin 5 to the existing pin 3 for reset from the partent
programmer rather than overwriting the reset pin.

This commit clears any pre-existing pin definition first before
assigning the new pin number or pin list (for vcc or buff).
2023-01-02 23:57:53 +00:00
Stefan Rueger
c44d0e9c73 Fix duplicate lockbits memory output of -p*/s
In order to output memories of a part always in the same order the
developer options use an odered list of all known memories. Owing
to the partial match feature of dev_locate_mem_noalias() they
would therefore print an existing lockbits memory twice, once for
the memory lock and once for the memory lockbits.
2023-01-02 22:22:34 +00:00
Stefan Rueger
82cf688357 Stop printing redundant usbpid and hvupdi_support lists for -c*/s 2023-01-02 21:59:51 +00:00
Stefan Rueger
abdc65d79f Shift initial current_struct setting from grammar to parser 2023-01-02 21:48:53 +00:00
Stefan Rueger
a301a3c4bc Update NEWS 2023-01-02 17:36:26 +00:00
Stefan Rueger
eca0fab1f7 Merge pull request #1258 from stefanrueger/usbsn
Move static usbsn into serdev structure, remove serno access function
2023-01-02 17:33:36 +00:00
Stefan Rueger
74cbb51ef5 Clarify comment on copying usbsn 2023-01-02 17:10:15 +00:00
Stefan Rueger
0a883973a2 Move static usbsn into serdev structure, remove serno access function 2023-01-02 16:55:33 +00:00
Stefan Rueger
8d8157bf8b Merge pull request #1255 from dl8dtl/add_q_terminal_command
Add a "q" command to the terminal
2023-01-02 14:28:49 +00:00
Stefan Rueger
b5cabc1dcf Move q command to end of list 2023-01-02 14:26:11 +00:00
Stefan Rueger
bc198fd18d Merge pull request #1256 from stefanrueger/partial-matches
Fix partial matches for locate_mem() and do_cmd()
2023-01-02 14:23:25 +00:00
Bas Wijnen
dc0ab33a58 Change definition of NO_PIN to 1+PIN_MAX (#1231)
Fixes bug #1228 that gpio 0 could not be used by the linuxgpio system.

* Add sanity checks
* Loop over defined pins only

Co-authored-by: Stefan Rueger <stefan.rueger@urclocks.com>
2023-01-02 14:23:01 +00:00
Stefan Rueger
17e2feff26 Fix partial matches for locate_mem() and do_cmd() 2023-01-01 23:29:06 +00:00
Joerg Wunsch
b6d50ef0a9 Extend the comment for the serial number function
Hint that it is actually a function pointer rather than a serial
number itself (in whatever form).
2023-01-01 22:36:50 +01:00
Joerg Wunsch
e45195d643 Add a "q" command to the terminal
"q" used to be a unique abbrevation for "quit" before the introduction
of the "quell" command, and it was an easy way to exit terminal mode.

By adding it as an explicit command (must be before all longer
commands starting with "q"), this functionality is regained.
2023-01-01 22:33:30 +01:00
Joerg Wunsch
06e999b8c5 Check whether serial_serno is not NULL before calling it.
For devices connected through a real serial device rather than
USB, there is no transport-layer serial number available.

stk500v2.c (and jtag3.c) tried to always call this function.

Closes #1254
2023-01-01 22:23:44 +01:00
Stefan Rueger
b2c03f5d40 Update NEWS 2022-12-31 16:14:49 +00:00
Stefan Rueger
f0649d76da Merge pull request #1251 from stefanrueger/urclock-drain
Guard urclock_getsync() against initial spurious input
2022-12-31 14:59:43 +00:00
Stefan Rueger
d09b83079c Merge pull request #1248 from mariusgreuel/pr-fix-win32-ser_recv-timeout
Make WIN32 implementation of ser_recv() fail on time-out
2022-12-31 14:58:42 +00:00
Stefan Rueger
9c3263a851 Merge pull request #1247 from mariusgreuel/pr-silence-conf-path-detection
Silence conf path detection debug output
2022-12-31 14:57:27 +00:00
Stefan Rueger
90dfee80ba Change info on libreadline to notice2 level 2022-12-31 12:42:12 +00:00
Stefan Rueger
ac10272bb6 Lengthen delay after reset for benefit of autobaud bootloaders 2022-12-31 12:27:07 +00:00
Stefan Rueger
ab3da9f87c Guard urclock_getsync() against initial spurious input 2022-12-30 21:05:57 +00:00
Marius Greuel
161e25e886 Correct messages in WIN32 net_recv() 2022-12-30 12:13:36 +01:00
Marius Greuel
894d4cba10 Make WIN32 implementation of ser_recv() fail on time-out 2022-12-29 15:35:20 +01:00
Marius Greuel
d001172b46 Silence conf path detection debug output 2022-12-29 11:55:15 +01:00
Stefan Rueger
0f956e90eb Update NEWS 2022-12-29 03:05:09 +00:00
Stefan Rueger
d91c33b5e3 Merge pull request #1243 from mariusgreuel/pr-cmake-updates
CMake updates
2022-12-29 03:03:57 +00:00
Stefan Rueger
e2dc3621db Update NEWS 2022-12-29 03:03:08 +00:00
Stefan Rueger
b11475f077 Merge pull request #1246 from stefanrueger/urclock-sync-ftdi
Modify recv timeouts to accommodate urclock sync with ftdi
2022-12-29 02:59:42 +00:00
Stefan Rueger
50a5d87a4e Modify recv timeouts to accommodate urclock sync with ftdi 2022-12-28 15:30:38 +00:00
Stefan Rueger
92f980d15f Update NEWS 2022-12-28 13:21:28 +00:00
Stefan Rueger
71b7e6d51f Downgrade flash read unsupported err msg to notice 2022-12-28 13:16:53 +00:00
Joerg Wunsch
8a4ab97360 Remove trailing white space in NEWS 2022-12-28 08:58:33 +01:00
Marius Greuel
724fd9d572 CMake: Add Visual Studio settings file 2022-12-27 16:38:48 +01:00
Marius Greuel
a138ec259f CMake: Rename option USE_EXTERNAL to USE_EXTERNAL_LIBS 2022-12-27 16:35:36 +01:00
Marius Greuel
80740071e2 CMake: Remove unused MSVC disable warning options 2022-12-27 16:31:49 +01:00
Marius Greuel
7a5883b75d CMake: Bump minimum version to 3.14 2022-12-27 16:31:28 +01:00
mcuee
46368b7059 Update NEWS 2022-12-27 22:43:27 +08:00
mcuee
3e08177450 Merge pull request #1242 from mariusgreuel/pr-add-ft2232h-support
Add FT2232H support for Windows, Tigard programmer
2022-12-27 22:12:36 +08:00
Marius Greuel
f220656e0b CMake: For MSVC builds, use latest libftdi for Windows 2022-12-27 13:35:52 +01:00
Marius Greuel
805db5b13e Add tigard programmer 2022-12-27 13:17:27 +01:00
Marius Greuel
aed9e1b7fa Improve FTDI programmer documentation 2022-12-27 13:09:00 +01:00
Marius Greuel
9412413fca Make 2232hio programmer derive from ft2232h 2022-12-27 13:05:38 +01:00
Marius Greuel
252d6833d4 Add ft4232h programmer 2022-12-27 13:03:41 +01:00
Marius Greuel
5d0f151f4a Add ft2232h programmer for consistency with existing ft232h programmer 2022-12-27 13:00:57 +01:00
mcuee
0c0da9162c Merge pull request #1237 from MCUdude/print-expected-signature
Print expected signature when the one read by the programmer doesn't match the expected one
2022-12-27 08:56:25 +08:00
mcuee
afb72c998e Merge pull request #1241 from mcuee/build_sh_netbsd
Update build.sh for NetBSD
2022-12-27 08:53:51 +08:00
mcuee
d4bef10e30 Update build.sh for NetBSD
https://github.com/avrdudes/avrdude/issues/1177#issuecomment-1336364197

This is to address issue https://github.com/avrdudes/avrdude/issues/1177 for NetBSD
2022-12-27 08:43:26 +08:00
mcuee
eba5cea8e1 Merge pull request #1240 from mcuee/build_sh_linux
To work around Issue #1107
2022-12-27 08:36:25 +08:00
mcuee
2c4f2ada3f To work around Issue #1107
https://github.com/avrdudes/avrdude/issues/1107#issuecomment-1265873339
2022-12-27 08:25:43 +08:00
mcuee
49834a47cd Merge pull request #1239 from mcuee/macos_action
Temporarily disable brew update in macOS github action
2022-12-27 08:02:10 +08:00
mcuee
39ab053937 Temporary disable brew update in macOS github action 2022-12-27 07:52:31 +08:00
MCUdude
57cfced151 Print expected signature
... when the one read by the programmer doesn't match the expected one.
2022-12-25 18:23:53 +01:00
Stefan Rueger
857344295c Merge pull request #1234 from stefanrueger/docs
Mention developer options in documentation and Usage()
2022-12-23 13:17:43 +00:00
Stefan Rueger
292f1d54b9 Update NEWS 2022-12-21 19:14:50 +00:00
Stefan Rueger
217adc543b Merge pull request #1233 from janegilruud/fix-pickit4-snap-jtag
#1052 Add JTAG support for PICkit4 and Snap.
2022-12-21 19:12:33 +00:00
Stefan Rueger
c2070d44c7 Merge pull request #1226 from stefanrueger/optiboot-eeprom
Hint at -xeepromrw option in EEPROM error messages
2022-12-21 19:12:06 +00:00
Hans
c991ae9739 Read programmer serial number from libusb or hidusb (#1223)
* Silence compiler warnings

* Fix a fall-through error in switch

* Slightly reformat programmer info printout
Now the target voltage is printed out along with the HW version, FW version and serial number, and they all allign nicely. When in ISP mode, the "SCK period" value is printed _after_ the target voltage readout, and _before_ the additional clocks the programmer holds, such as JTAG, PDI and UPDI clocks.

Co-authored-by: Stefan Rueger <stefan.rueger@urclocks.com>
2022-12-21 19:11:31 +00:00
Stefan Rueger
a696c94d8f Merge pull request #1220 from stefanrueger/terminal-prompt
Remove extraneous avrdude> prompt at end of terminal session
2022-12-21 19:09:51 +00:00
Stefan Rueger
b29dfb77e9 Merge pull request #1219 from MCUdude/pic-mode-recovery
Add alternative USB PID for PICkit4/SNAP in PIC mode
2022-12-21 19:09:34 +00:00
Stefan Rueger
3c152dc122 Merge pull request #1216 from MCUdude/slow-clock-error
Print meaningful error when a too slow ISP clock is detected
2022-12-21 19:09:11 +00:00
Stefan Rueger
41c9ed02e3 Mention developer options in documentation and Usage() 2022-12-21 19:06:26 +00:00
Stefan Rueger
435343bab3 Add more bootloader hashes 2022-12-20 23:25:43 +00:00
Stefan Rueger
c6633fedce Emphasise -xeepromrw and -xbootsize=<n> in documentation 2022-12-20 22:40:27 +00:00
Jan Egil Ruud
a2ae465484 #1052 Update PICkit4 and Snap documentation with new modes. 2022-12-20 22:47:06 +01:00
Stefan Rueger
4d9d4050e0 Add hashes for optiboot bootloader instantiations 2022-12-20 21:37:20 +00:00
Jan Egil Ruud
918e01d93d #1052 Remove AVR32JTAG support for PICkit4 and Snap. 2022-12-20 12:02:42 +01:00
Jan Egil Ruud
d1010fd46f #1052 Add JTAG support for PICkit4 and Snap. 2022-12-20 11:59:00 +01:00
Stefan Rueger
3b14c2df77 Hint at -xeepromrw option in EEPROM error messages 2022-12-17 18:40:09 +00:00
MCUdude
0be8f3b82d Start sentence with lower case character 2022-12-16 20:27:20 +01:00
Stefan Rueger
412eb9503e Remove extraneous avrdude> prompt at end of terminal session 2022-12-14 23:17:44 +00:00
MCUdude
30e90bdfd2 Add alternative USB PID for PICkit4/SNAP in PIC mode 2022-12-14 20:11:43 +01:00
Stefan Rueger
159d12693e Update NEWS 2022-12-14 00:27:13 +00:00
Hans
95363a11a7 Terminal read improvements (#1209)
* Preserve last address read from and length when reading a memory
* Add support for "graceful" memory read rollover
* Add extra padding for memories larger than 64kiB
* Bu default, don't read more bytes than the memory contains
* Prevent users from reading the same memory address twice
* Remove >>> echo and print read/dump command
* Only echo dump command in verbose mode
2022-12-14 00:10:30 +00:00
Stefan Rueger
bbd3ed21ef Merge pull request #1208 from stefanrueger/urclock-updi
Add urclock support for parts with bootloaders in low flash
2022-12-14 00:08:27 +00:00
Jörg Wunsch
b10854677d Consider libedit only in interactive mode (#1207) 2022-12-14 00:07:41 +00:00
Stefan Rueger
72f097502f Merge pull request #1206 from stefanrueger/nsafety
Fix reading of .elf files
2022-12-14 00:06:47 +00:00
Stefan Rueger
e4f10a33ab Clarify comment 2022-12-13 23:59:58 +00:00
Stefan Rueger
9bd4dee254 Merge pull request #1205 from janegilruud/jtag3-tpi-jer
Added TPI support for Microchip tools
2022-12-13 23:56:25 +00:00
Jan Egil Ruud
f08f771ab4 #822 Fixed print_parms for TPI. 2022-12-13 15:07:14 +01:00
Jan Egil Ruud
af43a7757d #822 Print Vtarget when using TPI. 2022-12-12 14:31:41 +01:00
Jan Egil Ruud
2561d87fbd #822 Removed JTAGICE3 TPI support. 2022-12-12 14:10:42 +01:00
Stefan Rueger
db0258a7d8 Add fuses, usersig, userrow, signature and data to elf_mem_limits() 2022-12-10 23:28:56 +00:00
Stefan Rueger
8024bfd4fb Add partial urclock support for parts with bootloaders in low flash 2022-12-03 23:20:05 +00:00
Stefan Rueger
6b03d7dc5a Correct upper flash boundary for 8-bit AVR parts in elf_mem_limits() 2022-12-03 13:39:28 +00:00
Stefan Rueger
23dddef64b Mark unused function parameters as such 2022-12-02 19:03:06 +00:00
Stefan Rueger
f688baabb7 Improve error messaging 2022-12-02 18:45:47 +00:00
Stefan Rueger
2e98ee3a1c Check elf section fits into memory and fail elf2b() on elf handling errors 2022-12-02 18:28:19 +00:00
Stefan Rueger
3b30e5d424 Fix elf2b() to consider all sections in segments 2022-12-01 20:29:54 +00:00
Stefan Rueger
0ae632070f Rewrite elf2b() in equivalent way absorbing elf_get_scn() 2022-12-01 20:21:33 +00:00
Jan Egil Ruud
8db18e64ed Remove redundant mem-check. 2022-12-01 20:12:26 +01:00
Jan Egil Ruud
dc64fb716f Fix wrongfully call to initCache() according to stefanrueger's instructions. 2022-12-01 20:05:55 +01:00
Jan Egil Ruud
f78e14ee96 Revert "Skip chaching when size of memory is 0."
This reverts commit bb808e8d5f.
2022-12-01 20:01:11 +01:00
Jan Egil Ruud
bb808e8d5f Skip chaching when size of memory is 0. 2022-12-01 15:16:23 +01:00
Jan Egil Ruud
e18b5c4fb0 Made the code a little prettier. 2022-12-01 00:01:29 +01:00
Jan Egil Ruud
b643f0a1a0 #822 Fixed bug in TPI byte write for ATtiny20 and ATtiny40. 2022-11-30 23:49:20 +01:00
Jan Egil Ruud
b52bd393de #822 Added TPI support for JTAGICE3. 2022-11-30 23:39:37 +01:00
Jan Egil Ruud
95160e8801 Changed verbose level on TPI initialize notice. 2022-11-30 23:21:30 +01:00
Jan Egil Ruud
e87a9b59b6 #822 Added and tested TPI support for AtmelICE, PowerDebugger, PICkit4 and Snap. 2022-11-30 23:08:55 +01:00
Jan Egil Ruud
1eb6a06055 #822 Small refactoring and clean up. 2022-11-30 23:07:05 +01:00
Jan Egil Ruud
cad296f780 Attempt to fix msvc builds. 2022-11-30 00:27:25 +01:00
Jan Egil Ruud
90bd24a902 #822 Added support for TPI page write. 2022-11-30 00:14:19 +01:00
Stefan Rueger
ea2d7eec95 Fix fopen() file mode in fileio_fmt_autodetect() 2022-11-29 19:46:48 +00:00
Jan Egil Ruud
2f5566a8ed #822 Added support for TPI page load. 2022-11-29 20:34:05 +01:00
Jan Egil Ruud
f2156b834d #822 Added sigrow memory to tiny102 and tiny 104, and removed duplicate lockbits. 2022-11-29 09:52:45 +01:00
MCUdude
2d7ad8e373 Print meaningful ISP clock error message
Currently, only some JTAG3 compatible programmers are able to detect that the connected target's main clock speed actually is too low for for the programmer.
In this case, these will return 0xCC.
2022-11-27 22:52:45 +01:00
MCUdude
6385fb09f7 Add missing stk500v2 status constants 2022-11-27 22:41:29 +01:00
Stefan Rueger
2f2a6c0008 Update NEWS 2022-11-27 19:12:19 +00:00
Stefan Rueger
bb14386f63 Merge pull request #1199 from stefanrueger/userrow
Fix userrow size and page_size for ATtiny3216 and ATtiny3217
2022-11-27 19:05:25 +00:00
Stefan Rueger
2ac582fa02 Merge pull request #1198 from stefanrueger/delay
Tie up loose ends for urclock programmer
2022-11-27 19:04:07 +00:00
Stefan Rueger
58e2bca42c Update n_interrupts in avrdude.conf.in and introduce eind 2022-11-27 16:56:49 +00:00
Stefan Rueger
5a0975aee7 Allow / as path deliminator in Windows for urclock metadata 2022-11-27 14:44:46 +00:00
Stefan Rueger
0c96f5d6dc Calibrate urboot's -xdelay for windows 2022-11-27 13:57:37 +00:00
Stefan Rueger
ba9d24fdd2 Fix userrow size and page_size for ATtiny3216 and ATtiny3217 2022-11-26 17:37:51 +00:00
Stefan Rueger
0e0a0ba0eb Get boot section info from avrdude.conf and not from avrintel.c 2022-11-26 13:53:46 +00:00
Stefan Rueger
d774e87a59 Update documentation re the urclock programmer 2022-11-26 13:23:25 +00:00
Stefan Rueger
3a5f3735ba Adapt urclock_getsync() to consider legacy bootloaders 2022-11-26 12:54:42 +00:00
Stefan Rueger
baa52e3a02 Update NEWS 2022-11-25 23:35:37 +00:00
Stefan Rueger
1cb169ec93 Establish avr_*timestamp() routines for timing 2022-11-25 22:09:02 +00:00
Stefan Rueger
231e88aaf9 Add autobaud_sync to avrdude.conf part description 2022-11-25 19:20:45 +00:00
Stefan Rueger
d2a2ec1d1b Merge pull request #1194 from stefanrueger/exitrc
Fix shell exit value when chip erase is delayed to next flash write
2022-11-25 17:50:01 +00:00
Stefan Rueger
bbc52499e7 Merge branch 'main' into exitrc 2022-11-25 17:43:13 +00:00
Stefan Rueger
2cecf66a61 Merge pull request #1191 from stefanrueger/jtagice_mkii
Fix parameters for JTAGICE mkII and devices with bootloaders
2022-11-25 17:40:54 +00:00
Stefan Rueger
10ca3661bb Merge pull request #1190 from stefanrueger/bootloader-hash
Provide bootloader-hash tool
2022-11-25 17:40:36 +00:00
Stefan Rueger
664b1aa1f6 Merge pull request #1189 from stefanrueger/culture
Deprecate mosi/miso in favour of sdo/sdi
2022-11-25 17:40:25 +00:00
Stefan Rueger
607f0c48be Merge pull request #1188 from stefanrueger/not-all-is-nor-memory
Pad pages with input file contents before avr_write()
2022-11-25 17:40:11 +00:00
Stefan Rueger
289ca4f34c Add optiboot_lgt8f328p.hex bootloader hashes to urclock.c 2022-11-25 17:26:17 +00:00
Stefan Rueger
7269370bf6 Change notices about libreadline presence in urclock.c 2022-11-25 13:58:11 +00:00
Stefan Rueger
e6f7e158cd Change periphery to peripheral; document deprecated miso/mosi are now sdi/sdo 2022-11-24 13:18:06 +00:00
Stefan Rueger
2b3534ea8a Remove tabs and reformat 2022-11-24 12:36:49 +00:00
Stefan Rueger
8e79b7dc52 Fix error detection for reading a page to pad unset bytes 2022-11-24 12:16:43 +00:00
Stefan Rueger
68c6ffd7fc Silence compiler warnings, change comments, remove typos 2022-11-24 12:14:54 +00:00
Stefan Rueger
afa57ace84 Merge pull request #1196 from mcuee/disable_readline_msvc
Disable GNU Readline for MSVC build
2022-11-24 10:13:51 +00:00
mcuee
01ed17bd5c Disable GNU Readline for MSVC build
This is to work around the issue of finding the wrong libreadline.a from Strawberry Perl for Windows MSVC github action.

Reference:
https://github.com/avrdudes/avrdude/pull/1194#issuecomment-1325824150
2022-11-24 13:22:12 +08:00
Stefan Rueger
c3413ff0f4 Fix shell exit value when chip erase is delayed to next flash write 2022-11-23 19:53:55 +00:00
Jan Egil Ruud
f9a2bd0327 Got added support for reading and writing fuses, and chiperase. 2022-11-23 14:25:14 +01:00
Stefan Rueger
19cd7d8c69 Remove non-stk500v1 bootloaders from urclock hash table 2022-11-22 22:38:43 +00:00
Stefan Rueger
d3b14f21f9 Provide bootloader-hash tool 2022-11-22 22:38:09 +00:00
Stefan Rueger
b925b5113d Silence compiler warnings 2022-11-22 21:49:26 +00:00
Stefan Rueger
25ca91371d Pad pages with input file contents before avr_write() 2022-11-22 21:32:42 +00:00
Stefan Rueger
33dd231e4c Silence some compiler warnings 2022-11-22 21:17:39 +00:00
Stefan Rueger
8c73609c0e Fix parameters for JTAGICE mkII and devices with bootloaders 2022-11-22 21:02:25 +00:00
Stefan Rueger
796e97ee3a Update avrdude.conf.in wrt n_boot_sections, boot_section_size, eecr, spmcr 2022-11-22 20:49:12 +00:00
Stefan Rueger
9599bf2243 Add n_boot_sections and boot_section_size to part definitions 2022-11-22 20:44:12 +00:00
Stefan Rueger
7d5ab433ca Replace gratuitous references to slave and master with technical terms 2022-11-22 17:11:33 +00:00
Stefan Rueger
adc333ea54 Deprecate mosi/miso in favour of sdo/sdi
See https://www.oshwa.org/a-resolution-to-redefine-spi-signal-names/
2022-11-22 17:04:05 +00:00
Jan Egil Ruud
5dc2545716 Cleaned and improved TPI send and receive. 2022-11-22 14:05:01 +01:00
Jan Egil Ruud
3afdd55089 Get rid of TPI magic numbers. 2022-11-22 13:23:57 +01:00
Jan Egil Ruud
32a6ca39e4 Cleaned up whitespace in jtag3.c so it at least is consistent within the file. 2022-11-22 13:05:14 +01:00
Stefan Rueger
883d9494c8 Silence compiler warnings for urclock.c 2022-11-22 01:39:27 +00:00
Stefan Rueger
05d78828e0 Update NEWS 2022-11-22 01:29:07 +00:00
Stefan Rueger
eee17ab096 Merge pull request #1187 from mcuee/revert_pr1156
Revert PR #1156
2022-11-22 01:19:10 +00:00
Stefan Rueger
ef824d4d89 Merge pull request #1184 from mcuee/cmake_print_readline
Print HAVE_LIBREADLINE status
2022-11-22 01:18:56 +00:00
Stefan Rueger
9c30ccc6ea Merge pull request #1175 from stefanrueger/terminal
Make terminal write's automatic number width less surprising
2022-11-22 01:18:30 +00:00
Stefan Rueger
3400527c7d Merge pull request #1174 from stefanrueger/default_programmer
Ensure default_programmer from config files is used
2022-11-22 01:17:55 +00:00
Cristiano De Alti
c3acdccbe5 Fix JTAGICE mkII by removing the initialize call after CMD_CHIP_ERASE_ISP (#1172)
- The extra call to initialize() sends CMD_ENTER_PROGMODE_ISP causing a flash
   verification mismatch
2022-11-22 01:17:19 +00:00
Stefan Rueger
02e02be6f9 Merge pull request #1171 from stefanrueger/urclock
Provide Urclock programmer
2022-11-22 01:13:57 +00:00
Stefan Rueger
2063671a02 Merge pull request #1147 from mcuee/Xplained_Pro_PDI
Add xplainedpro_pdi programmer
2022-11-22 01:13:23 +00:00
Stefan Rueger
f9aea24fba Reduce drain timeout value for Windows in urclock.c 2022-11-22 00:49:34 +00:00
Stefan Rueger
2e398916a7 Hash known bootloaders for urclock; they don't need -xbootsize=.... 2022-11-22 00:47:26 +00:00
mcuee
b1b8d95154 Update build.yml to remove readline under macOS
This commmit updates github action to remove the needs of GNU Readline under macOS, after the merge of PR avrdudes#1185.
2022-11-22 06:59:29 +08:00
mcuee
4c8a900452 Remove the needs of readline under macOS
This commmit updates build.sh to remove the needs of GNU Readline under macOS, after the merge of PR #1185.
2022-11-22 06:56:37 +08:00
Joerg Wunsch
8a61ae5acf PR 1181 and 1185 done 2022-11-21 23:33:37 +01:00
Jörg Wunsch
3892c5a459 Merge pull request #1181 from dl8dtl/add_em_evr_for_openbsd
Add fallback for EM_AVR
2022-11-21 23:31:14 +01:00
Jan Egil Ruud
10ccf0f515 Initial commit for jtag3 TPI support. Can read signature on ATtiny104 XPlained mini, but nothing else yet. 2022-11-21 21:18:13 +01:00
Jörg Wunsch
13e0bd030f Merge pull request #1185 from dl8dtl/workaround_1173
Add a workaround for issue #1173
2022-11-21 15:56:40 +01:00
Joerg Wunsch
461d75bbc7 Add Marius to the dev team as well
Marius handles the MSVC and CMake staff as well as the Github
runners.
2022-11-21 09:41:46 +01:00
Joerg Wunsch
f90e36f231 Add a workaround for issue #1173
The readline compat layer for libedit which otherwise provides native
readline functionality in NetBSD and MacOS appears to have a bug that
causes subsequent prompts to be delayed until another line is being
processed.

Re-installing the callback over and over again works around that, and
does not seem to harm with GNU libreadline.
2022-11-20 22:52:41 +01:00
Stefan Rueger
7f4474f049 Delete previous metadata when writing new file to flash in urclock 2022-11-20 13:02:51 +00:00
Stefan Rueger
c0e4dd494e Use file basename in -c urclock metadata under WIN32 2022-11-20 01:48:39 +00:00
mcuee
df4dccabfc Update configure.ac to print libreadline status 2022-11-20 09:46:07 +08:00
Stefan Rueger
53de22cb83 Update avrintel.c for LGT8F(8|16|32)8P parts 2022-11-20 01:12:14 +00:00
Stefan Rueger
f276d325ec Handle verification errors in read only memory areas gracefully 2022-11-20 00:27:49 +00:00
Stefan Rueger
ee25a62df6 Emulate chip erase in terminal when pgm->chip_erase() soft fails 2022-11-19 23:09:18 +00:00
Stefan Rueger
d65a9a3cee Adapt -c urclock to new reset vector protection in urboot v7.7 2022-11-19 19:39:39 +00:00
mcuee
c9357132fa Print HAVE_LIBREADLINE status 2022-11-19 17:22:04 +08:00
Joerg Wunsch
ff478dcb83 PR 1182 done 2022-11-19 10:00:20 +01:00
Jörg Wunsch
6c3ce22b1e Merge pull request #1182 from dl8dtl/rewrite_authors
Rewrite authors/copyrights
2022-11-19 09:55:23 +01:00
Joerg Wunsch
77ad26ddf4 Replace the hint to AUTHORS by an URL
Suggested by: Hans
2022-11-18 21:24:10 +01:00
Joerg Wunsch
efad24e3de Rewrite authors/copyrights 2022-11-18 10:31:45 +01:00
Joerg Wunsch
2fc351750e Add Stefan and Xiaofan to the list of authors 2022-11-18 10:26:01 +01:00
Joerg Wunsch
908e6b15da Add NetBSD and OpenBSD to the build script 2022-11-17 21:20:07 +01:00
Joerg Wunsch
9df522a219 Add <sys/select.h> where appropriate
Under Posix systems, this header is documented to be required
when using select().
2022-11-17 14:14:22 +01:00
Joerg Wunsch
01be288b18 Add fallback for EM_AVR
OpenBSD still lacks this definition, so provide our own for
them.
2022-11-16 21:21:51 +01:00
Stefan Rueger
a3eeedd176 Silence some compiler warnings 2022-11-16 02:32:32 +00:00
Stefan Rueger
2abb666bd2 Prepare urclock for autobaud synchronisation 2022-11-16 02:08:13 +00:00
Stefan Rueger
d901e0a768 Update urbootPutVersion() to reflect urboot v7.7 changes 2022-11-16 00:42:36 +00:00
Stefan Rueger
82b9491cbd Harden urclock against bootloader bricking
- Detect write restrictions with new pgm->readonly(..., addr)
 - Check in byte-wise cached write whether mem/addr allows write
 - Emulated chip erase tells user CE is delayed until first -U
 - After bootloader CE urclock_chip_erase will init reset vector
 - Low level paged write @ 0 unconditionally protects reset vector
 - Low level paged read @ 0 checks and repairs reset vector
2022-11-16 00:08:46 +00:00
Stefan Rueger
afc2f7cf0c Hint at option -xdelay=... for urclock programmer not responding messages 2022-11-12 13:47:48 +00:00
Stefan Rueger
ff9c8bbe46 Silence min()/max() compiler warnings, fix urclock.c typo etc 2022-11-12 13:32:53 +00:00
Stefan Rueger
e2b69dec75 Remove MacOS compiler warnings for urclock.c 2022-11-12 01:12:31 +00:00
Stefan Rueger
b178deef5f Handle n_page_erase in urclock for parts t441, t841 and t1634 2022-11-11 01:33:42 +00:00
Stefan Rueger
6e3a99be87 Add write statistics for patched flash input files at notice2 level 2022-11-11 01:27:55 +00:00
Stefan Rueger
22bd977365 Indent erasing chip message in main 2022-11-10 23:18:43 +00:00
Stefan Rueger
c67bfe39a3 Show input file staistics before patching in update.c 2022-11-10 23:00:18 +00:00
Stefan Rueger
321bddbf7b Rename urclock's option forcetrim to restore 2022-11-10 22:35:40 +00:00
Stefan Rueger
2434c3f7f6 Make terminal write's automatic number width less surprising 2022-11-10 19:38:21 +00:00
Stefan Rueger
4c4952d4f6 Ensure default_programmer from config files is used 2022-11-10 18:20:13 +00:00
Stefan Rueger
afa408e2c6 Make urclock.c iron out a bug in some bootloaders 2022-11-09 21:00:16 +00:00
Stefan Rueger
d5d0b940cc Harden vector bootloaders more against reset overwrites 2022-11-09 19:28:29 +00:00
Stefan Rueger
84a3e2cc2b Fix avr.c comment 2022-11-09 19:27:34 +00:00
Stefan Rueger
c7ba53bca0 Harden urclock against terminal time outs and vector overwrites 2022-11-09 16:16:59 +00:00
Stefan Rueger
ea65918dca Omit verify after write failure in term.c 2022-11-09 15:43:57 +00:00
Stefan Rueger
20b86fb739 Warn in uclock when bootloader cannot read/write memories 2022-11-08 20:16:05 +00:00
Stefan Rueger
6a6d333849 Update urclock documentation 2022-11-08 15:18:30 +00:00
Stefan Rueger
cf3c81f714 Update urclock's -x parameters 2022-11-07 18:01:23 +00:00
Stefan Rueger
715db4c690 Make -A default for urclock programmer 2022-11-07 02:43:34 +00:00
Stefan Rueger
21d93ec8cb Update urclock programmer 2022-11-07 01:26:47 +00:00
Stefan Rueger
e6c26d8db4 Provide urclock programmer 2022-11-06 01:29:07 +00:00
Stefan Rueger
4c92030e3a Update NEWS 2022-11-01 18:20:06 +00:00
Stefan Rueger
d211c4e5f5 Merge pull request #1164 from MCUdude/hvupdi-type2-fix
Fix Type 2 HV UPDI
2022-11-01 18:17:52 +00:00
Stefan Rueger
02fe08aed2 Open programmer before allocating part
So any programmer that knows exactly which part it is connected to
can set the -p part option should the user not have done so.

Also no longer exits main without closing open programmer.
2022-11-01 18:12:00 +00:00
MCUdude
577ee72db7 Fix Type 2 HV UPDI
Used on AVR-DD and AVR-Ex targets
2022-10-31 11:06:14 +01:00
Stefan Rueger
b5699663c4 Update NEWS 2022-10-29 11:05:25 +01:00
Stefan Rueger
50046da923 Merge pull request #1151 from dbuchwald/serialupdi_page_erase
Implementation of SerialUPDI page erase operation
2022-10-29 11:02:17 +01:00
Stefan Rueger
a3c04d294e Merge pull request #1156 from mcuee/readline_macos
Readline macos
2022-10-29 11:00:06 +01:00
Stefan Rueger
d87eb14dc9 Make -p variable partdesc global 2022-10-29 10:55:58 +01:00
Stefan Rueger
87df3216cb Make fileio() and do_op() arguments const where possible 2022-10-29 10:48:47 +01:00
Stefan Rueger
a1018999c4 Correct plural for message writing %d bytes in term.c 2022-10-26 08:42:03 +01:00
Stefan Rueger
418cf08e84 Change avrdude.conf.in comment on location of per-user config file 2022-10-25 18:13:28 +01:00
mcuee
5862a5b7e9 Use readline for github action macOS Homebrew
Update github action to use readline keg and not the default libedit under Homebrew
2022-10-24 08:50:57 +08:00
mcuee
79c43789a9 Update build.sh to use readline keg
For macOS Homebrew, readline is a keg. This change makes avrdude uses readline keg.
2022-10-24 08:47:02 +08:00
mcuee
f2a413d2dc Merge branch 'avrdudes:main' into Xplained_Pro_PDI 2022-10-24 07:57:55 +08:00
Stefan Rueger
1dba916e06 Update NEWS 2022-10-23 23:33:56 +01:00
Stefan Rueger
3769332afd Merge pull request #1142 from MCUdude/stk600-pdi
STK600 supports programming using PDI
2022-10-23 23:10:10 +01:00
Stefan Rueger
ec1e7156bd Merge pull request #1154 from avrdudes/revert-1148-readline_mingw
Revert "Add readline for MSYS2 mingw32/mingw64 build"
2022-10-23 23:09:18 +01:00
Stefan Rueger
960bf7b959 Revert "Add readline for MSYS2 mingw32/mingw64 build" 2022-10-23 23:04:16 +01:00
Stefan Rueger
0ebf220315 Merge pull request #1148 from mcuee/readline_mingw
Add readline for MSYS2 mingw32/mingw64 build
2022-10-23 22:42:10 +01:00
Stefan Rueger
b1b4a180ba Merge pull request #1146 from mcuee/readline_action
Add libreadline-dev for Linux github action build
2022-10-23 22:39:54 +01:00
Stefan Rueger
ae5b460859 Merge pull request #1141 from stefanrueger/paged
Always use paged access for programmers that serve bootloaders
2022-10-23 22:33:31 +01:00
Stefan Rueger
baaad71aa5 Support optiboot, optiboot_dx and optiboot_x bootloaders for -c arduino (#1140)
* If bootloaders are served, send word addresses for classic parts and
  byte addresses for newer parts, eg, UPDI and PDI
* Load ext addr for stk500v1 bootloaders after grazing 64k boundaries
* Fix bootloader stk500v1 EEPROM r/w for classic parts with page size 1
2022-10-23 22:32:29 +01:00
Stefan Rueger
16922842be Improve -B bitclock documentation 2022-10-23 22:26:07 +01:00
Stefan Rueger
2c7083f001 Merge pull request #1139 from steelman/isp-clock-error-message
Mention -B in the error message and document -F better
2022-10-23 21:59:21 +01:00
Stefan Rueger
4f6bab6303 Merge pull request #1138 from MCUdude/pic-detect-mode-cherry
Detect PICkit4 and SNAP in PIC mode
2022-10-23 21:57:26 +01:00
Stefan Rueger
5b008a04cf Revamp terminal output: progress bar, callback and stdout/stderr (#1132)
* Print parms output to stdout
* Flush terminal writes and other minor changes
* Prepare terminal for periodic calls to programmer to reset bootloader WDT
* Only show progress reports for memories > 32 bytes or on -vv
* Freeze progress bar on serious error
* Allow cached r/w byte routines to be used in pgm->read_byte and pgm->write_byte
2022-10-23 21:56:45 +01:00
steelman
34fa2faba5 Look for ~/.config/avrdude/avrduce.rc configuration file (#1131)
* Look for ~/.config/avrdude/config configuration file

Traditionally per-user configuration files have been placed
in user's home directory with their names beginnig with a dot
to hide them from some tools like ls(1). However, the number
of programs following this convention have grown over time
to the point where the number of hidden files becomes inconvenient to
some users. For this reason the XDG Base Directory Specification[1]
specifies an alternate place to store configuration files under
~/.config directory.

This patch enables avrdude to look for ~/.config/avrdude/config
configuration file, if ~/.avrduderc doesn't exist.

[1] https://specifications.freedesktop.org/basedir-spec/basedir-spec-0.8.html

* Safely concatenate directories and configurations files and minor changes in docs

* Make stats variable available for WIN32 again in main.c

* Utilise full usr_config[] array space

* Check for xdg-style avrdude.rc file first before fallback ~/.avrduderc

Co-authored-by: Stefan Rueger <stefan.rueger@urclocks.com>
2022-10-23 21:52:54 +01:00
Dawid Buchwald
fa1c081a94 Implemented page erase operation for SerialUPDI 2022-10-23 15:06:06 +02:00
Dawid Buchwald
2230c05871 Merge pull request #1 from avrdudes/main
Merge latest avrdudes/avrdude main branch
2022-10-23 13:56:52 +02:00
mcuee
e300861505 Add readline for MSYS2 mingw32/mingw64 build 2022-10-23 14:40:04 +08:00
mcuee
4a5efa7635 Add xplainedpro_pdi programmer
This will fix https://github.com/avrdudes/avrdude/issues/1143.

Xplained Pro should be able to support PDI mode as per the documentation.

Reference: take note that the following document does not cover UPDI support.
https://ww1.microchip.com/downloads/en/DeviceDoc/Atmel-42096-Microcontrollers-Embedded-Debugger_User-Guide.pdf

Reference discussion:
* https://github.com/avrdudes/avrdude/pull/1139#issuecomment-1286760773
* https://github.com/avrdudes/avrdude/discussions/1019#discussioncomment-3569440
2022-10-23 14:24:57 +08:00
mcuee
21e372f639 Add libreadline-dev for Linux github action build 2022-10-23 14:03:33 +08:00
MCUdude
992e9666a3 STK600 supports programming using PDI 2022-10-22 12:51:03 +02:00
Łukasz Stelmach
c890ff90eb Mention -B in the error message
One of possible problems of failed initialization is too hight frequency
of ISP clock. Mention using -B option as a possible solution.

Closes #1133
2022-10-21 02:33:34 +02:00
Stefan Rueger
b9396bcd02 Always use paged access for programmers that serve bootloaders 2022-10-21 00:56:43 +01:00
Łukasz Stelmach
9977f1ed12 Document meaning of -F during initialization 2022-10-20 19:52:35 +02:00
MCUdude
72da5c73db Fix formatting and replace tabs with spaces 2022-10-20 12:39:11 +02:00
MCUdude
867d83c215 Print error message if no HID device is connected when using hidapi 2022-10-20 12:27:59 +02:00
MCUdude
14446950df Check for PICkit4 or SNAP in PIC mode 2022-10-20 12:19:10 +02:00
MCUdude
b083416e3b Let Avrdude use the valid SNAP USB PID first 2022-10-20 12:19:10 +02:00
MCUdude
13817459e1 Add missing USB VID/PIDs 2022-10-20 12:19:10 +02:00
MCUdude
c999083b8f Change message type from error to warning and add additional USB info 2022-10-20 12:18:42 +02:00
Stefan Rueger
b864d7e73a Update NEWS and resolve minor residual messaging issues 2022-10-17 16:39:45 +01:00
Stefan Rueger
e172877724 Review and overhaul AVRDUDE's messaging system (#1126)
* Change avrdude_message(MSG_XYZ, ...) to msg_xyz(...)
* Define and use pmsg_xyz(...) instead of msg_xyz("%s: ...", progname, ...)
* Review and change avrdude_message() levels
   - Introduce new levels warning, error and ext_error
   - Distribute info level to info, warning, error, ext_error
   - Assign levels (more) consistently
   - Unify grammar, punctuation and style of messages
* Use imsg_xyz() to print indented messages
* Show function name in errors and warnings on -v
* Reduce effective verbosity level by number of -q above one
2022-10-17 15:44:55 +01:00
Stefan Rueger
2503ae03ce Merge pull request #1125 from MCUdude/updi-lock-fix
Fix UPDI erase when target is locked
2022-10-17 14:17:32 +01:00
Stefan Rueger
ff1d26ad18 Merge pull request #1122 from mariusgreuel/pr-teensy-warning
Suppress Teensy USB communication error message on reboot
2022-10-17 14:17:07 +01:00
Stefan Rueger
8e879cfae6 Merge pull request #1121 from stefanrueger/avr_cache
Use byte-wise read/write when page size is 1 in terminal cache
2022-10-17 14:16:43 +01:00
Dan Applegate
946b701b08 Fix writing of last word on DWORD TPI parts (#1115)
* Fix writing of last word on DWORD TPI parts

* Add n_word_writes AVRMEM config option

* TPI word chunk mode in avr_write_mem

* Simplify addition of n_words_write mem component to grammar

Co-authored-by: Stefan Rueger <stefan.rueger@urclocks.com>
2022-10-17 14:15:50 +01:00
Stefan Rueger
08f4f6c63f Merge pull request #1112 from MCUdude/jtag3-page-erase-updi
Fix jtag3_page_erase for targets with UPDI
2022-10-17 14:12:17 +01:00
MCUdude
bfec594ffd Fix issue where locked UPDI devices couldn't be erased
Resolves issue #1124
2022-10-13 14:14:46 +02:00
Stefan Rueger
714c2fbf95 Rename variable for clarity in avrcache.c 2022-10-12 15:55:22 +01:00
Stefan Rueger
8a3864d263 Fall back on bytewise r/w if paged access fails for avr cache 2022-10-12 15:53:54 +01:00
Marius Greuel
86155bdf66 Suppress Teensy USB communication error message on reboot 2022-10-11 18:23:03 +02:00
Stefan Rueger
48919f59b3 Use byte-wise read/write when page size is 1 in terminal cache 2022-10-11 15:31:18 +01:00
Stefan Rueger
e14e5d2f74 Update NEWS 2022-10-11 14:49:44 +01:00
Stefan Rueger
929441eb82 Merge pull request #1119 from mariusgreuel/pr-pointer-truncation
Fix pointer truncation for Windows x64
2022-10-11 14:43:41 +01:00
Stefan Rueger
22362e9f08 Merge branch 'main' into pr-pointer-truncation 2022-10-11 14:43:19 +01:00
Stefan Rueger
d3a3257cf7 Improve help message in terminal and provide new command pgerase (#1113) 2022-10-11 14:40:37 +01:00
Marius Greuel
9377acee0e Fix pointer truncation for Windows x64 2022-10-08 19:02:03 +02:00
MCUdude
1ca1be0447 Use avr_mem_is_flash_type() instead of checking m->desc directly 2022-10-06 20:59:32 +02:00
Stefan Rueger
44fe5bec2d Update NEWS 2022-10-05 23:21:52 +01:00
MCUdude
d5e4ed9f89 Fix jtag3_page_erase for targets with UPDI
Very handy to have now that #1106 is merged
2022-10-05 23:52:05 +02:00
Stefan Rueger
cd79f81747 Merge pull request #1109 from MCUdude/jtag-mki-targets
Add missing AVR variants the original JTAG ICE supports
2022-10-05 22:21:42 +01:00
Stefan Rueger
f2fb3b45b4 Merge pull request #1108 from MCUdude/avr109-xmega
AVR109: support for prodsig read and usersig read/write
2022-10-05 22:20:16 +01:00
Stefan Rueger
d74b17b9b4 Provide cached byte-wise read/write API (#1106)
* Provide cached byte-wise read/write API

int avr_read_byte_cached(const PROGRAMMER *pgm, const AVRPART *p, const
  AVRMEM *mem, unsigned long addr, unsigned char *value);

int avr_write_byte_cached(const PROGRAMMER *pgm, const AVRPART *p, const
 AVRMEM *mem, unsigned long addr, unsigned char data);

int avr_flush_cache(const PROGRAMMER *pgm, const AVRPART *p);

int avr_chip_erase_cached(const PROGRAMMER *pgm, const AVRPART *p);

int avr_reset_cache(const PROGRAMMER *pgm, const AVRPART *p);

avr_read_byte_cached() and avr_write_byte_cached() use a cache if paged
routines are available and if the device memory is EEPROM or flash,
otherwise they fall back to pgm->read_byte() and pgm->write_byte(),
respectively. Byte-wise cached read always gets its data from the cache,
possibly after reading a page from the device memory. Byte-wise cached
write with an address in memory range only ever modifies the cache. Any
modifications are written to the device after calling avr_flush_cache() or
when attempting to read or write from a location outside the address range
of the device memory.

avr_flush_cache() synchronises pending writes to EEPROM and flash with the
device. With some programmer and part combinations, flash (and sometimes
EEPROM, too) looks like a NOR memory, ie, one can only write 0 bits, not 1
bits. When this is detected, either page erase is deployed (eg, with parts
that have PDI/UPDI interfaces), or if that is not available, both EEPROM
and flash caches are fully read in, a pgm->chip_erase() command is issued
and both EEPROM and flash are written back to the device. Hence, it can
take minutes to ensure that a single previously cleared bit is set and,
therefore, this routine should be called sparingly.

avr_chip_erase_cached() erases the chip and discards pending writes() to
flash or EEPROM. It presets the flash cache to all 0xff alleviating the
need to read from the device flash. However, if the programmer serves
bootloaders (pgm->prog_modes & PM_SPM) then the flash cache is reset
instead, necessitating flash memory be fetched from the device on first
read; the reason for this is that bootloaders emulate chip erase and they
won't overwrite themselves (some bootloaders, eg, optiboot ignore chip
erase commands altogether) making it truly unknowable what the flash
contents on device is after a chip erase. 

For EEPROM avr_chip_erase_cached() concludes that it has been deleted if a
previously cached EEPROM page that contained cleared bits now no longer
has these clear bits on the device. Only with this evidence is the EEPROM
cache preset to all 0xff otherwise the cache discards all pending writes
to EEPROM and is left unchanged otherwise.

Finally, avr_reset_cache() resets the cache without synchronising pending
writes() to the device.
2022-10-05 22:16:15 +01:00
Stefan Rueger
c4cb242823 Merge pull request #1105 from MCUdude/power-debugger-features
Support for Power Debugger analog readings in terminal mode
2022-10-05 22:03:52 +01:00
Stefan Rueger
bc9137854b Merge pull request #1103 from s-wakaba/sunxi_linuxspi_support
saving errno of ioctl() call in a temporary variable to prevent overwrite
2022-10-05 22:02:42 +01:00
Stefan Rueger
83232bc7e1 Merge pull request #1102 from MCUdude/flip2-reset
Add support for Flip 2 reset on exit
2022-10-05 22:02:22 +01:00
Stefan Rueger
59a191ee2c Merge pull request #1101 from MCUdude/avr109-fix
Fix avr109 extended address
2022-10-05 22:00:59 +01:00
Hans
da275f8ef2 Adjust prog_modes on a few chip variants
Now variants of chips that the JTAG ICE supports will not cause a warning when used with the original JTAG ICE mkI.
Also, The ATmega165 isn't officially supported by the ICE mkI, so this should be properly tested with the ICE mkI first.
2022-10-05 19:24:40 +02:00
Hans
2c8cef2712 Merge branch 'avrdudes:main' into avr109-xmega 2022-10-02 22:43:03 +02:00
MCUdude
31c3db2617 Add support for prodsig read and usersig read/write
Currently only supported by the Xboot bootloader
2022-10-02 22:36:43 +02:00
MCUdude
ffabab1fb2 Improve pgm->id detection handling 2022-10-02 11:48:30 +02:00
MCUdude
4bc9e020f1 Merge branch 'flip2-reset' of https://github.com/MCUdude/avrdude into flip2-reset 2022-10-01 22:13:06 +02:00
MCUdude
419fd35b72 Mention linuxspi and flip2 programmers
in the -E exitspecs section. linuxspi and flip2 supports "-E reset" and "-E noreset".
2022-10-01 22:12:37 +02:00
Marius Greuel
ef209fe44e GitHub Actions: Update apt index before installing packages 2022-10-01 22:12:37 +02:00
MCUdude
e05aa16510 use pgm->id to identify Power Debugger instead of USB PID 2022-10-01 21:17:55 +02:00
MCUdude
e39133daf5 Initial support for Power Debugger analog reading
Voltage and current though channel A and B
2022-10-01 21:17:01 +02:00
Hans
52eb2e36a7 Merge branch 'avrdudes:main' into flip2-reset 2022-09-30 20:16:58 +02:00
MCUdude
01ccab08b4 Improve exitspecs (-E) parsing
Use the same implementation as linuxspi does, instead of the one suggested in #733
2022-09-30 20:16:16 +02:00
MCUdude
521155c1c2 Improve punctuation in error message 2022-09-30 20:03:04 +02:00
Marius Greuel
3b8f41ca20 GitHub Actions: Update apt index before installing packages 2022-09-29 22:02:04 +02:00
MCUdude
e1a317c670 Remove Flip 2 stub functions
Used when compiling without libusb. Print reasonable error instead
2022-09-27 19:35:25 +02:00
Shunichi Wakabayashi
2a64e78c7b bugfix: saving errno of ioctl() call in a temporary variable to prevent overwriting by following avrdude_message() call 2022-09-25 16:46:10 +09:00
MCUdude
80ca8a644e Add support for Flip 2 reset on exit
This makes it possible for the application to start immedeatly after the program has been loaded.
Simply use '-E reset' or '-E noreset'. Default is no reset.
Closes #733
2022-09-24 22:48:14 +02:00
MCUdude
62aa480876 Fix avr109 extended address
Closes #360 #454
2022-09-24 20:42:42 +02:00
Stefan Rueger
8f478f0098 Update NEWS 2022-09-24 13:29:04 +01:00
Stefan Rueger
9a59941dfe Merge pull request #1100 from s-wakaba/sunxi_linuxspi_support
add extended parameter "disable_no_sc" for linuxspi programmer
2022-09-24 13:23:38 +01:00
Stefan Rueger
94203eb441 Merge pull request #1099 from stefanrueger/prog_modes
Print compatible parts for programmer and vice versa using -c? or -p?
2022-09-24 13:23:12 +01:00
Stefan Rueger
f172f05372 Merge pull request #1096 from mariusgreuel/pr-cmake-texinfo
CMake: Build docs
2022-09-24 13:22:55 +01:00
Stefan Rueger
7743051926 Merge pull request #1095 from mariusgreuel/pr-fix-multiline-configure
CMake: Fix dependency chain between avrdude.conf.in and avrdude.conf
2022-09-24 13:22:37 +01:00
Stefan Rueger
db8b04f423 Merge pull request #1094 from papazoga/main
avrdude.conf.in: Adds digilent-hs2 dongle
2022-09-24 13:22:14 +01:00
Stefan Rueger
3b8ac76246 Merge pull request #1093 from stefanrueger/gemmaBoot
Create two bootloader programmers for gemmaBoot boards
2022-09-24 13:21:44 +01:00
Stefan Rueger
fe991b8214 Merge pull request #917 from asmirnou/iss45256-sysfs-gpio
Fix permission denied error in linuxgpio programmer
2022-09-24 13:21:08 +01:00
Stefan Rueger
f17a012325 Update documentation for linuxspi extended parameter disable_no_cs 2022-09-24 00:16:55 +01:00
Stefan Rueger
097c78098d Change printf() to avrdude_message() in linuxgio.c 2022-09-23 23:28:47 +01:00
Stefan Rueger
ca154f812f Improve error messaging in linuxspi.c 2022-09-23 16:53:52 +01:00
Stefan Rueger
aa789d4662 Change error messages in linuxspi.c to maintain single style 2022-09-22 10:39:31 +01:00
Stefan Rueger
93df07866a Inform user of -x disable_no_spi when needed (without -v) 2022-09-22 10:31:59 +01:00
Stefan Rueger
d8ff9bef6c Improve error messaging when part or programmer are invalid 2022-09-21 15:38:05 +01:00
Stefan Rueger
9e836d7988 Ensure avrdude.conf (programmer, part) pairs allow max one programming mode 2022-09-21 12:12:06 +01:00
Stefan Rueger
4c29edbc41 Warn if a part shares multiple programming modes with a programmer 2022-09-21 12:10:24 +01:00
Stefan Rueger
0175ffd21f Shorten more redundant programmer description for -c \? -p part 2022-09-20 22:03:40 +01:00
Stefan Rueger
505d53c2e1 Shorten redundant for bootloader description in -c ? -p part output 2022-09-20 21:55:29 +01:00
Stefan Rueger
b04a83b1a2 Document conditional options -c ? -p part and -p ? -c programmer 2022-09-20 21:39:15 +01:00
Stefan Rueger
97c5ac312a Shorten redundant programmer description for -c \? -p part 2022-09-20 21:37:49 +01:00
Stefan Rueger
4070ca9012 Distinguish different JTAG programming modes 2022-09-20 18:36:46 +01:00
Shunichi Wakabayashi
be40d3b260 add extended parameter "disable_no_sc" for linuxspi programmer 2022-09-20 01:32:12 +09:00
Stefan Rueger
07f1f60020 Make cosmetic changes to avrdude.conf.in 2022-09-16 19:10:39 +01:00
Stefan Rueger
fba2ac0330 Align = of -p? and -c? output 2022-09-16 19:09:35 +01:00
Stefan Rueger
7a76967851 Clarify desc lines for SPM programmers in avrdude.conf.in 2022-09-16 16:14:18 +01:00
Stefan Rueger
669796119a Add prog_modes lines for par programmers in avrdude.conf.in 2022-09-16 16:13:18 +01:00
Stefan Rueger
f8a62cca34 Print compatible parts for programmer and vice versa using -c? or -p?
For example:
 $ avrdude -p m328p -c?
 $ avrdude -p? -c jtag2dw
2022-09-14 23:00:57 +01:00
Stefan Rueger
0d411f2879 Add prog_modes lines for programmers in avrdude.conf.in 2022-09-14 18:36:37 +01:00
Stefan Rueger
ac8fbadff4 Add assignment injection code for -c*/si 2022-09-14 18:04:12 +01:00
Stefan Rueger
7087fd9f3e Raise info level for overwriting mcuid to MSG_DEBUG 2022-09-11 23:08:48 +01:00
Stefan Rueger
168a8b92e9 Default mcuid without warning for parts known at compile time 2022-09-11 15:33:23 +01:00
Stefan Rueger
a5f3885b50 Add and modify programmers for gemmaBoot in avrdude.conf.in 2022-09-07 09:56:28 +01:00
Marius Greuel
8ecae62f4a CMake: Add install commands for docs 2022-09-04 17:48:12 +02:00
Marius Greuel
c633255c01 CMake: Add initial support for texinfo docs 2022-09-04 16:55:16 +02:00
Marius Greuel
07ed4746be CMake: Fix dependency chain between avrdude.conf.in and avrdude.conf 2022-09-04 16:19:01 +02:00
Stefan Rueger
b99df388bd Change comment for diligent-hs2 in avrdude.conf.in 2022-09-01 13:08:44 +01:00
Alex Papazoglou
bf70b5fc8c avrdude.conf.in: Cosmetic changes
Corrected formatting using /s. Added a URL for the
reference manual.
2022-08-31 20:43:27 -07:00
Alex Papazoglou
4af49bb5fb avrdude.conf.in: Adds digilent-hs2 dongle
Adds support for Digilint JTAG HS2 in MPSSE mode.
2022-08-31 11:45:08 -07:00
Stefan Rueger
a536a01ebf Create a bespoke bootloader programmer for gammaBoot trinkets 2022-08-31 18:15:35 +01:00
Stefan Rueger
dab99c0823 Update NEWS 2022-08-31 17:35:03 +01:00
Stefan Rueger
0d1b49a4e4 Merge pull request #1091 from stefanrueger/config_file
Add new components in `avrdude.conf.in`
2022-08-31 17:27:05 +01:00
Stefan Rueger
602fab481c Relax uniqueness check of mcuid for parts that might be variants
Two parts are considered variants here if one part name starts with the name
of the other, flash memory sizes are the same, flash page sizes are the same
and the number of interrupts are the same.
2022-08-31 11:59:19 +01:00
Stefan Rueger
fc970226b6 Add avrintel.[ch] to Makefile.am 2022-08-31 11:31:58 +01:00
Stefan Rueger
40896802af Allow integer expressions in config file where numbers are expected
Notable exceptions are for pin numbers and where numbers are separated by
space only, eg, in signature and readback assignments.
2022-08-31 11:29:06 +01:00
Stefan Rueger
b328067f87 Remove has_jtag, has_debugwire, etc assignments in avrdude.conf.in
These assignments have been removed as they are redundant and only
imitate the single prog_modes = PM_... | PM_....; assignment. They
are still allowed in the grammar, and would still work.
2022-08-30 23:25:00 +01:00
Stefan Rueger
ffb8b7fcdf Try different header files for Windows compatibility 2022-08-30 21:31:11 +01:00
Stefan Rueger
4f7868ef4b Declare rather than define extern const uPcore_t uP_table[372]; 2022-08-30 19:54:41 +01:00
Stefan Rueger
626a43b139 Add avrintel.[ch] to the project and warn if mcuid incompatible with avrintel.c 2022-08-30 19:48:17 +01:00
Stefan Rueger
b0198a319f Offload the programming interface info from part->flags to part->prog_modes
flags now just hold parameters of the JTAG interface and some secondary
serial, parallel, pseudo parallel info. This separation brings clarity. It
used to be hard to augur whether a part has an ISP interface:

   (part->flags & (AVRPART_HAS_PDI | AVRPART_AVR32 | AVRPART_HAS_TPI
    | AVRPART_HAS_UPDI)) == 0 && (part->flags & AVRPART_SERIALOK) != 0

or had HVSP or HVPP capability, for that matter. Now it is just, eg,

  part->prog_modes & PM_ISP
  part->prog_modes & PM_HVPP
2022-08-30 16:33:42 +01:00
Stefan Rueger
0756b8e3ad Declare rather than define current_strct in header config.h 2022-08-30 02:49:37 +01:00
Stefan Rueger
0df8b87eda Set part prog_modes, mcuid, n_interrupts and n_page_erase in avrdude.conf.in 2022-08-30 02:31:57 +01:00
Stefan Rueger
ed2b8342df Prepare for new components in avrdude.conf incl prog_modes
- Add prog_modes to part and programmer definitions; prog_mode is a bitwise
   or of programming modes
     + PM_SPM: Bootloaders, self-programming with SPM/NVM Controllers
     + PM_TPI: t4, t5, t9, t10, t20, t40, t102, t104
     + PM_ISP: SPI programming for In-System Programming (typ classic parts)
     + PM_PDI: Program and Debug Interface (xmega parts)
     + PM_UPDI: Unified Program and Debug Interface
     + PM_HVSP: High Voltage Serial Programming (some classic parts)
     + PM_HVPP: High Voltage Parallel Programming (most non-HVSP classic parts)
     + PM_debugWIRE: Simpler alternative to JTAG (a subset of HVPP/HVSP parts)
     + PM_JTAG: some classic parts, some xmega
     + PM_aWire: AVR32 parts
 - Add mcuid, a unique id in 0..2039, to part definition for urclock programmer
 - Add n_interrupts, the number of interrupts, to part definition
 - Add n_page_erase to part definition (# of pages erased during NVM erase)

 - Implement a simple calculator in config_gram.y so numeric values can be
   expressed as simple expressions such as PM_SPM | PM_UPDI

 - Introduce a new method of assigning simple components to the grammar without
   touching config_gram.y via an eligible-component list in config.c; numeric
   expressions on the rhs of an assignment resolve to integer values

 - Update documentation in avrdude.conf.in and avrdude.texi
2022-08-30 02:08:15 +01:00
Stefan Rueger
eb7bdfd422 Merge pull request #1086 from stefanrueger/config_file
Rewrite avrdude.conf.in with developer options
2022-08-30 01:19:00 +01:00
Stefan Rueger
cddf2943eb Line up assignment operators in avrdude.conf.in 2022-08-30 01:10:45 +01:00
Stefan Rueger
0ccdd24d7e Ensure arrays in developer_opts.c have at least one element 2022-08-24 13:50:07 +01:00
Stefan Rueger
c97eb85cd8 Fix reset=dedicated|io; in avrdude.conf.in
Done by adding code in developer_opts.c that allows to inject part
or memory parameters into a semi-automated rewrite of avrdude.conf
This is a generic method, whereby an external program can, eg.,
scrape atdf files for the right parameters and put them into a
source table into developer_opts.c
  - Then write parts description with -p*/i
  - Use the output in a new avrdude.conf
  - Output again with -p* (no /i) and use that for final avrdude.conf
  - Remove table entries
2022-08-24 12:55:00 +01:00
Stefan Rueger
7fab75336e Replace tabs in avrdude.conf.in with spaces 2022-08-24 11:46:24 +01:00
Stefan Rueger
716984dbb1 Reformat conditional programmers in avrdude.conf.in using -c* 2022-08-24 10:57:25 +01:00
Stefan Rueger
57ebd36a01 Rewrite avrdude.conf.in file from avrdude -c* -p* output
Some manual editing is still necessary to cater for the
@HAVE_PARPORT_BEGIN@ etc sections. This commit also fixes
superfluous whitesapce at the end of avrdude.conf.in lines

Although the avrdude.conf file has changed much, the internal
representation in avrdude has not. This can be verified by
exporting the raw internal data through

  avrdude -c*/r -p*/r >/tmp/avrdude.raw

before the change and by comparing again after the change:

  avrdude -c*/r -p*/r | diff - /tmp/avrdude.raw
2022-08-24 01:10:51 +01:00
Stefan Rueger
09d14601af Fix 4 parts wrt to their interfaces in avrdude.conf 2022-08-24 00:54:11 +01:00
Stefan Rueger
3e49f078b3 Harden list management in pgm.c/config_gram.y 2022-08-24 00:03:45 +01:00
Stefan Rueger
731d581398 Update NEWS 2022-08-23 17:23:47 +01:00
Stefan Rueger
88c48cdf82 Merge pull request #1074 from stefanrueger/1073
Correct flash paged write for avrftdi.c
2022-08-23 17:09:46 +01:00
Stefan Rueger
fc6ef68b98 Merge pull request #1083 from stefanrueger/1081
Make avr910 programmer initialize() less verbose
2022-08-23 17:08:23 +01:00
Stefan Rueger
61efb02ef8 Merge pull request #1078 from stefanrueger/terminal
Use const for programmer functions where useful
2022-08-23 17:06:53 +01:00
Stefan Rueger
5f910580b7 Extend const args to avr_set_*() and developer_opts.c
... and print programming modes for -p*/d
2022-08-23 16:57:49 +01:00
Stefan Rueger
c6ef6a9b9b Adapt indentation of a line in buspirate.c to neighbouring lines 2022-08-22 00:00:39 +01:00
Stefan Rueger
c7951813ef Make avr910 programmer initialize() less verbose 2022-08-21 23:49:54 +01:00
Stefan Rueger
56aae55737 Replace loop/if condition and reduce signed comparison warnings in avrftfi.c
Change (int) poll_index >= (int) addr to poll_index+1 > addr as the former
might turn out to be implementation-defined. The latter is always defined
and what we want here (poll_index+1 won't overflow). Originally, the
condition was poll_index > addr-1, which was always false for addr=0 owing to
2^n modulo arithmetic of unsigned.

Also changed a few comparisons so they no longer are between signed
and unsigned integers reducing compiler warnings.
2022-08-21 00:05:44 +01:00
Stefan Rueger
f8dd9bc97d Correct flash paged write for avrftdi.c 2022-08-20 14:08:04 +01:00
Stefan Rueger
38aa1313f9 Print device code in avr910.c as unsigned char 2022-08-19 23:14:19 +01:00
Stefan Rueger
c03f4a7925 Use const in PROGRAMMER function arguments where appropriate
In order to get meaningful const properties for the PROGRAMMER, AVRPART and
AVRMEM arguments, some code needed to be moved around, otherwise a network of
"tainted" assignments risked rendering nothing const:

 - Change void (*enable)(PROGRAMMER *pgm) to void (*enable)(PROGRAMMER *pgm,
   const AVRPART *p); this allows changes in the PROGRAMMER structure after
   the part is known. For example, use TPI, UPDI, PDI functions in that
   programmer appropriate to the part. This used to be done later in the
   process, eg, in the initialize() function, which "taints" all other
   programmer functions wrt const and sometimes requires other finessing with
   flags etc. Much clearer with the modified enable() interface.

 - Move TPI initpgm-type code from initialize() to enable() --- note that
   initpgm() does not have the info at the time when it is called whether or
   not TPI is required

 - buspirate.c: move pgm->flag to PDATA(pgm)->flag (so legitimate
   modification of the flag does not change PROGRAMMER structure)

 - Move AVRPART_INIT_SMC and AVRPART_WRITE bits from the flags field in
   AVRPART to jtagmkII.c's private data flags32 fiels as FLAGS32_INIT_SMC and
   FLAGS32_WRITE bits

 - Move the xbeeResetPin component to private data in stk500.c as this is
   needed by xbee when it saddles on the stk500 code (previously, the flags
   component of the part was re-dedicated to this)

 - Change the way the "chained" private data are used in jtag3.c whilst
   keeping the PROGRAMMER structure read-only otherwise

 - In stk500v2.c move the STK600 pgm update from stk500v2_initialize() to
   stk500v2_enable() so the former keeps the PROGRAMMER structure read-only
   (for const assertion).

 - In usbasp change the code from changing PROGRAMMER functions late to
   dispatching to TPI or regular SPI protocol functions at runtime; reason
   being the decision whether to use TPI protocol is done at run-time
   depending on the capability of the attached programmer

Also fixes Issue #1071, the treatment of default eecr value.
2022-08-17 16:05:28 +01:00
Stefan Rueger
dfef8bb0a8 Add libavrdude functions avr_mem_is_flash_type() and avr_mem_is_eeprom_type() 2022-08-15 14:57:12 +01:00
Stefan Rueger
e332ecf0b4 Change array for copy mem->desc to const char * in term.c 2022-08-15 14:25:58 +01:00
Stefan Rueger
a4bfa8247d Update NEWS 2022-08-15 00:56:38 +01:00
Stefan Rueger
4c6ba0aae6 Merge pull request #1063 from sbngross/main
man-page: Fix logfile short option
2022-08-15 00:49:39 +01:00
Stefan Rueger
0b94ffdd3b Merge pull request #1059 from stefanrueger/programmer-devopts
Implement -c <wildcard>/dev_options for printing programmer entries of avrdude.conf
2022-08-15 00:48:35 +01:00
Stefan Rueger
0987416387 Merge pull request #1056 from stefanrueger/dry-run
Implement a dry run for -U updates before opening the programmer
2022-08-15 00:46:06 +01:00
Stefan Rueger
297740db0e Stop listing programmers where id starts with . 2022-08-13 22:57:54 +01:00
Stefan Rueger
c9736a9db5 Specifying the full memory name now always works
... even if a memory with longer name and same initial part exists
2022-08-13 20:51:31 +01:00
brutzzl3r
266eb23207 man-page: Fix install dir
`avrdude.1` is installed into `man` dir instead of its proper section
location.
This is due to the definition of `TYPE MAN` which points to
`<DATAROOT>/man` according to cmake docs.

Use `DESTINATION` and add proper section subdir.

This allows for `man -M <YOUR INSTALL dir>/share/man -w 1 avrdude` to succeed
instead of throwing `No manual entry for avrdude in section 1`

Signed-off-by: brutzzl3r <s3b.gr0ss@gmail.com>
2022-08-12 19:49:47 +02:00
Stefan Rueger
533feec4ed Revert grammar to remove introduced shift/reduce conflicts 2022-08-12 15:52:51 +01:00
Stefan Rueger
8420b27233 Address compiler warnings in 4 source files 2022-08-12 14:58:21 +01:00
Stefan Rueger
c2c9053b13 Show comments with -p*/s or -c*/s and reduce -p */r raw output 2022-08-12 00:28:54 +01:00
brutzzl3r
346de71cd5 man-page: Fix logfile short option
man synopsis states [-n -logfile] option. Later on in avrdude.1 as well as in
main.c -l is used.
Also '-logfile' is no option alternative but a parameter.
This is a minor issue but still confusing when one uses / to search
through man pages.

-- Always leave the code cleaner than you found it --

Signed-off-by: brutzzl3r <s3b.gr0ss@gmail.com>
2022-08-11 20:11:48 +02:00
Stefan Rueger
ccb576ebc1 Ensure memories are printed at most once for -p */S 2022-08-10 22:25:19 +01:00
Stefan Rueger
c9cf308037 Include ctype.h in term.c to resolve missing functions 2022-08-10 16:24:39 +01:00
Stefan Rueger
f4c5a8350d Replace string arrays with const char * and allocated space (part 2)
This commit replaces fixed-string buffers in PROGRAMMER, AVRPART and AVRMEM
that are dealt with by the parser and grammar. Now, string assignments are
always to const char *, ie, these are read-only strings with arbitrary
length.

config_gram.y now only needs to consider one type of string assignment.

This commit also

  - Replaces the simple linear-search cache_string() function with faster
    hashed cache_string(). Either way, the returned value is likely to be
    shared, so should never be free()'d.

  - Duplicates hvupdi_support list in pgm_dup() and frees it in pgm_free()

  - Adds const qualifier to some function args in avrpart.c and pgm.c

  - Hardens some functions against being called with NULL pointers

  - Ensures _new() and _dup() functions for parts, programmers and memory
    return a suitable memory. Out of memory triggers exit in one of three
    functions, cfg_malloc(), cfg_realloc() and cfg_strdup(); there is
    rarely anything useful that AVRDUDE or, for that matter, any
    application compiled against libavrdude can do once you run out of
    memory as AVRDUDE/libavrdude rely heavily on allocation of memory.
2022-08-10 16:14:56 +01:00
Stefan Rueger
7375477f70 Replace string arrays with const char * and allocated space (part 1)
This commit deals with default_programmer, default_serial, default_parallel
and default_spi. The long term objective is to remove all fixed-size buffers
from the structures that lexer.l and config_gram.y deal with.
2022-08-10 11:36:17 +01:00
Stefan Rueger
22c4dbf23e Harden string processing during parsing in lexer.l, config_gram.y and otherwise
- Replace strdup(s) with cfg_strdup(funname, s) that exits on out of mem
 - Replace malloc(n) with cfg_malloc(funname, n) that exits on out of mem
 - Change multiline string scanning in lexer.l to avoid core dump
 - Remove global variables string_buf and string_bug_ptr
 - Ensure reading strings unescapes strings C-Style
 - Ensure writing strings escapes strings C-Style again

Commit looks longer than needed as unescape() and auxiliary functions needed
to be moved from term.c (not in libavrdude) to config.c (in libavrdude).
2022-08-09 21:20:44 +01:00
Stefan Rueger
8a717987ec Change unsigned short eecr; to unsigned char eecr; in libavrdude's AVRPART 2022-08-09 13:19:40 +01:00
Stefan Rueger
7c8d336e27 Change dev_info() to stdout and no longer redirect stderr to stdout 2022-08-09 09:23:26 +01:00
Stefan Rueger
c21be27a7d Replace const char array indexing with equivalent code in pindefs.c 2022-08-08 17:27:38 +01:00
Stefan Rueger
1da97f6825 Adjust declaration of locate_programmer_type_id() to definition 2022-08-08 17:21:21 +01:00
Stefan Rueger
f25bc55806 Treat -c* the same as -c*/s 2022-08-08 17:03:06 +01:00
Stefan Rueger
49fcd8a96e Implement -c */[sSA] (syntax-correct dump of programmer structure) 2022-08-08 16:52:09 +01:00
Stefan Rueger
075dee1dd3 Implement -c */r (raw dump of programmer structure) 2022-08-07 17:52:17 +01:00
Stefan Rueger
08049a40ea Implement dev option -c */[ASsrt] skeleton
Also changed usbdev, usbsn, usbvendor and usbproduct components from
PROGRAMMER structure to be cached string pointers rather than fixed-size
arrays. These will be initialised by pgm_new() with a pointer to nul;
2022-08-07 14:06:04 +01:00
Stefan Rueger
81136688f6 Establish a third option to print out part definitions
Introduced -p <part>/A, which prints what -p <part>/S used to print, ie, all
components of the part structures including the default ones. Now -p <part>/S
prints the expanded part structure without use of parent and without printing
default values. This functionality is new and predominantly needed for
checking specific avrdude.conf entries, eg, avrdude -p*/St | grep pollindex

The option -p <part>/s continues to print a short entry of `avrdude.conf`
using its parent if so defined:

$ avrdude -p m328p/s

part parent "m328"
    desc                = "ATmega328P";
    id                  = "m328p";
    signature           = 0x1e 0x95 0x0f;
;
2022-08-07 08:53:24 +01:00
Stefan Rueger
a8bbedcde3 Switch from strerror_r() to strerror() in update.c for portability 2022-08-06 00:20:43 +01:00
Stefan Rueger
e681035cc4 Add strerror_r() and access() modes to MSVC compat file 2022-08-05 18:47:40 +01:00
Stefan Rueger
e590aead93 Treat comparison of different signedness warning in fileio.c 2022-08-05 18:04:46 +01:00
Stefan Rueger
b24a1cf667 Implement a dry run for -U updates before opening the programmer
This commit checks -U update requests for
  - Typos in memory names
  - Whether the files can be written or read
  - Automatic format detection if necessary

before opening the programmer. This to reduce the chances of the
programming failing midway through.

Minor additional changes:
  - Give strerror() system info when files are not read/writeable
  - Lift the auto detection message from MSG_INFO to MSG_NOTICE
  - Provide fileio_fmt_autodetect() in the AVRDUDE library
  - Rename fmtstr() in the AVRDUDE library to fileio_fmtstr() to
    avoid name clashes when an application links with it

Example:

$ avrdude -U - -U typo:r:.:h -U eeprom:w:testin:r -p ... -c ...
avrdude: can't auto detect file format for stdin/out, specify explicitly
avrdude: unknown memory type typo
avrdude: file . is not writeable (not a regular or character file?)
avrdude: file testin is not readable. No such file or directory
2022-08-05 17:38:59 +01:00
Stefan Rueger
5f5002eeaa Change name of update helper functions for print messages 2022-08-04 18:25:14 +01:00
Stefan Rueger
4eec8d15db Update NEWS 2022-08-04 18:19:43 +01:00
Stefan Rueger
bdfeb0ad34 Merge pull request #1042 from dl8dtl/fix_1041
Handle invalid -U file format specifiers for input
2022-08-04 18:11:21 +01:00
Stefan Rueger
ed36c7e1f6 Merge branch 'main' into fix_1041 2022-08-04 18:03:49 +01:00
Stefan Rueger
5f01d900f5 Merge pull request #1053 from stefanrueger/main
Enable stdin verification and display correct number of bytes written/verified
2022-08-04 17:58:15 +01:00
Stefan Rueger
3412196cd9 Weaken -U memory type check and move after config file parsing in main.c
The check for typos in -U memory names against a list of known memory names
now happens after the config files have been read, so newly declared memory
names can be considered. This commit also weakens the check against existence
of a known memory: it is now sufficent for a name to pass when it could be
the initial string of any known memory of any part. Any -U memory that cannot
possibly be matched up with a known memory is considered a typo and leads to
an exit before the programmer is opened.

This to protect users from typos that leave a device partially programmed.

When every -U memory name might be matching one of the known memories, the
programming is attempted. If the part to be programmed turns out not to have
a particular -U memory, AVRDUDE warns the user and skips this -U update.

This to support unifying interfaces that call AVRDUDE with potentially more
memories than the actual part has (eg, efuse on ATmega8).
2022-08-04 00:14:19 +01:00
Stefan Rueger
53ece53862 Update NEWS 2022-08-03 01:19:48 +01:00
Stefan Rueger
648f3319a9 Ignore target memories not present in part
$ avrdude -qp m8 -c ... -U efuse:w:0xff:m && echo OK

avrdude: AVR device initialized and ready to accept instructions
avrdude: skipping -U efuse:... as memory not defined for part ATmega8

avrdude done.  Thank you.

OK
2022-08-03 00:23:15 +01:00
Stefan Rueger
9604a3ef36 Check -U option for unknown memories during parsing
$ avrdude -qp ATmega2560 -c usbtiny -U flesh:w:blink-mega2560+lext-test.hex:i
avrdude: unknown memory type flesh
avrdude: error parsing update operation 'flesh:w:blink-mega2560+lext-test.hex:i'
2022-08-03 00:04:14 +01:00
Stefan Rueger
42c8169c37 Add ordered list of known memories to avr.c with access functions 2022-08-02 23:53:00 +01:00
Stefan Rueger
02027ab766 Enable stdin verification and display correct number of bytes written/verified
Counting the number of bytes written to a memory and/or verified is not
trivial owing to potential holes in the input file and to potential trailing
0xff bytes in flash memory that are not written per default (but see -A). The
new function memstats(), which is best called just after an input file has
been read into mem->buf/mem->tags, computes the right number of bytes written
and allows easy computation of the number of bytes verified.

This commit also changes the strategy for the default verification after
writing to a chip memory, so that the input file only needs reading once thus
enabling successful verification of stdin input files.

Other, minor changes:
 - Improving the grammar of AVRDUDE output, eg, 1 byte written instead of
   1 bytes written
 - Better description of the input file structure in terms of its sections,
   the interval it spans, the number  of pages, the number of padding bytes
   in pages, and the number of actually cut off trailing 0xff bytes for flash
 - Printing <stdin> or <stdout> instead of - in the -U routines
 - Option -V no longer needs to be specified before option -U in order to work

As an aside this commit also provides useful helper functions for printing
plural(), inname(), outname() and interval() all of which return strings fit
for printing.

$ avrdude -qp ATmega2560 -c usbtiny -U blink-mega2560+lext-test.hex

avrdude: AVR device initialized and ready to accept instructions
avrdude: Device signature = 0x1e9801 (probably m2560)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: input file blink-mega2560+lext-test.hex auto detected as Intel Hex
avrdude: reading input file blink-mega2560+lext-test.hex for flash
         with 1346 bytes in 4 sections within [0, 0x3106d]
         using 7 pages and 446 pad bytes
avrdude: writing 1346 bytes flash ...
avrdude: 1346 bytes of flash written
avrdude: verifying flash memory against blink-mega2560+lext-test.hex
avrdude: 1346 bytes of flash verified

avrdude done.  Thank you.

$ avrdude -qp ATmega328P -c usb-bub-ii -U sketch-ending-in-ff.hex

avrdude: AVR device initialized and ready to accept instructions
avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: input file sketch-ending-in-ff.hex auto detected as Intel Hex
avrdude: reading input file sketch-ending-in-ff.hex for flash
         with 2160 bytes in 1 section within [0, 0x888]
         using 17 pages and 16 pad bytes, cutting off 25 trailing 0xff bytes
avrdude: writing 2160 bytes flash ...
avrdude: 2160 bytes of flash written
avrdude: verifying flash memory against sketch-ending-in-ff.hex
avrdude: 2185 bytes of flash verified

avrdude done.  Thank you.

$ echo "Hello, world..." | avrdude -qp ATmega328P -c ... -U eeprom:w:-:r

avrdude: AVR device initialized and ready to accept instructions
avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading input file <stdin> for eeprom
avrdude: writing 16 bytes eeprom ...
avrdude: 16 bytes of eeprom written
avrdude: verifying eeprom memory against <stdin>
avrdude: 16 bytes of eeprom verified

avrdude done.  Thank you.
2022-08-02 23:26:01 +01:00
Stefan Rueger
e91f73392c Merge pull request #1048 from MCUdude/jtagmkii-updi
Add `jtagmkii_updi` programmer option
2022-08-02 18:32:12 +01:00
Stefan Rueger
310b801c59 Merge pull request #1046 from stefanrueger/stk500
Deprecate original STK500 v1 protocol in favour of optiboot and Arduino as ISP
2022-08-02 18:30:21 +01:00
Stefan Rueger
7f63632c6e Merge pull request #1040 from stefanrueger/partdesc
Developer options to describe parts and extend avrdude.conf syntax
2022-08-02 18:27:42 +01:00
Stefan Rueger
18e5bfd203 Merge pull request #1033 from MCUdude/ignore-safemode-flag
Ignore `-s` flag as safemode is no longer supported
2022-08-02 18:26:58 +01:00
Stefan Rueger
33ae3719e3 Merge pull request #1031 from MCUdude/jtagmki-fuses-fix
Apply jtagmki patch provided in #443
2022-08-02 18:24:25 +01:00
Stefan Rueger
7730706498 Merge pull request #1030 from stefanrueger/ihexcomments
Provide file format I: Intel HEX with comments that ignores checksum errors
2022-08-02 18:23:23 +01:00
Stefan Rueger
5e9be93100 Merge pull request #1016 from ffontaine/main
CMakeLists.txt: fix build without C++
2022-08-02 18:22:16 +01:00
MCUdude
de124bfd9b Improve error detection logic 2022-07-29 12:48:53 +02:00
Stefan Rueger
f299439b97 Move developer_opts* file names from library section to main section for c/make 2022-07-27 00:18:06 +01:00
Stefan Rueger
004b46b594 Move useful CMDBIT/part functions from developer_opts.c to avrpart.c 2022-07-27 00:12:57 +01:00
Stefan Rueger
62dcc2e6e8 Declare useful CMDBIT/part functions of developer_opts.c in libavrdude.h 2022-07-26 23:55:42 +01:00
Stefan Rueger
78754b8ccc Add parent id output for developer options -p*/s for parts 2022-07-26 23:43:56 +01:00
MCUdude
104dcf6052 Add new jtagmkii_updi programmer type option
in order to resolve issue #1037
2022-07-26 11:36:50 +02:00
Stefan Rueger
1549273529 Add comments with part names to -p*/s output 2022-07-25 20:30:40 +01:00
Stefan Rueger
d5d3a0e09e Improve help message -p/h for developer option -p 2022-07-24 23:38:51 +01:00
Stefan Rueger
3d06457a16 Deprecate original STK500 v1 protocol in favour of optiboot and Arduino as ISP
For paged read/write early AVRDUDE implementations of the STK500 v1 protocol
communicated a word address (below a_div=2) or byte address (a_div=1) based
on the following code irrespective of which memories were used:

  if(m->op[AVR_OP_LOADPAGE_LO] || m->op[AVR_OP_READ_LO])
    a_div = 2;
  else
    a_div = 1;

This turned out to be a bug: it really should have been a_div=2 for flash and
a_div=1 for eeprom. At the time presumably no one noted because Atmel was at
the cusp of replacing their FW 1.x with FW 2 (and the STK500 v2 protocol).

It seems that the world (optiboot, Arduino as ISP, ...) has compensated for
the bug by assuming AVRDUDE sends *all* eeprom addresses as word addresses.
Actually these programmers overcompensated for the bug because for six out of
the 146 known SPI programmable parts with eeprom and page size > 1, AVRDUDE
would still send the eeprom addresses as byte addresses (ATmega8 ATmega8A
ATmega64 ATmega64A ATmega128 ATmega128A) owing to above code.

It makes no sense to correct the bug now seeing that virtually no one uses
the old 2005 STK 500 v1 firmware. This commit now follows optiboot, Arduino
as ISP and other projects, and simply sends all addresses for paged read or
write as word addresses. There are no longer (little known) exceptions for
ATmega8 et al that surprised some optiboot etc users.
2022-07-24 20:39:14 +01:00
Stefan Rueger
29c6645abc Resolve signed/unsigned comparisons in stk500.c and stk500v2.c 2022-07-24 19:41:42 +01:00
Stefan Rueger
535004ee3d Consolidate error messages for stk500.c 2022-07-24 19:27:07 +01:00
Stefan Rueger
7310df030f Check stk500_recv() actually worked before accepting SYNC byte 2022-07-24 18:48:22 +01:00
Stefan Rueger
4babe183da Initialise memory before avr_set_bits() calls in stk500.c and stk500v2.c 2022-07-24 18:20:35 +01:00
Joerg Wunsch
cc93bd2c83 Move the error handling for invalid file formats to fileio.c
The checks used to be in update.c, but as they are related to
the intended file operation, they are better placed in fileio.c.

The checks affected are to refuse 'm' on output (file write),
and 'd', 'h', 'o', and 'b' formats on input (file read).
2022-07-23 22:47:38 +02:00
MCUdude
248c17177c Mention -s and -u in the docs 2022-07-23 22:33:11 +02:00
Joerg Wunsch
ce1ae41dd6 Document that 'h', 'o', and 'd' file formats are output-only. 2022-07-23 16:30:38 +02:00
Joerg Wunsch
26f431c944 Handle invalid -U file format specifiers for input
The file format specifiers 'h', 'd', 'o', and 'b' are only valid for
outputting data. Reject them with a proper error message when
attempting to use them for input.
2022-07-23 10:26:17 +02:00
Stefan Rueger
5a517fb74d Make developer opts portable: change statement exprs and index(); use size_t 2022-07-22 23:50:22 +01:00
Stefan Rueger
a95d169ccc Warn whenever address bits in avrdude.conf SPI commands are misplaced 2022-07-21 23:11:44 +01:00
Stefan Rueger
02788fb48a Warn whenever address bits in avrdude.conf SPI commands miss 2022-07-21 22:43:08 +01:00
Stefan Rueger
572849ec2a Provide avr_set_addr_mem() to set addresses in SPI opcodes within boundaries
The function avr_set_addr_mem(AVRMEM *mem, int opnum, unsigned char *cmd,
unsigned long addr) is meant to replace avr_set_addr(OPCODE *op, unsigned
char *cmd, unsigned long addr) in future.

avr_set_addr_mem() has more information about the context of the task in that
it knows the memory size, memory page size, whether or not the memory is a
flash memory (which gets words addressees supplied) and, crucially, knows
which SPI operation it is meant to compute the address bits for.

avr_set_addr_mem() first computes the interval of bit numbers that must be
supplied for the SPI command to stand a chance to work. The function only
sets those address bits that are needed. Once all avr_set_addr() function
calls have been replaced by avr_set_addr_mem(), the SPI commands that need an
address can afford to declare in avrdude.conf all 16 address bits in the
middle two bytes of the SPI command. This over-declaration will be corrected
during runtime by avr_set_addr_mem(). One consequence of this is that parts
can inherit smaller or larger memories from parents without the need to use
different SPI codes in avrdude.conf. Another consequence is that
avr_set_addr_mem() can, and does, tell the caller whether vital address bits
were not declared in the SPI opcode. During parsing of avrdude.conf this
might be utilised to generate a corresponding warning. This will uncover
problematic SPI codes in avrdude.conf that in the past went undetected.
2022-07-21 21:42:07 +01:00
Stefan Rueger
55f6765ea5 Make more useful functions from developer_optc.c available 2022-07-21 18:47:48 +01:00
Stefan Rueger
192e118d2c Make useful functions from developer_optc.c available 2022-07-21 18:36:04 +01:00
Stefan Rueger
696574d1eb Replace !fnmatch(p, s, 0) with own part_match(p, s) 2022-07-21 18:04:41 +01:00
Stefan Rueger
4ada98a1a8 Udate the avrdude.conf introductory documentation 2022-07-20 00:57:35 +01:00
Stefan Rueger
6afa115a5f Make -p*/s print SPI opcodes like "0100.0000--000.aaaa--aaaa.aaaa--iiii.iiii" 2022-07-19 23:44:58 +01:00
Stefan Rueger
30041e3f5f Add compact alternative specification for SPI opcodes in avrdude.conf
As the address bit numbers in the SPI opcodes are highly systematic, they
don't really need to be specified. Each bit can therefore be described as one
of the characters 0 (always 0), 1 (always 1), x (don't care, but will be set
as 0), a (a copy of the correct bit of the byte or word address of read,
write, load, pagewrite or load extended address command of memories with more
than one byte), i (input bit for a load/write) or o (output bit from a read).
The bits therefore do not need to be individually separated.

If a string in the list of strings that describe an SPI opcode does *not*
contain a space *and* is longer than 7 characters, it is interpreted as a
compact bit-pattern  representation. The characters 0, 1, x, a, i and o will
be recognised as the corresponding bit, whilst any of the characters ., -, _
or / can act as arbitrary visual separators, which are ignored. Examples:

  loadpage_lo = "0100.0000--000x.xxxx--xxaa.aaaa--iiii.iiii";

  loadpage_lo = "0100.0000", "000x.xxxx", "xxaa.aaaa", "iiii.iiii";

  loadpage_lo = "0100.0000", "000x.xxxx.xxaa.aaaa", "iiii.iiii";

  loadpage_lo = "0100.0000-000x.xxxx--xxaa.aaaa-iiii.iiii";

  loadpage_lo = "0100.0000/000x.xxxx/xxaa.aaaa/iiii.iiii";

The compact format is an extension of the current format, which remains
valid. Both, the compact and the traditional specification can be mixed in
different strings, albeit not in the same string:

  load_ext_addr = "0100.1101", "0000.0000.0000", "0 0 0 a16", "0000.0000";
2022-07-19 22:59:46 +01:00
MCUdude
bfdad78fcb Add EEPROM dummy read 2022-07-19 23:44:22 +02:00
Stefan Rueger
db37c9d286 Extend rather than reset memory entries in avrdude.conf
This commit changes the philosophy whenever avrdude.conf encounters the
same memory of a part for the second time or whenever a memory is
described that, through inheritance, already existed: AVRDUDE no longer
zaps the memory, it rather extends it.

Therefore, avrdude.conf.in's entry for ATmega128RFA1, which inherits from
the ATmega2561, needs a line `load_ext_addr = NULL;` in its flash memory
description to zap the inherited load_ext_addr SPI command.

Other than this, avrdude.conf.in needs no other change in order to effect
the same internal representation proving earlier updates to the .conf.in
file correct that manually ensured inheritance of memory contents.
2022-07-19 20:00:17 +01:00
Stefan Rueger
bdb5ba6055 Add avrdude.conf syntax ((pp|hvsp)_controlstack|(eeprom|flash)_instr) = NULL; 2022-07-19 16:16:55 +01:00
Stefan Rueger
1555906604 Add avrdude.conf syntax memory "name" = NULL; 2022-07-19 15:58:40 +01:00
Stefan Rueger
8503f2d2d5 Add avrdude.conf syntax opcode = NULL; for SPI programming 2022-07-19 15:38:54 +01:00
Stefan Rueger
f8b6a246ef Add in lexer.l capability to scan negative decimal integers or reals 2022-07-19 15:17:00 +01:00
Stefan Rueger
bb6e1bbaec Add avrdude.conf new syntax: readback = 0x80 0x7f; 2022-07-19 15:01:51 +01:00
Stefan Rueger
8da9c2bbf6 Correct bit number for lone 'a' in config_gram.y
When an SPI command has a lone 'a' the initialisation now is as would be
expected by all commands that take an address. Atmel's opcodes for SPI
programming are consistent in this respect. This commit makes specifying
the bit number in avrdude.conf optional. Instead of

 read_lo = "0 0 1 0 0 0 0 0  0 0 a13 a12 a11 a10 a9 a8  a7 a6 a5 a4 a3 a2 a1 a0  o o o o o o o o";

one can now use

 read_lo = "0 0 1 0 0 0 0 0  0 0 a a a a a a  a a a a a a a a  o o o o o o o o";
2022-07-19 14:46:08 +01:00
Stefan Rueger
8989e6515b Change macros __f() to _f() and adapt to config_file and hvupdi changes 2022-07-19 14:38:34 +01:00
Stefan Rueger
43e2955c61 Merge branch 'avrdudes:main' into partdesc 2022-07-19 13:20:25 +01:00
Stefan Rueger
affe4cb50a Merge pull request #1034 from stefanrueger/config_file
Cache config_file components in AVRPART and PROGRAMMER structures
2022-07-19 13:05:42 +01:00
Stefan Rueger
3b5a1f63c6 Merge branch 'avrdudes:main' into partdesc 2022-07-19 12:57:13 +01:00
Stefan Rueger
3c05fe6412 Merge branch 'avrdudes:main' into config_file 2022-07-19 12:33:12 +01:00
Stefan Rueger
e52bd2b99b Move realpath() compatibility definition from config_gram.y to config.h 2022-07-19 08:05:42 +01:00
Stefan Rueger
eba67e56fc Make realpath() available for MSC and MINGW32 2022-07-19 07:42:44 +01:00
Stefan Rueger
f95a1d3448 Cache config_file components in AVRPART and PROGRAMMER structures
Some 90% of the space of AVRPART and some 50% of PROGRAMMER is occupied by a
4 kB array config_file[] that contains the configuration file name. In
preparation of developer options that output a raw dump of the part
descriptions, this commit changes the config_file components from a large
array, which is duplicated in each part and programmer description, to a
cached string for each config file allowing for smaller raw dumps.

This commit also changes the config file name to its realpath(), eg, shortens
unwarranted `/bin/../etc/` file name components. It also changes the global
variable names `infile` and `fileno` to cfg_infile and cfg_fileno for an ever
so slight improvement of code clarity.
2022-07-18 18:10:09 +01:00
Stefan Rueger
0e7c1512e4 Avoid the warning: enumeration value ‘CONNTYPE_SPI’ not handled in switch 2022-07-18 17:34:06 +01:00
MCUdude
ec467c465e Ignore -s flag as safemode is no longer supported
Resolves #1032
2022-07-18 17:13:10 +02:00
Stefan Rueger
068e78e832 Merge branch 'avrdudes:main' into partdesc 2022-07-18 16:02:01 +01:00
Stefan Rueger
87401d341e Merge branch 'main' into main 2022-07-18 15:56:43 +01:00
Stefan Rueger
a5552f64cf Update NEWS 2022-07-18 14:38:37 +01:00
Stefan Rueger
6e5bf3bc8d Merge pull request #1029 from stefanrueger/issue992
Fix usbtiny read/verify for parts with more than 64 kB flash
2022-07-18 14:32:15 +01:00
Stefan Rueger
494199fa78 Merge pull request #1025 from stefanrueger/terminal
Fix terminal write edge cases; add one read mode and add quell command
2022-07-18 14:30:45 +01:00
Stefan Rueger
6fa7400e4e Merge pull request #1015 from MCUdude/hv-updi
Add support for high-voltage UPDI
2022-07-18 14:28:39 +01:00
Stefan Rueger
1d3a7591ea Merge pull request #933 from MCUdude/linuxspi-default-port-fix
Fix linuxspi default port
2022-07-18 14:25:52 +01:00
MCUdude
5904611928 Apply jtagmki patch provided in #443 2022-07-17 12:51:43 +02:00
Stefan Rueger
79921e52dc Provide file format I: Intel HEX with comments that ignores checksum errors
The new file type I is essentially Intel HEX that, on download, inserts
comments next to data records with the resolved effective address and an
ASCII dump of that same record. On upload the `I` format is permissive
with respect to check sum errors, eg, after manipulated an Intel HEX file
for debugging.
2022-07-16 23:40:36 +01:00
Stefan Rueger
d05ddd188d Fix usbtiny read/verify for parts with more than 64 kB flash
Usbtiny has a protocol or firmware problem that prevents it from reading
flash above 64 kB in page mode (used by -U flash:r:... and -U flash✌️...).
This commit fixes that problem by falling back on byte access for flash paged
reads above 64k. It also issues the correct load extended address command for
parts with more than 128 kB flash thus extending support to ATmega2560 et al.
2022-07-16 11:06:18 +01:00
Stefan Rueger
e7e062ec05 Fix terminal line parsing for strings (to some extent) 2022-07-15 18:50:20 +01:00
Stefan Rueger
7ceb163cba Echo terminal command line on Apple 2022-07-14 18:31:44 +01:00
Stefan Rueger
14b27726d4 Protect terminal dump from vagaries of C libray implementation of isalpha() etc
Some C libraries assign true to isalpha(0xff), isdigit(0xff) or
ispunct(0xff), which means that the Operating System terminal sees a
character 0xff which it may not have a useful display character for.

This commit only outputs printable ASCII characters for an AVRDUDE
terminal dump reducing the risk of the OS terminal not being able
to print the character properly.
2022-07-14 17:16:30 +01:00
Stefan Rueger
5721908e63 Revert to double/float only in terminal write and clarify usage 2022-07-14 17:13:13 +01:00
MCUdude
dde35018eb Exit if programmer can't send HV pulse to target 2022-07-13 23:49:14 +02:00
Stefan Rueger
901d49c4e6 Change terminal write usage message to accommodate long double 2022-07-13 12:37:10 +01:00
Stefan Rueger
b02cce38d7 Added long double data type for terminal write 2022-07-13 12:25:09 +01:00
Stefan Rueger
0b3a5781fc Flush stderr and stdout with all terminal error messages
Error messages are written to stderr whilst normal terminal output is stdout.
When redirecting output to pipelines or files these two streams can get
separated as they are buffered separately. To avoid this, term.c now provides
a function terminal_message() that works just like avrdude_message() but
flushes stderr and stdout before printing on stderr, and it flushes stderr
afterwards.

This commit replaces all avrdude_message() calls except for progress report
with terminal_message() to ensure stdout and stderr streams keep together.
2022-07-13 11:48:29 +01:00
Stefan Rueger
1efbc64922 Add terminal_setup_update_progress() library interface to term.c
This enables the new quell terminal command to switch on and off progress
reports to the terminal. The code for this was moved from main.c to term.c.

It can be used as library call for other frontends than main.c
2022-07-13 11:38:43 +01:00
Stefan Rueger
ea226936b7 Fix isspace() and other isxxx() calls in term.c 2022-07-13 11:19:21 +01:00
Stefan Rueger
f8145ae1c4 Echo >>> terminal command line for Windows or non-libreadline 2022-07-12 21:53:37 +01:00
Stefan Rueger
5690352676 Merge branch 'avrdudes:main' into main 2022-07-12 18:19:57 +01:00
Stefan Rueger
3ef8122d90 Merge branch 'avrdudes:main' into partdesc 2022-07-12 18:19:17 +01:00
Stefan Rueger
feb38b83ef Merge branch 'avrdudes:main' into terminal 2022-07-12 18:18:39 +01:00
Hans
dc6c10dc6c Merge pull request #3 from janegilruud/hv-updi
Clean up and simplify hvupdi handling, and set default hvupdi_variant
2022-07-12 19:09:07 +02:00
Stefan Rueger
c81f52ff10 Update NEWS 2022-07-12 15:52:37 +01:00
Stefan Rueger
09a95a3717 Merge pull request #936 from stefanrueger/issue918
Fix Issue #918: Enable avrdude to send full input file incl trailing 0xff
2022-07-12 15:34:17 +01:00
Stefan Rueger
b6204b181a Provide echo of terminal command line prompt under Windows 2022-07-12 15:22:52 +01:00
Stefan Rueger
0edb77bdf8 Merge branch 'main' into issue918 2022-07-12 15:05:45 +01:00
Stefan Rueger
04f790ad85 Merge pull request #1018 from stefanrueger/issue995
Fix Issue #995 ft245r paged read for ATmega2560 et al
2022-07-12 14:55:44 +01:00
Stefan Rueger
e867486f3f Merge pull request #1023 from stefanrueger/issue1004
Fix PICKit2 ATmega2560 flash paged flash read
2022-07-12 14:51:56 +01:00
Stefan Rueger
1e8b56751e Add quell command in terminal
Sets the quell_progress global variable that can be, and is, consulted by
programmers.

Setting quell_progress to a positive number also switches off progress
bars. It is currently not possible to switch on progress bars again: that
is enabled in main.c once at the start of AVRDUDE.

That code in main should move to avr.c to enable report_update() to consult
quell_progress directly. Will do at another time when touching main.c and
avr.c. smr
2022-07-12 13:19:09 +01:00
Stefan Rueger
d9cb9772d7 Fix verbosity level parsing in term.c 2022-07-12 12:30:29 +01:00
Stefan Rueger
63fb79accb Consolidate more error messages in term.c 2022-07-12 12:24:30 +01:00
Stefan Rueger
f871a4dc1e Adapt capitalisation of comments in term.c to existing style 2022-07-12 12:02:43 +01:00
Stefan Rueger
7c766ef9bd Refine type detection in terminal write
The code no longer accepts valid mantissa-only doubles that are integer
rejects, eg, 078 or ULL overflows. These are most likely input errors by
the user: 8 is not an octal digit, they might have typed 17 hex digits,
not 16. It's just too hard to explain that 0xffffFFFFffffFFFFf writes
0x4430000000000000, which is the correct double representation of the
valid 17-digit hex mantissa that strtod() is perfectly happy to accept.
2022-07-12 12:01:14 +01:00
Stefan Rueger
704d253636 Remove comparisons between signed and unsigned integers in term.c 2022-07-12 11:59:42 +01:00
Stefan Rueger
8140c9c90b Consolidate error messages in term.c 2022-07-12 11:58:51 +01:00
Stefan Rueger
56113f6d8a Remove echo of tokenised terminal command 2022-07-12 11:51:04 +01:00
Stefan Rueger
c5f522342d Improve terminal help message 2022-07-12 11:50:23 +01:00
Stefan Rueger
92425af0cc Improve terminal dump usage message 2022-07-12 11:47:33 +01:00
Stefan Rueger
602e9bb80c Change size for memory type variable in terminal read 2022-07-12 11:44:20 +01:00
Stefan Rueger
7205bbae80 Enhance terminal read with new mode: read <memory> <addr> 2022-07-12 11:43:45 +01:00
Stefan Rueger
aa09bcf900 Ensure terminal writes little endian numbers 2022-07-12 11:42:59 +01:00
Stefan Rueger
ddffabe86a Improve terminal write usage message 2022-07-12 11:40:40 +01:00
Stefan Rueger
0b2f38c67d Allow optional comma separators for data items in terminal write 2022-07-12 11:39:52 +01:00
Stefan Rueger
5c4cfa642a Parse terminal writes of string and character constants in C-style 2022-07-12 11:39:02 +01:00
Stefan Rueger
9fe6820236 Add double type for terminal write in anticipation of future avr-libc extension 2022-07-12 11:36:57 +01:00
Stefan Rueger
feda75b60a Remove unnecessary bool is_float in terminal write 2022-07-12 11:35:27 +01:00
Stefan Rueger
51355d04fb Remodel logic of the size that integer items occupy in terminal write
Integers can be hexadecimal, decimal or octal. An optional case-insensitive
suffix specifies their size: HH: 8 bit, H/S: 16 bit, L: 32 bit, LL: 64 bit

An optional U suffix makes a number unsigned. Ordinary 0x hex numbers are
always treated as unsigned. +0x or -0x hex numbers are treated as signed
unless they have a U suffix. Unsigned integers cannot be larger than 2^64-1.

If n is an unsigned integer then -n is also a valid unsigned integer as in C.

Signed integers must fall into the [-2^63, 2^63-1] range or a correspondingly
smaller range when a suffix specifies a smaller type. Out of range signed
numbers trigger a warning.

Ordinary 0x hex numbers with n hex digits (counting leading zeros) use
the smallest size of 1, 2, 4 and 8 bytes that can accommodate any n-digit hex
number. If a suffix specifies a size explicitly the corresponding number of
least significant bytes are written. Otherwise, signed and unsigned integers
alike occupy the smallest of 1, 2, 4, or 8 bytes needed to accommodate them
in their respective representation.
2022-07-12 11:32:38 +01:00
Stefan Rueger
62d3eebd56 Fix 64-bit integer terminal write where high bit set
Using strtoll() can only return numbers in the range [-2^63, 2^63-1]. This
means that 0xffffFFFFffffFFFF (2^64-1) will be out of range and is written as
max LL. Actually, every 64-bit number with high-bit set will wrongly be
written as max LL.

This commit uses strtoull() instead to fix this, and checks for unsiged out-
of-range error. strtoull() also has the neat benefit that input with a minus
sign is treated like C unsigned numbers, ie, -u is also a valid unsigned
number if only u is one. In case the input is meant to be treated as signed,
it is therefore still OK to use strtoull() in the first instance only that in
this case a second check against the range of the signed domain is necessary.
2022-07-12 11:19:47 +01:00
Stefan Rueger
9afa56381e Remove unused component is_signed in terminal write 2022-07-12 11:19:05 +01:00
Stefan Rueger
ff43e0544d Correct a parse message in terminal write 2022-07-12 11:18:15 +01:00
Stefan Rueger
177834ae7c Ensure enough memory is allocated for buf in terminal write 2022-07-12 11:16:16 +01:00
Stefan Rueger
d3ad078577 Ensure terminal write fill mode ... always fills with last data item 2022-07-12 11:15:30 +01:00
Stefan Rueger
39a00bc71e Ensure +0x...f does not strip suffix f in terminal write 2022-07-12 11:14:41 +01:00
Stefan Rueger
360d7c502b Make suffix fully case insensitive (allow Hh, Ll, ...) in terminal write 2022-07-12 11:13:46 +01:00
Stefan Rueger
d9450058c8 Cache strlen(argv[i]) in term.c cmd_write() and prevent negative array index 2022-07-12 11:12:20 +01:00
Jan Egil Ruud
69ee5da613 Improve error handling for devices that does not support HVUPDI. 2022-07-12 12:01:17 +02:00
Jan Egil Ruud
2478c18745 Do not let the hvupdi extended option take any configuration values. The hvupdi type is implied by the part configuration. 2022-07-11 15:26:41 +02:00
Jan Egil Ruud
173b4f9d0a Clean up and simplify hvupdi handling, and set default hvupdi_variant to -1. 2022-07-11 14:07:45 +02:00
Stefan Rueger
ff8f519a34 Fix PICKit2 ATmega2560 flash paged flash read
The paged read in pickit2.c has two errors:
  - It drops load extended address commands unless a paged read happens at a
    64k byte boundary; this is invalid when reading files with holes
  - It wrongly assumed that flash memory is byte addressed

The fix is to carry out a load extended address command, if needed, at the
beginning of each paged flash read with the correct word address. Although the
pickit2_paged_load() has independent parameters page_size, addr and n_bytes,
AVRDUDE only ever calls paged read/write functions with page_size and n_bytes
both set to mem->page_size and addr aligned with a page boundary. Therefore, it
is sufficient to set the load extended address at the beginning of each page
read.
2022-07-10 23:41:44 +01:00
Hans
913509d6e6 Merge pull request #2 from janegilruud/hv-updi
Add HVUPDI_SUPPORT list for programmers.
2022-07-07 20:12:43 +02:00
Stefan Rueger
215ea1af5c Merge branch 'partdesc' of github.com:stefanrueger/avrdude into partdesc 2022-07-07 18:34:26 +01:00
Stefan Rueger
9e2cea3ada Implement developer options -p */[*cdosSrwt] for part descriptions 2022-07-07 18:32:19 +01:00
Jan Egil Ruud
91310e6f50 Move hvupdi_support list to a new prog_parm_updi group, and initialize the list. 2022-07-07 12:23:05 +02:00
Ruud, Jan Egil
9e5ea25b9e Add HVUPDI_SUPPORT list for programmers. 2022-07-05 14:14:37 +02:00
Stefan Rueger
64ee4858fd Update 2nd debug message in avr.c with correct function name 2022-07-05 01:00:45 +01:00
Stefan Rueger
d3b22fa3c6 Update debug message in avr.c with correct function name 2022-07-05 00:57:40 +01:00
Stefan Rueger
9742c7b97a Add #474 and #976 to NEWS 2022-07-05 00:55:58 +01:00
Stefan Rueger
00ea21597e Merge pull request #1001 from MCUdude/add-missing-bits-and-pieces
Add missing delays in avrdude.conf
2022-07-05 00:05:32 +01:00
Stefan Rueger
9ea02c4431 Merge pull request #998 from stefanrueger/issue474
Fix Issue #474 FT232H support for ATmega2560 et al (load extended address)
2022-07-05 00:00:54 +01:00
Stefan Rueger
2b6ee8f4d1 Adapt whitespace to existing style in avrftdi.c 2022-07-04 23:54:02 +01:00
Stefan Rueger
7aad03cbcd Fix paged read for ATmega2560 et al for ft245r.c 2022-07-04 23:11:32 +01:00
Stefan Rueger
a721e485cb Refactor paged read/write routines in ft245r.c 2022-07-04 23:04:36 +01:00
Stefan Rueger
bb049a085e Merge branch 'issue474' of github.com:stefanrueger/avrdude into issue474 2022-07-04 12:31:11 +01:00
Stefan Rueger
237cb63211 Steamline avrftdi support for ATmega2560 et al 2022-07-04 12:30:37 +01:00
Stefan Rueger
2827c2695e Update NEWS 2022-07-04 12:30:37 +01:00
Joerg Wunsch
bdab12d8fb PR 996 and 1013 done 2022-07-04 12:30:37 +01:00
MCUdude
d2bb964fc7 Attempt to fix EEPROM write issue #1009 2022-07-04 12:30:37 +01:00
Joerg Wunsch
f22b81c00e Fix a number of logic errors in the previous commits
RSP3_FAIL_CRC_FAILURE is 0x43 rather than 0x47.

jtag3_errcode() must only be applied to a reason code, not
to any general status code.
2022-07-04 12:30:37 +01:00
Joerg Wunsch
8953967fc3 Replace internal knowledge in jtag3.c by a public API
In certain situations (CRC failure, device locked), that JTAG3
read functions need to return an indication to the caller that
it is OK to proceed, and allow erasing the device anyway.

Historically, the JTAG3 code passed the respective protocol
errors directly (and unexplained) up to the caller, leaving
the decision to the caller how to handle the situation.

Replace that by a more common return value API. New code should
prefer this API instead of any hardcoded return values.
2022-07-04 12:30:37 +01:00
Stefan Rueger
ef785a617a Treat x bits in .conf SPI commands as 0 2022-07-04 12:30:37 +01:00
Joerg Wunsch
ad2be990b7 PR 993 done 2022-07-04 12:30:37 +01:00
prchal
134509cc6f adding support for all Linux baud rates v.2
If optiboot can work at higher bauds, why not avrdude.
Versoin 2 of #985.
Linux uses the old-style bitmapped version of the Bxxxx macros.
2022-07-04 12:30:37 +01:00
Joerg Wunsch
8bd39157c1 Closing PR 979 2022-07-04 12:30:37 +01:00
MCUdude
963a1e54af Fix JTAG transaction close issue
Fixes issue #366
2022-07-04 12:30:37 +01:00
Joerg Wunsch
37026cad52 PR #1000 is done now 2022-07-04 12:30:37 +01:00
MCUdude
b167e88422 Reduce programmer description string length
to less than 80 characters. #941 related
2022-07-04 12:30:37 +01:00
Stefan Rueger
3893a21164 Fix avrftdi support for ATmega2560 et al (load extended address) 2022-07-04 12:30:25 +01:00
Stefan Rueger
d95c1a91f7 Steamline avrftdi support for ATmega2560 et al 2022-07-04 12:25:50 +01:00
Stefan Rueger
c4add116d6 Merge branch 'avrdudes:main' into issue474 2022-07-04 10:07:05 +01:00
MCUdude
6473a6d71a Add avrdude_message to verbose mode 2022-07-01 07:36:07 +02:00
MCUdude
30c1b31b8d Send 12V pulse to HV_UPDI_VARIANT_2 targets as well 2022-06-29 17:12:57 +02:00
Ruud, Jan Egil
65763b5700 Correct hvupdi_variant for AVR DD devices. 2022-06-29 17:12:57 +02:00
Ruud, Jan Egil
39008ac2c1 Add UPDI HV type to device description. 2022-06-29 17:12:57 +02:00
MCUdude
577856cf15 Use HV UPDI constants rather than arbitrary numbers 2022-06-29 17:12:57 +02:00
MCUdude
50220289bb Add high-voltage UPDI info to docs 2022-06-29 17:12:57 +02:00
MCUdude
e068341716 Make sure "-x hvupdi" is only valid for Pickit4 and Powerdebugger 2022-06-29 17:12:57 +02:00
MCUdude
f67c35744e add support for "-x hvupdi" that triggers HV UPDI 2022-06-29 17:12:57 +02:00
MCUdude
ba98e48880 add "hvupdi_variant" property to avrdude.conf 2022-06-29 17:12:52 +02:00
Stefan Rueger
0240b361f5 Merge branch 'avrdudes:main' into partdesc 2022-06-28 22:53:22 +01:00
Stefan Rueger
66c69a7584 Merge pull request #943 from stefanrueger/issue942
Fix Issue #942: Treat x bits in .conf SPI commands as 0
2022-06-28 22:50:53 +01:00
Stefan Rueger
43c6b04226 Update NEWS 2022-06-28 22:46:06 +01:00
Stefan Rueger
a21f3d20af Merge branch 'avrdudes:main' into issue942 2022-06-28 22:38:47 +01:00
Joerg Wunsch
a6ea797c1c PR 996 and 1013 done 2022-06-28 22:53:24 +02:00
Jörg Wunsch
8cd6f357b1 Merge pull request #1013 from MCUdude/jtag3-eeprom-fix
JTAG3 UPDI EEPROM fix
2022-06-28 22:36:19 +02:00
Jörg Wunsch
7ec51a5185 Merge pull request #996 from dl8dtl/jtag3_retcode
Replace internal knowledge in jtag3.c by a public API

Supersedes #982
2022-06-28 22:21:50 +02:00
Stefan Rueger
09c168a186 Merge branch 'avrdudes:main' into issue942 2022-06-28 20:56:49 +01:00
Stefan Rueger
d8a30aa8c4 Merge branch 'avrdudes:main' into partdesc 2022-06-28 20:44:34 +01:00
Stefan Rueger
3bd75e74c6 Move developer options into own source file and expand part description -p \*
-p \*/c  check address bits in SPI commands
  -p \*/d  description of core part features
  -p \*/o  opcodes for SPI programming parts and memories
  -p \*/s  show avrdude.conf entries of parts
  -p \*/ss show full avrdude.conf entry as tab separated table
  -p \*/w  wd_... constants for ISP parts
  -p \*/\* all of the above except -p \*/s
  -p \*    same as -p\*/\*
2022-06-28 20:34:31 +01:00
Stefan Rueger
cef3abac14 Merge branch 'avrdudes:main' into issue474 2022-06-26 23:54:43 +01:00
Joerg Wunsch
362e6993ac PR 993 done 2022-06-26 23:00:32 +02:00
Jörg Wunsch
6d1c83e182 Merge pull request #993 from prchal/patch-1
adding support for all Linux baud rates
2022-06-26 22:59:49 +02:00
Joerg Wunsch
1b997968a5 Closing PR 979 2022-06-26 22:58:25 +02:00
Jörg Wunsch
55dddc57cc Merge pull request #979 from MCUdude/dragon-jtag-fix
Dragon JTAG fix: restart firmware after programming
2022-06-26 22:53:32 +02:00
Fabrice Fontaine
17509d2ef4 CMakeLists.txt: fix build without C++
Fix the following build failure without a C++ compiler:

CMake Error at CMakeLists.txt:24 (project):
  No CMAKE_CXX_COMPILER could be found.

  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2022-06-26 21:35:42 +02:00
Stefan Rueger
0a7f2645c9 Merge branch 'partdesc' of github.com:stefanrueger/avrdude into partdesc 2022-06-26 15:15:37 +01:00
Stefan Rueger
54d590b9c1 Merge branch 'avrdudes:main' into issue474 2022-06-26 15:12:17 +01:00
Stefan Rueger
317cc6d492 Add part type to -p \* .desc output 2022-06-26 15:10:19 +01:00
Stefan Rueger
40425ffac4 Merge branch 'avrdudes:main' into partdesc 2022-06-26 14:49:07 +01:00
Hans
8159c46013 Merge branch 'avrdudes:main' into hv-updi 2022-06-25 22:47:27 +02:00
MCUdude
89b0aa72e0 Attempt to fix EEPROM write issue #1009 2022-06-25 11:39:16 +02:00
Joerg Wunsch
ae0e3e2f8e Fix a number of logic errors in the previous commits
RSP3_FAIL_CRC_FAILURE is 0x43 rather than 0x47.

jtag3_errcode() must only be applied to a reason code, not
to any general status code.
2022-06-22 23:33:53 +02:00
Joerg Wunsch
1aa59aaa98 PR #1000 is done now 2022-06-19 19:56:56 +02:00
Jörg Wunsch
6b5ca522d7 Merge pull request #1000 from MCUdude/reduce-str-length
Reduce programmer desc string length in avrdude.conf to < 80 characters
2022-06-19 19:56:02 +02:00
MCUdude
692c13ed98 Add missing chip erase delay for ATmega48/88/168/328PB 2022-06-19 19:40:31 +02:00
MCUdude
aa211f7580 Add missing efuse write delay for ATmega169/A/P/PA and ATmega328P 2022-06-19 19:23:34 +02:00
MCUdude
3b0a2abc20 Reduce programmer description string length
to less than 80 characters. #941 related
2022-06-19 10:53:07 +02:00
Stefan Rueger
c8350f816c Fix support for ATmega2560 et al (load extended address) 2022-06-18 22:34:54 +01:00
Joerg Wunsch
3082630430 Replace internal knowledge in jtag3.c by a public API
In certain situations (CRC failure, device locked), that JTAG3
read functions need to return an indication to the caller that
it is OK to proceed, and allow erasing the device anyway.

Historically, the JTAG3 code passed the respective protocol
errors directly (and unexplained) up to the caller, leaving
the decision to the caller how to handle the situation.

Replace that by a more common return value API. New code should
prefer this API instead of any hardcoded return values.
2022-06-15 23:32:22 +02:00
Marius Greuel
cb114233ef Mention PR #945, #962, #972 2022-06-10 20:38:54 +02:00
Marius Greuel
3148b31e01 Merge pull request #972 from earies/cmake-libdir-fix
Fix src/CMakeLists.txt to honor CMAKE_INSTALL_LIBDIR
2022-06-08 21:53:22 +02:00
Marius Greuel
fc9d640f0b Merge pull request #945 from mariusgreuel/pr-micronucleus-macos-usb-issue
Fix micronucleus bootloader to check for unresponsive USB devices
2022-06-08 21:46:40 +02:00
Marius Greuel
d9f8fded51 Merge pull request #962 from mariusgreuel/pr-cmake-enhancements
CMake Enhancements
2022-06-08 17:32:54 +02:00
prchal
bd8c17b35f adding support for all Linux baud rates v.2
If optiboot can work at higher bauds, why not avrdude.
Versoin 2 of #985.
Linux uses the old-style bitmapped version of the Bxxxx macros.
2022-06-07 11:50:03 +02:00
MCUdude
bdb4128de3 Fix JTAG transaction close issue
Fixes issue #366
2022-05-30 19:22:20 +02:00
Joerg Wunsch
feaa1c6a6b PR 950 done 2022-05-30 07:02:38 +02:00
Jörg Wunsch
5695b0d55a Merge pull request #950 from hallard/patch-1
fix M1 homebrew path
2022-05-30 07:00:38 +02:00
Stefan Rueger
952ad72fb9 Add -p \* to summarise properties of parts in conf 2022-05-24 16:56:11 +01:00
Ebben Aries
3b0d7e5d5d Fix src/CMakeLists.txt to honor CMAKE_INSTALL_LIBDIR 2022-05-21 14:25:27 -06:00
Marius Greuel
65bb41f8e9 CMake: Add build option to select static or shared libraries 2022-05-11 21:08:05 +02:00
Marius Greuel
0ea4b08b2f CMake: If installed, use static version of libreadline for MSYS2 2022-05-11 21:02:03 +02:00
Marius Greuel
053c2dcdd3 CMake: Include GCC specific options also for MSYS2 2022-05-11 20:57:14 +02:00
Marius Greuel
8b61c9dd8f CMake: Move MSVC compatibility shim into library 2022-05-11 20:56:05 +02:00
Marius Greuel
15fe12b1a9 Add CMakeSettings.json for Visual Studio 2022 2022-05-09 15:42:48 +02:00
Marius Greuel
b8420ee52d Update GitHub deploy action 2022-05-09 15:42:48 +02:00
Marius Greuel
6ebbd4e162 Update README.md 2022-05-09 15:42:48 +02:00
Marius Greuel
4b2bf38849 Add support for COM port discovery via USB VID/PID Add support for Leonardo USB bootloader auto-reset 2022-05-09 15:41:06 +02:00
Marius Greuel
9d6420e723 Correct endpoint direction for control messages of USBtinyISP devices 2022-05-09 15:41:06 +02:00
Marius Greuel
bc9b67a153 Change Intel HEX line length from 32 to 16 to match line length of avr-objcopy 2022-05-09 15:41:06 +02:00
Marius Greuel
93b2a56c0e Change program URL to github.com 2022-05-09 15:41:06 +02:00
Charles
a23055d648 fix typo 2022-05-09 14:51:16 +02:00
Charles
75bfbf7bef fix M1 homebrew path 2022-05-09 02:02:42 +02:00
Joerg Wunsch
4601bee4af Mention PR 949 2022-05-08 20:39:12 +02:00
Jörg Wunsch
5f091a6c1c Merge pull request #949 from subnut/manpage
Fix `.Dd` macro in manpage
2022-05-08 18:20:09 +02:00
Subhaditya Nath
b9a012cebb Fix .Dd macro in manpage
The correct format for .Dd according to mdoc(7) is -

	.Dd month day, year
2022-05-08 20:35:32 +05:30
Jörg Wunsch
1797c62c25 Merge pull request #948 from avrdudes/7.0-branch
Correctly name the release in CMakeLists.txt as well
2022-05-08 14:06:18 +02:00
Joerg Wunsch
d6347f4187 Correctly name the release in CMakeLists.txt as well 2022-05-08 14:00:53 +02:00
Joerg Wunsch
a855692d97 Correctly name the release in CMakeLists.txt as well 2022-05-08 13:58:44 +02:00
Joerg Wunsch
9bc28d410e Post-7.0 changes
Update version date in configure.ac.
Update template in NEWS
2022-05-07 22:57:49 +02:00
Joerg Wunsch
ec50337434 Correctly name the release in NEWS 2022-05-07 22:39:47 +02:00
Joerg Wunsch
a2e456ca8a v7.0 release preparation 2022-05-07 22:20:31 +02:00
Joerg Wunsch
43ddea9102 Calibration memory of ATtiny43U is only 1 byte
Closes issue #921.
2022-05-05 22:58:45 +02:00
Marius Greuel
01a9e42d7d Fix typo in micronucleus message 2022-05-05 22:08:46 +02:00
Marius Greuel
c64f2030a1 Improve micronucleus bootloader user experience for unresponsive USB devices 2022-05-05 21:42:27 +02:00
Marius Greuel
3bdf138721 Fix micronucleus bootloader to check for unresponsive USB devices 2022-05-05 20:45:47 +02:00
Joerg Wunsch
a4c9fcdcd7 More fixes for PR #915 2022-05-02 22:51:22 +02:00
Joerg Wunsch
28ccd82edc PR 930 931 issue 927 are done 2022-05-01 22:32:54 +02:00
Jörg Wunsch
ca16fc2ce6 Merge pull request #930 from cederom/cederom-programmer-avrftdi-ktlink
Added KT-LINK FT2232H interface with IO switching and voltage buffers.
2022-05-01 22:29:46 +02:00
Jörg Wunsch
d7c59ca2f9 Merge pull request #931 from MCUdude/linuxspi-baud-fix
Fix linuxspi baud to clock period calculation
2022-05-01 22:26:23 +02:00
Joerg Wunsch
4bcd0eaa1d Fix a number of mistakes in avrdude.conf.in
Stefan Rueger found a lot of mistakes in this file.

Closes #915
2022-05-01 21:55:50 +02:00
Stefan Rueger
033b2ed796 Treat x bits in .conf SPI commands as 0 2022-04-29 00:37:28 +01:00
Stefan Rueger
580c37fbfe Describe -A in the man and .texi documentation 2022-04-29 00:14:45 +01:00
Stefan Rueger
f47ec634f8 On verify always verify full input file 2022-04-28 17:53:10 +01:00
Stefan Rueger
52734bafc6 Add option -A to separately disable trailing-0xff removal 2022-04-28 17:29:06 +01:00
Stefan Rueger
52b20f4a28 Provide self-documenting API for disabling trailing-0xff removal 2022-04-28 17:26:09 +01:00
Stefan Rueger
2397984d2b Disable trailing-0xff removal when invoking arduino programmer 2022-04-27 18:54:13 +01:00
Joerg Wunsch
08ad5ea445 Fix broken texinfo
@ must be escaped as @@
2022-04-26 23:19:20 +02:00
Joerg Wunsch
5a3ff78844 Fix syntax error in workflow build.yml file 2022-04-26 21:41:03 +02:00
Joerg Wunsch
74a92d7991 Try to exclude the 'onlinedocs' branch from actions
There's no sourcecode within that branch, anyway.
2022-04-26 21:29:46 +02:00
Stefan Rueger
e18d436f88 Move evaluating 'is flash' from caller to callee avr_mem_hiaddr() 2022-04-15 20:48:46 +01:00
Stefan Rueger
ed38456f83 Piggy-back 'Do not remove trailing 0xff' onto option -D 2022-04-15 20:46:40 +01:00
MCUdude
6fceea8f71 Fix linuxspi default port
If no port is specified, Avrdude will try to use the default port specified in avrdude.conf. If not present, use port specified in linuxspi.c
2022-04-11 22:28:12 +02:00
MCUdude
9d025e6a70 Fix linuxspi baud to clock period calculation
#927 related
2022-04-10 23:36:53 +02:00
Tomasz 'CeDeROM' CEDRO
b99a145b9f Added KT-LINK FT2232H interface with IO switching and voltage buffers.
Example TPI run: https://github.com/avrdudes/avrdude/issues/928

Signed-off-by: Tomasz 'CeDeROM' CEDRO <tomek@cedro.info>
2022-04-10 22:28:44 +02:00
Joerg Wunsch
60960ba590 Closed 922, 924, 929 2022-04-10 22:20:11 +02:00
Jörg Wunsch
99a75701b1 Merge pull request #924 from MCUdude/terminal-overflow-fix
Fix terminal write buffer overflow issue
2022-04-10 22:19:27 +02:00
Jörg Wunsch
abe7180bb8 Merge pull request #929 from per1234/update-docs-link
Update documentation link to new URL
2022-04-10 22:15:23 +02:00
per1234
157b6a63c1 Update documentation link to new URL
The project documentation is now hosted on GitHub pages. Pointing the documentation link to the documentation site home page will offer the reader easy access to the documentation for the latest and previous releases while also avoiding the maintenance burden of updating the readme on every release
2022-04-10 11:28:39 -07:00
MCUdude
1363c7fe76 Fix buffer overflow issue
when in terminal fill mode
2022-04-09 20:08:44 +02:00
Joerg Wunsch
7e26a15375 PRs/Issues 900, 901, 913, 914 done 2022-04-05 20:55:23 +02:00
Jörg Wunsch
e84210c6b0 Merge pull request #914 from MCUdude/terminal-write-str
Add terminal write string functionality
2022-04-05 20:54:20 +02:00
MCUdude
08bd5fa938 Add string write to terminal example 2022-04-05 19:37:45 +02:00
MCUdude
17b67da03e Make sure memory can be filled with a string
... and not just the last character
2022-04-04 09:38:02 +02:00
Alexander Smirnov
3dc1e4e72b Wait and retry until deplayed udev permission rule applies after exporting gpio pin 2022-04-03 20:29:56 +01:00
MCUdude
795dd91575 Code cleanup + formatting 2022-04-01 22:23:55 +02:00
MCUdude
8f100f5df3 Initial support for string write 2022-04-01 21:57:53 +02:00
MCUdude
f0f9059ade Tweak nexttok for better string handling
Now a string that starts and ends with a quote (") is combined into a single (argc) argument rather than being split where spaces used to be
2022-04-01 16:52:59 +02:00
Nav
e069871c8e Increased timeout passed to hid_read_timeout() - set to 10000 for consistency (#901) 2022-03-31 23:26:53 +02:00
Joerg Wunsch
0aa43968a0 Add PR 908, 909, 910, 912 2022-03-31 23:14:35 +02:00
Hans
f22bc62b06 Mask out unused ATmega32U4 efuse bits (#909)
Closes #446
2022-03-31 23:13:57 +02:00
Hans
d09a4e93a2 Add ATmega16U4 to avrdude.conf (#910)
Closes #447
2022-03-31 23:12:32 +02:00
Hans
aa7ae7bb87 Add MacOS serial/parallel port note (#908)
Closes #510
2022-03-31 22:32:57 +02:00
Hans
1d0cbc2246 Add progressbar for read and write command (#912) 2022-03-31 22:21:49 +02:00
Joerg Wunsch
79c4137289 Mention the new search order for avrdude.conf 2022-03-22 08:49:04 +01:00
Joerg Wunsch
8697f6def7 Remove remnants of the old erase-cycle counter from examples 2022-03-21 06:38:28 +01:00
Joerg Wunsch
981a6f1f20 Restore the -u option as a dummy.
Closes #890
2022-03-20 21:50:45 +01:00
Joerg Wunsch
c64db5fb76 Link the project's "Pages" for documentation 2022-03-19 23:26:27 +01:00
Joerg Wunsch
50c373bf71 Mention issues #771, #897, PRs #898, #899, #902, #903 2022-03-19 23:05:19 +01:00
Jörg Wunsch
0c722bf288 Merge pull request #903 from dl8dtl/term-docs
Terminal mode documentation
2022-03-19 23:04:50 +01:00
Jörg Wunsch
28d1442fc8 Merge pull request #902 from MCUdude/terminal-fix
Minor terminal write improvements
2022-03-19 23:02:24 +01:00
Jörg Wunsch
75e4d06463 Merge pull request #899 from MCUdude/avrdude-conf-fix
Fix errors in Avrdude.conf

This also closes #897
2022-03-19 23:01:12 +01:00
Jörg Wunsch
99f191a0ca Merge pull request #898 from dl8dtl/macos-nonstandard-baudrates
Macos nonstandard baudrates

closes #266
2022-03-19 22:57:37 +01:00
Joerg Wunsch
33bace0cee Provide an example for the second form of the "write" command
In terminal mode, there are two forms of "write", one that
explicitly mentions all data values, and a second one that
instead specifies a total range to write, where the last data
value given is replicated as needed.
2022-03-19 17:30:55 +01:00
Joerg Wunsch
0c912a201f Try making the cindex (concept index) meaningful
Rearrange existing @cindex entries, add a lot of new ones.
2022-03-19 00:03:17 +01:00
Joerg Wunsch
31feb9ff75 Link the concept index 2022-03-19 00:00:54 +01:00
Joerg Wunsch
c5a28eedc0 Also tweak smallexample 2022-03-19 00:00:41 +01:00
Joerg Wunsch
29a01c1047 Terminal mode: fix documentation of second version of "write"
Right after start_addr, the next element is the number of bytes
to be written.
2022-03-18 23:42:32 +01:00
MCUdude
426ea1fa78 Add missing free()'s 2022-03-18 21:20:58 +01:00
MCUdude
6a5988ad64 Print write info message when in verbose mode 2022-03-18 21:19:36 +01:00
MCUdude
dcf771424b Increase buffer size to prevent potential overflow 2022-03-18 19:17:17 +01:00
Joerg Wunsch
67b56d322b Update texinfo documentation for terminal-mode changes
This documents the recent changes that have been implemented in
terminal mode.
2022-03-17 23:13:52 +01:00
Joerg Wunsch
27d201acb1 Also tweak smallexample 2022-03-17 07:21:33 +01:00
Joerg Wunsch
ded30f86bc CSS test 2022-03-16 23:22:14 +01:00
Joerg Wunsch
9bc4a2463d Attempt to tweak CSS of the generated HTML docs a bit 2022-03-16 23:19:45 +01:00
Joerg Wunsch
8ad55e07ac Update generated documentation 2022-03-13 22:55:33 +01:00
Joerg Wunsch
d89817ddb9 Merge branch 'main' into pages-test 2022-03-13 22:54:24 +01:00
Joerg Wunsch
fc6a71a142 Merge remote-tracking branch 'upstream/main' 2022-03-13 22:53:46 +01:00
Joerg Wunsch
da1271642e Remove the pointer to the mailing list
It makes more sense to point people to Github issue trackers now,
even for questions.
2022-03-13 22:52:44 +01:00
Joerg Wunsch
0e441013e9 Update docs 2022-03-13 00:31:27 +01:00
Joerg Wunsch
c5f7939fca Merge branch 'main' into pages-test 2022-03-13 00:29:54 +01:00
Joerg Wunsch
297d81818a Merge remote-tracking branch 'upstream/main' 2022-03-13 00:25:50 +01:00
Joerg Wunsch
7391e569b3 Bring the texinfo doc up to date
* remove copyright years; they are not meaningful anyway
* reflect the project move from Savannah to Github
2022-03-13 00:21:35 +01:00
Joerg Wunsch
67ab74cd6a Fix a one-bit error in ATmega165* signature read command. 2022-03-13 00:21:35 +01:00
Joerg Wunsch
631f671fe8 Mention PRs #893, #894, #896, bug #889 2022-03-13 00:21:20 +01:00
MCUdude
248b554e8d Add support for read with ... "operator"
This means that you can use ... to read the "rest" of the memory.
$ read eeprom ...   will dump the entire memory
$ read eeorm 0x80 ...   will dump the memory from address 0x80 to the end address
2022-03-13 00:20:07 +01:00
MCUdude
40e3aa1790 Incread default read size to 256 bytes 2022-03-13 00:20:07 +01:00
MCUdude
dca5fc92bf Restructure "write mode" code 2022-03-13 00:20:07 +01:00
MCUdude
4e05a8fa41 Update description 2022-03-13 00:20:07 +01:00
MCUdude
1299d6b8bd Fix terminal write bug
Wouldn't write data properly after an integer >= 2 bytes was written
2022-03-13 00:20:07 +01:00
MCUdude
da315d7323 Support both userrow and usersig names 2022-03-13 00:20:07 +01:00
Joerg Wunsch
416c465ec0 Bring the texinfo doc up to date
* remove copyright years; they are not meaningful anyway
* reflect the project move from Savannah to Github
2022-03-13 00:13:29 +01:00
MCUdude
41f524c1ba Use the same device signature on ATmega165 and ATmega165A 2022-03-08 13:17:01 +01:00
MCUdude
5ebb9047be Fix incorrect ATxmega128D4 flash page size 2022-03-08 12:50:17 +01:00
MCUdude
fde7881611 Fix incorrect ATmega64M1 flash and eeprom size
#897 related
2022-03-08 12:34:06 +01:00
MCUdude
1c94c95f1c Fix target names not following the standard 2022-03-08 12:32:41 +01:00
Joerg Wunsch
e2995857ac Remove verboseness from build.sh
Got accidentally committed.
2022-03-07 23:27:54 +01:00
Joerg Wunsch
a4cbd5c6fc Append a newline to the nonstandard baudrate warning 2022-03-07 23:25:36 +01:00
Joerg Wunsch
87b39637ff Implement nonstandard baudrate handling on MacOS
Alas, MacOS doesn't handle nonstandard baud rates like other systems
in regular tcsetattr() calls. Instead, they invented a new ioctl
(IOSSIOSPEED). So, if we notice we are going to configure a
nonstandard rate on MacOS, issue that ioctl after configuring
everything else using tcsetattr().
2022-03-07 23:20:50 +01:00
Joerg Wunsch
34168759b0 Fix a one-bit error in ATmega165* signature read command. 2022-03-07 22:52:14 +01:00
Joerg Wunsch
c746c9bc9e Fix a one-bit error in ATmega165* signature read command. 2022-03-07 22:49:46 +01:00
Joerg Wunsch
65618ed655 Fix a one-bit error in the signature read command for ATmega165* 2022-03-07 21:38:17 +01:00
Joerg Wunsch
00ea962abe Add link to docs 2022-03-07 00:22:59 +01:00
Joerg Wunsch
d62f309a00 Add symlink for index.html 2022-03-07 00:18:04 +01:00
Joerg Wunsch
92a5ae20a6 Test for Github pages 2022-03-07 00:09:47 +01:00
Joerg Wunsch
5cbc9c37fc Mention PRs #893, #894, #896, bug #889 2022-03-03 23:15:20 +01:00
Jörg Wunsch
0f4b5b223b Merge pull request #894 from MCUdude/terminal
Improve terminal read functionality
2022-03-03 23:14:37 +01:00
Jörg Wunsch
0b82b5c573 Merge pull request #896 from MCUdude/terminal-write
Fix ugly terminal write bug
2022-03-03 23:12:47 +01:00
Jörg Wunsch
9355d67e0f Merge pull request #893 from MCUdude/userrow-fix
Support both userrow and usersig names
2022-03-03 23:09:20 +01:00
MCUdude
d9c52249a9 Restructure "write mode" code 2022-03-03 19:37:42 +01:00
MCUdude
c7174d7678 Update description 2022-03-02 20:24:51 +01:00
MCUdude
df6e2eea12 Fix terminal write bug
Wouldn't write data properly after an integer >= 2 bytes was written
2022-03-02 20:09:59 +01:00
Joerg Wunsch
0d58adb10a Close #892 #895 2022-03-01 23:30:11 +01:00
Jörg Wunsch
ebb1849724 Merge pull request #895 from janegilruud/bugfix/fix-cnano-updi-flash-read
For UPDI devices do not add offset when accessing flash.
2022-03-01 23:26:11 +01:00
Jan Egil Ruud
0c8b42524e For UPDI devices do not add offset when accessing flash. 2022-03-01 14:24:33 +01:00
MCUdude
b688b1f601 Add support for read with ... "operator"
This means that you can use ... to read the "rest" of the memory.
$ read eeprom ...   will dump the entire memory
$ read eeorm 0x80 ...   will dump the memory from address 0x80 to the end address
2022-02-28 23:59:30 +01:00
MCUdude
d89f695c31 Incread default read size to 256 bytes 2022-02-28 23:59:30 +01:00
MCUdude
1f2b570216 Support both userrow and usersig names 2022-02-28 19:46:47 +01:00
Joerg Wunsch
64cc54ac35 PR #888 done 2022-02-21 23:28:50 +01:00
Jörg Wunsch
e2e5e44bab Merge pull request #888 from MCUdude/userrow-alias
Add userrow and usersig aliases
2022-02-21 23:28:05 +01:00
MCUdude
07ea8f5e09 Add userrow and usersig aliases 2022-02-21 22:36:06 +01:00
Joerg Wunsch
0269817217 Add a missing @end table
Has been slipped when adding some -x documentation before.
2022-02-21 22:01:05 +01:00
Joerg Wunsch
fe6290072a PR #880 done 2022-02-21 21:54:47 +01:00
Jörg Wunsch
008f95f6ff Merge pull request #880 from MCUdude/terminal-write
Avrdude terminal write improvements
2022-02-21 21:53:38 +01:00
MCUdude
a73567893b Properly handle negative number sizes 2022-02-21 13:43:38 +01:00
MCUdude
fa706f0d01 Handle data size warning better
Now it only outputs a warning when the size of the data the user input is actually ambiguous
2022-02-20 23:03:31 +01:00
MCUdude
3532c567ac Add suffix for 8-bit data
use [val]HH or [val]hh to force 8-bit writes to memory
2022-02-20 22:23:15 +01:00
Joerg Wunsch
14f646822c PR #886 done 2022-02-20 20:59:28 +01:00
Jörg Wunsch
bb73ade70b Merge pull request #886 from dbuchwald/ser_posix_cleanup
Cleanup of POSIX serial init code
2022-02-20 20:58:22 +01:00
MCUdude
bb99a36a14 Formatting
Use enums for write mode, and change datatypes from int/long/char to int32_t/uint8_t where possible
2022-02-20 19:08:30 +01:00
Joerg Wunsch
0d7d034d24 Issue #884 closed 2022-02-20 16:58:39 +01:00
Joerg Wunsch
c7d1ebcf1f Issue #881 also fixed 2022-02-20 14:37:04 +01:00
Joerg Wunsch
b891b7c64b Issue #874 is closed 2022-02-20 14:35:50 +01:00
MCUdude
a9b756e5c7 Add struct initialization list 2022-02-20 12:46:53 +01:00
Dawid Buchwald
cf67a76c23 Merge branch 'main' into ser_posix_cleanup 2022-02-20 12:37:19 +01:00
MCUdude
0e29b43bd0 Add support for 64-bit integers
Also, move everything data related into a struct, to keep tings a little more organized
2022-02-19 23:34:50 +01:00
MCUdude
4b9219edee Add support for suffixes for manually specifying data size
H/h/S/s: 16-bit, L/l: 32-bit, F/f: 32-bit float
2022-02-19 22:48:58 +01:00
Joerg Wunsch
428cd89e8d PRs #878, #873, #885 done 2022-02-19 21:54:23 +01:00
Jörg Wunsch
3efd3b2052 Merge pull request #873 from MCUdude/add-arduino-programmers
Add missing USBtiny derived programmers
2022-02-19 21:51:31 +01:00
Jörg Wunsch
7c65adba26 Merge pull request #885 from dbuchwald/simple_updi_fix
Smallest possible fix for PL2303HX
2022-02-19 21:50:41 +01:00
Dawid Buchwald
75ab3c418e Fixed warning with unsigned char 2022-02-19 21:18:03 +01:00
MCUdude
62f3b84eee Use union for simpler data representation
It is a bit hacky, but for this purpose it fits surprisingly well
2022-02-19 20:15:52 +01:00
Dawid Buchwald
066f54fbfa Cleanup of POSIX serial init code 2022-02-19 18:00:58 +01:00
Dawid Buchwald
de19f203e0 Smallest possible fix for PL2303HX 2022-02-19 15:07:32 +01:00
Jörg Wunsch
d054c68b19 Merge pull request #878 from MCUdude/fix-pkob-target-voltage
Fix Curiosity Nano target voltage
2022-02-18 23:01:49 +01:00
Joerg Wunsch
5c90fbbaae PR #877 done 2022-02-18 22:53:45 +01:00
Jörg Wunsch
c2fe68ef7d Merge pull request #877 from MCUdude/jtag3-verbosity
Reduce jtag3 output verbosity
2022-02-18 22:38:40 +01:00
Hans
c345985928 Merge branch 'avrdudes:main' into terminal-write 2022-02-18 22:09:42 +01:00
Joerg Wunsch
c1ec836fbd PR #882 done 2022-02-18 21:37:27 +01:00
Jörg Wunsch
ba01fd7e30 Merge pull request #882 from mariusgreuel/pr-libhid-cleanup-part1
Remove libhid support in ser_avrdoper.c in favor of libhidapi
2022-02-18 21:36:12 +01:00
Marius Greuel
59ecd4cc65 Remove libhid support in ser_avrdoper.c in favor of libhidapi 2022-02-18 20:05:52 +01:00
Marius Greuel
e31be88ce0 Add LIB_LIBHID to CMake project to fix MinGW build issue 2022-02-18 19:58:13 +01:00
MCUdude
6e7f38e81f Properly handle negative numbers
Now -3.141592 and -32768 are valid numbers that's stored correctly in memory
2022-02-18 09:58:16 +01:00
MCUdude
10e05eed21 Require single quotes when writing characters 2022-02-18 09:58:16 +01:00
MCUdude
551046052e Add support for writing floats 2022-02-18 09:58:16 +01:00
MCUdude
2a92b8cce4 Add support for memory "fill" with arbitrary data too
If you run the following command: $ write eeprom 0x00 0x10 A B C ...

It will write the following data to EEPROM:
|ABCCCCCCCCCCCCCC|
starting from address 0x00
2022-02-18 09:58:16 +01:00
MCUdude
c007dc7d24 Add support for writing single characters
Now this is possible: write eeprom 0x00 a b c d e f 0x80 0x90 ! H E L L O
2022-02-18 09:58:16 +01:00
MCUdude
2589b17640 Add support for memory "fill" mode
Syntax: write <memtype> <start addr> <no. byte to write> <byte to write> ...
2022-02-18 09:58:13 +01:00
MCUdude
19e2cae053 Add Curiosity Nano to terminal list 2022-02-14 10:30:21 +01:00
MCUdude
932f68f24c Set target voltage even thoug not target is detected 2022-02-14 10:28:54 +01:00
MCUdude
b1d34a510c Reduce jtag3 output verbosity 2022-02-13 19:23:48 +01:00
MCUdude
f2bdcbe977 Add missing USBtiny derived programmers
ArduinoISP and the Arduino.org ISP are commercial versions of the USBtiny programmer with different USB VIDs/PIDs
2022-02-11 22:46:11 +01:00
Joerg Wunsch
7b79b72794 PR #872 done 2022-02-11 22:17:24 +01:00
Jörg Wunsch
76a17be4d0 Merge pull request #872 from MCUdude/jtag-string-formatting
Tweak programmer info formatting strings
2022-02-11 22:16:39 +01:00
MCUdude
80f1d96e07 Tweak programmer info formatting strings
Now all colons are on a straight line, just like #853 did to all jtag3 compatible programmers
2022-02-11 22:10:52 +01:00
Joerg Wunsch
09fe08e51c PR #853 done 2022-02-11 21:45:31 +01:00
Jörg Wunsch
f2c73c2bb8 Merge pull request #853 from MCUdude/jtag3-clock-update
Print JTAG3 clocks after configuration + string formatting
2022-02-11 21:44:54 +01:00
MCUdude
b581d14823 String formatting
Allign colons, only print clocks that are actually present (>0 kHz)
2022-02-11 21:35:07 +01:00
Joerg Wunsch
354a1c4f1f PR #869 closed 2022-02-11 21:17:01 +01:00
Jörg Wunsch
23a09a6197 Merge pull request #869 from MCUdude/alias-memories
Add fuse name aliases to avrdude.conf + tweak update.c
2022-02-11 21:15:34 +01:00
MCUdude
3fc39c47ad Print memory name alias together with the canonical name if present
in avrdude.conf. An example would be "avrdude: reading fuse0/wdtcfg memory:"
2022-02-11 21:10:05 +01:00
MCUdude
d6ccf7a3ff Add memory alias names for megaAVR0/tinyAVR0,1,2/AVR-Dx/AVR-Ex fuses 2022-02-10 22:34:33 +01:00
Joerg Wunsch
452f673f38 Back out the last "alias" commit (search for existing alias).
It breaks the alias handling completely as the search happens
way too late. So instead, just keep any possibly duplicate
name as it won't be in our way anyway.
2022-02-10 21:26:05 +01:00
Joerg Wunsch
38a3af37e2 Mention PRs #863 and #868. 2022-02-10 20:39:51 +01:00
Jörg Wunsch
d134dc8fff Alias keyword (#868)
Implementation for an "alias" keyword.

By now, only applied inside memory descriptions.

* Make "mem_alias" a separate nonterminal.

The previous implementation attempt caused a syntax error in
yacc code, and separating mem_alias on the same level as
mem_spec appears to be the cleaner solution anyway.

* Maintain real memory aliases.

Instead of duplicating the aliased memory with a new name, maintain a
second list of memory aliases (per device) that contains a pointer to
the memory area it is aliased to. That way, a memory name can be
clearly distinguished between the canonical one and any aliases.

* Check p->mem_alias != NULL before touching it

* Add avr_find_memalias()

This takes a memory region as input, and searches whether an
alias can be found for it.

* We need to add a list structure for the mem_alias list, always.

By that means, mem_alias won't ever be NULL, so no need to check
later.

Also, in avr_dup_part(), duplicate the alias list.

* In a memory alias, actually remember the current name.

* In avr_dup_part(), adjust pointers of aliased memories

While walking the list of memories, for each entry, see if there is an
alias pointing to it. If so, allocate a duplicated one, and fix its
aliased_mem pointer to point to the duplicated memory region instead
of the original one.

* Add avr_locate_mem_noalias()

When looking whether any memory region has already been defined for
the current part while parsing the config file, only non-aliased names
must be considered. Otherwise, a newly defined alias would kick out
the memory definition it is being aliased to.

* When defining a mem_alias, drop any existing one of that name.

* Actually use avr_find_memalias() to find aliases

* Add declaration for avr_find_memalias()

* When defining a memory, also search for an existing alias

If the newly defined name has the same as an existing alias, the alias
can be removed.

Note that we do explicitly *not* remove any memory by the same name of
a later defined alias, as this might invalidate another alias'es
pointer. If someone defines that, the alias name just won't ever be
found by avr_locate_mem().
2022-02-10 20:39:19 +01:00
Jörg Wunsch
ba314f23e9 Merge pull request #863 from MCUdude/jtag3-read-memory-alias
Add support for reading from more memory sections
2022-02-10 20:35:06 +01:00
MCUdude
a43f220ef9 Add support for reading from more memory sections
It's now possible to read the following memories if present: osccal16, osccal20, tempsense, osc16err, osc20err
2022-02-07 21:51:35 +01:00
Joerg Wunsch
1c0b70da89 PR #859 done 2022-02-05 22:03:59 +01:00
Jörg Wunsch
b6a6c681df Merge pull request #859 from dl8dtl/safemode-removal
Remove the "safemode" feature.
2022-02-05 22:03:12 +01:00
Joerg Wunsch
3eda1d15f9 Mention PR #858 2022-02-05 21:59:04 +01:00
Marius Greuel
c6438532f0 Merge pull request #858 from yegorich/cmake-install-fix
CMake: use CMAKE_CURRENT_BINARY_DIR to locate avrdude.conf
2022-02-05 21:46:38 +01:00
MCUdude
625027a807 Add HV UPDI pulse command 2022-02-05 14:44:13 +01:00
Joerg Wunsch
6fd68ed7fe Mention Hans Eirik Bull for his recent contributions 2022-02-01 23:26:20 +01:00
Joerg Wunsch
36de84ab48 Mention Dawid and Marius for their recent contributions. 2022-02-01 20:35:15 +01:00
Joerg Wunsch
8c6c6a14ec Remove the "safemode" feature.
This feature has been designed with the sometimes quite flakey direct
(parallel or serial port attached) bitbang programming adapters in
mind that were quite common about two decades ago.

With parallel ports vanishing from modern PCs almost completely, and
the advent of various USB-attached low-cost programming devices,
this class of programmers disappeared almost completely.

Furthermore, the fuse combinations that were covered by the feature
are no longer around on all recent AVR devices, so for an ever
increasing number of devices, safemode already became meaningless and
was turned off anyway.

With the prospective version 7.x release, it's a good point in time to
introduce a major change like this one.
2022-01-31 20:44:32 +01:00
Yegor Yefremov
7ed3632902 CMake: use CMAKE_CURRENT_BINARY_DIR to locate avrdude.conf
With the split CMakeLists.txt infrastructure avrdude.conf
will be created in the build/src and not build folder. Hence,
fix its location in the install command.
2022-01-31 07:18:59 +01:00
Joerg Wunsch
e28e28d7c3 With the new CMake file structure, no need to dive into "src" 2022-01-30 10:46:27 +01:00
Joerg Wunsch
a3868a8260 Mention PR/issue 855, 856, 857 2022-01-30 10:45:53 +01:00
Jörg Wunsch
e0bc6a8bd6 Merge pull request #855 from MCUdude/fix-arduino-retry-attempts
Fix Arduino retry attempts
2022-01-30 10:45:24 +01:00
Jörg Wunsch
69177dfe3f Merge pull request #857 from dl8dtl/fix-856
Assign proper type to msg[] in errstr()
2022-01-30 10:41:53 +01:00
Joerg Wunsch
b84e6862a7 Assign proper type to msg[] in errstr()
Obviously, the array ought to be of type char.

Closes Issue #856
2022-01-29 23:32:39 +01:00
MCUdude
7144a9f2ae Replace incorrect warning message
Was mistakenly added in PR #854.
2022-01-29 20:08:43 +01:00
MCUdude
28be45d8b6 Fix Ardino sync attempts
In order for the Arduino bootloader to re-sync with Avrdude, the microcontroller needs to be reset to start the bootloader again.
2022-01-29 19:53:42 +01:00
Joerg Wunsch
4ff72ac462 Mention all closed PRs and bug issues. 2022-01-27 23:20:26 +01:00
Jörg Wunsch
4ea4ff7fba Merge pull request #850 from dl8dtl/usbasp-errstr
Fix libusb-1.0 error strings
2022-01-27 23:18:51 +01:00
Jörg Wunsch
7e7c4e630e Merge pull request #854 from MCUdude/arduino-stk500
Set number of connection retry attempts for Arduino/STK500 programmer
2022-01-27 23:17:28 +01:00
Jörg Wunsch
39deb3a600 Merge pull request #852 from yegorich/cmake-split
CMake: split configuration in two files
2022-01-27 23:16:37 +01:00
Jörg Wunsch
dd8c3ff830 Merge pull request #843 from mariusgreuel/pr-ftdi-syncbb
Fix receive buffer implementation in ftdi_syncbb programmer
2022-01-27 23:15:10 +01:00
MCUdude
ad6eff0f76 Set number of Arduino/STK500 connection retry attempts
Using the extended parameter flag -x. Usage: . Default number of attempts is still 10 if not -x flag is specified
2022-01-25 09:40:24 +01:00
MCUdude
286c0f5e2a Don't print irrelevant information for the Arduino programmer 2022-01-24 22:16:31 +01:00
MCUdude
f6bbaadfa6 Print clock info after the correct clock speeds has been set
The "new" clock speed set by the -B flag wasn't reflected in the output log
2022-01-23 22:45:54 +01:00
Yegor Yefremov
acee6afa4e CMake: split configuration in two files
The main CMakeLists.txt file in the project's root directory takes
care of the main project settings like project name and version,
handling the options, finding dependencies, etc.

The src/CMakeLists.txt handles options that are necessary to build
libavrdude library and avrdude binary.
2022-01-23 21:22:07 +01:00
Joerg Wunsch
42a154dddf Fix libusb-1.0 error strings
Previously, all libusb-1.0 error strings have been translated
by libusb_to_errno() into an errno-like integer, only in order
to pass that one straight into strerror().

For unhandled libusb-1.0 error codes, ERANGE was returned, which
is just nonsense ("Result too large", bug #848).

Instead, use a single function errstr() now that either can
use strerror() on some well-defined errno-like code, or otherwise
just return a string that mentions the numeric value.
2022-01-21 23:13:56 +01:00
Joerg Wunsch
de3d7c1659 PR #849 merged 2022-01-21 21:56:36 +01:00
Joerg Wunsch
a8f7e96222 PR #815 merged 2022-01-21 21:56:07 +01:00
Joerg Wunsch
37b0659951 PR #816 merged
Copy over man page additions into texinfo file as well.
2022-01-21 21:56:07 +01:00
Joerg Wunsch
4538d91091 PR #829 merged 2022-01-21 21:56:07 +01:00
Jörg Wunsch
6d762a835b Merge pull request #849 from dl8dtl/buildscripts
Add a build script for Unix-like systems
2022-01-21 21:55:57 +01:00
Jörg Wunsch
cce7a934d6 Merge pull request #815 from MCUdude/add-memory-sections
Add more memory sections to read from
2022-01-21 21:49:29 +01:00
Jörg Wunsch
490558049e Merge pull request #816 from andrewshadura/usbtiny-spi
Add SPI support to USBtiny
2022-01-21 21:40:00 +01:00
Jörg Wunsch
512cce405c Merge pull request #829 from yegorich/cmake-install-liavrdude
CMake: add initial support for installing lib and include files
2022-01-21 21:37:21 +01:00
Joerg Wunsch
e5ac9e943c Add a build script for Unix-like systems 2022-01-21 21:33:10 +01:00
Joerg Wunsch
0b1db09daf PR #944 merged 2022-01-21 21:28:15 +01:00
Jörg Wunsch
1b8b1d69e7 Merge pull request #844 from MCUdude/jtagmkii-retry-attempts
jtagmkii: Reduce the number of sync attempts to 10 + print number of attempts
2022-01-21 21:27:30 +01:00
Hans
d401b2224e Merge branch 'main' into jtagmkii-retry-attempts 2022-01-21 13:28:20 +01:00
Joerg Wunsch
950583323f PR #845 merged 2022-01-20 10:23:31 +01:00
Jörg Wunsch
0682af212c Merge pull request #845 from MCUdude/reduce-verbosity
Reduce verbosity when setting fuses and uploading programs
2022-01-20 10:22:52 +01:00
MCUdude
b1cbbfc9f0 Reduce verbosity when setting fuses and uploading programs
Affects commands with no -v flag and one -v flag
2022-01-20 09:45:34 +01:00
MCUdude
dbac0ecf8c Reduce the number of attempts to 10
+ print number of attempts
2022-01-19 23:25:47 +01:00
Joerg Wunsch
325604f970 PR #842 done 2022-01-19 22:56:47 +01:00
Yegor Yefremov
8be18c788e CMake: add initial support for installing lib and include files 2022-01-18 14:54:42 +01:00
Joerg Wunsch
090920298d PR #842 done 2022-01-18 13:26:52 +01:00
Jörg Wunsch
fa58267643 Merge pull request #842 from mariusgreuel/pr-ft232r
Add a new programmer ft232h
2022-01-18 13:25:25 +01:00
Marius Greuel
44b0c0715f Fix receive buffer implementation in ftdi_syncbb programmer 2022-01-17 22:53:58 +01:00
Marius Greuel
7b9f258806 Add a new programmer 'ft232h', similar to ft232r. Improve and correct pinout documentation for um232h and c232hm programmer. 2022-01-17 22:49:03 +01:00
MCUdude
0e451f73cf Print alias names if present 2022-01-17 21:34:09 +01:00
Joerg Wunsch
b3c76f3e54 PR #836 is merged, mention all new devices brought by that 2022-01-16 23:01:10 +01:00
Jörg Wunsch
54d143d4a5 Merge pull request #836 from MCUdude/add-missing-targets
Add missing tinyAVR-2, AVR DD and AVR EA targets
2022-01-16 22:59:41 +01:00
MCUdude
4453d54296 Add memory name aliases for AVR DA/DB
+ add sernum and tempsense memory sections to read from
2022-01-15 21:53:58 +01:00
MCUdude
9c08c0c164 Attempt to fix incorrect readsize values
Values copied AVR64DD__.atdf and AVR64EA__.atdf. The order atdf files doesn't exist at the moment
2022-01-15 12:47:58 +01:00
MCUdude
628c48aff6 Add AVR EA targets
This includes AVR8EA28/32, AVR16EA28/32/48, AVR32EA28/32/48 and AVR64EA28/32/64
2022-01-14 20:30:49 +01:00
MCUdude
8e47768600 Add AVR DD targets
This includes AVR16DD14/20/28/32, AVR32DD14/20/28/32 and AVR64DD14/20/28/32
2022-01-14 19:52:22 +01:00
Joerg Wunsch
e5edecf95e PR #811 is merged 2022-01-14 08:25:43 +01:00
Jörg Wunsch
b99687f33c Merge pull request #811 from dbuchwald/main
Added missing RTS/DTR management feature to serialupdi programmer
2022-01-14 08:24:58 +01:00
Joerg Wunsch
153031d6d6 Copy over description of extended parameters to avrdude.1 2022-01-14 08:18:56 +01:00
Joerg Wunsch
c31578cbbd Add cscope.out to list of ignored files 2022-01-13 22:43:03 +01:00
MCUdude
310fe49b73 Add missing tinyAVR-2 series targets
Includes ATtiny3224, ATtiny3226 and ATtiny3227
2022-01-13 22:29:22 +01:00
Joerg Wunsch
5c264992fc PR #832 is done 2022-01-13 21:47:53 +01:00
Jörg Wunsch
77a5703c5c Merge pull request #832 from MCUdude/add-even-more-missing-targets
Add missing ATmega and ATtiny targets
2022-01-13 21:26:43 +01:00
Joerg Wunsch
822578cffd Mention PR #809
Also fix signatures for ATmega169A, ATmega165 and ATmega165A.
2022-01-13 20:08:40 +01:00
Jörg Wunsch
d1634e4d96 Merge pull request #809 from MCUdude/add-missing-atmega-targets
Add missing ATmega__5 and ATmega__9 targets to avrdude.conf
2022-01-13 19:59:42 +01:00
MCUdude
99d8fa5d88 Add missing ATtiny targets
+ a little formatting
2022-01-13 19:45:45 +01:00
MCUdude
cc77f89953 Add missing ATmega targets
+ a little formatting
2022-01-13 19:45:30 +01:00
MCUdude
7064447378 Add all possible ATmega__5 and ATmega__9 targets
This includes the "non-P", A, P and PA suffixes
2022-01-13 18:27:36 +01:00
MCUdude
77ed8b98c5 Add ATmega165A/P targets 2022-01-13 18:27:36 +01:00
MCUdude
32232faa2b Add missing ATmega targets 2022-01-13 18:27:34 +01:00
Dawid Buchwald
ab57f38387 Replaced tabs by spaces 2022-01-13 10:01:01 +01:00
Dawid Buchwald
90d0fa7346 Merge remote-tracking branch 'avrdudes/main' into main 2022-01-13 09:57:42 +01:00
Marius Greuel
956a274abd Remove libreadline from GitHub build action 2022-01-12 23:19:28 +01:00
Marius Greuel
3fbac230b3 Enable printf %n format specifier for MSVC 2022-01-12 20:41:52 +01:00
Marius Greuel
0ba4d2eaee Change GitHub build action to create separate artifacts for executables 2022-01-12 18:16:02 +01:00
Joerg Wunsch
1faa02b9cb Mention PR #828 and issue #823 2022-01-11 22:13:57 +01:00
Jörg Wunsch
dc2f5b25a2 Merge pull request #828 from dl8dtl/fix-tpi-fuse-write
Fix for TPI fuse write (closes #823)
2022-01-11 22:12:37 +01:00
Joerg Wunsch
65d5cfadc1 Fix for TPI fuse write
In get_fuse_bitmask(), ensure the AVR_OP_READ and AVR_OP_WRITE
m->op[] fields are actually filled in, before referencing them.
If they are missing, just return a full byte mask (0xFF).

In avr_write(), for TPI memory, if the write consist of one byte onle
(which is the case for fuse byte writing), resort to avr_write_byte()
instead as it already implements everything needed. This leaves the
avr_write() implementation to handle full paged writes with an even
number of bytes only.
2022-01-11 22:00:22 +01:00
Joerg Wunsch
1049777283 PR #826 is done 2022-01-11 15:41:32 +01:00
Jörg Wunsch
4e1bbf07ac Merge pull request #826 from yegorich/cmake-dll
CMake: enable dynamic-link library for libavrdude
2022-01-11 15:40:58 +01:00
Yegor Yefremov
e72fa01073 Fix libavrdude library file name
CMake adds "lib" prefix to the library name and hence we get the
following name "liblibavrdude". Use set_target_properties to
set the prefix to "".
2022-01-11 14:58:40 +01:00
Joerg Wunsch
60bda0bcc4 PR #820 is merged 2022-01-11 12:45:04 +01:00
Jörg Wunsch
2d833e7ceb Merge pull request #820 from dl8dtl/libavrdude-remove-ac_cfg_h
Remove ac_cfg.h from libavrdude.h
2022-01-11 12:44:26 +01:00
Yegor Yefremov
8374564665 CMake: enable dynamic-link library for libavrdude
Add on option BUILD_SHARED_LIBS to also build a DLL variant
of the libavrdude library. Turn it off by default to preserve
current behavior.
2022-01-11 12:02:36 +01:00
Joerg Wunsch
b33709bc04 Mention Micronucleus bootloader (PR #786 - thanks, Hans!) 2022-01-10 22:15:14 +01:00
Joerg Wunsch
c7f7fcda8e Fix URL for linuxgpio programmer
Closes #419
2022-01-10 22:12:36 +01:00
Joerg Wunsch
6870417860 Merge branch 'main' of github.com:avrdudes/avrdude 2022-01-10 21:45:14 +01:00
Joerg Wunsch
829425f246 Mention PR #818 2022-01-10 21:33:31 +01:00
Jörg Wunsch
22e6c4b325 Merge pull request #818 from yegorich/pindefs-fix-warning
pindefs: conform to the function declaration
2022-01-10 21:33:04 +01:00
Joerg Wunsch
a3bf6cc4c5 Fix names of Logic Green devices
There's some confusion as the datasheet calls the device family
LGT8FX8P but the devices itself are LGT8F88P through LGT8F328P.
Obviously, the "X" is actually a wildcard denoting the flash size.
2022-01-10 21:29:09 +01:00
Joerg Wunsch
b1b80bfa4a Mention PR #817 and issue #812 2022-01-10 21:27:01 +01:00
Jörg Wunsch
0a4193f742 Merge pull request #817 from mariusgreuel/pr-print-expected-part
Print expected part
2022-01-10 21:25:39 +01:00
Joerg Wunsch
48bcc269e2 Remove ac_cfg.h from libavrdude.h 2022-01-10 15:12:33 +01:00
Joerg Wunsch
cf35b7fe32 Include ac_cfg.h before libavrdude.h
On MSVC, this is required in order to have a definition of
PATH_MAX in place.
2022-01-10 14:51:48 +01:00
Joerg Wunsch
fa8a31740f Remove ac_cfg.h from libavrdude.h 2022-01-10 14:27:08 +01:00
Dawid Buchwald
92a3eb1080 Merge remote-tracking branch 'avrdudes/main' into main 2022-01-09 23:39:09 +01:00
Joerg Wunsch
ea29434568 Mention PR #814 and the issues it closes 2022-01-09 20:33:05 +01:00
Jörg Wunsch
5746bb2670 Merge pull request #814 from dl8dtl/notify-open-failure
Notify user about open failure

Closes #813 (also closes #471)
2022-01-09 20:30:10 +01:00
Marius Greuel
f043e1b484 Work around choco failure in build.yml 2022-01-09 20:13:11 +01:00
MCUdude
2fd967866c Don't display target info that's not present in Avrdude.conf
I still have to figure out why all parts are flagged with support for both serial and parallel programming interfaces, even when this is not the case
2022-01-09 18:13:07 +01:00
Yegor Yefremov
1a85e01b63 pindefs: conform to the function declaration
The last parameter in the pins_check() routine is declared as
"const bool". Add the missing "const" specifier.
2022-01-09 15:57:45 +01:00
Marius Greuel
f67cb3c224 Preserve the insertion order of programmers and parts when parsing the avrdude.conf file 2022-01-09 11:52:52 +01:00
Marius Greuel
1297098eae When the specified part has a matching signature, print the specified part instead of one from the parts list 2022-01-09 11:52:47 +01:00
David Fries
40f0fae5a4 Update manpage for USBtiny and direct SPI 2022-01-09 10:57:22 +01:00
David Fries
cffa6c7ca0 Add direct SPI mode to USBtiny
It is limited to exactly sending (and receiving) multiples of 4 bytes,
and unlike programming mode where slave select isn't required, SS must
be held low for SPI to work. USBtiny programmers don't usually have
a wire for SS.
2022-01-09 10:57:22 +01:00
David Fries
112b6edd1c Set back to programming mode on quit
Otherwise it can't read the fuses and the safe fuse code complains.
2022-01-09 10:27:36 +01:00
MCUdude
8f16c2a1e4 Add more memory sections to read from
+ improve Avrdude output in verbose mode
2022-01-08 23:57:37 +01:00
Joerg Wunsch
a182ef5a26 Notify user if pgm->open() failes
This is supposed to fix issue #813
2022-01-08 22:02:25 +01:00
Jörg Wunsch
a447673b07 Merge branch 'avrdudes:main' into main 2022-01-08 21:46:12 +01:00
Dawid Buchwald
a8de8b8b8f Merge branch 'avrdudes:main' into main 2022-01-08 19:44:20 +01:00
Dawid Buchwald
4a26aac5c8 Added RTS/DTR release message 2022-01-08 19:14:33 +01:00
Dawid Buchwald
b70fe0e956 Added RTS/DTR status message 2022-01-08 18:53:46 +01:00
Joerg Wunsch
e3338c428f Add PR #810 2022-01-08 18:27:48 +01:00
Jörg Wunsch
f1dbb2aae8 Merge pull request #810 from yegorich/ignore-ac-cfg-h-in
Ignore ac_cfg.h.in~
2022-01-08 18:27:12 +01:00
Yegor Yefremov
b13c61893b Ignore ac_cfg.h.in~
Ignore temporary ac_cfg.h.in~ file.
2022-01-08 18:06:39 +01:00
Marius Greuel
d2ae6a824f Add C code alternative to __builtin_popcount. 2022-01-08 16:13:32 +01:00
Marius Greuel
21d7fc58b6 Add -Wall to CMake compiler options 2022-01-08 16:13:26 +01:00
Dawid Buchwald
1631fc4dd8 Implemented extended parameter for RTS/DTR lines management 2022-01-08 10:04:25 +01:00
Marius Greuel
c71fab0889 Move README.md build instructions to wiki 2022-01-08 00:33:11 +01:00
Marius Greuel
47b5d1af73 Add build status to README.md 2022-01-08 00:30:48 +01:00
Marius Greuel
872f3a3a8d Add GitHub deploy action 2022-01-07 23:57:54 +01:00
Marius Greuel
428f5828b4 Add cross-compile to GitHub build actions 2022-01-07 23:57:54 +01:00
Marius Greuel
b87b527b3a Add advapi32.lib to MSVC builds 2022-01-07 23:57:54 +01:00
Marius Greuel
80d53839dd Replace MSVC implementation of __builtin_popcount with C code 2022-01-07 23:57:54 +01:00
Marius Greuel
e1221e22ff Fix -Wpointer-sign warning in micronucleus.c 2022-01-07 23:48:56 +01:00
Joerg Wunsch
7d574ccf0b PR #808 is done 2022-01-07 21:40:59 +01:00
Jörg Wunsch
366a368882 Merge pull request #808 from yegorich/fix-invalid-sscanf-arg-type
buspirate: fix invalidScanfArgType_int warning
2022-01-07 21:40:25 +01:00
Yegor Yefremov
f2d6342d21 buspirate: fix invalidScanfArgType_int warning
"%x" specifies an unsigned int, hence change the type of spi_write, spi_read
accordingly.
2022-01-07 19:22:57 +01:00
Joerg Wunsch
11f7692cc0 Mention PR #798 - all those Windows changes 2022-01-07 18:31:54 +01:00
Jörg Wunsch
6a737a0c13 Merge pull request #798 from mariusgreuel/pr-msvc
Add MSVC builds and better WinUSB/FTDI support
2022-01-07 18:30:19 +01:00
Marius Greuel
fc54ef5e59 Clean up legacy code 2022-01-07 17:57:02 +01:00
Marius Greuel
fe6f08d48f Use alloca for stack based memory allocation 2022-01-07 17:54:36 +01:00
Marius Greuel
d05c2db3fb Add a missing define to the MSVC compatiblity shim 2022-01-07 17:54:36 +01:00
Marius Greuel
1fb88c3040 Add external libraries to CMake project 2022-01-07 17:54:36 +01:00
Marius Greuel
c035c91db5 Add compatibility shim for MSVC 2022-01-07 17:54:36 +01:00
Joerg Wunsch
3a3250322d Mention PR #807 2022-01-07 13:17:25 +01:00
Jörg Wunsch
a91e389a5e Merge pull request #807 from yegorich/src-typos
Fix typos all over the code
2022-01-07 13:15:14 +01:00
Yegor Yefremov
f29b2a283a Fix typos all over the code 2022-01-07 11:31:16 +01:00
Joerg Wunsch
8c4c9d0090 Add PR #801 2022-01-07 09:23:49 +01:00
Jörg Wunsch
539eec79e6 Merge pull request #801 from dl8dtl/conffile-clean-up
Conffile clean up
2022-01-07 09:23:17 +01:00
Joerg Wunsch
32d78cc9a0 Mention new ATtinys supported 2022-01-07 09:10:30 +01:00
Joerg Wunsch
5cbd6a5160 Mention PR #802 2022-01-07 09:08:58 +01:00
Jörg Wunsch
ac7a794b70 Merge pull request #802 from mariusgreuel/pr-teensy
Add support for Teensy bootloader
2022-01-07 09:07:40 +01:00
Marius Greuel
f20c4bd9e6 Add support for Teensy bootloader 2022-01-06 23:39:17 +01:00
Joerg Wunsch
67df9b0782 Mention closed PR #803 (and its related issues) 2022-01-06 22:58:46 +01:00
Jörg Wunsch
118993a584 Merge pull request #803 from MCUdude/add-missing-targets
Add missing ATtiny targets to avrdude.conf
2022-01-06 22:51:57 +01:00
Joerg Wunsch
6cfdb3a04b Remove obsolete file 2022-01-06 22:39:36 +01:00
Joerg Wunsch
fffbd09767 Mention PR #806 as fixed 2022-01-06 15:55:51 +01:00
Jörg Wunsch
75fd2d5ea4 Merge pull request #806 from yegorich/fix-realloc
term: fix memleakOnRealloc
2022-01-06 15:55:19 +01:00
Yegor Yefremov
d5b2106644 term: fix memleakOnRealloc
Assign the newly allocated value to a temporary variable and in the
case where we cannot allocate memory, free the initial pointer.
2022-01-06 11:28:39 +01:00
Jörg Wunsch
a61707bb65 Merge branch 'avrdudes:main' into main 2022-01-06 10:06:04 +01:00
Joerg Wunsch
7bf9711392 Mention PR #804 2022-01-05 22:46:36 +01:00
Jörg Wunsch
3069105134 Merge pull request #804 from yegorich/add-tags-to-gitignore
Ignore ctags index file
2022-01-05 22:43:29 +01:00
Yegor Yefremov
a6ad88d9c4 Ignore ctags index file
ctags creates an index file called 'tags'.
2022-01-05 22:30:13 +01:00
Joerg Wunsch
8c1c803fb2 Mention PR #792 as closed 2022-01-05 17:54:49 +01:00
Jörg Wunsch
97c34f7b26 Merge pull request #792 from yegorich/ftdi-fix-deprecated-call
avrftdi: don't use the deprecated ftdi_usb_purge_buffers routine
2022-01-05 17:41:08 +01:00
Joerg Wunsch
1529277477 When finding LIBFTDI, don't clobber LIBS but extend it 2022-01-05 17:26:39 +01:00
MCUdude
50e15a5cf8 Add missing ATtiny targets
ATtiny48, 87, 102, 104, 167 and 828
2022-01-05 11:50:31 +01:00
Jörg Wunsch
48a8388b09 Merge pull request #789 from MCUdude/main
Add jtag2updi support
2022-01-05 08:26:55 +01:00
Hans
4b76ccc951 Merge branch 'main' into main 2022-01-05 08:05:38 +01:00
Jörg Wunsch
e27990bd54 Merge pull request #786 from mariusgreuel/pr-micronucleus
Add support for Micronucleus bootloader
2022-01-04 23:52:00 +01:00
Jörg Wunsch
b8c825c9af Merge pull request #795 from MCUdude/add-pkobn_updi-vtarg
Add target voltage adjustment for Curiosity Nano boards
2022-01-04 23:50:20 +01:00
Joerg Wunsch
124ef7fe3d Move the backslash replacement out into a separate function 2022-01-04 23:10:14 +01:00
Joerg Wunsch
6a87a110cc Move the config file names out as #define into avrdude.h 2022-01-04 23:03:47 +01:00
Joerg Wunsch
374861f62e Move the system config file search after option processing
For one, this allows us to use MSG_DEBUG in order to emit debug
messages (requires -v processing).

As another effect, if the -C conffile option was given, there is no
need at all to run through all the process of looking up a system
config file - it's right there already.

Also, move it after the logfile creation if -l logfile was given, so
the respective debug message can go to the logfile.
2022-01-04 22:45:47 +01:00
Marius Greuel
3747db516a Add support for Micronucleus bootloader 2022-01-04 18:37:57 +01:00
Joerg Wunsch
dba89e7269 Mention PR #796 as fixed 2022-01-04 14:07:15 +01:00
Joerg Wunsch
863f77d827 Fix a (valid) warning about comparison of char vs. int against EOF
Closes PR #796
2022-01-04 13:48:11 +01:00
Joerg Wunsch
9c7bb3787d Revert "Hint about possibly differing licensing terms."
This reverts commit fa079bec8c.

Changing the COPYING file prevents automatic license detections
from working correctly.
2022-01-04 12:53:27 +01:00
Joerg Wunsch
eff180353e Merge branch 'main' of github.com:dl8dtl/avrdude 2022-01-03 23:55:27 +01:00
Joerg Wunsch
f9ea588525 Update the man page to reflect the search order for avrdude.conf 2022-01-03 23:53:51 +01:00
Joerg Wunsch
fa079bec8c Hint about possibly differing licensing terms.
With the advent of whereami.[ch], not all files have a uniform
license anymore.
2022-01-03 23:35:59 +01:00
Joerg Wunsch
3a77394d67 Mention recent PRs and fixed issues 2022-01-03 23:35:10 +01:00
Kristof Mulier
5c896992cd Find 'avrdude.conf' based on absolute path to executable (#780)
* Find 'avrdude.conf' based on absolute path to executable

* Update coding style

* Update coding style

* Update 'src/doc/avrdude.texi' to reflect the new search method for 'avrdude.conf'
2022-01-03 23:20:31 +01:00
Jörg Wunsch
6aa65683ad Merge pull request #794 from mariusgreuel/pr-auto-version
Derive program version string from last commit

(Works on CMake only.)
2022-01-03 23:06:37 +01:00
MCUdude
ecca860972 Add target voltage adjustment for Curiosity Nano boards
in Avrdude terminal mode
2022-01-03 18:51:33 +01:00
Yegor Yefremov
dc1fed40bf avrftdi: don't use the deprecated ftdi_usb_purge_buffers routine
Since commit ed46f09c1ccd1351e003a200ba50e3e4778ac478 (Implement
tc[io]flush methods & deprecate broken purge_buffers methods.)
ftdi_usb_purge_buffers() routine is deprecated. Use HAVE_FTDI_TCIOFLUSH
macro to invoke the newly introduced ftdi_tcioflush() routine.
2022-01-03 17:59:05 +01:00
Marius Greuel
4d5af6370d Change version URL from Savannah to GitHub 2022-01-03 15:13:00 +01:00
Marius Greuel
12a67554d9 Derive program version from last commit 2022-01-03 15:04:25 +01:00
Jörg Wunsch
aa2f132b24 Merge pull request #793 from mariusgreuel/pr-yacc
Use yacc/byacc as an alternative to bison, closes #785
2022-01-03 14:05:11 +01:00
Marius Greuel
e843db55ae Use yacc/byacc as an alternative to bison 2022-01-03 13:10:54 +01:00
MCUdude
f96b98e9df Mute "flash and boot" warning if s UPDI programmer is used
Currently, no UPDI compatible AVR has a dedicated boot section like the Xmegas do
2022-01-02 19:20:05 +01:00
MCUdude
dcd5374ae9 Print meaningful error if programmer doesn't support target 2022-01-02 12:57:42 +01:00
MCUdude
b9f03b1377 Fix typo in URL 2022-01-02 12:13:15 +01:00
MCUdude
f5bec43812 Add jtag2updi programmer to docs 2022-01-02 12:13:15 +01:00
MCUdude
a2a276a8cc Add support for UPDI devices though jtag2updi
'Hack' borrowed from https://github.com/facchinm/avrdude
2022-01-02 12:13:15 +01:00
MCUdude
71d5dbec48 Add more jtagmkii baud rates 2022-01-02 12:13:13 +01:00
Joerg Wunsch
c69627a87c Update NEWS
Structure has also been changed to use the Github terminology
(issues and pull requests, rather than bugs and patches).
2022-01-01 21:11:31 +01:00
Joerg Wunsch
a6a06f47f6 Prevent spi' and pgm' commands from crashing terminal mode
These commands are been meaningful only on direct bitbang programming
adapters which implement a pgm->setpin method.

Disable these commands for all other programmers, and issue an
informational message.

This is a partial fix for bug #790.
2022-01-01 20:58:26 +01:00
Jörg Wunsch
69231d7ad0 Merge pull request #791 from MCUdude/add-programmers
Add PicKit4 and SNAP programmers
2022-01-01 20:31:59 +01:00
MCUdude
2623e7a9fa Update docs to reflect new programmers 2022-01-01 12:06:52 +01:00
MCUdude
302b6eb05a Add PicKit4 and SNAP ISP and PDI programmer options 2022-01-01 12:04:16 +01:00
Joerg Wunsch
89c4ab0375 Remove the License subclause 2021-12-31 00:07:52 +01:00
Marius Greuel
5246cf1750 Make Windows version resource accept fewer than four version numbers 2021-12-29 22:28:19 +01:00
Marius Greuel
65e3fe358a Always upload GitHub Build artifacts, even on failure 2021-12-29 22:27:36 +01:00
MCUdude
0a335e2f73 Add jtag2updi programmer 2021-12-29 14:27:51 +01:00
Joerg Wunsch
e3520aba9d Merge remote-tracking branch 'upstream/main' 2021-12-28 23:42:08 +01:00
Jörg Wunsch
4c3530e199 Merge pull request #787 from dl8dtl/serialupdi-manpage
Serialupdi manpage
2021-12-28 23:41:22 +01:00
Joerg Wunsch
a369f9d28f SerialUPDI man page addition 2021-12-28 23:34:34 +01:00
Joerg Wunsch
fd276c1e88 Add SerialUPDI documentation to man page 2021-12-28 23:32:48 +01:00
Joerg Wunsch
805ca48ffa Merge remote-tracking branch 'upstream/main' 2021-12-28 23:24:13 +01:00
Jörg Wunsch
b14459dc04 Merge pull request #782 from dbuchwald/main
Documentation for SerialUPDI programmer
2021-12-28 23:23:37 +01:00
Joerg Wunsch
a625db23e0 Merge remote-tracking branch 'upstream/main' 2021-12-28 15:00:53 +01:00
Jörg Wunsch
f531af70db Merge pull request #783 from mariusgreuel/pr-improve-cmake
Improve CMake project
2021-12-28 14:47:58 +01:00
Jörg Wunsch
5520bd6711 Merge pull request #784 from mariusgreuel/pr-bugfix-avr_read
Fix avr_read() for page reads

Closes issue #481
2021-12-26 18:34:39 +01:00
Marius Greuel
55251ea6f5 Fix avr_read() for page reads with page sizes that are not a multiple of the memory size 2021-12-26 16:57:23 +01:00
Marius Greuel
3840468e36 Improve CMake project to filter conditional sections 2021-12-26 16:46:15 +01:00
Marius Greuel
f391b7138b Improve CMake project for FreeBSD builds 2021-12-26 16:40:28 +01:00
Dawid Buchwald
c48c5135d8 Added SerialUPDI related documentation 2021-12-26 14:34:01 +01:00
Dawid Buchwald
993b8d7792 Another addition to .gitignore file 2021-12-26 14:22:39 +01:00
Dawid Buchwald
b78170397a Added missing entry to .gitignore 2021-12-26 13:06:21 +01:00
Jörg Wunsch
c60c5c4b83 Merge pull request #779 from yegorich/memleaks
Fix memory leaks

In jtag3_send() and jtagmkI_send(), free the buffer when returning an error.
2021-12-26 00:44:33 +01:00
Yegor Yefremov
d14bb02dca Fix memory leaks
Free buf in the case of an error. Found via cppcheck.
2021-12-24 10:14:16 +01:00
Jörg Wunsch
3d39f3f232 Merge pull request #777 from yegorich/typos
Fix typos in src/avrftdi.c.

No actual code change imposed.
2021-12-23 17:52:36 +01:00
Yegor Yefremov
f2dc95ea01 Fix typos 2021-12-23 17:17:08 +01:00
Joerg Wunsch
025ebd4ae8 Ah OK, CMAKE doesn't like dashes in the version number.
Turn 6.99-20211218 into 6.99.20211218
2021-12-22 23:33:20 +01:00
Joerg Wunsch
47947fb35c Make version numbers of configure.ac and CMakeLists.txt match
We are moving towards AVRDUDE 7.0, so express this by using
6.99 by now.
2021-12-22 23:27:05 +01:00
Marius Greuel
86cef2559f Add serialupdi to CMakeLists.txt 2021-12-22 22:40:21 +01:00
Jörg Wunsch
1f44ec5e0c Merge pull request #768 from mariusgreuel/pr-migration2
GitHub Migration part 2: start a CMake infrastructure
2021-12-22 22:20:21 +01:00
Jörg Wunsch
2c0ccfed3a Merge pull request #772 from dbuchwald/main
SerialUPDI implementation - release candidate 1
2021-12-22 20:01:35 +01:00
Dawid Buchwald
c093b21a67 Moved SerialUPDI sources to correct location 2021-12-21 21:45:36 +01:00
Dawid Buchwald
291549d021 Merged AVRDUDES/main into SerialUPDI branch 2021-12-21 21:38:51 +01:00
Dawid Buchwald
0bb1b758a4 Removed files from old location 2021-12-21 21:30:31 +01:00
Jörg Wunsch
cef773d17f Merge pull request #769 from mariusgreuel/pr-windows-cleanup
Remove 'windows' folder with giveio.sys driver
2021-12-21 18:11:10 +01:00
Marius Greuel
764c0f6e19 Add credits for giveio.sys driver contributions 2021-12-21 17:57:39 +01:00
Marius Greuel
60cb548075 Remove 'windows' folder with giveio.sys driver 2021-12-21 17:45:35 +01:00
Marius Greuel
89c345c6a6 Add GitHub build action for CMake project 2021-12-20 17:52:37 +01:00
Marius Greuel
e4ebfe420c Add Windows version resource 2021-12-20 17:51:44 +01:00
Marius Greuel
fbdb6a98c0 Add CMake project 2021-12-20 17:50:42 +01:00
Joerg Wunsch
868895e2e0 Make `bootstrap' executable
That bit appears to get lost during transition from SVN.
2021-12-19 00:35:52 +01:00
Jörg Wunsch
6454bd79a8 Merge pull request #767 from dl8dtl/toplevel-updates
Update toplevel files.
2021-12-18 22:35:02 +01:00
Joerg Wunsch
3a8af359f3 Update toplevel files.
Integrate old INSTALL into README.md, both files had a lot
of (potential) overlap.

Add template for new entries in NEWS, targetting next release.

Bump version number to 6.99-20211218

Tentatively, with the Github migration and all ongoing code
restructuring, we aim for a version 7.0 release at some point
in the future.
2021-12-18 22:32:50 +01:00
Jörg Wunsch
6404e78154 Merge pull request #765 from mariusgreuel/pr-migration1
GitHub Migration
* Move source files to src/ subdir
* Remove ChangeLog* - meta information is kept in VCS anyway
* replace old README by readme.md
2021-12-18 21:38:03 +01:00
Dawid Buchwald
d1dddad896 Added support for writing USERROW memory 2021-12-18 16:47:37 +01:00
Dawid Buchwald
c3100763cb Implemented lockbits programming and forced chip erase procedure
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/branches/serialupdi@1522 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-12-18 15:25:30 +01:00
Dawid Buchwald
dc846ba7e8 Fix candidate for EEPROM writing issue
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/branches/serialupdi@1520 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-12-18 15:25:30 +01:00
Dawid Buchwald
189f829c3f Fix candidate for write fuse operation
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/branches/serialupdi@1519 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-12-18 15:25:30 +01:00
Dawid Buchwald
9ff14b7a42 Fix candidate for issue with atmega4809
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/branches/serialupdi@1518 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-12-18 15:25:30 +01:00
Dawid Buchwald
e941d4d3f1 Implemented faster flash programming method
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/branches/serialupdi@1517 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-12-18 15:25:30 +01:00
Dawid Buchwald
c6902553be First successful programming
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/branches/serialupdi@1516 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-12-18 15:25:30 +01:00
Dawid Buchwald
8f67f9c50b Implemented byte and page read operations
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/branches/serialupdi@1514 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-12-18 15:25:29 +01:00
Dawid Buchwald
748bee8ecf Basic read operations implemented
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/branches/serialupdi@1513 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-12-18 15:25:29 +01:00
Dawid Buchwald
b6e72dce4c Implemented basic serial code refactoring for upcoming SerialUPDI implementation
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/branches/serial_refactoring@1511 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-12-18 15:25:27 +01:00
Marius Greuel
062fa8c77b Add link of original AVRDUDE repository to README.md 2021-12-17 22:52:27 +01:00
Marius Greuel
e6427d3420 Add AUTHORS file back in 2021-12-17 22:47:12 +01:00
Marius Greuel
5633a6d88a Move source files to 'src' folder 2021-12-17 09:17:42 +01:00
Marius Greuel
d5959d27b8 Remove README, AUTHORS, ChangeLog*, BUILD-FROM-SVN 2021-12-16 23:25:06 +01:00
Marius Greuel
5596d06d93 Add README.md 2021-12-16 23:24:32 +01:00
Marius Greuel
9d916b31a0 Add .editorconfig 2021-12-16 23:24:32 +01:00
Marius Greuel
e85d112891 Add .gitattributes and .gitignore, remove .cvsignore 2021-12-16 23:24:32 +01:00
Joerg Wunsch
7015ebe0d6 Update for release of version 6.4
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1523 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-12-16 21:02:35 +00:00
Joerg Wunsch
02a2cab296 Add a project-related INSTALL file
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1521 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-12-14 22:03:51 +00:00
Joerg Wunsch
6264404cc1 Allow for overriding make tool from environment
gmake (GNU make) appears to handle some dependencies better here than
bmake (BSD make).



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1515 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-12-10 22:34:57 +00:00
Joerg Wunsch
2df2587155 bug #57338: if safemode has to change fuses avrdude should exit with non-zero exit code
In main.c, drop unused variable `fuses_specified'.
Variable ran out of service in r519, but never got removed.



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1509 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-12-06 21:46:41 +00:00
Joerg Wunsch
202b6cab39 bug #58994: VPP PWM still enabled at the end of programming process
Submitted by Dmitrii Chernukhin:
* pickit2.c (pickit2_disable): turn off VPP before shutting down




git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1508 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-12-06 21:13:00 +00:00
Joerg Wunsch
6f69ddb068 Disable parport support by default; bump version date
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1507 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-12-05 21:57:12 +00:00
Joerg Wunsch
1214f99c2b patch #10153: linuxspi: Support "-E reset" and "-E noreset"
Submitted by Alex Sverdlin:
* linuxspi.c (linuxspi_parseexitspecs): New function




git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1506 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-12-03 22:30:05 +00:00
Joerg Wunsch
eb7ccaf92b Turn off FT245R_BITBANG_VARIABLE_PULSE_WIDTH_WORKAROUND by default
Seems it's not really needed for modern FT245, and it has the
potential to break bulk readout.



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1505 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-12-01 22:17:50 +00:00
Joerg Wunsch
b376b6acdc In ft245r.c, move forward function declaratons up-front.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1504 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-30 06:32:27 +00:00
Joerg Wunsch
f09f308ff8 Bug #55462 was fixed in the course of patch #9757
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1503 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-27 23:15:06 +00:00
Joerg Wunsch
53de300b6e bug #58440: linuxgpio PIN limit too low
* libavrdude.h (PIN_MAX): bump (for HAVE_LINUXGPIO) to 400



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1502 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-27 21:54:56 +00:00
Joerg Wunsch
03132d7338 patch #8923: Enable TPI for linuxgpio
Submitted by David Mosberger-Tang:
* linuxgpio.c (linuxgpio_initpgm): add cmd_tpi entry




git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1501 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-27 21:41:44 +00:00
Joerg Wunsch
15bd30d442 patch #8996: Remove lock byte read mask (bug#21954, bug#46759)
Submitted by: Milan Kupcevic <milan@debian.org>
* avrdude.conf.in (ATmega48, ATmega88, ATmega168, ATmega328)
(ATmega32U4, ATmega640, ATmega1280, ATmega1281, ATmega2560)
(ATmega2561, ATmega8, ATtiny13, ATmega64, ATmega128, ATmega16)
(AT90CAN32, AT90CAN64, AT90CAN128, ATmega324, ATmega644)
(ATmega1284, ATmega161, ATmega162, ATmega163, ATmega169, ATmega32)
(ATmega329, ATmega649, ATmega8515, ATmega8535, ATtiny2313, ATtiny4313)
(AT90PWM2, AT90USB646, AT90USB1286, AT90USB162, AT90USB82, ATmega32U2)
(ATmega16U2, ATmega8U2, ATmega325, ATmega645, ATtiny1634): Remove
lock byte read mask (bug#46759).




git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1500 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-27 21:28:45 +00:00
Joerg Wunsch
4396674aa7 patch #9304: [Bug #48767] Implemented WinSock variation of "ser_drain(...)" functionality
Submitted by Christopher Cooper:
* ser_win32.c (ser_drain): Implement a network drain
function.




git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1499 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-27 21:15:55 +00:00
Joerg Wunsch
c9a1405547 * linux_spi.c (linuxspi_open): ensure correct SPI mode is
Submitted by Lars Ollén:
set (submitted in the audit trail of patch #9816).




git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1498 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-27 20:18:44 +00:00
Joerg Wunsch
2aee540bfa Use -B <bitclock> rather than -b <baudrate> to specify the clock rate
in linuxspi driver.

This offers the additional advantage of being able to parse kHz and
MHz values (in main.c).


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1497 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-27 18:21:44 +00:00
Joerg Wunsch
dd1255b0c8 Improve defaults and documentation of linuxspi
* avrdude.conf.in: use @HAVE_LINUXGPIO_BEGIN/END@ and
@HAVE_LINUXSPI_BEGIN/END@ brackets around respective config
snippets; values were already set in configure.ac.
* linuxspi.c (linuxspi_open): Provide a reasonable (for the
Raspberry Pi) default for the -P option
* avrdude.1: Extend linuxspi documentation
* doc/avrdude.texi: (Dito.)



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1496 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-27 17:33:49 +00:00
Joerg Wunsch
18fe8ef834 patch #10031: linuxspi: Support GPIO uAPI v2
Submitted by Alex Sverdlin:
* linuxspi.c (linuxspi_reset_mcu, linuxspi_open): Since Linux
v5.10 GPIO ABI Version 1 is optional and depends on
CONFIG_GPIO_CDEV_V1.




git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1495 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-27 15:51:24 +00:00
Joerg Wunsch
bd4f46b1ff patch #10030: linuxspi: Support inverted GPIO pin
Submitted by Alex Sverdlin:
* linuxspi.c (linuxspi_open): Clear the inversion mask on request
and set default state to avoid short glitches on the GPIO line.




git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1494 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-27 15:48:30 +00:00
Joerg Wunsch
6f183d427c patch #10029: linuxspi: Report GPIO_GET_LINEHANDLE_IOCTL errors
Submitted by Alex Sverdlin:
* linuxspi.c (linuxspi_open): Report ioctl error




git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1493 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-27 15:46:10 +00:00
Joerg Wunsch
d208503911 Actually apply patch #10028 :)
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1492 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-27 15:43:57 +00:00
Joerg Wunsch
93767e0de1 patch #10028: linuxspi: close() only when necessary
Submitted by Alex Sverdlin:
* linuxspi.c: unify descriptor closing




git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1491 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-27 15:42:33 +00:00
Joerg Wunsch
711323e7cc Submitted by Alex Sverdlin:
patch #10027: linuxspi: Add reset pulse, according to AVR programming algorithm
* linuxspi.c (linuxspi_open, linuxspi_program_enable):
movw out reset code into linuxspi_reset_mcu()



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1490 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-27 15:40:12 +00:00
Joerg Wunsch
6887f4f373 Add David Mosberger's email address (with permission)
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1489 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-25 18:51:54 +00:00
Joerg Wunsch
49e5f2451c patch #9328: ft245r.c: add TPI support (patches 5-7)
Submitted by David Mosberger-Tang:
* ft245r.c (ft245r_set_bitclock): add workaround for
FT245 hardware bugs in bitclock setting

Correct baud rate calculation (multiplying with factor of 2 was wrong)
and add compile-time workaround for FTDI chips suffering for the
variable pulse-width errata.  The workaround entails always running
the chip at 3MHz and stuffing the channel with repeated bytes to
achieve the desired baudrate.

This has no effect on programming speed.  Note, however, that now a
baudrate option -b750000 has to be used to achieve maximum speed.

(Option enabled by default now.)



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1488 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-25 09:17:11 +00:00
Joerg Wunsch
2015a874e0 patch #9328: ft245r.c: add TPI support (patches 5-7)
Submitted by David Mosberger-Tang:
* ft245r.c: Remove the reader thread (also removes
patch #9079)

Eliminate separate reader thread by tracking how many bytes are queued
in the FTDI chip's RX FIFO and reading those bytes when it fills up
(since in synchronous bitbang mode, the chip won't send any more bytes
until it has space in the RX FIFO).  This reduces TPI programming time
by another 33%.

Since write data is now queued as much as possible, we need flush this
queued data (a) before reading and (b) before sleeping.  For the
latter case, a new helper function ft245r_usleep() is introduced.




git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1487 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-25 09:10:30 +00:00
Joerg Wunsch
5bf24e4e96 patch #9327: ft245r.c: add TPI support (patches 1-4)
Submitted by David Mosberger-Tang:

ft245r.c (set_pin, ft245r_open): use
ft245r_send_and_discard() so ft245r_in can go away




git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1486 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-24 22:27:59 +00:00
Joerg Wunsch
105cebb389 patch #9327: ft245r.c: add TPI support (patches 1-4)
Submitted by David Mosberger-Tang:

Optimize TPI programming speed by reducing number of USB reads.
Specifically, when writing to the FTDI chip (without needing the data
it accumulates), simply increment a count of how many bytes the next
read should ignore.  Thus, if there is one or more write followed by a
read, we only need to read from the device once.

Improves TPI programming speed by another factor of 2.



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1485 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-24 22:06:31 +00:00
Joerg Wunsch
7ff5652edc patch #9327: ft245r.c: add TPI support (patches 1-4)
Submitted by David Mosberger-Tang

With newer versions of the Linux kernel (e.g., Ubuntu's
linux-image-4.4.0-75-generic), the default for the latency timer is
set to a high value.  Since this driver needs quick turnaround times,
set it explicitly to the minium.  This improves TPI programming speed
by almost a factor of 10.




git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1484 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-24 22:00:45 +00:00
Joerg Wunsch
6de6c0ffce patch #9327: ft245r.c: add TPI support (patches 1-4)
Submitted by David Mosberger-Tang:
* ft245r.c: add TPI support
* avrdude.conf.in (tc2030): New programmer




git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1483 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-24 21:25:45 +00:00
Joerg Wunsch
d947e5893f * ft245r.c (ft245r_open): allow for picking a default
device if none has been provided by -P



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1482 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-24 21:09:33 +00:00
Joerg Wunsch
391439493d * jtag3.c (jtag3_edbg_recv_frame): Better handling for
fragment_info == 0x00 (no response available)



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1481 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-24 21:04:47 +00:00
Joerg Wunsch
265aa3296b Fix logic bug in previous commit
Comparison against "usb" was done the wrong way.



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1480 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-23 09:54:18 +00:00
Joerg Wunsch
172fcb7c7e Now that we have a matches() function, prefer it over strncmp()
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1479 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-23 09:48:15 +00:00
Joerg Wunsch
bd50422644 patch #9757: Fix ATtiny817 Xplained Mini programmer
* jtag3.c (jtag3_getsync, jtag3_close): correctly extract
programmer name from list of names



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1478 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-23 09:42:39 +00:00
Joerg Wunsch
8004e38403 patch #8719: Support Over-the-Air bootloading with XBeeBoot
Submitted by David Sainty:
* xbee.c: New programmer
* xbee.h: (Dito.)
* pgm_type.c: Add xbee.h
* avrdude.conf.in (xbee): New programmer
* Makefile.am (libavrdude_a_SOURCES): add xbee.c, xbee.h
* avrdude.1: document the new programmer
* doc/avrdude.texi: (Dito.)




git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1477 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-22 21:35:26 +00:00
Joerg Wunsch
9a15fcb25f Update ChangeLog for ft245r.c patches
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1476 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-14 15:48:53 +00:00
Joerg Wunsch
f821bfc03d patch #9123: ftdi_syncbb: use FT245R_CYCLES in ft245r_set_bitclock()
Submitted by Ivan Frederiks:

Replace magic numbers by #defined constant



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1475 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-14 15:47:29 +00:00
Joerg Wunsch
e8c5ed0fcd patch #9122: Fixed MISO sampling in ftdi_syncbb
Submitted by Ivan Frederiks

Fix MISO sampling on falling edge of SCK.



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1474 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-14 15:44:54 +00:00
Joerg Wunsch
ebea9b5237 Submitted by Ivan Frederiks:
patch #9079: Fix ftdi_syncbb teardown

Fix teardown sequence between reader thread and libusb.



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1473 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-14 13:34:20 +00:00
Joerg Wunsch
5e6a662e8a Submitted by David Mosberger-Tang:
patch #9320: fix TPI RESET in bitbang.c
* bitbang.c (bitbang_initialize): wait for 128 ms after deasserting
/RESET (per datasheet), and keep /RESET low during MOSI/MISO link check



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1472 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-14 13:17:44 +00:00
Joerg Wunsch
3d1b0ff308 Submitted by Jon Thacker:
patch #9253: Fix for giving terminal_mode commands more than 20 arguments
* term.c (tokenize): fix realloc usage, pointer returned not necessarily
the same as pointer passed



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1471 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-12 22:11:49 +00:00
Joerg Wunsch
db7249bf57 Submitted by Martino Facchin:
patch #9110: Let reserved fuse bits to be read as *don't care*
* avr.c (compare_memory_masked): New function
* libavrdude.h: declare compare_memory_masked(); also, insist on C99
so <stdint.h> is required now
* main.c: Use compare_memory_masked() in safemode comparisons

C99 / stdint.h has basically already been required before, as types
like uint8_t are in use in a number of other locations throughout the
source.



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1470 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-12 22:02:29 +00:00
Joerg Wunsch
10df0ff15a Submitted by Joseph Coffland:
patch #8957: Allow reading prodsig memory from stk500v2 on xmega devices
* stk500v2.c (stk600_xprog_read_byte, stk600_xprog_paged_load):
treat "prodsig" memory space as equivalent to "calibration"



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1469 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-11 20:59:25 +00:00
Joerg Wunsch
91948428a6 Submitted by Martin Thierer:
patch #10017: uspasp / tpi: Automatically clear configuration byte (fuse) before writing it
* usbasp.c (usbasp_tpi_paged_write): clear fuse region before writing it



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1468 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-07 20:10:24 +00:00
Joerg Wunsch
62a00cedc7 Submitted by Michael Petersen:
patch #9697: Add iseavrprog support
* avrdude.conf.in (iseavrprog): New programmer



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1467 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-07 19:37:50 +00:00
Joerg Wunsch
8841a9cd93 bug #50630: Erase Cycle Counter options ( -y -Y n ) should be removed from usage Message
* main.c (usage): remove -y / -Y descriptions



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1466 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-07 16:51:42 +00:00
Joerg Wunsch
46628eb3c6 Add ATmega8A as an alias for ATmega8
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1465 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-07 16:49:12 +00:00
Joerg Wunsch
84af4b36a1 bug #50517: Reading fails if "immediate mode" for output file format
is selected - fileio: invalid operation=1

* update.c (do_op): refuse to write to "immediate format" argument




git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1464 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-07 16:22:00 +00:00
Joerg Wunsch
1b3afa4cef Move ATmega164P definition after its parent ATmega324P
Error was introduced in r1458.



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1463 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-07 16:06:42 +00:00
Joerg Wunsch
eb461f706f Submitted by Martin Thierer:
bug #60863: avrftdi programming error probably caused by multiple, consecutive empty pages
* avrftdi.c (avrftdi_flash_write): Skip empty pages



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1462 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-07 16:00:16 +00:00
Joerg Wunsch
9cf4edf76f Submitted by Matwey V. Kornilov:
bug #58495: Add atmega324pb support to avrdude.conf.in
* avrdude.conf.in (ATmega324PB): new entry



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1461 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-07 15:50:53 +00:00
Joerg Wunsch
ea27bfef1e bug #51409: Can't program EFUSE on ATmega32M1
Was already fixed, adjust bug id in NEWS



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1460 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-07 15:48:01 +00:00
Joerg Wunsch
7c554b0035 bug #55734: USBtiny programming of ATmega328p broken by Patch #9278
* usbtiny.c (usbtiny_initialize): undo change from patch #9728



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1459 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-07 15:44:18 +00:00
Joerg Wunsch
8907155291 Fix entry for ATmega164P, by deriving it from ATmega324P
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1458 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-07 15:28:24 +00:00
Joerg Wunsch
aedc3b0c2a Submitted by evan Venn:
bug #59227: Add new part. How does one get a part added to the CONF file?
* avrdude.conf.in (LGT8FX88P, LGT8FX168P, LGT8FX328P): new parts



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1457 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-07 09:18:32 +00:00
Joerg Wunsch
b05e8af0a7 Submitted by Britton Kerin:
bug #57453: [PATCH] fix reference to nonexistant -m option by changing to -U
* avrdude.1: replace -m option by -U



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1456 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-06 22:44:21 +00:00
Joerg Wunsch
60f5885849 Submitted by Andrew D'Addesio:
bug #58078: [PATCH] buspirate: remove compound literals (fixes GCC>=9)
* buspirate.c (buspirate_start_mode_bin):
avoid propagating local scope compound literals



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1455 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-06 22:34:29 +00:00
Joerg Wunsch
e074edf4cb Submitted by Jan Egil Ruud:
patch #10000: Add support for extended UPDI device context
* avrdude.conf.in (pickit4_updi, snap_updi, pkobn_updi):
new programmers
* avrdude.conf.in (ATmega808, ATmega809, ATmega1608, ATmega1609)
(AVR DA, AVR DB): new devices
* jtag3.c: Add support for extended UPDI device context
* jtag3_private.h: (Dito.)
* tools/atdf-to-avrdude.xslt: Bug fixes
* usbdevs.h: Bump USBDEV_MAX_XFER_3 to 912
* doc/avrdude.texi: Document changes
* avrdude.1: (Dito)



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1454 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-11-06 22:13:51 +00:00
Joerg Wunsch
c9aeaf8928 Submitted by gerardoallende:
bug #59525: Bogus error message because Copy/Paste typo in stk500.c
* stk500.c (stk500_getparm): Fix bogus ID in error message




git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1453 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-06-27 20:42:06 +00:00
Joerg Wunsch
38e5aa33ea bug #60753: Patch #1436 breaks multiple programmer/device combinations on MacOS BigSur
* avr.c: compare page_size > 1 instead of != 0
* stk500v2.c: (Ditto.)




git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1452 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-06-27 20:26:05 +00:00
Joerg Wunsch
69a771317f ChangeLog rotation
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1451 81a1dc3b-b13d-400b-aceb-764788c761c2
2021-06-27 20:24:30 +00:00
Joerg Wunsch
1b650f594d * avrdude.conf.in (m32m1): add "size" parameter in "efuse"
section

Reported by Hannes Wallnöfer:



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1450 81a1dc3b-b13d-400b-aceb-764788c761c2
2020-09-22 07:36:45 +00:00
Joerg Wunsch
c934f95f5e patch #9744: Patch for ATMega324A support
* avrdude.conf.in (m324a): New entry.

Submitted by Björn Mellström



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1449 81a1dc3b-b13d-400b-aceb-764788c761c2
2020-09-20 20:51:51 +00:00
Joerg Wunsch
e98f9854b7 patch #9811: ATmega328pb has efuse bit 3
* avrdude.conf.in (m328pb): Add own efuse definition

Submitted by Ronald Sutherland



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1448 81a1dc3b-b13d-400b-aceb-764788c761c2
2020-09-20 18:29:03 +00:00
Joerg Wunsch
40b0b104d6 patch #9816: Implement new programmer type: linuxspi
* linuxspi.c: (New file.)
* linuxspi.h: (New file.)
* Makefile.am: Add new files
* configure.ac: Add "linuxspi" --enable option
* avrdude.conf.in: Add "linuxspi" programmer template
* pgm_type.c: Include linuxspi programmer
* doc/avrdude.texi: Document new programmer
* avrdude.1: (Dito.)

Submitted by Ralf Ramsauer



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1447 81a1dc3b-b13d-400b-aceb-764788c761c2
2020-09-19 21:32:38 +00:00
Joerg Wunsch
9b3762a812 patch #9963: UsbAsp 3 MHz patch for UsbAsp-flash firmware
* usbasp.c: Implement 3 MHz clock option including capability check
* usbasp.h: (Dito.)

Submitted by Marcin Miskiewic



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1446 81a1dc3b-b13d-400b-aceb-764788c761c2
2020-09-18 21:52:12 +00:00
Joerg Wunsch
1d2e4ef388 patch #9966: Add JTAGICE3 in UPDI mode
* avrdude.conf (jtag3updi): New entry.

Submitted by Sven Schwermer:



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1445 81a1dc3b-b13d-400b-aceb-764788c761c2
2020-09-18 21:24:03 +00:00
Joerg Wunsch
2c4f9d23b4 patch #9732: usbtiny_paged_load overflows buffer e.g. when reading EEPROM
* usbtiny.c (usbtiny_paged_load, usbtiny_paged_write): ensure chunk
does not overflow memory area

Submitted by Joel Ray Holveck




git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1444 81a1dc3b-b13d-400b-aceb-764788c761c2
2020-09-18 21:16:13 +00:00
Joerg Wunsch
3f5e101f09 Fix various typos.
Submitted by Adrian Klieber
patch #9818: correct typos in SVN rev 1429



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1443 81a1dc3b-b13d-400b-aceb-764788c761c2
2020-09-16 21:31:19 +00:00
Joerg Wunsch
e35e8f414a Document patch #9820 has been applied
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1442 81a1dc3b-b13d-400b-aceb-764788c761c2
2020-09-16 21:26:42 +00:00
Joerg Wunsch
4278300d8e Fix some possibly uninitialized variables in stk500v2_display()
Submitted by Adrian Klieber
patch #9820: Fix some out-of-bounds/uninitialized issues



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1441 81a1dc3b-b13d-400b-aceb-764788c761c2
2020-09-16 21:19:50 +00:00
Joerg Wunsch
34a1c8394c Fix handling of SCK parameter table in AVRISP2
Submitted by Adrian Klieber
patch #9820: Fix some out-of-bounds/uninitialized issues



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1440 81a1dc3b-b13d-400b-aceb-764788c761c2
2020-09-16 21:15:30 +00:00
Joerg Wunsch
acd2aa6417 Use correct pmg->type field in WIN32 implementation
Submitted by Adrian Klieber
patch #9820: Fix some out-of-bounds/uninitialized issues



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1439 81a1dc3b-b13d-400b-aceb-764788c761c2
2020-09-16 21:13:24 +00:00
Joerg Wunsch
b23c506cbd Enforce correct length of target string constraints in strncpy().
Clang did warn about these.



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1438 81a1dc3b-b13d-400b-aceb-764788c761c2
2020-09-10 21:43:23 +00:00
Joerg Wunsch
60529b4e50 ChangeLog entry for previous commit
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1437 81a1dc3b-b13d-400b-aceb-764788c761c2
2020-09-10 21:40:40 +00:00
Joerg Wunsch
da0e437eaa Ensure page_size is always at least 1
This avoids potential divisions by 0, and possibly also other mistakes
in case of malformed avrdude.conf entries.

The solution is different than the one in patch #9820 but is supposed
to cover that condition as well.

patch #9820: Fix some out-of-bounds/uninitialized issues



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1436 81a1dc3b-b13d-400b-aceb-764788c761c2
2020-09-10 21:37:34 +00:00
Joerg Wunsch
785b0cea55 patch #9819: Address several leaks in SVN rev 1429
Submitted by Adrian Klieber



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1435 81a1dc3b-b13d-400b-aceb-764788c761c2
2020-03-14 22:34:45 +00:00
Joerg Wunsch
c34fb88844 Submitted by: kautism
patch #9893: [PATCH] Reader reads ftdi handle after main thread close it
* ft245r.c: Wait until reader thread has been stopped before closing FTDI



git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1434 81a1dc3b-b13d-400b-aceb-764788c761c2
2020-03-11 12:39:57 +00:00
Joerg Wunsch
ae24d7a284 Add changelog entry for previous commit (fix compiler warnings)
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1433 81a1dc3b-b13d-400b-aceb-764788c761c2
2020-03-11 09:43:15 +00:00
Joerg Wunsch
e43c47a93f Annual ChangeLog rotation
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1432 81a1dc3b-b13d-400b-aceb-764788c761c2
2020-03-11 09:42:02 +00:00
Joerg Wunsch
061406c602 Fix compiler warnings
* misleading indentation after spin loop
* EM_AVR32 might be defined in system <libelf.h> already


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1431 81a1dc3b-b13d-400b-aceb-764788c761c2
2020-03-11 09:41:15 +00:00
Joerg Wunsch
4648eca956 bug #57428: [PATCH] document when 'arduino' or 'wiring' should be used, and -D requirement of latter
* avrdude.1: Clarify
* doc/avrdude.texi: (dito)

Submitted by Britton Kerin




git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1430 81a1dc3b-b13d-400b-aceb-764788c761c2
2019-12-17 22:31:51 +00:00
Joerg Wunsch
bb7be5efe6 Submitted by Martino Facchin:
patch #9728: Fix UsbTiny programmer
* usbtiny.c (usbtiny_initialize): Only consider
pgm->program_enable successful if returning 0




git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1429 81a1dc3b-b13d-400b-aceb-764788c761c2
2019-01-05 23:16:11 +00:00
Joerg Wunsch
536816087b Submitted by Milan Kupcevic:
patch #9735: spelling error fix: psuedo -> pseudo
* avrpart.c (avr_display): Spelling fix




git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1428 81a1dc3b-b13d-400b-aceb-764788c761c2
2019-01-05 23:01:56 +00:00
Joerg Wunsch
0a3faafd57 Annual ChangeLog rotation.
git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1427 81a1dc3b-b13d-400b-aceb-764788c761c2
2019-01-05 22:59:06 +00:00
297 changed files with 50024 additions and 60120 deletions

View File

@@ -1,9 +1,39 @@
# To learn more about .editorconfig see https://aka.ms/editorconfigdocs
# EditorConfig: https://editorconfig.org
[*]
indent_style = space
root = true
[{CMakeLists.txt,*.cmake}]
charset = utf-8
tab_width = 4
indent_size = 4
tab_width = 8
indent_style = space
trim_trailing_whitespace = true
[{bootstrap,configure.ac,avrdude.spec.in,Makefile.am}]
charset = utf-8
tab_width = 4
indent_size = 4
indent_style = tab
[avrdude.conf.in]
indent_size = 4
indent_style = space
[*.{c,h,cpp,y}]
tab_width = 4
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
charset = utf-8
tab_width = 2
indent_size = 2
indent_style = space
[*.yml]
charset = utf-8
tab_width = 2
indent_size = 2
indent_style = space

293
.github/workflows/build.yml vendored Normal file
View File

@@ -0,0 +1,293 @@
#
# build.yml - GitHub build action for AVRDUDE
# Copyright (C) 2021 Marius Greuel
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
name: Build
on:
push:
branches-ignore:
- 'onlinedocs'
pull_request:
branches-ignore:
- 'onlinedocs'
workflow_call:
env:
BUILD_TYPE: RelWithDebInfo
jobs:
linux-x86_64:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install prerequisites
run: >-
sudo apt-get update
sudo apt-get install -y
build-essential
cmake
flex
bison
libelf-dev
libusb-dev
libusb-1.0-0-dev
libhidapi-dev
libftdi1-dev
libreadline-dev
texinfo
texlive
texi2html
- name: Configure
run: >-
cmake
-D BUILD_DOC=1
-D DEBUG_CMAKE=1
-D HAVE_LINUXGPIO=1
-D HAVE_LINUXSPI=1
-D CMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
-B build
- name: Build
run: cmake --build build
- name: Archive build artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: build-linux-x86_64
path: |
build/
!**/*.d
!**/*.o
- name: Archive executables
uses: actions/upload-artifact@v3
with:
name: avrdude-linux-x86_64
path: |
build/src/avrdude
build/src/avrdude.conf
linux:
runs-on: ubuntu-latest
container: debian:11
strategy:
matrix:
include:
- { arch: i386, processor: i686, prefix: i686-linux-gnu, inc-lib: i386-linux-gnu }
- { arch: armhf, processor: armhf, prefix: arm-linux-gnueabihf, inc-lib: arm-linux-gnueabihf }
- { arch: arm64, processor: aarch64, prefix: aarch64-linux-gnu, inc-lib: aarch64-linux-gnu }
steps:
- uses: actions/checkout@v3
- name: Add architecture
run: |
dpkg --add-architecture ${{matrix.arch}}
apt-get update
- name: Install prerequisites
run: >-
apt-get update
apt-get install -y
git
cmake
flex
bison
crossbuild-essential-${{matrix.arch}}
libelf-dev:${{matrix.arch}}
libusb-dev:${{matrix.arch}}
libusb-1.0-0-dev:${{matrix.arch}}
libhidapi-dev:${{matrix.arch}}
libftdi1-dev:${{matrix.arch}}
libreadline-dev:${{matrix.arch}}
- name: Configure
run: >-
cmake
-D DEBUG_CMAKE=1
-D HAVE_LINUXGPIO=1
-D HAVE_LINUXSPI=1
-D CMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
-D CMAKE_SYSTEM_NAME=Linux
-D CMAKE_SYSTEM_PROCESSOR=${{matrix.processor}}
-D CMAKE_C_COMPILER=${{matrix.prefix}}-gcc
-D CMAKE_FIND_ROOT_PATH=/usr/${{matrix.prefix}}
-D CMAKE_INCLUDE_PATH=/usr/include/${{matrix.inc-lib}}
-D CMAKE_LIBRARY_PATH=/usr/lib/${{matrix.inc-lib}}
-B build
- name: Build
run: cmake --build build
- name: Archive build artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: build-linux-${{matrix.processor}}
path: |
build/
!**/*.d
!**/*.o
- name: Archive executables
uses: actions/upload-artifact@v3
with:
name: avrdude-linux-${{matrix.processor}}
path: |
build/src/avrdude
build/src/avrdude.conf
macos-x86_64:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: Install prerequisites
run: >-
# brew update
brew install
cmake
flex
bison
libelf
libusb
hidapi
libftdi
readline
- name: Configure
run: >-
cmake
-D CMAKE_C_FLAGS=-I/usr/local/include
-D CMAKE_EXE_LINKER_FLAGS=-L/usr/local/Cellar
-D DEBUG_CMAKE=1
-D CMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
-B build
- name: Build
run: cmake --build build
- name: Archive build artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: build-macos-x86_64
path: |
build/
!**/*.d
!**/*.o
- name: Archive executables
uses: actions/upload-artifact@v3
with:
name: avrdude-macos-x86_64
path: |
build/src/avrdude
build/src/avrdude.conf
msvc:
runs-on: windows-latest
strategy:
matrix:
include:
- { arch: x86, platform: Win32 }
- { arch: x64, platform: x64 }
- { arch: arm64, platform: ARM64 }
steps:
- uses: actions/checkout@v3
- name: Install prerequisites
# As Chocolatey is notoriously unreliable, install winflexbison3 directly from GitHub.
# run: choco install winflexbison3
run: |
curl https://github.com/lexxmark/winflexbison/releases/download/v2.5.24/win_flex_bison-2.5.24.zip --location --output winflexbison.zip
unzip winflexbison.zip -d ${{github.workspace}}\winflexbison
echo "${{github.workspace}}\winflexbison" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Configure
run: >-
cmake
-A ${{matrix.platform}}
-D DEBUG_CMAKE=1
-D CMAKE_SYSTEM_VERSION=11
-D CMAKE_C_FLAGS_RELWITHDEBINFO="/MT /GL /Zi /O2 /Ob1 /DNDEBUG"
-D CMAKE_CXX_FLAGS_RELWITHDEBINFO="/MT /GL /Zi /O2 /Ob1 /DNDEBUG"
-D CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO="/DEBUG /INCREMENTAL:NO /LTCG /OPT:REF /OPT:ICF"
-D HAVE_LIBREADLINE=HAVE_LIBREADLINE-NOTFOUND
-D CMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
-D USE_EXTERNAL_LIBS=1
-B build
- name: Build
run: cmake --build build --config ${{env.BUILD_TYPE}}
- name: Archive build artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: build-msvc-${{matrix.arch}}
path: |
build/
!**/_deps/
!**/*.obj
- name: Move executables
run: |
mv build/src/RelWithDebInfo/avrdude.exe build/src
mv build/src/RelWithDebInfo/avrdude.pdb build/src
- name: Archive executables
uses: actions/upload-artifact@v3
with:
name: avrdude-msvc-${{matrix.arch}}
path: |
build/src/avrdude.exe
build/src/avrdude.pdb
build/src/avrdude.conf
mingw:
runs-on: windows-latest
defaults:
run:
shell: msys2 {0}
strategy:
matrix:
include:
- { sys: mingw32, env: i686 }
- { sys: mingw64, env: x86_64 }
steps:
- uses: actions/checkout@v3
- uses: msys2/setup-msys2@v2
with:
msystem: ${{matrix.sys}}
update: true
install: >-
base-devel
mingw-w64-${{matrix.env}}-gcc
mingw-w64-${{matrix.env}}-cmake
mingw-w64-${{matrix.env}}-libelf
mingw-w64-${{matrix.env}}-libusb
mingw-w64-${{matrix.env}}-libusb-compat-git
mingw-w64-${{matrix.env}}-hidapi
mingw-w64-${{matrix.env}}-libftdi
- name: Configure
run: >-
cmake
-G"MSYS Makefiles"
-D DEBUG_CMAKE=1
-D CMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
-B build
- name: Build
run: cmake --build build
- name: Archive build artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: build-mingw-${{matrix.env}}
path: |
build/
- name: Archive executables
uses: actions/upload-artifact@v3
with:
name: avrdude-mingw-${{matrix.env}}
path: |
build/src/avrdude.exe
build/src/avrdude.conf

78
.github/workflows/deploy.yml vendored Normal file
View File

@@ -0,0 +1,78 @@
#
# deploy.yml - GitHub deploy action for AVRDUDE
# Copyright (C) 2021 Marius Greuel
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
name: Deploy
on:
push:
tags:
- 'v*'
jobs:
build:
uses: mariusgreuel/avrdude/.github/workflows/build.yml@windows
release:
needs: build
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
with:
tag_name: ${{github.ref}}
release_name: AVRDUDE ${{github.ref}}
body: "See **[Release Notes](https://github.com/avrdudes/avrdude/blob/main/NEWS)** for changes"
draft: false
prerelease: false
asset-msvc:
needs: release
runs-on: ubuntu-latest
strategy:
matrix:
include:
- { arch: x86 }
- { arch: x64 }
- { arch: arm64 }
steps:
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: avrdude-msvc-${{matrix.arch}}
- name: Create release asset
run: >-
zip -j asset.zip
avrdude.exe
avrdude.pdb
avrdude.conf
- name: Upload release asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
with:
upload_url: ${{needs.release.outputs.upload_url}}
asset_path: ./asset.zip
asset_name: avrdude-${{github.ref_name}}-windows-${{matrix.arch}}.zip
asset_content_type: application/zip

85
.gitignore vendored
View File

@@ -1,68 +1,67 @@
.deps
.libs
autom4te.cache
m4
ac_cfg.h
.DS_Store
.deps/
.libs/
m4/
*.diff
*.patch
y.output
y.tab.h
lexer.c
config_gram.c
config_gram.h
.depend
INSTALL
Makefile.in
Makefile
ac_cfg.h.in
ac_cfg.h.in~
aclocal.m4
avrdude
autom4te.cache
configure
configure~
depcomp
install-sh
compile
missing
mkinstalldirs
stamp-h.in
stamp-h1
ac_cfg.h
avrdude.conf
avrdude.conf.tmp
avrdude.spec
compile
config.guess
config.log
config.status
config.sub
config_gram.c
config_gram.h
configure
depcomp
INSTALL
install-sh
lexer.c
avrdude
libtool
ltmain.sh
Makefile
Makefile.in
mdate-sh
mkinstalldirs
missing
stamp-h.in
stamp-h1
texinfo.tex
y.output
y.tab.h
ylwrap
tags
cscope.out
*.o
*.lo
*.a
*.la
*.diff
*.patch
## Ignore Visual Studio build results
# CMake
out/
build/
build_*/
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# Build results
# Visual Studio
.vs/
[Dd]ebug/
[Rr]elease/
x64/
x86/
*.suo
*.user
*.userosscache
*.sln.docstates
*.log
# Visual Studio cache/options directory
.vs/
# Include pre-built files
!ac_cfg.h
!config_gram.c
!config_gram.h
!lexer.c
# Visual Studio code
.vscode/

View File

@@ -1,33 +0,0 @@
language: c++
matrix:
include:
- name: "Linux (GCC)"
os: linux
dist: bionic
compiler: gcc
before_install:
- sudo apt-get -y install make gcc automake libtool flex bison
- sudo apt-get -y install libelf-dev libusb-dev libftdi1-dev libhidapi-dev
script:
- ./bootstrap
- ./configure
- make
- name: "macOS (clang)"
os: osx
osx_image: xcode12u
compiler: clang
before_install:
- brew install flex bison
script:
- ./bootstrap
- ./configure
- make
- name: "Windows (MSVC)"
if: branch = windows OR branch = dev
os: windows
before_install:
- choco install visualstudio2019buildtools --package-parameters "--add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.Windows10SDK.18362"
- export PATH=$PATH:"/c/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/MSBuild/Current/Bin"
script:
- MSBuild.exe -fileLogger -target:avrdude -property:Configuration=Release -property:Platform=x64 avrdude.sln

24
AUTHORS
View File

@@ -2,6 +2,14 @@ AVRDUDE was written by:
Brian S. Dean <bsd@bdmicro.com>
AVRDUDE is currently maintained by:
Hans Eirik Bull
Stefan Rueger
Xiaofan Chen
Marius Greuel
Joerg Wunsch
Contributors:
Joerg Wunsch <j@uriah.heep.sax.de>
@@ -24,7 +32,19 @@ Contributors:
Rene Liebscher <r.liebscher@gmx.de>
Jim Paris <jim@jtan.com>
Jan Egil Ruud <janegil.ruud@microchip.com>
David Mosberger-Tang
David Mosberger <davidm@egauge.net>
David Sainty
Marius Greuel <greuelm@mgtek.com>
Dawid Buchwald <dawid.buchwald@hotmail.com>
Hans Eirik Bull
Stefan Rueger
Xiaofan Chen
For minor contributions, please see the ChangeLog files.
Contributors to code no longer present:
Dale Roberts for the giveio driver
Paula Tomlinson for the loaddrv sources
Chris Liechti for loaddrv modifications
For minor contributions, please see the ChangeLog files / Git log.

396
CMakeLists.txt Normal file
View File

@@ -0,0 +1,396 @@
#
# CMakeLists.txt - CMake project for AVRDUDE
# Copyright (C) 2021 Marius Greuel
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Typical usage:
# cmake -B build
# cmake --build build
cmake_minimum_required(VERSION 3.14)
project(avrdude VERSION 7.1 LANGUAGES C)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED True)
option(BUILD_DOC "Enable building documents" OFF)
option(HAVE_LINUXGPIO "Enable Linux sysfs GPIO support" OFF)
option(HAVE_LINUXSPI "Enable Linux SPI support" OFF)
option(HAVE_PARPORT "Enable parallel port support" OFF)
option(USE_EXTERNAL_LIBS "Use external libraries from AVRDUDE GitHub repositories" OFF)
option(USE_LIBUSBWIN32 "Prefer libusb-win32 over libusb" OFF)
option(DEBUG_CMAKE "Enable debugging output for this CMake project" OFF)
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
if(WIN32)
# Prefer static libraries over DLLs on Windows
option(USE_STATIC_LIBS "Use static libraries" ON)
else()
option(USE_STATIC_LIBS "Use static libraries" OFF)
endif()
include(CheckIncludeFile)
include(CheckSymbolExists)
include(FetchContent)
include(FindPackageMessage)
include(GNUInstallDirs)
set(CONFIG_DIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}")
set(AVRDUDE_FULL_VERSION ${CMAKE_PROJECT_VERSION})
# =====================================
# Get Git commit info
# =====================================
# GIT_COMMIT_HASH -> hash of latest commit, e.g. b8b859f5
# GIT_COMMIT_DATE -> date of latest commit, e.g. 20201231
# GIT_COMMIT_YEAR -> year of latest commit, e.g. 2020
find_package(Git)
if(Git_FOUND)
execute_process(
COMMAND "${GIT_EXECUTABLE}" log -1 --format=%h
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_COMMIT_HASH
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND "${GIT_EXECUTABLE}" log -1 --format=%ad --date=format:%Y%m%d
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_COMMIT_DATE
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND "${GIT_EXECUTABLE}" log -1 --format=%ad --date=format:%Y
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_COMMIT_YEAR
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND "${GIT_EXECUTABLE}" log -1 --tags --format=%h
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_TAG_HASH
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
)
# If the commit is not tagged, include the date and commit hash in the full version string.
if(NOT GIT_COMMIT_HASH STREQUAL GIT_TAG_HASH)
set(AVRDUDE_FULL_VERSION "${CMAKE_PROJECT_VERSION}-${GIT_COMMIT_DATE} (${GIT_COMMIT_HASH})")
endif()
endif()
find_package(FLEX)
if(NOT FLEX_FOUND)
message(SEND_ERROR "This CMake project requires 'flex', which is not installed on your system." )
endif()
find_package(BISON QUIET)
if(BISON_FOUND)
find_package_message(BISON "Found BISON: ${BISON_EXECUTABLE} (found version \"${BISON_VERSION}\")" "[${BISON_EXECUTABLE}][${BISON_VERSION}]")
else()
find_program(YACC_EXECUTABLE NAMES yacc byacc DOC "path to the yacc executable")
mark_as_advanced(YACC_EXECUTABLE)
if(YACC_EXECUTABLE)
find_package_message(YACC "Found YACC: ${YACC_EXECUTABLE}" "[${YACC_EXECUTABLE}]")
else()
message(SEND_ERROR "This CMake project requires 'bison', 'yacc', or 'byacc', which is not installed on your system." )
endif()
endif()
# =====================================
# Detect installed libraries
# =====================================
if(USE_STATIC_LIBS)
set(PREFERRED_LIBELF libelf.a elf)
set(PREFERRED_LIBUSB libusb.a usb)
set(PREFERRED_LIBUSB_1_0 libusb-1.0.a usb-1.0)
set(PREFERRED_LIBHIDAPI libhidapi.a libhidapi-libusb.a libhidapi-hidraw.a hidapi hidapi-libusb hidapi-hidraw)
set(PREFERRED_LIBFTDI libftdi.a ftdi)
set(PREFERRED_LIBFTDI1 libftdi1.a ftdi1)
set(PREFERRED_LIBREADLINE libreadline.a)
else()
set(PREFERRED_LIBELF elf)
set(PREFERRED_LIBUSB usb)
set(PREFERRED_LIBUSB_1_0 usb-1.0)
set(PREFERRED_LIBHIDAPI hidapi hidapi-libusb hidapi-hidraw)
set(PREFERRED_LIBFTDI ftdi)
set(PREFERRED_LIBFTDI1 ftdi1)
set(PREFERRED_LIBREADLINE readline)
endif()
# -------------------------------------
# Find libelf
find_library(HAVE_LIBELF NAMES ${PREFERRED_LIBELF})
if(HAVE_LIBELF)
set(LIB_LIBELF ${HAVE_LIBELF})
check_include_file(libelf.h HAVE_LIBELF_H)
check_include_file(libelf/libelf.h HAVE_LIBELF_LIBELF_H)
endif()
# -------------------------------------
# Find libusb
find_library(HAVE_LIBUSB NAMES ${PREFERRED_LIBUSB})
if(HAVE_LIBUSB)
set(LIB_LIBUSB ${HAVE_LIBUSB})
endif()
find_library(HAVE_LIBUSB_1_0 NAMES ${PREFERRED_LIBUSB_1_0})
if(HAVE_LIBUSB_1_0)
set(LIB_LIBUSB_1_0 ${HAVE_LIBUSB_1_0})
endif()
# FreeBSD's library 'libusb' supports both the libusb-0.1 and libusb-1.0 API.
if (HAVE_LIBUSB AND CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
set(HAVE_LIBUSB_1_0 ${HAVE_LIBUSB})
endif()
find_library(HAVE_LIBUSB_WIN32 NAMES libusb0.a usb0)
if(HAVE_LIBUSB OR HAVE_LIBUSB_1_0 OR HAVE_LIBUSB_WIN32)
check_include_file(usb.h HAVE_USB_H)
check_include_file(lusb0_usb.h HAVE_LUSB0_USB_H)
check_include_file(libusb.h HAVE_LIBUSB_H)
check_include_file(libusb-1.0/libusb.h HAVE_LIBUSB_1_0_LIBUSB_H)
if((USE_LIBUSBWIN32 OR NOT HAVE_LIBUSB) AND HAVE_LIBUSB_WIN32)
set(HAVE_LIBUSB ${HAVE_LIBUSB_WIN32})
set(LIB_LIBUSB ${HAVE_LIBUSB_WIN32})
unset(HAVE_USB_H CACHE)
elseif(NOT HAVE_USB_H)
find_path(LIBUSB_COMPAT_DIR libusb-compat/usb.h)
if(LIBUSB_COMPAT_DIR)
set(LIBUSB_COMPAT_DIR ${LIBUSB_COMPAT_DIR}/libusb-compat)
set(HAVE_USB_H 1)
else()
unset(LIBUSB_COMPAT_DIR CACHE)
endif()
endif()
endif()
# -------------------------------------
# Find libhidapi
find_library(HAVE_LIBHID NAMES hid)
if(HAVE_LIBHID)
set(LIB_LIBHID ${HAVE_LIBHID})
endif()
find_library(HAVE_LIBHIDAPI NAMES ${PREFERRED_LIBHIDAPI})
if(HAVE_LIBHIDAPI)
set(LIB_LIBHIDAPI ${HAVE_LIBHIDAPI})
check_include_file(hidapi/hidapi.h HAVE_HIDAPI_HIDAPI_H)
endif()
# -------------------------------------
# Find libftdi
find_library(HAVE_LIBFTDI NAMES ${PREFERRED_LIBFTDI})
if(HAVE_LIBFTDI)
set(LIB_LIBFTDI ${HAVE_LIBFTDI})
set(HAVE_LIBFTDI_TYPE_232H 1)
endif()
find_library(HAVE_LIBFTDI1 NAMES ${PREFERRED_LIBFTDI1})
if(HAVE_LIBFTDI1)
set(LIB_LIBFTDI1 ${HAVE_LIBFTDI1})
set(HAVE_LIBFTDI_TYPE_232H 1)
set(CMAKE_REQUIRED_LIBRARIES ${LIB_LIBFTDI1} ${LIB_LIBUSB} ${LIB_LIBUSB_1_0})
check_symbol_exists(ftdi_tcioflush "libftdi1/ftdi.h" HAVE_FTDI_TCIOFLUSH)
endif()
# -------------------------------------
# Find libreadline
find_library(HAVE_LIBREADLINE NAMES ${PREFERRED_LIBREADLINE})
if(HAVE_LIBREADLINE)
set(LIB_LIBREADLINE ${HAVE_LIBREADLINE})
elseif(MSVC)
set(HAVE_LIBREADLINE 1)
endif()
# =====================================
# Use external libraries if requested
# =====================================
if(USE_EXTERNAL_LIBS)
FetchContent_Declare(libelf
GIT_REPOSITORY https://github.com/avrdudes/libelf.git
GIT_TAG e5a39bf19bd6598c42e09172be5a78ceec2a065c
)
FetchContent_Declare(libusb
GIT_REPOSITORY https://github.com/avrdudes/libusb.git
GIT_TAG 632bc25d04eff563cc00de29435b9a7ed6f4654c
)
FetchContent_Declare(libhidapi
GIT_REPOSITORY https://github.com/avrdudes/libhidapi.git
GIT_TAG d1307487973c857bc158e27ecc99644b2f5e68ea
)
FetchContent_Declare(libftdi
GIT_REPOSITORY https://github.com/avrdudes/libftdi.git
GIT_TAG f9fe6e96b97c3a08efd081632c1859cb83aa14e3
)
message(STATUS "Fetching external libraries, please wait...")
FetchContent_MakeAvailable(
libelf
libusb
libhidapi
libftdi
)
message(STATUS "Using external library 'libelf'")
set(LIB_LIBELF libelf)
set(HAVE_LIBELF 1)
set(HAVE_LIBELF_H 1)
message(STATUS "Using external library 'libusb'")
set(LIB_LIBUSB libusb)
set(HAVE_LIBUSB 1)
set(HAVE_LUSB0_USB_H 1)
message(STATUS "Using external library 'libhidapi'")
set(LIB_LIBHIDAPI libhidapi)
set(HAVE_LIBHIDAPI 1)
set(HAVE_HIDAPI_HIDAPI_H 1)
message(STATUS "Using external library 'libftdi'")
set(LIB_LIBFTDI libftdi)
set(HAVE_LIBFTDI 1)
set(HAVE_LIBFTDI_TYPE_232H 1)
endif()
add_subdirectory(src)
if(BUILD_DOC)
add_subdirectory(src/doc)
endif()
# =====================================
# Configuration
# =====================================
message(STATUS "Configuration summary:")
message(STATUS "----------------------")
if (DEBUG_CMAKE)
message(STATUS "CMAKE_HOST_SYSTEM: ${CMAKE_HOST_SYSTEM}")
message(STATUS "CMAKE_SYSTEM: ${CMAKE_SYSTEM}")
message(STATUS "CMAKE_FIND_ROOT_PATH: ${CMAKE_FIND_ROOT_PATH}")
message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")
message(STATUS "CONFIG_DIR: ${CONFIG_DIR}")
message(STATUS "AVRDUDE_FULL_VERSION: ${AVRDUDE_FULL_VERSION}")
message(STATUS "USE_EXTERNAL_LIBS: ${USE_EXTERNAL_LIBS}")
message(STATUS "USE_LIBUSBWIN32: ${USE_LIBUSBWIN32}")
message(STATUS "HAVE_LIBELF: ${HAVE_LIBELF}")
message(STATUS "HAVE_LIBUSB: ${HAVE_LIBUSB}")
message(STATUS "HAVE_LIBUSB_1_0: ${HAVE_LIBUSB_1_0}")
message(STATUS "HAVE_LIBUSB_WIN32: ${HAVE_LIBUSB_WIN32}")
message(STATUS "HAVE_LIBHID: ${HAVE_LIBHID}")
message(STATUS "HAVE_LIBHIDAPI: ${HAVE_LIBHIDAPI}")
message(STATUS "HAVE_LIBFTDI: ${HAVE_LIBFTDI}")
message(STATUS "HAVE_LIBFTDI1: ${HAVE_LIBFTDI1}")
message(STATUS "HAVE_LIBREADLINE: ${HAVE_LIBREADLINE}")
message(STATUS "HAVE_LIBELF_H: ${HAVE_LIBELF_H}")
message(STATUS "HAVE_LIBELF_LIBELF_H: ${HAVE_LIBELF_LIBELF_H}")
message(STATUS "HAVE_USB_H: ${HAVE_USB_H}")
message(STATUS "HAVE_LUSB0_USB_H: ${HAVE_LUSB0_USB_H}")
message(STATUS "HAVE_LIBUSB_H: ${HAVE_LIBUSB_H}")
message(STATUS "HAVE_LIBUSB_1_0_LIBUSB_H: ${HAVE_LIBUSB_1_0_LIBUSB_H}")
message(STATUS "HAVE_HIDAPI_HIDAPI_H: ${HAVE_HIDAPI_HIDAPI_H}")
message(STATUS "LIBUSB_COMPAT_DIR: ${LIBUSB_COMPAT_DIR}")
message(STATUS "----------------------")
endif()
if(HAVE_LIBELF)
message(STATUS "DO HAVE libelf")
else()
message(STATUS "DON'T HAVE libelf")
endif()
if(HAVE_LIBUSB)
message(STATUS "DO HAVE libusb")
else()
message(STATUS "DON'T HAVE libusb")
endif()
if(HAVE_LIBUSB_1_0)
message(STATUS "DO HAVE libusb_1_0")
else()
message(STATUS "DON'T HAVE libusb_1_0")
endif()
if(HAVE_LIBHIDAPI)
message(STATUS "DO HAVE libhidapi")
else()
message(STATUS "DON'T HAVE libhidapi")
endif()
if(HAVE_LIBFTDI)
if(HAVE_LIBFTDI1)
message(STATUS "DO HAVE libftdi (but prefer to use libftdi1)")
else()
message(STATUS "DO HAVE libftdi")
endif()
else()
message(STATUS "DON'T HAVE libftdi")
endif()
if(HAVE_LIBFTDI1)
message(STATUS "DO HAVE libftdi1")
else()
message(STATUS "DON'T HAVE libftdi1")
endif()
if(HAVE_LIBREADLINE)
message(STATUS "DO HAVE libreadline")
else()
message(STATUS "DON'T HAVE libreadline")
endif()
if(BUILD_DOC)
message(STATUS "ENABLED doc")
else()
message(STATUS "DISABLED doc")
endif()
if(HAVE_PARPORT)
message(STATUS "ENABLED parport")
else()
message(STATUS "DISABLED parport")
endif()
if(HAVE_LINUXGPIO)
message(STATUS "ENABLED linuxgpio")
else()
message(STATUS "DISABLED linuxgpio")
endif()
if(HAVE_LINUXSPI)
message(STATUS "ENABLED linuxspi")
else()
message(STATUS "DISABLED linuxspi")
endif()
message(STATUS "----------------------")

76
CMakeSettings.json Normal file
View File

@@ -0,0 +1,76 @@
{
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"variables": [
{
"name": "USE_EXTERNAL_LIBS",
"value": "true",
"type": "BOOL"
}
]
},
{
"name": "x64-Release",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x64_x64" ],
"variables": [
{
"name": "USE_EXTERNAL_LIBS",
"value": "true",
"type": "BOOL"
}
]
},
{
"name": "x86-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x86" ],
"variables": [
{
"name": "USE_EXTERNAL_LIBS",
"value": "true",
"type": "BOOL"
}
]
},
{
"name": "x86-Release",
"generator": "Ninja",
"configurationType": "RelWithDebInfo",
"buildRoot": "${projectDir}\\out\\build\\${name}",
"installRoot": "${projectDir}\\out\\install\\${name}",
"cmakeCommandArgs": "",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"inheritEnvironments": [ "msvc_x86" ],
"variables": [
{
"name": "USE_EXTERNAL_LIBS",
"value": "true",
"type": "BOOL"
}
]
}
]
}

4
INSTALL Normal file
View File

@@ -0,0 +1,4 @@
Installation Instructions
*************************
See README.md.

581
NEWS
View File

@@ -2,10 +2,506 @@ $Id$
Approximate change log for AVRDUDE by version.
(For more detailed changes, see the ChangeLog file.)
(For detailed changes, see the version control system logs.)
----------------------------------------------------------------------
Current:
Changes since version 7.1:
* Major changes compared to the previous version:
* New devices supported: none
* New programmers supported:
* Issues fixed:
* Pull requests:
* Internals:
Changes in version 7.1:
* Major changes compared to the previous version:
- Provide a new programmer -c urclock for bootloader urprotocol
+ Urclock fully supports vector bootloaders at no extra code size
+ Uprotocol
https://github.com/stefanrueger/urboot/blob/main/urprotocol.md
allows programming much shorter bootloaders with more features:
* Exports a pgm_write_page(sram, progmem) function that the
application can call at FLASHEND-4+1 to use flash as storage
* Supports EEPROM reads/writes
* Protects itself from overwriting
* Vector bootloaders: can protect the reset vector
* Offers Chip Erase function (quicker than uploading 0xff's)
+ Urclock when compiled with libreadline supports bootloaders in
terminal mode (preventing them from WDT timeout)
+ The -c urclock programmer provides a metadata interface that
allows unused flash to be used as storage
+ avrdude -c urclock is backward compatible with avrdude -c arduino
- Add TPI support for Microchip tools #1205
- Add C-strings, C characters and double to terminal write
- Provide write flash in the terminal (using a cache)
- Provide page erase in the terminal as pgerase
- Add support for NetBSD and OpenBSD to build.sh
* New devices supported: none
* New programmers supported:
- urclock = Urclock programmer for bootloaders using urprotocol
- xplainedmini_tpi = Atmel AVR XplainedMini in TPI mode
- xplainedpro_pdi = Atmel AVR XplainedPro in PDI mode
- atmelice_tpi = Atmel-ICE (ARM/AVR) in TPI mode
- powerdebugger_tpi = Atmel PowerDebugger (ARM/AVR) in TPI mode
- pickit4 = MPLAB(R) PICkit 4 in JTAG mode
- pickit4_tpi = MPLAB(R) PICkit 4 in TPI mode
- snap = MPLAB(R) SNAP in JTAG mode
- snap_tpi = MPLAB(R) SNAP in TPI mode
- arduino_gemma = Arduino Gemma bootloader disguised as USBtiny
- adafruit_gemma = Adafruit Trinket Gemma bootloader disguised as USBtiny
- digilent-hs2 = Digilient JTAG HS2 (MPSSE)
- tigard = Tigard interface board
* Issues fixed:
- Fix micronucleus bootloader to check for unresponsive USB
devices #945
- Fix src/CMakeLists.txt to honor CMAKE_INSTALL_LIBDIR #972
- [bug #43898] atmega644p remains stopped after JTAG
transaction #366
- Wrong timings for ATmega328PB and other parts in avrdude.conf
#976
- FT232R based programmer ATmega2560 Flash Reading Problem #995
also #474
- Enable avrdude to send full input file incl trailing 0xff
#936
- Portname default for linuxspi programmer not recognized #926
- JTAG1 unable to write fuse and lock bits #443
- Unknown option '-s' on command line (legacy) #1032
- STK500/arduino/xbee programmers fail EEPROM r/w for some
parts #967 also #421
- Design issue: jtag2updi is hardcoded to fail for parts with
has_pdi = yes #1037
- Option parse error: after -U flash:w:program_to_upload.hex,
subsequent -V ignored #441
- Automatic verification is designed to fail for stdin #1044
- Display correct number of bytes when input file has holes
#1005
- Cmake installs avrdude.1 in the wrong place on Linux #1064
- avr910 -qq prompt too verbose #1081
- avrftdi.c: paged write can fail at addr 0 #1073
- Permission denied accessing /sys/class/gpio/gpioX/direction
would leave pin exported #472 also #372
- Raspberry Pi sysfs bug workaround for linuxgpio driver #386
- Fix CMake avrdude.conf dependency to avrdude.conf.in #1035
- CMake infrastructure does not handle documentation #947
- New feature: ability to reset FLIPv2 targets #733
- Fix Extended address not sent with avr109/butterfly #360
and #454
- Enable AVR JTAG ICE mkI program EEPROM in terminal mode
#1054
- Make flash writes work in terminal mode #1020
- Add support for XMEGA specific AVR109 protocol extensions
used by XBoot #200
- jtag2updi can not write EEPROM in terminal mode #1116
- Make UPDI programmers less verbose during initialization
#1084
- Quell mode isn't handled systematically #1114
- Mixing the progress bar with warning messages #1136
- Inconsistent terminal output re stdout and stderr #1130
- Supress the warning for Microchip SNAP #1135
- ATtiny85 communication problem with default bitclock #1133
- [Regression] Optiboot for "modern AVRs" no longer works #1120
- Cannot access EEPROM on some bootloader/part combos #970
- -U writes sometimes more bytes to flash/memory than input
file has #1050
- debugWire using dragon_dw and jtag2dw not working #1168
- && echo OK does not work after -c urclock #1192
- Serial drain timeout needs calibrating for -c urclock #1193
- avrdude -U file.elf misses second and following suitable
sections in elf segements #1204
- Avrdude on macOS has problems with libedit #1173
- urclock support for optiboot_x and optiboot_dx #1200
- Terminal does not continue read/dump correctly #1201
- JTAG3 programmer info not available in ISP mode #1212
- Extra avrdude> prompt with -qqt in terminal mode #1214
- PICkit4 and SNAP serial numbers not read by Avrdude #1038
- Optiboot EEPROM support cannot be detected by avrdude #1224
- megaAVR JTAG programming doesn't work for SNAP and PICkit4
#1052
- urclock/FTDI communication issues #1245
- stk500v2.c dumps core on open #1254
- linuxgpio cannot use pin 0 #1228
- Remove non-working butterfly page erase function
- linuxgpio and linuxspi: input files with unset bytes don't program
correctly #1263 #455
* Pull requests:
- Fix .Dd macro in manpage #949
- fix M1 homebrew path #950
- CMake Enhancements #962
- Reduce programmer desc string length in avrdude.conf
to < 80 characters #1000
- Dragon JTAG fix #979
- adding support for all Linux baud rates v.2 #993
- Replace internal knowledge in jtag3.c by a public API #996
- JTAG3 UPDI EEPROM fix #1013
- Treat x bits in .conf SPI commands as 0 #943
- Fix avrftdi support for ATmega2560 et al #998
- Fix avrdude.conf timings for ATmega328PB and other parts #1001
- Fix PICKit2 ATmega2560 flash paged flash read #1023
- Fix ft245r paged read for ATmega2560 et al #1018
- Add option -A that supresses trailing 0xff optimisation
and automatically do so for -c arduino #936
- Fix linuxspi default port #933
- Add support for high-voltage UPDI im jtag3.c #1015
- Fix terminal write edge cases; add one read mode; add quell
command #1025
- Fix usbtiny read for parts with more than 64 kB flash #1029
- CMakeLists.txt: fix build without C++ #1016
- Provide file format I: Intel HEX with comments that ignores
checksum errors #1030
- Enable writing fuse and lock bits for AVR-JTAGICE #1031
- Ignore -s flag as safemode is no longer supported #1033
- Developer options to describe parts and
extend avrdude.conf syntax #1040
- Deprecate original STK500 v1 protocol in favour of optiboot
and Arduino as ISP #1046
- Add jtagmkii_updi programmer option #1048
- Enable stdin verification, display correct number of bytes
written/verified, check -U memory names against spelling
errors and exit but skip -U memory updates with known
memories that the part lacks #1053
- Handle invalid -U file format specifiers for input #1042
- Implement a dry run for -U updates before opening the
programmer #1056
- Implement -c <wildcard>/dev_options for printing avrdude.conf
show comments with -p*/s or -c*/s; Reduce -p */r raw output;
specifying the full memory name now always works; stop
listing programmers where id starts with dot #1059
- Fix logfile short option in man-page; fix install dir for man
page #1063
- Use const for programmer functions where useful; add second
argument for programmer enable interface function
void (*enable)(PROGRAMMER *pgm, const AVRPART *p) #1078
- Make avr910 programmer initialize() less verbose #1083
- Fix flash paged write for avrftdi.c #1074
- Fix 4 parts wrt to their interfaces in avrdude.conf; rewrite
avrdude.conf.in file from avrdude -c* -p* output; reformat
conditional programmers in avrdude.conf.in using -c*; fix
reset=dedicated|io; entries #1086
- Add prog_modes, a bitwise or of prgramming modes, to part and
programmer definitions; add to part definition
+ mcuid, a unique id in 0..2039 for 8-bit AVR
+ n_interrupts, the number of interrupts
+ n_page_erase, if set, the # of pages erased for NVM erase
implement a simple calculator in config_gram.y for numeric
values; set part prog_modes, mcuid, n_interrupts and
n_page_erase in avrdude.conf.in; add external intelligence
about AVRs avrintel.[ch] to the project and warn during
parsing if mcuid is incompatible with it #1091
- Fix permission denied error in linuxgpio programmer #917
- Add a programmer arduino_gemma for the Arduino Gemma
bootloader and another one, adafruit_gemma, for the Adafruit
Trinket Gemma bootloader in avrdude.conf; #1093
- Add digilent-hs2 programmer in avrdude.conf #1094
- Fix dependency chain between avrdude.conf.in and
avrdude.conf #1095
- Build docs with CMake #1096
- New feature so user can print all compatible parts for a
programmer using -p\? -c programmer and vice versa #1099
- Add extended parameter disable_no_cs for linuxspi programmer
#1100
- Fix avr109 extended address #1101
- Add support for Flip 2 reset on exit #1102
- Support for Power Debugger analog readings in terminal mode
#1105
- Provide cached byte-wise read/write API #1106
- AVR109: support for prodsig read and usersig read/write #1108
- Add missing AVR variants the original JTAG ICE supports #1109
- Improve help message in terminal and provide new command
pgerase #1113
- Fix pointer truncation for Windows x64 #1119
- Fix jtag3_page_erase for targets with UPDI #1112
- Fix writing of last word on DWORD TPI parts #1115
- Use byte-wise read/write when page size is 1 in terminal
cache #1121
- Suppress Teensy USB communication error message on reboot #1122
- Fix UPDI erase when target is locked #1125
- Review and overhaul AVRDUDE's messaging system #1126
- Look for ~/.config/avrdude/avrdude.rc then ~/.avrduderc #1131
- Revamp terminal output (progress bar, callback and
stdout/stderr) #1132
- Detect PICkit4 and SNAP in PIC mode #1138
- Mention -B in the error message #1139
- Support optiboot, optiboot_dx and optiboot_x bootloaders for
-c arduino #1140
- Always use paged access for programmers that serve
bootloaders #1141
- Add libreadline-dev for Linux github action build #1146
- Implementation of SerialUPDI page erase operation #1151
- Fix Type 2 HV UPDI #1164
- Rewrite authors/copyrights #1182
- Add fallback for EM_AVR #1181
- Add a workaround for issue 1173 #1185
- Add xplainedpro_pdi programmer #1147
- Provide Urclock programmer #1171
- Fix JTAGICE mkII (not initializing after chip erase) #1172
- Ensure default_programmer from config files is used #1174
- Make terminal write's automatic number width less surprising
#1175
- Print HAVE_LIBREADLINE status when making the project #1184
- Pad pages with input file contents before avr_write() #1188
- Deprecate mosi/miso in favour of sdo/sdi #1189
- Provide bootloader-hash tool #1190
- Fix JTAGICE mkII parameters for parts with bootloaders #1191
- Fix shell exit value when chip erase is delayed #1194
- Support autobaud for urclock programmer #1198
- Fix userrow size and page_size for ATtiny3216/7 #1199
- Added TPI support for Microchip tools #1205
- Fix reading of .elf files #1206
- Use libedit only in interactive mode #1207
- Add urclock support for bootloaders in low flash #1208
- Terminal read improvements #1209
- Print meaningful error when a too slow ISP clock is detected #1216
- Check alternative USB PID for PICkit4/SNAP in PIC mode #1219
- Remove extraneous avrdude> prompt at end of terminal session #1220
- Read programmer serial number from libusb or hidusb #1223
- Hint at -xeepromrw option in EEPROM error messages #1226
- Add JTAG support for PICkit4 and Snap. #1233
- Mention developer options in documentation and Usage() #1234
- Print expected signature on signature mismatch #1237
- To work around Issue #1107 #1240
- Update build.sh for NetBSD #1241
- Add FT2232H support for Windows, Tigard programmer #1242
- Modify recv timeouts to accommodate urclock sync with ftdi
#1246
- CMake updates #1243
- Silence conf path detection debug output #1247
- Make WIN32 ser_recv() fail on time-out #1248
- Guard urclock_getsync() against initial spurious input #1251
- Change definition of NO_PIN to 1+PIN_MAX #1231
- Fix partial matches for locate_mem() and do_cmd() #1256
- Add abbreviated q command in terminal
- Move static usbsn into serdev struct and remove serno #1258
- Clean up avrdude.conf.in fixing a couple of bugs #1260
- Add readline library replacement for MSVC #1264
- Ensure full words are loaded for ISP programming #1265
- Silence page erase in cache code #1266
- Update to latest MSVC fork of hidapi to include bug fixes
#1269
* Internals:
- Implement -c <wildcard>/dev_opts and -p <wildcard>/dev_opts
for printing avrdude.conf programmer and part entries
- Added shorter alternative ISP commands for avrdude.conf
- Reformatted avrdude.conf to canonical form
- Reviewed API for prgrammer functions: use const for
programmer functions where useful; add second argument for
void (*enable)(PROGRAMMER *pgm, const AVRPART *p) #1078
- Reviewed messaging system making warnings and errors explicit
and treat them systematically
Changes in version 7.0:
* Major changes compared to the previous version:
- Completely revamped Windows support, including MSVC
- Started to add CMake (by now, parallel with autoconf/automake)
- New-architecture devices (AVR8X mega and tiny) can access all
fuses, and memory display shows meaningful alias names
- The "safemode" feature has been removed. The major class of
programmers it has been designed for (lowlevel bitbang
programmers on parallel or serial ports) virtually doesn't exist
anymore, and the fuse combination that was covered by it do not
match the fuses of modern AVR devices anyway.
- avrdude.conf is now being looked up in the location of the
executable file first, before considering the configured default
location; this eases a "portable use" where the entire suite is
not installed into its configured default location. (Basically
only relevant for unixoid systems; on Windows, this search order
has been used for many years already.)
* New devices supported:
- ATtiny828, ATtiny87, ATtiny167, ATtiny48, ATtiny102, ATtiny104
- LGT8F88P, LGT8F168P, LGT8F328P (fixed names of these parts)
- ATmeg164A, ATmega169A, ATmega169P, ATmega169PA, ATmega329A,
ATmega329PA, ATmega3290, ATmega3290A, ATmega3290PA, ATmega649A,
ATmega649P, ATmega6490A, ATmega6490P, ATmega165, ATmega165A,
ATmega165P, ATmega165PA, ATmega325A, ATmega325P, ATmega325PA,
ATmega645A, ATmega645P, ATmega3250A, ATmega3250P, ATmega3250PA,
ATmega6450A, ATmega6450P
- ATmega48A/48PA/88A/88PA/168A/168PA, ATmega164A/644A/644PA,
ATmega16A/32A/64A/128A, ATtiny13A, ATtiny24A/44A/84A,
ATtiny261A/461A/861A, ATtiny828R, ATtiny2313A, ATtiny1634R
- ATtiny3224, ATtiny3226 and ATtiny3227
- AVR16DD14/20/28/32, AVR32DD14/20/28/32 and AVR64DD14/20/28/32
- AVR8EA28/32, AVR16EA28/32/48, AVR32EA28/32/48 and AVR64EA28/32/64
- ATmega16U4
* New programmers supported:
- SerialUPDI (UPDI devices connected to serial port with few
passive parts)
- PicKit4 / SNAP (now also in ISP and PDI mode)
- Teensy bootloader (PR #802)
- Micronucleus bootloader (PR #786)
- ft232h (generic variant, PR #842)
- Kristech KT-LINK FT2232H interface with IO switching and voltage
buffers (PR #930)
* Issues fixed:
- Curiosity Nano and terminal mode #790 (only the actual bugs
reported)
- CMake doesn't correctly handle conditionals in avrdude.conf.in
#776
- CMake doesn't detect FreeBSD's libusb-1.0 (compatibility) #775
- CMake doesn't correctly handle conditionals in avrdude.conf.in
#776
- CMake: Recognize more than just bison #785
- [bug #26007] ATTiny167 not supported #150
- [bug #47375] ATtiny102/104 descriptions missing in configuration
file #409
- No error message when connecting to a not-connected AVRISP mkII
programmer #813
- [bug #53180] missing programmer or bad -P option argument
doesn't result in error message #471
- ATmega328P reported as lgt8fx328p #812
- [bug #48004] Dead link for linuxgpio in avrdude description #419
- Segmentation fault when writing ATtiny104 fuse #823
- USBasp returns ERANGE for unknown error #848
- Compiler warnings #856
- Can't get serialupdi to work #874
- Rework HID support for Windows #881
- List of signing keys? #884
- Pickit4 UPDI is writing at offset 0x4000 into flash instead of 0x0000. #892
- SerialUPDI programmer can't write to usersig/userrow in terminal mode #889
- Signature read command for ATmega165* was wrong (no-id)
- Cannot use non-standard baud rates for uploading on MacOS #771
- Wrong values in avrdude.conf #897
- AVR-Eclipse plugin broken by missing -u commandline option #890
- Timeout passed to hid_read_timeout() is too short for instances
where the EDBG AVRISP 'Enter Programming Mode' command fails #900
- Terminal write mode doesn't support string input (yet) #913
- Terminal mode: memory fill with strings may cause Avrdude to crash. #922
- Some parts have wrong or missing ISP commands #915
- Incorrect -b conversion for linuxspi programmer #927
- ATtiny43U calibration memory size #921
* Pull requests:
- GitHub Migration #765
- Update toplevel files. #767
- GitHub Migration part 2 #768
- Remove 'windows' folder with giveio.sys driver #769
- SerialUPDI implementation - release candidate 1 #772
- Fix typos #777
- Fix memory leaks #779
- As promised, documentation for SerialUPDI programmer #782
- Improve CMake project #783
- Fix avr_read() for page reads #784
- Serialupdi manpage #787
- Add PicKit4 and SNAP programmers #791
- Use yacc/byacc as an alternative to bison, closes #785 #793
- Derive program version string from last commit #794
- Find 'avrdude.conf' based on absolute path to executable #780
- buspirate: fix -Wtautological-constant-out-of-range-compare #796
- avrftdi: don't use the deprecated ftdi_usb_purge_buffers routine #792
- Ignore ctags index file #804
- term: fix memleakOnRealloc #806
- Add missing ATtiny targets to avrdude.conf #803
- Add support for Teensy bootloader #802
- Conffile clean up #801
- Fix typos all over the code #807
- Add MSVC builds and better WinUSB/FTDI support #798
- buspirate: fix invalidScanfArgType_int warning #808
- Ignore ac_cfg.h.in~ #810
- Notify open failure #814
- Print expected part #817
- pindefs: conform to the function declaration #818
- Add support for Micronucleus bootloader #786
- Remove ac_cfg.h from libavrdude.h #820
- CMake: enable dynamic-link library for libavrdude #826
- Fix for TPI fuse write (issue #823) #828
- Add missing ATmega__5 and ATmega__9 targets to avrdude.conf #809
- Add missing ATmega and ATtiny targets #832
- Added missing RTS/DTR management feature to serialupdi
programmer #811
- Add missing tinyAVR-2, AVR DD and AVR EA targets #836
- Add a new programmer ft232h #842
- Reduce verbosity when setting fuses and uploading programs #845
- jtagmkii: Reduce the number of sync attempts to 10 + print
number of attempts #844
- CMake: add initial support for installing lib and include files #829
- Add SPI support to USBtiny #816
- Add more memory sections to read from #815
- Add a build script for Unix-like systems #849
- Fix receive buffer implementation in ftdi_syncbb programmer #843
- CMake: split configuration in two files #852
- Set number of connection retry attempts for Arduino/STK500
programmer #854
- Fix libusb-1.0 error strings #850
- Assign proper type to msg[] in errstr() #857
- Fix Arduino retry attempts #855
- CMake: use CMAKE_CURRENT_BINARY_DIR to locate avrdude.conf #858
- Remove the "safemode" feature. #859
- Add support for reading from more memory sections #863
- Alias keyword #868
- Add fuse name aliases to avrdude.conf + tweak update.c #869
- Print JTAG3 clocks after configuration + string formatting #853
- Tweak programmer info formatting strings #872
- Remove libhid support in ser_avrdoper.c in favor of libhidapi #882
- Reduce jtag3 output verbosity #877
- Fix Curiosity Nano target voltage #878
- Smallest possible fix for PL2303HX #885
- Add missing USBtiny derived programmers #873
- Cleanup of POSIX serial init code #886
- Avrdude terminal write improvements #880
- Add userrow and usersig aliases #888
- For UPDI devices do not add offset when accessing flash. #895
- Support both userrow and usersig names #893
- Fix ugly terminal write bug #896
- Improve terminal read functionality #894
- Macos nonstandard baudrates #898
- Fix errors in Avrdude.conf #899
- Minor terminal write improvements #902
- Term docs #903
- Add progressbar for read and write command #912
- Add MacOS serial/parallel port note #908
- Add ATmega16U4 to avrdude.conf #910
- Mask out unused ATmega32U4 efuse bits #909
- Increased timeout passed to hid_read_timeout() #901
- Add terminal write string functionality #914
- Update documentation link to new URL #929
- Fix terminal write buffer overflow issue #924
- Fix linuxspi baud to clock period calculation #931
- Added KT-LINK FT2232H interface with IO switching and voltage buffers. #930
* Internals:
- Development moved to Github
- Addition of "alias" keyword to avrdude.conf.in syntax; used
for fuse name aliases right now
Version 6.4:
* Major changes compared to the previous version:
@@ -14,9 +510,18 @@ Current:
debuggers (JTAGICE3 with firmware 3+, AtmelICE, EDBG, mEDBG)
- UPDI support added (AVR8X family)
- TPI support for USBtinyISP
- TPI support for ft245r
- TPI support for linuxgpio
- AVR Doper uses libhidapi rather than raw libusb (patch #9033)
- -P net:host:port can use IPv6 now (Posix systems only)
- New configure option: -disable-libusb_1_0
- extended UPDI device context (> 64 Ki flash)
- major overhaul of ft245r driver (patch #9327/#9328)
- some improvements in linuxspi driver
- Use -B <bitclock> rather than -b <baudrate> for linuxspi driver
- unused lock byte bits are not masked on read anymore
- parport support disabled by default; configure with
--enable-parport to explicitly enable it
* New devices supported:
@@ -30,13 +535,23 @@ Current:
ATmega4809
- ATtiny841, ATtiny441
- ATmega64M1
- ATmega324A
- ATmega808, ATmega809, ATmega1608, ATmega1609, AVR DA, AVR DB
- LGT8FX88P, LGT8FX168P, LGT8FX328P
- ATmega324PB
- ATmega8A
* New programmers supported:
- ehajo-isp (commercial version of USBtiny)
- XplainedPro in UPDI mode
- XplainedMini in UPDI mode
- JTAGICE3 in UPDI mode
- Atmel Powerdebugger in all modes (JTAG, PDI, UPDI, debugWIRE, ISP)
- linuxspi (direct SPI bus e.g. on Raspberry Pi devices)
- PICkit4, Snap, PKoB
- iseavrprog
- XBeeBoot
* Bugfixes:
bug #47550: Linux GPIO broken
@@ -44,6 +559,27 @@ Current:
bug #48084: Avoid compiled-in timestamp for reproducible release builds
bug #47376: ATtiny841 description missing in configuration file
bug #49455: support for tiny441
bug #57428: document when 'arduino' or 'wiring' should be used, and -D requirement of latter
bug #58095: error setting efuse on atmega328pb variant
bug #51409: Can't program EFUSE on ATmega32M1
bug #60753: Patch #1436 breaks multiple programmer/device combinations on MacOS BigSur
bug #59525: Bogus error message because Copy/Paste typo in stk500.c
bug #58078: [PATCH] buspirate: remove compound literals (fixes GCC>=9)
bug #57453: [PATCH] fix reference to nonexistant -m option by changing to -U
bug #59227: Add new part. How does one get a part added to the CONF file?
bug #55009: no efuses for m164a/pa
bug #55734: USBtiny programming of ATmega328p broken by Patch #9278
bug #58495: Add atmega324pb support to avrdude.conf.in
bug #60863: avrftdi programming error probably caused by multiple, consecutive empty pages
bug #50517: Reading fails if "immediate mode" for output file format is selected - fileio: invalid operation=1
bug #50630: Erase Cycle Counter options ( -y -Y n ) should be removed from usage Message
bug #48767: ser_drain() for TCP on Windows doesn't work
bug #46759: avrdude 6.1 -> 6.2 regression: lock byte verification error
bug #58440: linuxgpio PIN limit too low
bug #55462: wrong programmer id check in jtag3_getsync() and jtag3_close()
bug #58994: VPP PWM still enabled at the end of programming process
bug #57338: if safemode has to change fuses avrdude should exit with non-zero exit code
bug #60575: Permission denied on macOS Big Sur
* Patches:
patch #9482: Add support for UPDI and AVR8X
@@ -64,8 +600,43 @@ Current:
patch #8311: Add IPv6 support to the -Pnet:host:port option
patch #9542: Correct "usersig" on avr8x devices
patch #8128: Added new option to configure.ac script
patch #8444: Proposal for modifications in -B and -U command options managment
(partially)
patch #8444: Proposal for modifications in -B and -U command options managment (partially)
patch #9735: spelling error fix: psuedo -> pseudo
patch #9893: [PATCH] Reader reads ftdi handle after main thread close it
patch #9819: Address several leaks in SVN rev 1429
patch #9820: Fix some out-of-bounds/uninitialized issues
patch #9818: correct typos in SVN rev 1429
patch #9732: usbtiny_paged_load overflows buffer e.g. when reading EEPROM
patch #9966: Add JTAGICE3 in UPDI mode
patch #9963: UsbAsp 3 MHz patch for UsbAsp-flash firmware
patch #9816: Implement new programmer type: linuxspi
patch #9811: ATmega328pb has efuse bit 3
patch #9744: Patch for ATMega324A support
patch #10000: Add support for extended UPDI device context
patch #9697: Add iseavrprog support
patch #10017: uspasp / tpi: Automatically clear configuration byte (fuse) before writing it
patch #8957: Allow reading prodsig memory from stk500v2 on xmega devices
patch #9110: Let reserved fuse bits to be read as *don't care*
patch #9253: Fix for giving terminal_mode commands more than 20 arguments
patch #9320: fix TPI RESET in bitbang.c
patch #9079: Fix ftdi_syncbb teardown (supersedes #9893, superseded by #9328)
patch #9122: Fixed MISO sampling in ftdi_syncbb
patch #9123: ftdi_syncbb: use FT245R_CYCLES in ft245r_set_bitclock()
patch #8719: Support Over-the-Air bootloading with XBeeBoot
patch #9757: Fix ATtiny817 Xplained Mini programmer
patch #9327: ft245r.c: add TPI support (patches 1-4)
patch #9328: ft245r.c: add TPI support (patches 5-7)
patch #10027: linuxspi: Add reset pulse, according to AVR programming algorithm
patch #10028: linuxspi: close() only when necessary
patch #10029: linuxspi: Report GPIO_GET_LINEHANDLE_IOCTL errors
patch #10030: linuxspi: Support inverted GPIO pin
patch #10031: linuxspi: Support GPIO uAPI v2
(no-id): Improve documentation of linuxspi driver, provide portname default
(no-id): Use -B <bitclock> rather than -b <baudrate> for linuxspi driver
patch #9304: [Bug #48767] Implemented WinSock variation of "ser_drain(...)" functionality
patch #8996: Remove lock byte read mask (bug#21954, bug#46759)
patch #8923: Enable TPI for linuxgpio
patch #10153: linuxspi: Support "-E reset" and "-E noreset"
* Internals:
- New avrdude.conf keyword "family_id", used to verify SIB attributes
@@ -668,7 +1239,7 @@ Version 4.3.0:
* Added "Troubleshooting"-Appendix to the manual.
* Add ATmega8515 support.
Contributed by: Matthias Wei<EFBFBD>er <matthias@matwei.de>
Contributed by: Matthias Weißer <matthias@matwei.de>
* Add ATmega64 support.
Contributed by: Erik Christiansen <erik@dd.nec.com.au>

64
README-old.md Normal file
View File

@@ -0,0 +1,64 @@
# AVRDUDE
[![Build Status](https://github.com/avrdudes/avrdude/actions/workflows/build.yml/badge.svg)](https://github.com/avrdudes/avrdude/actions/workflows/build.yml)
AVRDUDE - AVR Downloader Uploader - is a program for downloading and uploading
the on-chip memories of Microchips [AVR microcontrollers](https://en.wikipedia.org/wiki/AVR_microcontrollers).
It can program the Flash and EEPROM, and where supported by the programming
protocol, it can program fuse and lock bits.
AVRDUDE also supplies a direct instruction mode allowing one to issue any
programming instruction to the AVR chip regardless of whether AVRDUDE
implements that specific feature of a particular chip.
AVRDUDE was originally written in 2003 by Brian S. Dean. Since 2006, AVRDUDE has been maintained by Jörg Wunsch,
with the help of [various contributors](./AUTHORS).
The latest version of AVRDUDE is always available here:\
<https://github.com/avrdudes/avrdude>
## Documentation
Documentation for current and previous releases is [on Github Pages](https://avrdudes.github.io/avrdude/).
## Getting AVRDUDE for Windows
To get AVRDUDE for Windows, install the latest version from the [Releases](http://download.savannah.gnu.org/releases/avrdude/) page.
Alternatively, you may [build AVRDUDE](https://github.com/avrdudes/avrdude/wiki) yourself from source.
## Getting AVRDUDE for Linux
To install AVRDUDE for Linux, install the package `avrdude` by running the following commands:
```console
sudo apt-get install avrdude
```
Alternatively, you may [build AVRDUDE](https://github.com/avrdudes/avrdude/wiki) yourself from source.
## Getting AVRDUDE for MacOS
On MacOS, AVRDUDE can be installed through Mac Ports.
Alternatively, you may [build AVRDUDE](https://github.com/avrdudes/avrdude/wiki) yourself from source.
## Using AVRDUDE
AVRDUDE is a command-line application. Run the command `avrdude` without any arguments for a list of options.
A typical command to program your HEX file into your AVR microcontroller looks like this:
```console
avrdude -c <programmer> -p <part> -U flash:w:<file>:i
```
For instance, to program an **Arduino Uno** connected to the serial port **COM1** with a HEX file called `blink.hex`,
you would run the following command:
```console
avrdude -c arduino -P COM1 -b 115200 -p atmega328p -D -U flash:w:objs/blink.hex:i
```
There are many different programmers and options that may be required for the programming to succeed.
For more information, refer to the [AVRDUDE documentation](https://avrdudes.github.io/avrdude/).

View File

@@ -1,8 +1,8 @@
# AVRDUDE for Windows
[![Build Status](https://travis-ci.com/mariusgreuel/avrdude.svg?branch=windows)](https://travis-ci.com/mariusgreuel/avrdude)
[![Build Status](https://github.com/mariusgreuel/avrdude/actions/workflows/build.yml/badge.svg?branch=windows)](https://github.com/mariusgreuel/avrdude/actions/workflows/build.yml)
This is a fork of AVRDUDE 6.3 from <https://www.nongnu.org/avrdude/>.
This is a fork of AVRDUDE 7.0 from <https://github.com/avrdudes/avrdude>.
The purpose of this fork is to add better support for Windows to bring it on par with the Linux version of AVRDUDE.
@@ -19,7 +19,11 @@ Noteable changes include:
- [Support Visual Studio](#support-visual-studio)
- [Miscellaneous bug-fixes and patches](#miscellaneous-bug-fixes-and-patches)
The original AVRDUDE project homepage can be found here <https://savannah.nongnu.org/projects/avrdude>.
The original AVRDUDE project homepage can be found here <https://github.com/avrdudes/avrdude>.
## Documentation
Documentation for current and previous releases is [on Github Pages](https://avrdudes.github.io/avrdude/).
## Download
@@ -168,57 +172,27 @@ You can find the original users manual (does not contain AVRDUDE for Windows ext
## Build
### Building AVRDUDE for Windows
The build instructions have been moved here:\
<https://github.com/avrdudes/avrdude/wiki>
### Building AVRDUDE for Windows using MSVC
#### Windows Prerequisites
In order to build AVRDUDE on Windows, you need:
- Microsoft Visual Studio 2019 with 'Desktop development with C++' enabled
- Flex and Bison installed, for instance via [Chocolatey](https://chocolatey.org/)
- Microsoft Visual Studio 2019 with **Desktop development with C++** and **CMake** enabled
#### Windows Build Instructions
To build AVRDUDE on Windows, do the following:
- `git clone --branch windows https://github.com/mariusgreuel/avrdude`
- Open the solution `avrdude.sln` and build the project.
- Open the folder **avrdude** using the menu item **File->Open->Folder**
- Build the project using the menu item **Build->Build All**
Note: The folder `msvc\generated` includes pre-built files from the AVRDUDE configure and grammar generation.
### Building AVRDUDE for Linux
Note that the AVRDUDE for Linux version does not contain all extra Windows features. The features that have been added to the stock version of AVRDUDE include:
- Support Micronucleus bootloader
- Support Teensy HalfKay bootloader
#### Linux Prerequisites
In order to build AVRDUDE on Linux, you need to install the following packages:
```console
sudo apt install git make gcc automake libtool flex bison libelf-dev libusb-dev libftdi1-dev libhidapi-dev
```
#### Linux Build Instructions
To build AVRDUDE on Linux, run the following commands:
```console
git clone --branch windows https://github.com/mariusgreuel/avrdude
cd avrdude
./bootstrap
./configure
make
```
To install a local build of AVRDUDE on your system, run the following command:
```console
sudo make install
```
#### Linux udev rules
### Linux udev rules
If you intent to use either the Micronucleus or Teensy bootloader, you should edit the udev rules so that you can run AVRDUDE without root.
@@ -248,6 +222,3 @@ You should use an older driver package that does not contain this bug.
The most current version of libusb0.sys is 1.2.6.0, signed on 12/17/2012 by Travis Lee Robinson. If you are using an older version (check with Windows Device Manager), you may not be able to connect to your USB devices using the libusb0 driver.
## License
AVRDUDE is licensed under the GNU GPLv2.

92
build.sh Executable file
View File

@@ -0,0 +1,92 @@
#!/bin/sh
#
# Build script for Unix-like systems, using the CMake subsystem
#
# This script covers some common cases. It does *not* install any
# prerequisites though.
#
# For documentation of AVRDUDE's build system, please refer to the
# Wiki:
#
# https://github.com/avrdudes/avrdude/wiki
# Determine OS type
#
# So far, this script tries to handle three different Unix-like
# systems:
#
# Linux
# FreeBSD
# Darwin (aka. MacOS)
#
# On Linux, if the machine is ARM-based, LINUXSPI and LINUXGPIO are
# enabled.
# On MacOS, an attempt is made to find out whether Mac ports or brew
# are in place, and are assumed to have install the prerequisites.
ostype=$(uname | tr '[A-Z]' '[a-z]')
build_type=RelWithDebInfo
# build_type=Release # no debug info
# See CMakeLists.txt for all options
#
# Use this to enable (historical) parallel-port based programmers:
#extra_enable="-D HAVE_PARPORT=1"
extra_enable=""
build_flags=""
case "${ostype}" in
linux)
# try to find out whether this is an Embedded Linux
# platform (e.g. Raspberry Pi)
machine=$(uname -m)
if expr "${machine}" : '^\(arm\|aarch\)' >/dev/null
then
extra_enable="${extra_enable} -D HAVE_LINUXGPIO=1 -D HAVE_LINUXSPI=1"
fi
;;
darwin)
# determine whether we are running using Mac Ports
# if not, assume Mac Brew
if [ -f /opt/local/bin/port ]
then
build_flags="${build_flags} -D CMAKE_C_FLAGS=-I/opt/local/include -D CMAKE_EXE_LINKER_FLAGS=-L/opt/local/lib"
else
# Apple M1 (may be new version of homebrew also)
if [ -d /opt/homebrew ]
then
build_flags="${build_flags} -D CMAKE_C_FLAGS=-I/opt/homebrew/include -D CMAKE_EXE_LINKER_FLAGS=-L/opt/homebrew/Cellar"
else
build_flags="${build_flags} -D CMAKE_C_FLAGS=-I/usr/local/include -D CMAKE_EXE_LINKER_FLAGS=-L/usr/local/Cellar"
fi
fi
;;
netbsd)
build_flags="${build_flags} -D CMAKE_C_FLAGS=-I/usr/pkg/include -D CMAKE_EXE_LINKER_FLAGS=-R/usr/pkg/lib -D CMAKE_INSTALL_PREFIX:PATH=/usr/pkg"
;;
*bsd)
build_flags="${build_flags} -D CMAKE_C_FLAGS=-I/usr/local/include -D CMAKE_EXE_LINKER_FLAGS=-L/usr/local/lib"
;;
esac
cmake ${build_flags} ${extra_enable} -D CMAKE_BUILD_TYPE=${build_type} -B build_${ostype} ||\
{ echo "CMake failed."; exit 1; }
cmake --build build_${ostype} ||\
{ echo "Build failed."; exit 1; }
cat <<EOF
Build succeeded.
Run
sudo cmake --build build_${ostype} --target install
to install.
EOF

View File

@@ -1,481 +0,0 @@
GNU LIBRARY GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the library GPL. It is
numbered 2 because it goes with version 2 of the ordinary GPL.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Library General Public License, applies to some
specially designated Free Software Foundation software, and to any
other libraries whose authors decide to use it. You can use it for
your libraries, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if
you distribute copies of the library, or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link a program with the library, you must provide
complete object files to the recipients so that they can relink them
with the library, after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
Our method of protecting your rights has two steps: (1) copyright
the library, and (2) offer you this license which gives you legal
permission to copy, distribute and/or modify the library.
Also, for each distributor's protection, we want to make certain
that everyone understands that there is no warranty for this free
library. If the library is modified by someone else and passed on, we
want its recipients to know that what they have is not the original
version, so that any problems introduced by others will not reflect on
the original authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that companies distributing free
software will individually obtain patent licenses, thus in effect
transforming the program into proprietary software. To prevent this,
we have made it clear that any patent must be licensed for everyone's
free use or not licensed at all.
Most GNU software, including some libraries, is covered by the ordinary
GNU General Public License, which was designed for utility programs. This
license, the GNU Library General Public License, applies to certain
designated libraries. This license is quite different from the ordinary
one; be sure to read it in full, and don't assume that anything in it is
the same as in the ordinary license.
The reason we have a separate public license for some libraries is that
they blur the distinction we usually make between modifying or adding to a
program and simply using it. Linking a program with a library, without
changing the library, is in some sense simply using the library, and is
analogous to running a utility program or application program. However, in
a textual and legal sense, the linked executable is a combined work, a
derivative of the original library, and the ordinary General Public License
treats it as such.
Because of this blurred distinction, using the ordinary General
Public License for libraries did not effectively promote software
sharing, because most developers did not use the libraries. We
concluded that weaker conditions might promote sharing better.
However, unrestricted linking of non-free programs would deprive the
users of those programs of all benefit from the free status of the
libraries themselves. This Library General Public License is intended to
permit developers of non-free programs to use free libraries, while
preserving your freedom as a user of such programs to change the free
libraries that are incorporated in them. (We have not seen how to achieve
this as regards changes in header files, but we have achieved it as regards
changes in the actual functions of the Library.) The hope is that this
will lead to faster development of free libraries.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, while the latter only
works together with the library.
Note that it is possible for a library to be covered by the ordinary
General Public License rather than by this special one.
GNU LIBRARY GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library which
contains a notice placed by the copyright holder or other authorized
party saying it may be distributed under the terms of this Library
General Public License (also called "this License"). Each licensee is
addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also compile or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
c) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
d) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the source code distributed need not include anything that is normally
distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Library General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
<one line to give the library's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
<signature of Ty Coon>, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!

File diff suppressed because it is too large Load Diff

332
external/libelf/README vendored
View File

@@ -1,332 +0,0 @@
This is the public release of libelf-0.8.13, a free ELF object
file access library. If you have problems with applications
that use libelf and work with the commercial (SVR4, Solaris)
version but not with this one, please contact me.
IMPORTANT NOTE: If you have libelf-0.5.2 installed, you probably
have a file .../include/elf.h that contains the single line
``#include <libelf/elf.h>''. REMOVE THIS FILE BEFORE YOU RUN
configure.
Installation is straightforward - the package is autoconf'ed. Just do
``cd libelf-0.8.13; ./configure; make; make install''. Header files
will be installed in .../include/libelf/. If your system does not
provide its own versions of libelf.h, nlist.h or gelf.h, ``make
install'' will add the missing headers. If you prefer not to have
these files installed in /usr/include, use ``--disable-compat'' and
add ``-I /usr/include/libelf'' to your CFLAGS when compiling
libelf-based programs.
Note to distribution makers: You can install libelf in a separate root
hierarchy by using the command ``make instroot=/my/root install''.
You should also use the ``--enable-compat'' configure option in that
case, or run ``make instroot=/my/root install-compat'' manually, to
install all the required header files.
If you are running Linux with libc 5.* as the default C library,
and you plan to use the 64-bit functions, you must either use
``-I.../include/libelf'', or remove /usr/include/libelf.h and use
``--enable-compat'' when running configure. Libc 6.* (aka glibc2)
doesn't have its own <libelf.h>, <nlist.h> or <gelf.h>.
You need an ANSI/ISO C compiler to build libelf. Gcc is optimal.
On some systems (in particular, Solaris and all variants of Linux),
``make'' will try to build a shared library. If you run into problems
on your system, please pass ``--disable-shared'' to configure.
If you build a shared library and want it to be installed as
``libelf-0.8.13.so'' rather than ``libelf.so.0.8.13'', please use
``./configure --enable-gnu-names''. Other files, e.g. ``libelf.so'' and
``libelf.so.0'' are NOT affected.
Another configure option, ``--enable-debug'', adds debugging code to
libelf; if you don't run into problems, you will probably not need it.
When creating an ELF shared library, it is possible to add references
to other shared libraries in the DYNAMIC section of the resulting
file. The make variable DEPSHLIBS contains a list of libraries to add.
It is set to ``-lc'' on Linux systems, and empty otherwise. To
override this setting, use something like ``make DEPSHLIBS="-la -lb"''.
For Linux, `-lc' is included automagically.
NLS is available and enabled by default. To turn it off, pass the
``--disable-nls'' option to configure.
Libelf can use gettext or catgets for accessing message
catalogs. If gettext is available AND is part of libc (i.e. not
in a separate library), it will be used. Otherwise, configure
will look for catgets. If you have gettext in a separate
library and want to use it, you should pass the library's name
to configure, e.g. ``LIBS=-lintl ./configure''. Note that you
MUST link your libelf-based applications with -lintl then,
which is probably not what you want, or change the DEPSHLIBS variable
described above (in case you're building a shared library).
If you have GNU gettext 0.10 installed on your system, and if GNU gettext
runs on top of the catgets interface (rather old Linux systems, using
libc5), configure will refuse to use it and use catgets instead. If you
absolutely want to use GNU gettext, go ahead and rebuild it (which is
IMHO a good idea in general in this case):
cd .../gettext-0.10
ac_cv_func_catgets=no ac_cv_func_gettext=no ./configure
make
make install
After that, return to the libelf build directory, remove
config.cache, and start over.
*** Large File Support (LFS) applications ***
Some 32-bit systems support files that are larger than the address space
of the architecture. On these, the `off_t' data type may have 32 or
64 bits, depending on the API you choose. Since off_t is also part of
the libelf API, in particular the Elf_Data and Elf_Arhdr structures,
an application compiled with large file support will need a version of
libelf that has also been compiled with LFS; otherwise, it won't work
correctly. Similarly, a program compiled without LFS needs a library
compiled without LFS.
Note that libelf is currently unable to process large files on 32-bit
architectures, whether you compile it for LFS or not, for the simple
reason that the files won't fit into the processes' address space.
Therefore, libelf is compiled without LFS by default. It can of course
read and write ELF files for 64-bit architectures, but they will be
limited in length on a 32-bit system.
You may compile libelf with large file support by setting CPPFLAGS at
configuration time:
CPPFLAGS=`getconf LFS_CFLAGS` ./configure
But I really, really recommend you don't, because it breaks binary
compatibility with existing libelf based applications.
*** 64-bit support ***
Starting with libelf-0.7.0, libelf also supports 64-bit ELF files.
This is enabled by default unless your system (or your compiler) does
not support 64-bit integers, or lacks 64-bit declarations in <elf.h>.
If you have problems building with 64-bit support, please do
./configure --disable-elf64
for the moment, and contact me. Please note that I haven't tested 64-bit
support much. There are still some unresolved problems, e.g. IRIX
uses different Elf64_Rel and Elf64_Rela structures (they replaced the
r_info member), and the enumeration values for Elf_Type differ from
the commercial (SVR4) implementation of libelf - they broke binary
compatibility for no good reason, and I'm not willing to follow their
footsteps. The result is that libelf-0.7.* ist upward compatible with
libelf-0.6.4 (as it should be) but INCOMPATIBLE WITH SVR4 LIBELF. If you
have both versions installed, you'd better make sure that you link with
the library that matches the <libelf.h> you're #include'ing.
*** Symbol Versioning ***
Libelf >= 0.8.0 supports the data structures and definitions used for
symbol versioning on Solaris and Linux, in particular, the Elfxx_Verdef,
Elfxx_Verdaux, Elfxx_Verneed, Elfxx_Vernaux and Elfxx_Versym structures
and the SHT_XXX_verdef, SHT_XXX_verneed and SHT_XXX_versym section types
(where `xx' is either `32' or `64', and `XXX' is either `SUNW' or `GNU').
Libelf now translates versioning sections to/from their external
representation properly (earlier versions left them in `raw' format,
with the data type set to ELF_T_BYTE). This may cause problems on
systems which use the same (OS-specific) section types for different
purposes. The configure program tries to figure out if your OS uses
versioning; if that check fails, you can use
./configure --disable-versioning
to turn off versioning translation support.
*** W32 Support ***
There is now some support for building on W32 systems (requires Microsoft
VC++). In order to build a W32 DLL, cd into the `lib' subdirectory, edit
build.bat if necessary (it needs the path to your compiler binaries) and
run it. If you're lucky, libelf.dll and the import/export libraries will
be built. If not, please drop me a line.
I tested it on XP Pro (SP2), using VC++ 2005 Express Edition.
Apparently, Visual Studio .NET 2003 works fine as well.
Various notes regarding the W32 port:
- When you open() an ELF file, remember to use the O_BINARY flag.
- You may have to add /MD to the linker command line.
*** Missing things ***
* There is no documentation. You can use the Solaris
manpages instead (available at http://docs.sun.com/).
The ELF file format is described in several places;
among them Suns "Linker and Libraries Guide" and the
"System V Application Binary Interface" documents;
http://www.caldera.com/developer/devspecs/gabi41.pdf and
http://www.caldera.com/developer/gabi/ are probably good
starting points. Processor-specific documentation is spread
across a number of `Processor Supplement' documents, one
for each architecture; you'll have to use a search engine to
find them.
* The COFF file format is not understood. This is so obsolete
that it will probably never be implemented.
* nlist(3) is incomplete; the n_type and n_sclass
members of struct nl are set to zero even if type
(that is, debug) information is available.
* Libelf does not translate Solaris' `Move' and `Syminfo'
sections. You can read them using elf_getdata(), but you'll
only get raw (untranslated) bytes.
Changes since 0.8.12:
* New function elf_getaroff().
* Build fixes.
Changes since 0.8.11:
* Due to some unfortunate confusion, the elf_getphnum(),
elf_getshnum() and elf_getshstrndx() are not compatible
between libelf implementations. Therefore, the developers
decided to replace them with new functions: elf_getphdrnum(),
elf_getshdrnum() and elf_getshdrstrndx(), which will always
return -1 on failure and 0 on success. Code using the old
interface should be upgraded to increase portability.
Changes since 0.8.10:
* Fixed a bug in elf_rawfile().
* If you use ELF_F_LAYOUT together with ELF_F_LAYOUT_OVERLAP,
elf_update() will now tolerate overlapping sections.
Changes since 0.8.9:
* Ported to QNX Neutrino.
* Fixed Windows build errors.
* Parallel (make -j) installation should work now.
* It's now possible to enable and disable select sanity checks
libelf performs. Currently, this affects the "NUL terminated
string table entry" check performed in elf_strptr(). By
default, the function will return an error if the string
requested is not properly terminated - because some
applications might dump core otherwise. If you configure
libelf with `--disable-sanity-checks', however, the check
(and, in the future, probably others as well) is disabled
by default. You can still turn it on and off at runtime by
setting the LIBELF_SANITY_CHECKS environment variable to
an integer value:
# disable all sanity checks
export LIBELF_SANITY_CHECKS=0
# enable all sanity checks
export LIBELF_SANITY_CHECKS=-1
Each bit of the value corresponds to a particular check,
so you could use LIBELF_SANITY_CHECKS=1 to enable only
the elf_strptr() check. You may also use a value in hex
(0x...) or octal (0...) format.
Changes since 0.8.8:
* Improved translator for symbol versioning sections.
* The W32 library is now built in the `lib' subdirectory.
* Windows DLLs should work now.
Changes since 0.8.6:
* added elf_getphnum().
* added elf_getshnum().
* added elf_getshstrndx().
* added elfx_update_shstrndx().
* handle interrupted reads/writes more gracefully.
* added (partial) support for unusual e_[ps]hentsize values.
* fixed the bugs introduced in 0.8.7.
Changes since 0.8.5:
* added W32 support.
* added workaround for alignment errors in archive members.
* my email address has changed again ;)
Changes since 0.8.4:
* elf_strptr() should now work more safely with fragmented
or badly formatted string tables.
Changes since 0.8.3:
* Fixed a bug in elf_update() that was introduced in 0.8.3.
Changes since 0.8.2:
* Should compile on MacOSX now.
* Can read and write files with more than 65280 sections
* Tries to handle 64-bit ELF files that use 8-byte hash table
entries. In particular, libelf tries to guess the data type in
elf_getdata(), and doesn't override sh_entsize in elf_update()
any longer. If you want the library to pick the entry size,
you must set its value to 0 before you call elf_update().
* No longer dumps core in elf_update() when a versioning section
has no data. Instead, it returns an error message. Note that
you're supposed to provide a valid d_buf for any section, unless
it's empty or has SHT_NOBITS type.
* Building a shared library is now the default (if supported).
Changes since 0.8.0:
* Corrected typo in lib/{32,64}.xlatetof.c that sometimes
caused a compilation failure.
* Use open(name, O_RDONLY|O_BINARY) in lib/nlist.c.
Changes since 0.7.0:
* I implemented the gelf_* interface, as found on Solaris.
I don't know whether it's compatible -- the Solaris manpage
isn't very specific, so I had to guess return values etc. in
some cases.
* Added elf{32,64}_checksum (supposed to be compatible with
Solaris).
* Added symbol versioning support.
Changes since 0.6.4:
* Fixed configure for IRIX systems
* Added check for truncated archive members
* Added check for misaligned SHDR/PHDR tables
* Support for building libelf together with GNU libc
* Added elf_memory(3)
* Added 64-bit support
Changes since 0.5.2:
* some bug fixes
* mmap support
* new directory layout
* There is a new function, elf_delscn(), that deletes
a section from an ELF file. It also adjusts the
sh_link and sh_info members in the section header
table, if (and ONLY if) the ELF standard indicates
that these values are section indices. References
to the deleted section will be cleared, so be careful.
* my email address has changed ;)
Where to get libelf:
ftp://ftp.ibiblio.org/pub/Linux/libs/
http://www.mr511.de/software/
Michael "Tired" Riepe
<libelf@mr511.de>

View File

@@ -1 +0,0 @@
0.8.13

View File

@@ -1,305 +0,0 @@
/*
* libelf.h - public header file for libelf.
* Copyright (C) 1995 - 2008 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* @(#) $Id: libelf.h,v 1.29 2009/07/07 17:57:43 michael Exp $ */
#ifndef _LIBELF_H
#define _LIBELF_H
#include <stddef.h> /* for size_t */
#include <sys/types.h>
#if __LIBELF_INTERNAL__
#include <sys_elf.h>
#else /* __LIBELF_INTERNAL__ */
#include <libelf/sys_elf.h>
#endif /* __LIBELF_INTERNAL__ */
#if defined __GNUC__ && !defined __cplusplus
#define DEPRECATED __attribute__((deprecated))
#else
#define DEPRECATED /* nothing */
#endif
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#ifndef __P
# if (__STDC__ + 0) || defined(__cplusplus) || defined(_WIN32)
# define __P(args) args
# else /* __STDC__ || defined(__cplusplus) */
# define __P(args) ()
# endif /* __STDC__ || defined(__cplusplus) */
#endif /* __P */
/*
* Commands
*/
typedef enum {
ELF_C_NULL = 0, /* must be first, 0 */
ELF_C_READ,
ELF_C_WRITE,
ELF_C_CLR,
ELF_C_SET,
ELF_C_FDDONE,
ELF_C_FDREAD,
ELF_C_RDWR,
ELF_C_NUM /* must be last */
} Elf_Cmd;
/*
* Flags
*/
#define ELF_F_DIRTY 0x1
#define ELF_F_LAYOUT 0x4
/*
* Allow sections to overlap when ELF_F_LAYOUT is in effect.
* Note that this flag ist NOT portable, and that it may render
* the output file unusable. Use with extreme caution!
*/
#define ELF_F_LAYOUT_OVERLAP 0x10000000
/*
* File types
*/
typedef enum {
ELF_K_NONE = 0, /* must be first, 0 */
ELF_K_AR,
ELF_K_COFF,
ELF_K_ELF,
ELF_K_NUM /* must be last */
} Elf_Kind;
/*
* Data types
*/
typedef enum {
ELF_T_BYTE = 0, /* must be first, 0 */
ELF_T_ADDR,
ELF_T_DYN,
ELF_T_EHDR,
ELF_T_HALF,
ELF_T_OFF,
ELF_T_PHDR,
ELF_T_RELA,
ELF_T_REL,
ELF_T_SHDR,
ELF_T_SWORD,
ELF_T_SYM,
ELF_T_WORD,
/*
* New stuff for 64-bit.
*
* Most implementations add ELF_T_SXWORD after ELF_T_SWORD
* which breaks binary compatibility with earlier versions.
* If this causes problems for you, contact me.
*/
ELF_T_SXWORD,
ELF_T_XWORD,
/*
* Symbol versioning. Sun broke binary compatibility (again!),
* but I won't.
*/
ELF_T_VDEF,
ELF_T_VNEED,
ELF_T_NUM /* must be last */
} Elf_Type;
/*
* Elf descriptor
*/
typedef struct Elf Elf;
/*
* Section descriptor
*/
typedef struct Elf_Scn Elf_Scn;
/*
* Archive member header
*/
typedef struct {
char* ar_name;
time_t ar_date;
long ar_uid;
long ar_gid;
unsigned long ar_mode;
off_t ar_size;
char* ar_rawname;
} Elf_Arhdr;
/*
* Archive symbol table
*/
typedef struct {
char* as_name;
size_t as_off;
unsigned long as_hash;
} Elf_Arsym;
/*
* Data descriptor
*/
typedef struct {
void* d_buf;
Elf_Type d_type;
size_t d_size;
off_t d_off;
size_t d_align;
unsigned d_version;
} Elf_Data;
/*
* Function declarations
*/
extern Elf *elf_begin __P((int __fd, Elf_Cmd __cmd, Elf *__ref));
extern Elf *elf_memory __P((char *__image, size_t __size));
extern int elf_cntl __P((Elf *__elf, Elf_Cmd __cmd));
extern int elf_end __P((Elf *__elf));
extern const char *elf_errmsg __P((int __err));
extern int elf_errno __P((void));
extern void elf_fill __P((int __fill));
extern unsigned elf_flagdata __P((Elf_Data *__data, Elf_Cmd __cmd,
unsigned __flags));
extern unsigned elf_flagehdr __P((Elf *__elf, Elf_Cmd __cmd,
unsigned __flags));
extern unsigned elf_flagelf __P((Elf *__elf, Elf_Cmd __cmd,
unsigned __flags));
extern unsigned elf_flagphdr __P((Elf *__elf, Elf_Cmd __cmd,
unsigned __flags));
extern unsigned elf_flagscn __P((Elf_Scn *__scn, Elf_Cmd __cmd,
unsigned __flags));
extern unsigned elf_flagshdr __P((Elf_Scn *__scn, Elf_Cmd __cmd,
unsigned __flags));
extern size_t elf32_fsize __P((Elf_Type __type, size_t __count,
unsigned __ver));
extern Elf_Arhdr *elf_getarhdr __P((Elf *__elf));
extern Elf_Arsym *elf_getarsym __P((Elf *__elf, size_t *__ptr));
extern off_t elf_getbase __P((Elf *__elf));
extern Elf_Data *elf_getdata __P((Elf_Scn *__scn, Elf_Data *__data));
extern Elf32_Ehdr *elf32_getehdr __P((Elf *__elf));
extern char *elf_getident __P((Elf *__elf, size_t *__ptr));
extern Elf32_Phdr *elf32_getphdr __P((Elf *__elf));
extern Elf_Scn *elf_getscn __P((Elf *__elf, size_t __index));
extern Elf32_Shdr *elf32_getshdr __P((Elf_Scn *__scn));
extern unsigned long elf_hash __P((const unsigned char *__name));
extern Elf_Kind elf_kind __P((Elf *__elf));
extern size_t elf_ndxscn __P((Elf_Scn *__scn));
extern Elf_Data *elf_newdata __P((Elf_Scn *__scn));
extern Elf32_Ehdr *elf32_newehdr __P((Elf *__elf));
extern Elf32_Phdr *elf32_newphdr __P((Elf *__elf, size_t __count));
extern Elf_Scn *elf_newscn __P((Elf *__elf));
extern Elf_Cmd elf_next __P((Elf *__elf));
extern Elf_Scn *elf_nextscn __P((Elf *__elf, Elf_Scn *__scn));
extern size_t elf_rand __P((Elf *__elf, size_t __offset));
extern Elf_Data *elf_rawdata __P((Elf_Scn *__scn, Elf_Data *__data));
extern char *elf_rawfile __P((Elf *__elf, size_t *__ptr));
extern char *elf_strptr __P((Elf *__elf, size_t __section, size_t __offset));
extern off_t elf_update __P((Elf *__elf, Elf_Cmd __cmd));
extern unsigned elf_version __P((unsigned __ver));
extern Elf_Data *elf32_xlatetof __P((Elf_Data *__dst, const Elf_Data *__src,
unsigned __encode));
extern Elf_Data *elf32_xlatetom __P((Elf_Data *__dst, const Elf_Data *__src,
unsigned __encode));
/*
* Additional functions found on Solaris
*/
extern long elf32_checksum __P((Elf *__elf));
#if __LIBELF64
/*
* 64-bit ELF functions
* Not available on all platforms
*/
extern Elf64_Ehdr *elf64_getehdr __P((Elf *__elf));
extern Elf64_Ehdr *elf64_newehdr __P((Elf *__elf));
extern Elf64_Phdr *elf64_getphdr __P((Elf *__elf));
extern Elf64_Phdr *elf64_newphdr __P((Elf *__elf, size_t __count));
extern Elf64_Shdr *elf64_getshdr __P((Elf_Scn *__scn));
extern size_t elf64_fsize __P((Elf_Type __type, size_t __count,
unsigned __ver));
extern Elf_Data *elf64_xlatetof __P((Elf_Data *__dst, const Elf_Data *__src,
unsigned __encode));
extern Elf_Data *elf64_xlatetom __P((Elf_Data *__dst, const Elf_Data *__src,
unsigned __encode));
/*
* Additional functions found on Solaris
*/
extern long elf64_checksum __P((Elf *__elf));
#endif /* __LIBELF64 */
/*
* ELF format extensions
*
* These functions return 0 on failure, 1 on success. Since other
* implementations of libelf may behave differently (there was quite
* some confusion about the correct values), they are now officially
* deprecated and should be replaced with the three new functions below.
*/
DEPRECATED extern int elf_getphnum __P((Elf *__elf, size_t *__resultp));
DEPRECATED extern int elf_getshnum __P((Elf *__elf, size_t *__resultp));
DEPRECATED extern int elf_getshstrndx __P((Elf *__elf, size_t *__resultp));
/*
* Replacement functions (return -1 on failure, 0 on success).
*/
extern int elf_getphdrnum __P((Elf *__elf, size_t *__resultp));
extern int elf_getshdrnum __P((Elf *__elf, size_t *__resultp));
extern int elf_getshdrstrndx __P((Elf *__elf, size_t *__resultp));
/*
* Convenience functions
*
* elfx_update_shstrndx is elf_getshstrndx's counterpart.
* It should be used to set the e_shstrndx member.
* There is no update function for e_shnum or e_phnum
* because libelf handles them internally.
*/
extern int elfx_update_shstrndx __P((Elf *__elf, size_t __index));
/*
* Experimental extensions:
*
* elfx_movscn() moves section `__scn' directly after section `__after'.
* elfx_remscn() removes section `__scn'. Both functions update
* the section indices; elfx_remscn() also adjusts the ELF header's
* e_shnum member. The application is responsible for updating other
* data (in particular, e_shstrndx and the section headers' sh_link and
* sh_info members).
*
* elfx_movscn() returns the new index of the moved section.
* elfx_remscn() returns the original index of the removed section.
* A return value of zero indicates an error.
*/
extern size_t elfx_movscn __P((Elf *__elf, Elf_Scn *__scn, Elf_Scn *__after));
extern size_t elfx_remscn __P((Elf *__elf, Elf_Scn *__scn));
/*
* elf_delscn() is obsolete. Please use elfx_remscn() instead.
*/
extern size_t elf_delscn __P((Elf *__elf, Elf_Scn *__scn));
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _LIBELF_H */

View File

@@ -1,996 +0,0 @@
/*
* elf_repl.h - public header file for systems that lack it.
* Copyright (C) 1995 - 2006 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* @(#) $Id: elf_repl.h,v 1.22 2009/11/01 13:04:19 michael Exp $ */
/*
* NEVER INCLUDE THIS FILE DIRECTLY - USE <libelf.h> INSTEAD!
*/
#ifndef _ELF_REPL_H
#define _ELF_REPL_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/*
* Scalar data types
*/
typedef __libelf_u32_t Elf32_Addr;
typedef __libelf_u16_t Elf32_Half;
typedef __libelf_u32_t Elf32_Off;
typedef __libelf_i32_t Elf32_Sword;
typedef __libelf_u32_t Elf32_Word;
#define ELF32_FSZ_ADDR 4
#define ELF32_FSZ_HALF 2
#define ELF32_FSZ_OFF 4
#define ELF32_FSZ_SWORD 4
#define ELF32_FSZ_WORD 4
#if __LIBELF64
typedef __libelf_u64_t Elf64_Addr;
typedef __libelf_u16_t Elf64_Half;
typedef __libelf_u64_t Elf64_Off;
typedef __libelf_i32_t Elf64_Sword;
typedef __libelf_u32_t Elf64_Word;
typedef __libelf_i64_t Elf64_Sxword;
typedef __libelf_u64_t Elf64_Xword;
#define ELF64_FSZ_ADDR 8
#define ELF64_FSZ_HALF 2
#define ELF64_FSZ_OFF 8
#define ELF64_FSZ_SWORD 4
#define ELF64_FSZ_WORD 4
#define ELF64_FSZ_SXWORD 8
#define ELF64_FSZ_XWORD 8
/*
* Blame Sun for this...
*/
typedef __libelf_u64_t Elf64_Lword;
typedef __libelf_u64_t Elf32_Lword;
#endif /* __LIBELF64 */
/*
* ELF header
*/
#define EI_NIDENT 16
typedef struct {
unsigned char e_ident[EI_NIDENT];
Elf32_Half e_type;
Elf32_Half e_machine;
Elf32_Word e_version;
Elf32_Addr e_entry;
Elf32_Off e_phoff;
Elf32_Off e_shoff;
Elf32_Word e_flags;
Elf32_Half e_ehsize;
Elf32_Half e_phentsize;
Elf32_Half e_phnum;
Elf32_Half e_shentsize;
Elf32_Half e_shnum;
Elf32_Half e_shstrndx;
} Elf32_Ehdr;
#if __LIBELF64
typedef struct {
unsigned char e_ident[EI_NIDENT];
Elf64_Half e_type;
Elf64_Half e_machine;
Elf64_Word e_version;
Elf64_Addr e_entry;
Elf64_Off e_phoff;
Elf64_Off e_shoff;
Elf64_Word e_flags;
Elf64_Half e_ehsize;
Elf64_Half e_phentsize;
Elf64_Half e_phnum;
Elf64_Half e_shentsize;
Elf64_Half e_shnum;
Elf64_Half e_shstrndx;
} Elf64_Ehdr;
#endif /* __LIBELF64 */
/*
* e_ident
*/
#define EI_MAG0 0
#define EI_MAG1 1
#define EI_MAG2 2
#define EI_MAG3 3
#define EI_CLASS 4
#define EI_DATA 5
#define EI_VERSION 6
#define EI_OSABI 7
#define EI_ABIVERSION 8
#define EI_PAD 9
#define ELFMAG0 0x7f
#define ELFMAG1 'E'
#define ELFMAG2 'L'
#define ELFMAG3 'F'
#define ELFMAG "\177ELF"
#define SELFMAG 4
/*
* e_ident[EI_CLASS]
*/
#define ELFCLASSNONE 0
#define ELFCLASS32 1
#define ELFCLASS64 2
#define ELFCLASSNUM 3
/*
* e_ident[EI_DATA]
*/
#define ELFDATANONE 0
#define ELFDATA2LSB 1
#define ELFDATA2MSB 2
#define ELFDATANUM 3
/*
* e_ident[EI_OSABI]
*/
#define ELFOSABI_NONE 0 /* No extensions or unspecified */
#define ELFOSABI_SYSV ELFOSABI_NONE
#define ELFOSABI_HPUX 1 /* Hewlett-Packard HP-UX */
#define ELFOSABI_NETBSD 2 /* NetBSD */
#define ELFOSABI_LINUX 3 /* Linux */
#define ELFOSABI_SOLARIS 6 /* Sun Solaris */
#define ELFOSABI_AIX 7 /* AIX */
#define ELFOSABI_IRIX 8 /* IRIX */
#define ELFOSABI_FREEBSD 9 /* FreeBSD */
#define ELFOSABI_TRU64 10 /* Compaq TRU64 UNIX */
#define ELFOSABI_MODESTO 11 /* Novell Modesto */
#define ELFOSABI_OPENBSD 12 /* Open BSD */
#define ELFOSABI_OPENVMS 13 /* Open VMS */
#define ELFOSABI_NSK 14 /* Hewlett-Packard Non-Stop Kernel */
#define ELFOSABI_AROS 15 /* Amiga Research OS */
/* these are probably obsolete: */
#define ELFOSABI_ARM 97 /* ARM */
#define ELFOSABI_STANDALONE 255 /* standalone (embedded) application */
/*
* e_type
*/
#define ET_NONE 0
#define ET_REL 1
#define ET_EXEC 2
#define ET_DYN 3
#define ET_CORE 4
#define ET_NUM 5
#define ET_LOOS 0xfe00
#define ET_HIOS 0xfeff
#define ET_LOPROC 0xff00
#define ET_HIPROC 0xffff
/*
* e_machine
*/
#define EM_NONE 0 /* No machine */
#define EM_M32 1 /* AT&T WE 32100 */
#define EM_SPARC 2 /* SPARC */
#define EM_386 3 /* Intel 80386 */
#define EM_68K 4 /* Motorola 68000 */
#define EM_88K 5 /* Motorola 88000 */
#define EM_486 6 /* Intel i486 (DO NOT USE THIS ONE) */
#define EM_860 7 /* Intel 80860 */
#define EM_MIPS 8 /* MIPS I Architecture */
#define EM_S370 9 /* IBM System/370 Processor */
#define EM_MIPS_RS3_LE 10 /* MIPS RS3000 Little-endian */
#define EM_SPARC64 11 /* SPARC 64-bit */
#define EM_PARISC 15 /* Hewlett-Packard PA-RISC */
#define EM_VPP500 17 /* Fujitsu VPP500 */
#define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */
#define EM_960 19 /* Intel 80960 */
#define EM_PPC 20 /* PowerPC */
#define EM_PPC64 21 /* 64-bit PowerPC */
#define EM_S390 22 /* IBM System/390 Processor */
#define EM_V800 36 /* NEC V800 */
#define EM_FR20 37 /* Fujitsu FR20 */
#define EM_RH32 38 /* TRW RH-32 */
#define EM_RCE 39 /* Motorola RCE */
#define EM_ARM 40 /* Advanced RISC Machines ARM */
#define EM_ALPHA 41 /* Digital Alpha */
#define EM_SH 42 /* Hitachi SH */
#define EM_SPARCV9 43 /* SPARC Version 9 */
#define EM_TRICORE 44 /* Siemens TriCore embedded processor */
#define EM_ARC 45 /* Argonaut RISC Core, Argonaut Technologies Inc. */
#define EM_H8_300 46 /* Hitachi H8/300 */
#define EM_H8_300H 47 /* Hitachi H8/300H */
#define EM_H8S 48 /* Hitachi H8S */
#define EM_H8_500 49 /* Hitachi H8/500 */
#define EM_IA_64 50 /* Intel IA-64 processor architecture */
#define EM_MIPS_X 51 /* Stanford MIPS-X */
#define EM_COLDFIRE 52 /* Motorola ColdFire */
#define EM_68HC12 53 /* Motorola M68HC12 */
#define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator */
#define EM_PCP 55 /* Siemens PCP */
#define EM_NCPU 56 /* Sony nCPU embedded RISC processor */
#define EM_NDR1 57 /* Denso NDR1 microprocessor */
#define EM_STARCORE 58 /* Motorola Star*Core processor */
#define EM_ME16 59 /* Toyota ME16 processor */
#define EM_ST100 60 /* STMicroelectronics ST100 processor */
#define EM_TINYJ 61 /* Advanced Logic Corp. TinyJ embedded processor family */
#define EM_X86_64 62 /* AMD x86-64 architecture */
#define EM_AMD64 EM_X86_64
#define EM_PDSP 63 /* Sony DSP Processor */
#define EM_FX66 66 /* Siemens FX66 microcontroller */
#define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 bit microcontroller */
#define EM_ST7 68 /* STMicroelectronics ST7 8-bit microcontroller */
#define EM_68HC16 69 /* Motorola MC68HC16 Microcontroller */
#define EM_68HC11 70 /* Motorola MC68HC11 Microcontroller */
#define EM_68HC08 71 /* Motorola MC68HC08 Microcontroller */
#define EM_68HC05 72 /* Motorola MC68HC05 Microcontroller */
#define EM_SVX 73 /* Silicon Graphics SVx */
#define EM_ST19 74 /* STMicroelectronics ST19 8-bit microcontroller */
#define EM_VAX 75 /* Digital VAX */
#define EM_CRIS 76 /* Axis Communications 32-bit embedded processor */
#define EM_JAVELIN 77 /* Infineon Technologies 32-bit embedded processor */
#define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor */
#define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor */
#define EM_MMIX 80 /* Donald Knuth's educational 64-bit processor */
#define EM_HUANY 81 /* Harvard University machine-independent object files */
#define EM_PRISM 82 /* SiTera Prism */
#define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */
#define EM_FR30 84 /* Fujitsu FR30 */
#define EM_D10V 85 /* Mitsubishi D10V */
#define EM_D30V 86 /* Mitsubishi D30V */
#define EM_V850 87 /* NEC v850 */
#define EM_M32R 88 /* Mitsubishi M32R */
#define EM_MN10300 89 /* Matsushita MN10300 */
#define EM_MN10200 90 /* Matsushita MN10200 */
#define EM_PJ 91 /* picoJava */
#define EM_OPENRISC 92 /* OpenRISC 32-bit embedded processor */
#define EM_ARC_A5 93 /* ARC Cores Tangent-A5 */
#define EM_XTENSA 94 /* Tensilica Xtensa Architecture */
#define EM_VIDEOCORE 95 /* Alphamosaic VideoCore processor */
#define EM_TMM_GPP 96 /* Thompson Multimedia General Purpose Processor */
#define EM_NS32K 97 /* National Semiconductor 32000 series */
#define EM_TPC 98 /* Tenor Network TPC processor */
#define EM_SNP1K 99 /* Trebia SNP 1000 processor */
#define EM_ST200 100 /* STMicroelectronics (www.st.com) ST200 microcontroller */
#define EM_IP2K 101 /* Ubicom IP2xxx microcontroller family */
#define EM_MAX 102 /* MAX Processor */
#define EM_CR 103 /* National Semiconductor CompactRISC microprocessor */
#define EM_F2MC16 104 /* Fujitsu F2MC16 */
#define EM_MSP430 105 /* Texas Instruments embedded microcontroller msp430 */
#define EM_BLACKFIN 106 /* Analog Devices Blackfin (DSP) processor */
#define EM_SE_C33 107 /* S1C33 Family of Seiko Epson processors */
#define EM_SEP 108 /* Sharp embedded microprocessor */
#define EM_ARCA 109 /* Arca RISC Microprocessor */
#define EM_UNICORE 110 /* Microprocessor series from PKU-Unity Ltd. and MPRC of Peking University */
#define EM_NUM 111
/*
* e_ident[EI_VERSION], e_version
*/
#define EV_NONE 0
#define EV_CURRENT 1
#define EV_NUM 2
/*
* Section header
*/
typedef struct {
Elf32_Word sh_name;
Elf32_Word sh_type;
Elf32_Word sh_flags;
Elf32_Addr sh_addr;
Elf32_Off sh_offset;
Elf32_Word sh_size;
Elf32_Word sh_link;
Elf32_Word sh_info;
Elf32_Word sh_addralign;
Elf32_Word sh_entsize;
} Elf32_Shdr;
#if __LIBELF64
typedef struct {
Elf64_Word sh_name;
Elf64_Word sh_type;
Elf64_Xword sh_flags;
Elf64_Addr sh_addr;
Elf64_Off sh_offset;
Elf64_Xword sh_size;
Elf64_Word sh_link;
Elf64_Word sh_info;
Elf64_Xword sh_addralign;
Elf64_Xword sh_entsize;
} Elf64_Shdr;
#endif /* __LIBELF64 */
/*
* Special section indices
*/
#define SHN_UNDEF 0
#define SHN_LORESERVE 0xff00
#define SHN_LOPROC 0xff00
#define SHN_HIPROC 0xff1f
#define SHN_LOOS 0xff20
#define SHN_HIOS 0xff3f
#define SHN_ABS 0xfff1
#define SHN_COMMON 0xfff2
#define SHN_XINDEX 0xffff
#define SHN_HIRESERVE 0xffff
/*
* sh_type
*/
#define SHT_NULL 0
#define SHT_PROGBITS 1
#define SHT_SYMTAB 2
#define SHT_STRTAB 3
#define SHT_RELA 4
#define SHT_HASH 5
#define SHT_DYNAMIC 6
#define SHT_NOTE 7
#define SHT_NOBITS 8
#define SHT_REL 9
#define SHT_SHLIB 10
#define SHT_DYNSYM 11
#define SHT_INIT_ARRAY 14
#define SHT_FINI_ARRAY 15
#define SHT_PREINIT_ARRAY 16
#define SHT_GROUP 17
#define SHT_SYMTAB_SHNDX 18
#define SHT_NUM 19
#define SHT_LOOS 0x60000000
#define SHT_HIOS 0x6fffffff
#define SHT_LOPROC 0x70000000
#define SHT_HIPROC 0x7fffffff
#define SHT_LOUSER 0x80000000
#define SHT_HIUSER 0xffffffff
/*
* Solaris extensions
*/
#define SHT_LOSUNW 0x6ffffff4
#define SHT_SUNW_dof 0x6ffffff4
#define SHT_SUNW_cap 0x6ffffff5
#define SHT_SUNW_SIGNATURE 0x6ffffff6
#define SHT_SUNW_ANNOTATE 0x6ffffff7
#define SHT_SUNW_DEBUGSTR 0x6ffffff8
#define SHT_SUNW_DEBUG 0x6ffffff9
#define SHT_SUNW_move 0x6ffffffa
#define SHT_SUNW_COMDAT 0x6ffffffb
#define SHT_SUNW_syminfo 0x6ffffffc
#define SHT_SUNW_verdef 0x6ffffffd
#define SHT_SUNW_verneed 0x6ffffffe
#define SHT_SUNW_versym 0x6fffffff
#define SHT_HISUNW 0x6fffffff
#define SHT_SPARC_GOTDATA 0x70000000
#define SHT_AMD64_UNWIND 0x70000001
/*
* GNU extensions
*/
#define SHT_GNU_verdef 0x6ffffffd
#define SHT_GNU_verneed 0x6ffffffe
#define SHT_GNU_versym 0x6fffffff
/*
* sh_flags
*/
#define SHF_WRITE 0x1
#define SHF_ALLOC 0x2
#define SHF_EXECINSTR 0x4
#define SHF_MERGE 0x10
#define SHF_STRINGS 0x20
#define SHF_INFO_LINK 0x40
#define SHF_LINK_ORDER 0x80
#define SHF_OS_NONCONFORMING 0x100
#define SHF_GROUP 0x200
#define SHF_TLS 0x400
#define SHF_MASKOS 0x0ff00000
#define SHF_MASKPROC 0xf0000000
/*
* Solaris extensions
*/
#define SHF_AMD64_LARGE 0x10000000
#define SHF_ORDERED 0x40000000
#define SHF_EXCLUDE 0x80000000
/*
* Section group flags
*/
#define GRP_COMDAT 0x1
#define GRP_MASKOS 0x0ff00000
#define GRP_MASKPROC 0xf0000000
/*
* Symbol table
*/
typedef struct {
Elf32_Word st_name;
Elf32_Addr st_value;
Elf32_Word st_size;
unsigned char st_info;
unsigned char st_other;
Elf32_Half st_shndx;
} Elf32_Sym;
#if __LIBELF64
typedef struct {
Elf64_Word st_name;
unsigned char st_info;
unsigned char st_other;
Elf64_Half st_shndx;
Elf64_Addr st_value;
Elf64_Xword st_size;
} Elf64_Sym;
#endif /* __LIBELF64 */
/*
* Special symbol indices
*/
#define STN_UNDEF 0
/*
* Macros for manipulating st_info
*/
#define ELF32_ST_BIND(i) ((i)>>4)
#define ELF32_ST_TYPE(i) ((i)&0xf)
#define ELF32_ST_INFO(b,t) (((b)<<4)+((t)&0xf))
#if __LIBELF64
#define ELF64_ST_BIND(i) ((i)>>4)
#define ELF64_ST_TYPE(i) ((i)&0xf)
#define ELF64_ST_INFO(b,t) (((b)<<4)+((t)&0xf))
#endif /* __LIBELF64 */
/*
* Symbol binding
*/
#define STB_LOCAL 0
#define STB_GLOBAL 1
#define STB_WEAK 2
#define STB_NUM 3
#define STB_LOOS 10
#define STB_HIOS 12
#define STB_LOPROC 13
#define STB_HIPROC 15
/*
* Symbol types
*/
#define STT_NOTYPE 0
#define STT_OBJECT 1
#define STT_FUNC 2
#define STT_SECTION 3
#define STT_FILE 4
#define STT_COMMON 5
#define STT_TLS 6
#define STT_NUM 7
#define STT_LOOS 10
#define STT_HIOS 12
#define STT_LOPROC 13
#define STT_HIPROC 15
/*
* Macros for manipulating st_other
*/
#define ELF32_ST_VISIBILITY(o) ((o)&0x3)
#if __LIBELF64
#define ELF64_ST_VISIBILITY(o) ((o)&0x3)
#endif /* __LIBELF64 */
/*
* Symbol visibility
*/
#define STV_DEFAULT 0
#define STV_INTERNAL 1
#define STV_HIDDEN 2
#define STV_PROTECTED 3
/*
* Relocation
*/
typedef struct {
Elf32_Addr r_offset;
Elf32_Word r_info;
} Elf32_Rel;
typedef struct {
Elf32_Addr r_offset;
Elf32_Word r_info;
Elf32_Sword r_addend;
} Elf32_Rela;
#if __LIBELF64
typedef struct {
Elf64_Addr r_offset;
Elf64_Xword r_info;
} Elf64_Rel;
typedef struct {
Elf64_Addr r_offset;
Elf64_Xword r_info;
Elf64_Sxword r_addend;
} Elf64_Rela;
#endif /* __LIBELF64 */
/*
* Macros for manipulating r_info
*/
#define ELF32_R_SYM(i) ((i)>>8)
#define ELF32_R_TYPE(i) ((unsigned char)(i))
#define ELF32_R_INFO(s,t) (((s)<<8)+(unsigned char)(t))
#if __LIBELF64
#define ELF64_R_SYM(i) ((Elf64_Xword)(i)>>32)
#define ELF64_R_TYPE(i) ((i)&0xffffffffL)
#define ELF64_R_INFO(s,t) (((Elf64_Xword)(s)<<32)+((t)&0xffffffffL))
#endif /* __LIBELF64 */
/*
* Note entry header
*/
typedef struct {
Elf32_Word n_namesz; /* name size */
Elf32_Word n_descsz; /* descriptor size */
Elf32_Word n_type; /* descriptor type */
} Elf32_Nhdr;
#if __LIBELF64
/* Solaris and GNU use this layout. Be compatible. */
/* XXX: Latest ELF specs say it's 64-bit!!! */
typedef struct {
Elf64_Word n_namesz; /* name size */
Elf64_Word n_descsz; /* descriptor size */
Elf64_Word n_type; /* descriptor type */
} Elf64_Nhdr;
#endif /* __LIBELF64 */
/*
* Well-known descriptor types for ET_CORE files
*/
#define NT_PRSTATUS 1
#define NT_PRFPREG 2
#define NT_PRPSINFO 3
/*
* Program header
*/
typedef struct {
Elf32_Word p_type;
Elf32_Off p_offset;
Elf32_Addr p_vaddr;
Elf32_Addr p_paddr;
Elf32_Word p_filesz;
Elf32_Word p_memsz;
Elf32_Word p_flags;
Elf32_Word p_align;
} Elf32_Phdr;
#if __LIBELF64
typedef struct {
Elf64_Word p_type;
Elf64_Word p_flags;
Elf64_Off p_offset;
Elf64_Addr p_vaddr;
Elf64_Addr p_paddr;
Elf64_Xword p_filesz;
Elf64_Xword p_memsz;
Elf64_Xword p_align;
} Elf64_Phdr;
#endif /* __LIBELF64 */
/*
* Special numbers
*/
#define PN_XNUM 0xffff
/*
* p_type
*/
#define PT_NULL 0
#define PT_LOAD 1
#define PT_DYNAMIC 2
#define PT_INTERP 3
#define PT_NOTE 4
#define PT_SHLIB 5
#define PT_PHDR 6
#define PT_TLS 7
#define PT_NUM 8
#define PT_LOOS 0x60000000
#define PT_HIOS 0x6fffffff
#define PT_LOPROC 0x70000000
#define PT_HIPROC 0x7fffffff
/*
* Solaris extensions
*/
#define PT_SUNW_UNWIND 0x6464e550
#define PT_LOSUNW 0x6ffffffa
#define PT_SUNWBSS 0x6ffffffa
#define PT_SUNWSTACK 0x6ffffffb
#define PT_SUNWDTRACE 0x6ffffffc
#define PT_SUNWCAP 0x6ffffffd
#define PT_HISUNW 0x6fffffff
/*
* p_flags
*/
#define PF_X 0x1
#define PF_W 0x2
#define PF_R 0x4
#define PF_MASKOS 0x0ff00000
#define PF_MASKPROC 0xf0000000
/*
* Dynamic structure
*/
typedef struct {
Elf32_Sword d_tag;
union {
Elf32_Word d_val;
Elf32_Addr d_ptr;
} d_un;
} Elf32_Dyn;
#if __LIBELF64
typedef struct {
Elf64_Sxword d_tag;
union {
Elf64_Xword d_val;
Elf64_Addr d_ptr;
} d_un;
} Elf64_Dyn;
#endif /* __LIBELF64 */
/*
* Dynamic array tags
*/
/* d_un exec shared */
#define DT_NULL 0 /* ign. mand. mand. */
#define DT_NEEDED 1 /* d_val opt. opt. */
#define DT_PLTRELSZ 2 /* d_val opt. opt. */
#define DT_PLTGOT 3 /* d_ptr opt. opt. */
#define DT_HASH 4 /* d_ptr mand. mand. */
#define DT_STRTAB 5 /* d_ptr mand. mand. */
#define DT_SYMTAB 6 /* d_ptr mand. mand. */
#define DT_RELA 7 /* d_ptr mand. opt. */
#define DT_RELASZ 8 /* d_val mand. opt. */
#define DT_RELAENT 9 /* d_val mand. opt. */
#define DT_STRSZ 10 /* d_val mand. mand. */
#define DT_SYMENT 11 /* d_val mand. mand. */
#define DT_INIT 12 /* d_ptr opt. opt. */
#define DT_FINI 13 /* d_ptr opt. opt. */
#define DT_SONAME 14 /* d_val ign. opt. */
#define DT_RPATH 15 /* d_val opt. ign. */
#define DT_SYMBOLIC 16 /* ign. ign. opt. */
#define DT_REL 17 /* d_ptr mand. opt. */
#define DT_RELSZ 18 /* d_val mand. opt. */
#define DT_RELENT 19 /* d_val mand. opt. */
#define DT_PLTREL 20 /* d_val opt. opt. */
#define DT_DEBUG 21 /* d_ptr opt. ign. */
#define DT_TEXTREL 22 /* ign. opt. opt. */
#define DT_JMPREL 23 /* d_ptr opt. opt. */
#define DT_BIND_NOW 24 /* ign. opt. opt. */
#define DT_INIT_ARRAY 25 /* d_ptr opt. opt. */
#define DT_FINI_ARRAY 26 /* d_ptr opt. opt. */
#define DT_INIT_ARRAYSZ 27 /* d_val opt. opt. */
#define DT_FINI_ARRAYSZ 28 /* d_val opt. opt. */
#define DT_RUNPATH 29 /* d_val opt. opt. */
#define DT_FLAGS 30 /* d_val opt. opt. */
#define DT_ENCODING 32 /* odd/even encoding rule starts here */
#define DT_PREINIT_ARRAY 32 /* d_ptr opt. ign. */
#define DT_PREINIT_ARRAYSZ 33 /* d_val opt. ign. */
#define DT_NUM 34
#define DT_LOOS 0x6000000D
#define DT_HIOS 0x6ffff000
#define DT_LOPROC 0x70000000
#define DT_HIPROC 0x7fffffff
/*
* DT_FLAGS values
*/
#define DF_ORIGIN 0x1
#define DF_SYMBOLIC 0x2
#define DF_TEXTREL 0x4
#define DF_BIND_NOW 0x8
#define DF_STATIC_TLS 0x10
/*
* Solaris extensions
*/
#define DT_VALRNGLO 0x6ffffd00
#define DT_CHECKSUM 0x6ffffdf8
#define DT_PLTPADSZ 0x6ffffdf9
#define DT_MOVEENT 0x6ffffdfa
#define DT_MOVESZ 0x6ffffdfb
#define DT_FEATURE_1 0x6ffffdfc
#define DT_POSFLAG_1 0x6ffffdfd
#define DT_SYMINSZ 0x6ffffdfe
#define DT_SYMINENT 0x6ffffdff
#define DT_VALRNGHI 0x6ffffdff
#define DT_ADDRRNGLO 0x6ffffe00
#define DT_CONFIG 0x6ffffefa
#define DT_DEPAUDIT 0x6ffffefb
#define DT_AUDIT 0x6ffffefc
#define DT_PLTPAD 0x6ffffefd
#define DT_MOVETAB 0x6ffffefe
#define DT_SYMINFO 0x6ffffeff
#define DT_ADDRRNGHI 0x6ffffeff
#define DT_RELACOUNT 0x6ffffff9
#define DT_RELCOUNT 0x6ffffffa
#define DT_FLAGS_1 0x6ffffffb
#define DT_VERDEF 0x6ffffffc
#define DT_VERDEFNUM 0x6ffffffd
#define DT_VERNEED 0x6ffffffe
#define DT_VERNEEDNUM 0x6fffffff
#define DT_AUXILIARY 0x7ffffffd
#define DT_USED 0x7ffffffe
#define DT_FILTER 0x7fffffff
/*
* GNU extensions
*/
#define DT_VERSYM 0x6ffffff0
/*
* DT_FEATURE_1 values
*/
#define DTF_1_PARINIT 0x1
#define DTF_1_CONFEXP 0x2
/*
* DT_POSFLAG_1 values
*/
#define DF_P1_LAZYLOAD 0x1
#define DF_P1_GROUPPERM 0x2
/*
* DT_FLAGS_1 values
*/
#define DF_1_NOW 0x00000001
#define DF_1_GLOBAL 0x00000002
#define DF_1_GROUP 0x00000004
#define DF_1_NODELETE 0x00000008
#define DF_1_LOADFLTR 0x00000010
#define DF_1_INITFIRST 0x00000020
#define DF_1_NOOPEN 0x00000040
#define DF_1_ORIGIN 0x00000080
#define DF_1_DIRECT 0x00000100
#define DF_1_TRANS 0x00000200
#define DF_1_INTERPOSE 0x00000400
#define DF_1_NODEFLIB 0x00000800
#define DF_1_NODUMP 0x00001000
#define DF_1_CONFALT 0x00002000
#define DF_1_ENDFILTEE 0x00004000
#define DF_1_DISPRELDNE 0x00008000
#define DF_1_DISPRELPND 0x00010000
/*
* Syminfo structure
*/
typedef struct {
Elf32_Half si_boundto;
Elf32_Half si_flags;
} Elf32_Syminfo;
#if __LIBELF64
typedef struct {
Elf64_Half si_boundto;
Elf64_Half si_flags;
} Elf64_Syminfo;
#endif /* __LIBELF64 */
/*
* Syminfo version (stored in unused first entry)
*/
#define SYMINFO_NONE 0
#define SYMINFO_CURRENT 1
#define SYMINFO_NUM 2
/*
* si_boundto special values
*/
#define SYMINFO_BT_LOWRESERVE 0xff00
#define SYMINFO_BT_PARENT 0xfffe /* bound to parent */
#define SYMINFO_BT_SELF 0xffff /* bound to self */
/*
* si_flags
*/
#define SYMINFO_FLG_DIRECT 0x01 /* bound to an object */
#define SYMINFO_FLG_PASSTHRU 0x02 /* pass-thru symbol */
#define SYMINFO_FLG_COPY 0x04 /* result of a copy relocation */
#define SYMINFO_FLG_LAZYLOAD 0x08 /* bound to lazy-loaded object */
/*
* Version definitions
*/
typedef struct {
Elf32_Half vd_version;
Elf32_Half vd_flags;
Elf32_Half vd_ndx;
Elf32_Half vd_cnt;
Elf32_Word vd_hash;
Elf32_Word vd_aux;
Elf32_Word vd_next;
} Elf32_Verdef;
typedef struct {
Elf32_Word vda_name;
Elf32_Word vda_next;
} Elf32_Verdaux;
typedef struct {
Elf32_Half vn_version;
Elf32_Half vn_cnt;
Elf32_Word vn_file;
Elf32_Word vn_aux;
Elf32_Word vn_next;
} Elf32_Verneed;
typedef struct {
Elf32_Word vna_hash;
Elf32_Half vna_flags;
Elf32_Half vna_other;
Elf32_Word vna_name;
Elf32_Word vna_next;
} Elf32_Vernaux;
typedef Elf32_Half Elf32_Versym;
#if __LIBELF64
typedef struct {
Elf64_Half vd_version;
Elf64_Half vd_flags;
Elf64_Half vd_ndx;
Elf64_Half vd_cnt;
Elf64_Word vd_hash;
Elf64_Word vd_aux;
Elf64_Word vd_next;
} Elf64_Verdef;
typedef struct {
Elf64_Word vda_name;
Elf64_Word vda_next;
} Elf64_Verdaux;
typedef struct {
Elf64_Half vn_version;
Elf64_Half vn_cnt;
Elf64_Word vn_file;
Elf64_Word vn_aux;
Elf64_Word vn_next;
} Elf64_Verneed;
typedef struct {
Elf64_Word vna_hash;
Elf64_Half vna_flags;
Elf64_Half vna_other;
Elf64_Word vna_name;
Elf64_Word vna_next;
} Elf64_Vernaux;
typedef Elf64_Half Elf64_Versym;
#endif /* __LIBELF64 */
/*
* vd_version
*/
#define VER_DEF_NONE 0
#define VER_DEF_CURRENT 1
#define VER_DEF_NUM 2
/*
* vn_version
*/
#define VER_NEED_NONE 0
#define VER_NEED_CURRENT 1
#define VER_NEED_NUM 2
/*
* vd_flags / vna_flags
*/
#define VER_FLG_BASE 0x1 /* vd_flags only */
#define VER_FLG_WEAK 0x2
/*
* Elf*_Versym special values
*/
#define VER_NDX_LOCAL 0
#define VER_NDX_GLOBAL 1
/*
* Solaris extensions
*/
/*
* Move section
*/
#if __LIBELF64
typedef struct {
Elf32_Lword m_value;
Elf32_Word m_info;
Elf32_Word m_poffset;
Elf32_Half m_repeat;
Elf32_Half m_stride;
} Elf32_Move;
typedef struct {
Elf64_Lword m_value;
Elf64_Xword m_info;
Elf64_Xword m_poffset;
Elf64_Half m_repeat;
Elf64_Half m_stride;
} Elf64_Move;
#define ELF32_M_SYM(info) ((info)>>8)
#define ELF32_M_SIZE(info) ((unsigned char)(info))
#define ELF32_M_INFO(sym, sz) (((sym)<<8)+(unsigned char)(sz))
#define ELF64_M_SYM(info) ((Elf64_Xword)(info)>>8)
#define ELF64_M_SIZE(info) ((unsigned char)(info))
#define ELF64_M_INFO(sym, sz) (((Elf64_Xword)(sym)<<8)+(unsigned char)(sz))
#endif /* __LIBELF64 */
/*
* Capabilities
*/
typedef struct {
Elf32_Word c_tag;
union {
Elf32_Word c_val;
Elf32_Addr c_ptr;
} c_un;
} Elf32_Cap;
#if __LIBELF64
typedef struct {
Elf64_Xword c_tag;
union {
Elf64_Xword c_val;
Elf64_Addr c_ptr;
} c_un;
} Elf64_Cap;
#endif /* __LIBELF64 */
#define CA_SUNW_NULL 0 /* c_un ignored */
#define CA_SUNW_HW_1 1 /* c_un.c_val */
#define CA_SUNW_SF_1 2 /* c_un.c_val */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _ELF_REPL_H */

View File

@@ -1,130 +0,0 @@
/*
* lib/sys_elf.h.w32 - internal configuration file for W32 port
* Copyright (C) 2004 - 2006 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @(#) $Id: sys_elf.h.w32,v 1.2 2006/09/07 15:55:42 michael Exp $
*/
/*
* DO NOT USE THIS IN APPLICATIONS - #include <libelf.h> INSTEAD!
*/
/* Define to `<elf.h>' or `<sys/elf.h>' if one of them is present */
#undef __LIBELF_HEADER_ELF_H
/* Define if Elf32_Dyn is declared in <link.h> */
#undef __LIBELF_NEED_LINK_H
/* Define if Elf32_Dyn is declared in <sys/link.h> */
#undef __LIBELF_NEED_SYS_LINK_H
/* Define if you want 64-bit support (and your system supports it) */
#define __LIBELF64 1
/* Define if you want 64-bit support, and are running IRIX */
#undef __LIBELF64_IRIX
/* Define if you want 64-bit support, and are running Linux */
#undef __LIBELF64_LINUX
/* Define if you want symbol versioning (and your system supports it) */
#define __LIBELF_SYMBOL_VERSIONS 1
/* Define to a 64-bit signed integer type if one exists */
#define __libelf_i64_t __int64
/* Define to a 64-bit unsigned integer type if one exists */
#define __libelf_u64_t unsigned __int64
/* Define to a 32-bit signed integer type if one exists */
#define __libelf_i32_t int
/* Define to a 32-bit unsigned integer type if one exists */
#define __libelf_u32_t unsigned int
/* Define to a 16-bit signed integer type if one exists */
#define __libelf_i16_t short int
/* Define to a 16-bit unsigned integer type if one exists */
#define __libelf_u16_t unsigned short int
/*
* Ok, now get the correct instance of elf.h...
*/
#ifdef __LIBELF_HEADER_ELF_H
# include __LIBELF_HEADER_ELF_H
#else /* __LIBELF_HEADER_ELF_H */
# if __LIBELF_INTERNAL__
# include <elf_repl.h>
# else /* __LIBELF_INTERNAL__ */
# include <libelf/elf_repl.h>
# endif /* __LIBELF_INTERNAL__ */
#endif /* __LIBELF_HEADER_ELF_H */
/*
* On some systems, <elf.h> is severely broken. Try to fix it.
*/
#ifdef __LIBELF_HEADER_ELF_H
# ifndef ELF32_FSZ_ADDR
# define ELF32_FSZ_ADDR 4
# define ELF32_FSZ_HALF 2
# define ELF32_FSZ_OFF 4
# define ELF32_FSZ_SWORD 4
# define ELF32_FSZ_WORD 4
# endif /* ELF32_FSZ_ADDR */
# ifndef STN_UNDEF
# define STN_UNDEF 0
# endif /* STN_UNDEF */
# if __LIBELF64
# ifndef ELF64_FSZ_ADDR
# define ELF64_FSZ_ADDR 8
# define ELF64_FSZ_HALF 2
# define ELF64_FSZ_OFF 8
# define ELF64_FSZ_SWORD 4
# define ELF64_FSZ_WORD 4
# define ELF64_FSZ_SXWORD 8
# define ELF64_FSZ_XWORD 8
# endif /* ELF64_FSZ_ADDR */
# ifndef ELF64_ST_BIND
# define ELF64_ST_BIND(i) ((i)>>4)
# define ELF64_ST_TYPE(i) ((i)&0xf)
# define ELF64_ST_INFO(b,t) (((b)<<4)+((t)&0xf))
# endif /* ELF64_ST_BIND */
# ifndef ELF64_R_SYM
# define ELF64_R_SYM(i) ((Elf64_Xword)(i)>>32)
# define ELF64_R_TYPE(i) ((i)&0xffffffffL)
# define ELF64_R_INFO(s,t) (((Elf64_Xword)(s)<<32)+((t)&0xffffffffL))
# endif /* ELF64_R_SYM */
# if __LIBELF64_LINUX
typedef __libelf_u64_t Elf64_Addr;
typedef __libelf_u16_t Elf64_Half;
typedef __libelf_u64_t Elf64_Off;
typedef __libelf_i32_t Elf64_Sword;
typedef __libelf_u32_t Elf64_Word;
typedef __libelf_i64_t Elf64_Sxword;
typedef __libelf_u64_t Elf64_Xword;
# endif /* __LIBELF64_LINUX */
# endif /* __LIBELF64 */
#endif /* __LIBELF_HEADER_ELF_H */

View File

@@ -1,222 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\32.fsize.c" />
<ClCompile Include="src\32.getehdr.c" />
<ClCompile Include="src\32.getphdr.c" />
<ClCompile Include="src\32.getshdr.c" />
<ClCompile Include="src\32.newehdr.c" />
<ClCompile Include="src\32.newphdr.c" />
<ClCompile Include="src\32.xlatetof.c" />
<ClCompile Include="src\64.xlatetof.c" />
<ClCompile Include="src\assert.c" />
<ClCompile Include="src\begin.c" />
<ClCompile Include="src\checksum.c" />
<ClCompile Include="src\cntl.c" />
<ClCompile Include="src\cook.c" />
<ClCompile Include="src\data.c" />
<ClCompile Include="src\end.c" />
<ClCompile Include="src\errmsg.c" />
<ClCompile Include="src\errno.c" />
<ClCompile Include="src\fill.c" />
<ClCompile Include="src\flag.c" />
<ClCompile Include="src\gelfehdr.c" />
<ClCompile Include="src\gelfphdr.c" />
<ClCompile Include="src\gelfshdr.c" />
<ClCompile Include="src\gelftrans.c" />
<ClCompile Include="src\getarhdr.c" />
<ClCompile Include="src\getaroff.c" />
<ClCompile Include="src\getarsym.c" />
<ClCompile Include="src\getbase.c" />
<ClCompile Include="src\getdata.c" />
<ClCompile Include="src\getident.c" />
<ClCompile Include="src\getscn.c" />
<ClCompile Include="src\hash.c" />
<ClCompile Include="src\input.c" />
<ClCompile Include="src\kind.c" />
<ClCompile Include="src\memset.c" />
<ClCompile Include="src\ndxscn.c" />
<ClCompile Include="src\newdata.c" />
<ClCompile Include="src\newscn.c" />
<ClCompile Include="src\next.c" />
<ClCompile Include="src\nextscn.c" />
<ClCompile Include="src\nlist.c" />
<ClCompile Include="src\opt.delscn.c" />
<ClCompile Include="src\rand.c" />
<ClCompile Include="src\rawdata.c" />
<ClCompile Include="src\rawfile.c" />
<ClCompile Include="src\strptr.c" />
<ClCompile Include="src\swap64.c" />
<ClCompile Include="src\update.c" />
<ClCompile Include="src\verdef_32_tof.c" />
<ClCompile Include="src\verdef_32_tom.c" />
<ClCompile Include="src\verdef_64_tof.c" />
<ClCompile Include="src\verdef_64_tom.c" />
<ClCompile Include="src\version.c" />
<ClCompile Include="src\x.elfext.c" />
<ClCompile Include="src\x.movscn.c" />
<ClCompile Include="src\x.remscn.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\libelf.h" />
<ClInclude Include="include\libelf\elf_repl.h" />
<ClInclude Include="include\libelf\sys_elf.h" />
<ClInclude Include="src\byteswap.h" />
<ClInclude Include="src\config.h" />
<ClInclude Include="src\errors.h" />
<ClInclude Include="src\ext_types.h" />
<ClInclude Include="src\gelf.h" />
<ClInclude Include="src\nlist.h" />
<ClInclude Include="src\private.h" />
<ClInclude Include="src\verdef.h" />
<ClInclude Include="src\verneed.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{a2d07885-a0d1-473b-83b2-209cd008ee8f}</ProjectGuid>
<RootNamespace>libelf</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>libelf</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;HAVE_CONFIG_H=1;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>include;include\libelf;src</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4244;4267;4311</DisableSpecificWarnings>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;HAVE_CONFIG_H=1;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalIncludeDirectories>include;include\libelf;src</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4244;4267;4311</DisableSpecificWarnings>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;HAVE_CONFIG_H=1;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>include;include\libelf;src</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4244;4267;4311</DisableSpecificWarnings>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS;HAVE_CONFIG_H=1;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalIncludeDirectories>include;include\libelf;src</AdditionalIncludeDirectories>
<DisableSpecificWarnings>4244;4267;4311</DisableSpecificWarnings>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -1,74 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="src\32.fsize.c" />
<ClCompile Include="src\32.getehdr.c" />
<ClCompile Include="src\32.getphdr.c" />
<ClCompile Include="src\32.getshdr.c" />
<ClCompile Include="src\32.newehdr.c" />
<ClCompile Include="src\32.newphdr.c" />
<ClCompile Include="src\32.xlatetof.c" />
<ClCompile Include="src\64.xlatetof.c" />
<ClCompile Include="src\assert.c" />
<ClCompile Include="src\begin.c" />
<ClCompile Include="src\checksum.c" />
<ClCompile Include="src\cntl.c" />
<ClCompile Include="src\cook.c" />
<ClCompile Include="src\data.c" />
<ClCompile Include="src\end.c" />
<ClCompile Include="src\errmsg.c" />
<ClCompile Include="src\errno.c" />
<ClCompile Include="src\fill.c" />
<ClCompile Include="src\flag.c" />
<ClCompile Include="src\gelfehdr.c" />
<ClCompile Include="src\gelfphdr.c" />
<ClCompile Include="src\gelfshdr.c" />
<ClCompile Include="src\gelftrans.c" />
<ClCompile Include="src\getarhdr.c" />
<ClCompile Include="src\getaroff.c" />
<ClCompile Include="src\getarsym.c" />
<ClCompile Include="src\getbase.c" />
<ClCompile Include="src\getdata.c" />
<ClCompile Include="src\getident.c" />
<ClCompile Include="src\getscn.c" />
<ClCompile Include="src\hash.c" />
<ClCompile Include="src\input.c" />
<ClCompile Include="src\kind.c" />
<ClCompile Include="src\memset.c" />
<ClCompile Include="src\ndxscn.c" />
<ClCompile Include="src\newdata.c" />
<ClCompile Include="src\newscn.c" />
<ClCompile Include="src\next.c" />
<ClCompile Include="src\nextscn.c" />
<ClCompile Include="src\nlist.c" />
<ClCompile Include="src\opt.delscn.c" />
<ClCompile Include="src\rand.c" />
<ClCompile Include="src\rawdata.c" />
<ClCompile Include="src\rawfile.c" />
<ClCompile Include="src\strptr.c" />
<ClCompile Include="src\swap64.c" />
<ClCompile Include="src\update.c" />
<ClCompile Include="src\verdef_32_tof.c" />
<ClCompile Include="src\verdef_32_tom.c" />
<ClCompile Include="src\verdef_64_tof.c" />
<ClCompile Include="src\verdef_64_tom.c" />
<ClCompile Include="src\version.c" />
<ClCompile Include="src\x.elfext.c" />
<ClCompile Include="src\x.movscn.c" />
<ClCompile Include="src\x.remscn.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\byteswap.h" />
<ClInclude Include="src\config.h" />
<ClInclude Include="src\errors.h" />
<ClInclude Include="src\ext_types.h" />
<ClInclude Include="src\gelf.h" />
<ClInclude Include="src\nlist.h" />
<ClInclude Include="src\private.h" />
<ClInclude Include="src\verdef.h" />
<ClInclude Include="src\verneed.h" />
<ClInclude Include="include\libelf\elf_repl.h" />
<ClInclude Include="include\libelf\sys_elf.h" />
<ClInclude Include="include\libelf.h" />
</ItemGroup>
</Project>

View File

@@ -1,155 +0,0 @@
/*
32.fsize.c - implementation of the elf{32,64}_fsize(3) functions.
Copyright (C) 1995 - 2001 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#include <ext_types.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: 32.fsize.c,v 1.13 2008/05/23 08:15:33 michael Exp $";
#endif /* lint */
const size_t
_elf_fmsize[2][EV_CURRENT - EV_NONE][ELF_T_NUM][2] = {
/* ELFCLASS32 */
{
/* version 1 */
{
{ sizeof(unsigned char), sizeof(unsigned char) },
{ sizeof(Elf32_Addr), sizeof(__ext_Elf32_Addr) },
{ sizeof(Elf32_Dyn), sizeof(__ext_Elf32_Dyn) },
{ sizeof(Elf32_Ehdr), sizeof(__ext_Elf32_Ehdr) },
{ sizeof(Elf32_Half), sizeof(__ext_Elf32_Half) },
{ sizeof(Elf32_Off), sizeof(__ext_Elf32_Off) },
{ sizeof(Elf32_Phdr), sizeof(__ext_Elf32_Phdr) },
{ sizeof(Elf32_Rela), sizeof(__ext_Elf32_Rela) },
{ sizeof(Elf32_Rel), sizeof(__ext_Elf32_Rel) },
{ sizeof(Elf32_Shdr), sizeof(__ext_Elf32_Shdr) },
{ sizeof(Elf32_Sword), sizeof(__ext_Elf32_Sword) },
{ sizeof(Elf32_Sym), sizeof(__ext_Elf32_Sym) },
{ sizeof(Elf32_Word), sizeof(__ext_Elf32_Word) },
{ 0, 0 }, /* there is no Elf32_Sxword */
{ 0, 0 }, /* there is no Elf32_Xword */
/* XXX: check Solaris values */
{ 0, 0 }, /* Elf32_Verdef/Verdaux size varies */
{ 0, 0 }, /* Elf32_Verneed/Vernaux size varies */
},
},
#if __LIBELF64
/* ELFCLASS64 */
{
/* version 1 */
{
{ sizeof(unsigned char), sizeof(unsigned char) },
{ sizeof(Elf64_Addr), sizeof(__ext_Elf64_Addr) },
{ sizeof(Elf64_Dyn), sizeof(__ext_Elf64_Dyn) },
{ sizeof(Elf64_Ehdr), sizeof(__ext_Elf64_Ehdr) },
{ sizeof(Elf64_Half), sizeof(__ext_Elf64_Half) },
{ sizeof(Elf64_Off), sizeof(__ext_Elf64_Off) },
{ sizeof(Elf64_Phdr), sizeof(__ext_Elf64_Phdr) },
{ sizeof(Elf64_Rela), sizeof(__ext_Elf64_Rela) },
{ sizeof(Elf64_Rel), sizeof(__ext_Elf64_Rel) },
{ sizeof(Elf64_Shdr), sizeof(__ext_Elf64_Shdr) },
{ sizeof(Elf64_Sword), sizeof(__ext_Elf64_Sword) },
{ sizeof(Elf64_Sym), sizeof(__ext_Elf64_Sym) },
{ sizeof(Elf64_Word), sizeof(__ext_Elf64_Word) },
{ sizeof(Elf64_Sxword), sizeof(__ext_Elf64_Sxword) },
{ sizeof(Elf64_Xword), sizeof(__ext_Elf64_Xword) },
/* XXX: check Solaris values */
{ 0, 0 }, /* Elf64_Verdef/Verdaux size varies */
{ 0, 0 }, /* Elf64_Verneed/Vernaux size varies */
},
},
#endif /* __LIBELF64 */
};
static size_t
_elf_fsize(unsigned cls, Elf_Type type, unsigned ver) {
size_t n = 0;
if (!valid_version(ver)) {
seterr(ERROR_UNKNOWN_VERSION);
}
else if (!valid_type(type)) {
seterr(ERROR_UNKNOWN_TYPE);
}
else if (!(n = _fsize(cls, ver, type))) {
seterr(ERROR_UNKNOWN_TYPE);
}
return n;
}
size_t
elf32_fsize(Elf_Type type, size_t count, unsigned ver) {
return count * _elf_fsize(ELFCLASS32, type, ver);
}
#if __LIBELF64
size_t
elf64_fsize(Elf_Type type, size_t count, unsigned ver) {
return count * _elf_fsize(ELFCLASS64, type, ver);
}
size_t
gelf_fsize(Elf *elf, Elf_Type type, size_t count, unsigned ver) {
if (elf) {
if (elf->e_kind != ELF_K_ELF) {
seterr(ERROR_NOTELF);
}
else if (valid_class(elf->e_class)) {
return count * _elf_fsize(elf->e_class, type, ver);
}
else {
seterr(ERROR_UNKNOWN_CLASS);
}
}
return 0;
}
/*
* Extension: report memory size
*/
size_t
gelf_msize(Elf *elf, Elf_Type type, size_t count, unsigned ver) {
size_t n;
if (elf) {
if (elf->e_kind != ELF_K_ELF) {
seterr(ERROR_NOTELF);
}
else if (!valid_class(elf->e_class)) {
seterr(ERROR_UNKNOWN_CLASS);
}
else if (!valid_version(ver)) {
seterr(ERROR_UNKNOWN_VERSION);
}
else if (!valid_type(type)) {
seterr(ERROR_UNKNOWN_TYPE);
}
else if (!(n = _msize(elf->e_class, ver, type))) {
seterr(ERROR_UNKNOWN_TYPE);
}
else {
return count * n;
}
}
return 0;
}
#endif /* __LIBELF64 */

View File

@@ -1,56 +0,0 @@
/*
32.getehdr.c - implementation of the elf{32,64}_getehdr(3) functions.
Copyright (C) 1995 - 1998 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: 32.getehdr.c,v 1.9 2008/05/23 08:15:34 michael Exp $";
#endif /* lint */
char*
_elf_getehdr(Elf *elf, unsigned cls) {
if (!elf) {
return NULL;
}
elf_assert(elf->e_magic == ELF_MAGIC);
if (elf->e_kind != ELF_K_ELF) {
seterr(ERROR_NOTELF);
}
else if (elf->e_class != cls) {
seterr(ERROR_CLASSMISMATCH);
}
else if (elf->e_ehdr || _elf_cook(elf)) {
return elf->e_ehdr;
}
return NULL;
}
Elf32_Ehdr*
elf32_getehdr(Elf *elf) {
return (Elf32_Ehdr*)_elf_getehdr(elf, ELFCLASS32);
}
#if __LIBELF64
Elf64_Ehdr*
elf64_getehdr(Elf *elf) {
return (Elf64_Ehdr*)_elf_getehdr(elf, ELFCLASS64);
}
#endif /* __LIBELF64 */

View File

@@ -1,56 +0,0 @@
/*
32.getphdr.c - implementation of the elf{32,64}_getphdr(3) functions.
Copyright (C) 1995 - 2000 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: 32.getphdr.c,v 1.11 2008/05/23 08:15:34 michael Exp $";
#endif /* lint */
char*
_elf_getphdr(Elf *elf, unsigned cls) {
if (!elf) {
return NULL;
}
elf_assert(elf->e_magic == ELF_MAGIC);
if (elf->e_kind != ELF_K_ELF) {
seterr(ERROR_NOTELF);
}
else if (elf->e_class != cls) {
seterr(ERROR_CLASSMISMATCH);
}
else if (elf->e_ehdr || _elf_cook(elf)) {
return elf->e_phdr;
}
return NULL;
}
Elf32_Phdr*
elf32_getphdr(Elf *elf) {
return (Elf32_Phdr*)_elf_getphdr(elf, ELFCLASS32);
}
#if __LIBELF64
Elf64_Phdr*
elf64_getphdr(Elf *elf) {
return (Elf64_Phdr*)_elf_getphdr(elf, ELFCLASS64);
}
#endif /* __LIBELF64 */

View File

@@ -1,58 +0,0 @@
/*
32.getshdr.c - implementation of the elf{32,64}_getshdr(3) functions.
Copyright (C) 1995 - 1998 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: 32.getshdr.c,v 1.10 2008/05/23 08:15:34 michael Exp $";
#endif /* lint */
Elf32_Shdr*
elf32_getshdr(Elf_Scn *scn) {
if (!scn) {
return NULL;
}
elf_assert(scn->s_magic == SCN_MAGIC);
elf_assert(scn->s_elf);
elf_assert(scn->s_elf->e_magic == ELF_MAGIC);
if (scn->s_elf->e_class == ELFCLASS32) {
return &scn->s_shdr32;
}
seterr(ERROR_CLASSMISMATCH);
return NULL;
}
#if __LIBELF64
Elf64_Shdr*
elf64_getshdr(Elf_Scn *scn) {
if (!scn) {
return NULL;
}
elf_assert(scn->s_magic == SCN_MAGIC);
elf_assert(scn->s_elf);
elf_assert(scn->s_elf->e_magic == ELF_MAGIC);
if (scn->s_elf->e_class == ELFCLASS64) {
return &scn->s_shdr64;
}
seterr(ERROR_CLASSMISMATCH);
return NULL;
}
#endif /* __LIBELF64 */

View File

@@ -1,80 +0,0 @@
/*
* 32.newehdr.c - implementation of the elf{32,64}_newehdr(3) functions.
* Copyright (C) 1995 - 2006 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: 32.newehdr.c,v 1.16 2008/05/23 08:15:34 michael Exp $";
#endif /* lint */
static char*
_elf_newehdr(Elf *elf, unsigned cls) {
size_t size;
if (!elf) {
return NULL;
}
elf_assert(elf->e_magic == ELF_MAGIC);
if (elf->e_readable) {
return _elf_getehdr(elf, cls);
}
else if (!elf->e_ehdr) {
size = _msize(cls, _elf_version, ELF_T_EHDR);
elf_assert(size);
if ((elf->e_ehdr = (char*)malloc(size))) {
memset(elf->e_ehdr, 0, size);
elf->e_ehdr_flags |= ELF_F_DIRTY;
elf->e_kind = ELF_K_ELF;
elf->e_class = cls;
return elf->e_ehdr;
}
seterr(ERROR_MEM_EHDR);
}
else if (elf->e_class != cls) {
seterr(ERROR_CLASSMISMATCH);
}
else {
elf_assert(elf->e_kind == ELF_K_ELF);
return elf->e_ehdr;
}
return NULL;
}
Elf32_Ehdr*
elf32_newehdr(Elf *elf) {
return (Elf32_Ehdr*)_elf_newehdr(elf, ELFCLASS32);
}
#if __LIBELF64
Elf64_Ehdr*
elf64_newehdr(Elf *elf) {
return (Elf64_Ehdr*)_elf_newehdr(elf, ELFCLASS64);
}
unsigned long
gelf_newehdr(Elf *elf, int cls) {
if (!valid_class(cls) || !_msize(cls, _elf_version, ELF_T_EHDR)) {
seterr(ERROR_UNKNOWN_CLASS);
return 0;
}
return (unsigned long)_elf_newehdr(elf, cls);
}
#endif /* __LIBELF64 */

View File

@@ -1,118 +0,0 @@
/*
* 32.newphdr.c - implementation of the elf{32,64}_newphdr(3) functions.
* Copyright (C) 1995 - 2006 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: 32.newphdr.c,v 1.16 2008/05/23 08:15:34 michael Exp $";
#endif /* lint */
static char*
_elf_newphdr(Elf *elf, size_t count, unsigned cls) {
size_t extcount = 0;
Elf_Scn *scn = NULL;
char *phdr = NULL;
size_t size;
if (!elf) {
return NULL;
}
elf_assert(elf->e_magic == ELF_MAGIC);
if (!elf->e_ehdr && !elf->e_readable) {
seterr(ERROR_NOEHDR);
}
else if (elf->e_kind != ELF_K_ELF) {
seterr(ERROR_NOTELF);
}
else if (elf->e_class != cls) {
seterr(ERROR_CLASSMISMATCH);
}
else if (elf->e_ehdr || _elf_cook(elf)) {
size = _msize(cls, _elf_version, ELF_T_PHDR);
elf_assert(size);
if (!(scn = _elf_first_scn(elf))) {
return NULL;
}
if (count) {
if (!(phdr = (char*)malloc(count * size))) {
seterr(ERROR_MEM_PHDR);
return NULL;
}
memset(phdr, 0, count * size);
}
elf_assert(elf->e_ehdr);
elf->e_phnum = count;
if (count >= PN_XNUM) {
/*
* get NULL section (create it if necessary)
*/
extcount = count;
count = PN_XNUM;
}
if (cls == ELFCLASS32) {
((Elf32_Ehdr*)elf->e_ehdr)->e_phnum = count;
scn->s_shdr32.sh_info = extcount;
}
#if __LIBELF64
else if (cls == ELFCLASS64) {
((Elf64_Ehdr*)elf->e_ehdr)->e_phnum = count;
scn->s_shdr64.sh_info = extcount;
}
#endif /* __LIBELF64 */
else {
seterr(ERROR_UNIMPLEMENTED);
if (phdr) {
free(phdr);
}
return NULL;
}
if (elf->e_phdr) {
free(elf->e_phdr);
}
elf->e_phdr = phdr;
elf->e_phdr_flags |= ELF_F_DIRTY;
elf->e_ehdr_flags |= ELF_F_DIRTY;
scn->s_scn_flags |= ELF_F_DIRTY;
return phdr;
}
return NULL;
}
Elf32_Phdr*
elf32_newphdr(Elf *elf, size_t count) {
return (Elf32_Phdr*)_elf_newphdr(elf, count, ELFCLASS32);
}
#if __LIBELF64
Elf64_Phdr*
elf64_newphdr(Elf *elf, size_t count) {
return (Elf64_Phdr*)_elf_newphdr(elf, count, ELFCLASS64);
}
unsigned long
gelf_newphdr(Elf *elf, size_t phnum) {
if (!valid_class(elf->e_class)) {
seterr(ERROR_UNKNOWN_CLASS);
return 0;
}
return (unsigned long)_elf_newphdr(elf, phnum, elf->e_class);
}
#endif /* __LIBELF64 */

View File

@@ -1,438 +0,0 @@
/*
* 32.xlatetof.c - implementation of the elf32_xlateto[fm](3) functions.
* Copyright (C) 1995 - 2006 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#include <ext_types.h>
#include <byteswap.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: 32.xlatetof.c,v 1.27 2008/05/23 08:15:34 michael Exp $";
#endif /* lint */
/*
* Ugly, ugly
*/
#ifdef _WIN32
# define Cat2(a,b)a##b
# define Cat3(a,b,c)a##b##c
# define Ex1(m1,m2,a,b)m1##m2(a##b)
# define Ex2(m1,m2,a,b,c)m1##m2(a,b##c)
#else /* _WIN32 */
# define x
# if defined/**/x
# define Cat2(a,b)a##b
# define Cat3(a,b,c)a##b##c
# define Ex1(m1,m2,a,b)m1##m2(a##b)
# define Ex2(m1,m2,a,b,c)m1##m2(a,b##c)
# else
# define Cat2(a,b)a/**/b
# define Cat3(a,b,c)a/**/b/**/c
# define Ex1(m1,m2,a,b)m1/**/m2(a/**/b)
# define Ex2(m1,m2,a,b,c)m1/**/m2(a,b/**/c)
# endif
# undef x
#endif /* _WIN32 */
/*
* auxiliary macros for execution order reversal
*/
#define seq_forw(a,b) a b
#define seq_back(a,b) b a
/*
* function instantiator
*/
#define copy_type_e_io(name,e,io,tfrom,tto,copy) \
static size_t \
Cat3(name,_,io)(unsigned char *dst, const unsigned char *src, size_t n) { \
n /= sizeof(tfrom); \
if (n && dst) { \
const tfrom *from = (const tfrom*)src; \
tto *to = (tto*)dst; \
size_t i; \
\
if (sizeof(tfrom) < sizeof(tto)) { \
from += n; \
to += n; \
for (i = 0; i < n; i++) { \
--from; \
--to; \
copy(e,io,seq_back) \
} \
} \
else { \
for (i = 0; i < n; i++) { \
copy(e,io,seq_forw) \
from++; \
to++; \
} \
} \
} \
return n * sizeof(tto); \
}
#define copy_type_e(name,e,type,copy) \
copy_type_e_io(name,e,tom,Cat2(__ext_,type),type,copy) \
copy_type_e_io(name,e,tof,type,Cat2(__ext_,type),copy)
/*
* master function instantiator
*/
#define copy_type(name,version,type,copy) \
copy_type_e(Cat3(name,L,version),L,type,copy) \
copy_type_e(Cat3(name,M,version),M,type,copy)
/*
* scalar copying
*/
#define copy_scalar_tom(type) *to = Cat2(__load_,type)(*from);
#define copy_scalar_tof(type) Cat2(__store_,type)(*to, *from);
/*
* structure member copying
*/
#define copy_tom(mb,type) to->mb = Cat2(__load_,type)(from->mb);
#define copy_tof(mb,type) Cat2(__store_,type)(to->mb, from->mb);
/*
* structure member copying (direction independent)
*/
#define copy_byte(e,io,mb) to->mb = from->mb;
#define copy_addr(e,io,mb) Ex2(copy_,io,mb,u32,e)
#define copy_half(e,io,mb) Ex2(copy_,io,mb,u16,e)
#define copy_off(e,io,mb) Ex2(copy_,io,mb,u32,e)
#define copy_sword(e,io,mb) Ex2(copy_,io,mb,i32,e)
#define copy_word(e,io,mb) Ex2(copy_,io,mb,u32,e)
#define copy_arr(e,io,mb) \
array_copy(to->mb, sizeof(to->mb), from->mb, sizeof(from->mb));
/*
* scalar copying (direction independent)
* these macros are used as `copy' arguments to copy_type()
*/
#define copy_addr_11(e,io,seq) Ex1(copy_scalar_,io,u32,e)
#define copy_half_11(e,io,seq) Ex1(copy_scalar_,io,u16,e)
#define copy_off_11(e,io,seq) Ex1(copy_scalar_,io,u32,e)
#define copy_sword_11(e,io,seq) Ex1(copy_scalar_,io,i32,e)
#define copy_word_11(e,io,seq) Ex1(copy_scalar_,io,u32,e)
/*
* structure copying (direction independent)
* these macros are used as `copy' arguments to copy_type()
*/
#define copy_dyn_11(e,io,seq) \
seq(copy_sword(e,io,d_tag), \
seq(copy_addr(e,io,d_un.d_ptr), \
nullcopy))
#define copy_ehdr_11(e,io,seq) \
seq(copy_arr(e,io,e_ident), \
seq(copy_half(e,io,e_type), \
seq(copy_half(e,io,e_machine), \
seq(copy_word(e,io,e_version), \
seq(copy_addr(e,io,e_entry), \
seq(copy_off(e,io,e_phoff), \
seq(copy_off(e,io,e_shoff), \
seq(copy_word(e,io,e_flags), \
seq(copy_half(e,io,e_ehsize), \
seq(copy_half(e,io,e_phentsize), \
seq(copy_half(e,io,e_phnum), \
seq(copy_half(e,io,e_shentsize), \
seq(copy_half(e,io,e_shnum), \
seq(copy_half(e,io,e_shstrndx), \
nullcopy))))))))))))))
#define copy_phdr_11(e,io,seq) \
seq(copy_word(e,io,p_type), \
seq(copy_off(e,io,p_offset), \
seq(copy_addr(e,io,p_vaddr), \
seq(copy_addr(e,io,p_paddr), \
seq(copy_word(e,io,p_filesz), \
seq(copy_word(e,io,p_memsz), \
seq(copy_word(e,io,p_flags), \
seq(copy_word(e,io,p_align), \
nullcopy))))))))
#define copy_rela_11(e,io,seq) \
seq(copy_addr(e,io,r_offset), \
seq(copy_word(e,io,r_info), \
seq(copy_sword(e,io,r_addend), \
nullcopy)))
#define copy_rel_11(e,io,seq) \
seq(copy_addr(e,io,r_offset), \
seq(copy_word(e,io,r_info), \
nullcopy))
#define copy_shdr_11(e,io,seq) \
seq(copy_word(e,io,sh_name), \
seq(copy_word(e,io,sh_type), \
seq(copy_word(e,io,sh_flags), \
seq(copy_addr(e,io,sh_addr), \
seq(copy_off(e,io,sh_offset), \
seq(copy_word(e,io,sh_size), \
seq(copy_word(e,io,sh_link), \
seq(copy_word(e,io,sh_info), \
seq(copy_word(e,io,sh_addralign), \
seq(copy_word(e,io,sh_entsize), \
nullcopy))))))))))
#define copy_sym_11(e,io,seq) \
seq(copy_word(e,io,st_name), \
seq(copy_addr(e,io,st_value), \
seq(copy_word(e,io,st_size), \
seq(copy_byte(e,io,st_info), \
seq(copy_byte(e,io,st_other), \
seq(copy_half(e,io,st_shndx), \
nullcopy))))))
#define nullcopy /**/
static size_t
byte_copy(unsigned char *dst, const unsigned char *src, size_t n) {
if (n && dst && dst != src) {
#if HAVE_BROKEN_MEMMOVE
size_t i;
if (dst >= src + n || dst + n <= src) {
memcpy(dst, src, n);
}
else if (dst < src) {
for (i = 0; i < n; i++) {
dst[i] = src[i];
}
}
else {
for (i = n; --i; ) {
dst[i] = src[i];
}
}
#else /* HAVE_BROKEN_MEMMOVE */
memmove(dst, src, n);
#endif /* HAVE_BROKEN_MEMMOVE */
}
return n;
}
static void
array_copy(unsigned char *dst, size_t dlen, const unsigned char *src, size_t slen) {
byte_copy(dst, src, dlen < slen ? dlen : slen);
if (dlen > slen) {
memset(dst + slen, 0, dlen - slen);
}
}
/*
* instantiate copy functions
*/
copy_type(addr_32,_,Elf32_Addr,copy_addr_11)
copy_type(half_32,_,Elf32_Half,copy_half_11)
copy_type(off_32,_,Elf32_Off,copy_off_11)
copy_type(sword_32,_,Elf32_Sword,copy_sword_11)
copy_type(word_32,_,Elf32_Word,copy_word_11)
copy_type(dyn_32,11,Elf32_Dyn,copy_dyn_11)
copy_type(ehdr_32,11,Elf32_Ehdr,copy_ehdr_11)
copy_type(phdr_32,11,Elf32_Phdr,copy_phdr_11)
copy_type(rela_32,11,Elf32_Rela,copy_rela_11)
copy_type(rel_32,11,Elf32_Rel,copy_rel_11)
copy_type(shdr_32,11,Elf32_Shdr,copy_shdr_11)
copy_type(sym_32,11,Elf32_Sym,copy_sym_11)
typedef size_t (*xlator)(unsigned char*, const unsigned char*, size_t);
typedef xlator xltab[ELF_T_NUM][2];
/*
* translation table (32-bit, version 1 -> version 1)
*/
#if PIC
static xltab
#else /* PIC */
static const xltab
#endif /* PIC */
xlate32_11[/*encoding*/] = {
{
{ byte_copy, byte_copy },
{ addr_32L__tom, addr_32L__tof },
{ dyn_32L11_tom, dyn_32L11_tof },
{ ehdr_32L11_tom, ehdr_32L11_tof },
{ half_32L__tom, half_32L__tof },
{ off_32L__tom, off_32L__tof },
{ phdr_32L11_tom, phdr_32L11_tof },
{ rela_32L11_tom, rela_32L11_tof },
{ rel_32L11_tom, rel_32L11_tof },
{ shdr_32L11_tom, shdr_32L11_tof },
{ sword_32L__tom, sword_32L__tof },
{ sym_32L11_tom, sym_32L11_tof },
{ word_32L__tom, word_32L__tof },
{ 0, 0 }, /* there is no Sxword */
{ 0, 0 }, /* there is no Xword */
#if __LIBELF_SYMBOL_VERSIONS
{ _elf_verdef_32L11_tom, _elf_verdef_32L11_tof },
{ _elf_verneed_32L11_tom, _elf_verneed_32L11_tof },
#else /* __LIBELF_SYMBOL_VERSIONS */
{ 0, 0 },
{ 0, 0 },
#endif /* __LIBELF_SYMBOL_VERSIONS */
},
{
{ byte_copy, byte_copy },
{ addr_32M__tom, addr_32M__tof },
{ dyn_32M11_tom, dyn_32M11_tof },
{ ehdr_32M11_tom, ehdr_32M11_tof },
{ half_32M__tom, half_32M__tof },
{ off_32M__tom, off_32M__tof },
{ phdr_32M11_tom, phdr_32M11_tof },
{ rela_32M11_tom, rela_32M11_tof },
{ rel_32M11_tom, rel_32M11_tof },
{ shdr_32M11_tom, shdr_32M11_tof },
{ sword_32M__tom, sword_32M__tof },
{ sym_32M11_tom, sym_32M11_tof },
{ word_32M__tom, word_32M__tof },
{ 0, 0 }, /* there is no Sxword */
{ 0, 0 }, /* there is no Xword */
#if __LIBELF_SYMBOL_VERSIONS
{ _elf_verdef_32M11_tom, _elf_verdef_32M11_tof },
{ _elf_verneed_32M11_tom, _elf_verneed_32M11_tof },
#else /* __LIBELF_SYMBOL_VERSIONS */
{ 0, 0 },
{ 0, 0 },
#endif /* __LIBELF_SYMBOL_VERSIONS */
},
};
/*
* main translation table (32-bit)
*/
#if PIC
static xltab*
#else /* PIC */
static const xltab *const
#endif /* PIC */
xlate32[EV_CURRENT - EV_NONE][EV_CURRENT - EV_NONE] = {
{ xlate32_11, },
};
#define translator(sv,dv,enc,type,d) \
(xlate32[(sv) - EV_NONE - 1] \
[(dv) - EV_NONE - 1] \
[(enc) - ELFDATA2LSB] \
[(type) - ELF_T_BYTE] \
[d])
/*
* destination buffer size
*/
size_t
_elf32_xltsize(const Elf_Data *src, unsigned dv, unsigned encode, int tof) {
Elf_Type type = src->d_type;
unsigned sv = src->d_version;
xlator op;
if (!valid_version(sv) || !valid_version(dv)) {
seterr(ERROR_UNKNOWN_VERSION);
return (size_t)-1;
}
if (tof) {
/*
* Encoding doesn't really matter (the translator only looks at
* the source, which resides in memory), but we need a proper
* encoding to select a translator...
*/
encode = ELFDATA2LSB;
}
else if (!valid_encoding(encode)) {
seterr(ERROR_UNKNOWN_ENCODING);
return (size_t)-1;
}
if (!valid_type(type)) {
seterr(ERROR_UNKNOWN_TYPE);
return (size_t)-1;
}
if (!(op = translator(sv, dv, encode, type, tof))) {
seterr(ERROR_UNKNOWN_TYPE);
return (size_t)-1;
}
return (*op)(NULL, src->d_buf, src->d_size);
}
/*
* direction-independent translation
*/
static Elf_Data*
elf32_xlate(Elf_Data *dst, const Elf_Data *src, unsigned encode, int tof) {
Elf_Type type;
int dv;
int sv;
size_t dsize;
size_t tmp;
xlator op;
if (!src || !dst) {
return NULL;
}
if (!src->d_buf || !dst->d_buf) {
seterr(ERROR_NULLBUF);
return NULL;
}
if (!valid_encoding(encode)) {
seterr(ERROR_UNKNOWN_ENCODING);
return NULL;
}
sv = src->d_version;
dv = dst->d_version;
if (!valid_version(sv) || !valid_version(dv)) {
seterr(ERROR_UNKNOWN_VERSION);
return NULL;
}
type = src->d_type;
if (!valid_type(type)) {
seterr(ERROR_UNKNOWN_TYPE);
return NULL;
}
op = translator(sv, dv, encode, type, tof);
if (!op) {
seterr(ERROR_UNKNOWN_TYPE);
return NULL;
}
dsize = (*op)(NULL, src->d_buf, src->d_size);
if (dsize == (size_t)-1) {
return NULL;
}
if (dst->d_size < dsize) {
seterr(ERROR_DST2SMALL);
return NULL;
}
if (dsize) {
tmp = (*op)(dst->d_buf, src->d_buf, src->d_size);
if (tmp == (size_t)-1) {
return NULL;
}
elf_assert(tmp == dsize);
}
dst->d_size = dsize;
dst->d_type = type;
return dst;
}
/*
* finally, the "official" translation functions
*/
Elf_Data*
elf32_xlatetom(Elf_Data *dst, const Elf_Data *src, unsigned encode) {
return elf32_xlate(dst, src, encode, 0);
}
Elf_Data*
elf32_xlatetof(Elf_Data *dst, const Elf_Data *src, unsigned encode) {
return elf32_xlate(dst, src, encode, 1);
}

View File

@@ -1,512 +0,0 @@
/*
* 64.xlatetof.c - implementation of the elf64_xlateto[fm](3) functions.
* Copyright (C) 1995 - 2006 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#include <ext_types.h>
#include <byteswap.h>
#if __LIBELF64
#ifndef lint
static const char rcsid[] = "@(#) $Id: 64.xlatetof.c,v 1.27 2008/05/23 08:15:34 michael Exp $";
#endif /* lint */
/*
* Ugly, ugly
*/
#ifdef _WIN32
# define Cat2(a,b)a##b
# define Cat3(a,b,c)a##b##c
# define Ex1(m1,m2,a,b)m1##m2(a##b)
# define Ex2(m1,m2,a,b,c)m1##m2(a,b##c)
#else /* _WIN32 */
# define x
# if defined/**/x
# define Cat2(a,b)a##b
# define Cat3(a,b,c)a##b##c
# define Ex1(m1,m2,a,b)m1##m2(a##b)
# define Ex2(m1,m2,a,b,c)m1##m2(a,b##c)
# else
# define Cat2(a,b)a/**/b
# define Cat3(a,b,c)a/**/b/**/c
# define Ex1(m1,m2,a,b)m1/**/m2(a/**/b)
# define Ex2(m1,m2,a,b,c)m1/**/m2(a,b/**/c)
# endif
# undef x
#endif /* _WIN32 */
/*
* auxiliary macros for execution order reversal
*/
#define seq_forw(a,b) a b
#define seq_back(a,b) b a
/*
* function instantiator
*/
#define copy_type_e_io(name,e,io,tfrom,tto,copy) \
static size_t \
Cat3(name,_,io)(unsigned char *dst, const unsigned char *src, size_t n) { \
n /= sizeof(tfrom); \
if (n && dst) { \
const tfrom *from = (const tfrom*)src; \
tto *to = (tto*)dst; \
size_t i; \
\
if (sizeof(tfrom) < sizeof(tto)) { \
from += n; \
to += n; \
for (i = 0; i < n; i++) { \
--from; \
--to; \
copy(e,io,seq_back) \
} \
} \
else { \
for (i = 0; i < n; i++) { \
copy(e,io,seq_forw) \
from++; \
to++; \
} \
} \
} \
return n * sizeof(tto); \
}
#define copy_type_e(name,e,type,copy) \
copy_type_e_io(name,e,tom,Cat2(__ext_,type),type,copy) \
copy_type_e_io(name,e,tof,type,Cat2(__ext_,type),copy)
/*
* master function instantiator
*/
#define copy_type(name,version,type,copy) \
copy_type_e(Cat3(name,L,version),L,type,copy) \
copy_type_e(Cat3(name,M,version),M,type,copy)
/*
* scalar copying
*/
#define copy_scalar_tom(type) *to = Cat2(__load_,type)(*from);
#define copy_scalar_tof(type) Cat2(__store_,type)(*to, *from);
/*
* structure member copying
*/
#define copy_tom(mb,type) to->mb = Cat2(__load_,type)(from->mb);
#define copy_tof(mb,type) Cat2(__store_,type)(to->mb, from->mb);
/*
* structure member copying (direction independent)
*/
#define copy_byte(e,io,mb) to->mb = from->mb;
#define copy_addr(e,io,mb) Ex2(copy_,io,mb,u64,e)
#define copy_half(e,io,mb) Ex2(copy_,io,mb,u16,e)
#define copy_off(e,io,mb) Ex2(copy_,io,mb,u64,e)
#define copy_sword(e,io,mb) Ex2(copy_,io,mb,i32,e)
#define copy_word(e,io,mb) Ex2(copy_,io,mb,u32,e)
#define copy_sxword(e,io,mb) Ex2(copy_,io,mb,i64,e)
#define copy_xword(e,io,mb) Ex2(copy_,io,mb,u64,e)
#define copy_arr(e,io,mb) \
array_copy(to->mb, sizeof(to->mb), from->mb, sizeof(from->mb));
/*
* scalar copying (direction independent)
* these macros are used as `copy' arguments to copy_type()
*/
#define copy_addr_11(e,io,seq) Ex1(copy_scalar_,io,u64,e)
#define copy_half_11(e,io,seq) Ex1(copy_scalar_,io,u16,e)
#define copy_off_11(e,io,seq) Ex1(copy_scalar_,io,u64,e)
#define copy_sword_11(e,io,seq) Ex1(copy_scalar_,io,i32,e)
#define copy_word_11(e,io,seq) Ex1(copy_scalar_,io,u32,e)
#define copy_sxword_11(e,io,seq)Ex1(copy_scalar_,io,i64,e)
#define copy_xword_11(e,io,seq) Ex1(copy_scalar_,io,u64,e)
/*
* structure copying (direction independent)
* these macros are used as `copy' arguments to copy_type()
*/
#define copy_dyn_11(e,io,seq) \
seq(copy_xword(e,io,d_tag), \
seq(copy_addr(e,io,d_un.d_ptr), \
nullcopy))
#define copy_ehdr_11(e,io,seq) \
seq(copy_arr(e,io,e_ident), \
seq(copy_half(e,io,e_type), \
seq(copy_half(e,io,e_machine), \
seq(copy_word(e,io,e_version), \
seq(copy_addr(e,io,e_entry), \
seq(copy_off(e,io,e_phoff), \
seq(copy_off(e,io,e_shoff), \
seq(copy_word(e,io,e_flags), \
seq(copy_half(e,io,e_ehsize), \
seq(copy_half(e,io,e_phentsize), \
seq(copy_half(e,io,e_phnum), \
seq(copy_half(e,io,e_shentsize), \
seq(copy_half(e,io,e_shnum), \
seq(copy_half(e,io,e_shstrndx), \
nullcopy))))))))))))))
#define copy_phdr_11(e,io,seq) \
seq(copy_word(e,io,p_type), \
seq(copy_word(e,io,p_flags), \
seq(copy_off(e,io,p_offset), \
seq(copy_addr(e,io,p_vaddr), \
seq(copy_addr(e,io,p_paddr), \
seq(copy_xword(e,io,p_filesz), \
seq(copy_xword(e,io,p_memsz), \
seq(copy_xword(e,io,p_align), \
nullcopy))))))))
#if __LIBELF64_IRIX
#define copy_rela_11(e,io,seq) \
seq(copy_addr(e,io,r_offset), \
seq(copy_word(e,io,r_sym), \
seq(copy_byte(e,io,r_ssym), \
seq(copy_byte(e,io,r_type3), \
seq(copy_byte(e,io,r_type2), \
seq(copy_byte(e,io,r_type), \
seq(copy_sxword(e,io,r_addend), \
nullcopy)))))))
#define copy_rel_11(e,io,seq) \
seq(copy_addr(e,io,r_offset), \
seq(copy_word(e,io,r_sym), \
seq(copy_byte(e,io,r_ssym), \
seq(copy_byte(e,io,r_type3), \
seq(copy_byte(e,io,r_type2), \
seq(copy_byte(e,io,r_type), \
nullcopy))))))
#else /* __LIBELF64_IRIX */
#define copy_rela_11(e,io,seq) \
seq(copy_addr(e,io,r_offset), \
seq(copy_xword(e,io,r_info), \
seq(copy_sxword(e,io,r_addend), \
nullcopy)))
#define copy_rel_11(e,io,seq) \
seq(copy_addr(e,io,r_offset), \
seq(copy_xword(e,io,r_info), \
nullcopy))
#endif /* __LIBELF64_IRIX */
#define copy_shdr_11(e,io,seq) \
seq(copy_word(e,io,sh_name), \
seq(copy_word(e,io,sh_type), \
seq(copy_xword(e,io,sh_flags), \
seq(copy_addr(e,io,sh_addr), \
seq(copy_off(e,io,sh_offset), \
seq(copy_xword(e,io,sh_size), \
seq(copy_word(e,io,sh_link), \
seq(copy_word(e,io,sh_info), \
seq(copy_xword(e,io,sh_addralign), \
seq(copy_xword(e,io,sh_entsize), \
nullcopy))))))))))
#define copy_sym_11(e,io,seq) \
seq(copy_word(e,io,st_name), \
seq(copy_byte(e,io,st_info), \
seq(copy_byte(e,io,st_other), \
seq(copy_half(e,io,st_shndx), \
seq(copy_addr(e,io,st_value), \
seq(copy_xword(e,io,st_size), \
nullcopy))))))
#define nullcopy /**/
static size_t
byte_copy(unsigned char *dst, const unsigned char *src, size_t n) {
if (n && dst && dst != src) {
#if HAVE_BROKEN_MEMMOVE
size_t i;
if (dst >= src + n || dst + n <= src) {
memcpy(dst, src, n);
}
else if (dst < src) {
for (i = 0; i < n; i++) {
dst[i] = src[i];
}
}
else {
for (i = n; --i; ) {
dst[i] = src[i];
}
}
#else /* HAVE_BROKEN_MEMMOVE */
memmove(dst, src, n);
#endif /* HAVE_BROKEN_MEMMOVE */
}
return n;
}
static void
array_copy(unsigned char *dst, size_t dlen, const unsigned char *src, size_t slen) {
byte_copy(dst, src, dlen < slen ? dlen : slen);
if (dlen > slen) {
memset(dst + slen, 0, dlen - slen);
}
}
/*
* instantiate copy functions
*/
copy_type(addr_64,_,Elf64_Addr,copy_addr_11)
copy_type(half_64,_,Elf64_Half,copy_half_11)
copy_type(off_64,_,Elf64_Off,copy_off_11)
copy_type(sword_64,_,Elf64_Sword,copy_sword_11)
copy_type(word_64,_,Elf64_Word,copy_word_11)
copy_type(sxword_64,_,Elf64_Sxword,copy_sxword_11)
copy_type(xword_64,_,Elf64_Xword,copy_xword_11)
copy_type(dyn_64,11,Elf64_Dyn,copy_dyn_11)
copy_type(ehdr_64,11,Elf64_Ehdr,copy_ehdr_11)
copy_type(phdr_64,11,Elf64_Phdr,copy_phdr_11)
copy_type(rela_64,11,Elf64_Rela,copy_rela_11)
copy_type(rel_64,11,Elf64_Rel,copy_rel_11)
copy_type(shdr_64,11,Elf64_Shdr,copy_shdr_11)
copy_type(sym_64,11,Elf64_Sym,copy_sym_11)
typedef size_t (*xlator)(unsigned char*, const unsigned char*, size_t);
typedef xlator xltab[ELF_T_NUM][2];
/*
* translation table (64-bit, version 1 -> version 1)
*/
#if PIC
static xltab
#else /* PIC */
static const xltab
#endif /* PIC */
xlate64_11[/*encoding*/] = {
{
{ byte_copy, byte_copy },
{ addr_64L__tom, addr_64L__tof },
{ dyn_64L11_tom, dyn_64L11_tof },
{ ehdr_64L11_tom, ehdr_64L11_tof },
{ half_64L__tom, half_64L__tof },
{ off_64L__tom, off_64L__tof },
{ phdr_64L11_tom, phdr_64L11_tof },
{ rela_64L11_tom, rela_64L11_tof },
{ rel_64L11_tom, rel_64L11_tof },
{ shdr_64L11_tom, shdr_64L11_tof },
{ sword_64L__tom, sword_64L__tof },
{ sym_64L11_tom, sym_64L11_tof },
{ word_64L__tom, word_64L__tof },
{ sxword_64L__tom, sxword_64L__tof },
{ xword_64L__tom, xword_64L__tof },
#if __LIBELF_SYMBOL_VERSIONS
{ _elf_verdef_64L11_tom, _elf_verdef_64L11_tof },
{ _elf_verneed_64L11_tom, _elf_verneed_64L11_tof },
#else /* __LIBELF_SYMBOL_VERSIONS */
{ 0, 0 },
{ 0, 0 },
#endif /* __LIBELF_SYMBOL_VERSIONS */
},
{
{ byte_copy, byte_copy },
{ addr_64M__tom, addr_64M__tof },
{ dyn_64M11_tom, dyn_64M11_tof },
{ ehdr_64M11_tom, ehdr_64M11_tof },
{ half_64M__tom, half_64M__tof },
{ off_64M__tom, off_64M__tof },
{ phdr_64M11_tom, phdr_64M11_tof },
{ rela_64M11_tom, rela_64M11_tof },
{ rel_64M11_tom, rel_64M11_tof },
{ shdr_64M11_tom, shdr_64M11_tof },
{ sword_64M__tom, sword_64M__tof },
{ sym_64M11_tom, sym_64M11_tof },
{ word_64M__tom, word_64M__tof },
{ sxword_64M__tom, sxword_64M__tof },
{ xword_64M__tom, xword_64M__tof },
#if __LIBELF_SYMBOL_VERSIONS
{ _elf_verdef_64M11_tom, _elf_verdef_64M11_tof },
{ _elf_verneed_64M11_tom, _elf_verneed_64M11_tof },
#else /* __LIBELF_SYMBOL_VERSIONS */
{ 0, 0 },
{ 0, 0 },
#endif /* __LIBELF_SYMBOL_VERSIONS */
},
};
/*
* main translation table (64-bit)
*/
#if PIC
static xltab*
#else /* PIC */
static const xltab *const
#endif /* PIC */
xlate64[EV_CURRENT - EV_NONE][EV_CURRENT - EV_NONE] = {
{ xlate64_11, },
};
#define translator(sv,dv,enc,type,d) \
(xlate64[(sv) - EV_NONE - 1] \
[(dv) - EV_NONE - 1] \
[(enc) - ELFDATA2LSB] \
[(type) - ELF_T_BYTE] \
[d])
/*
* destination buffer size
*/
size_t
_elf64_xltsize(const Elf_Data *src, unsigned dv, unsigned encode, int tof) {
Elf_Type type = src->d_type;
unsigned sv = src->d_version;
xlator op;
if (!valid_version(sv) || !valid_version(dv)) {
seterr(ERROR_UNKNOWN_VERSION);
return (size_t)-1;
}
if (tof) {
/*
* Encoding doesn't really matter (the translator only looks at
* the source, which resides in memory), but we need a proper
* encoding to select a translator...
*/
encode = ELFDATA2LSB;
}
else if (!valid_encoding(encode)) {
seterr(ERROR_UNKNOWN_ENCODING);
return (size_t)-1;
}
if (!valid_type(type)) {
seterr(ERROR_UNKNOWN_TYPE);
return (size_t)-1;
}
if (!(op = translator(sv, dv, encode, type, tof))) {
seterr(ERROR_UNKNOWN_TYPE);
return (size_t)-1;
}
return (*op)(NULL, src->d_buf, src->d_size);
}
/*
* direction-independent translation
*/
static Elf_Data*
elf64_xlate(Elf_Data *dst, const Elf_Data *src, unsigned encode, int tof) {
Elf_Type type;
int dv;
int sv;
size_t dsize;
size_t tmp;
xlator op;
if (!src || !dst) {
return NULL;
}
if (!src->d_buf || !dst->d_buf) {
seterr(ERROR_NULLBUF);
return NULL;
}
if (!valid_encoding(encode)) {
seterr(ERROR_UNKNOWN_ENCODING);
return NULL;
}
sv = src->d_version;
dv = dst->d_version;
if (!valid_version(sv) || !valid_version(dv)) {
seterr(ERROR_UNKNOWN_VERSION);
return NULL;
}
type = src->d_type;
if (!valid_type(type)) {
seterr(ERROR_UNKNOWN_TYPE);
return NULL;
}
op = translator(sv, dv, encode, type, tof);
if (!op) {
seterr(ERROR_UNKNOWN_TYPE);
return NULL;
}
dsize = (*op)(NULL, src->d_buf, src->d_size);
if (dsize == (size_t)-1) {
return NULL;
}
if (dst->d_size < dsize) {
seterr(ERROR_DST2SMALL);
return NULL;
}
if (dsize) {
tmp = (*op)(dst->d_buf, src->d_buf, src->d_size);
if (tmp == (size_t)-1) {
return NULL;
}
elf_assert(tmp == dsize);
}
dst->d_size = dsize;
dst->d_type = type;
return dst;
}
/*
* finally, the "official" translation functions
*/
Elf_Data*
elf64_xlatetom(Elf_Data *dst, const Elf_Data *src, unsigned encode) {
return elf64_xlate(dst, src, encode, 0);
}
Elf_Data*
elf64_xlatetof(Elf_Data *dst, const Elf_Data *src, unsigned encode) {
return elf64_xlate(dst, src, encode, 1);
}
Elf_Data*
gelf_xlatetom(Elf *elf, Elf_Data *dst, const Elf_Data *src, unsigned encode) {
if (elf) {
if (elf->e_kind != ELF_K_ELF) {
seterr(ERROR_NOTELF);
}
else if (elf->e_class == ELFCLASS32) {
return elf32_xlatetom(dst, src, encode);
}
else if (elf->e_class == ELFCLASS64) {
return elf64_xlatetom(dst, src, encode);
}
else if (valid_class(elf->e_class)) {
seterr(ERROR_UNIMPLEMENTED);
}
else {
seterr(ERROR_UNKNOWN_CLASS);
}
}
return NULL;
}
Elf_Data*
gelf_xlatetof(Elf *elf, Elf_Data *dst, const Elf_Data *src, unsigned encode) {
if (elf) {
if (elf->e_kind != ELF_K_ELF) {
seterr(ERROR_NOTELF);
}
else if (elf->e_class == ELFCLASS32) {
return elf32_xlatetof(dst, src, encode);
}
else if (elf->e_class == ELFCLASS64) {
return elf64_xlatetof(dst, src, encode);
}
else if (valid_class(elf->e_class)) {
seterr(ERROR_UNIMPLEMENTED);
}
else {
seterr(ERROR_UNKNOWN_CLASS);
}
}
return NULL;
}
#endif /* __LIBELF64__ */

View File

@@ -1,33 +0,0 @@
/*
assert.c - assert function for libelf.
Copyright (C) 1999 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: assert.c,v 1.5 2008/05/23 08:15:34 michael Exp $";
#endif /* lint */
#include <stdio.h>
void
__elf_assert(const char *file, unsigned line, const char *cond) {
fprintf(stderr, "%s:%u: libelf assertion failure: %s\n",
file, line, cond);
abort();
}

View File

@@ -1,429 +0,0 @@
/*
* begin.c - implementation of the elf_begin(3) and elf_memory(3) functions.
* Copyright (C) 1995 - 2004 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: begin.c,v 1.22 2009/11/01 13:04:19 michael Exp $";
#endif /* lint */
static const Elf _elf_init = INIT_ELF;
static const char fmag[] = ARFMAG;
static unsigned long
getnum(const char *str, size_t len, int base, size_t *err) {
unsigned long result = 0;
while (len && *str == ' ') {
str++; len--;
}
while (len && *str >= '0' && (*str - '0') < base) {
result = base * result + *str++ - '0'; len--;
}
while (len && *str == ' ') {
str++; len--;
}
if (len) {
*err = len;
}
return result;
}
static void
_elf_init_ar(Elf *elf) {
struct ar_hdr *hdr;
size_t offset;
size_t size;
size_t err = 0;
elf->e_kind = ELF_K_AR;
elf->e_idlen = SARMAG;
elf->e_off = SARMAG;
/* process special members */
offset = SARMAG;
while (!elf->e_strtab && offset + sizeof(*hdr) <= elf->e_size) {
hdr = (struct ar_hdr*)(elf->e_data + offset);
if (memcmp(hdr->ar_fmag, fmag, sizeof(fmag) - 1)) {
break;
}
if (hdr->ar_name[0] != '/') {
break;
}
size = getnum(hdr->ar_size, sizeof(hdr->ar_size), 10, &err);
if (err || !size) {
break;
}
offset += sizeof(*hdr);
if (offset + size > elf->e_size) {
break;
}
if (hdr->ar_name[1] == '/' && hdr->ar_name[2] == ' ') {
elf->e_strtab = elf->e_data + offset;
elf->e_strlen = size;
break;
}
if (hdr->ar_name[1] != ' ') {
break;
}
/*
* Windows (.lib) archives provide two symbol tables
* The first one is the one we want.
*/
if (!elf->e_symtab) {
elf->e_symtab = elf->e_data + offset;
elf->e_symlen = size;
}
offset += size + (size & 1);
}
}
static Elf_Arhdr*
_elf_arhdr(Elf *arf) {
struct ar_hdr *hdr;
Elf_Arhdr *arhdr;
size_t namelen;
size_t tmp;
char *name;
size_t err = 0;
if (arf->e_off == arf->e_size) {
/* no error! */
return NULL;
}
if (arf->e_off < 0 || arf->e_off > arf->e_size) {
seterr(ERROR_OUTSIDE);
return NULL;
}
if (arf->e_off + sizeof(*hdr) > arf->e_size) {
seterr(ERROR_TRUNC_ARHDR);
return NULL;
}
elf_assert(arf->e_data != NULL);
hdr = (struct ar_hdr*)(arf->e_data + arf->e_off);
if (memcmp(hdr->ar_fmag, fmag, sizeof(fmag) - 1)) {
seterr(ERROR_ARFMAG);
return NULL;
}
name = hdr->ar_name;
for (namelen = sizeof(hdr->ar_name); namelen > 0; namelen--) {
if (name[namelen - 1] != ' ') {
break;
}
}
if (name[0] == '/') {
if (name[1] >= '0' && name[1] <= '9') {
if (!arf->e_strtab) {
seterr(ERROR_ARSTRTAB);
return NULL;
}
tmp = getnum(&name[1], namelen - 1, 10, &err);
if (err) {
seterr(ERROR_ARSPECIAL);
return NULL;
}
if (tmp < 0 || tmp >= arf->e_strlen) {
seterr(ERROR_ARSTRTAB);
return NULL;
}
for (namelen = tmp; namelen < arf->e_strlen; namelen++) {
if (arf->e_strtab[namelen] == '/') {
break;
}
}
if (namelen == arf->e_strlen) {
seterr(ERROR_ARSTRTAB);
return NULL;
}
name = arf->e_strtab + tmp;
namelen -= tmp;
}
else if (namelen != 1 && !(namelen == 2 && name[1] == '/')) {
seterr(ERROR_ARSPECIAL);
return NULL;
}
}
else if (namelen > 0 && name[namelen - 1] == '/') {
namelen--;
}
/* XXX some broken software omits the trailing slash
else {
namelen = 0;
}
*/
if (!(arhdr = (Elf_Arhdr*)malloc(sizeof(*arhdr) +
sizeof(hdr->ar_name) + namelen + 2))) {
seterr(ERROR_MEM_ARHDR);
return NULL;
}
arhdr->ar_name = NULL;
arhdr->ar_rawname = (char*)(arhdr + 1);
arhdr->ar_date = getnum(hdr->ar_date, sizeof(hdr->ar_date), 10, &err);
arhdr->ar_uid = getnum(hdr->ar_uid, sizeof(hdr->ar_uid), 10, &err);
arhdr->ar_gid = getnum(hdr->ar_gid, sizeof(hdr->ar_gid), 10, &err);
arhdr->ar_mode = getnum(hdr->ar_mode, sizeof(hdr->ar_mode), 8, &err);
arhdr->ar_size = getnum(hdr->ar_size, sizeof(hdr->ar_size), 10, &err);
if (err) {
free(arhdr);
seterr(ERROR_ARHDR);
return NULL;
}
if (arf->e_off + sizeof(struct ar_hdr) + arhdr->ar_size > arf->e_size) {
free(arhdr);
seterr(ERROR_TRUNC_MEMBER);
return NULL;
}
memcpy(arhdr->ar_rawname, hdr->ar_name, sizeof(hdr->ar_name));
arhdr->ar_rawname[sizeof(hdr->ar_name)] = '\0';
if (namelen) {
arhdr->ar_name = arhdr->ar_rawname + sizeof(hdr->ar_name) + 1;
memcpy(arhdr->ar_name, name, namelen);
arhdr->ar_name[namelen] = '\0';
}
return arhdr;
}
static void
_elf_check_type(Elf *elf, size_t size) {
elf->e_idlen = size;
if (size >= EI_NIDENT && !memcmp(elf->e_data, ELFMAG, SELFMAG)) {
elf->e_kind = ELF_K_ELF;
elf->e_idlen = EI_NIDENT;
elf->e_class = elf->e_data[EI_CLASS];
elf->e_encoding = elf->e_data[EI_DATA];
elf->e_version = elf->e_data[EI_VERSION];
}
else if (size >= SARMAG && !memcmp(elf->e_data, ARMAG, SARMAG)) {
_elf_init_ar(elf);
}
}
Elf*
elf_begin(int fd, Elf_Cmd cmd, Elf *ref) {
Elf_Arhdr *arhdr = NULL;
size_t size = 0;
off_t off;
Elf *elf;
elf_assert(_elf_init.e_magic == ELF_MAGIC);
if (_elf_version == EV_NONE) {
seterr(ERROR_VERSION_UNSET);
return NULL;
}
else if (cmd == ELF_C_NULL) {
return NULL;
}
else if (cmd == ELF_C_WRITE) {
ref = NULL;
}
else if (cmd != ELF_C_READ && cmd != ELF_C_RDWR) {
seterr(ERROR_INVALID_CMD);
return NULL;
}
else if (ref) {
elf_assert(ref->e_magic == ELF_MAGIC);
if (!ref->e_readable || (cmd == ELF_C_RDWR && !ref->e_writable)) {
seterr(ERROR_CMDMISMATCH);
return NULL;
}
if (ref->e_kind != ELF_K_AR) {
ref->e_count++;
return ref;
}
if (cmd == ELF_C_RDWR) {
seterr(ERROR_MEMBERWRITE);
return NULL;
}
if (ref->e_memory) {
fd = ref->e_fd;
}
else if (fd != ref->e_fd) {
seterr(ERROR_FDMISMATCH);
return NULL;
}
if (!(arhdr = _elf_arhdr(ref))) {
return NULL;
}
size = arhdr->ar_size;
}
else if ((off = lseek(fd, (off_t)0, SEEK_END)) == (off_t)-1
|| (off_t)(size = off) != off) {
seterr(ERROR_IO_GETSIZE);
return NULL;
}
if (!(elf = (Elf*)malloc(sizeof(Elf)))) {
seterr(ERROR_MEM_ELF);
return NULL;
}
*elf = _elf_init;
elf->e_fd = fd;
elf->e_parent = ref;
elf->e_size = elf->e_dsize = size;
if (cmd != ELF_C_READ) {
elf->e_writable = 1;
}
if (cmd != ELF_C_WRITE) {
elf->e_readable = 1;
}
else {
return elf;
}
if (ref) {
size_t offset = ref->e_off + sizeof(struct ar_hdr);
Elf *xelf;
elf_assert(arhdr);
elf->e_arhdr = arhdr;
elf->e_base = ref->e_base + offset;
/*
* Share the archive's memory image. To avoid
* multiple independent elf descriptors if the
* same member is requested twice, scan the list
* of open members for duplicates.
*
* I don't know how SVR4 handles this case. Don't rely on it.
*/
for (xelf = ref->e_members; xelf; xelf = xelf->e_link) {
elf_assert(xelf->e_parent == ref);
if (xelf->e_base == elf->e_base) {
free(arhdr);
free(elf);
xelf->e_count++;
return xelf;
}
}
if (size == 0) {
elf->e_data = NULL;
}
#if 1
else {
/*
* Archive members may be misaligned. Freezing them will
* cause libelf to allocate buffers for translated data,
* which should be properly aligned in all cases.
*/
elf_assert(!ref->e_cooked);
elf->e_data = elf->e_rawdata = ref->e_data + offset;
}
#else
else if (ref->e_data == ref->e_rawdata) {
elf_assert(!ref->e_cooked);
/*
* archive is frozen - freeze member, too
*/
elf->e_data = elf->e_rawdata = ref->e_data + offset;
}
else {
elf_assert(!ref->e_memory);
elf->e_data = ref->e_data + offset;
/*
* The member's memory image may have been modified if
* the member has been processed before. Since we need the
* original image, we have to re-read the archive file.
* Will fail if the archive's file descriptor is disabled.
*/
if (!ref->e_cooked) {
ref->e_cooked = 1;
}
else if (!_elf_read(ref, elf->e_data, offset, size)) {
free(arhdr);
free(elf);
return NULL;
}
}
#endif
elf->e_next = offset + size + (size & 1);
elf->e_disabled = ref->e_disabled;
elf->e_memory = ref->e_memory;
/* parent/child linking */
elf->e_link = ref->e_members;
ref->e_members = elf;
ref->e_count++;
/* Slowaris compatibility - do not rely on this! */
ref->e_off = elf->e_next;
}
else if (size) {
#if HAVE_MMAP
/*
* Using mmap on writable files will interfere with elf_update
*/
if (!elf->e_writable && (elf->e_data = _elf_mmap(elf))) {
elf->e_unmap_data = 1;
}
else
#endif /* HAVE_MMAP */
if (!(elf->e_data = _elf_read(elf, NULL, 0, size))) {
free(elf);
return NULL;
}
}
_elf_check_type(elf, size);
return elf;
}
Elf*
elf_memory(char *image, size_t size) {
Elf *elf;
elf_assert(_elf_init.e_magic == ELF_MAGIC);
if (_elf_version == EV_NONE) {
seterr(ERROR_VERSION_UNSET);
return NULL;
}
else if (size == 0 || image == NULL) {
/* TODO: set error code? */
return NULL;
}
if (!(elf = (Elf*)malloc(sizeof(Elf)))) {
seterr(ERROR_MEM_ELF);
return NULL;
}
*elf = _elf_init;
elf->e_size = elf->e_dsize = size;
elf->e_data = elf->e_rawdata = image;
elf->e_readable = 1;
elf->e_disabled = 1;
elf->e_memory = 1;
_elf_check_type(elf, size);
return elf;
}
#if __LIBELF64
int
gelf_getclass(Elf *elf) {
if (elf && elf->e_kind == ELF_K_ELF && valid_class(elf->e_class)) {
return elf->e_class;
}
return ELFCLASSNONE;
}
#endif /* __LIBELF64 */

View File

@@ -1,95 +0,0 @@
/*
byteswap.h - functions and macros for byte swapping.
Copyright (C) 1995 - 2001 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* @(#) $Id: byteswap.h,v 1.7 2008/05/23 08:15:34 michael Exp $ */
#ifndef _BYTESWAP_H
#define _BYTESWAP_H
#define lu(from,i,s) (((__libelf_u32_t)((unsigned char*)(from))[i])<<(s))
#define li(from,i,s) (((__libelf_i32_t)(( signed char*)(from))[i])<<(s))
#define __load_u16L(from) ((__libelf_u32_t) \
(lu(from,1,8) | lu(from,0,0)))
#define __load_u16M(from) ((__libelf_u32_t) \
(lu(from,0,8) | lu(from,1,0)))
#define __load_i16L(from) ((__libelf_i32_t) \
(li(from,1,8) | lu(from,0,0)))
#define __load_i16M(from) ((__libelf_i32_t) \
(li(from,0,8) | lu(from,1,0)))
#define __load_u32L(from) ((__libelf_u32_t) \
(lu(from,3,24) | lu(from,2,16) | lu(from,1,8) | lu(from,0,0)))
#define __load_u32M(from) ((__libelf_u32_t) \
(lu(from,0,24) | lu(from,1,16) | lu(from,2,8) | lu(from,3,0)))
#define __load_i32L(from) ((__libelf_i32_t) \
(li(from,3,24) | lu(from,2,16) | lu(from,1,8) | lu(from,0,0)))
#define __load_i32M(from) ((__libelf_i32_t) \
(li(from,0,24) | lu(from,1,16) | lu(from,2,8) | lu(from,3,0)))
#define su(to,i,v,s) (((char*)(to))[i]=((__libelf_u32_t)(v)>>(s)))
#define si(to,i,v,s) (((char*)(to))[i]=((__libelf_i32_t)(v)>>(s)))
#define __store_u16L(to,v) \
(su(to,1,v,8), su(to,0,v,0))
#define __store_u16M(to,v) \
(su(to,0,v,8), su(to,1,v,0))
#define __store_i16L(to,v) \
(si(to,1,v,8), si(to,0,v,0))
#define __store_i16M(to,v) \
(si(to,0,v,8), si(to,1,v,0))
#define __store_u32L(to,v) \
(su(to,3,v,24), su(to,2,v,16), su(to,1,v,8), su(to,0,v,0))
#define __store_u32M(to,v) \
(su(to,0,v,24), su(to,1,v,16), su(to,2,v,8), su(to,3,v,0))
#define __store_i32L(to,v) \
(si(to,3,v,24), si(to,2,v,16), si(to,1,v,8), si(to,0,v,0))
#define __store_i32M(to,v) \
(si(to,0,v,24), si(to,1,v,16), si(to,2,v,8), si(to,3,v,0))
#if __LIBELF64
/*
* conversion functions from swap64.c
*/
extern __libelf_u64_t _elf_load_u64L(const unsigned char *from);
extern __libelf_u64_t _elf_load_u64M(const unsigned char *from);
extern __libelf_i64_t _elf_load_i64L(const unsigned char *from);
extern __libelf_i64_t _elf_load_i64M(const unsigned char *from);
extern void _elf_store_u64L(unsigned char *to, __libelf_u64_t v);
extern void _elf_store_u64M(unsigned char *to, __libelf_u64_t v);
extern void _elf_store_i64L(unsigned char *to, __libelf_u64_t v);
extern void _elf_store_i64M(unsigned char *to, __libelf_u64_t v);
/*
* aliases for existing conversion code
*/
#define __load_u64L _elf_load_u64L
#define __load_u64M _elf_load_u64M
#define __load_i64L _elf_load_i64L
#define __load_i64M _elf_load_i64M
#define __store_u64L _elf_store_u64L
#define __store_u64M _elf_store_u64M
#define __store_i64L _elf_store_i64L
#define __store_i64M _elf_store_i64M
#endif /* __LIBELF64 */
#endif /* _BYTESWAP_H */

View File

@@ -1,178 +0,0 @@
/*
checksum.c - implementation of the elf{32,64}_checksum(3) functions.
Copyright (C) 1995 - 2001 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: checksum.c,v 1.7 2008/05/23 08:15:34 michael Exp $";
#endif /* lint */
/*
* Compatibility note:
*
* The algorithm used in {elf32,elf64,gelf}_checksum() does not seem to
* be documented. I hope I got it right. My implementation does the
* following:
*
* - skip sections that do not have the SHF_ALLOC flag set
* - skip sections of type SHT_NULL, SHT_NOBITS, SHT_DYNSYM and
* SHT_DYNAMIC
* - add all data bytes from the remaining sections, modulo 2**32
* - add upper and lower half of the result
* - subtract 0xffff if the result is > 0xffff
* - if any error occurs, return 0L
*/
static int
skip_section(Elf_Scn *scn, unsigned cls) {
if (cls == ELFCLASS32) {
Elf32_Shdr *shdr = &scn->s_shdr32;
if (!(shdr->sh_flags & SHF_ALLOC)) {
return 1;
}
switch (shdr->sh_type) {
case SHT_NULL:
case SHT_NOBITS:
/* Solaris seems to ignore these, too */
case SHT_DYNSYM:
case SHT_DYNAMIC:
return 1;
}
}
#if __LIBELF64
else if (cls == ELFCLASS64) {
Elf64_Shdr *shdr = &scn->s_shdr64;
if (!(shdr->sh_flags & SHF_ALLOC)) {
return 1;
}
switch (shdr->sh_type) {
case SHT_NULL:
case SHT_NOBITS:
/* Solaris seems to ignore these, too */
case SHT_DYNSYM:
case SHT_DYNAMIC:
return 1;
}
}
#endif /* __LIBELF64 */
else {
seterr(ERROR_UNIMPLEMENTED);
}
return 0;
}
static long
add_bytes(unsigned char *ptr, size_t len) {
long csum = 0;
while (len--) {
csum += *ptr++;
}
return csum;
}
static long
_elf_csum(Elf *elf) {
long csum = 0;
Elf_Data *data;
Elf_Scn *scn;
if (!elf->e_ehdr && !_elf_cook(elf)) {
/* propagate errors from _elf_cook */
return 0L;
}
seterr(0);
for (scn = elf->e_scn_1; scn; scn = scn->s_link) {
if (scn->s_index == SHN_UNDEF || skip_section(scn, elf->e_class)) {
continue;
}
data = NULL;
while ((data = elf_getdata(scn, data))) {
if (data->d_size) {
if (data->d_buf == NULL) {
seterr(ERROR_NULLBUF);
return 0L;
}
csum += add_bytes(data->d_buf, data->d_size);
}
}
}
if (_elf_errno) {
return 0L;
}
csum = (csum & 0xffff) + ((csum >> 16) & 0xffff);
if (csum > 0xffff) {
csum -= 0xffff;
}
return csum;
}
long
elf32_checksum(Elf *elf) {
if (elf) {
if (elf->e_kind != ELF_K_ELF) {
seterr(ERROR_NOTELF);
}
else if (elf->e_class != ELFCLASS32) {
seterr(ERROR_CLASSMISMATCH);
}
else {
return _elf_csum(elf);
}
}
return 0L;
}
#if __LIBELF64
long
elf64_checksum(Elf *elf) {
if (elf) {
if (elf->e_kind != ELF_K_ELF) {
seterr(ERROR_NOTELF);
}
else if (elf->e_class != ELFCLASS64) {
seterr(ERROR_CLASSMISMATCH);
}
else {
return _elf_csum(elf);
}
}
return 0L;
}
long
gelf_checksum(Elf *elf) {
if (elf) {
if (elf->e_kind != ELF_K_ELF) {
seterr(ERROR_NOTELF);
}
else if (!valid_class(elf->e_class)) {
seterr(ERROR_UNKNOWN_CLASS);
}
else {
return _elf_csum(elf);
}
}
return 0L;
}
#endif /* __LIBELF64 */

View File

@@ -1,71 +0,0 @@
/*
cntl.c - implementation of the elf_cntl(3) function.
Copyright (C) 1995 - 1998 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: cntl.c,v 1.7 2008/05/23 08:15:34 michael Exp $";
#endif /* lint */
int
elf_cntl(Elf *elf, Elf_Cmd cmd) {
Elf_Scn *scn;
Elf *child;
if (!elf) {
return -1;
}
elf_assert(elf->e_magic == ELF_MAGIC);
if (cmd == ELF_C_FDREAD) {
if (!elf->e_readable) {
seterr(ERROR_WRONLY);
return -1;
}
}
else if (cmd != ELF_C_FDDONE) {
seterr(ERROR_INVALID_CMD);
return -1;
}
if (elf->e_disabled) {
return 0;
}
if (elf->e_kind == ELF_K_AR) {
for (child = elf->e_members; child; child = child->e_link) {
elf_assert(elf == child->e_parent);
if (elf_cntl(child, cmd)) {
return -1;
}
}
}
else if (elf->e_kind == ELF_K_ELF && cmd == ELF_C_FDREAD) {
if (!elf->e_ehdr && !_elf_cook(elf)) {
return -1;
}
for (scn = elf->e_scn_1; scn; scn = scn->s_link) {
if (scn->s_index == SHN_UNDEF || scn->s_type == SHT_NULL) {
continue;
}
else if (!elf_getdata(scn, NULL)) {
return -1;
}
}
}
elf->e_disabled = 1;
return 0;
}

View File

@@ -1,164 +0,0 @@
/*
* lib/config.h.w32 - configuration file for W32 port
* Copyright (C) 2004 - 2006 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @(#) $Id: config.h.w32,v 1.2 2006/09/07 15:55:42 michael Exp $
*/
/* Define to empty if the keyword does not work. */
#undef const
/* Define if you have a working `mmap' system call. */
#undef HAVE_MMAP
/* Define to `long' if <sys/types.h> doesn't define. */
#undef off_t
/* Define to `unsigned' if <sys/types.h> doesn't define. */
#undef size_t
/* Define if you have the ANSI C header files. */
#define STDC_HEADERS 1
/* Define if you want to include extra debugging code */
#define ENABLE_DEBUG 1
/* Define if memmove() does not copy overlapping arrays correctly */
#undef HAVE_BROKEN_MEMMOVE
/* Define if you have the catgets function. */
#undef HAVE_CATGETS
/* Define if you have the dgettext function. */
#undef HAVE_DGETTEXT
/* Define if you have the memset function. */
#define HAVE_MEMSET 1
/* Define if struct nlist is declared in <elf.h> or <sys/elf.h> */
#undef HAVE_STRUCT_NLIST_DECLARATION
/* Define if Elf32_Dyn is declared in <link.h> */
#undef __LIBELF_NEED_LINK_H
/* Define if Elf32_Dyn is declared in <sys/link.h> */
#undef __LIBELF_NEED_SYS_LINK_H
/* Define to `<elf.h>' or `<sys/elf.h>' if one of them is present */
#undef __LIBELF_HEADER_ELF_H
/* Define if you want 64-bit support (and your system supports it) */
#define __LIBELF64 1
/* Define if you want 64-bit support, and are running IRIX */
#undef __LIBELF64_IRIX
/* Define if you want 64-bit support, and are running Linux */
#undef __LIBELF64_LINUX
/* Define if you want symbol versioning (and your system supports it) */
#define __LIBELF_SYMBOL_VERSIONS 1
/* Define if symbol versioning uses Sun section type (SHT_SUNW_*) */
#define __LIBELF_SUN_SYMBOL_VERSIONS 1
/* Define if symbol versioning uses GNU section types (SHT_GNU_*) */
#undef __LIBELF_GNU_SYMBOL_VERSIONS
/* Define to a 64-bit signed integer type if one exists */
#define __libelf_i64_t __int64
/* Define to a 64-bit unsigned integer type if one exists */
#define __libelf_u64_t unsigned __int64
/* Define to a 32-bit signed integer type if one exists */
#define __libelf_i32_t int
/* Define to a 32-bit unsigned integer type if one exists */
#define __libelf_u32_t unsigned int
/* Define to a 16-bit signed integer type if one exists */
#define __libelf_i16_t short int
/* Define to a 16-bit unsigned integer type if one exists */
#define __libelf_u16_t unsigned short int
/* The number of bytes in a __int64. */
#define SIZEOF___INT64 8
/* The number of bytes in a int. */
#define SIZEOF_INT 4
/* The number of bytes in a long. */
#define SIZEOF_LONG 4
/* The number of bytes in a long long. */
#define SIZEOF_LONG_LONG 0
/* The number of bytes in a short. */
#define SIZEOF_SHORT 2
/* Define if you have the ftruncate function. */
#undef HAVE_FTRUNCATE
/* Define if you have the getpagesize function. */
#undef HAVE_GETPAGESIZE
/* Define if you have the memcmp function. */
#define HAVE_MEMCMP 1
/* Define if you have the memcpy function. */
#define HAVE_MEMCPY 1
/* Define if you have the memmove function. */
#define HAVE_MEMMOVE 1
/* Define if you have the memset function. */
#define HAVE_MEMSET 1
/* Define if you have the <ar.h> header file. */
#undef HAVE_AR_H
/* Define if you have the <elf.h> header file. */
#undef HAVE_ELF_H
/* Define if you have the <fcntl.h> header file. */
#undef HAVE_FCNTL_H
/* Define if you have the <gelf.h> header file. */
#undef HAVE_GELF_H
/* Define if you have the <libelf.h> header file. */
#undef HAVE_LIBELF_H
/* Define if you have the <link.h> header file. */
#undef HAVE_LINK_H
/* Define if you have the <nlist.h> header file. */
#undef HAVE_NLIST_H
/* Define if you have the <sys/elf.h> header file. */
#undef HAVE_SYS_ELF_H
/* Define if you have the <sys/link.h> header file. */
#undef HAVE_SYS_LINK_H
/* Define if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to 1 if you have the <stdint.h> header file. */
#define HAVE_STDINT_H 1

View File

@@ -1,501 +0,0 @@
/*
* cook.c - read and translate ELF files.
* Copyright (C) 1995 - 2006 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: cook.c,v 1.29 2008/05/23 08:15:34 michael Exp $";
#endif /* lint */
const Elf_Scn _elf_scn_init = INIT_SCN;
const Scn_Data _elf_data_init = INIT_DATA;
Elf_Type
_elf_scn_type(unsigned t) {
switch (t) {
case SHT_DYNAMIC: return ELF_T_DYN;
case SHT_DYNSYM: return ELF_T_SYM;
case SHT_HASH: return ELF_T_WORD;
case SHT_REL: return ELF_T_REL;
case SHT_RELA: return ELF_T_RELA;
case SHT_SYMTAB: return ELF_T_SYM;
case SHT_SYMTAB_SHNDX: return ELF_T_WORD; /* XXX: really? */
#if __LIBELF_SYMBOL_VERSIONS
#if __LIBELF_SUN_SYMBOL_VERSIONS
case SHT_SUNW_verdef: return ELF_T_VDEF;
case SHT_SUNW_verneed: return ELF_T_VNEED;
case SHT_SUNW_versym: return ELF_T_HALF;
#else /* __LIBELF_SUN_SYMBOL_VERSIONS */
case SHT_GNU_verdef: return ELF_T_VDEF;
case SHT_GNU_verneed: return ELF_T_VNEED;
case SHT_GNU_versym: return ELF_T_HALF;
#endif /* __LIBELF_SUN_SYMBOL_VERSIONS */
#endif /* __LIBELF_SYMBOL_VERSIONS */
}
return ELF_T_BYTE;
}
/*
* Check for overflow on 32-bit systems
*/
#define overflow(a,b,t) (sizeof(a) < sizeof(t) && (t)(a) != (b))
#define truncerr(t) ((t)==ELF_T_EHDR?ERROR_TRUNC_EHDR: \
((t)==ELF_T_PHDR?ERROR_TRUNC_PHDR: \
ERROR_INTERNAL))
#define memerr(t) ((t)==ELF_T_EHDR?ERROR_MEM_EHDR: \
((t)==ELF_T_PHDR?ERROR_MEM_PHDR: \
ERROR_INTERNAL))
Elf_Data*
_elf_xlatetom(const Elf *elf, Elf_Data *dst, const Elf_Data *src) {
if (elf->e_class == ELFCLASS32) {
return elf32_xlatetom(dst, src, elf->e_encoding);
}
#if __LIBELF64
else if (elf->e_class == ELFCLASS64) {
return elf64_xlatetom(dst, src, elf->e_encoding);
}
#endif /* __LIBELF64 */
seterr(ERROR_UNIMPLEMENTED);
return NULL;
}
static char*
_elf_item(void *buf, Elf *elf, Elf_Type type, size_t off) {
Elf_Data src, dst;
elf_assert(valid_type(type));
if (off < 0 || off > elf->e_size) {
seterr(ERROR_OUTSIDE);
return NULL;
}
src.d_type = type;
src.d_version = elf->e_version;
src.d_size = _fsize(elf->e_class, src.d_version, type);
elf_assert(src.d_size);
if ((elf->e_size - off) < src.d_size) {
seterr(truncerr(type));
return NULL;
}
dst.d_version = _elf_version;
dst.d_size = _msize(elf->e_class, dst.d_version, type);
elf_assert(dst.d_size);
if (!(dst.d_buf = buf) && !(dst.d_buf = malloc(dst.d_size))) {
seterr(memerr(type));
return NULL;
}
elf_assert(elf->e_data);
if (elf->e_rawdata) {
src.d_buf = elf->e_rawdata + off;
}
else {
src.d_buf = elf->e_data + off;
}
if (_elf_xlatetom(elf, &dst, &src)) {
return (char*)dst.d_buf;
}
if (dst.d_buf != buf) {
free(dst.d_buf);
}
return NULL;
}
static int
_elf_cook_phdr(Elf *elf) {
size_t num, off, entsz;
if (elf->e_class == ELFCLASS32) {
num = ((Elf32_Ehdr*)elf->e_ehdr)->e_phnum;
off = ((Elf32_Ehdr*)elf->e_ehdr)->e_phoff;
entsz = ((Elf32_Ehdr*)elf->e_ehdr)->e_phentsize;
}
#if __LIBELF64
else if (elf->e_class == ELFCLASS64) {
num = ((Elf64_Ehdr*)elf->e_ehdr)->e_phnum;
off = ((Elf64_Ehdr*)elf->e_ehdr)->e_phoff;
entsz = ((Elf64_Ehdr*)elf->e_ehdr)->e_phentsize;
/*
* Check for overflow on 32-bit systems
*/
if (overflow(off, ((Elf64_Ehdr*)elf->e_ehdr)->e_phoff, Elf64_Off)) {
seterr(ERROR_OUTSIDE);
return 0;
}
}
#endif /* __LIBELF64 */
else {
seterr(ERROR_UNIMPLEMENTED);
return 0;
}
if (off) {
Elf_Scn *scn;
size_t size;
unsigned i;
char *p;
if (num == PN_XNUM) {
/*
* Overflow in ehdr->e_phnum.
* Get real value from first SHDR.
*/
if (!(scn = elf->e_scn_1)) {
seterr(ERROR_NOSUCHSCN);
return 0;
}
if (elf->e_class == ELFCLASS32) {
num = scn->s_shdr32.sh_info;
}
#if __LIBELF64
else if (elf->e_class == ELFCLASS64) {
num = scn->s_shdr64.sh_info;
}
#endif /* __LIBELF64 */
/* we already had this
else {
seterr(ERROR_UNIMPLEMENTED);
return 0;
}
*/
}
size = _fsize(elf->e_class, elf->e_version, ELF_T_PHDR);
elf_assert(size);
#if ENABLE_EXTENDED_FORMAT
if (entsz < size) {
#else /* ENABLE_EXTENDED_FORMAT */
if (entsz != size) {
#endif /* ENABLE_EXTENDED_FORMAT */
seterr(ERROR_EHDR_PHENTSIZE);
return 0;
}
size = _msize(elf->e_class, _elf_version, ELF_T_PHDR);
elf_assert(size);
if (!(p = malloc(num * size))) {
seterr(memerr(ELF_T_PHDR));
return 0;
}
for (i = 0; i < num; i++) {
if (!_elf_item(p + i * size, elf, ELF_T_PHDR, off + i * entsz)) {
free(p);
return 0;
}
}
elf->e_phdr = p;
elf->e_phnum = num;
}
return 1;
}
static int
_elf_cook_shdr(Elf *elf) {
size_t num, off, entsz;
if (elf->e_class == ELFCLASS32) {
num = ((Elf32_Ehdr*)elf->e_ehdr)->e_shnum;
off = ((Elf32_Ehdr*)elf->e_ehdr)->e_shoff;
entsz = ((Elf32_Ehdr*)elf->e_ehdr)->e_shentsize;
}
#if __LIBELF64
else if (elf->e_class == ELFCLASS64) {
num = ((Elf64_Ehdr*)elf->e_ehdr)->e_shnum;
off = ((Elf64_Ehdr*)elf->e_ehdr)->e_shoff;
entsz = ((Elf64_Ehdr*)elf->e_ehdr)->e_shentsize;
/*
* Check for overflow on 32-bit systems
*/
if (overflow(off, ((Elf64_Ehdr*)elf->e_ehdr)->e_shoff, Elf64_Off)) {
seterr(ERROR_OUTSIDE);
return 0;
}
}
#endif /* __LIBELF64 */
else {
seterr(ERROR_UNIMPLEMENTED);
return 0;
}
if (off) {
struct tmp {
Elf_Scn scn;
Scn_Data data;
} *head;
Elf_Data src, dst;
Elf_Scn *scn;
Scn_Data *sd;
unsigned i;
if (off < 0 || off > elf->e_size) {
seterr(ERROR_OUTSIDE);
return 0;
}
src.d_type = ELF_T_SHDR;
src.d_version = elf->e_version;
src.d_size = _fsize(elf->e_class, src.d_version, ELF_T_SHDR);
elf_assert(src.d_size);
#if ENABLE_EXTENDED_FORMAT
if (entsz < src.d_size) {
#else /* ENABLE_EXTENDED_FORMAT */
if (entsz != src.d_size) {
#endif /* ENABLE_EXTENDED_FORMAT */
seterr(ERROR_EHDR_SHENTSIZE);
return 0;
}
dst.d_version = EV_CURRENT;
if (num == 0) {
union {
Elf32_Shdr sh32;
#if __LIBELF64
Elf64_Shdr sh64;
#endif /* __LIBELF64 */
} u;
/*
* Overflow in ehdr->e_shnum.
* Get real value from first SHDR.
*/
if (elf->e_size - off < entsz) {
seterr(ERROR_TRUNC_SHDR);
return 0;
}
if (elf->e_rawdata) {
src.d_buf = elf->e_rawdata + off;
}
else {
src.d_buf = elf->e_data + off;
}
dst.d_buf = &u;
dst.d_size = sizeof(u);
if (!_elf_xlatetom(elf, &dst, &src)) {
return 0;
}
elf_assert(dst.d_size == _msize(elf->e_class, EV_CURRENT, ELF_T_SHDR));
elf_assert(dst.d_type == ELF_T_SHDR);
if (elf->e_class == ELFCLASS32) {
num = u.sh32.sh_size;
}
#if __LIBELF64
else if (elf->e_class == ELFCLASS64) {
num = u.sh64.sh_size;
/*
* Check for overflow on 32-bit systems
*/
if (overflow(num, u.sh64.sh_size, Elf64_Xword)) {
seterr(ERROR_OUTSIDE);
return 0;
}
}
#endif /* __LIBELF64 */
}
if ((elf->e_size - off) / entsz < num) {
seterr(ERROR_TRUNC_SHDR);
return 0;
}
if (!(head = (struct tmp*)malloc(num * sizeof(struct tmp)))) {
seterr(ERROR_MEM_SCN);
return 0;
}
for (scn = NULL, i = num; i-- > 0; ) {
head[i].scn = _elf_scn_init;
head[i].data = _elf_data_init;
head[i].scn.s_link = scn;
if (!scn) {
elf->e_scn_n = &head[i].scn;
}
scn = &head[i].scn;
sd = &head[i].data;
if (elf->e_rawdata) {
src.d_buf = elf->e_rawdata + off + i * entsz;
}
else {
src.d_buf = elf->e_data + off + i * entsz;
}
dst.d_buf = &scn->s_uhdr;
dst.d_size = sizeof(scn->s_uhdr);
if (!_elf_xlatetom(elf, &dst, &src)) {
elf->e_scn_n = NULL;
free(head);
return 0;
}
elf_assert(dst.d_size == _msize(elf->e_class, EV_CURRENT, ELF_T_SHDR));
elf_assert(dst.d_type == ELF_T_SHDR);
scn->s_elf = elf;
scn->s_index = i;
scn->s_data_1 = sd;
scn->s_data_n = sd;
sd->sd_scn = scn;
if (elf->e_class == ELFCLASS32) {
Elf32_Shdr *shdr = &scn->s_shdr32;
scn->s_type = shdr->sh_type;
scn->s_size = shdr->sh_size;
scn->s_offset = shdr->sh_offset;
sd->sd_data.d_align = shdr->sh_addralign;
sd->sd_data.d_type = _elf_scn_type(scn->s_type);
}
#if __LIBELF64
else if (elf->e_class == ELFCLASS64) {
Elf64_Shdr *shdr = &scn->s_shdr64;
scn->s_type = shdr->sh_type;
scn->s_size = shdr->sh_size;
scn->s_offset = shdr->sh_offset;
sd->sd_data.d_align = shdr->sh_addralign;
/*
* Check for overflow on 32-bit systems
*/
if (overflow(scn->s_size, shdr->sh_size, Elf64_Xword)
|| overflow(scn->s_offset, shdr->sh_offset, Elf64_Off)
|| overflow(sd->sd_data.d_align, shdr->sh_addralign, Elf64_Xword)) {
seterr(ERROR_OUTSIDE);
return 0;
}
sd->sd_data.d_type = _elf_scn_type(scn->s_type);
/*
* QUIRKS MODE:
*
* Some 64-bit architectures use 64-bit entries in the
* .hash section. This violates the ELF standard, and
* should be fixed. It's mostly harmless as long as the
* binary and the machine running your program have the
* same byte order, but you're in trouble if they don't,
* and if the entry size is wrong.
*
* As a workaround, I let libelf guess the right size
* for the binary. This relies pretty much on the fact
* that the binary provides correct data in the section
* headers. If it doesn't, it's probably broken anyway.
* Therefore, libelf uses a standard conforming value
* when it's not absolutely sure.
*/
if (scn->s_type == SHT_HASH) {
int override = 0;
/*
* sh_entsize must reflect the entry size
*/
if (shdr->sh_entsize == ELF64_FSZ_ADDR) {
override++;
}
/*
* sh_size must be a multiple of sh_entsize
*/
if (shdr->sh_size % ELF64_FSZ_ADDR == 0) {
override++;
}
/*
* There must be room for at least 2 entries
*/
if (shdr->sh_size >= 2 * ELF64_FSZ_ADDR) {
override++;
}
/*
* sh_addralign must be correctly set
*/
if (shdr->sh_addralign == ELF64_FSZ_ADDR) {
override++;
}
/*
* The section must be properly aligned
*/
if (shdr->sh_offset % ELF64_FSZ_ADDR == 0) {
override++;
}
/* XXX: also look at the data? */
/*
* Make a conservative decision...
*/
if (override >= 5) {
sd->sd_data.d_type = ELF_T_ADDR;
}
}
/*
* END QUIRKS MODE.
*/
}
#endif /* __LIBELF64 */
/* we already had this
else {
seterr(ERROR_UNIMPLEMENTED);
return 0;
}
*/
sd->sd_data.d_size = scn->s_size;
sd->sd_data.d_version = _elf_version;
}
elf_assert(scn == &head[0].scn);
elf->e_scn_1 = &head[0].scn;
head[0].scn.s_freeme = 1;
}
return 1;
}
static int
_elf_cook_file(Elf *elf) {
elf->e_ehdr = _elf_item(NULL, elf, ELF_T_EHDR, 0);
if (!elf->e_ehdr) {
return 0;
}
/*
* Note: _elf_cook_phdr may require the first section header!
*/
if (!_elf_cook_shdr(elf)) {
return 0;
}
if (!_elf_cook_phdr(elf)) {
return 0;
}
return 1;
}
int
_elf_cook(Elf *elf) {
elf_assert(_elf_scn_init.s_magic == SCN_MAGIC);
elf_assert(_elf_data_init.sd_magic == DATA_MAGIC);
elf_assert(elf);
elf_assert(elf->e_magic == ELF_MAGIC);
elf_assert(elf->e_kind == ELF_K_ELF);
elf_assert(!elf->e_ehdr);
if (!valid_version(elf->e_version)) {
seterr(ERROR_UNKNOWN_VERSION);
}
else if (!valid_encoding(elf->e_encoding)) {
seterr(ERROR_UNKNOWN_ENCODING);
}
else if (valid_class(elf->e_class)) {
return _elf_cook_file(elf);
}
else {
seterr(ERROR_UNKNOWN_CLASS);
}
return 0;
}

View File

@@ -1,36 +0,0 @@
/*
* data.c - libelf internal variables.
* Copyright (C) 1995 - 1998, 2007 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: data.c,v 1.8 2008/05/23 08:15:34 michael Exp $";
#endif /* lint */
unsigned _elf_version = EV_NONE;
int _elf_errno = 0;
int _elf_fill = 0;
#if ENABLE_SANITY_CHECKS
#define SANITY_CHECKS -1
#else
#define SANITY_CHECKS 0
#endif
int _elf_sanity_checks = SANITY_CHECKS;

View File

@@ -1,118 +0,0 @@
/*
* end.c - implementation of the elf_end(3) function.
* Copyright (C) 1995 - 2004 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: end.c,v 1.12 2008/05/23 08:15:34 michael Exp $";
#endif /* lint */
#if HAVE_MMAP
#include <sys/mman.h>
#endif /* HAVE_MMAP */
static void
_elf_free(void *ptr) {
if (ptr) {
free(ptr);
}
}
static void
_elf_free_scns(Elf *elf, Elf_Scn *scn) {
Scn_Data *sd, *tmp;
Elf_Scn *freescn;
for (freescn = NULL; scn; scn = scn->s_link) {
elf_assert(scn->s_magic == SCN_MAGIC);
elf_assert(scn->s_elf == elf);
for (sd = scn->s_data_1; sd; sd = tmp) {
elf_assert(sd->sd_magic == DATA_MAGIC);
elf_assert(sd->sd_scn == scn);
tmp = sd->sd_link;
if (sd->sd_free_data) {
_elf_free(sd->sd_memdata);
}
if (sd->sd_freeme) {
free(sd);
}
}
if ((sd = scn->s_rawdata)) {
elf_assert(sd->sd_magic == DATA_MAGIC);
elf_assert(sd->sd_scn == scn);
if (sd->sd_free_data) {
_elf_free(sd->sd_memdata);
}
if (sd->sd_freeme) {
free(sd);
}
}
if (scn->s_freeme) {
_elf_free(freescn);
freescn = scn;
}
}
_elf_free(freescn);
}
int
elf_end(Elf *elf) {
Elf **siblings;
if (!elf) {
return 0;
}
elf_assert(elf->e_magic == ELF_MAGIC);
if (--elf->e_count) {
return elf->e_count;
}
if (elf->e_parent) {
elf_assert(elf->e_parent->e_magic == ELF_MAGIC);
elf_assert(elf->e_parent->e_kind == ELF_K_AR);
siblings = &elf->e_parent->e_members;
while (*siblings) {
if (*siblings == elf) {
*siblings = elf->e_link;
break;
}
siblings = &(*siblings)->e_link;
}
elf_end(elf->e_parent);
_elf_free(elf->e_arhdr);
}
#if HAVE_MMAP
else if (elf->e_unmap_data) {
munmap(elf->e_data, elf->e_size);
}
#endif /* HAVE_MMAP */
else if (!elf->e_memory) {
_elf_free(elf->e_data);
}
_elf_free_scns(elf, elf->e_scn_1);
if (elf->e_rawdata != elf->e_data) {
_elf_free(elf->e_rawdata);
}
if (elf->e_free_syms) {
_elf_free(elf->e_symtab);
}
_elf_free(elf->e_ehdr);
_elf_free(elf->e_phdr);
free(elf);
return 0;
}

View File

@@ -1,77 +0,0 @@
/*
* errmsg.c - implementation of the elf_errmsg(3) function.
* Copyright (C) 1995 - 1999, 2004 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: errmsg.c,v 1.11 2008/05/23 08:15:34 michael Exp $";
#endif /* lint */
#if HAVE_DGETTEXT
# undef HAVE_CATGETS
# include <libintl.h>
#else /* HAVE_DGETTEXT */
# define dgettext(dom, str) str
#endif /* HAVE_DGETTEXT */
#if HAVE_CATGETS
# include <nl_types.h>
static nl_catd _libelf_cat = (nl_catd)0;
#endif /* HAVE_CATGETS */
#if HAVE_DGETTEXT || HAVE_CATGETS
static const char domain[] = "libelf";
#endif /* HAVE_DGETTEXT || HAVE_CATGETS */
#if PIC
static const char *_messages[] = {
#else /* PIC */
static const char *const _messages[] = {
#endif /* PIC */
#define __err__(a,b) b,
#include <errors.h> /* include string tables from errors.h */
#undef __err__
};
const char*
elf_errmsg(int err) {
if (err == 0) {
err = _elf_errno;
if (err == 0) {
return NULL;
}
}
else if (err == -1) {
err = _elf_errno;
}
if (err < 0 || err >= ERROR_NUM || _messages[err] == NULL) {
err = ERROR_UNKNOWN;
}
#if HAVE_CATGETS
if (_libelf_cat == (nl_catd)0) {
_libelf_cat = catopen(domain, 0);
}
if (_libelf_cat != (nl_catd)-1) {
return catgets(_libelf_cat, 1, err + 1, _messages[err]);
}
#endif /* HAVE_CATGETS */
return dgettext(domain, _messages[err]);
}

View File

@@ -1,32 +0,0 @@
/*
errno.c - implementation of the elf_errno(3) function.
Copyright (C) 1995 - 1998 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: errno.c,v 1.7 2008/05/23 08:15:34 michael Exp $";
#endif /* lint */
int
elf_errno(void) {
int tmp = _elf_errno;
_elf_errno = 0;
return tmp;
}

View File

@@ -1,100 +0,0 @@
/*
* errors.h - exhaustive list of all error codes and messages for libelf.
* Copyright (C) 1995 - 2003, 2006 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* @(#) $Id: errors.h,v 1.18 2008/05/23 08:15:34 michael Exp $ */
/* dummy for xgettext */
#define _(str) str
__err__(ERROR_OK, _("no error"))
__err__(ERROR_UNKNOWN, _("unknown error"))
__err__(ERROR_INTERNAL, _("Internal error: unknown reason"))
__err__(ERROR_UNIMPLEMENTED, _("Internal error: not implemented"))
__err__(ERROR_WRONLY, _("Request error: cntl(ELF_C_FDREAD) on write-only file"))
__err__(ERROR_INVALID_CMD, _("Request error: invalid ELF_C_* argument"))
__err__(ERROR_FDDISABLED, _("Request error: file descriptor disabled"))
__err__(ERROR_NOTARCHIVE, _("Request error: not an archive"))
__err__(ERROR_BADOFF, _("Request error: offset out of range"))
__err__(ERROR_UNKNOWN_VERSION, _("Request error: unknown ELF version"))
__err__(ERROR_CMDMISMATCH, _("Request error: ELF_C_* argument does not match"))
__err__(ERROR_MEMBERWRITE, _("Request error: archive member begin() for writing"))
__err__(ERROR_FDMISMATCH, _("Request error: archive/member file descriptor mismatch"))
__err__(ERROR_NOTELF, _("Request error: not an ELF file"))
__err__(ERROR_CLASSMISMATCH, _("Request error: class file/memory mismatch"))
__err__(ERROR_UNKNOWN_TYPE, _("Request error: invalid ELF_T_* argument"))
__err__(ERROR_UNKNOWN_ENCODING, _("Request error: unknown data encoding"))
__err__(ERROR_DST2SMALL, _("Request error: destination buffer too small"))
__err__(ERROR_NULLBUF, _("Request error: d_buf is NULL"))
__err__(ERROR_UNKNOWN_CLASS, _("Request error: unknown ELF class"))
__err__(ERROR_ELFSCNMISMATCH, _("Request error: section does not belong to file"))
__err__(ERROR_NOSUCHSCN, _("Request error: no section at index"))
__err__(ERROR_NULLSCN, _("Request error: can't manipulate null section"))
__err__(ERROR_SCNDATAMISMATCH, _("Request error: data does not belong to section"))
__err__(ERROR_NOSTRTAB, _("Request error: no string table"))
__err__(ERROR_BADSTROFF, _("Request error: string table offset out of range"))
__err__(ERROR_RDONLY, _("Request error: update(ELF_C_WRITE) on read-only file"))
__err__(ERROR_IO_SEEK, _("I/O error: seek"))
__err__(ERROR_IO_2BIG, _("I/O error: file too big for memory"))
__err__(ERROR_IO_READ, _("I/O error: raw read"))
__err__(ERROR_IO_GETSIZE, _("I/O error: get file size"))
__err__(ERROR_IO_WRITE, _("I/O error: output write"))
__err__(ERROR_IO_TRUNC, _("I/O error: can't truncate output file"))
__err__(ERROR_VERSION_UNSET, _("Sequence error: must set ELF version first"))
__err__(ERROR_NOEHDR, _("Sequence error: must create ELF header first"))
__err__(ERROR_OUTSIDE, _("Format error: reference outside file"))
__err__(ERROR_TRUNC_ARHDR, _("Format error: archive header truncated"))
__err__(ERROR_ARFMAG, _("Format error: archive fmag"))
__err__(ERROR_ARHDR, _("Format error: archive header"))
__err__(ERROR_TRUNC_MEMBER, _("Format error: archive member truncated"))
__err__(ERROR_SIZE_ARSYMTAB, _("Format error: archive symbol table size"))
__err__(ERROR_ARSTRTAB, _("Format error: archive string table"))
__err__(ERROR_ARSPECIAL, _("Format error: archive special name unknown"))
__err__(ERROR_TRUNC_EHDR, _("Format error: ELF header truncated"))
__err__(ERROR_TRUNC_PHDR, _("Format error: program header table truncated"))
__err__(ERROR_TRUNC_SHDR, _("Format error: section header table truncated"))
__err__(ERROR_TRUNC_SCN, _("Format error: data region truncated"))
__err__(ERROR_ALIGN_PHDR, _("Format error: program header table alignment"))
__err__(ERROR_ALIGN_SHDR, _("Format error: section header table alignment"))
__err__(ERROR_VERDEF_FORMAT, _("Format error: bad parameter in Verdef record"))
__err__(ERROR_VERDEF_VERSION, _("Format error: unknown Verdef version"))
__err__(ERROR_VERNEED_FORMAT, _("Format error: bad parameter in Verneed record"))
__err__(ERROR_VERNEED_VERSION, _("Format error: unknown Verneed version"))
__err__(ERROR_EHDR_SHNUM, _("Format error: bad e_shnum value"))
__err__(ERROR_EHDR_SHENTSIZE, _("Format error: bad e_shentsize value"))
__err__(ERROR_EHDR_PHENTSIZE, _("Format error: bad e_phentsize value"))
__err__(ERROR_UNTERM, _("Format error: unterminated string in string table"))
__err__(ERROR_SCN2SMALL, _("Layout error: section size too small for data"))
__err__(ERROR_SCN_OVERLAP, _("Layout error: overlapping sections"))
__err__(ERROR_MEM_ELF, _("Memory error: elf descriptor"))
__err__(ERROR_MEM_ARSYMTAB, _("Memory error: archive symbol table"))
__err__(ERROR_MEM_ARHDR, _("Memory error: archive member header"))
__err__(ERROR_MEM_EHDR, _("Memory error: ELF header"))
__err__(ERROR_MEM_PHDR, _("Memory error: program header table"))
__err__(ERROR_MEM_SHDR, _("Memory error: section header table"))
__err__(ERROR_MEM_SCN, _("Memory error: section descriptor"))
__err__(ERROR_MEM_SCNDATA, _("Memory error: section data"))
__err__(ERROR_MEM_OUTBUF, _("Memory error: output file space"))
__err__(ERROR_MEM_TEMPORARY, _("Memory error: temporary buffer"))
__err__(ERROR_BADVALUE, _("GElf error: value out of range"))
__err__(ERROR_BADINDEX, _("GElf error: index out of range"))
__err__(ERROR_BADTYPE, _("GElf error: type mismatch"))
__err__(ERROR_MEM_SYM, _("GElf error: not enough memory for GElf_Sym"))
__err__(ERROR_MEM_DYN, _("GElf error: not enough memory for GElf_Dyn"))
__err__(ERROR_MEM_RELA, _("GElf error: not enough memory for GElf_Rela"))
__err__(ERROR_MEM_REL, _("GElf error: not enough memory for GElf_Rel"))

View File

@@ -1,334 +0,0 @@
/*
ext_types.h - external representation of ELF data types.
Copyright (C) 1995 - 1998 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* @(#) $Id: ext_types.h,v 1.9 2008/05/23 08:15:34 michael Exp $ */
#ifndef _EXT_TYPES_H
#define _EXT_TYPES_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/*
* Scalar data types
*/
typedef unsigned char __ext_Elf32_Addr [ELF32_FSZ_ADDR];
typedef unsigned char __ext_Elf32_Half [ELF32_FSZ_HALF];
typedef unsigned char __ext_Elf32_Off [ELF32_FSZ_OFF];
typedef unsigned char __ext_Elf32_Sword [ELF32_FSZ_SWORD];
typedef unsigned char __ext_Elf32_Word [ELF32_FSZ_WORD];
#if __LIBELF64
typedef unsigned char __ext_Elf32_Lword [8];
typedef unsigned char __ext_Elf64_Addr [ELF64_FSZ_ADDR];
typedef unsigned char __ext_Elf64_Half [ELF64_FSZ_HALF];
typedef unsigned char __ext_Elf64_Off [ELF64_FSZ_OFF];
typedef unsigned char __ext_Elf64_Sword [ELF64_FSZ_SWORD];
typedef unsigned char __ext_Elf64_Word [ELF64_FSZ_WORD];
typedef unsigned char __ext_Elf64_Sxword[ELF64_FSZ_SXWORD];
typedef unsigned char __ext_Elf64_Xword [ELF64_FSZ_XWORD];
typedef unsigned char __ext_Elf64_Lword [8];
#endif /* __LIBELF64 */
/*
* ELF header
*/
typedef struct {
unsigned char e_ident[EI_NIDENT];
__ext_Elf32_Half e_type;
__ext_Elf32_Half e_machine;
__ext_Elf32_Word e_version;
__ext_Elf32_Addr e_entry;
__ext_Elf32_Off e_phoff;
__ext_Elf32_Off e_shoff;
__ext_Elf32_Word e_flags;
__ext_Elf32_Half e_ehsize;
__ext_Elf32_Half e_phentsize;
__ext_Elf32_Half e_phnum;
__ext_Elf32_Half e_shentsize;
__ext_Elf32_Half e_shnum;
__ext_Elf32_Half e_shstrndx;
} __ext_Elf32_Ehdr;
#if __LIBELF64
typedef struct {
unsigned char e_ident[EI_NIDENT];
__ext_Elf64_Half e_type;
__ext_Elf64_Half e_machine;
__ext_Elf64_Word e_version;
__ext_Elf64_Addr e_entry;
__ext_Elf64_Off e_phoff;
__ext_Elf64_Off e_shoff;
__ext_Elf64_Word e_flags;
__ext_Elf64_Half e_ehsize;
__ext_Elf64_Half e_phentsize;
__ext_Elf64_Half e_phnum;
__ext_Elf64_Half e_shentsize;
__ext_Elf64_Half e_shnum;
__ext_Elf64_Half e_shstrndx;
} __ext_Elf64_Ehdr;
#endif /* __LIBELF64 */
/*
* Section header
*/
typedef struct {
__ext_Elf32_Word sh_name;
__ext_Elf32_Word sh_type;
__ext_Elf32_Word sh_flags;
__ext_Elf32_Addr sh_addr;
__ext_Elf32_Off sh_offset;
__ext_Elf32_Word sh_size;
__ext_Elf32_Word sh_link;
__ext_Elf32_Word sh_info;
__ext_Elf32_Word sh_addralign;
__ext_Elf32_Word sh_entsize;
} __ext_Elf32_Shdr;
#if __LIBELF64
typedef struct {
__ext_Elf64_Word sh_name;
__ext_Elf64_Word sh_type;
__ext_Elf64_Xword sh_flags;
__ext_Elf64_Addr sh_addr;
__ext_Elf64_Off sh_offset;
__ext_Elf64_Xword sh_size;
__ext_Elf64_Word sh_link;
__ext_Elf64_Word sh_info;
__ext_Elf64_Xword sh_addralign;
__ext_Elf64_Xword sh_entsize;
} __ext_Elf64_Shdr;
#endif /* __LIBELF64 */
/*
* Symbol table
*/
typedef struct {
__ext_Elf32_Word st_name;
__ext_Elf32_Addr st_value;
__ext_Elf32_Word st_size;
unsigned char st_info;
unsigned char st_other;
__ext_Elf32_Half st_shndx;
} __ext_Elf32_Sym;
#if __LIBELF64
typedef struct {
__ext_Elf64_Word st_name;
unsigned char st_info;
unsigned char st_other;
__ext_Elf64_Half st_shndx;
__ext_Elf64_Addr st_value;
__ext_Elf64_Xword st_size;
} __ext_Elf64_Sym;
#endif /* __LIBELF64 */
/*
* Relocation
*/
typedef struct {
__ext_Elf32_Addr r_offset;
__ext_Elf32_Word r_info;
} __ext_Elf32_Rel;
typedef struct {
__ext_Elf32_Addr r_offset;
__ext_Elf32_Word r_info;
__ext_Elf32_Sword r_addend;
} __ext_Elf32_Rela;
#if __LIBELF64
typedef struct {
__ext_Elf64_Addr r_offset;
#if __LIBELF64_IRIX
__ext_Elf64_Word r_sym;
unsigned char r_ssym;
unsigned char r_type3;
unsigned char r_type2;
unsigned char r_type;
#else /* __LIBELF64_IRIX */
__ext_Elf64_Xword r_info;
#endif /* __LIBELF64_IRIX */
} __ext_Elf64_Rel;
typedef struct {
__ext_Elf64_Addr r_offset;
#if __LIBELF64_IRIX
__ext_Elf64_Word r_sym;
unsigned char r_ssym;
unsigned char r_type3;
unsigned char r_type2;
unsigned char r_type;
#else /* __LIBELF64_IRIX */
__ext_Elf64_Xword r_info;
#endif /* __LIBELF64_IRIX */
__ext_Elf64_Sxword r_addend;
} __ext_Elf64_Rela;
#endif /* __LIBELF64 */
/*
* Program header
*/
typedef struct {
__ext_Elf32_Word p_type;
__ext_Elf32_Off p_offset;
__ext_Elf32_Addr p_vaddr;
__ext_Elf32_Addr p_paddr;
__ext_Elf32_Word p_filesz;
__ext_Elf32_Word p_memsz;
__ext_Elf32_Word p_flags;
__ext_Elf32_Word p_align;
} __ext_Elf32_Phdr;
#if __LIBELF64
typedef struct {
__ext_Elf64_Word p_type;
__ext_Elf64_Word p_flags;
__ext_Elf64_Off p_offset;
__ext_Elf64_Addr p_vaddr;
__ext_Elf64_Addr p_paddr;
__ext_Elf64_Xword p_filesz;
__ext_Elf64_Xword p_memsz;
__ext_Elf64_Xword p_align;
} __ext_Elf64_Phdr;
#endif /* __LIBELF64 */
/*
* Dynamic structure
*/
typedef struct {
__ext_Elf32_Sword d_tag;
union {
__ext_Elf32_Word d_val;
__ext_Elf32_Addr d_ptr;
} d_un;
} __ext_Elf32_Dyn;
#if __LIBELF64
typedef struct {
__ext_Elf64_Sxword d_tag;
union {
__ext_Elf64_Xword d_val;
__ext_Elf64_Addr d_ptr;
} d_un;
} __ext_Elf64_Dyn;
#endif /* __LIBELF64 */
/*
* Version definitions
*/
typedef struct {
__ext_Elf32_Half vd_version;
__ext_Elf32_Half vd_flags;
__ext_Elf32_Half vd_ndx;
__ext_Elf32_Half vd_cnt;
__ext_Elf32_Word vd_hash;
__ext_Elf32_Word vd_aux;
__ext_Elf32_Word vd_next;
} __ext_Elf32_Verdef;
typedef struct {
__ext_Elf32_Word vda_name;
__ext_Elf32_Word vda_next;
} __ext_Elf32_Verdaux;
typedef struct {
__ext_Elf32_Half vn_version;
__ext_Elf32_Half vn_cnt;
__ext_Elf32_Word vn_file;
__ext_Elf32_Word vn_aux;
__ext_Elf32_Word vn_next;
} __ext_Elf32_Verneed;
typedef struct {
__ext_Elf32_Word vna_hash;
__ext_Elf32_Half vna_flags;
__ext_Elf32_Half vna_other;
__ext_Elf32_Word vna_name;
__ext_Elf32_Word vna_next;
} __ext_Elf32_Vernaux;
#if __LIBELF64
typedef struct {
__ext_Elf64_Half vd_version;
__ext_Elf64_Half vd_flags;
__ext_Elf64_Half vd_ndx;
__ext_Elf64_Half vd_cnt;
__ext_Elf64_Word vd_hash;
__ext_Elf64_Word vd_aux;
__ext_Elf64_Word vd_next;
} __ext_Elf64_Verdef;
typedef struct {
__ext_Elf64_Word vda_name;
__ext_Elf64_Word vda_next;
} __ext_Elf64_Verdaux;
typedef struct {
__ext_Elf64_Half vn_version;
__ext_Elf64_Half vn_cnt;
__ext_Elf64_Word vn_file;
__ext_Elf64_Word vn_aux;
__ext_Elf64_Word vn_next;
} __ext_Elf64_Verneed;
typedef struct {
__ext_Elf64_Word vna_hash;
__ext_Elf64_Half vna_flags;
__ext_Elf64_Half vna_other;
__ext_Elf64_Word vna_name;
__ext_Elf64_Word vna_next;
} __ext_Elf64_Vernaux;
#endif /* __LIBELF64 */
/*
* Move section
*/
#if __LIBELF64
typedef struct {
__ext_Elf32_Lword m_value;
__ext_Elf32_Word m_info;
__ext_Elf32_Word m_poffset;
__ext_Elf32_Half m_repeat;
__ext_Elf32_Half m_stride;
} __ext_Elf32_Move;
typedef struct {
__ext_Elf64_Lword m_value;
__ext_Elf64_Xword m_info;
__ext_Elf64_Xword m_poffset;
__ext_Elf64_Half m_repeat;
__ext_Elf64_Half m_stride;
} __ext_Elf64_Move;
#endif /* __LIBELF64 */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _EXT_TYPES_H */

View File

@@ -1,29 +0,0 @@
/*
fill.c - implementation of the elf_fill(3) function.
Copyright (C) 1995 - 1998 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: fill.c,v 1.7 2008/05/23 08:15:34 michael Exp $";
#endif /* lint */
void
elf_fill(int fill) {
_elf_fill = fill;
}

View File

@@ -1,92 +0,0 @@
/*
flag.c - implementation of the elf_flag*(3) functions.
Copyright (C) 1995 - 1998 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: flag.c,v 1.7 2008/05/23 08:15:34 michael Exp $";
#endif /* lint */
static unsigned
_elf_flag(unsigned *f, Elf_Cmd cmd, unsigned flags) {
if (cmd == ELF_C_SET) {
return *f |= flags;
}
if (cmd == ELF_C_CLR) {
return *f &= ~flags;
}
seterr(ERROR_INVALID_CMD);
return 0;
}
unsigned
elf_flagdata(Elf_Data *data, Elf_Cmd cmd, unsigned flags) {
Scn_Data *sd = (Scn_Data*)data;
if (!sd) {
return 0;
}
elf_assert(sd->sd_magic == DATA_MAGIC);
return _elf_flag(&sd->sd_data_flags, cmd, flags);
}
unsigned
elf_flagehdr(Elf *elf, Elf_Cmd cmd, unsigned flags) {
if (!elf) {
return 0;
}
elf_assert(elf->e_magic == ELF_MAGIC);
return _elf_flag(&elf->e_ehdr_flags, cmd, flags);
}
unsigned
elf_flagelf(Elf *elf, Elf_Cmd cmd, unsigned flags) {
if (!elf) {
return 0;
}
elf_assert(elf->e_magic == ELF_MAGIC);
return _elf_flag(&elf->e_elf_flags, cmd, flags);
}
unsigned
elf_flagphdr(Elf *elf, Elf_Cmd cmd, unsigned flags) {
if (!elf) {
return 0;
}
elf_assert(elf->e_magic == ELF_MAGIC);
return _elf_flag(&elf->e_phdr_flags, cmd, flags);
}
unsigned
elf_flagscn(Elf_Scn *scn, Elf_Cmd cmd, unsigned flags) {
if (!scn) {
return 0;
}
elf_assert(scn->s_magic == SCN_MAGIC);
return _elf_flag(&scn->s_scn_flags, cmd, flags);
}
unsigned
elf_flagshdr(Elf_Scn *scn, Elf_Cmd cmd, unsigned flags) {
if (!scn) {
return 0;
}
elf_assert(scn->s_magic == SCN_MAGIC);
return _elf_flag(&scn->s_shdr_flags, cmd, flags);
}

View File

@@ -1,155 +0,0 @@
/*
* gelf.h - public header file for libelf.
* Copyright (C) 2000 - 2006 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* @(#) $Id: gelf.h,v 1.16 2008/05/23 08:15:34 michael Exp $ */
#ifndef _GELF_H
#define _GELF_H
#if __LIBELF_INTERNAL__
#include <libelf.h>
#else /* __LIBELF_INTERNAL__ */
#include <libelf/libelf.h>
#endif /* __LIBELF_INTERNAL__ */
#if __LIBELF_NEED_LINK_H
#include <link.h>
#elif __LIBELF_NEED_SYS_LINK_H
#include <sys/link.h>
#endif /* __LIBELF_NEED_LINK_H */
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#ifndef __P
# if (__STDC__ + 0) || defined(__cplusplus) || defined(_WIN32)
# define __P(args) args
# else /* __STDC__ || defined(__cplusplus) */
# define __P(args) ()
# endif /* __STDC__ || defined(__cplusplus) */
#endif /* __P */
#if !__LIBELF64
#error "GElf is not supported on this system."
#else /* __LIBELF64 */
typedef Elf64_Addr GElf_Addr;
typedef Elf64_Half GElf_Half;
typedef Elf64_Off GElf_Off;
typedef Elf64_Sword GElf_Sword;
typedef Elf64_Word GElf_Word;
typedef Elf64_Sxword GElf_Sxword;
typedef Elf64_Xword GElf_Xword;
typedef Elf64_Ehdr GElf_Ehdr;
typedef Elf64_Phdr GElf_Phdr;
typedef Elf64_Shdr GElf_Shdr;
typedef Elf64_Dyn GElf_Dyn;
typedef Elf64_Rel GElf_Rel;
typedef Elf64_Rela GElf_Rela;
typedef Elf64_Sym GElf_Sym;
/*
* Symbol versioning
*/
#if __LIBELF_SYMBOL_VERSIONS
typedef Elf64_Verdef GElf_Verdef;
typedef Elf64_Verneed GElf_Verneed;
typedef Elf64_Verdaux GElf_Verdaux;
typedef Elf64_Vernaux GElf_Vernaux;
#endif /* __LIBELF_SYMBOL_VERSIONS */
/*
* These types aren't implemented (yet)
*
typedef Elf64_Move GElf_Move;
typedef Elf64_Syminfo GElf_Syminfo;
*/
/*
* Generic macros
*/
#define GELF_ST_BIND ELF64_ST_BIND
#define GELF_ST_TYPE ELF64_ST_TYPE
#define GELF_ST_INFO ELF64_ST_INFO
#define GELF_R_TYPE ELF64_R_TYPE
#define GELF_R_SYM ELF64_R_SYM
#define GELF_R_INFO ELF64_R_INFO
/*
* Function declarations
*/
extern int gelf_getclass __P((Elf *__elf));
extern size_t gelf_fsize __P((Elf *__elf, Elf_Type __type, size_t __count, unsigned __ver));
extern Elf_Data *gelf_xlatetof __P((Elf *__elf, Elf_Data *__dst, const Elf_Data *__src, unsigned __encode));
extern Elf_Data *gelf_xlatetom __P((Elf *__elf, Elf_Data *__dst, const Elf_Data *__src, unsigned __encode));
extern GElf_Ehdr *gelf_getehdr __P((Elf *__elf, GElf_Ehdr *__dst));
extern int gelf_update_ehdr __P((Elf *__elf, GElf_Ehdr *__src));
extern unsigned long gelf_newehdr __P((Elf *__elf, int __elfclass));
extern GElf_Phdr *gelf_getphdr __P((Elf *__elf, int ndx, GElf_Phdr *__dst));
extern int gelf_update_phdr __P((Elf *__elf, int ndx, GElf_Phdr *__src));
extern unsigned long gelf_newphdr __P((Elf *__elf, size_t __phnum));
extern GElf_Shdr *gelf_getshdr __P((Elf_Scn *__scn, GElf_Shdr *__dst));
extern int gelf_update_shdr __P((Elf_Scn *__scn, GElf_Shdr *__src));
extern GElf_Dyn *gelf_getdyn __P((Elf_Data *__src, int __ndx, GElf_Dyn *__dst));
extern int gelf_update_dyn __P((Elf_Data *__dst, int __ndx, GElf_Dyn *__src));
extern GElf_Rel *gelf_getrel __P((Elf_Data *__src, int __ndx, GElf_Rel *__dst));
extern int gelf_update_rel __P((Elf_Data *__dst, int __ndx, GElf_Rel *__src));
extern GElf_Rela *gelf_getrela __P((Elf_Data *__src, int __ndx, GElf_Rela *__dst));
extern int gelf_update_rela __P((Elf_Data *__dst, int __ndx, GElf_Rela *__src));
extern GElf_Sym *gelf_getsym __P((Elf_Data *__src, int __ndx, GElf_Sym *__dst));
extern int gelf_update_sym __P((Elf_Data *__dst, int __ndx, GElf_Sym *__src));
extern long gelf_checksum __P((Elf *__elf));
/*
* These functions aren't implemented (yet)
*
extern GElf_Move *gelf_getmove __P((Elf_Data *__src, int __ndx, GElf_Move *__src));
extern int gelf_update_move __P((Elf_Data *__dst, int __ndx, GElf_Move *__src));
*
extern GElf_Syminfo* gelf_getsyminfo __P((Elf_Data *__src, int __ndx, GElf_Syminfo *__dst));
extern int gelf_update_syminfo __P((Elf_Data *__dst, int __ndx, GElf_Syminfo *__src));
*/
/*
* Extensions (not available in other versions of libelf)
*/
extern size_t gelf_msize __P((Elf *__elf, Elf_Type __type, size_t __count, unsigned __ver));
#endif /* __LIBELF64 */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _GELF_H */

View File

@@ -1,140 +0,0 @@
/*
* gelfehdr.c - gelf_* translation functions.
* Copyright (C) 2000 - 2006 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#if __LIBELF64
#ifndef lint
static const char rcsid[] = "@(#) $Id: gelfehdr.c,v 1.9 2008/05/23 08:15:34 michael Exp $";
#endif /* lint */
#define check_and_copy(type, d, s, name, eret) \
do { \
if (sizeof((d)->name) < sizeof((s)->name) \
&& (type)(s)->name != (s)->name) { \
seterr(ERROR_BADVALUE); \
return (eret); \
} \
(d)->name = (type)(s)->name; \
} while (0)
GElf_Ehdr*
gelf_getehdr(Elf *elf, GElf_Ehdr *dst) {
GElf_Ehdr buf;
char *tmp;
if (!elf) {
return NULL;
}
elf_assert(elf->e_magic == ELF_MAGIC);
tmp = _elf_getehdr(elf, elf->e_class);
if (!tmp) {
return NULL;
}
if (!dst) {
dst = &buf;
}
if (elf->e_class == ELFCLASS64) {
*dst = *(Elf64_Ehdr*)tmp;
}
else if (elf->e_class == ELFCLASS32) {
Elf32_Ehdr *src = (Elf32_Ehdr*)tmp;
memcpy(dst->e_ident, src->e_ident, EI_NIDENT);
check_and_copy(GElf_Half, dst, src, e_type, NULL);
check_and_copy(GElf_Half, dst, src, e_machine, NULL);
check_and_copy(GElf_Word, dst, src, e_version, NULL);
check_and_copy(GElf_Addr, dst, src, e_entry, NULL);
check_and_copy(GElf_Off, dst, src, e_phoff, NULL);
check_and_copy(GElf_Off, dst, src, e_shoff, NULL);
check_and_copy(GElf_Word, dst, src, e_flags, NULL);
check_and_copy(GElf_Half, dst, src, e_ehsize, NULL);
check_and_copy(GElf_Half, dst, src, e_phentsize, NULL);
check_and_copy(GElf_Half, dst, src, e_phnum, NULL);
check_and_copy(GElf_Half, dst, src, e_shentsize, NULL);
check_and_copy(GElf_Half, dst, src, e_shnum, NULL);
check_and_copy(GElf_Half, dst, src, e_shstrndx, NULL);
}
else {
if (valid_class(elf->e_class)) {
seterr(ERROR_UNIMPLEMENTED);
}
else {
seterr(ERROR_UNKNOWN_CLASS);
}
return NULL;
}
if (dst == &buf) {
dst = (GElf_Ehdr*)malloc(sizeof(GElf_Ehdr));
if (!dst) {
seterr(ERROR_MEM_EHDR);
return NULL;
}
*dst = buf;
}
return dst;
}
int
gelf_update_ehdr(Elf *elf, GElf_Ehdr *src) {
char *tmp;
if (!elf || !src) {
return 0;
}
elf_assert(elf->e_magic == ELF_MAGIC);
tmp = _elf_getehdr(elf, elf->e_class);
if (!tmp) {
return 0;
}
if (elf->e_class == ELFCLASS64) {
*(Elf64_Ehdr*)tmp = *src;
}
else if (elf->e_class == ELFCLASS32) {
Elf32_Ehdr *dst = (Elf32_Ehdr*)tmp;
memcpy(dst->e_ident, src->e_ident, EI_NIDENT);
check_and_copy(Elf32_Half, dst, src, e_type, 0);
check_and_copy(Elf32_Half, dst, src, e_machine, 0);
check_and_copy(Elf32_Word, dst, src, e_version, 0);
check_and_copy(Elf32_Addr, dst, src, e_entry, 0);
check_and_copy(Elf32_Off, dst, src, e_phoff, 0);
check_and_copy(Elf32_Off, dst, src, e_shoff, 0);
check_and_copy(Elf32_Word, dst, src, e_flags, 0);
check_and_copy(Elf32_Half, dst, src, e_ehsize, 0);
check_and_copy(Elf32_Half, dst, src, e_phentsize, 0);
check_and_copy(Elf32_Half, dst, src, e_phnum, 0);
check_and_copy(Elf32_Half, dst, src, e_shentsize, 0);
check_and_copy(Elf32_Half, dst, src, e_shnum, 0);
check_and_copy(Elf32_Half, dst, src, e_shstrndx, 0);
}
else {
if (valid_class(elf->e_class)) {
seterr(ERROR_UNIMPLEMENTED);
}
else {
seterr(ERROR_UNKNOWN_CLASS);
}
return 0;
}
return 1;
}
#endif /* __LIBELF64 */

View File

@@ -1,148 +0,0 @@
/*
* gelfphdr.c - gelf_* translation functions.
* Copyright (C) 2000 - 2006 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#if __LIBELF64
#ifndef lint
static const char rcsid[] = "@(#) $Id: gelfphdr.c,v 1.9 2008/05/23 08:15:34 michael Exp $";
#endif /* lint */
#define check_and_copy(type, d, s, name, eret) \
do { \
if (sizeof((d)->name) < sizeof((s)->name) \
&& (type)(s)->name != (s)->name) { \
seterr(ERROR_BADVALUE); \
return (eret); \
} \
(d)->name = (type)(s)->name; \
} while (0)
GElf_Phdr*
gelf_getphdr(Elf *elf, int ndx, GElf_Phdr *dst) {
GElf_Phdr buf;
char *tmp;
size_t n;
if (!elf) {
return NULL;
}
elf_assert(elf->e_magic == ELF_MAGIC);
tmp = _elf_getphdr(elf, elf->e_class);
if (!tmp) {
return NULL;
}
if (ndx < 0 || ndx >= elf->e_phnum) {
seterr(ERROR_BADINDEX);
return NULL;
}
n = _msize(elf->e_class, _elf_version, ELF_T_PHDR);
if (n == 0) {
seterr(ERROR_UNIMPLEMENTED);
return NULL;
}
if (!dst) {
dst = &buf;
}
if (elf->e_class == ELFCLASS64) {
*dst = *(Elf64_Phdr*)(tmp + ndx * n);
}
else if (elf->e_class == ELFCLASS32) {
Elf32_Phdr *src = (Elf32_Phdr*)(tmp + ndx * n);
check_and_copy(GElf_Word, dst, src, p_type, NULL);
check_and_copy(GElf_Word, dst, src, p_flags, NULL);
check_and_copy(GElf_Off, dst, src, p_offset, NULL);
check_and_copy(GElf_Addr, dst, src, p_vaddr, NULL);
check_and_copy(GElf_Addr, dst, src, p_paddr, NULL);
check_and_copy(GElf_Xword, dst, src, p_filesz, NULL);
check_and_copy(GElf_Xword, dst, src, p_memsz, NULL);
check_and_copy(GElf_Xword, dst, src, p_align, NULL);
}
else {
if (valid_class(elf->e_class)) {
seterr(ERROR_UNIMPLEMENTED);
}
else {
seterr(ERROR_UNKNOWN_CLASS);
}
return NULL;
}
if (dst == &buf) {
dst = (GElf_Phdr*)malloc(sizeof(GElf_Phdr));
if (!dst) {
seterr(ERROR_MEM_PHDR);
return NULL;
}
*dst = buf;
}
return dst;
}
int
gelf_update_phdr(Elf *elf, int ndx, GElf_Phdr *src) {
char *tmp;
size_t n;
if (!elf || !src) {
return 0;
}
elf_assert(elf->e_magic == ELF_MAGIC);
tmp = _elf_getphdr(elf, elf->e_class);
if (!tmp) {
return 0;
}
if (ndx < 0 || ndx >= elf->e_phnum) {
seterr(ERROR_BADINDEX);
return 0;
}
n = _msize(elf->e_class, _elf_version, ELF_T_PHDR);
if (n == 0) {
seterr(ERROR_UNIMPLEMENTED);
return 0;
}
if (elf->e_class == ELFCLASS64) {
*(Elf64_Phdr*)(tmp + ndx * n) = *src;
}
else if (elf->e_class == ELFCLASS32) {
Elf32_Phdr *dst = (Elf32_Phdr*)(tmp + ndx * n);
check_and_copy(Elf32_Word, dst, src, p_type, 0);
check_and_copy(Elf32_Off, dst, src, p_offset, 0);
check_and_copy(Elf32_Addr, dst, src, p_vaddr, 0);
check_and_copy(Elf32_Addr, dst, src, p_paddr, 0);
check_and_copy(Elf32_Word, dst, src, p_filesz, 0);
check_and_copy(Elf32_Word, dst, src, p_memsz, 0);
check_and_copy(Elf32_Word, dst, src, p_flags, 0);
check_and_copy(Elf32_Word, dst, src, p_align, 0);
}
else {
if (valid_class(elf->e_class)) {
seterr(ERROR_UNIMPLEMENTED);
}
else {
seterr(ERROR_UNKNOWN_CLASS);
}
return 0;
}
return 1;
}
#endif /* __LIBELF64 */

View File

@@ -1,125 +0,0 @@
/*
* gelfshdr.c - gelf_* translation functions.
* Copyright (C) 2000 - 2006 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#if __LIBELF64
#ifndef lint
static const char rcsid[] = "@(#) $Id: gelfshdr.c,v 1.10 2008/05/23 08:15:34 michael Exp $";
#endif /* lint */
#define check_and_copy(type, d, s, name, eret) \
do { \
if (sizeof((d)->name) < sizeof((s)->name) \
&& (type)(s)->name != (s)->name) { \
seterr(ERROR_BADVALUE); \
return (eret); \
} \
(d)->name = (type)(s)->name; \
} while (0)
GElf_Shdr*
gelf_getshdr(Elf_Scn *scn, GElf_Shdr *dst) {
GElf_Shdr buf;
if (!scn) {
return NULL;
}
elf_assert(scn->s_magic == SCN_MAGIC);
elf_assert(scn->s_elf);
elf_assert(scn->s_elf->e_magic == ELF_MAGIC);
if (!dst) {
dst = &buf;
}
if (scn->s_elf->e_class == ELFCLASS64) {
*dst = scn->s_shdr64;
}
else if (scn->s_elf->e_class == ELFCLASS32) {
Elf32_Shdr *src = &scn->s_shdr32;
check_and_copy(GElf_Word, dst, src, sh_name, NULL);
check_and_copy(GElf_Word, dst, src, sh_type, NULL);
check_and_copy(GElf_Xword, dst, src, sh_flags, NULL);
check_and_copy(GElf_Addr, dst, src, sh_addr, NULL);
check_and_copy(GElf_Off, dst, src, sh_offset, NULL);
check_and_copy(GElf_Xword, dst, src, sh_size, NULL);
check_and_copy(GElf_Word, dst, src, sh_link, NULL);
check_and_copy(GElf_Word, dst, src, sh_info, NULL);
check_and_copy(GElf_Xword, dst, src, sh_addralign, NULL);
check_and_copy(GElf_Xword, dst, src, sh_entsize, NULL);
}
else {
if (valid_class(scn->s_elf->e_class)) {
seterr(ERROR_UNIMPLEMENTED);
}
else {
seterr(ERROR_UNKNOWN_CLASS);
}
return NULL;
}
if (dst == &buf) {
dst = (GElf_Shdr*)malloc(sizeof(GElf_Shdr));
if (!dst) {
seterr(ERROR_MEM_SHDR);
return NULL;
}
*dst = buf;
}
return dst;
}
int
gelf_update_shdr(Elf_Scn *scn, GElf_Shdr *src) {
if (!scn || !src) {
return 0;
}
elf_assert(scn->s_magic == SCN_MAGIC);
elf_assert(scn->s_elf);
elf_assert(scn->s_elf->e_magic == ELF_MAGIC);
if (scn->s_elf->e_class == ELFCLASS64) {
scn->s_shdr64 = *src;
}
else if (scn->s_elf->e_class == ELFCLASS32) {
Elf32_Shdr *dst = &scn->s_shdr32;
check_and_copy(Elf32_Word, dst, src, sh_name, 0);
check_and_copy(Elf32_Word, dst, src, sh_type, 0);
check_and_copy(Elf32_Word, dst, src, sh_flags, 0);
check_and_copy(Elf32_Addr, dst, src, sh_addr, 0);
check_and_copy(Elf32_Off, dst, src, sh_offset, 0);
check_and_copy(Elf32_Word, dst, src, sh_size, 0);
check_and_copy(Elf32_Word, dst, src, sh_link, 0);
check_and_copy(Elf32_Word, dst, src, sh_info, 0);
check_and_copy(Elf32_Word, dst, src, sh_addralign, 0);
check_and_copy(Elf32_Word, dst, src, sh_entsize, 0);
}
else {
if (valid_class(scn->s_elf->e_class)) {
seterr(ERROR_UNIMPLEMENTED);
}
else {
seterr(ERROR_UNKNOWN_CLASS);
}
return 0;
}
return 1;
}
#endif /* __LIBELF64 */

View File

@@ -1,407 +0,0 @@
/*
gelftrans.c - gelf_* translation functions.
Copyright (C) 2000 - 2001 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#if __LIBELF64
#ifndef lint
static const char rcsid[] = "@(#) $Id: gelftrans.c,v 1.10 2008/05/23 08:15:34 michael Exp $";
#endif /* lint */
#define check_and_copy(type, d, s, name, eret) \
do { \
if (sizeof((d)->name) < sizeof((s)->name) \
&& (type)(s)->name != (s)->name) { \
seterr(ERROR_BADVALUE); \
return (eret); \
} \
(d)->name = (type)(s)->name; \
} while (0)
/*
* These macros are missing on some Linux systems
*/
#if !defined(ELF32_R_SYM) || !defined(ELF32_R_TYPE) || !defined(ELF32_R_INFO)
# undef ELF32_R_SYM
# undef ELF32_R_TYPE
# undef ELF32_R_INFO
# define ELF32_R_SYM(i) ((i)>>8)
# define ELF32_R_TYPE(i) ((unsigned char)(i))
# define ELF32_R_INFO(s,t) (((s)<<8)+(unsigned char)(t))
#endif /* !defined(...) */
#if !defined(ELF64_R_SYM) || !defined(ELF64_R_TYPE) || !defined(ELF64_R_INFO)
# undef ELF64_R_SYM
# undef ELF64_R_TYPE
# undef ELF64_R_INFO
# define ELF64_R_SYM(i) ((i)>>32)
# define ELF64_R_TYPE(i) ((i)&0xffffffffL)
# define ELF64_R_INFO(s,t) (((Elf64_Xword)(s)<<32)+((t)&0xffffffffL))
#endif /* !defined(...) */
static char*
get_addr_and_class(const Elf_Data *data, int ndx, Elf_Type type, unsigned *cls) {
Scn_Data *sd = (Scn_Data*)data;
Elf_Scn *scn;
Elf *elf;
size_t n;
if (!sd) {
return NULL;
}
elf_assert(sd->sd_magic == DATA_MAGIC);
scn = sd->sd_scn;
elf_assert(scn);
elf_assert(scn->s_magic == SCN_MAGIC);
elf = scn->s_elf;
elf_assert(elf);
elf_assert(elf->e_magic == ELF_MAGIC);
if (elf->e_kind != ELF_K_ELF) {
seterr(ERROR_NOTELF);
return NULL;
}
if (!valid_class(elf->e_class)) {
seterr(ERROR_UNKNOWN_CLASS);
return NULL;
}
if (data->d_type != type) {
seterr(ERROR_BADTYPE);
return NULL;
}
n = _msize(elf->e_class, data->d_version, type);
if (n == 0) {
seterr(ERROR_UNIMPLEMENTED);
return NULL;
}
if (ndx < 0 || data->d_size < (ndx + 1) * n) {
seterr(ERROR_BADINDEX);
return NULL;
}
if (!data->d_buf) {
seterr(ERROR_NULLBUF);
return NULL;
}
if (cls) {
*cls = elf->e_class;
}
return (char*)data->d_buf + n * ndx;
}
GElf_Sym*
gelf_getsym(Elf_Data *src, int ndx, GElf_Sym *dst) {
GElf_Sym buf;
unsigned cls;
char *tmp;
if (!dst) {
dst = &buf;
}
tmp = get_addr_and_class(src, ndx, ELF_T_SYM, &cls);
if (!tmp) {
return NULL;
}
if (cls == ELFCLASS64) {
*dst = *(Elf64_Sym*)tmp;
}
else if (cls == ELFCLASS32) {
Elf32_Sym *src = (Elf32_Sym*)tmp;
check_and_copy(GElf_Word, dst, src, st_name, NULL);
check_and_copy(unsigned char, dst, src, st_info, NULL);
check_and_copy(unsigned char, dst, src, st_other, NULL);
check_and_copy(GElf_Half, dst, src, st_shndx, NULL);
check_and_copy(GElf_Addr, dst, src, st_value, NULL);
check_and_copy(GElf_Xword, dst, src, st_size, NULL);
}
else {
seterr(ERROR_UNIMPLEMENTED);
return NULL;
}
if (dst == &buf) {
dst = (GElf_Sym*)malloc(sizeof(GElf_Sym));
if (!dst) {
seterr(ERROR_MEM_SYM);
return NULL;
}
*dst = buf;
}
return dst;
}
int
gelf_update_sym(Elf_Data *dst, int ndx, GElf_Sym *src) {
unsigned cls;
char *tmp;
tmp = get_addr_and_class(dst, ndx, ELF_T_SYM, &cls);
if (!tmp) {
return 0;
}
if (cls == ELFCLASS64) {
*(Elf64_Sym*)tmp = *src;
}
else if (cls == ELFCLASS32) {
Elf32_Sym *dst = (Elf32_Sym*)tmp;
check_and_copy(Elf32_Word, dst, src, st_name, 0);
check_and_copy(Elf32_Addr, dst, src, st_value, 0);
check_and_copy(Elf32_Word, dst, src, st_size, 0);
check_and_copy(unsigned char, dst, src, st_info, 0);
check_and_copy(unsigned char, dst, src, st_other, 0);
check_and_copy(Elf32_Half, dst, src, st_shndx, 0);
}
else {
seterr(ERROR_UNIMPLEMENTED);
return 0;
}
return 1;
}
GElf_Dyn*
gelf_getdyn(Elf_Data *src, int ndx, GElf_Dyn *dst) {
GElf_Dyn buf;
unsigned cls;
char *tmp;
if (!dst) {
dst = &buf;
}
tmp = get_addr_and_class(src, ndx, ELF_T_DYN, &cls);
if (!tmp) {
return NULL;
}
if (cls == ELFCLASS64) {
*dst = *(Elf64_Dyn*)tmp;
}
else if (cls == ELFCLASS32) {
Elf32_Dyn *src = (Elf32_Dyn*)tmp;
check_and_copy(GElf_Sxword, dst, src, d_tag, NULL);
check_and_copy(GElf_Xword, dst, src, d_un.d_val, NULL);
}
else {
seterr(ERROR_UNIMPLEMENTED);
return NULL;
}
if (dst == &buf) {
dst = (GElf_Dyn*)malloc(sizeof(GElf_Dyn));
if (!dst) {
seterr(ERROR_MEM_DYN);
return NULL;
}
*dst = buf;
}
return dst;
}
int
gelf_update_dyn(Elf_Data *dst, int ndx, GElf_Dyn *src) {
unsigned cls;
char *tmp;
tmp = get_addr_and_class(dst, ndx, ELF_T_DYN, &cls);
if (!tmp) {
return 0;
}
if (cls == ELFCLASS64) {
*(Elf64_Dyn*)tmp = *src;
}
else if (cls == ELFCLASS32) {
Elf32_Dyn *dst = (Elf32_Dyn*)tmp;
check_and_copy(Elf32_Sword, dst, src, d_tag, 0);
check_and_copy(Elf32_Word, dst, src, d_un.d_val, 0);
}
else {
seterr(ERROR_UNIMPLEMENTED);
return 0;
}
return 1;
}
GElf_Rela*
gelf_getrela(Elf_Data *src, int ndx, GElf_Rela *dst) {
GElf_Rela buf;
unsigned cls;
char *tmp;
if (!dst) {
dst = &buf;
}
tmp = get_addr_and_class(src, ndx, ELF_T_RELA, &cls);
if (!tmp) {
return NULL;
}
if (cls == ELFCLASS64) {
*dst = *(Elf64_Rela*)tmp;
}
else if (cls == ELFCLASS32) {
Elf32_Rela *src = (Elf32_Rela*)tmp;
check_and_copy(GElf_Addr, dst, src, r_offset, NULL);
dst->r_info = ELF64_R_INFO((Elf64_Xword)ELF32_R_SYM(src->r_info),
(Elf64_Xword)ELF32_R_TYPE(src->r_info));
check_and_copy(GElf_Sxword, dst, src, r_addend, NULL);
}
else {
seterr(ERROR_UNIMPLEMENTED);
return NULL;
}
if (dst == &buf) {
dst = (GElf_Rela*)malloc(sizeof(GElf_Rela));
if (!dst) {
seterr(ERROR_MEM_RELA);
return NULL;
}
*dst = buf;
}
return dst;
}
int
gelf_update_rela(Elf_Data *dst, int ndx, GElf_Rela *src) {
unsigned cls;
char *tmp;
tmp = get_addr_and_class(dst, ndx, ELF_T_RELA, &cls);
if (!tmp) {
return 0;
}
if (cls == ELFCLASS64) {
*(Elf64_Rela*)tmp = *src;
}
else if (cls == ELFCLASS32) {
Elf32_Rela *dst = (Elf32_Rela*)tmp;
check_and_copy(Elf32_Addr, dst, src, r_offset, 0);
if (ELF64_R_SYM(src->r_info) > 0xffffffUL
|| ELF64_R_TYPE(src->r_info) > 0xffUL) {
seterr(ERROR_BADVALUE);
return 0;
}
dst->r_info = ELF32_R_INFO((Elf32_Word)ELF64_R_SYM(src->r_info),
(Elf32_Word)ELF64_R_TYPE(src->r_info));
check_and_copy(Elf32_Sword, dst, src, r_addend, 0);
}
else {
seterr(ERROR_UNIMPLEMENTED);
return 0;
}
return 1;
}
GElf_Rel*
gelf_getrel(Elf_Data *src, int ndx, GElf_Rel *dst) {
GElf_Rel buf;
unsigned cls;
char *tmp;
if (!dst) {
dst = &buf;
}
tmp = get_addr_and_class(src, ndx, ELF_T_REL, &cls);
if (!tmp) {
return NULL;
}
if (cls == ELFCLASS64) {
*dst = *(Elf64_Rel*)tmp;
}
else if (cls == ELFCLASS32) {
Elf32_Rel *src = (Elf32_Rel*)tmp;
check_and_copy(GElf_Addr, dst, src, r_offset, NULL);
dst->r_info = ELF64_R_INFO((Elf64_Xword)ELF32_R_SYM(src->r_info),
(Elf64_Xword)ELF32_R_TYPE(src->r_info));
}
else {
seterr(ERROR_UNIMPLEMENTED);
return NULL;
}
if (dst == &buf) {
dst = (GElf_Rel*)malloc(sizeof(GElf_Rel));
if (!dst) {
seterr(ERROR_MEM_REL);
return NULL;
}
*dst = buf;
}
return dst;
}
int
gelf_update_rel(Elf_Data *dst, int ndx, GElf_Rel *src) {
unsigned cls;
char *tmp;
tmp = get_addr_and_class(dst, ndx, ELF_T_REL, &cls);
if (!tmp) {
return 0;
}
if (cls == ELFCLASS64) {
*(Elf64_Rel*)tmp = *src;
}
else if (cls == ELFCLASS32) {
Elf32_Rel *dst = (Elf32_Rel*)tmp;
check_and_copy(Elf32_Addr, dst, src, r_offset, 0);
if (ELF64_R_SYM(src->r_info) > 0xffffffUL
|| ELF64_R_TYPE(src->r_info) > 0xffUL) {
seterr(ERROR_BADVALUE);
return 0;
}
dst->r_info = ELF32_R_INFO((Elf32_Word)ELF64_R_SYM(src->r_info),
(Elf32_Word)ELF64_R_TYPE(src->r_info));
}
else {
seterr(ERROR_UNIMPLEMENTED);
return 0;
}
return 1;
}
#if 0
GElf_Syminfo*
gelf_getsyminfo(Elf_Data *src, int ndx, GElf_Syminfo *dst) {
seterr(ERROR_UNIMPLEMENTED);
return NULL;
}
int
gelf_update_syminfo(Elf_Data *dst, int ndx, GElf_Syminfo *src) {
seterr(ERROR_UNIMPLEMENTED);
return 0;
}
GElf_Move*
gelf_getmove(Elf_Data *src, int ndx, GElf_Move *src) {
seterr(ERROR_UNIMPLEMENTED);
return NULL;
}
int
gelf_update_move(Elf_Data *dst, int ndx, GElf_Move *src) {
seterr(ERROR_UNIMPLEMENTED);
return 0;
}
#endif
#endif /* __LIBELF64 */

View File

@@ -1,37 +0,0 @@
/*
getarhdr.c - implementation of the elf_getarhdr(3) function.
Copyright (C) 1995 - 1998 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: getarhdr.c,v 1.7 2008/05/23 08:15:34 michael Exp $";
#endif /* lint */
Elf_Arhdr*
elf_getarhdr(Elf *elf) {
if (!elf) {
return NULL;
}
elf_assert(elf->e_magic == ELF_MAGIC);
if (elf->e_arhdr) {
return elf->e_arhdr;
}
seterr(ERROR_NOTARCHIVE);
return NULL;
}

View File

@@ -1,40 +0,0 @@
/*
* getaroff.c - implementation of the elf_getaroff(3) function.
* Copyright (C) 2009 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: getaroff.c,v 1.1 2009/11/01 13:04:19 michael Exp $";
#endif /* lint */
off_t
elf_getaroff(Elf *elf) {
Elf *ref;
if (!elf) {
return (off_t)-1;
}
elf_assert(elf->e_magic == ELF_MAGIC);
if (!(ref = elf->e_parent)) {
return (off_t)-1;
}
elf_assert(ref->e_magic == ELF_MAGIC);
elf_assert(elf->e_base >= ref->e_base + SARMAG + sizeof(struct ar_hdr));
return (off_t)(elf->e_base - ref->e_base - sizeof(struct ar_hdr));
}

View File

@@ -1,87 +0,0 @@
/*
* getarsym.c - implementation of the elf_getarsym(3) function.
* Copyright (C) 1995 - 1998, 2004 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#include <byteswap.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: getarsym.c,v 1.9 2008/05/23 08:15:34 michael Exp $";
#endif /* lint */
Elf_Arsym*
elf_getarsym(Elf *elf, size_t *ptr) {
Elf_Arsym *syms;
size_t count;
size_t tmp;
size_t i;
char *s;
char *e;
if (!ptr) {
ptr = &tmp;
}
*ptr = 0;
if (!elf) {
return NULL;
}
elf_assert(elf->e_magic == ELF_MAGIC);
if (elf->e_kind != ELF_K_AR) {
seterr(ERROR_NOTARCHIVE);
return NULL;
}
if (elf->e_symtab && !elf->e_free_syms) {
if (elf->e_symlen < 4) {
seterr(ERROR_SIZE_ARSYMTAB);
return NULL;
}
count = __load_u32M(elf->e_symtab);
if (elf->e_symlen < 4 * (count + 1)) {
seterr(ERROR_SIZE_ARSYMTAB);
return NULL;
}
if (!(syms = (Elf_Arsym*)malloc((count + 1) * sizeof(*syms)))) {
seterr(ERROR_MEM_ARSYMTAB);
return NULL;
}
s = elf->e_symtab + 4 * (count + 1);
e = elf->e_symtab + elf->e_symlen;
for (i = 0; i < count; i++, s++) {
syms[i].as_name = s;
while (s < e && *s) {
s++;
}
if (s >= e) {
seterr(ERROR_SIZE_ARSYMTAB);
free(syms);
return NULL;
}
elf_assert(!*s);
syms[i].as_hash = elf_hash((unsigned char*)syms[i].as_name);
syms[i].as_off = __load_u32M(elf->e_symtab + 4 * (i + 1));
}
syms[count].as_name = NULL;
syms[count].as_hash = ~0UL;
syms[count].as_off = 0;
elf->e_symtab = (char*)syms;
elf->e_symlen = count + 1;
elf->e_free_syms = 1;
}
*ptr = elf->e_symlen;
return (Elf_Arsym*)elf->e_symtab;
}

View File

@@ -1,33 +0,0 @@
/*
getbase.c - implementation of the elf_getbase(3) function.
Copyright (C) 1995 - 1998 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: getbase.c,v 1.7 2008/05/23 08:15:34 michael Exp $";
#endif /* lint */
off_t
elf_getbase(Elf *elf) {
if (!elf) {
return -1;
}
elf_assert(elf->e_magic == ELF_MAGIC);
return (off_t)elf->e_base;
}

View File

@@ -1,157 +0,0 @@
/*
getdata.c - implementation of the elf_getdata(3) function.
Copyright (C) 1995 - 2001 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: getdata.c,v 1.13 2008/05/23 08:15:34 michael Exp $";
#endif /* lint */
static Elf_Data*
_elf_cook_scn(Elf *elf, Elf_Scn *scn, Scn_Data *sd) {
Elf_Data dst;
Elf_Data src;
int flag = 0;
size_t dlen;
elf_assert(elf->e_data);
/*
* Prepare source
*/
src = sd->sd_data;
src.d_version = elf->e_version;
if (elf->e_rawdata) {
src.d_buf = elf->e_rawdata + scn->s_offset;
}
else {
src.d_buf = elf->e_data + scn->s_offset;
}
/*
* Prepare destination (needs prepared source!)
*/
dst = sd->sd_data;
if (elf->e_class == ELFCLASS32) {
dlen = _elf32_xltsize(&src, dst.d_version, elf->e_encoding, 0);
}
#if __LIBELF64
else if (elf->e_class == ELFCLASS64) {
dlen = _elf64_xltsize(&src, dst.d_version, elf->e_encoding, 0);
}
#endif /* __LIBELF64 */
else {
elf_assert(valid_class(elf->e_class));
seterr(ERROR_UNIMPLEMENTED);
return NULL;
}
if (dlen == (size_t)-1) {
return NULL;
}
dst.d_size = dlen;
if (elf->e_rawdata != elf->e_data && dst.d_size <= src.d_size) {
dst.d_buf = elf->e_data + scn->s_offset;
}
else if (!(dst.d_buf = malloc(dst.d_size))) {
seterr(ERROR_MEM_SCNDATA);
return NULL;
}
else {
flag = 1;
}
/*
* Translate data
*/
if (_elf_xlatetom(elf, &dst, &src)) {
sd->sd_memdata = (char*)dst.d_buf;
sd->sd_data = dst;
if (!(sd->sd_free_data = flag)) {
elf->e_cooked = 1;
}
return &sd->sd_data;
}
if (flag) {
free(dst.d_buf);
}
return NULL;
}
Elf_Data*
elf_getdata(Elf_Scn *scn, Elf_Data *data) {
Scn_Data *sd;
Elf *elf;
if (!scn) {
return NULL;
}
elf_assert(scn->s_magic == SCN_MAGIC);
if (scn->s_index == SHN_UNDEF) {
seterr(ERROR_NULLSCN);
}
else if (data) {
for (sd = scn->s_data_1; sd; sd = sd->sd_link) {
elf_assert(sd->sd_magic == DATA_MAGIC);
elf_assert(sd->sd_scn == scn);
if (data == &sd->sd_data) {
/*
* sd_link allocated by elf_newdata().
*/
return &sd->sd_link->sd_data;
}
}
seterr(ERROR_SCNDATAMISMATCH);
}
else if ((sd = scn->s_data_1)) {
elf_assert(sd->sd_magic == DATA_MAGIC);
elf_assert(sd->sd_scn == scn);
elf = scn->s_elf;
elf_assert(elf);
elf_assert(elf->e_magic == ELF_MAGIC);
if (sd->sd_freeme) {
/* allocated by elf_newdata() */
return &sd->sd_data;
}
else if (scn->s_type == SHT_NULL) {
seterr(ERROR_NULLSCN);
}
else if (sd->sd_memdata) {
/* already cooked */
return &sd->sd_data;
}
else if (scn->s_offset < 0 || scn->s_offset > elf->e_size) {
seterr(ERROR_OUTSIDE);
}
else if (scn->s_type == SHT_NOBITS || !scn->s_size) {
/* no data to read */
return &sd->sd_data;
}
else if (scn->s_offset + scn->s_size > elf->e_size) {
seterr(ERROR_TRUNC_SCN);
}
else if (valid_class(elf->e_class)) {
return _elf_cook_scn(elf, scn, sd);
}
else {
seterr(ERROR_UNKNOWN_CLASS);
}
}
return NULL;
}

View File

@@ -1,48 +0,0 @@
/*
getident.c - implementation of the elf_getident(3) function.
Copyright (C) 1995 - 1998 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: getident.c,v 1.7 2008/05/23 08:15:34 michael Exp $";
#endif /* lint */
char*
elf_getident(Elf *elf, size_t *ptr) {
size_t tmp;
if (!ptr) {
ptr = &tmp;
}
if (!elf) {
*ptr = 0;
return NULL;
}
elf_assert(elf->e_magic == ELF_MAGIC);
if (elf->e_kind != ELF_K_ELF) {
*ptr = elf->e_idlen;
return elf->e_data;
}
if (elf->e_ehdr || _elf_cook(elf)) {
*ptr = elf->e_idlen;
return elf->e_ehdr;
}
*ptr = 0;
return NULL;
}

View File

@@ -1,48 +0,0 @@
/*
getscn.c - implementation of the elf_getscn(3) function.
Copyright (C) 1995 - 1998 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: getscn.c,v 1.7 2008/05/23 08:15:35 michael Exp $";
#endif /* lint */
Elf_Scn*
elf_getscn(Elf *elf, size_t index) {
Elf_Scn *scn;
if (!elf) {
return NULL;
}
elf_assert(elf->e_magic == ELF_MAGIC);
if (elf->e_kind != ELF_K_ELF) {
seterr(ERROR_NOTELF);
}
else if (elf->e_ehdr || _elf_cook(elf)) {
for (scn = elf->e_scn_1; scn; scn = scn->s_link) {
elf_assert(scn->s_magic == SCN_MAGIC);
elf_assert(scn->s_elf == elf);
if (scn->s_index == index) {
return scn;
}
}
seterr(ERROR_NOSUCHSCN);
}
return NULL;
}

View File

@@ -1,38 +0,0 @@
/*
hash.c - implementation of the elf_hash(3) function.
Copyright (C) 1995 - 2002 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: hash.c,v 1.10 2008/05/23 08:15:35 michael Exp $";
#endif /* lint */
unsigned long
elf_hash(const unsigned char *name) {
unsigned long hash = 0;
unsigned long tmp;
while (*name) {
hash = (hash << 4) + (unsigned char)*name++;
if ((tmp = hash & 0xf0000000)) {
hash ^= tmp | (tmp >> 24);
}
}
return hash;
}

View File

@@ -1,106 +0,0 @@
/*
* input.c - low-level input for libelf.
* Copyright (C) 1995 - 2001, 2005 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: input.c,v 1.11 2008/05/23 08:15:35 michael Exp $";
#endif /* lint */
#include <errno.h>
#if HAVE_MMAP
#include <sys/mman.h>
#endif /* HAVE_MMAP */
static int
xread(int fd, char *buffer, size_t len) {
size_t done = 0;
size_t n;
while (done < len) {
n = read(fd, buffer + done, len - done);
if (n == 0) {
/* premature end of file */
return -1;
}
else if (n != (size_t)-1) {
/* some bytes read, continue */
done += n;
}
else if (errno != EAGAIN && errno != EINTR) {
/* real error */
return -1;
}
}
return 0;
}
void*
_elf_read(Elf *elf, void *buffer, size_t off, size_t len) {
void *tmp;
elf_assert(elf);
elf_assert(elf->e_magic == ELF_MAGIC);
elf_assert(off >= 0 && off + len <= elf->e_size);
if (elf->e_disabled) {
seterr(ERROR_FDDISABLED);
}
else if (len) {
off += elf->e_base;
if (lseek(elf->e_fd, (off_t)off, SEEK_SET) != (off_t)off) {
seterr(ERROR_IO_SEEK);
}
else if (!(tmp = buffer) && !(tmp = malloc(len))) {
seterr(ERROR_IO_2BIG);
}
else if (xread(elf->e_fd, tmp, len)) {
seterr(ERROR_IO_READ);
if (tmp != buffer) {
free(tmp);
}
}
else {
return tmp;
}
}
return NULL;
}
void*
_elf_mmap(Elf *elf) {
#if HAVE_MMAP
void *tmp;
elf_assert(elf);
elf_assert(elf->e_magic == ELF_MAGIC);
elf_assert(elf->e_base == 0);
if (elf->e_disabled) {
seterr(ERROR_FDDISABLED);
}
else if (elf->e_size) {
tmp = (void*)mmap(0, elf->e_size, PROT_READ | PROT_WRITE,
MAP_PRIVATE, elf->e_fd, 0);
if (tmp != (void*)-1) {
return tmp;
}
}
#endif /* HAVE_MMAP */
return NULL;
}

View File

@@ -1,33 +0,0 @@
/*
kind.c - implementation of the elf_kind(3) function.
Copyright (C) 1995 - 1998 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: kind.c,v 1.7 2008/05/23 08:15:35 michael Exp $";
#endif /* lint */
Elf_Kind
elf_kind(Elf *elf) {
if (!elf) {
return ELF_K_NONE;
}
elf_assert(elf->e_magic == ELF_MAGIC);
return elf->e_kind;
}

View File

@@ -1,82 +0,0 @@
LIBRARY libelf
VERSION 0.8
EXPORTS
elf_begin
elf_cntl
elf_delscn
elf_end
elf_errmsg
elf_errno
elf_fill
elf_flagdata
elf_flagehdr
elf_flagelf
elf_flagphdr
elf_flagscn
elf_flagshdr
elf_getarhdr
elf_getarsym
elf_getbase
elf_getdata
elf_getident
elf_getscn
elf_hash
elf_kind
elf_memory
elf_ndxscn
elf_newdata
elf_newscn
elf_next
elf_nextscn
elf_rand
elf_rawdata
elf_rawfile
elf_strptr
elf_update
elf_version
elf32_checksum
elf32_fsize
elf32_getehdr
elf32_getphdr
elf32_getshdr
elf32_newehdr
elf32_newphdr
elf32_xlatetof
elf32_xlatetom
elf64_checksum
elf64_fsize
elf64_getehdr
elf64_getphdr
elf64_getshdr
elf64_newehdr
elf64_newphdr
elf64_xlatetof
elf64_xlatetom
elfx_movscn
elfx_remscn
gelf_checksum
gelf_fsize
gelf_getclass
gelf_getdyn
gelf_getehdr
gelf_getphdr
gelf_getrel
gelf_getrela
gelf_getshdr
gelf_getsym
gelf_msize
gelf_newehdr
gelf_newphdr
gelf_update_dyn
gelf_update_ehdr
gelf_update_phdr
gelf_update_rel
gelf_update_rela
gelf_update_shdr
gelf_update_sym
gelf_xlatetof
gelf_xlatetom
elf_getphnum
elf_getshnum
elf_getshstrndx
elfx_update_shstrndx

View File

@@ -1,53 +0,0 @@
/*
* memset.c - replacement for memset(3), using duff's device.
* Copyright (C) 1995 - 2004 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#if HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
#ifndef lint
static const char rcsid[] = "@(#) $Id: memset.c,v 1.11 2008/05/23 08:15:35 michael Exp $";
#endif /* lint */
#include <stddef.h> /* for size_t */
#include <sys/types.h>
void*
_elf_memset(void *s, int c, size_t n) {
char *t = (char*)s;
if (n) {
switch (n % 8u) {
do {
n -= 8;
default:
case 0: *t++ = (char)c;
case 7: *t++ = (char)c;
case 6: *t++ = (char)c;
case 5: *t++ = (char)c;
case 4: *t++ = (char)c;
case 3: *t++ = (char)c;
case 2: *t++ = (char)c;
case 1: *t++ = (char)c;
}
while (n > 8);
}
}
return s;
}

View File

@@ -1,33 +0,0 @@
/*
ndxscn.c - implementation of the elf_ndxscn(3) function.
Copyright (C) 1995 - 1998 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: ndxscn.c,v 1.7 2008/05/23 08:15:35 michael Exp $";
#endif /* lint */
size_t
elf_ndxscn(Elf_Scn *scn) {
if (!scn) {
return SHN_UNDEF;
}
elf_assert(scn->s_magic == SCN_MAGIC);
return scn->s_index;
}

View File

@@ -1,56 +0,0 @@
/*
newdata.c - implementation of the elf_newdata(3) function.
Copyright (C) 1995 - 2000 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: newdata.c,v 1.10 2008/05/23 08:15:35 michael Exp $";
#endif /* lint */
Elf_Data*
elf_newdata(Elf_Scn *scn) {
Scn_Data *sd;
if (!scn) {
return NULL;
}
elf_assert(scn->s_magic == SCN_MAGIC);
if (scn->s_index == SHN_UNDEF) {
seterr(ERROR_NULLSCN);
}
else if (!(sd = (Scn_Data*)malloc(sizeof(*sd)))) {
seterr(ERROR_MEM_SCNDATA);
}
else {
*sd = _elf_data_init;
sd->sd_scn = scn;
sd->sd_data_flags = ELF_F_DIRTY;
sd->sd_freeme = 1;
sd->sd_data.d_version = _elf_version;
if (scn->s_data_n) {
scn->s_data_n->sd_link = sd;
}
else {
scn->s_data_1 = sd;
}
scn->s_data_n = sd;
return &sd->sd_data;
}
return NULL;
}

View File

@@ -1,145 +0,0 @@
/*
* newscn.c - implementation of the elf_newscn(3) function.
* Copyright (C) 1995 - 2006 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: newscn.c,v 1.13 2008/05/23 08:15:35 michael Exp $";
#endif /* lint */
int
_elf_update_shnum(Elf *elf, size_t shnum) {
size_t extshnum = 0;
Elf_Scn *scn;
elf_assert(elf);
elf_assert(elf->e_ehdr);
scn = elf->e_scn_1;
elf_assert(scn);
elf_assert(scn->s_index == 0);
if (shnum >= SHN_LORESERVE) {
extshnum = shnum;
shnum = 0;
}
if (elf->e_class == ELFCLASS32) {
((Elf32_Ehdr*)elf->e_ehdr)->e_shnum = shnum;
scn->s_shdr32.sh_size = extshnum;
}
#if __LIBELF64
else if (elf->e_class == ELFCLASS64) {
((Elf64_Ehdr*)elf->e_ehdr)->e_shnum = shnum;
scn->s_shdr64.sh_size = extshnum;
}
#endif /* __LIBELF64 */
else {
if (valid_class(elf->e_class)) {
seterr(ERROR_UNIMPLEMENTED);
}
else {
seterr(ERROR_UNKNOWN_CLASS);
}
return -1;
}
elf->e_ehdr_flags |= ELF_F_DIRTY;
scn->s_shdr_flags |= ELF_F_DIRTY;
return 0;
}
static Elf_Scn*
_makescn(Elf *elf, size_t index) {
Elf_Scn *scn;
elf_assert(elf);
elf_assert(elf->e_magic == ELF_MAGIC);
elf_assert(elf->e_ehdr);
elf_assert(_elf_scn_init.s_magic == SCN_MAGIC);
if (!(scn = (Elf_Scn*)malloc(sizeof(*scn)))) {
seterr(ERROR_MEM_SCN);
return NULL;
}
*scn = _elf_scn_init;
scn->s_elf = elf;
scn->s_scn_flags = ELF_F_DIRTY;
scn->s_shdr_flags = ELF_F_DIRTY;
scn->s_freeme = 1;
scn->s_index = index;
return scn;
}
Elf_Scn*
_elf_first_scn(Elf *elf) {
Elf_Scn *scn;
elf_assert(elf);
elf_assert(elf->e_magic == ELF_MAGIC);
if ((scn = elf->e_scn_1)) {
return scn;
}
if ((scn = _makescn(elf, 0))) {
elf->e_scn_1 = elf->e_scn_n = scn;
if (_elf_update_shnum(elf, 1)) {
free(scn);
elf->e_scn_1 = elf->e_scn_n = scn = NULL;
}
}
return scn;
}
static Elf_Scn*
_buildscn(Elf *elf) {
Elf_Scn *scn;
if (!_elf_first_scn(elf)) {
return NULL;
}
scn = elf->e_scn_n;
elf_assert(scn);
if (!(scn = _makescn(elf, scn->s_index + 1))) {
return NULL;
}
if (_elf_update_shnum(elf, scn->s_index + 1)) {
free(scn);
return NULL;
}
elf->e_scn_n = elf->e_scn_n->s_link = scn;
return scn;
}
Elf_Scn*
elf_newscn(Elf *elf) {
Elf_Scn *scn;
if (!elf) {
return NULL;
}
elf_assert(elf->e_magic == ELF_MAGIC);
if (!elf->e_readable && !elf->e_ehdr) {
seterr(ERROR_NOEHDR);
}
else if (elf->e_kind != ELF_K_ELF) {
seterr(ERROR_NOTELF);
}
else if (!elf->e_ehdr && !_elf_cook(elf)) {
return NULL;
}
else if ((scn = _buildscn(elf))) {
return scn;
}
return NULL;
}

View File

@@ -1,42 +0,0 @@
/*
next.c - implementation of the elf_next(3) function.
Copyright (C) 1995 - 1998 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: next.c,v 1.7 2008/05/23 08:15:35 michael Exp $";
#endif /* lint */
Elf_Cmd
elf_next(Elf *elf) {
if (!elf) {
return ELF_C_NULL;
}
elf_assert(elf->e_magic == ELF_MAGIC);
if (!elf->e_parent) {
return ELF_C_NULL;
}
elf_assert(elf->e_parent->e_magic == ELF_MAGIC);
elf_assert(elf->e_parent->e_kind == ELF_K_AR);
elf->e_parent->e_off = elf->e_next;
if (elf->e_next == elf->e_parent->e_size) {
return ELF_C_NULL;
}
return ELF_C_READ;
}

View File

@@ -1,54 +0,0 @@
/*
nextscn.c - implementation of the elf_nextscn(3) function.
Copyright (C) 1995 - 1998 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: nextscn.c,v 1.7 2008/05/23 08:15:35 michael Exp $";
#endif /* lint */
Elf_Scn*
elf_nextscn(Elf *elf, Elf_Scn *scn) {
if (!elf) {
return NULL;
}
elf_assert(elf->e_magic == ELF_MAGIC);
if (scn) {
elf_assert(scn->s_magic == SCN_MAGIC);
if (scn->s_elf == elf) {
return scn->s_link;
}
seterr(ERROR_ELFSCNMISMATCH);
}
else if (elf->e_kind != ELF_K_ELF) {
seterr(ERROR_NOTELF);
}
else if (elf->e_ehdr || _elf_cook(elf)) {
elf_assert(elf->e_ehdr);
for (scn = elf->e_scn_1; scn; scn = scn->s_link) {
elf_assert(scn->s_magic == SCN_MAGIC);
elf_assert(scn->s_elf == elf);
if (scn->s_index == 1) {
return scn;
}
}
seterr(ERROR_NOSUCHSCN);
}
return NULL;
}

View File

@@ -1,253 +0,0 @@
/*
* nlist.c - implementation of the nlist(3) function.
* Copyright (C) 1995 - 2004 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#include <nlist.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: nlist.c,v 1.15 2008/05/23 08:15:35 michael Exp $";
#endif /* lint */
#if !defined(_WIN32)
#if HAVE_FCNTL_H
#include <fcntl.h>
#else
extern int open();
#endif /* HAVE_FCNTL_H */
#endif /* defined(_WIN32) */
#ifndef O_RDONLY
#define O_RDONLY 0
#endif /* O_RDONLY */
#ifndef O_BINARY
#define O_BINARY 0
#endif /* O_BINARY */
#define FILE_OPEN_MODE (O_RDONLY | O_BINARY)
#define PRIME 217
struct hash {
const char* name;
unsigned long hash;
unsigned next;
};
static const char*
symbol_name(Elf *elf, const void *syms, const char *names, size_t nlimit, size_t index) {
size_t off;
if (elf->e_class == ELFCLASS32) {
off = ((Elf32_Sym*)syms)[index].st_name;
}
#if __LIBELF64
else if (elf->e_class == ELFCLASS64) {
off = ((Elf64_Sym*)syms)[index].st_name;
}
#endif /* __LIBELF64 */
else {
return NULL;
}
if (off >= 0 && off < nlimit) {
return &names[off];
}
return NULL;
}
static void
copy_symbol(Elf *elf, struct nlist *np, const void *syms, size_t index) {
if (elf->e_class == ELFCLASS32) {
np->n_value = ((Elf32_Sym*)syms)[index].st_value;
np->n_scnum = ((Elf32_Sym*)syms)[index].st_shndx;
}
#if __LIBELF64
else if (elf->e_class == ELFCLASS64) {
np->n_value = ((Elf64_Sym*)syms)[index].st_value;
np->n_scnum = ((Elf64_Sym*)syms)[index].st_shndx;
}
#endif /* __LIBELF64 */
/*
* this needs more work
*/
np->n_type = 0;
np->n_sclass = 0;
np->n_numaux = 0;
}
static int
_elf_nlist(Elf *elf, struct nlist *nl) {
unsigned first[PRIME];
Elf_Scn *symtab = NULL;
Elf_Scn *strtab = NULL;
Elf_Data *symdata;
Elf_Data *strdata;
size_t symsize;
size_t nsymbols;
const char *name;
struct hash *table;
unsigned long hash;
unsigned i;
struct nlist *np;
/*
* Get and translate ELF header, section table and so on.
* Must be class independent, so don't use elf32_get*().
*/
if (elf->e_kind != ELF_K_ELF) {
return -1;
}
if (!elf->e_ehdr && !_elf_cook(elf)) {
return -1;
}
/*
* Find symbol table. If there is none, try dynamic symbols.
*/
for (symtab = elf->e_scn_1; symtab; symtab = symtab->s_link) {
if (symtab->s_type == SHT_SYMTAB) {
break;
}
if (symtab->s_type == SHT_DYNSYM) {
strtab = symtab;
}
}
if (!symtab && !(symtab = strtab)) {
return -1;
}
/*
* Get associated string table.
*/
i = 0;
if (elf->e_class == ELFCLASS32) {
i = symtab->s_shdr32.sh_link;
}
#if __LIBELF64
else if (elf->e_class == ELFCLASS64) {
i = symtab->s_shdr64.sh_link;
}
#endif /* __LIBELF64 */
if (i == 0) {
return -1;
}
for (strtab = elf->e_scn_1; strtab; strtab = strtab->s_link) {
if (strtab->s_index == i) {
break;
}
}
if (!strtab || strtab->s_type != SHT_STRTAB) {
return -1;
}
/*
* Get and translate section data.
*/
symdata = elf_getdata(symtab, NULL);
strdata = elf_getdata(strtab, NULL);
if (!symdata || !strdata) {
return -1;
}
symsize = _msize(elf->e_class, _elf_version, ELF_T_SYM);
elf_assert(symsize);
nsymbols = symdata->d_size / symsize;
if (!symdata->d_buf || !strdata->d_buf || !nsymbols || !strdata->d_size) {
return -1;
}
/*
* Build a simple hash table.
*/
if (!(table = (struct hash*)malloc(nsymbols * sizeof(*table)))) {
return -1;
}
for (i = 0; i < PRIME; i++) {
first[i] = 0;
}
for (i = 0; i < nsymbols; i++) {
table[i].name = NULL;
table[i].hash = 0;
table[i].next = 0;
}
for (i = 1; i < nsymbols; i++) {
name = symbol_name(elf, symdata->d_buf, strdata->d_buf,
strdata->d_size, i);
if (name == NULL) {
free(table);
return -1;
}
if (*name != '\0') {
table[i].name = name;
table[i].hash = elf_hash((unsigned char*)name);
hash = table[i].hash % PRIME;
table[i].next = first[hash];
first[hash] = i;
}
}
/*
* Lookup symbols, one by one.
*/
for (np = nl; (name = np->n_name) && *name; np++) {
hash = elf_hash((unsigned char*)name);
for (i = first[hash % PRIME]; i; i = table[i].next) {
if (table[i].hash == hash && !strcmp(table[i].name, name)) {
break;
}
}
if (i) {
copy_symbol(elf, np, symdata->d_buf, i);
}
else {
np->n_value = 0;
np->n_scnum = 0;
np->n_type = 0;
np->n_sclass = 0;
np->n_numaux = 0;
}
}
free(table);
return 0;
}
int
nlist(const char *filename, struct nlist *nl) {
int result = -1;
unsigned oldver;
Elf *elf;
int fd;
if ((oldver = elf_version(EV_CURRENT)) != EV_NONE) {
if ((fd = open(filename, FILE_OPEN_MODE)) != -1) {
if ((elf = elf_begin(fd, ELF_C_READ, NULL))) {
result = _elf_nlist(elf, nl);
elf_end(elf);
}
close(fd);
}
elf_version(oldver);
}
if (result) {
while (nl->n_name && *nl->n_name) {
nl->n_value = 0;
nl++;
}
}
return result;
}

View File

@@ -1,48 +0,0 @@
/*
* nlist.h - public header file for nlist(3).
* Copyright (C) 1995 - 2006 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* @(#) $Id: nlist.h,v 1.10 2008/05/23 08:15:35 michael Exp $ */
#ifndef _NLIST_H
#define _NLIST_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
struct nlist {
char* n_name;
long n_value;
short n_scnum;
unsigned short n_type;
char n_sclass;
char n_numaux;
};
#if (__STDC__ + 0) || defined(__cplusplus) || defined(_WIN32)
extern int nlist(const char *__filename, struct nlist *__nl);
#else /* __STDC__ || defined(__cplusplus) */
extern int nlist();
#endif /* __STDC__ || defined(__cplusplus) */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _NLIST_H */

View File

@@ -1,205 +0,0 @@
/*
opt.delscn.c - implementation of the elf_delscn(3) function.
Copyright (C) 1995 - 2001 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: opt.delscn.c,v 1.12 2008/05/23 08:15:35 michael Exp $";
#endif /* lint */
static size_t
_newindex(size_t old, size_t index) {
return old == index ? SHN_UNDEF : (old > index ? old - 1 : old);
}
static void
_elf32_update_shdr(Elf *elf, size_t index) {
Elf32_Shdr *shdr;
Elf_Scn *scn;
((Elf32_Ehdr*)elf->e_ehdr)->e_shnum = elf->e_scn_n->s_index + 1;
for (scn = elf->e_scn_1; scn; scn = scn->s_link) {
shdr = &scn->s_shdr32;
switch (shdr->sh_type) {
case SHT_REL:
case SHT_RELA:
shdr->sh_info = _newindex(shdr->sh_info, index);
/* fall through */
case SHT_DYNSYM:
case SHT_DYNAMIC:
case SHT_HASH:
case SHT_SYMTAB:
#if __LIBELF_SYMBOL_VERSIONS
#if __LIBELF_SUN_SYMBOL_VERSIONS
case SHT_SUNW_verdef:
case SHT_SUNW_verneed:
case SHT_SUNW_versym:
#else /* __LIBELF_SUN_SYMBOL_VERSIONS */
case SHT_GNU_verdef:
case SHT_GNU_verneed:
case SHT_GNU_versym:
#endif /* __LIBELF_SUN_SYMBOL_VERSIONS */
#endif /* __LIBELF_SYMBOL_VERSIONS */
shdr->sh_link = _newindex(shdr->sh_link, index);
/* fall through */
default:
break;
}
}
}
#if __LIBELF64
static void
_elf64_update_shdr(Elf *elf, size_t index) {
Elf64_Shdr *shdr;
Elf_Scn *scn;
((Elf64_Ehdr*)elf->e_ehdr)->e_shnum = elf->e_scn_n->s_index + 1;
for (scn = elf->e_scn_1; scn; scn = scn->s_link) {
shdr = &scn->s_shdr64;
switch (shdr->sh_type) {
case SHT_REL:
case SHT_RELA:
shdr->sh_info = _newindex(shdr->sh_info, index);
/* fall through */
case SHT_DYNSYM:
case SHT_DYNAMIC:
case SHT_HASH:
case SHT_SYMTAB:
#if __LIBELF_SYMBOL_VERSIONS
#if __LIBELF_SUN_SYMBOL_VERSIONS
case SHT_SUNW_verdef:
case SHT_SUNW_verneed:
case SHT_SUNW_versym:
#else /* __LIBELF_SUN_SYMBOL_VERSIONS */
case SHT_GNU_verdef:
case SHT_GNU_verneed:
case SHT_GNU_versym:
#endif /* __LIBELF_SUN_SYMBOL_VERSIONS */
#endif /* __LIBELF_SYMBOL_VERSIONS */
shdr->sh_link = _newindex(shdr->sh_link, index);
/* fall through */
default:
break;
}
}
}
#endif /* __LIBELF64 */
size_t
elf_delscn(Elf *elf, Elf_Scn *scn) {
Elf_Scn *pscn;
Scn_Data *sd;
Scn_Data *tmp;
size_t index;
if (!elf || !scn) {
return SHN_UNDEF;
}
elf_assert(elf->e_magic == ELF_MAGIC);
elf_assert(scn->s_magic == SCN_MAGIC);
elf_assert(elf->e_ehdr);
if (scn->s_elf != elf) {
seterr(ERROR_ELFSCNMISMATCH);
return SHN_UNDEF;
}
elf_assert(elf->e_scn_1);
if (scn == elf->e_scn_1) {
seterr(ERROR_NULLSCN);
return SHN_UNDEF;
}
/*
* Find previous section.
*/
for (pscn = elf->e_scn_1; pscn->s_link; pscn = pscn->s_link) {
if (pscn->s_link == scn) {
break;
}
}
if (pscn->s_link != scn) {
seterr(ERROR_ELFSCNMISMATCH);
return SHN_UNDEF;
}
/*
* Unlink section.
*/
if (elf->e_scn_n == scn) {
elf->e_scn_n = pscn;
}
pscn->s_link = scn->s_link;
index = scn->s_index;
/*
* Free section descriptor and data.
*/
for (sd = scn->s_data_1; sd; sd = tmp) {
elf_assert(sd->sd_magic == DATA_MAGIC);
elf_assert(sd->sd_scn == scn);
tmp = sd->sd_link;
if (sd->sd_free_data && sd->sd_memdata) {
free(sd->sd_memdata);
}
if (sd->sd_freeme) {
free(sd);
}
}
if ((sd = scn->s_rawdata)) {
elf_assert(sd->sd_magic == DATA_MAGIC);
elf_assert(sd->sd_scn == scn);
if (sd->sd_free_data && sd->sd_memdata) {
free(sd->sd_memdata);
}
if (sd->sd_freeme) {
free(sd);
}
}
if (scn->s_freeme) {
elf_assert(scn->s_index > 0);
free(scn);
}
/*
* Adjust section indices.
*/
for (scn = pscn->s_link; scn; scn = scn->s_link) {
elf_assert(scn->s_index > index);
scn->s_index--;
}
/*
* Adjust ELF header and well-known section headers.
*/
if (elf->e_class == ELFCLASS32) {
_elf32_update_shdr(elf, index);
return index;
}
#if __LIBELF64
else if (elf->e_class == ELFCLASS64) {
_elf64_update_shdr(elf, index);
return index;
}
#endif /* __LIBELF64 */
else if (valid_class(elf->e_class)) {
seterr(ERROR_UNIMPLEMENTED);
}
else {
seterr(ERROR_UNKNOWN_CLASS);
}
return SHN_UNDEF;
}

View File

@@ -1,446 +0,0 @@
/*
* private.h - private definitions for libelf.
* Copyright (C) 1995 - 2007 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* @(#) $Id: private.h,v 1.40 2009/11/01 13:04:19 michael Exp $ */
#ifndef _PRIVATE_H
#define _PRIVATE_H
#define __LIBELF_INTERNAL__ 1
#if HAVE_CONFIG_H
# include <config.h>
#endif /* HAVE_CONFIG_H */
/*
* Workaround for GLIBC bug:
* include <stdint.h> before <sys/types.h>
*/
#if HAVE_STDINT_H
#include <stdint.h>
#endif
#include <sys/types.h>
#if STDC_HEADERS
# include <stdlib.h>
# include <string.h>
#else /* STDC_HEADERS */
extern void *malloc(), *realloc();
extern void free(), bcopy(), abort();
extern int strcmp(), strncmp(), memcmp();
extern void *memcpy(), *memmove(), *memset();
#endif /* STDC_HEADERS */
#if defined(_WIN32)
#include <io.h>
#else
#if HAVE_UNISTD_H
# include <unistd.h>
#else /* HAVE_UNISTD_H */
extern int read(), write(), close();
extern off_t lseek();
#if HAVE_FTRUNCATE
extern int ftruncate();
#endif /* HAVE_FTRUNCATE */
#endif /* HAVE_UNISTD_H */
#endif /* defined(_WIN32) */
#ifndef SEEK_SET
#define SEEK_SET 0
#endif /* SEEK_SET */
#ifndef SEEK_CUR
#define SEEK_CUR 1
#endif /* SEEK_CUR */
#ifndef SEEK_END
#define SEEK_END 2
#endif /* SEEK_END */
#if !HAVE_MEMCMP
# define memcmp strncmp
#endif /* !HAVE_MEMCMP */
#if !HAVE_MEMCPY
# define memcpy(d,s,n) bcopy(s,d,n)
#endif /* !HAVE_MEMCPY */
#if !HAVE_MEMMOVE
# define memmove(d,s,n) bcopy(s,d,n)
#endif /* !HAVE_MEMMOVE */
#if !HAVE_MEMSET
# define memset _elf_memset
extern void *_elf_memset();
#endif /* !HAVE_MEMSET */
#if HAVE_STRUCT_NLIST_DECLARATION
# define nlist __override_nlist_declaration
#endif /* HAVE_STRUCT_NLIST_DECLARATION */
#if __LIBELF_NEED_LINK_H
# include <link.h>
#elif __LIBELF_NEED_SYS_LINK_H
# include <sys/link.h>
#endif /* __LIBELF_NEED_LINK_H */
#if HAVE_AR_H
#include <ar.h>
#else /* HAVE_AR_H */
#define ARMAG "!<arch>\n"
#define SARMAG 8
struct ar_hdr {
char ar_name[16];
char ar_date[12];
char ar_uid[6];
char ar_gid[6];
char ar_mode[8];
char ar_size[10];
char ar_fmag[2];
};
#define ARFMAG "`\n"
#endif /* HAVE_AR_H */
#include <libelf.h>
#if HAVE_STRUCT_NLIST_DECLARATION
# undef nlist
#endif /* HAVE_STRUCT_NLIST_DECLARATION */
#if __LIBELF64
#include <gelf.h>
#endif /* __LIBELF64 */
typedef struct Scn_Data Scn_Data;
/*
* ELF descriptor
*/
struct Elf {
/* common */
size_t e_size; /* file/member size */
size_t e_dsize; /* size of memory image */
Elf_Kind e_kind; /* kind of file */
char* e_data; /* file/member data */
char* e_rawdata; /* file/member raw data */
size_t e_idlen; /* identifier size */
int e_fd; /* file descriptor */
unsigned e_count; /* activation count */
/* archive members (still common) */
Elf* e_parent; /* NULL if not an archive member */
size_t e_next; /* 0 if not an archive member */
size_t e_base; /* 0 if not an archive member */
Elf* e_link; /* next archive member or NULL */
Elf_Arhdr* e_arhdr; /* archive member header or NULL */
/* archives */
size_t e_off; /* current member offset (for elf_begin) */
Elf* e_members; /* linked list of active archive members */
char* e_symtab; /* archive symbol table */
size_t e_symlen; /* length of archive symbol table */
char* e_strtab; /* archive string table */
size_t e_strlen; /* length of archive string table */
/* ELF files */
unsigned e_class; /* ELF class */
unsigned e_encoding; /* ELF data encoding */
unsigned e_version; /* ELF version */
char* e_ehdr; /* ELF header */
char* e_phdr; /* ELF program header table */
size_t e_phnum; /* size of program header table */
Elf_Scn* e_scn_1; /* first section */
Elf_Scn* e_scn_n; /* last section */
unsigned e_elf_flags; /* elf flags (ELF_F_*) */
unsigned e_ehdr_flags; /* ehdr flags (ELF_F_*) */
unsigned e_phdr_flags; /* phdr flags (ELF_F_*) */
/* misc flags */
unsigned e_readable : 1; /* file is readable */
unsigned e_writable : 1; /* file is writable */
unsigned e_disabled : 1; /* e_fd has been disabled */
unsigned e_cooked : 1; /* e_data was modified */
unsigned e_free_syms : 1; /* e_symtab is malloc'ed */
unsigned e_unmap_data : 1; /* e_data is mmap'ed */
unsigned e_memory : 1; /* created by elf_memory() */
/* magic number for debugging */
long e_magic;
};
#define ELF_MAGIC 0x012b649e
#define INIT_ELF {\
/* e_size */ 0,\
/* e_dsize */ 0,\
/* e_kind */ ELF_K_NONE,\
/* e_data */ NULL,\
/* e_rawdata */ NULL,\
/* e_idlen */ 0,\
/* e_fd */ -1,\
/* e_count */ 1,\
/* e_parent */ NULL,\
/* e_next */ 0,\
/* e_base */ 0,\
/* e_link */ NULL,\
/* e_arhdr */ NULL,\
/* e_off */ 0,\
/* e_members */ NULL,\
/* e_symtab */ NULL,\
/* e_symlen */ 0,\
/* e_strtab */ NULL,\
/* e_strlen */ 0,\
/* e_class */ ELFCLASSNONE,\
/* e_encoding */ ELFDATANONE,\
/* e_version */ EV_NONE,\
/* e_ehdr */ NULL,\
/* e_phdr */ NULL,\
/* e_phnum */ 0,\
/* e_scn_1 */ NULL,\
/* e_scn_n */ NULL,\
/* e_elf_flags */ 0,\
/* e_ehdr_flags */ 0,\
/* e_phdr_flags */ 0,\
/* e_readable */ 0,\
/* e_writable */ 0,\
/* e_disabled */ 0,\
/* e_cooked */ 0,\
/* e_free_syms */ 0,\
/* e_unmap_data */ 0,\
/* e_memory */ 0,\
/* e_magic */ ELF_MAGIC\
}
/*
* Section descriptor
*/
struct Elf_Scn {
Elf_Scn* s_link; /* pointer to next Elf_Scn */
Elf* s_elf; /* pointer to elf descriptor */
size_t s_index; /* number of this section */
unsigned s_scn_flags; /* section flags (ELF_F_*) */
unsigned s_shdr_flags; /* shdr flags (ELF_F_*) */
Scn_Data* s_data_1; /* first data buffer */
Scn_Data* s_data_n; /* last data buffer */
Scn_Data* s_rawdata; /* raw data buffer */
/* data copied from shdr */
unsigned s_type; /* section type */
size_t s_offset; /* section offset */
size_t s_size; /* section size */
/* misc flags */
unsigned s_freeme : 1; /* this Elf_Scn was malloc'ed */
/* section header */
union {
#if __LIBELF64
Elf64_Shdr u_shdr64;
#endif /* __LIBELF64 */
Elf32_Shdr u_shdr32;
} s_uhdr;
/* magic number for debugging */
long s_magic;
};
#define s_shdr32 s_uhdr.u_shdr32
#define s_shdr64 s_uhdr.u_shdr64
#define SCN_MAGIC 0x012c747d
#define INIT_SCN {\
/* s_link */ NULL,\
/* s_elf */ NULL,\
/* s_index */ 0,\
/* s_scn_flags */ 0,\
/* s_shdr_flags */ 0,\
/* s_data_1 */ NULL,\
/* s_data_n */ NULL,\
/* s_rawdata */ NULL,\
/* s_type */ SHT_NULL,\
/* s_offset */ 0,\
/* s_size */ 0,\
/* s_freeme */ 0,\
/* s_uhdr */ {{0,}},\
/* s_magic */ SCN_MAGIC\
}
/*
* Data descriptor
*/
struct Scn_Data {
Elf_Data sd_data; /* must be first! */
Scn_Data* sd_link; /* pointer to next Scn_Data */
Elf_Scn* sd_scn; /* pointer to section */
char* sd_memdata; /* memory image of section */
unsigned sd_data_flags; /* data flags (ELF_F_*) */
/* misc flags */
unsigned sd_freeme : 1; /* this Scn_Data was malloc'ed */
unsigned sd_free_data : 1; /* sd_memdata is malloc'ed */
/* magic number for debugging */
long sd_magic;
};
#define DATA_MAGIC 0x01072639
#define INIT_DATA {\
{\
/* d_buf */ NULL,\
/* d_type */ ELF_T_BYTE,\
/* d_size */ 0,\
/* d_off */ 0,\
/* d_align */ 0,\
/* d_version */ EV_NONE\
},\
/* sd_link */ NULL,\
/* sd_scn */ NULL,\
/* sd_memdata */ NULL,\
/* sd_data_flags */ 0,\
/* sd_freeme */ 0,\
/* sd_free_data */ 0,\
/* sd_magic */ DATA_MAGIC\
}
/*
* Private status variables
*/
extern unsigned _elf_version;
extern int _elf_errno;
extern int _elf_fill;
extern int _elf_sanity_checks;
#define SANITY_CHECK_STRPTR (1u << 0)
/*
* Private functions
*/
extern void *_elf_read __P((Elf*, void*, size_t, size_t));
extern void *_elf_mmap __P((Elf*));
extern int _elf_cook __P((Elf*));
extern char *_elf_getehdr __P((Elf*, unsigned));
extern char *_elf_getphdr __P((Elf*, unsigned));
extern Elf_Data *_elf_xlatetom __P((const Elf*, Elf_Data*, const Elf_Data*));
extern Elf_Type _elf_scn_type __P((unsigned));
extern size_t _elf32_xltsize __P((const Elf_Data *__src, unsigned __dv, unsigned __encode, int __tof));
extern size_t _elf64_xltsize __P((const Elf_Data *__src, unsigned __dv, unsigned __encode, int __tof));
extern int _elf_update_shnum(Elf *__elf, size_t __shnum);
extern Elf_Scn *_elf_first_scn(Elf *__elf);
/*
* Special translators
*/
extern size_t _elf_verdef_32L11_tof __P((unsigned char *dst, const unsigned char *src, size_t n));
extern size_t _elf_verdef_32L11_tom __P((unsigned char *dst, const unsigned char *src, size_t n));
extern size_t _elf_verdef_32M11_tof __P((unsigned char *dst, const unsigned char *src, size_t n));
extern size_t _elf_verdef_32M11_tom __P((unsigned char *dst, const unsigned char *src, size_t n));
extern size_t _elf_verdef_64L11_tof __P((unsigned char *dst, const unsigned char *src, size_t n));
extern size_t _elf_verdef_64L11_tom __P((unsigned char *dst, const unsigned char *src, size_t n));
extern size_t _elf_verdef_64M11_tof __P((unsigned char *dst, const unsigned char *src, size_t n));
extern size_t _elf_verdef_64M11_tom __P((unsigned char *dst, const unsigned char *src, size_t n));
extern size_t _elf_verneed_32L11_tof __P((unsigned char *dst, const unsigned char *src, size_t n));
extern size_t _elf_verneed_32L11_tom __P((unsigned char *dst, const unsigned char *src, size_t n));
extern size_t _elf_verneed_32M11_tof __P((unsigned char *dst, const unsigned char *src, size_t n));
extern size_t _elf_verneed_32M11_tom __P((unsigned char *dst, const unsigned char *src, size_t n));
extern size_t _elf_verneed_64L11_tof __P((unsigned char *dst, const unsigned char *src, size_t n));
extern size_t _elf_verneed_64L11_tom __P((unsigned char *dst, const unsigned char *src, size_t n));
extern size_t _elf_verneed_64M11_tof __P((unsigned char *dst, const unsigned char *src, size_t n));
extern size_t _elf_verneed_64M11_tom __P((unsigned char *dst, const unsigned char *src, size_t n));
/*
* Private data
*/
extern const Elf_Scn _elf_scn_init;
extern const Scn_Data _elf_data_init;
extern const size_t _elf_fmsize[2][EV_CURRENT - EV_NONE][ELF_T_NUM][2];
/*
* Access macros for _elf_fmsize[]
*/
#define _fmsize(c,v,t,w) \
(_elf_fmsize[(c)-ELFCLASS32][(v)-EV_NONE-1][(t)-ELF_T_BYTE][(w)])
#define _fsize(c,v,t) _fmsize((c),(v),(t),1)
#define _msize(c,v,t) _fmsize((c),(v),(t),0)
/*
* Various checks
*/
#define valid_class(c) ((c) >= ELFCLASS32 && (c) <= ELFCLASS64)
#define valid_encoding(e) ((e) >= ELFDATA2LSB && (e) <= ELFDATA2MSB)
#define valid_version(v) ((v) > EV_NONE && (v) <= EV_CURRENT)
#define valid_type(t) ((unsigned)(t) < ELF_T_NUM)
/*
* Error codes
*/
enum {
#define __err__(a,b) a,
#include <errors.h> /* include constants from errors.h */
#undef __err__
ERROR_NUM
};
#define seterr(err) (_elf_errno = (err))
/*
* Sizes of data types (external representation)
* These definitions should be in <elf.h>, but...
*/
#ifndef ELF32_FSZ_ADDR
# define ELF32_FSZ_ADDR 4
# define ELF32_FSZ_HALF 2
# define ELF32_FSZ_OFF 4
# define ELF32_FSZ_SWORD 4
# define ELF32_FSZ_WORD 4
#endif /* ELF32_FSZ_ADDR */
#ifndef ELF64_FSZ_ADDR
# define ELF64_FSZ_ADDR 8
# define ELF64_FSZ_HALF 2
# define ELF64_FSZ_OFF 8
# define ELF64_FSZ_SWORD 4
# define ELF64_FSZ_SXWORD 8
# define ELF64_FSZ_WORD 4
# define ELF64_FSZ_XWORD 8
#endif /* ELF64_FSZ_ADDR */
/*
* More missing pieces, in no particular order
*/
#ifndef SHT_SYMTAB_SHNDX
#define SHT_SYMTAB_SHNDX 18
#endif /* SHT_SYMTAB_SHNDX */
#ifndef SHN_XINDEX
#define SHN_XINDEX 0xffff
#endif /* SHN_XINDEX */
#ifndef PN_XNUM
#define PN_XNUM 0xffff
#endif /* PN_XNUM */
/*
* Debugging
*/
#if ENABLE_DEBUG
extern void __elf_assert __P((const char*, unsigned, const char*));
# if (__STDC__ + 0)
# define elf_assert(x) do{if(!(x))__elf_assert(__FILE__,__LINE__,#x);}while(0)
# else /* __STDC__ */
# define elf_assert(x) do{if(!(x))__elf_assert(__FILE__,__LINE__,"x");}while(0)
# endif /* __STDC__ */
#else /* ENABLE_DEBUG */
# define elf_assert(x) do{}while(0)
#endif /* ENABLE_DEBUG */
/*
* Return values for certain functions
*/
#define LIBELF_SUCCESS 1
#define LIBELF_FAILURE 0
#endif /* _PRIVATE_H */

View File

@@ -1,43 +0,0 @@
/*
rand.c - implementation of the elf_rand(3) function.
Copyright (C) 1995 - 1998 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: rand.c,v 1.7 2008/05/23 08:15:35 michael Exp $";
#endif /* lint */
size_t
elf_rand(Elf *elf, size_t offset) {
if (!elf) {
return 0;
}
elf_assert(elf->e_magic == ELF_MAGIC);
if (elf->e_kind != ELF_K_AR) {
seterr(ERROR_NOTARCHIVE);
}
else if (offset <= 0 || offset > elf->e_size) {
seterr(ERROR_BADOFF);
}
else {
elf->e_off = offset;
return offset;
}
return 0;
}

View File

@@ -1,89 +0,0 @@
/*
rawdata.c - implementation of the elf_rawdata(3) function.
Copyright (C) 1995 - 2000 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: rawdata.c,v 1.10 2008/05/23 08:15:35 michael Exp $";
#endif /* lint */
Elf_Data*
elf_rawdata(Elf_Scn *scn, Elf_Data *data) {
Scn_Data *sd;
Elf *elf;
if (!scn) {
return NULL;
}
elf_assert(scn->s_magic == SCN_MAGIC);
elf = scn->s_elf;
elf_assert(elf);
elf_assert(elf->e_magic == ELF_MAGIC);
if (!elf->e_readable) {
return NULL;
}
else if (scn->s_index == SHN_UNDEF || scn->s_type == SHT_NULL) {
seterr(ERROR_NULLSCN);
}
else if (data) {
return NULL;
}
else if ((sd = scn->s_rawdata)) {
elf_assert(sd->sd_magic == DATA_MAGIC);
elf_assert(sd->sd_scn == scn);
return &sd->sd_data;
}
else if (scn->s_offset < 0 || scn->s_offset > elf->e_size) {
seterr(ERROR_OUTSIDE);
}
else if (scn->s_type != SHT_NOBITS
&& scn->s_offset + scn->s_size > elf->e_size) {
seterr(ERROR_TRUNC_SCN);
}
else if (!(sd = (Scn_Data*)malloc(sizeof(*sd)))) {
seterr(ERROR_MEM_SCNDATA);
}
else {
*sd = _elf_data_init;
sd->sd_scn = scn;
sd->sd_freeme = 1;
sd->sd_data.d_size = scn->s_size;
sd->sd_data.d_version = _elf_version;
if (scn->s_type != SHT_NOBITS && scn->s_size) {
if (!(sd->sd_memdata = (char*)malloc(scn->s_size))) {
seterr(ERROR_IO_2BIG);
free(sd);
return NULL;
}
else if (elf->e_rawdata) {
memcpy(sd->sd_memdata, elf->e_rawdata + scn->s_offset, scn->s_size);
}
else if (!_elf_read(elf, sd->sd_memdata, scn->s_offset, scn->s_size)) {
free(sd->sd_memdata);
free(sd);
return NULL;
}
sd->sd_data.d_buf = sd->sd_memdata;
sd->sd_free_data = 1;
}
scn->s_rawdata = sd;
return &sd->sd_data;
}
return NULL;
}

View File

@@ -1,54 +0,0 @@
/*
* rawfile.c - implementation of the elf_rawfile(3) function.
* Copyright (C) 1995 - 2009 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: rawfile.c,v 1.8 2009/05/22 17:07:46 michael Exp $";
#endif /* lint */
char*
elf_rawfile(Elf *elf, size_t *ptr) {
size_t tmp;
if (!ptr) {
ptr = &tmp;
}
*ptr = 0;
if (!elf) {
return NULL;
}
elf_assert(elf->e_magic == ELF_MAGIC);
if (!elf->e_readable) {
return NULL;
}
else if (elf->e_size) {
if (!elf->e_rawdata) {
elf_assert(elf->e_data);
if (!elf->e_cooked) {
elf->e_rawdata = elf->e_data;
}
else if (!(elf->e_rawdata = _elf_read(elf, NULL, 0, elf->e_size))) {
return NULL;
}
}
*ptr = elf->e_size;
}
return elf->e_rawdata;
}

View File

@@ -1,150 +0,0 @@
/*
* strptr.c - implementation of the elf_strptr(3) function.
* Copyright (C) 1995 - 2007 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: strptr.c,v 1.12 2008/05/23 08:15:35 michael Exp $";
#endif /* lint */
char*
elf_strptr(Elf *elf, size_t section, size_t offset) {
Elf_Data *data;
Elf_Scn *scn;
size_t n;
char *s;
if (!elf) {
return NULL;
}
elf_assert(elf->e_magic == ELF_MAGIC);
if (!(scn = elf_getscn(elf, section))) {
return NULL;
}
if (scn->s_index == SHN_UNDEF) {
seterr(ERROR_NOSTRTAB);
return NULL;
}
/*
* checking the section header is more appropriate
*/
if (elf->e_class == ELFCLASS32) {
if (scn->s_shdr32.sh_type != SHT_STRTAB) {
seterr(ERROR_NOSTRTAB);
return NULL;
}
}
#if __LIBELF64
else if (elf->e_class == ELFCLASS64) {
if (scn->s_shdr64.sh_type != SHT_STRTAB) {
seterr(ERROR_NOSTRTAB);
return NULL;
}
}
#endif /* __LIBELF64 */
else if (valid_class(elf->e_class)) {
seterr(ERROR_UNIMPLEMENTED);
return NULL;
}
else {
seterr(ERROR_UNKNOWN_CLASS);
return NULL;
}
/*
* Find matching buffer
*/
n = 0;
data = NULL;
if (elf->e_elf_flags & ELF_F_LAYOUT) {
/*
* Programmer is responsible for d_off
* Note: buffers may be in any order!
*/
while ((data = elf_getdata(scn, data))) {
n = data->d_off;
if (offset >= n && offset - n < data->d_size) {
/*
* Found it
*/
break;
}
}
}
else {
/*
* Calculate offsets myself
*/
while ((data = elf_getdata(scn, data))) {
if (data->d_align > 1) {
n += data->d_align - 1;
n -= n % data->d_align;
}
if (offset < n) {
/*
* Invalid offset: points into a hole
*/
seterr(ERROR_BADSTROFF);
return NULL;
}
if (offset - n < data->d_size) {
/*
* Found it
*/
break;
}
n += data->d_size;
}
}
if (data == NULL) {
/*
* Not found
*/
seterr(ERROR_BADSTROFF);
return NULL;
}
if (data->d_buf == NULL) {
/*
* Buffer is NULL (usually the programmers' fault)
*/
seterr(ERROR_NULLBUF);
return NULL;
}
offset -= n;
s = (char*)data->d_buf;
if (!(_elf_sanity_checks & SANITY_CHECK_STRPTR)) {
return s + offset;
}
/*
* Perform extra sanity check
*/
for (n = offset; n < data->d_size; n++) {
if (s[n] == '\0') {
/*
* Return properly NUL terminated string
*/
return s + offset;
}
}
/*
* String is not NUL terminated
* Return error to avoid SEGV in application
*/
seterr(ERROR_UNTERM);
return NULL;
}

View File

@@ -1,81 +0,0 @@
/*
swap64.c - 64-bit byte swapping functions.
Copyright (C) 1995 - 2001 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#include <byteswap.h>
#if __LIBELF64
#ifndef lint
static const char rcsid[] = "@(#) $Id: swap64.c,v 1.6 2008/05/23 08:15:35 michael Exp $";
#endif /* lint */
__libelf_u64_t
_elf_load_u64L(const unsigned char *from) {
return ((__libelf_u64_t)__load_u32L(from + 4) << 32)
| (__libelf_u64_t)__load_u32L(from);
}
__libelf_u64_t
_elf_load_u64M(const unsigned char *from) {
return ((__libelf_u64_t)__load_u32M(from) << 32)
| (__libelf_u64_t)__load_u32M(from + 4);
}
__libelf_i64_t
_elf_load_i64L(const unsigned char *from) {
return ((__libelf_i64_t)__load_i32L(from + 4) << 32)
| (__libelf_u64_t)__load_u32L(from);
}
__libelf_i64_t
_elf_load_i64M(const unsigned char *from) {
return ((__libelf_i64_t)__load_i32M(from) << 32)
| (__libelf_u64_t)__load_u32M(from + 4);
}
void
_elf_store_u64L(unsigned char *to, __libelf_u64_t v) {
__store_u32L(to, (__libelf_u32_t)v);
v >>= 32;
__store_u32L(to + 4, (__libelf_u32_t)v);
}
void
_elf_store_u64M(unsigned char *to, __libelf_u64_t v) {
__store_u32M(to + 4, (__libelf_u32_t)v);
v >>= 32;
__store_u32M(to, (__libelf_u32_t)v);
}
void
_elf_store_i64L(unsigned char *to, __libelf_u64_t v) {
__store_u32L(to, (__libelf_u32_t)v);
v >>= 32;
__store_i32L(to + 4, (__libelf_u32_t)v);
}
void
_elf_store_i64M(unsigned char *to, __libelf_u64_t v) {
__store_u32M(to + 4, (__libelf_u32_t)v);
v >>= 32;
__store_i32M(to, (__libelf_u32_t)v);
}
#endif /* __LIBELF64 */

File diff suppressed because it is too large Load Diff

View File

@@ -1,241 +0,0 @@
/*
* verdef.h - copy versioning information.
* Copyright (C) 2001 - 2006 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef lint
static const char verdef_h_rcsid[] = "@(#) $Id: verdef.h,v 1.13 2008/05/23 08:15:35 michael Exp $";
#endif /* lint */
#if VER_DEF_CURRENT != 1
#error libelf currently does not support VER_DEF_CURRENT != 1
#endif /* VER_DEF_CURRENT != 1 */
#if TOFILE
static void
__store_verdaux(verdaux_ftype *dst, const verdaux_mtype *src, unsigned enc) {
if (enc == ELFDATA2LSB) {
__store_u32L(dst->vda_name, src->vda_name);
__store_u32L(dst->vda_next, src->vda_next);
}
else {
__store_u32M(dst->vda_name, src->vda_name);
__store_u32M(dst->vda_next, src->vda_next);
}
}
static void
__store_verdef(verdef_ftype *dst, const verdef_mtype *src, unsigned enc) {
if (enc == ELFDATA2LSB) {
__store_u16L(dst->vd_version, src->vd_version);
__store_u16L(dst->vd_flags, src->vd_flags);
__store_u16L(dst->vd_ndx, src->vd_ndx);
__store_u16L(dst->vd_cnt, src->vd_cnt);
__store_u32L(dst->vd_hash, src->vd_hash);
__store_u32L(dst->vd_aux, src->vd_aux);
__store_u32L(dst->vd_next, src->vd_next);
}
else {
__store_u16M(dst->vd_version, src->vd_version);
__store_u16M(dst->vd_flags, src->vd_flags);
__store_u16M(dst->vd_ndx, src->vd_ndx);
__store_u16M(dst->vd_cnt, src->vd_cnt);
__store_u32M(dst->vd_hash, src->vd_hash);
__store_u32M(dst->vd_aux, src->vd_aux);
__store_u32M(dst->vd_next, src->vd_next);
}
}
typedef verdaux_mtype verdaux_stype;
typedef verdaux_ftype verdaux_dtype;
typedef verdef_mtype verdef_stype;
typedef verdef_ftype verdef_dtype;
typedef align_mtype verdef_atype;
#define copy_verdaux_srctotmp(d, s, e) (*(d) = *(s))
#define copy_verdaux_tmptodst(d, s, e) __store_verdaux((d), (s), (e))
#define copy_verdef_srctotmp(d, s, e) (*(d) = *(s))
#define copy_verdef_tmptodst(d, s, e) __store_verdef((d), (s), (e))
#define translator_suffix _tof
#else /* TOFILE */
static void
__load_verdaux(verdaux_mtype *dst, const verdaux_ftype *src, unsigned enc) {
if (enc == ELFDATA2LSB) {
dst->vda_name = __load_u32L(src->vda_name);
dst->vda_next = __load_u32L(src->vda_next);
}
else {
dst->vda_name = __load_u32M(src->vda_name);
dst->vda_next = __load_u32M(src->vda_next);
}
}
static void
__load_verdef(verdef_mtype *dst, const verdef_ftype *src, unsigned enc) {
if (enc == ELFDATA2LSB) {
dst->vd_version = __load_u16L(src->vd_version);
dst->vd_flags = __load_u16L(src->vd_flags);
dst->vd_ndx = __load_u16L(src->vd_ndx);
dst->vd_cnt = __load_u16L(src->vd_cnt);
dst->vd_hash = __load_u32L(src->vd_hash);
dst->vd_aux = __load_u32L(src->vd_aux);
dst->vd_next = __load_u32L(src->vd_next);
}
else {
dst->vd_version = __load_u16M(src->vd_version);
dst->vd_flags = __load_u16M(src->vd_flags);
dst->vd_ndx = __load_u16M(src->vd_ndx);
dst->vd_cnt = __load_u16M(src->vd_cnt);
dst->vd_hash = __load_u32M(src->vd_hash);
dst->vd_aux = __load_u32M(src->vd_aux);
dst->vd_next = __load_u32M(src->vd_next);
}
}
typedef verdaux_ftype verdaux_stype;
typedef verdaux_mtype verdaux_dtype;
typedef verdef_ftype verdef_stype;
typedef verdef_mtype verdef_dtype;
typedef align_ftype verdef_atype;
#define copy_verdaux_srctotmp(d, s, e) __load_verdaux((d), (s), (e))
#define copy_verdaux_tmptodst(d, s, e) (*(d) = *(s))
#define copy_verdef_srctotmp(d, s, e) __load_verdef((d), (s), (e))
#define copy_verdef_tmptodst(d, s, e) (*(d) = *(s))
#define translator_suffix _tom
#endif /* TOFILE */
#define cat3(a,b,c) a##b##c
#define xlt3(p,e,s) cat3(p,e,s)
#define xltprefix(x) xlt3(x,_,class_suffix)
#define translator(x,e) xlt3(xltprefix(_elf_##x),e,translator_suffix)
static size_t
xlt_verdef(unsigned char *dst, const unsigned char *src, size_t n, unsigned enc) {
size_t off;
if (sizeof(verdef_stype) != sizeof(verdef_dtype)
|| sizeof(verdaux_stype) != sizeof(verdaux_dtype)) {
/* never happens for ELF v1 and Verneed v1 */
seterr(ERROR_UNIMPLEMENTED);
return (size_t)-1;
}
/* size translation shortcut */
if (dst == NULL) {
return n;
}
if (src == NULL) {
seterr(ERROR_NULLBUF);
return (size_t)-1;
}
off = 0;
while (off + sizeof(verdef_stype) <= n) {
const verdef_stype *svd;
verdef_dtype *dvd;
verdef_mtype vd;
size_t acount;
size_t aoff;
/*
* check for proper alignment
*/
if (off % sizeof(verdef_atype)) {
seterr(ERROR_VERDEF_FORMAT);
return (size_t)-1;
}
/*
* copy and check src
*/
svd = (verdef_stype*)(src + off);
dvd = (verdef_dtype*)(dst + off);
copy_verdef_srctotmp(&vd, svd, enc);
if (vd.vd_version < 1
|| vd.vd_version > VER_DEF_CURRENT) {
seterr(ERROR_VERDEF_VERSION);
return (size_t)-1;
}
if (vd.vd_cnt < 1
|| vd.vd_aux == 0) {
seterr(ERROR_VERDEF_FORMAT);
return (size_t)-1;
}
copy_verdef_tmptodst(dvd, &vd, enc);
/*
* copy aux array
*/
aoff = off + vd.vd_aux;
for (acount = 0; acount < vd.vd_cnt; acount++) {
const verdaux_stype *svda;
verdaux_dtype *dvda;
verdaux_mtype vda;
/*
* are we still inside the buffer limits?
*/
if (aoff + sizeof(verdaux_stype) > n) {
break;
}
/*
* check for proper alignment
*/
if (aoff % sizeof(verdef_atype)) {
seterr(ERROR_VERDEF_FORMAT);
return (size_t)-1;
}
/*
* copy and check src
*/
svda = (verdaux_stype*)(src + aoff);
dvda = (verdaux_dtype*)(dst + aoff);
copy_verdaux_srctotmp(&vda, svda, enc);
copy_verdaux_tmptodst(dvda, &vda, enc);
/*
* advance to next verdaux
*/
if (vda.vda_next == 0) {
/* end of list */
break;
}
aoff += vda.vda_next;
}
/*
* advance to next verdef
*/
if (vd.vd_next == 0) {
/* end of list */
break;
}
off += vd.vd_next;
}
return n;
}
size_t
translator(verdef,L11)(unsigned char *dst, const unsigned char *src, size_t n) {
return xlt_verdef(dst, src, n, ELFDATA2LSB);
}
size_t
translator(verdef,M11)(unsigned char *dst, const unsigned char *src, size_t n) {
return xlt_verdef(dst, src, n, ELFDATA2MSB);
}

View File

@@ -1,53 +0,0 @@
/*
verdef_32_tof.c - copy 32-bit versioning information.
Copyright (C) 2001 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#include <ext_types.h>
#include <byteswap.h>
#if __LIBELF_SYMBOL_VERSIONS
#ifndef lint
static const char rcsid[] = "@(#) $Id: verdef_32_tof.c,v 1.5 2008/05/23 08:15:35 michael Exp $";
#endif /* lint */
typedef Elf32_Verdaux verdaux_mtype;
typedef Elf32_Verdef verdef_mtype;
typedef Elf32_Vernaux vernaux_mtype;
typedef Elf32_Verneed verneed_mtype;
typedef Elf32_Word align_mtype;
typedef __ext_Elf32_Verdaux verdaux_ftype;
typedef __ext_Elf32_Verdef verdef_ftype;
typedef __ext_Elf32_Vernaux vernaux_ftype;
typedef __ext_Elf32_Verneed verneed_ftype;
typedef __ext_Elf32_Word align_ftype;
#define class_suffix 32
#undef TOFILE
#define TOFILE 1
/*
* Include shared code
*/
#include "verdef.h"
#include "verneed.h"
#endif /* __LIBELF_SYMBOL_VERSIONS */

View File

@@ -1,53 +0,0 @@
/*
verdef_32_tom.c - copy 32-bit versioning information.
Copyright (C) 2001 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#include <ext_types.h>
#include <byteswap.h>
#if __LIBELF_SYMBOL_VERSIONS
#ifndef lint
static const char rcsid[] = "@(#) $Id: verdef_32_tom.c,v 1.5 2008/05/23 08:15:35 michael Exp $";
#endif /* lint */
typedef Elf32_Verdaux verdaux_mtype;
typedef Elf32_Verdef verdef_mtype;
typedef Elf32_Vernaux vernaux_mtype;
typedef Elf32_Verneed verneed_mtype;
typedef Elf32_Word align_mtype;
typedef __ext_Elf32_Verdaux verdaux_ftype;
typedef __ext_Elf32_Verdef verdef_ftype;
typedef __ext_Elf32_Vernaux vernaux_ftype;
typedef __ext_Elf32_Verneed verneed_ftype;
typedef __ext_Elf32_Word align_ftype;
#define class_suffix 32
#undef TOFILE
#define TOFILE 0
/*
* Include shared code
*/
#include "verdef.h"
#include "verneed.h"
#endif /* __LIBELF_SYMBOL_VERSIONS */

View File

@@ -1,53 +0,0 @@
/*
verdef_64_tof.c - copy 64-bit versioning information.
Copyright (C) 2001 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#include <ext_types.h>
#include <byteswap.h>
#if __LIBELF64 && __LIBELF_SYMBOL_VERSIONS
#ifndef lint
static const char rcsid[] = "@(#) $Id: verdef_64_tof.c,v 1.5 2008/05/23 08:15:35 michael Exp $";
#endif /* lint */
typedef Elf64_Verdaux verdaux_mtype;
typedef Elf64_Verdef verdef_mtype;
typedef Elf64_Vernaux vernaux_mtype;
typedef Elf64_Verneed verneed_mtype;
typedef Elf64_Word align_mtype;
typedef __ext_Elf64_Verdaux verdaux_ftype;
typedef __ext_Elf64_Verdef verdef_ftype;
typedef __ext_Elf64_Vernaux vernaux_ftype;
typedef __ext_Elf64_Verneed verneed_ftype;
typedef __ext_Elf64_Word align_ftype;
#define class_suffix 64
#undef TOFILE
#define TOFILE 1
/*
* Include shared code
*/
#include "verdef.h"
#include "verneed.h"
#endif /* __LIBELF64 && __LIBELF_SYMBOL_VERSIONS */

View File

@@ -1,53 +0,0 @@
/*
verdef_64_tom.c - copy 64-bit versioning information.
Copyright (C) 2001 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#include <ext_types.h>
#include <byteswap.h>
#if __LIBELF64 && __LIBELF_SYMBOL_VERSIONS
#ifndef lint
static const char rcsid[] = "@(#) $Id: verdef_64_tom.c,v 1.5 2008/05/23 08:15:35 michael Exp $";
#endif /* lint */
typedef Elf64_Verdaux verdaux_mtype;
typedef Elf64_Verdef verdef_mtype;
typedef Elf64_Vernaux vernaux_mtype;
typedef Elf64_Verneed verneed_mtype;
typedef Elf64_Word align_mtype;
typedef __ext_Elf64_Verdaux verdaux_ftype;
typedef __ext_Elf64_Verdef verdef_ftype;
typedef __ext_Elf64_Vernaux vernaux_ftype;
typedef __ext_Elf64_Verneed verneed_ftype;
typedef __ext_Elf64_Word align_ftype;
#define class_suffix 64
#undef TOFILE
#define TOFILE 0
/*
* Include shared code
*/
#include "verdef.h"
#include "verneed.h"
#endif /* __LIBELF64 && __LIBELF_SYMBOL_VERSIONS */

View File

@@ -1,245 +0,0 @@
/*
* verneed.h - copy versioning information.
* Copyright (C) 2001 - 2006 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef lint
static const char verneed_h_rcsid[] = "@(#) $Id: verneed.h,v 1.13 2008/05/23 08:15:35 michael Exp $";
#endif /* lint */
#if VER_NEED_CURRENT != 1
#error libelf currently does not support VER_NEED_CURRENT != 1
#endif /* VER_NEED_CURRENT != 1 */
#if TOFILE
static void
__store_vernaux(vernaux_ftype *dst, const vernaux_mtype *src, unsigned enc) {
if (enc == ELFDATA2LSB) {
__store_u32L(dst->vna_hash, src->vna_hash);
__store_u16L(dst->vna_flags, src->vna_flags);
__store_u16L(dst->vna_other, src->vna_other);
__store_u32L(dst->vna_name, src->vna_name);
__store_u32L(dst->vna_next, src->vna_next);
}
else {
__store_u32M(dst->vna_hash, src->vna_hash);
__store_u16M(dst->vna_flags, src->vna_flags);
__store_u16M(dst->vna_other, src->vna_other);
__store_u32M(dst->vna_name, src->vna_name);
__store_u32M(dst->vna_next, src->vna_next);
}
}
static void
__store_verneed(verneed_ftype *dst, const verneed_mtype *src, unsigned enc) {
if (enc == ELFDATA2LSB) {
__store_u16L(dst->vn_version, src->vn_version);
__store_u16L(dst->vn_cnt, src->vn_cnt);
__store_u32L(dst->vn_file, src->vn_file);
__store_u32L(dst->vn_aux, src->vn_aux);
__store_u32L(dst->vn_next, src->vn_next);
}
else {
__store_u16M(dst->vn_version, src->vn_version);
__store_u16M(dst->vn_cnt, src->vn_cnt);
__store_u32M(dst->vn_file, src->vn_file);
__store_u32M(dst->vn_aux, src->vn_aux);
__store_u32M(dst->vn_next, src->vn_next);
}
}
typedef vernaux_mtype vernaux_stype;
typedef vernaux_ftype vernaux_dtype;
typedef verneed_mtype verneed_stype;
typedef verneed_ftype verneed_dtype;
typedef align_mtype verneed_atype;
#define copy_vernaux_srctotmp(d, s, e) (*(d) = *(s))
#define copy_vernaux_tmptodst(d, s, e) __store_vernaux((d), (s), (e))
#define copy_verneed_srctotmp(d, s, e) (*(d) = *(s))
#define copy_verneed_tmptodst(d, s, e) __store_verneed((d), (s), (e))
#define translator_suffix _tof
#else /* TOFILE */
static void
__load_vernaux(vernaux_mtype *dst, const vernaux_ftype *src, unsigned enc) {
if (enc == ELFDATA2LSB) {
dst->vna_hash = __load_u32L(src->vna_hash);
dst->vna_flags = __load_u16L(src->vna_flags);
dst->vna_other = __load_u16L(src->vna_other);
dst->vna_name = __load_u32L(src->vna_name);
dst->vna_next = __load_u32L(src->vna_next);
}
else {
dst->vna_hash = __load_u32M(src->vna_hash);
dst->vna_flags = __load_u16M(src->vna_flags);
dst->vna_other = __load_u16M(src->vna_other);
dst->vna_name = __load_u32M(src->vna_name);
dst->vna_next = __load_u32M(src->vna_next);
}
}
static void
__load_verneed(verneed_mtype *dst, const verneed_ftype *src, unsigned enc) {
if (enc == ELFDATA2LSB) {
dst->vn_version = __load_u16L(src->vn_version);
dst->vn_cnt = __load_u16L(src->vn_cnt);
dst->vn_file = __load_u32L(src->vn_file);
dst->vn_aux = __load_u32L(src->vn_aux);
dst->vn_next = __load_u32L(src->vn_next);
}
else {
dst->vn_version = __load_u16M(src->vn_version);
dst->vn_cnt = __load_u16M(src->vn_cnt);
dst->vn_file = __load_u32M(src->vn_file);
dst->vn_aux = __load_u32M(src->vn_aux);
dst->vn_next = __load_u32M(src->vn_next);
}
}
typedef vernaux_ftype vernaux_stype;
typedef vernaux_mtype vernaux_dtype;
typedef verneed_ftype verneed_stype;
typedef verneed_mtype verneed_dtype;
typedef align_ftype verneed_atype;
#define copy_vernaux_srctotmp(d, s, e) __load_vernaux((d), (s), (e))
#define copy_vernaux_tmptodst(d, s, e) (*(d) = *(s))
#define copy_verneed_srctotmp(d, s, e) __load_verneed((d), (s), (e))
#define copy_verneed_tmptodst(d, s, e) (*(d) = *(s))
#define translator_suffix _tom
#endif /* TOFILE */
#define cat3(a,b,c) a##b##c
#define xlt3(p,e,s) cat3(p,e,s)
#define xltprefix(x) xlt3(x,_,class_suffix)
#define translator(x,e) xlt3(xltprefix(_elf_##x),e,translator_suffix)
static size_t
xlt_verneed(unsigned char *dst, const unsigned char *src, size_t n, unsigned enc) {
size_t off;
if (sizeof(verneed_stype) != sizeof(verneed_dtype)
|| sizeof(vernaux_stype) != sizeof(vernaux_dtype)) {
/* never happens for ELF v1 and Verneed v1 */
seterr(ERROR_UNIMPLEMENTED);
return (size_t)-1;
}
/* size translation shortcut */
if (dst == NULL) {
return n;
}
if (src == NULL) {
seterr(ERROR_NULLBUF);
return (size_t)-1;
}
off = 0;
while (off + sizeof(verneed_stype) <= n) {
const verneed_stype *svn;
verneed_dtype *dvn;
verneed_mtype vn;
size_t acount;
size_t aoff;
/*
* check for proper alignment
*/
if (off % sizeof(verneed_atype)) {
seterr(ERROR_VERNEED_FORMAT);
return (size_t)-1;
}
/*
* copy and check src
*/
svn = (verneed_stype*)(src + off);
dvn = (verneed_dtype*)(dst + off);
copy_verneed_srctotmp(&vn, svn, enc);
if (vn.vn_version < 1
|| vn.vn_version > VER_NEED_CURRENT) {
seterr(ERROR_VERNEED_VERSION);
return (size_t)-1;
}
if (vn.vn_cnt < 1
|| vn.vn_aux == 0) {
seterr(ERROR_VERNEED_FORMAT);
return (size_t)-1;
}
copy_verneed_tmptodst(dvn, &vn, enc);
/*
* copy aux array
*/
aoff = off + vn.vn_aux;
for (acount = 0; acount < vn.vn_cnt; acount++) {
const vernaux_stype *svna;
vernaux_dtype *dvna;
vernaux_mtype vna;
/*
* are we still inside the buffer limits?
*/
if (aoff + sizeof(vernaux_stype) > n) {
break;
}
/*
* check for proper alignment
*/
if (aoff % sizeof(verneed_atype)) {
seterr(ERROR_VERNEED_FORMAT);
return (size_t)-1;
}
/*
* copy and check src
*/
svna = (vernaux_stype*)(src + aoff);
dvna = (vernaux_dtype*)(dst + aoff);
copy_vernaux_srctotmp(&vna, svna, enc);
copy_vernaux_tmptodst(dvna, &vna, enc);
/*
* advance to next vernaux
*/
if (vna.vna_next == 0) {
/* end of list */
break;
}
aoff += vna.vna_next;
}
/*
* advance to next verneed
*/
if (vn.vn_next == 0) {
/* end of list */
break;
}
off += vn.vn_next;
}
return n;
}
size_t
translator(verneed,L11)(unsigned char *dst, const unsigned char *src, size_t n) {
return xlt_verneed(dst, src, n, ELFDATA2LSB);
}
size_t
translator(verneed,M11)(unsigned char *dst, const unsigned char *src, size_t n) {
return xlt_verneed(dst, src, n, ELFDATA2MSB);
}

View File

@@ -1,44 +0,0 @@
/*
* version.c - implementation of the elf_version(3) function.
* Copyright (C) 1995 - 1998, 2007 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: version.c,v 1.8 2008/05/23 08:15:35 michael Exp $";
#endif /* lint */
unsigned
elf_version(unsigned ver) {
const char *s;
unsigned tmp;
if ((s = getenv("LIBELF_SANITY_CHECKS"))) {
_elf_sanity_checks = (int)strtol(s, (char**)NULL, 0);
}
if (ver == EV_NONE) {
return EV_CURRENT;
}
if (!valid_version(ver)) {
seterr(ERROR_UNKNOWN_VERSION);
return EV_NONE;
}
tmp = _elf_version == EV_NONE ? EV_CURRENT : _elf_version;
_elf_version = ver;
return tmp;
}

View File

@@ -1,190 +0,0 @@
/*
* x.elfext.c -- handle ELF format extensions
* Copyright (C) 2002 - 2006 Michael Riepe
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: x.elfext.c,v 1.5 2009/07/07 17:57:43 michael Exp $";
#endif /* lint */
int
elf_getphdrnum(Elf *elf, size_t *resultp) {
if (!elf) {
return -1;
}
elf_assert(elf->e_magic == ELF_MAGIC);
if (elf->e_kind != ELF_K_ELF) {
seterr(ERROR_NOTELF);
return -1;
}
if (!elf->e_ehdr && !_elf_cook(elf)) {
return -1;
}
if (resultp) {
*resultp = elf->e_phnum;
}
return 0;
}
int
elf_getshdrnum(Elf *elf, size_t *resultp) {
size_t num = 0;
Elf_Scn *scn;
if (!elf) {
return -1;
}
elf_assert(elf->e_magic == ELF_MAGIC);
if (elf->e_kind != ELF_K_ELF) {
seterr(ERROR_NOTELF);
return -1;
}
if (!elf->e_ehdr && !_elf_cook(elf)) {
return -1;
}
if ((scn = elf->e_scn_n)) {
num = scn->s_index + 1;
}
if (resultp) {
*resultp = num;
}
return 0;
}
int
elf_getshdrstrndx(Elf *elf, size_t *resultp) {
size_t num = 0;
size_t dummy;
Elf_Scn *scn;
if (!elf) {
return -1;
}
elf_assert(elf->e_magic == ELF_MAGIC);
if (resultp == NULL) {
resultp = &dummy; /* handle NULL pointer gracefully */
}
if (elf->e_kind != ELF_K_ELF) {
seterr(ERROR_NOTELF);
return -1;
}
if (!elf->e_ehdr && !_elf_cook(elf)) {
return -1;
}
if (elf->e_class == ELFCLASS32) {
num = ((Elf32_Ehdr*)elf->e_ehdr)->e_shstrndx;
}
#if __LIBELF64
else if (elf->e_class == ELFCLASS64) {
num = ((Elf64_Ehdr*)elf->e_ehdr)->e_shstrndx;
}
#endif /* __LIBELF64 */
else {
if (valid_class(elf->e_class)) {
seterr(ERROR_UNIMPLEMENTED);
}
else {
seterr(ERROR_UNKNOWN_CLASS);
}
return -1;
}
if (num != SHN_XINDEX) {
*resultp = num;
return 0;
}
/*
* look at first section header
*/
if (!(scn = elf->e_scn_1)) {
seterr(ERROR_NOSUCHSCN);
return -1;
}
elf_assert(scn->s_magic == SCN_MAGIC);
#if __LIBELF64
if (elf->e_class == ELFCLASS64) {
*resultp = scn->s_shdr64.sh_link;
return 0;
}
#endif /* __LIBELF64 */
*resultp = scn->s_shdr32.sh_link;
return 0;
}
int
elf_getphnum(Elf *elf, size_t *resultp) {
return elf_getphdrnum(elf, resultp) ? LIBELF_FAILURE : LIBELF_SUCCESS;
}
int
elf_getshnum(Elf *elf, size_t *resultp) {
return elf_getshdrnum(elf, resultp) ? LIBELF_FAILURE : LIBELF_SUCCESS;
}
int
elf_getshstrndx(Elf *elf, size_t *resultp) {
return elf_getshdrstrndx(elf, resultp) ? LIBELF_FAILURE : LIBELF_SUCCESS;
}
int
elfx_update_shstrndx(Elf *elf, size_t value) {
size_t extvalue = 0;
Elf_Scn *scn;
if (!elf) {
return LIBELF_FAILURE;
}
elf_assert(elf->e_magic == ELF_MAGIC);
if (value >= SHN_LORESERVE) {
extvalue = value;
value = SHN_XINDEX;
}
if (elf->e_kind != ELF_K_ELF) {
seterr(ERROR_NOTELF);
return LIBELF_FAILURE;
}
if (!elf->e_ehdr && !_elf_cook(elf)) {
return LIBELF_FAILURE;
}
if (!(scn = _elf_first_scn(elf))) {
return LIBELF_FAILURE;
}
elf_assert(scn->s_magic == SCN_MAGIC);
if (elf->e_class == ELFCLASS32) {
((Elf32_Ehdr*)elf->e_ehdr)->e_shstrndx = value;
scn->s_shdr32.sh_link = extvalue;
}
#if __LIBELF64
else if (elf->e_class == ELFCLASS64) {
((Elf64_Ehdr*)elf->e_ehdr)->e_shstrndx = value;
scn->s_shdr64.sh_link = extvalue;
}
#endif /* __LIBELF64 */
else {
if (valid_class(elf->e_class)) {
seterr(ERROR_UNIMPLEMENTED);
}
else {
seterr(ERROR_UNKNOWN_CLASS);
}
return LIBELF_FAILURE;
}
elf->e_ehdr_flags |= ELF_F_DIRTY;
scn->s_shdr_flags |= ELF_F_DIRTY;
return LIBELF_SUCCESS;
}

View File

@@ -1,112 +0,0 @@
/*
x.movscn.c - implementation of the elfx_movscn(3) function.
Copyright (C) 1995 - 2001, 2003 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: x.movscn.c,v 1.14 2008/05/23 08:15:35 michael Exp $";
#endif /* lint */
size_t
elfx_movscn(Elf *elf, Elf_Scn *scn, Elf_Scn *after) {
Elf_Scn *prev;
Elf_Scn *tmp;
int off;
if (!elf || !scn || !after) {
return SHN_UNDEF;
}
elf_assert(elf->e_magic == ELF_MAGIC);
if (elf->e_kind != ELF_K_ELF) {
seterr(ERROR_NOTELF);
return SHN_UNDEF;
}
elf_assert(scn->s_magic == SCN_MAGIC);
elf_assert(after->s_magic == SCN_MAGIC);
if (scn->s_elf != elf || after->s_elf != elf) {
seterr(ERROR_ELFSCNMISMATCH);
return SHN_UNDEF;
}
elf_assert(elf->e_scn_1);
if (scn == elf->e_scn_1) {
seterr(ERROR_NULLSCN);
return SHN_UNDEF;
}
if (scn == after || scn == after->s_link) {
/* nothing to do */
return scn->s_index;
}
/*
* Find previous section.
*/
prev = NULL;
for (tmp = elf->e_scn_1; tmp->s_link; tmp = tmp->s_link) {
if (tmp->s_link == scn) {
prev = tmp;
break;
}
}
elf_assert(prev != NULL);
/*
* Update section indices
*/
off = 0;
for (tmp = elf->e_scn_1; tmp; tmp = tmp->s_link) {
if (off) {
tmp->s_index += off;
}
if (tmp == after) {
off++;
}
else if (tmp == scn) {
off--;
}
}
elf_assert(off == 0);
/*
* Move section.
*/
prev->s_link = scn->s_link;
scn->s_link = after->s_link;
after->s_link = scn;
scn->s_index = after->s_index + 1;
if (elf->e_scn_n == scn) {
elf->e_scn_n = prev;
}
else if (elf->e_scn_n == after) {
elf->e_scn_n = scn;
}
#if ENABLE_DEBUG
/*
* Check section indices
*/
tmp = elf->e_scn_1;
elf_assert(tmp->s_index == 0);
while (tmp->s_link) {
elf_assert(tmp->s_link->s_index == tmp->s_index + 1);
tmp = tmp->s_link;
}
#endif /* ENABLE_DEBUG */
return scn->s_index;
}

View File

@@ -1,119 +0,0 @@
/*
x.remscn.c - implementation of the elfx_remscn(3) function.
Copyright (C) 1995 - 2001, 2003 Michael Riepe
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <private.h>
#ifndef lint
static const char rcsid[] = "@(#) $Id: x.remscn.c,v 1.15 2008/05/23 08:15:35 michael Exp $";
#endif /* lint */
size_t
elfx_remscn(Elf *elf, Elf_Scn *scn) {
Elf_Scn *pscn;
Scn_Data *sd;
Scn_Data *tmp;
size_t index;
if (!elf || !scn) {
return SHN_UNDEF;
}
elf_assert(elf->e_magic == ELF_MAGIC);
if (elf->e_kind != ELF_K_ELF) {
seterr(ERROR_NOTELF);
return SHN_UNDEF;
}
elf_assert(scn->s_magic == SCN_MAGIC);
elf_assert(elf->e_ehdr);
if (scn->s_elf != elf) {
seterr(ERROR_ELFSCNMISMATCH);
return SHN_UNDEF;
}
elf_assert(elf->e_scn_1);
if (scn == elf->e_scn_1) {
seterr(ERROR_NULLSCN);
return SHN_UNDEF;
}
/*
* Find previous section.
*/
for (pscn = elf->e_scn_1; pscn->s_link; pscn = pscn->s_link) {
if (pscn->s_link == scn) {
break;
}
}
if (pscn->s_link != scn) {
seterr(ERROR_ELFSCNMISMATCH);
return SHN_UNDEF;
}
/*
* Unlink section.
*/
if (elf->e_scn_n == scn) {
elf->e_scn_n = pscn;
}
pscn->s_link = scn->s_link;
index = scn->s_index;
/*
* Free section descriptor and data.
*/
for (sd = scn->s_data_1; sd; sd = tmp) {
elf_assert(sd->sd_magic == DATA_MAGIC);
elf_assert(sd->sd_scn == scn);
tmp = sd->sd_link;
if (sd->sd_free_data && sd->sd_memdata) {
free(sd->sd_memdata);
}
if (sd->sd_freeme) {
free(sd);
}
}
if ((sd = scn->s_rawdata)) {
elf_assert(sd->sd_magic == DATA_MAGIC);
elf_assert(sd->sd_scn == scn);
if (sd->sd_free_data && sd->sd_memdata) {
free(sd->sd_memdata);
}
if (sd->sd_freeme) {
free(sd);
}
}
if (scn->s_freeme) {
elf_assert(scn->s_index > 0);
free(scn);
}
/*
* Adjust section indices.
*/
for (scn = pscn->s_link; scn; scn = scn->s_link) {
elf_assert(scn->s_index > index);
scn->s_index--;
}
/*
* Adjust section count in ELF header
*/
if (_elf_update_shnum(elf, elf->e_scn_n->s_index + 1)) {
return SHN_UNDEF;
}
return index;
}

View File

@@ -1,91 +0,0 @@
Main developers:
Intra2net AG <opensource@intra2net.com>
Contributors in alphabetical order,
see Changelog for full details:
Adam Malinowski <amalinowski75@gmail.com>
Alain Abbas <aa@libertech.fr>
Alex Harford <harford@gmail.com>
Alexander Lehmann <lehmanna@in.tum.de>
Anders Larsen <al@alarsen.net>
Andrei Errapart <a.errapart@trenz-electronic.de>
Andrew John Rogers <andrew@rogerstech.co.uk>
Arnim Läuger <arnim.laeuger@gmx.net>
Aurelien Jarno <aurelien@aurel32.net>
Benjamin Vanheuverzwijn <bvanheu@gmail.com>
Chris Morgan <chmorgan@gmail.com>
Chris Zeh <chris.w.zeh@gmail.com>
Claudio Lanconelli <claudiolanconelli@gmail.com>
Clifford Wolf <clifford@clifford.at>
Dan Dedrick <dan.dedrick@gmail.com>
Daniel Kirkham <dk2@kirkham.id.au>
David Challis <dchallis@qsimaging.com>
Davide Michelizza <dmichelizza@gmail.com>
Denis Sirotkin <reg.libftdi@demitel.ru>
Diego Elio Pettenò <flameeyes@flameeyes.com>
Emil <emil@datel.co.uk>
Eneas U de Queiroz <cote2004-github@yahoo.com>
Eric Schott <els6@psu.edu>
Eugene Hutorny <eugene@hutorny.in.ua>
Evan Nemerson <evan@coeus-group.com>
Evgeny Sinelnikov <sin@geoft.ru>
Fabrice Fontaine <fontaine.fabrice@gmail.com>
Fahrzin Hemmati <fahhem@gmail.com>
Flynn Marquardt <ftdi@flynnux.de>
Forest Crossman <cyrozap@gmail.com>
Frank Dana <ferdnyc@gmail.com>
Holger Mößinger <h.moessinger@primes.de>
Ian Abbott <abbotti@mev.co.uk>
Jared Boone <jared@sharebrained.com>
Jarkko Sonninen <kasper@iki.fi>
Jean-Daniel Merkli <jdmerkli@computerscience.ch>
Jochen Sprickerhof <jochen@sprickerhof.de>
Joe Zbiciak <intvnut@gmail.com>
Jon Beniston <jon@beniston.com>
Jordan Rupprecht <rupprecht@google.com>
Juergen Beisert <juergen.beisert@weihenstephan.org>
Lorenz Moesenlechner <lorenz@hcilab.org>
Marek Vavruša <marek@vavrusa.com>
Marius Kintel <kintel@sim.no>
Mark Hämmerling <mail@markh.de>
Matthias Janke <janke@physi.uni-heidelberg.de>
Matthias Kranz <matthias@hcilab.org>
Matthias Richter <mail.to.mr@gmx.de>
Matthijs ten Berge <m.h.tenberge@alumnus.utwente.nl>
Max <max@koeln.ccc.de>
Maxwell Dreytser <admin@mdtech.us>
Michel Zou <xantares09@hotmail.com>
Mike Frysinger <vapier.adi@gmail.com>
Nathael Pajani <nathael.pajani@ed3l.fr>
Nathan Fraser <ndf@undershorts.org>
Oleg Seiljus <oseiljus@xverve.com>
Paul Fertser <fercerpav@gmail.com>
Pawel Jewstafjew <pawel.jewstafjew@gmail.com>
Peter Holik <peter@holik.at>
Raphael Assenat <raph@8d.com>
Richard Shaw <hobbes1069@gmail.com>
Robby McKilliam <robby.mckilliam@myriota.com>
Robert Cox <Robert.cox@novatechweb.com>
Robin Haberkorn <haberkorn@metratec.com>
Rodney Sinclair <rodney@sinclairrf.com>
Rogier Wolff <R.E.Wolff@harddisk-recovery.nl>
Rolf Fiedler <derRolf@gmx-topmail.de>
Roman Lapin <lampus.lapin@gmail.com>
Salvador Eduardo Tropea <salvador@inti.gob.ar>
Stephan Linz <linz@li-pro.net>
Steven Turner <steven.turner@ftdichip.com>
Tarek Heiland <tarek@illimitable.com>
Thilo Schulz <thilo@tjps.eu>
Thimo Eichstaedt <abc@digithi.de>
Thomas Fischl <fischl@fundf.net>
Thomas Klose <thomas.klose@hiperscan.com>
Tim Ansell <mithro@mithis.com>
Tom Saunders <trsaunders@gmail.com>
Uwe Bonnes <bon@elektron.ikp.physik.tu-darmstadt.de>
Vladimir Yakovlev <nagos@inbox.ru>
Wilfried Holzke <libftdi@holzke.net>
Xiaofan Chen <xiaofanc@gmail.com>
Yegor Yefremov <yegorslists@googlemail.com>
Yi-Shin Li <ysli@araisrobo.com>

View File

@@ -1,481 +0,0 @@
GNU LIBRARY GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1991 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the library GPL. It is
numbered 2 because it goes with version 2 of the ordinary GPL.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Library General Public License, applies to some
specially designated Free Software Foundation software, and to any
other libraries whose authors decide to use it. You can use it for
your libraries, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if
you distribute copies of the library, or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link a program with the library, you must provide
complete object files to the recipients so that they can relink them
with the library, after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
Our method of protecting your rights has two steps: (1) copyright
the library, and (2) offer you this license which gives you legal
permission to copy, distribute and/or modify the library.
Also, for each distributor's protection, we want to make certain
that everyone understands that there is no warranty for this free
library. If the library is modified by someone else and passed on, we
want its recipients to know that what they have is not the original
version, so that any problems introduced by others will not reflect on
the original authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that companies distributing free
software will individually obtain patent licenses, thus in effect
transforming the program into proprietary software. To prevent this,
we have made it clear that any patent must be licensed for everyone's
free use or not licensed at all.
Most GNU software, including some libraries, is covered by the ordinary
GNU General Public License, which was designed for utility programs. This
license, the GNU Library General Public License, applies to certain
designated libraries. This license is quite different from the ordinary
one; be sure to read it in full, and don't assume that anything in it is
the same as in the ordinary license.
The reason we have a separate public license for some libraries is that
they blur the distinction we usually make between modifying or adding to a
program and simply using it. Linking a program with a library, without
changing the library, is in some sense simply using the library, and is
analogous to running a utility program or application program. However, in
a textual and legal sense, the linked executable is a combined work, a
derivative of the original library, and the ordinary General Public License
treats it as such.
Because of this blurred distinction, using the ordinary General
Public License for libraries did not effectively promote software
sharing, because most developers did not use the libraries. We
concluded that weaker conditions might promote sharing better.
However, unrestricted linking of non-free programs would deprive the
users of those programs of all benefit from the free status of the
libraries themselves. This Library General Public License is intended to
permit developers of non-free programs to use free libraries, while
preserving your freedom as a user of such programs to change the free
libraries that are incorporated in them. (We have not seen how to achieve
this as regards changes in header files, but we have achieved it as regards
changes in the actual functions of the Library.) The hope is that this
will lead to faster development of free libraries.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, while the latter only
works together with the library.
Note that it is possible for a library to be covered by the ordinary
General Public License rather than by this special one.
GNU LIBRARY GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library which
contains a notice placed by the copyright holder or other authorized
party saying it may be distributed under the terms of this Library
General Public License (also called "this License"). Each licensee is
addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also compile or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
c) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
d) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the source code distributed need not include anything that is normally
distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Library General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms of the
ordinary General Public License).
To apply these terms, attach the following notices to the library. It is
safest to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least the
"copyright" line and a pointer to where the full notice is found.
<one line to give the library's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the library, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
<signature of Ty Coon>, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!

View File

@@ -1,280 +0,0 @@
New in 1.5 - 2020-07-07
-----------------------
* Implement tc[io]flush methods & deprecate broken purge_buffers methods
Please check your code for ftdi_usb_purge_rx_buffer(),
ftdi_usb_purge_tx_buffer() and ftdi_usb_purge_buffers()
and migrate to the new ftdi_tc[io]flush() methods.
Old code will continue to function, but you'll get
a deprecation warning during compilation.
* Add program to test buffer flush (purge) functionality
* Add kernel driver auto attach/detach.
See new AUTO_DETACH_REATACH_SIO_MODULE option
* Add ftdi_setflowctrl_xonxoff()
* ftdi_eeprom / eeprom handling:
* Unify handling of all boolean eeprom flags
* Add device release number support
* Add channel_a_driver support for type xxR chips
* Add support for group0 drive levels on x232H chips
* Fix handling of high_current_drive parameter
* Fix inverted handling of VCP driver field for TYPE_R chips
* New --verbose option for eeprom decode operation
* Add example code for async mode
* Add SPDX license identifiers to the core library & ftdi_eeprom
* Various python SWIG wrapper improvements
* Various cmake file improvements
* Fix small bugs in error code paths
New in 1.4 - 2017-08-07
-----------------------
* New ftdi_usb_open_bus_addr() open function
* Use BM/R series baud rate computation for FT230X
* ftdi_get_error_string() now returns const char*
* C++ API: Ability to open devices with empty descriptor strings
* C++ API: Fix enumerations for buffer purge and modem controls
* small build fixes and improvements in the python examples
* ftdi_eeprom / eeprom handling:
* New API function: ftdi_eeprom_get_strings()
* Fix USE_SERIAL handling for 230X type chips
* Make ftdi_read_eeprom_location() endianness independent
* Fix flashing of FT245R
New in 1.3 - 2016-05-20
-----------------------
* Added ftdi_usb_get_strings2() to prevent automatic device close (Fahrzin Hemmati)
* Added ftdi_transfer_data_cancel() for cancellation of a submitted transfer,
avoided resubmittion of a canceled transfer in the callbacks,
replaced calls to libusb_handle_events with
libusb_handle_events_timeout_completed (Eugene Hutorny)
* ftdi_eeprom / eeprom handling:
* Add support for arbitrary user data (Salvador Eduardo Tropea)
* Add --build-eeprom support (Salvador Eduardo Tropea)
* Fix use_usb_version config file option (Thilo Schulz)
* Ability to include other config files in EEPROM config file (Thilo Schulz)
* Add external oscillator enable bit (Raphael Assenat)
* Support channel configuration (Stephan Linz)
* Added --device option to ftdi_eeprom to specify FTDI device (Robin Haberkorn)
* Fixed EEPROM user-area space checks for FT232R and FT245R chips (Robin Haberkorn)
* Various improvements to CBUS handling, including the EEPROM (Robin Haberkorn)
* swig wrapper: Fix handling of binary strings in ftdi_write_data()
for python 3 (xantares09)
* cbus python example code (Rodney Sinclair)
* ftdi_stream: fix timeout setting (Ларионов Даниил)
* Fixed typo in CBUS defines: CBUSG_DRIVE1 -> CBUSH_DRIVE1
New in 1.2 - 2014-11-21
-----------------------
* Support for FT230X devices (Uwe Bonnes)
* ftdi_usb_get_strings(): Don't try to open an already open device (Denis Sirotkin)
* Support for finding devices bricked by the Windows driver (Forest Crossman)
* cmake build system: New LibFTDI1ConfigVersion.cmake file (xantares09)
* Fix a typo in the MPSSE command CLK_BYTES_OR_LOW (Benjamin Vanheuverzwijn)
* Minor fixes for MSVC++ (Andrei Errapart)
* Various small code improvements (Florian Preinstorfer, Jochen Sprickerhof, xantares09)
New in 1.1 - 2014-02-05
-----------------------
* Fix FT232H eeprom suspend pulldown setting (Davide Michelizza)
* Fix FT232H eeprom user area size (Davide Michelizza)
* Improved mingw build (Paul Fertser and Michel Zou)
* C++ wrapper: Get/set functions for USB timeouts (Jochen Sprickerhof)
* Partial support for FT230X (Nathael Pajani)
* New API function: ftdi_eeprom_set_strings() (Nathael Pajani)
* Prevent possible segfault in ftdi_eeprom_decode() (Nathael Pajani)
* Save device release number in eeprom (Jarkko Sonninen)
* Fix "self powered" eeprom flag (Jarkko Sonninen)
* Improved python wrapper (Michel Zou)
* Many buildsystem improvements (Michel Zou and Mike Frysinger)
* See the git history for more changes and fixes
New in 1.0 - 2013-01-29
-----------------------
* Ported to libusb 1.x (initial work by Jie Zhang)
* Many eeprom handling improvements (Uwe Bonnes, Anders Larsen)
* Renamed pkconfig, library .so etc. files to "libftdi1" (Intra2net)
* ftdi_eeprom is part of libftdi now (Intra2net)
* New baudrate calculation code + unit tests (Uwe Bonnes and Intra2net)
* Improved python bindings including python3 support (Michel Zou)
* Switched completely to cmake build system (Intra2net)
* cmake: Easy libftdi discovery via find_package() (Michel Zou)
* eeprom handling now done via get()/set() functions (Uwe Bonnes)
* C++ wrapper: Fixed use-after-free in List::find_all() (Intra2net)
* Documentation updates (Xiaofan Chen)
* See the git history for more changes and fixes
New in 0.20 - 2012-03-19
------------------------
* Support for FT232H (Uwe Bonnes)
* Fixed install location of header files (Uwe Bonnes and Intra2net)
* Backported serial_test tool from libftdi 1.x (Uwe Bonnes)
New in 0.19 - 2011-05-23
------------------------
* Make kernel driver detach configurable (Thomas Klose)
* Correct ftdi_poll_modem_status() result code (Tom Saunders)
* cmake build system improvements (Evgeny Sinelnikov)
* Fix uninitialized memory access in async mode (Intra2net)
* Support for FT232R eeprom features (Hermann Kraus)
* Fix size returned by ftdi_read_data (Hermann Kraus)
* C++ wrapper: Fix infinite recursion in set_bitmode (Intra2net)
* Improvements to the python wrapper (Flynn Marquardt and Chris Zeh)
New in 0.18 - 2010-06-25
------------------------
* Add ftdi_eeprom_free() to free allocated memory in eeprom (Wilfried Holzke)
* More generic error message for the FTDI kernel driver (Intra2net)
* Honor CPPFLAGS in python wrapper build (Alexander Lehmann)
* cmake: Fix package creation on 32-bit machines (Uwe Bonnes)
* Fix swig argument constraints (Intra2net)
* Don't segfault if device is closed or ftdi context is invalid (Intra2net)
* Ability to disable build of examples / documentation (Mike Frysinger and Intra2net)
* Fix typo in python wrapper build (Mike Frysinger)
* Autoconf build system improvements (Mike Frysinger)
New in 0.17 - 2009-12-19
------------------------
* C++ wrapper: Reduced code duplication and small other changes (Intra2net)
* Deprecated old ftdi_enable_bitbang() function (Intra2net)
* New ftdi_usb_open_desc_index() function (Intra2net)
* Added baud rate test example code (Intra2net)
* New serial input example code (Jim Paris)
* Fix modem status byte filtering for USB high speed chips (Intra2net and Jim Paris)
* Add bitmode for synchronous fifo in FT2232H (Uwe Bonnes)
* Fix usb_set_configuration() call on Windows 64 (NIL)
* Fix usb index in ftdi_convert_baudrate() for FT2232H/FT4232H chips (Thimo Eichstaedt)
* Set initial baudrate on correct interface instead of always the first one (Thimo Eichstaedt)
* Call usb_set_configuration() on Windows only (Uwe Bonnes)
* 64 bit and other buildsystem fixes (Uwe Bonnes)
* Don't build --with-async-mode w/ libusb-compat-0.1 (Clifford Wolf)
* Functions for read/write of a single eeprom location (Oleg Seiljus)
* Protect against double close of usb device (Nathan Fraser)
* Fix out-of-tree-build in python wrapper (Aurelien Jarno)
* Autoconf and doxygen cleanup (Jim Paris)
New in 0.16 - 2009-05-08
------------------------
* C++ wrapper: Reopen the device after calling get_strings() in Context::open() (Marek Vavruša and Intra2net)
* C++ wrapper: Fixed an inheritance problem (Marek Vavruša and Intra2net)
* C++ wrapper: Relicensed under GPLv2 + linking exception (Marek Vavruša and Intra2net)
* Support for FT2232H and FT4232H (David Challis, Alex Harford and Intra2net)
* Support for mingw cross compile (Uwe Bonnes)
* Python bindings and minor autoconf cleanup (Tarek Heiland)
* Code cleanup in various places (Intra2net)
* Fixed ftdi_read_chipid in some cases (Matthias Richter)
* eeprom decode function and small cleanups (Marius Kintel)
* cmake system improvements (Marius Kintel and Intra2net)
* Fix compilation in -ansi -pedantic mode (Matthias Janke)
New in 0.15 - 2008-12-19
------------------------
* Full C++ wrapper. Needs boost (Marek Vavruša and Intra2net)
* cmake rules (Marek Vavruša)
New in 0.14 - 2008-09-09
------------------------
* Fixed flow control code for second FT2232 interface (Marek Vavruša)
* Ability to set flow control via one USB call (Marek Vavruša)
* 64 bit build support in the RPM spec file (Uwe Bonnes)
* Small fix to the RPM spec file (Uwe Bonnes)
* Ability to set RS232 break type (Intra2net)
* Grouped flow control and modem status code together (Intra2net)
New in 0.13 - 2008-06-13
------------------------
* Build .spec file via configure.in (Intra2net)
* Fixed "libusb-config --cflags" call (Mike Frysinger and Intra2net)
* Always set usb configuration (Mike Frysinger and Intra2net)
* Improved libusb-win32 support (Mike Frysinger)
New in 0.12 - 2008-04-16
------------------------
* Fix build of documentation for "out of tree" builds
* Fix USB config descriptor in the eeprom (Juergen Beisert)
* Ability to purge RX/TX buffers separately (Arnim Läuger)
* Setting of event and error character (Arnim Läuger)
* Poll modem status function (Arnim Läuger and Intra2net)
* Updated documentation and created AUTHORS file
New in 0.11 - 2008-03-01
------------------------
* Vala bindings helper functions (ftdi_new, ftdi_free, ftdi_list_free2) (Even Nermerson)
* Support for different EEPROM sizes (Andrew John Rogers, andrew@rogerstech.co.uk)
* Async write support. Linux only and no error handling.
You have to enable it via --with-async-mode.
* Detection of R-type chips
* FTDIChip-ID read support (Peter Holik)
New in 0.10 - 2007-05-08
------------------------
* Examples for libftdi_usb_find_all and CBUS mode
* Fixed ftdi_list_free
* Small cosmetic changes
New in 0.9 - 2007-02-09
-----------------------
* Fixed build without doxygen
* Correct .so file library version
New in 0.8 - 2007-02-08
-----------------------
* Complete doxygen documentation and examples
* Extended FT2232C bitbang mode example code (Max)
* ftdi_usb_get_strings function to get device ID strings (Matthijs ten Berge)
* Fix ftdi_read_pins on PowerPC systems (Thomas Fischl)
* Automatically detach ftdi_sio kernel driver (Uwe Bonnes and Intra2net)
* Configurable flow control (Lorenz Moesenlechner and Matthias Kranz)
New in 0.7 - 2005-10-11
-----------------------
* Baudrate calculation fix for FT2232C (Steven Turner/FTDI)
* Find all devices by vendor/product id (Tim Ansell and Intra2net)
* Documentation updates (Tim Ansell)
New in 0.6 - 2005-04-24
-----------------------
* Set library version on .so file again
* Configurable serial line parameters (Alain Abbas)
* Improved filtering of status bytes (Evgeny Sinelnikov)
* Extended FT2232C support (Uwe Bonnes)
* Small improvement to the baudrate calculation code (Emil)
* Error handling cleanup (Rogier Wolff and Intra2net)
New in 0.5 - 2004-09-24
-----------------------
* New autoconf suite
* pkgconfig support
* Status byte filtering now works for "big" readbuffer sizes (Thanks Evgeny!)
* Open device by description and/or serial (Evgeny Sinelnikov)
* Improved error handling (Evgeny Sinelnikov)
New in 0.4 - 2004-06-15
-----------------------
* Fixed filtering of status bytes (Readbuffer size is now 64 bytes)
* FT2232C support (Steven Turner/FTDI)
* New baudrate calculation code (Ian Abbott)
* Automatic detection of chip type
* Important: ftdi_write_data now returns the bytes written
* Fixed defaults values in ftdi_eeprom_initdefaults (Jean-Daniel Merkli)
* Reset internal readbuffer offsets for reset()/purge_buffers()
* Small typo fixes (Mark Haemmerling)
New in 0.3 - 2004-03-25
-----------------------
* Improved read function which takes arbitrary input buffer sizes
Attention: Call ftdi_deinit() on exit to free used memory
* Vastly increased read/write performance (configurable chunksize, default is 4096)
* Set/get latency timer function working (Thanks Steven Turner/FTDI)
* Increased library version because the changes require recompilation
New in 0.2 - 2004-01-03
-----------------------
* EEPROM build fix by Daniel Kirkham (Melbourne, Australia)
* Implemented basic ftdi_read_data() function
* EEPROM write fixes
New in 0.1 - 2003-06-10
-----------------------
* First public release

View File

@@ -1,25 +0,0 @@
The C library "libftdi1" is distributed under the
GNU Library General Public License version 2.
A copy of the GNU Library General Public License (LGPL) is included
in this distribution, in the file COPYING.LIB.
----------------------------------------------------------------------
The C++ wrapper "ftdipp1" is distributed under the GNU General
Public License version 2 (with a special exception described below).
A copy of the GNU General Public License (GPL) is included
in this distribution, in the file COPYING.GPL.
As a special exception, if other files instantiate templates or use macros
or inline functions from this file, or you compile this file and link it
with other works to produce a work based on this file, this file
does not by itself cause the resulting work to be covered
by the GNU General Public License.
However the source code for this file must still be made available
in accordance with section (3) of the GNU General Public License.
This exception does not invalidate any other reasons why a work based
on this file might be covered by the GNU General Public License.

View File

@@ -1,67 +0,0 @@
--------------------------------------------------------------------
libftdi version 1.5
--------------------------------------------------------------------
libftdi - A library (using libusb) to talk to FTDI's UART/FIFO chips
including the popular bitbang mode.
The following chips are supported:
* FT230X
- FT4232H / FT2232H
- FT232R / FT245R
- FT2232L / FT2232D / FT2232C
- FT232BM / FT245BM (and the BL/BQ variants)
- FT8U232AM / FT8U245AM
libftdi requires libusb 1.x.
The AUTHORS file contains a list of all the people
that made libftdi possible what it is today.
Changes
-------
* Implement tc[io]flush methods & deprecate broken purge_buffers methods
Please check your code for ftdi_usb_purge_rx_buffer(),
ftdi_usb_purge_tx_buffer() and ftdi_usb_purge_buffers()
and migrate to the new ftdi_tc[io]flush() methods.
Old code will continue to function, but you'll get
a deprecation warning during compilation.
* Add program to test buffer flush (purge) functionality
* Add kernel driver auto attach/detach.
See new AUTO_DETACH_REATACH_SIO_MODULE option
* Add ftdi_setflowctrl_xonxoff()
* ftdi_eeprom / eeprom handling:
* Unify handling of all boolean eeprom flags
* Add device release number support
* Add channel_a_driver support for type xxR chips
* Add support for group0 drive levels on x232H chips
* Fix handling of high_current_drive parameter
* Fix inverted handling of VCP driver field for TYPE_R chips
* New --verbose option for eeprom decode operation
* Add example code for async mode
* Add SPDX license identifiers to the core library & ftdi_eeprom
* Various python SWIG wrapper improvements
* Various cmake file improvements
* Fix small bugs in error code paths
You'll find the newest version of libftdi at:
https://www.intra2net.com/en/developer/libftdi
Quick start
-----------
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX="/usr" ../
make
make install
More verbose build instructions are in "README.build"
--------------------------------------------------------------------
www.intra2net.com 2003-2020 Intra2net AG
--------------------------------------------------------------------

View File

@@ -1,96 +0,0 @@
Here is a short tutorial on how to build libftdi git under
Ubuntu 12.10, But it is similar on other Linux distros.
1) Install the build tools
sudo apt-get install build-essential (yum install make automake gcc gcc-c++ kernel-devel)
sudo apt-get install git-core (yum install git)
sudo apt-get install cmake (yum install cmake)
sudo apt-get install doxygen (for building documentations) (yum install doxygen)
2) Install dependencies
sudo apt-get install libusb-1.0-devel (yum install libusb-devel)
(if the system comes with older version like 1.0.8 or
earlier, it is recommended you build libusbx-1.0.14 or later).
sudo apt-get install libconfuse-dev (for ftdi-eeprom) (yum install libconfuse-devel)
sudo apt-get install swig python-dev (for python bindings) (yum install swig python-devel)
sudo apt-get install libboost-all-dev (for C++ binding and unit test) (yum install boost-devel)
3) Clone the git repository
mkdir libftdi
cd libftdi
git clone git://developer.intra2net.com/libftdi
If you are building the release tar ball, just extract the source
tar ball.
4) Build the git source and install
cd libftdi
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX="/usr" ../
make
sudo make install
5) carry out some tests
cd examples
mcuee@Ubuntu1210VM:~/Desktop/build/libftdi/libftdi/build/examples$
./find_all_pp -v 0x0403 -p 0x6001
Found devices ( VID: 0x403, PID: 0x6001 )
------------------------------------------------
FTDI (0x8730800): ftdi, usb serial converter, ftDEH51S (Open OK)
FTDI (0x8730918): FTDI, FT232R USB UART, A8007Ub5 (Open OK)
mcuee@Ubuntu1210VM:~/Desktop/build/libftdi/libftdi/build/examples$ ./eeprom
2 FTDI devices found: Only Readout on EEPROM done. Use
VID/PID/desc/serial to select device
Decoded values of device 1:
Chip type 1 ftdi_eeprom_size: 128
0x000: 00 00 03 04 01 60 00 04 a0 16 08 00 10 01 94 0a .....`.. ........
0x010: 9e 2a c8 12 0a 03 66 00 74 00 64 00 69 00 2a 03 .*....f. t.d.i.*.
0x020: 75 00 73 00 62 00 20 00 73 00 65 00 72 00 69 00 u.s.b. . s.e.r.i.
0x030: 61 00 6c 00 20 00 63 00 6f 00 6e 00 76 00 65 00 a.l. .c. o.n.v.e.
0x040: 72 00 74 00 65 00 72 00 12 03 66 00 74 00 44 00 r.t.e.r. ..f.t.D.
0x050: 45 00 48 00 35 00 31 00 53 00 02 03 00 00 00 00 E.H.5.1. S.......
0x060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ........ ........
0x070: 00 00 00 00 00 00 00 00 00 00 00 00 01 00 16 02 ........ ........
VID: 0x0403
PID: 0x6001
Release: 0x0400
Bus Powered: 44 mA USB Remote Wake Up
Manufacturer: ftdi
Product: usb serial converter
Serial: ftDEH51S
Checksum : 0216
Enable Remote Wake Up
PNP: 1
Decoded values of device 2:
Chip type 3 ftdi_eeprom_size: 128
0x000: 00 40 03 04 01 60 00 00 a0 2d 08 00 00 00 98 0a .@...`.. .-......
0x010: a2 20 c2 12 23 10 05 00 0a 03 46 00 54 00 44 00 . ..#... ..F.T.D.
0x020: 49 00 20 03 46 00 54 00 32 00 33 00 32 00 52 00 I. .F.T. 2.3.2.R.
0x030: 20 00 55 00 53 00 42 00 20 00 55 00 41 00 52 00 .U.S.B. .U.A.R.
0x040: 54 00 12 03 41 00 38 00 30 00 30 00 37 00 55 00 T...A.8. 0.0.7.U.
0x050: 62 00 35 00 c9 bf 1c 80 00 00 00 00 00 00 00 00 b.5..... ........
0x060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ........ ........
0x070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0f 23 ........ .......#
0x080: 2c 04 d3 fb 00 00 c9 bf 1c 80 42 00 00 00 00 00 ,....... ..B.....
0x090: 00 00 00 00 00 00 00 00 38 41 32 52 4a 33 47 4f ........ 8A2RJ3GO
VID: 0x0403
PID: 0x6001
Release: 0x0000
Bus Powered: 90 mA USB Remote Wake Up
Manufacturer: FTDI
Product: FT232R USB UART
Serial: A8007Ub5
Checksum : 230f
Internal EEPROM
Enable Remote Wake Up
PNP: 1
Channel A has Mode UART VCP
C0 Function: TXLED
C1 Function: RXLED
C2 Function: TXDEN
C3 Function: PWREN
C4 Function: SLEEP

View File

@@ -1,638 +0,0 @@
/***************************************************************************
ftdi.h - description
-------------------
begin : Fri Apr 4 2003
copyright : (C) 2003-2020 by Intra2net AG and the libftdi developers
email : opensource@intra2net.com
SPDX-License-Identifier: LGPL-2.1-only
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License *
* version 2.1 as published by the Free Software Foundation; *
* *
***************************************************************************/
#ifndef __libftdi_h__
#define __libftdi_h__
#include <stdint.h>
#ifndef _WIN32
#include <sys/time.h>
#endif
/* Define _FTDI_DISABLE_DEPRECATED to disable deprecated messages. */
#ifdef _FTDI_DISABLE_DEPRECATED
#define _Ftdi_Pragma(_msg)
#else
#define _Ftdi_Pragma(_msg) _Pragma(_msg)
#endif
/* 'interface' might be defined as a macro on Windows, so we need to
* undefine it so as not to break the current libftdi API, because
* struct ftdi_context has an 'interface' member
* As this can be problematic if you include windows.h after ftdi.h
* in your sources, we force windows.h to be included first. */
#if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE)
#include <windows.h>
#if defined(interface)
#undef interface
#endif
#endif
/** FTDI chip type */
enum ftdi_chip_type
{
TYPE_AM=0,
TYPE_BM=1,
TYPE_2232C=2,
TYPE_R=3,
TYPE_2232H=4,
TYPE_4232H=5,
TYPE_232H=6,
TYPE_230X=7,
};
/** Parity mode for ftdi_set_line_property() */
enum ftdi_parity_type { NONE=0, ODD=1, EVEN=2, MARK=3, SPACE=4 };
/** Number of stop bits for ftdi_set_line_property() */
enum ftdi_stopbits_type { STOP_BIT_1=0, STOP_BIT_15=1, STOP_BIT_2=2 };
/** Number of bits for ftdi_set_line_property() */
enum ftdi_bits_type { BITS_7=7, BITS_8=8 };
/** Break type for ftdi_set_line_property2() */
enum ftdi_break_type { BREAK_OFF=0, BREAK_ON=1 };
/** MPSSE bitbang modes */
enum ftdi_mpsse_mode
{
BITMODE_RESET = 0x00, /**< switch off bitbang mode, back to regular serial/FIFO */
BITMODE_BITBANG= 0x01, /**< classical asynchronous bitbang mode, introduced with B-type chips */
BITMODE_MPSSE = 0x02, /**< MPSSE mode, available on 2232x chips */
BITMODE_SYNCBB = 0x04, /**< synchronous bitbang mode, available on 2232x and R-type chips */
BITMODE_MCU = 0x08, /**< MCU Host Bus Emulation mode, available on 2232x chips */
/* CPU-style fifo mode gets set via EEPROM */
BITMODE_OPTO = 0x10, /**< Fast Opto-Isolated Serial Interface Mode, available on 2232x chips */
BITMODE_CBUS = 0x20, /**< Bitbang on CBUS pins of R-type chips, configure in EEPROM before */
BITMODE_SYNCFF = 0x40, /**< Single Channel Synchronous FIFO mode, available on 2232H chips */
BITMODE_FT1284 = 0x80, /**< FT1284 mode, available on 232H chips */
};
/** Port interface for chips with multiple interfaces */
enum ftdi_interface
{
INTERFACE_ANY = 0,
INTERFACE_A = 1,
INTERFACE_B = 2,
INTERFACE_C = 3,
INTERFACE_D = 4
};
/** Automatic loading / unloading of kernel modules */
enum ftdi_module_detach_mode
{
AUTO_DETACH_SIO_MODULE = 0,
DONT_DETACH_SIO_MODULE = 1,
AUTO_DETACH_REATACH_SIO_MODULE = 2
};
/* Shifting commands IN MPSSE Mode*/
#define MPSSE_WRITE_NEG 0x01 /* Write TDI/DO on negative TCK/SK edge*/
#define MPSSE_BITMODE 0x02 /* Write bits, not bytes */
#define MPSSE_READ_NEG 0x04 /* Sample TDO/DI on negative TCK/SK edge */
#define MPSSE_LSB 0x08 /* LSB first */
#define MPSSE_DO_WRITE 0x10 /* Write TDI/DO */
#define MPSSE_DO_READ 0x20 /* Read TDO/DI */
#define MPSSE_WRITE_TMS 0x40 /* Write TMS/CS */
/* FTDI MPSSE commands */
#define SET_BITS_LOW 0x80
/*BYTE DATA*/
/*BYTE Direction*/
#define SET_BITS_HIGH 0x82
/*BYTE DATA*/
/*BYTE Direction*/
#define GET_BITS_LOW 0x81
#define GET_BITS_HIGH 0x83
#define LOOPBACK_START 0x84
#define LOOPBACK_END 0x85
#define TCK_DIVISOR 0x86
/* H Type specific commands */
#define DIS_DIV_5 0x8a
#define EN_DIV_5 0x8b
#define EN_3_PHASE 0x8c
#define DIS_3_PHASE 0x8d
#define CLK_BITS 0x8e
#define CLK_BYTES 0x8f
#define CLK_WAIT_HIGH 0x94
#define CLK_WAIT_LOW 0x95
#define EN_ADAPTIVE 0x96
#define DIS_ADAPTIVE 0x97
#define CLK_BYTES_OR_HIGH 0x9c
#define CLK_BYTES_OR_LOW 0x9d
/*FT232H specific commands */
#define DRIVE_OPEN_COLLECTOR 0x9e
/* Value Low */
/* Value HIGH */ /*rate is 12000000/((1+value)*2) */
#define DIV_VALUE(rate) (rate > 6000000)?0:((6000000/rate -1) > 0xffff)? 0xffff: (6000000/rate -1)
/* Commands in MPSSE and Host Emulation Mode */
#define SEND_IMMEDIATE 0x87
#define WAIT_ON_HIGH 0x88
#define WAIT_ON_LOW 0x89
/* Commands in Host Emulation Mode */
#define READ_SHORT 0x90
/* Address_Low */
#define READ_EXTENDED 0x91
/* Address High */
/* Address Low */
#define WRITE_SHORT 0x92
/* Address_Low */
#define WRITE_EXTENDED 0x93
/* Address High */
/* Address Low */
/* Definitions for flow control */
#define SIO_RESET 0 /* Reset the port */
#define SIO_MODEM_CTRL 1 /* Set the modem control register */
#define SIO_SET_FLOW_CTRL 2 /* Set flow control register */
#define SIO_SET_BAUD_RATE 3 /* Set baud rate */
#define SIO_SET_DATA 4 /* Set the data characteristics of the port */
#define FTDI_DEVICE_OUT_REQTYPE (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_OUT)
#define FTDI_DEVICE_IN_REQTYPE (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE | LIBUSB_ENDPOINT_IN)
/* Requests */
#define SIO_RESET_REQUEST SIO_RESET
#define SIO_SET_BAUDRATE_REQUEST SIO_SET_BAUD_RATE
#define SIO_SET_DATA_REQUEST SIO_SET_DATA
#define SIO_SET_FLOW_CTRL_REQUEST SIO_SET_FLOW_CTRL
#define SIO_SET_MODEM_CTRL_REQUEST SIO_MODEM_CTRL
#define SIO_POLL_MODEM_STATUS_REQUEST 0x05
#define SIO_SET_EVENT_CHAR_REQUEST 0x06
#define SIO_SET_ERROR_CHAR_REQUEST 0x07
#define SIO_SET_LATENCY_TIMER_REQUEST 0x09
#define SIO_GET_LATENCY_TIMER_REQUEST 0x0A
#define SIO_SET_BITMODE_REQUEST 0x0B
#define SIO_READ_PINS_REQUEST 0x0C
#define SIO_READ_EEPROM_REQUEST 0x90
#define SIO_WRITE_EEPROM_REQUEST 0x91
#define SIO_ERASE_EEPROM_REQUEST 0x92
#define SIO_RESET_SIO 0
/* ** WARNING ** SIO_RESET_PURGE_RX or SIO_RESET_PURGE_TX are values used
* internally by libftdi to purge the RX and/or TX FIFOs (buffers).
* APPLICATION PROGRAMS SHOULD NOT BE USING THESE VALUES. Application
* programs should use one of the ftdi_tciflush, ftdi_tcoflush, or
* ftdi_tcioflush functions which emulate the Linux serial port tcflush(3)
* function.
*
* History:
*
* The definitions for these values are with respect to the FTDI chip, not the
* CPU. That is, when the FTDI chip receives a USB control transfer request
* with the command SIO_RESET_PURGE_RX, the FTDI chip empties the FIFO
* containing data received from the CPU awaiting transfer out the serial
* port to the connected serial device (e.g., a modem). Likewise, upon
* reception of the SIO_RESET_PURGE_TX command, the FTDI chip empties the
* FIFO of data received from the attached serial device destined to be
* transmitted to the CPU.
*
* Unfortunately the coding of the previous releases of libfti assumed these
* commands had the opposite effect. This resulted in the function
* ftdi_usb_purge_tx_buffer clearing data received from the attached serial
* device. Similarly, the function ftdi_usb_purge_rx_buffer cleared the
* FTDI FIFO containing data to be transmitted to the attached serial
* device. More seriously, this latter function clear the libftid's
* internal buffer of data received from the serial device, destined
* to the application program.
*/
#ifdef __GNUC__
#define SIO_RESET_PURGE_RX _Ftdi_Pragma("GCC warning \"SIO_RESET_PURGE_RX\" deprecated: - use tciflush() method") 1
#define SIO_RESET_PURGE_TX _Ftdi_Pragma("GCC warning \"SIO_RESET_PURGE_RX\" deprecated: - use tcoflush() method") 2
#else
#define SIO_RESET_PURGE_RX 1
#define SIO_RESET_PURGE_TX 2
#endif
/* New names for the values used internally to flush (purge). */
#define SIO_TCIFLUSH 2
#define SIO_TCOFLUSH 1
#define SIO_DISABLE_FLOW_CTRL 0x0
#define SIO_RTS_CTS_HS (0x1 << 8)
#define SIO_DTR_DSR_HS (0x2 << 8)
#define SIO_XON_XOFF_HS (0x4 << 8)
#define SIO_SET_DTR_MASK 0x1
#define SIO_SET_DTR_HIGH ( 1 | ( SIO_SET_DTR_MASK << 8))
#define SIO_SET_DTR_LOW ( 0 | ( SIO_SET_DTR_MASK << 8))
#define SIO_SET_RTS_MASK 0x2
#define SIO_SET_RTS_HIGH ( 2 | ( SIO_SET_RTS_MASK << 8 ))
#define SIO_SET_RTS_LOW ( 0 | ( SIO_SET_RTS_MASK << 8 ))
#define SIO_RTS_CTS_HS (0x1 << 8)
/* marker for unused usb urb structures
(taken from libusb) */
#define FTDI_URB_USERCONTEXT_COOKIE ((void *)0x1)
#ifdef _FTDI_DISABLE_DEPRECATED
#define DEPRECATED(func) func
#else
#ifdef __GNUC__
#define DEPRECATED(func) __attribute__ ((deprecated)) func
#elif defined(_MSC_VER)
#define DEPRECATED(func) __declspec(deprecated) func
#else
#pragma message("WARNING: You need to implement DEPRECATED for this compiler")
#define DEPRECATED(func) func
#endif
#endif
struct ftdi_transfer_control
{
int completed;
unsigned char *buf;
int size;
int offset;
struct ftdi_context *ftdi;
struct libusb_transfer *transfer;
};
/**
\brief Main context structure for all libftdi functions.
Do not access directly if possible.
*/
struct ftdi_context
{
/* USB specific */
/** libusb's context */
struct libusb_context *usb_ctx;
/** libusb's usb_dev_handle */
struct libusb_device_handle *usb_dev;
/** usb read timeout */
int usb_read_timeout;
/** usb write timeout */
int usb_write_timeout;
/* FTDI specific */
/** FTDI chip type */
enum ftdi_chip_type type;
/** baudrate */
int baudrate;
/** bitbang mode state */
unsigned char bitbang_enabled;
/** pointer to read buffer for ftdi_read_data */
unsigned char *readbuffer;
/** read buffer offset */
unsigned int readbuffer_offset;
/** number of remaining data in internal read buffer */
unsigned int readbuffer_remaining;
/** read buffer chunk size */
unsigned int readbuffer_chunksize;
/** write buffer chunk size */
unsigned int writebuffer_chunksize;
/** maximum packet size. Needed for filtering modem status bytes every n packets. */
unsigned int max_packet_size;
/* FTDI FT2232C requirecments */
/** FT2232C interface number: 0 or 1 */
int interface; /* 0 or 1 */
/** FT2232C index number: 1 or 2 */
int index; /* 1 or 2 */
/* Endpoints */
/** FT2232C end points: 1 or 2 */
int in_ep;
int out_ep; /* 1 or 2 */
/** Bitbang mode. 1: (default) Normal bitbang mode, 2: FT2232C SPI bitbang mode */
unsigned char bitbang_mode;
/** Decoded eeprom structure */
struct ftdi_eeprom *eeprom;
/** String representation of last error */
const char *error_str;
/** Defines behavior in case a kernel module is already attached to the device */
enum ftdi_module_detach_mode module_detach_mode;
};
/**
List all handled EEPROM values.
Append future new values only at the end to provide API/ABI stability*/
enum ftdi_eeprom_value
{
VENDOR_ID = 0,
PRODUCT_ID = 1,
SELF_POWERED = 2,
REMOTE_WAKEUP = 3,
IS_NOT_PNP = 4,
SUSPEND_DBUS7 = 5,
IN_IS_ISOCHRONOUS = 6,
OUT_IS_ISOCHRONOUS = 7,
SUSPEND_PULL_DOWNS = 8,
USE_SERIAL = 9,
USB_VERSION = 10,
USE_USB_VERSION = 11,
MAX_POWER = 12,
CHANNEL_A_TYPE = 13,
CHANNEL_B_TYPE = 14,
CHANNEL_A_DRIVER = 15,
CHANNEL_B_DRIVER = 16,
CBUS_FUNCTION_0 = 17,
CBUS_FUNCTION_1 = 18,
CBUS_FUNCTION_2 = 19,
CBUS_FUNCTION_3 = 20,
CBUS_FUNCTION_4 = 21,
CBUS_FUNCTION_5 = 22,
CBUS_FUNCTION_6 = 23,
CBUS_FUNCTION_7 = 24,
CBUS_FUNCTION_8 = 25,
CBUS_FUNCTION_9 = 26,
HIGH_CURRENT = 27,
HIGH_CURRENT_A = 28,
HIGH_CURRENT_B = 29,
INVERT = 30,
GROUP0_DRIVE = 31,
GROUP0_SCHMITT = 32,
GROUP0_SLEW = 33,
GROUP1_DRIVE = 34,
GROUP1_SCHMITT = 35,
GROUP1_SLEW = 36,
GROUP2_DRIVE = 37,
GROUP2_SCHMITT = 38,
GROUP2_SLEW = 39,
GROUP3_DRIVE = 40,
GROUP3_SCHMITT = 41,
GROUP3_SLEW = 42,
CHIP_SIZE = 43,
CHIP_TYPE = 44,
POWER_SAVE = 45,
CLOCK_POLARITY = 46,
DATA_ORDER = 47,
FLOW_CONTROL = 48,
CHANNEL_C_DRIVER = 49,
CHANNEL_D_DRIVER = 50,
CHANNEL_A_RS485 = 51,
CHANNEL_B_RS485 = 52,
CHANNEL_C_RS485 = 53,
CHANNEL_D_RS485 = 54,
RELEASE_NUMBER = 55,
EXTERNAL_OSCILLATOR= 56,
USER_DATA_ADDR = 57,
};
/**
\brief list of usb devices created by ftdi_usb_find_all()
*/
struct ftdi_device_list
{
/** pointer to next entry */
struct ftdi_device_list *next;
/** pointer to libusb's usb_device */
struct libusb_device *dev;
};
#define FT1284_CLK_IDLE_STATE 0x01
#define FT1284_DATA_LSB 0x02 /* DS_FT232H 1.3 amd ftd2xx.h 1.0.4 disagree here*/
#define FT1284_FLOW_CONTROL 0x04
#define POWER_SAVE_DISABLE_H 0x80
#define USE_SERIAL_NUM 0x08
enum ftdi_cbus_func
{
CBUS_TXDEN = 0, CBUS_PWREN = 1, CBUS_RXLED = 2, CBUS_TXLED = 3, CBUS_TXRXLED = 4,
CBUS_SLEEP = 5, CBUS_CLK48 = 6, CBUS_CLK24 = 7, CBUS_CLK12 = 8, CBUS_CLK6 = 9,
CBUS_IOMODE = 0xa, CBUS_BB_WR = 0xb, CBUS_BB_RD = 0xc
};
enum ftdi_cbush_func
{
CBUSH_TRISTATE = 0, CBUSH_TXLED = 1, CBUSH_RXLED = 2, CBUSH_TXRXLED = 3, CBUSH_PWREN = 4,
CBUSH_SLEEP = 5, CBUSH_DRIVE_0 = 6, CBUSH_DRIVE1 = 7, CBUSH_IOMODE = 8, CBUSH_TXDEN = 9,
CBUSH_CLK30 = 10, CBUSH_CLK15 = 11, CBUSH_CLK7_5 = 12
};
enum ftdi_cbusx_func
{
CBUSX_TRISTATE = 0, CBUSX_TXLED = 1, CBUSX_RXLED = 2, CBUSX_TXRXLED = 3, CBUSX_PWREN = 4,
CBUSX_SLEEP = 5, CBUSX_DRIVE_0 = 6, CBUSX_DRIVE1 = 7, CBUSX_IOMODE = 8, CBUSX_TXDEN = 9,
CBUSX_CLK24 = 10, CBUSX_CLK12 = 11, CBUSX_CLK6 = 12, CBUSX_BAT_DETECT = 13,
CBUSX_BAT_DETECT_NEG = 14, CBUSX_I2C_TXE = 15, CBUSX_I2C_RXF = 16, CBUSX_VBUS_SENSE = 17,
CBUSX_BB_WR = 18, CBUSX_BB_RD = 19, CBUSX_TIME_STAMP = 20, CBUSX_AWAKE = 21
};
/** Invert TXD# */
#define INVERT_TXD 0x01
/** Invert RXD# */
#define INVERT_RXD 0x02
/** Invert RTS# */
#define INVERT_RTS 0x04
/** Invert CTS# */
#define INVERT_CTS 0x08
/** Invert DTR# */
#define INVERT_DTR 0x10
/** Invert DSR# */
#define INVERT_DSR 0x20
/** Invert DCD# */
#define INVERT_DCD 0x40
/** Invert RI# */
#define INVERT_RI 0x80
/** Interface Mode. */
#define CHANNEL_IS_UART 0x0
#define CHANNEL_IS_FIFO 0x1
#define CHANNEL_IS_OPTO 0x2
#define CHANNEL_IS_CPU 0x4
#define CHANNEL_IS_FT1284 0x8
#define CHANNEL_IS_RS485 0x10
#define DRIVE_4MA 0
#define DRIVE_8MA 1
#define DRIVE_12MA 2
#define DRIVE_16MA 3
#define SLOW_SLEW 4
#define IS_SCHMITT 8
/** Driver Type. */
#define DRIVER_VCP 0x08
#define DRIVER_VCPH 0x10 /* FT232H has moved the VCP bit */
#define USE_USB_VERSION_BIT 0x10
#define SUSPEND_DBUS7_BIT 0x80
/** High current drive. */
#define HIGH_CURRENT_DRIVE 0x10
#define HIGH_CURRENT_DRIVE_R 0x04
/**
\brief Progress Info for streaming read
*/
struct size_and_time
{
uint64_t totalBytes;
struct timeval time;
};
typedef struct
{
struct size_and_time first;
struct size_and_time prev;
struct size_and_time current;
double totalTime;
double totalRate;
double currentRate;
} FTDIProgressInfo;
typedef int (FTDIStreamCallback)(uint8_t *buffer, int length,
FTDIProgressInfo *progress, void *userdata);
/**
* Provide libftdi version information
* major: Library major version
* minor: Library minor version
* micro: Currently unused, ight get used for hotfixes.
* version_str: Version as (static) string
* snapshot_str: Git snapshot version if known. Otherwise "unknown" or empty string.
*/
struct ftdi_version_info
{
int major;
int minor;
int micro;
const char *version_str;
const char *snapshot_str;
};
#ifdef __cplusplus
extern "C"
{
#endif
int ftdi_init(struct ftdi_context *ftdi);
struct ftdi_context *ftdi_new(void);
int ftdi_set_interface(struct ftdi_context *ftdi, enum ftdi_interface interface);
void ftdi_deinit(struct ftdi_context *ftdi);
void ftdi_free(struct ftdi_context *ftdi);
void ftdi_set_usbdev (struct ftdi_context *ftdi, struct libusb_device_handle *usbdev);
struct ftdi_version_info ftdi_get_library_version(void);
int ftdi_usb_find_all(struct ftdi_context *ftdi, struct ftdi_device_list **devlist,
int vendor, int product);
void ftdi_list_free(struct ftdi_device_list **devlist);
void ftdi_list_free2(struct ftdi_device_list *devlist);
int ftdi_usb_get_strings(struct ftdi_context *ftdi, struct libusb_device *dev,
char *manufacturer, int mnf_len,
char *description, int desc_len,
char *serial, int serial_len);
int ftdi_usb_get_strings2(struct ftdi_context *ftdi, struct libusb_device *dev,
char *manufacturer, int mnf_len,
char *description, int desc_len,
char *serial, int serial_len);
int ftdi_eeprom_get_strings(struct ftdi_context *ftdi,
char *manufacturer, int mnf_len,
char *product, int prod_len,
char *serial, int serial_len);
int ftdi_eeprom_set_strings(struct ftdi_context *ftdi, const char * manufacturer,
const char * product, const char * serial);
int ftdi_usb_open(struct ftdi_context *ftdi, int vendor, int product);
int ftdi_usb_open_desc(struct ftdi_context *ftdi, int vendor, int product,
const char* description, const char* serial);
int ftdi_usb_open_desc_index(struct ftdi_context *ftdi, int vendor, int product,
const char* description, const char* serial, unsigned int index);
int ftdi_usb_open_bus_addr(struct ftdi_context *ftdi, uint8_t bus, uint8_t addr);
int ftdi_usb_open_dev(struct ftdi_context *ftdi, struct libusb_device *dev);
int ftdi_usb_open_string(struct ftdi_context *ftdi, const char* description);
int ftdi_usb_close(struct ftdi_context *ftdi);
int ftdi_usb_reset(struct ftdi_context *ftdi);
int ftdi_tciflush(struct ftdi_context *ftdi);
int ftdi_tcoflush(struct ftdi_context *ftdi);
int ftdi_tcioflush(struct ftdi_context *ftdi);
int ftdi_usb_purge_rx_buffer(struct ftdi_context *ftdi);
int ftdi_usb_purge_tx_buffer(struct ftdi_context *ftdi);
int ftdi_usb_purge_buffers(struct ftdi_context *ftdi);
int ftdi_set_baudrate(struct ftdi_context *ftdi, int baudrate);
int ftdi_set_line_property(struct ftdi_context *ftdi, enum ftdi_bits_type bits,
enum ftdi_stopbits_type sbit, enum ftdi_parity_type parity);
int ftdi_set_line_property2(struct ftdi_context *ftdi, enum ftdi_bits_type bits,
enum ftdi_stopbits_type sbit, enum ftdi_parity_type parity,
enum ftdi_break_type break_type);
int ftdi_read_data(struct ftdi_context *ftdi, unsigned char *buf, int size);
int ftdi_read_data_set_chunksize(struct ftdi_context *ftdi, unsigned int chunksize);
int ftdi_read_data_get_chunksize(struct ftdi_context *ftdi, unsigned int *chunksize);
int ftdi_write_data(struct ftdi_context *ftdi, const unsigned char *buf, int size);
int ftdi_write_data_set_chunksize(struct ftdi_context *ftdi, unsigned int chunksize);
int ftdi_write_data_get_chunksize(struct ftdi_context *ftdi, unsigned int *chunksize);
int ftdi_readstream(struct ftdi_context *ftdi, FTDIStreamCallback *callback,
void *userdata, int packetsPerTransfer, int numTransfers);
struct ftdi_transfer_control *ftdi_write_data_submit(struct ftdi_context *ftdi, unsigned char *buf, int size);
struct ftdi_transfer_control *ftdi_read_data_submit(struct ftdi_context *ftdi, unsigned char *buf, int size);
int ftdi_transfer_data_done(struct ftdi_transfer_control *tc);
void ftdi_transfer_data_cancel(struct ftdi_transfer_control *tc, struct timeval * to);
int ftdi_set_bitmode(struct ftdi_context *ftdi, unsigned char bitmask, unsigned char mode);
int ftdi_disable_bitbang(struct ftdi_context *ftdi);
int ftdi_read_pins(struct ftdi_context *ftdi, unsigned char *pins);
int ftdi_set_latency_timer(struct ftdi_context *ftdi, unsigned char latency);
int ftdi_get_latency_timer(struct ftdi_context *ftdi, unsigned char *latency);
int ftdi_poll_modem_status(struct ftdi_context *ftdi, unsigned short *status);
/* flow control */
int ftdi_setflowctrl(struct ftdi_context *ftdi, int flowctrl);
int ftdi_setflowctrl_xonxoff(struct ftdi_context *ftdi, unsigned char xon, unsigned char xoff);
int ftdi_setdtr_rts(struct ftdi_context *ftdi, int dtr, int rts);
int ftdi_setdtr(struct ftdi_context *ftdi, int state);
int ftdi_setrts(struct ftdi_context *ftdi, int state);
int ftdi_set_event_char(struct ftdi_context *ftdi, unsigned char eventch, unsigned char enable);
int ftdi_set_error_char(struct ftdi_context *ftdi, unsigned char errorch, unsigned char enable);
/* init eeprom for the given FTDI type */
int ftdi_eeprom_initdefaults(struct ftdi_context *ftdi,
char * manufacturer, char *product,
char * serial);
int ftdi_eeprom_build(struct ftdi_context *ftdi);
int ftdi_eeprom_decode(struct ftdi_context *ftdi, int verbose);
int ftdi_get_eeprom_value(struct ftdi_context *ftdi, enum ftdi_eeprom_value value_name, int* value);
int ftdi_set_eeprom_value(struct ftdi_context *ftdi, enum ftdi_eeprom_value value_name, int value);
int ftdi_get_eeprom_buf(struct ftdi_context *ftdi, unsigned char * buf, int size);
int ftdi_set_eeprom_buf(struct ftdi_context *ftdi, const unsigned char * buf, int size);
int ftdi_set_eeprom_user_data(struct ftdi_context *ftdi, const char * buf, int size);
int ftdi_read_eeprom(struct ftdi_context *ftdi);
int ftdi_read_chipid(struct ftdi_context *ftdi, unsigned int *chipid);
int ftdi_write_eeprom(struct ftdi_context *ftdi);
int ftdi_erase_eeprom(struct ftdi_context *ftdi);
int ftdi_read_eeprom_location (struct ftdi_context *ftdi, int eeprom_addr, unsigned short *eeprom_val);
int ftdi_write_eeprom_location(struct ftdi_context *ftdi, int eeprom_addr, unsigned short eeprom_val);
const char *ftdi_get_error_string(struct ftdi_context *ftdi);
#ifdef __cplusplus
}
#endif
#endif /* __libftdi_h__ */

View File

@@ -1,153 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\ftdi.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\ftdi.h" />
<ClInclude Include="src\libwinftdi.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{632649ab-a351-46d4-a81f-1d6e9a819a5c}</ProjectGuid>
<RootNamespace>libftdi1</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalIncludeDirectories>include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<AdditionalIncludeDirectories>include</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@@ -1,10 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="src\ftdi.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\ftdi.h" />
<ClInclude Include="src\libwinftdi.h" />
</ItemGroup>
</Project>

View File

@@ -1,364 +0,0 @@
/*
* avrdude - A Downloader/Uploader for AVR device programmers
* Copyright (C) 2019 Marius Greuel
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "libwinftdi.h"
#include <winsock2.h>
#include <ftdi.h>
using namespace LibWinFtdi;
static ftdi_chip_type MapChipType(ULONG type)
{
switch (type)
{
case FT_DEVICE_BM:
return TYPE_BM;
case FT_DEVICE_AM:
return TYPE_AM;
case FT_DEVICE_100AX:
return TYPE_AM;
case FT_DEVICE_2232C:
return TYPE_2232C;
case FT_DEVICE_232R:
return TYPE_R;
case FT_DEVICE_2232H:
return TYPE_2232H;
case FT_DEVICE_4232H:
return TYPE_4232H;
case FT_DEVICE_232H:
return TYPE_232H;
default:
return TYPE_AM;
}
}
static int SetError(struct ftdi_context* ftdi, int result, const char* error_str)
{
if (ftdi != nullptr)
{
ftdi->error_str = error_str;
}
return result;
}
const char* ftdi_get_error_string(struct ftdi_context* ftdi)
{
return ftdi != nullptr && ftdi->error_str != nullptr ? ftdi->error_str : "unknown error";
}
struct ftdi_context* ftdi_new(void)
{
struct ftdi_context* ftdi = new struct ftdi_context();
if (ftdi_init(ftdi) != 0)
{
delete ftdi;
return nullptr;
}
return ftdi;
}
void ftdi_free(struct ftdi_context* ftdi)
{
ftdi_deinit(ftdi);
delete ftdi;
}
int ftdi_set_interface(struct ftdi_context* ftdi, enum ftdi_interface interface)
{
if (ftdi == nullptr)
{
return SetError(ftdi, -2, "USB device unavailable");
}
if (ftdi->usb_dev != nullptr)
{
if (ftdi->index != (interface != INTERFACE_ANY ? interface : INTERFACE_A))
{
return SetError(ftdi, -3, "Interface can not be changed on an already open device");
}
}
switch (interface)
{
case INTERFACE_ANY:
case INTERFACE_A:
ftdi->interface = 0;
ftdi->index = INTERFACE_A;
break;
case INTERFACE_B:
ftdi->interface = 1;
ftdi->index = INTERFACE_B;
break;
case INTERFACE_C:
ftdi->interface = 2;
ftdi->index = INTERFACE_C;
break;
case INTERFACE_D:
ftdi->interface = 3;
ftdi->index = INTERFACE_D;
break;
default:
return SetError(ftdi, -1, "Unknown interface");
}
return 0;
}
int ftdi_init(struct ftdi_context* ftdi)
{
std::memset(ftdi, 0, sizeof(struct ftdi_context));
return 0;
}
void ftdi_deinit(struct ftdi_context* ftdi)
{
if (ftdi != nullptr && ftdi->usb_dev != nullptr)
{
std::unique_ptr<FtdiDevice> device(reinterpret_cast<FtdiDevice*>(ftdi->usb_dev));
ftdi->usb_dev = nullptr;
}
}
int ftdi_usb_open_desc_index(struct ftdi_context* ftdi, int vendor, int product,
const char* description, const char* serial, unsigned int index)
{
if (ftdi == nullptr)
{
return SetError(ftdi, -3, "invalid ftdi context");
}
FtdiEnumerator enumerator;
auto status = enumerator.EnumerateDevices();
if (status != FT_OK)
{
return SetError(ftdi, -3, "failed to enumerate devices");
}
for (auto const& info : enumerator.GetDevices())
{
if ((info.Flags & FT_FLAGS_OPENED) != 0)
continue;
if (vendor != static_cast<uint16_t>(info.ID >> 16))
continue;
if (product != static_cast<uint16_t>(info.ID >> 0))
continue;
if (description != nullptr && strcmp(description, info.Description) != 0)
continue;
if (serial != nullptr && strcmp(serial, info.SerialNumber) != 0)
continue;
if (index > 0)
{
index--;
continue;
}
auto device = std::make_unique<FtdiDevice>();
FT_STATUS status = device->OpenBySerialNumber(info.SerialNumber);
if (status == FT_OK)
{
device->ResetDevice();
device->Purge();
device->SetBitMode(0, 0);
device->SetTimeouts(5000, 5000);
status = device->SetEventNotification(FT_EVENT_RXCHAR);
}
if (status != FT_OK)
{
return SetError(ftdi, -3, "failed to open device");
}
ftdi->type = MapChipType(info.Type);
ftdi->usb_dev = reinterpret_cast<struct libusb_device_handle*>(device.release());
return 0;
}
return SetError(ftdi, -3, "device not found");
}
int ftdi_usb_close(struct ftdi_context* ftdi)
{
if (ftdi == nullptr || ftdi->usb_dev == nullptr)
{
return SetError(ftdi, -3, "invalid device");
}
auto device = reinterpret_cast<FtdiDevice*>(ftdi->usb_dev);
auto status = device->Close();
if (status != FT_OK)
{
return SetError(ftdi, -1, "Failed to close device");
}
return 0;
}
int ftdi_usb_purge_buffers(struct ftdi_context* ftdi)
{
if (ftdi == nullptr || ftdi->usb_dev == nullptr)
{
return SetError(ftdi, -3, "invalid device");
}
auto device = reinterpret_cast<FtdiDevice*>(ftdi->usb_dev);
auto status = device->Purge();
if (status != FT_OK)
{
return SetError(ftdi, -1, "Failed to purge buffers");
}
return 0;
}
int ftdi_set_baudrate(struct ftdi_context* ftdi, int baudrate)
{
if (ftdi == nullptr || ftdi->usb_dev == nullptr)
{
return SetError(ftdi, -3, "invalid device");
}
if (ftdi->bitbang_enabled)
{
baudrate /= 16;
}
if (baudrate <= 0)
{
return SetError(ftdi, -1, "invalid baudrate");
}
auto device = reinterpret_cast<FtdiDevice*>(ftdi->usb_dev);
auto status = device->SetBaudRate(baudrate);
if (status != FT_OK)
{
return SetError(ftdi, -2, "Failed to set baudrate");
}
ftdi->baudrate = baudrate;
return 0;
}
int ftdi_set_bitmode(struct ftdi_context* ftdi, unsigned char bitmask, unsigned char mode)
{
if (ftdi == nullptr || ftdi->usb_dev == nullptr)
{
return SetError(ftdi, -2, "invalid device");
}
auto device = reinterpret_cast<FtdiDevice*>(ftdi->usb_dev);
auto status = device->SetBitMode(bitmask, mode);
if (status != FT_OK)
{
return SetError(ftdi, -1, "Failed to set bitmode");
}
ftdi->bitbang_mode = mode;
ftdi->bitbang_enabled = mode == BITMODE_RESET ? 0 : 1;
return 0;
}
int ftdi_set_latency_timer(struct ftdi_context* ftdi, unsigned char latency)
{
if (ftdi == nullptr || ftdi->usb_dev == nullptr)
{
return SetError(ftdi, -3, "invalid device");
}
if (latency < 1)
{
return SetError(ftdi, -1, "invalid latency");
}
auto device = reinterpret_cast<FtdiDevice*>(ftdi->usb_dev);
auto status = device->SetLatencyTimer(latency);
if (status != FT_OK)
{
return SetError(ftdi, -1, "Failed to set latency timer");
}
return 0;
}
int ftdi_read_data(struct ftdi_context* ftdi, unsigned char* buf, int size)
{
if (ftdi == nullptr || ftdi->usb_dev == nullptr)
{
return SetError(ftdi, -666, "invalid device");
}
auto device = reinterpret_cast<FtdiDevice*>(ftdi->usb_dev);
auto handle = device->GetNotificationEvent();
if (handle != nullptr)
{
DWORD dwStatus = WaitForSingleObject(handle, 1000);
if (dwStatus != WAIT_OBJECT_0)
{
return 0;
}
}
DWORD bytesInQueue = 0;
auto status = device->GetQueueStatus(&bytesInQueue);
if (status != FT_OK)
{
return SetError(ftdi, -1, "Failed to get queue status");
}
DWORD bytesRead = 0;
if (bytesInQueue > 0)
{
if (size > static_cast<int>(bytesInQueue))
size = static_cast<int>(bytesInQueue);
status = device->Read(buf, size, &bytesRead);
if (status != FT_OK)
{
return SetError(ftdi, -1, "Failed to read data");
}
}
return bytesRead;
}
int ftdi_write_data(struct ftdi_context* ftdi, const unsigned char* buf, int size)
{
if (ftdi == nullptr || ftdi->usb_dev == nullptr)
{
return SetError(ftdi, -666, "invalid device");
}
auto device = reinterpret_cast<FtdiDevice*>(ftdi->usb_dev);
DWORD bytesWritten = 0;
auto status = device->Write(const_cast<unsigned char*>(buf), size, &bytesWritten);
if (status != FT_OK)
{
return SetError(ftdi, -1, "Failed to write data");
}
return bytesWritten;
}

View File

@@ -1,431 +0,0 @@
//
// libwinftdi.h
// Copyright (C) 2019 Marius Greuel. All rights reserved.
//
#pragma once
#define WIN32_LEAN_AND_MEAN
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cerrno>
#include <memory>
#include <string>
#include <vector>
#include <windows.h>
namespace LibWinFtdi
{
enum
{
FT_OK,
FT_INVALID_HANDLE,
FT_DEVICE_NOT_FOUND,
FT_DEVICE_NOT_OPENED,
FT_IO_ERROR,
FT_INSUFFICIENT_RESOURCES,
FT_INVALID_PARAMETER,
FT_INVALID_BAUD_RATE,
FT_DEVICE_NOT_OPENED_FOR_ERASE,
FT_DEVICE_NOT_OPENED_FOR_WRITE,
FT_FAILED_TO_WRITE_DEVICE,
FT_EEPROM_READ_FAILED,
FT_EEPROM_WRITE_FAILED,
FT_EEPROM_ERASE_FAILED,
FT_EEPROM_NOT_PRESENT,
FT_EEPROM_NOT_PROGRAMMED,
FT_INVALID_ARGS,
FT_NOT_SUPPORTED,
FT_OTHER_ERROR,
FT_DEVICE_LIST_NOT_READY,
};
enum
{
FT_DEVICE_BM,
FT_DEVICE_AM,
FT_DEVICE_100AX,
FT_DEVICE_UNKNOWN,
FT_DEVICE_2232C,
FT_DEVICE_232R,
FT_DEVICE_2232H,
FT_DEVICE_4232H,
FT_DEVICE_232H,
};
enum
{
FT_FLAGS_OPENED = 1,
FT_FLAGS_HISPEED = 2,
};
enum
{
FT_OPEN_BY_SERIAL_NUMBER = 1,
FT_OPEN_BY_DESCRIPTION = 2,
FT_OPEN_BY_LOCATION = 4,
};
enum
{
FT_PURGE_RX = 1,
FT_PURGE_TX = 2,
};
enum
{
FT_EVENT_RXCHAR = 1,
FT_EVENT_MODEM_STATUS = 2,
FT_EVENT_LINE_STATUS = 4,
};
typedef PVOID FT_HANDLE;
typedef ULONG FT_STATUS;
struct DeviceInfo
{
ULONG Flags;
ULONG Type;
ULONG ID;
DWORD LocId;
char SerialNumber[16];
char Description[64];
FT_HANDLE ftHandle;
};
class FtdiApi
{
public:
FtdiApi() = default;
FtdiApi(const FtdiApi&) = delete;
FtdiApi& operator=(const FtdiApi&) = delete;
FtdiApi(FtdiApi&&) = delete;
FtdiApi& operator=(FtdiApi&&) = delete;
~FtdiApi()
{
Unload();
}
HRESULT Load()
{
if (m_module != nullptr)
return S_FALSE;
HMODULE module = LoadLibraryExW(L"ftd2xx.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
if (module == nullptr)
{
return HRESULT_FROM_WIN32(GetLastError());
}
HRESULT hr = S_OK;
if (FAILED(hr = LoadImport(module, "FT_CreateDeviceInfoList", &FT_CreateDeviceInfoList)) ||
FAILED(hr = LoadImport(module, "FT_GetDeviceInfoList", &FT_GetDeviceInfoList)) ||
FAILED(hr = LoadImport(module, "FT_OpenEx", &FT_OpenEx)) ||
FAILED(hr = LoadImport(module, "FT_Close", &FT_Close)) ||
FAILED(hr = LoadImport(module, "FT_ResetDevice", &FT_ResetDevice)) ||
FAILED(hr = LoadImport(module, "FT_ResetPort", &FT_ResetPort)) ||
FAILED(hr = LoadImport(module, "FT_CyclePort", &FT_ResetPort)) ||
FAILED(hr = LoadImport(module, "FT_Purge", &FT_Purge)) ||
FAILED(hr = LoadImport(module, "FT_SetTimeouts", &FT_SetTimeouts)) ||
FAILED(hr = LoadImport(module, "FT_SetBaudRate", &FT_SetBaudRate)) ||
FAILED(hr = LoadImport(module, "FT_SetBitMode", &FT_SetBitMode)) ||
FAILED(hr = LoadImport(module, "FT_SetLatencyTimer", &FT_SetLatencyTimer)) ||
FAILED(hr = LoadImport(module, "FT_GetQueueStatus", &FT_GetQueueStatus)) ||
FAILED(hr = LoadImport(module, "FT_SetEventNotification", &FT_SetEventNotification)) ||
FAILED(hr = LoadImport(module, "FT_SetUSBParameters", &FT_SetUSBParameters)) ||
FAILED(hr = LoadImport(module, "FT_Read", &FT_Read)) ||
FAILED(hr = LoadImport(module, "FT_Write", &FT_Write)))
{
FreeLibrary(module);
return hr;
}
m_module = module;
return S_OK;
}
HRESULT Unload()
{
if (m_module == nullptr)
return S_FALSE;
FreeLibrary(m_module);
m_module = nullptr;
return S_OK;
}
private:
template<typename T>
static HRESULT LoadImport(HMODULE module, LPCSTR lpProcName, T** ptr)
{
auto proc = GetProcAddress(module, lpProcName);
if (proc == nullptr)
{
*ptr = nullptr;
return HRESULT_FROM_WIN32(GetLastError());
}
*ptr = reinterpret_cast<T*>(proc);
return S_OK;
}
private:
HMODULE m_module = nullptr;
protected:
FT_STATUS(WINAPI* FT_CreateDeviceInfoList)(LPDWORD lpdwNumDevs) = nullptr;
FT_STATUS(WINAPI* FT_GetDeviceInfoList)(DeviceInfo* pDest, LPDWORD lpdwNumDevs) = nullptr;
FT_STATUS(WINAPI* FT_OpenEx)(PVOID pArg1, DWORD Flags, FT_HANDLE* pHandle) = nullptr;
FT_STATUS(WINAPI* FT_Close)(FT_HANDLE ftHandle) = nullptr;
FT_STATUS(WINAPI* FT_ResetDevice)(FT_HANDLE ftHandle) = nullptr;
FT_STATUS(WINAPI* FT_ResetPort)(FT_HANDLE ftHandle) = nullptr;
FT_STATUS(WINAPI* FT_CyclePort)(FT_HANDLE ftHandle) = nullptr;
FT_STATUS(WINAPI* FT_Purge)(FT_HANDLE ftHandle, DWORD dwMask) = nullptr;
FT_STATUS(WINAPI* FT_SetTimeouts)(FT_HANDLE ftHandle, DWORD dwReadTimeout, DWORD dwWriteTimeout) = nullptr;
FT_STATUS(WINAPI* FT_SetBaudRate)(FT_HANDLE ftHandle, DWORD dwBaudRate) = nullptr;
FT_STATUS(WINAPI* FT_SetBitMode)(FT_HANDLE ftHandle, UCHAR ucMask, UCHAR ucEnable) = nullptr;
FT_STATUS(WINAPI* FT_SetLatencyTimer)(FT_HANDLE ftHandle, UCHAR ucTimer) = nullptr;
FT_STATUS(WINAPI* FT_GetQueueStatus)(FT_HANDLE ftHandle, DWORD* dwRxBytes) = nullptr;
FT_STATUS(WINAPI* FT_SetEventNotification)(FT_HANDLE ftHandle, DWORD Mask, PVOID Param) = nullptr;
FT_STATUS(WINAPI* FT_SetUSBParameters)(FT_HANDLE ftHandle, DWORD dwInTransferSize, DWORD dwOutTransferSize) = nullptr;
FT_STATUS(WINAPI* FT_Read)(FT_HANDLE ftHandle, LPVOID lpBuffer, DWORD dwBytesToRead, LPDWORD lpBytesReturned) = nullptr;
FT_STATUS(WINAPI* FT_Write)(FT_HANDLE ftHandle, LPVOID lpBuffer, DWORD dwBytesToWrite, LPDWORD lpBytesWritten) = nullptr;
};
class FtdiEnumerator : public FtdiApi
{
public:
FtdiEnumerator() = default;
FtdiEnumerator(const FtdiEnumerator&) = delete;
FtdiEnumerator& operator=(const FtdiEnumerator&) = delete;
FtdiEnumerator(FtdiEnumerator&&) = delete;
FtdiEnumerator& operator=(FtdiEnumerator&&) = delete;
public:
FT_STATUS EnumerateDevices()
{
if (FAILED(Load()))
{
return FT_INVALID_HANDLE;
}
DWORD lpdwNumDevs = 0;
FT_STATUS status = FT_CreateDeviceInfoList(&lpdwNumDevs);
if (status != FT_OK)
return status;
m_devices.resize(lpdwNumDevs);
status = FT_GetDeviceInfoList(m_devices.data(), &lpdwNumDevs);
if (status != FT_OK)
return status;
return FT_OK;
}
const std::vector<DeviceInfo>& GetDevices() const
{
return m_devices;
}
private:
std::vector<DeviceInfo> m_devices;
};
class FtdiDevice : public FtdiApi
{
public:
FtdiDevice() = default;
FtdiDevice(const FtdiDevice&) = delete;
FtdiDevice& operator=(const FtdiDevice&) = delete;
FtdiDevice(FtdiDevice&&) = delete;
FtdiDevice& operator=(FtdiDevice&&) = delete;
~FtdiDevice()
{
if (m_event != nullptr)
{
CloseHandle(m_event);
}
}
HANDLE GetNotificationEvent() const
{
return m_event;
}
public:
FT_STATUS OpenBySerialNumber(const char* serialNumber)
{
if (FAILED(Load()))
{
return FT_INVALID_HANDLE;
}
return FT_OpenEx(const_cast<char*>(serialNumber), FT_OPEN_BY_SERIAL_NUMBER, &m_handle);
}
FT_STATUS OpenByLocation(uint32_t location)
{
if (FAILED(Load()))
{
return FT_INVALID_HANDLE;
}
return FT_OpenEx(&location, FT_OPEN_BY_LOCATION, &m_handle);
}
FT_STATUS Close()
{
if (FAILED(Load()))
{
return FT_INVALID_HANDLE;
}
return FT_Close(m_handle);
}
FT_STATUS ResetDevice()
{
if (FAILED(Load()))
{
return FT_INVALID_HANDLE;
}
return FT_ResetDevice(m_handle);
}
FT_STATUS ResetPort()
{
if (FAILED(Load()))
{
return FT_INVALID_HANDLE;
}
return FT_ResetPort(m_handle);
}
FT_STATUS CyclePort()
{
if (FAILED(Load()))
{
return FT_INVALID_HANDLE;
}
return FT_CyclePort(m_handle);
}
FT_STATUS Purge(DWORD dwMask = FT_PURGE_RX | FT_PURGE_TX)
{
if (FAILED(Load()))
{
return FT_INVALID_HANDLE;
}
return FT_Purge(m_handle, dwMask);
}
FT_STATUS SetTimeouts(DWORD dwReadTimeout, DWORD dwWriteTimeout)
{
if (FAILED(Load()))
{
return FT_INVALID_HANDLE;
}
return FT_SetTimeouts(m_handle, dwReadTimeout, dwWriteTimeout);
}
FT_STATUS SetBaudRate(DWORD dwBaudRate)
{
if (FAILED(Load()))
{
return FT_INVALID_HANDLE;
}
return FT_SetBaudRate(m_handle, dwBaudRate);
}
FT_STATUS SetBitMode(UCHAR ucMask, UCHAR ucEnable)
{
if (FAILED(Load()))
{
return FT_INVALID_HANDLE;
}
return FT_SetBitMode(m_handle, ucMask, ucEnable);
}
FT_STATUS SetLatencyTimer(UCHAR ucTimer)
{
if (FAILED(Load()))
{
return FT_INVALID_HANDLE;
}
return FT_SetLatencyTimer(m_handle, ucTimer);
}
FT_STATUS GetQueueStatus(DWORD* dwRxBytes)
{
if (FAILED(Load()))
{
return FT_INVALID_HANDLE;
}
return FT_GetQueueStatus(m_handle, dwRxBytes);
}
FT_STATUS SetEventNotification(DWORD Mask)
{
if (FAILED(Load()))
{
return FT_INVALID_HANDLE;
}
if (m_event == nullptr)
{
m_event = CreateEventW(nullptr, FALSE, FALSE, nullptr);
}
return FT_SetEventNotification(m_handle, Mask, m_event);
}
FT_STATUS SetUSBParameters(DWORD dwInTransferSize, DWORD dwOutTransferSize)
{
if (FAILED(Load()))
{
return FT_INVALID_HANDLE;
}
return FT_SetUSBParameters(m_handle, dwInTransferSize, dwOutTransferSize);
}
FT_STATUS Read(LPVOID lpBuffer, DWORD dwBytesToRead, LPDWORD lpBytesReturned)
{
if (FAILED(Load()))
{
return FT_INVALID_HANDLE;
}
return FT_Read(m_handle, lpBuffer, dwBytesToRead, lpBytesReturned);
}
FT_STATUS Write(LPVOID lpBuffer, DWORD dwBytesToWrite, LPDWORD lpBytesWritten)
{
if (FAILED(Load()))
{
return FT_INVALID_HANDLE;
}
return FT_Write(m_handle, lpBuffer, dwBytesToWrite, lpBytesWritten);
}
private:
FT_HANDLE m_handle = nullptr;
HANDLE m_event = nullptr;
};
}

View File

@@ -1,18 +0,0 @@
HIDAPI Authors:
Alan Ott <alan@signal11.us>:
Original Author and Maintainer
Linux, Windows, and Mac implementations
Ludovic Rousseau <rousseau@debian.org>:
Formatting for Doxygen documentation
Bug fixes
Correctness fixes
libusb/hidapi Team:
Development/maintainance since June 4th 2019
For a comprehensive list of contributions, see the commit list at github:
https://github.com/libusb/hidapi/commits/master

View File

@@ -1,15 +0,0 @@
This file is mostly for the maintainer.
1. Build hidapi.dll
2. Build hidtest.exe in DEBUG and RELEASE
3. Commit all
4. Run the Following
export VERSION=0.1.0
export TAG_NAME=hidapi-$VERSION
git tag $TAG_NAME
git archive --format zip --prefix $TAG_NAME/ $TAG_NAME >../$TAG_NAME.zip
5. Test the zip file.
6. Run the following:
git push origin $TAG_NAME

Some files were not shown because too many files have changed in this diff Show More