Flashing script wrongfully claims the phone is still locked

dear /e/os community,

i followed the following guide to install /e/os on my fairphone 4: Install /e/OS on a Fairphone FP4 - “FP4”

when i try to run the flash_FP4_factory.sh script i get the following text:
Info: Your phone is in regular bootloader mode.
Error: Your phone is still locked.
Did you execute ‘fastboot flashing unlock’?
Error: Your phone is not ready for flashing yet (see above), aborting…

however, i ran ‘fastboot flashing unlock’ and if i try again, it tells me the device is already unlocked.

does anyone have any idea what the issue might be?

Regain your privacy! Adopt /e/OS the deGoogled mobile OS and online servicesphone

2 Likes

Hi @stefann

Your computer might not be authorized to apply such a change. Have you enabled usb debugging in the developpers settings ?
You can also unlock the bootloader directly in the phone. See this https://support.fairphone.com/hc/en-us/articles/10492476238865-Manage-the-Bootloader

Good luck !!

I just ran into this issue as well. The problem for me was that the bash script tries to run fastboot but if you don’t add fastboot and adb to your path, the script will error and tell you that your phone is still locked. TBH very weird that the script doesn’t check if fastboot is availabe.

To fix the script, run export PATH="$<path-to-platform-tools>/platform-tools:$PATH" so that the bash script can actually find fastboot. (Obviously replace <path-to-platform-tools> with the actual path)

4 Likes

Hi @noel welcome to the /e/ forum.

I am pleased to hear that /e/OS installed ok for you, but I ask this really out of curiosity … to see if something changed.

While this post is from a Fairphone 3 guide [HOW-TO] Flash /e/-OS on Fairphone 3 using Debian based GNU/Linux - #58 by aibd I thought it was very similar for FP4.

adb and fastboot are included with the downloaded ROM and as long as the unzipped download remains intact and the user changes directory to work there the script is expected to find fastboot within the ROM.

Thanks for the welcome @aibd. I just checked, and indeed, the build I got from the official docs that @stefann used as well

i followed the following guide to install /e/os on my fairphone 4: Install /e/OS on a Fairphone FP4 - “FP4”

include adb and fastboot in the bin-linux-x86 directory. However, the flash_FP4_factory.sh script included with the build does not correctly call fastboot in the function check_unlock_status(). The whole function is pretty hacky. I am pretty busy, but I will try to send a bug report or a patch later, just have to read up on how to do that for e/OS.

1 Like

I’m having the same issue although I unlocked successfully git Bash it shows the “Error: Your phone is still locked” message.
I tried your instructions but failed…
Here ist what I did: (I’m doing it on windows)

  • I run gitBash within the unzipped folder (with all the files and the two folders with adb)
  • then I run your command, in my case: export PATH="$</c/Fairphone4eOSinstallation/bin-msys>/platform-tools:$PATH"
    I’m not sure if something happend but there is no error message either
  • then I run the flashing command (and I have the same error agin)

any idea what I’m doing wrong? or maybe I should add it directly in the script?

UPDATE
As I did not succeed with Noel’s solution I did use an other method. I just edited the flash_FP4_factory.ch and deleted the part from the code where the unlock status of the phone is checked as well as the variable mentioning of the unlock check (or what it is ^^) at the end of the script.

But I must admit I am not entirely sure what happens if you do that and your device is actually still locked. So be careful please.(be sure your device is unlocked)

It worked very fine for me and I have /e/ OS on the phone now :smiley:

1 Like

I also ran into this issue yesterday and today with my new Fairphone 5 and the flash_FP5_factory.sh script (eOS image 2.4.1 (stable)). I had the bootloader unlocked, but the flash-fp5-script complained falsely about the phone still being locked.

In my opinion, the script defines the fastboot-binary correctly in the function ‘os_checks()’.
However the function ‘check_unlock_status()’ uses a plain “fastboot” instead of the variable “${FASTBOOT_BIN}” (where the correct binary is stored). This probably has been forgotten to be adjusted in the script.

I replaced the “fastboot” commands inside ‘check_unlock_status()’ with the variable “${FASTBOOT_BIN}” and afterwards the script passes the check, detects the correct fastboot mode and does not complain anymore about the phone still being locked.

The changed function ‘check_unlock_status()’ looks like this after the modification:

# Check if the device is properly unlocked
check_unlock_status() {
  PHONE_IS_READY=true
  if ("${FASTBOOT_BIN}" getvar is-userspace 2>&1 | grep -q yes); then
    echo "Info: Your phone is in fastbootD mode."
    if ("${FASTBOOT_BIN}" getvar unlocked 2>&1 | grep -q no); then
      echo "Error: Your phone is still locked."
      echo "Did you execute 'fastboot flashing unlock'?"
      PHONE_IS_READY=false
    fi
  else
    echo "Info: Your phone is in regular bootloader mode."
    if ("${FASTBOOT_BIN}" getvar unlocked 2>&1 | grep -q no); then
      echo "Error: Your phone is still locked."
      echo "Did you execute 'fastboot flashing unlock'?"
      PHONE_IS_READY=false
    fi
    if ("${FASTBOOT_BIN}" oem device-info 2>&1 | grep -q "critical unlocked: false"); then
      echo "Error: Critical partitions are still locked."
      echo "Did you execute 'fastboot flashing unlock_critical'?"
      PHONE_IS_READY=false
    fi
  fi

  if [ "$PHONE_IS_READY" = "false" ]; then
    echo "Error: Your phone is not ready for flashing yet (see above), aborting..."
    exit 1
  fi
}

I will also ping the developer of the script (mentioned inside the script) about this thread so that this issue can be addressed properly.

5 Likes

Hi,
New FP5, same issue but this time with 2.5 stable. Did the developer respond? The script still returns, “Your phone is still locked” even though on the phone itself I see “Device State - unlocked”

Not knowing my the difference between if and fi in the code you posted, I am wary to start editing.

(I am trying this from Win11 so maybe I should try from Linux?)

Hi there!
Yes, I exchanged some information with the developer of the script.
In the meantime, I unfortunately did not find the time to look further into the issue.

Basically, the issue seems to be fixed in the official code repository according to the developer:

This version does not even have the ‘check_unlock_status()’ function anymore and also seems to be different in general from the version which is released with the official images.

I also did some more research today after seeing your post.

When you check the branches for the upcoming releases, the old script seems to be still in place e.g. for the stable version:

So something still seems to be wrong/out of place here. The script versions seem not to be aligned. In other words, corrections/changes to the script seem not to have been applied to all branches.

I was encouraged by the script developer to create Gitlab issues and merge requests to fix the issues.
I will do this as soon as I have received a Gitlab account (this is not easily possible/only possible via helpdesk ticket because of another issue). And even once the merge requests would be merged, nothing would change until the next release of the images (probably 2.6).

In the meantime, I provide the whole script which I have used to flash the 2.4.1 image on my Fairphone 5 here. It includes the changed code parts from my previous post (I refer to this as the “corrected script” at the bottom of this post):

#!/usr/bin/env bash

##########
# This script is created and maintained by
#       Bharath(@teamb58).org
# Feel free to connect for any queries or suggestions.
##########

##########
# This script flashes a software release and completely wipes the device.
#
##########

set -e
set -u

# Target device info
PRODUCT="Fairphone 5"
PRODUCT_ID="FP5"

# Paths/files
ROOT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
IMAGES_DIR="${ROOT_DIR}"

# Abort the script (and wait for a key to be pressed).
abort_now() {
  echo ""
  read -rp "ERROR: Aborting now (press Enter to terminate)." a
  exit 1
}

# Check for connected phone
find_device() {
  echo "INFO: Looking for connected device(s)..."
  DEVICE_FOUND="false"
  while [ ${DEVICE_FOUND} = "false" ]
  do
    serial_numbers=

    for sn in $("${FASTBOOT_BIN}" devices | grep fastboot | grep -oE '^[[:alnum:]]+')
    do
      # Checking the product ID
      PRODUCT_STRING=$("${FASTBOOT_BIN}" -s "${sn}" getvar product 2>&1)
      # Add serial, if product matches
      if [[ ${PRODUCT_STRING} == *"${PRODUCT_ID}"* ]] || [[ ${PRODUCT_STRING} == *"${PRODUCT_ID_OLD}"* ]]
      then
        serial_numbers="${serial_numbers} $sn"
      fi
    done

    case $(echo "${serial_numbers}" | wc -w | grep -oE '[0-9]+') in
      0)
        echo ""
        echo "WARNING: No ${PRODUCT} found in fastboot mode."
        echo "WARNING: Make sure that a ${PRODUCT} is connected."
        ;;
      1)
        echo "INFO: One ${PRODUCT} in fastboot mode found (serial number: ${sn})."
        DEVICE_FOUND="true"
        break
        ;;
      *)
        echo ""
        echo "WARNING: Several ${PRODUCT}'s in fastboot mode connected."
        echo "WARNING: Please connect only one ${PRODUCT}."
        ;;
    esac

    echo ""
    while true
    do
      read -rp "Do you want to look for a ${PRODUCT} again? [(Y)es/(n)o]: " a
      if [ -z "${a}" ] || [ "${a}" = 'y' ] || [ "${a}" = 'Y' ]
      then
        break
      elif [ "${a}" = 'n' ] || [ "${a}" = 'N' ]
      then
        exit 0
      fi
    done
  done
}

# Check if the device is properly unlocked
check_unlock_status() {
  PHONE_IS_READY=true
  if ("${FASTBOOT_BIN}" getvar is-userspace 2>&1 | grep -q yes); then
    echo "Info: Your phone is in fastbootD mode."
    if ("${FASTBOOT_BIN}" getvar unlocked 2>&1 | grep -q no); then
      echo "Error: Your phone is still locked."
      echo "Did you execute 'fastboot flashing unlock'?"
      PHONE_IS_READY=false
    fi
  else
    echo "Info: Your phone is in regular bootloader mode."
    if ("${FASTBOOT_BIN}" getvar unlocked 2>&1 | grep -q no); then
      echo "Error: Your phone is still locked."
      echo "Did you execute 'fastboot flashing unlock'?"
      PHONE_IS_READY=false
    fi
    if ("${FASTBOOT_BIN}" oem device-info 2>&1 | grep -q "critical unlocked: false"); then
      echo "Error: Critical partitions are still locked."
      echo "Did you execute 'fastboot flashing unlock_critical'?"
      PHONE_IS_READY=false
    fi
  fi

  if [ "$PHONE_IS_READY" = "false" ]; then
    echo "Error: Your phone is not ready for flashing yet (see above), aborting..."
    exit 1
  fi
}

# Flash (or manipulate) relevant partitions
flash_device() {
  flash_image_ab_or_abort "${sn}" bluetooth "${IMAGES_DIR}/bluetooth.img"
  flash_image_ab_or_abort "${sn}" devcfg "${IMAGES_DIR}/devcfg.img"
  flash_image_ab_or_abort "${sn}" dsp "${IMAGES_DIR}/dsp.img"
  flash_image_ab_or_abort "${sn}" modem "${IMAGES_DIR}/modem.img"
  flash_image_ab_or_abort "${sn}" xbl "${IMAGES_DIR}/xbl.img"
  flash_image_ab_or_abort "${sn}" tz "${IMAGES_DIR}/tz.img"
  flash_image_ab_or_abort "${sn}" hyp "${IMAGES_DIR}/hyp.img"
  flash_image_ab_or_abort "${sn}" keymaster "${IMAGES_DIR}/keymaster.img"

  flash_image_ab_or_abort "${sn}" abl "${IMAGES_DIR}/abl.img"
  flash_image_ab_or_abort "${sn}" boot "${IMAGES_DIR}/boot.img"
  flash_image_ab_or_abort "${sn}" dtbo "${IMAGES_DIR}/dtbo.img"
  flash_image_ab_or_abort "${sn}" vendor_boot "${IMAGES_DIR}/vendor_boot.img"
  flash_image_ab_or_abort "${sn}" vbmeta_system "${IMAGES_DIR}/vbmeta_system.img"
  flash_image_ab_or_abort "${sn}" vbmeta "${IMAGES_DIR}/vbmeta.img"
  flash_image_or_abort "${sn}" super "${IMAGES_DIR}/super.img"

  flash_image_ab_or_abort "${sn}" aop "${IMAGES_DIR}/aop.img"
  flash_image_ab_or_abort "${sn}" featenabler "${IMAGES_DIR}/featenabler.img"
  flash_image_ab_or_abort "${sn}" imagefv "${IMAGES_DIR}/imagefv.img"
  flash_image_ab_or_abort "${sn}" multiimgoem "${IMAGES_DIR}/multiimgoem.img"
  flash_image_ab_or_abort "${sn}" qupfw "${IMAGES_DIR}/qupfw.img"
  flash_image_ab_or_abort "${sn}" uefisecapp "${IMAGES_DIR}/uefisecapp.img"
  flash_image_ab_or_abort "${sn}" xbl_config "${IMAGES_DIR}/xbl_config.img"

  flash_image_ab_or_abort "${sn}" cpucp "${IMAGES_DIR}/cpucp.img"
  flash_image_ab_or_abort "${sn}" shrm "${IMAGES_DIR}/shrm.img"

  "$FASTBOOT_BIN" -s "${sn}" erase userdata
  "$FASTBOOT_BIN" -s "${sn}" erase metadata

  "$FASTBOOT_BIN" -s "${sn}" --set-active=a
}

# Flash an image to a partition. Abort on failure.
# Arguments: <device serial number> <partition name> <image file>
flash_image_or_abort() {
  local retval=0
  "$FASTBOOT_BIN" -s "${1}" flash "${2}" "${3}" || retval=$?

  if [ "${retval}" -ne 0 ]
  then
    echo ""
    echo "ERROR: Could not flash the ${2} partition on device ${1}."
    echo ""
    echo "ERROR: Please unplug the phone, take the battery out, boot the device into"
    echo "ERROR: fastboot mode, and start this script again."
    echo "ERROR: (To get to fastboot mode, press Volume-Down and plug in the USB-C)"
    echo "ERROR: (cable until the fastboot menu appears.)"
    abort_now
  fi
}

# Flash an image to both A and B slots of a partition. Abort on failure.
# Arguments: <device serial number> <partition name without slot> <image file>
flash_image_ab_or_abort() {
  flash_image_or_abort "${1}" "${2}_a" "${3}"
  flash_image_or_abort "${1}" "${2}_b" "${3}"
}

# Operating system checks and variable definition
os_checks() {
  case "$(uname -s 2> /dev/null)" in
    Linux|GNU/Linux)
      echo "INFO: You are using a Linux distribution."
      FASTBOOT_BIN="${ROOT_DIR}/bin-linux-x86/fastboot"
      ;;
    msys|MINGW*)
      echo "INFO: You are using MinGW on Windows"
      FASTBOOT_BIN="${ROOT_DIR}/bin-msys/fastboot.exe"
      ;;
    *)
      echo "ERROR: Unsupported operating system (${OSTYPE})."
      echo "ERROR: Only GNU/Linux, and MinGW on Windows are currently supported."
      abort_now
      ;;
  esac
}

# Control the reboot sequence
reboot_device() {
  echo "-----------"
  echo ""
  echo "INFO: Done. The device will reboot now."
  "${FASTBOOT_BIN}" -s "${sn}" reboot
  echo ""
  echo "INFO: You can unplug the USB cable now."
  echo ""
}

echo ""
echo "*** ${PRODUCT} flashing script ***"
echo ""
echo "INFO: The procedure will start soon. Please wait..."
echo "Note that this will detect and flash only on ${PRODUCT} device."
sleep 2

# Begin with some OS checks and variable definition
os_checks

# Call function to look for device(s)
# If only one device is found $sn will store its serial number
find_device

# Check if the device is properly unlocked
check_unlock_status

# Flash the device
flash_device
# Reboot device
reboot_device

If unsure how to replace the falsy, original script, I recommend to download Visual Studio Code, open the script and replace the whole falsy, original script with the whole corrected script from above. It’s best to create a copy of the original script beforehand to be able to compare.

For your understanding:
In a shell script, “if” marks the start of an if-block, and “fi” simply marks its end.

Also, making another attempt with the falsy, original script from/on Linux will probably change nothing as to my understanding, the issue lies in code parts which are executed the same way for all operating systems.

1 Like

Thanks for that. It’s too late for me to have a look now, I’ll check it out tomorrow sometime.

I finally fixed this with the help of @piero by adding an environment variable to my Windows11 installation which pointed to platform-tools. IMHO, this should not be a suggestion in the Win install guide but rather a pre-requisite so as to avoid trying to figure out why there are two versions of fastboot.exe in this install process, (one in platform-tools and the other in bin.msys). For someone with my relatively non-tech profile this has been quite frustrating.

1 Like

Hi Maryn. I created an account just now to thank you for posting the corrected script here. I had the exact same issue. I was a bit reluctant to make changes to the script, but using a text comparison tool (and some very basic programming skills) I became confident enough to run the script. Great community! I will continue to support you! :slight_smile:

1 Like

Thank you @marius.telcean96 !
In the meantime, I tried to create a Gitlab account again.
However this seems not to be possible currently due to the outage of services mentioned here:

I will contact the script developer(s) again so that they maybe have another look at the newest information from this thread.

There is new feedback from the script maintainers.
A merge request to fix the issue is now on the way:

This means we can expect this issue to be fixed soon - probably in the next release of the image.

1 Like

This topic was automatically closed after 180 days. New replies are no longer allowed.