uprev_firmware.sh: Fix a bug in rw_only firmware update

A recent change in firmware updater suggests that we define
'CROS_FIRMWARE_MAIN_RW_IMAGE' as an empty string early in the
firmware build.

But this script won't work well for rw_only firmware update
when the empty string of 'CROS_FIRMWARE_MAIN_RW_IMAGE'
is already defined in the ebuild.

Here is the fix.

TEST=uprev_firmware -b bob -v 8785.202.0 rw_only

Change-Id: Ic6d0e588f60b45b786308e52551dc45c975f7898
Reviewed-on: https://chromium-review.googlesource.com/510210
Commit-Ready: Philip Chen <philipchen@chromium.org>
Tested-by: Philip Chen <philipchen@chromium.org>
Reviewed-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-by: YH Lin <yueherngl@chromium.org>
diff --git a/uprev_firmware.sh b/uprev_firmware.sh
index b10f9ed..f06896d 100755
--- a/uprev_firmware.sh
+++ b/uprev_firmware.sh
@@ -160,7 +160,7 @@
 # Update the firmware ebuild file in the device private overlay
 update_fw_ebuild() {
   local keyword_main_fw="MAIN_IMAGE=\"bcs:\/\/${BOARD_NAME}"
-  local keyword_main_rw_fw="MAIN_RW_IMAGE=\"bcs:\/\/${BOARD_NAME}"
+  local keyword_main_rw_fw="CROS_FIRMWARE_MAIN_RW_IMAGE="
   local keyword_ec_fw="EC_IMAGE=\"bcs:\/\/${BOARD_NAME}"
   local keyword_pd_fw="PD_IMAGE=\"bcs:\/\/${BOARD_NAME}"
   local main_fw_line=$(grep -i "${keyword_main_fw}" "${EBUILD_FILE}")
@@ -188,16 +188,17 @@
   if [[ "${FLAGS_rw_only}" -eq "${FLAGS_FALSE}" ]]; then
     sed -i -e "s/${old_main_fw_tar_name}/${MAIN_FW_TAR_NAME}/" \
       -e "s/${old_ec_fw_tar_name}/${EC_FW_TAR_NAME}/" "${EBUILD_FILE}"
+    main_rw_fw_line="${keyword_main_rw_fw}\"\""
     if [[ -n "${PD_FW_TAR_NAME}" ]]; then
       sed -i -e "s/${old_pd_fw_tar_name}/${PD_FW_TAR_NAME}/" \
-    # Create a new line for CROS_FIRMWARE_MAIN_RW_IMAGE
-    main_rw_fw_line="CROS_FIRMWARE_MAIN_RW_IMAGE=\"\
+    main_rw_fw_line="${keyword_main_rw_fw}\"\
-    sed -i "/${old_main_fw_tar_name}/a ${main_rw_fw_line}" "${EBUILD_FILE}"
+  # Create a new line for CROS_FIRMWARE_MAIN_RW_IMAGE
+  sed -i "/${keyword_main_fw}/a ${main_rw_fw_line}" "${EBUILD_FILE}"
   # Update the manifest.
   ebuild-"${FLAGS_board}" "${EBUILD_FILE}" manifest