flashrom: Re-factor do_flashrom() with pipe support

This adds the capability in do_flashrom() to utilize pipes, thus
allowing the caller to obtain output from running flashrom. It
also renames it to do_cmd() since there is really nothing specific
to flashrom and it will be used to run other commands.

The caller may create an array of structs which contains the
direction, file descriptor, and buffer to be passed to/from
the child process. If no such array is provided, then we suppress
stdio as the default behavior. This implies that the caller intends
to operate on files specified in flashrom's arguments and only needs
to know whether flashrom succeeded or failed.

In the near-term this will be used for two things:
- Obtaining ROM size by running "flashrom --get-size" which will
  make it so we can remove the hard-coded constant used for each
  platform now.
- Replace popen() to call the `which` command, currently used in
  flashrom_path(). This is simply intended to reduce the number of
  ways in which we spawn a child process.

Eventually we may split this function into its own library, possibly
alongside the IPC stuff used for the global semaphore lock.

BUG=none
BRANCH=none
TEST="mosys memory spd print all" and "mosys eeprom map" on cyan works.

Change-Id: I63ff778a8f2fb48f86715cba0ebaecc9e1f7603a
Signed-off-by: David Hendricks <dhendrix@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/319645
Reviewed-by: Shawn N <shawnn@chromium.org>
1 file changed