factory_install: Get mini-omaha addreess from tftp server.

This is for dymaic mini-omaha server address assignment.
Factory install shim gets tftp url from kernel command line.
Next, it gets omahaserver.conf from tftp server to override
mini-omaha server address. Then start factory installation.

This change considers backward compatibility. It works well
if there is no omahaserver.conf in tftp server.

BUG=chrome-os-partner:22180
TEST=Network boot and install on Falco.

Change-Id: If3c1fa6da0bc22f003740fb9ae254db9963e3589
Reviewed-on: https://chromium-review.googlesource.com/172074
Tested-by: Bowgo Tsai <bowgotsai@chromium.org>
Reviewed-by: Hung-Te Lin <hungte@chromium.org>
Commit-Queue: Bowgo Tsai <bowgotsai@chromium.org>
diff --git a/factory_install.sh b/factory_install.sh
index feb3371..9dce6a6 100644
--- a/factory_install.sh
+++ b/factory_install.sh
@@ -344,6 +344,31 @@
   fi
 }
 
+override_from_tftp() {
+  # Check for Omaha URL from tftp server.
+  # OMAHA is override env variables used when calling memento_updater.
+  local omaha=""
+  local tftp=""
+  local omahaserver_config="omahaserver.conf"
+  local tftp_output=""
+  # Use board specific config if $BOARD is not null.
+  [ -z $BOARD ] || omahaserver_config="omahaserver_$BOARD.conf"
+  tftp_output="/tmp/${omahaserver_config}"
+
+  if tftp="$(find_var tftpserverip)"; then
+    log "override_from_tftp: kernel cmdline tftpserverip $tftp"
+    # Get omahaserver_config from tftp server.
+    # Use busybox tftp command with options: "-g: Get file",
+    # "-r FILE: Remote FILE" and "-l FILE: local FILE".
+    rm -rf "$tftp_output"
+    tftp -g -r $omahaserver_config -l $tftp_output $tftp || true
+    if [ -f $tftp_output ]; then
+      OMAHA="$(cat $tftp_output)"
+      log "override_from_tftp: OMAHA override to $OMAHA"
+    fi
+  fi
+}
+
 overrides() {
   override_from_firmware
   override_from_board
@@ -940,6 +965,9 @@
       fi
     done
 
+    # Check for OMAHA override from tftp server.
+    override_from_tftp
+
     # TODO(hungte) how to set time in RMA?
     set_time || die "Please check if the server is configured correctly."
   fi