Enable EVT2 flash

Add a flash flag to support EVT1 or older boards (flash.sh -o)
Add both memory configuration in bootloader.mk

Change-Id: I1819c0807e1f369fa1ef59eebc041ae1d54f3006
diff --git a/bootloader.mk b/bootloader.mk
index dcae7aa..6af0d72 100644
--- a/bootloader.mk
+++ b/bootloader.mk
@@ -29,7 +29,7 @@
 	$(LOG) lk.bin extract
 	find $(PRODUCT_OUT)/packages -name 'lk-bootloader*$(USERSPACE_ARCH)*.deb' | xargs \
 	dpkg --fsys-tarfile | \
-	tar --strip-components 2 -C $(PRODUCT_OUT) -xf - ./boot/lk.bin
+	tar --strip-components 2 -C $(PRODUCT_OUT) -xf - --wildcards ./boot/lk_*.bin
 	$(LOG) lk.bin finished
 
 $(PRODUCT_OUT)/fip.bin: excelsior-bootloader | out-dirs
@@ -43,7 +43,7 @@
 	$(LOG) bl2.img extract
 	find $(PRODUCT_OUT)/packages -name 'excelsior-bootloader*$(USERSPACE_ARCH)*.deb' | xargs \
 	dpkg --fsys-tarfile | \
-	tar --strip-components 2 -C $(PRODUCT_OUT) -xf - ./boot/bl2.img
+	tar --strip-components 2 -C $(PRODUCT_OUT) -xf - --wildcards ./boot/bl2_*.img
 	$(LOG) bl2.img finished
 
 $(PRODUCT_OUT)/u-boot-env.bin: excelsior-bootloader | out-dirs
diff --git a/flash.sh b/flash.sh
index 666950c..ab96c66 100755
--- a/flash.sh
+++ b/flash.sh
@@ -16,6 +16,7 @@
 
 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
 FASTBOOT_CMD="$(which fastboot)"
+DRAM_SIZE=2G
 
 function die {
     echo "$@" >/dev/stderr
@@ -29,8 +30,10 @@
 function load_fastboot {
   local files_dir="$1"
   python3 "${files_dir}/flashtools/debug_board_reset.py" --rom &
+  sleep 1
   pushd "${files_dir}"
   python3 "${files_dir}/flashtools/fbtool.py" -f "${files_dir}/dl_addr.ini"
+  sleep 1
   popd
 }
 
@@ -71,6 +74,20 @@
     ln -sf "${ROOTDIR}/board/flashtools" "${files_dir}/flashtools"
   fi
 
+  # BL2 and LK need to be handled separatedly for now. 
+  if [[ -f "${files_dir}/bl2_${DRAM_SIZE}.img" ]]; then
+    ln -sf "${files_dir}/bl2_${DRAM_SIZE}.img" "${files_dir}/bl2.img"
+  else
+    echo "bl2_${DRAM_SIZE}.img is missing!"
+    found_all_files=""
+  fi
+  if [[ -f "${files_dir}/lk_${DRAM_SIZE}.bin" ]]; then
+    ln -sf "${files_dir}/lk_${DRAM_SIZE}.bin" "${files_dir}/lk.bin"
+  else
+    echo "lk_${DRAM_SIZE}.bin is missing!"
+    found_all_files=""
+  fi
+
   for file in "${files[@]}"; do
     if [[ ! -f "${files_dir}/${file}" ]]; then
       echo "${file} is missing!"
@@ -116,18 +133,19 @@
 
 function main {
     local usage=$(cat <<EOF
-Usage: flash.sh [-d <files_dir>] [-s <serial>] [-r <detect_retries>]
+Usage: flash.sh [-d <files_dir>] [-s <serial>] [-r <detect_retries>] [-o] [-l]
   -l                  load LK into ram for fastboot mode
   -d <files_dir>      flashes files from <files_dir> (defaults to current dir)
   -s <serial>         only flashes the board with the given fastboot serial number
   -r <detect_retries> number of times to retry waiting for a device (defaults to 0)
+  -o                  flash the old boards.
 EOF
 )
   local detect_retries=1    # -r <retry_count>
   local serial_number       # -s <serial>
   local files_dir           # -d <files_dir>
   local lk_fastboot         # -l
-  local args=$(getopt hls:d:r: $*)
+  local args=$(getopt hlos:d:r: $*)
   set -- $args
 
   for i; do
@@ -155,6 +173,11 @@
         shift 2
         ;;
 
+      -o)  # old board 
+        DRAM_SIZE=1G
+        shift 1
+        ;;
+
       --)  # end of args
         shift
         break