<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://flashprog.org/wiki/index.php?action=history&amp;feed=atom&amp;title=Libflashprog</id>
	<title>Libflashprog - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://flashprog.org/wiki/index.php?action=history&amp;feed=atom&amp;title=Libflashprog"/>
	<link rel="alternate" type="text/html" href="https://flashprog.org/wiki/index.php?title=Libflashprog&amp;action=history"/>
	<updated>2026-04-30T08:14:50Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.3</generator>
	<entry>
		<id>https://flashprog.org/wiki/index.php?title=Libflashprog&amp;diff=207&amp;oldid=prev</id>
		<title>Icon: &quot;nico.h@gmx.de: Rename flashrom -&gt; flashprog&quot;</title>
		<link rel="alternate" type="text/html" href="https://flashprog.org/wiki/index.php?title=Libflashprog&amp;diff=207&amp;oldid=prev"/>
		<updated>2023-12-03T17:46:43Z</updated>

		<summary type="html">&lt;p&gt;&amp;quot;nico.h@gmx.de: Rename flashrom -&amp;gt; flashprog&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{DISPLAYTITLE:libflashprog}}&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;libflashprog&amp;#039;&amp;#039;&amp;#039; is a shared library which can be used to write programs which need to detect/read/write/erase flash ROM chips using various programmers.&lt;br /&gt;
&lt;br /&gt;
It is, among other things, useful so that different frontends can be written (a command-line tool, various GUIs, libpayload integration, others).&lt;br /&gt;
&lt;br /&gt;
== Status ==&lt;br /&gt;
&lt;br /&gt;
Work in progress.&lt;br /&gt;
&lt;br /&gt;
== Building ==&lt;br /&gt;
&lt;br /&gt;
 $ &amp;#039;&amp;#039;&amp;#039;make libflashprog.a&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;margin-top:0.5em; padding:0.5em 0.5em 0.5em 0.5em; background-color:#ff6666; align:right; border:1px solid #000000;&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Please note that some/all of the text below was written before libflashprog patches existed. The text below needs to be revised to reflect the available libflashprog patches and the design below needs review.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== API ==&lt;br /&gt;
&lt;br /&gt;
The following sections describe how a libflashprog API could look like. This is just a first attempt, it&amp;#039;s not yet finished and not yet implemented. Comments welcome.&lt;br /&gt;
&lt;br /&gt;
=== General ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;fl_init()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Initialize libflashprog.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;fl_shutdown()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Shut down libflashprog, close devices or files, free all resources, etc.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;fl_set_loglevel()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Set the loglevel which libflashprog should use to output errors/warnings/info/debug messages. Valid loglevels: TODO.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;fl_set_log_callback()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Set a callback function which will be invoked whenever libflashprog wants to output messages. This allows frontends to do whatever they see fit with such messages, e.g. write them to syslog, or to file, or print them in a GUI window, etc.&lt;br /&gt;
&lt;br /&gt;
=== Querying ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;fl_version()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Return one or more version items of libflashprog, e.g. the lib major/minor/micro version number, the svn revision, or similar.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;fl_sysinfo()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Return some information about the (build- and host-) system, which libflashprog knows about, e.g. gcc version used, libpci version, uname, etc.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;fl_supported_programmers()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Get a list of supported programmers.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;fl_supported_chips()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Get a list of supported flash ROM chips.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;fl_supported_boards()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Get a list of supported mainboards.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;fl_supported_chipsets()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Get a list of supported chipsets.&lt;br /&gt;
&lt;br /&gt;
=== Programmers ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;fl_programmer_init()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Initialize the specified programmer.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;fl_programmer_shutdown()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Shut down the specified programmer.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;fl_programmer_capabilities()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Get the capabilities of the specified programmer. Valid capabilities: TODO.&lt;br /&gt;
&lt;br /&gt;
=== Operations ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;fl_image_read()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Read the current image from the specified ROM chip.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;fl_image_write()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Write the specified image to the specified ROM chip.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;fl_image_erase()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Erase the specified ROM chip.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;fl_image_verify()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
Verify if the specified image is the same as the contents of the specified ROM chip.&lt;br /&gt;
&lt;br /&gt;
=== Layouts ===&lt;br /&gt;
&lt;br /&gt;
=== What we have: ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;struct flashprog_layout;&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;flashprog_layout_read_from_ifd(layout, flashctx[, buf])&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;flashprog_layout_read_fmap_from_rom(layout, flashctx)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;flashprog_layout_read_fmap_from_buffer(layout, flashctx, buf)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;flashprog_layout_include_region(layout, name)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;flashprog_layout_release(layout)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
=== We need more flexibility: ===&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;enum flashprog_layout_type;&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;struct flashprog_datasrc;&amp;#039;&amp;#039;&amp;#039; where the layout is read from, may include region infos&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;flashprog_layout_read(layout, layout_type, datasrc)&amp;#039;&amp;#039;&amp;#039; searches for &amp;#039;&amp;#039;layout_type&amp;#039;&amp;#039; and adds entries to &amp;#039;&amp;#039;layout&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;flashprog_layout_region_from_layout(region_datasrc, layout, region_name, datasrc)&amp;#039;&amp;#039;&amp;#039; creates region specific &amp;#039;&amp;#039;datasrc&amp;#039;&amp;#039; from layout info and original &amp;#039;&amp;#039;datasrc&amp;#039;&amp;#039; (maybe internal-only function)&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;flashprog_layout_region_from_path(region_datasrc, path, datasrc)&amp;#039;&amp;#039;&amp;#039; path like &amp;#039;&amp;#039;ifd:bios/ifwi:lbp2/obb&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;flashprog_layout_read(buf, len, datasrc)&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;flashprog_layout_release_region()&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;struct flashprog_layout&amp;#039;&amp;#039; could be exported as JSON, e.g.:&lt;br /&gt;
&lt;br /&gt;
  {&lt;br /&gt;
    &amp;quot;offset&amp;quot;: 0,&lt;br /&gt;
    &amp;quot;length&amp;quot;: 0x100000,&lt;br /&gt;
    &amp;quot;ifd&amp;quot;: [&lt;br /&gt;
      &amp;quot;fd&amp;quot;: {&lt;br /&gt;
        &amp;quot;offset&amp;quot;: 0,&lt;br /&gt;
        &amp;quot;length&amp;quot;: 0xfff&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;gbe&amp;quot;: {&lt;br /&gt;
        &amp;quot;offset&amp;quot;: 0x1000,&lt;br /&gt;
        &amp;quot;length&amp;quot;: 0x2000&lt;br /&gt;
      },&lt;br /&gt;
      &amp;quot;bios&amp;quot;: {&lt;br /&gt;
        &amp;quot;offset&amp;quot;: 0x3000,&lt;br /&gt;
        &amp;quot;length&amp;quot;: 0xffd000,&lt;br /&gt;
        &amp;quot;fmap&amp;quot;: [&lt;br /&gt;
          ...&lt;br /&gt;
        ]&lt;br /&gt;
      }&lt;br /&gt;
    ]&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==== Pseudocode example: ====&lt;br /&gt;
&lt;br /&gt;
We want to read a primary layout from a file and CBFS layout from flash:&lt;br /&gt;
&lt;br /&gt;
  file_datasrc = flashprog_datasrc_from_file(&amp;quot;file.name&amp;quot;);&lt;br /&gt;
  flash_datasrc = flashprog_datasrc_from_flashctx(flashctx);&lt;br /&gt;
&lt;br /&gt;
  flashprog_layout_read(layout, FLASHPROG_LAYOUT_TYPE_FMAP, file_datasrc);&lt;br /&gt;
  flashprog_layout_region_from_layout(region_datasrc, layout, &amp;quot;region3&amp;quot;, flash_datasrc);&lt;br /&gt;
  flashprog_layout_read(layout, FLASHPROG_LAYOUT_TYPE_CBFS, region_datasrc);&lt;br /&gt;
&lt;br /&gt;
And &amp;#039;&amp;#039;fallback/ramstage&amp;#039;&amp;#039; from within:&lt;br /&gt;
&lt;br /&gt;
  flashprog_layout_region_from_layout(ramstage_datasrc, layout, &amp;quot;fallback/ramstage&amp;quot;, region_datasrc);&lt;br /&gt;
  flashprog_layout_read(ramstage_buf, length, ramstage_datasrc);&lt;br /&gt;
&lt;br /&gt;
=== Other ===&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
== TODO ==&lt;br /&gt;
&lt;br /&gt;
This is a random list of TODO items which need to be fixed in order to make a usable and useful libflashprog.&lt;br /&gt;
&lt;br /&gt;
* There should be one single &amp;#039;&amp;#039;&amp;#039;flashprog.h&amp;#039;&amp;#039;&amp;#039; or &amp;#039;&amp;#039;&amp;#039;libflashprog.h&amp;#039;&amp;#039;&amp;#039; include file, which contains (only!) the function prototypes and macros which belong to the public libflashprog API.&lt;br /&gt;
* All functions and macros of the public API should have a prefix in order to not pollute the namespace of the programs that link against libflashprog.&lt;br /&gt;
** Suggestion: &amp;#039;&amp;#039;&amp;#039;fl_&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;FL_&amp;#039;&amp;#039;&amp;#039;. Examples: &amp;#039;&amp;#039;&amp;#039;fl_init()&amp;#039;&amp;#039;&amp;#039; or &amp;#039;&amp;#039;&amp;#039;FL_ERR_MALLOC&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
** Other ideas: &amp;#039;&amp;#039;&amp;#039;lf_&amp;#039;&amp;#039;&amp;#039;/&amp;#039;&amp;#039;&amp;#039;LF_&amp;#039;&amp;#039;&amp;#039; (for &amp;#039;&amp;#039;&amp;#039;l&amp;#039;&amp;#039;&amp;#039;ib&amp;#039;&amp;#039;&amp;#039;f&amp;#039;&amp;#039;&amp;#039;lashrom), or &amp;#039;&amp;#039;&amp;#039;lfr_&amp;#039;&amp;#039;&amp;#039;/&amp;#039;&amp;#039;&amp;#039;LFR_&amp;#039;&amp;#039;&amp;#039; or &amp;#039;&amp;#039;&amp;#039;rom_&amp;#039;&amp;#039;&amp;#039;/&amp;#039;&amp;#039;&amp;#039;ROM_&amp;#039;&amp;#039;&amp;#039; (though that&amp;#039;s a bit too generic maybe).&lt;br /&gt;
* No function in libflashprog is allowed to call &amp;#039;&amp;#039;&amp;#039;exit()&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
* All public API functions should return meaningful and unique error codes (which should have useful macros/names such as &amp;#039;&amp;#039;&amp;#039;FL_OK&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;FL_ERR_MALLOC&amp;#039;&amp;#039;&amp;#039;, etc.).&lt;br /&gt;
* pkg-config support would be nice, i.e., some simple &amp;#039;&amp;#039;&amp;#039;libflashprog.pc&amp;#039;&amp;#039;&amp;#039; file.&lt;br /&gt;
* It should be evaluated if it makes sense to use libtool (it probably does) to get a well-tested and portable shared library handling (only &amp;quot;manual&amp;quot; libtool, no autoconf/automake).&lt;br /&gt;
* The public API should not use C99 features, as that makes it hard or even impossible to use the lib from C++ code (e.g. via a Qt-based GUI) or to make a C++ wrapper lib. Specifically &amp;#039;&amp;#039;&amp;#039;.name = &amp;quot;foo&amp;quot;&amp;#039;&amp;#039;&amp;#039; syntax is problematic for example (in the public API, doesn&amp;#039;t matter if used elsewhere).&lt;br /&gt;
* Making Python- or Ruby-bindings at some point is also interesting and feasible once libflashprog is sufficiently usable.&lt;br /&gt;
* The number of global variables should be reduced, in the best case they should all be eliminated. Those that might remain should get the prefix (see above) to avoid namespace conflicts.&lt;br /&gt;
* All fprintf()/printf() calls in the lib should be eliminated, only msg_*() function calls should be used.&lt;br /&gt;
* A progress indicator functionality should be provided for all operations, in order to allow GUIs to display a progressbar or similar.&lt;/div&gt;</summary>
		<author><name>Icon</name></author>
	</entry>
</feed>