Skip to content

Commit

Permalink
Feature/no sleep emmc flashing (#15)
Browse files Browse the repository at this point in the history
* EMMC serial handshaking

EMMC flashing will no longer progress nonsensically when errors or
misshaps occur. Most all sleeps are gone.

* EMMC tests serial handshake

* Initial changelog 1.0.0 release
  • Loading branch information
ljkeller authored Jan 19, 2024
1 parent 2318460 commit e95bb75
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 53 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Changelog

This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.0] - 2024-01-24

### Added

- Initial release 🌱 of the rzboard_flash_util for [RZBoard](https://github.com/Avnet/RZ-V2L-HUB)
- Features include:
- eMMC flashing
- Bootloaders
- Linux image
- QSPI flashing
- Bootloaders
- Serial port configuration
- RZBoard IP configuration for linux image flashing
- Progress bars
- Automated [testing / CI](https://github.com/Avnet/rzboard_flash_util/actions)
- Support for...
- Windows, Mac, Linux (Assume Ubuntu)

### Changed

- Latest commits updated EMMC flashing to use serial handshaking and not sleeps. This means the flash utility waits for the RZBoard to send data before continuing the flash process.
94 changes: 44 additions & 50 deletions flash_utils/flash.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,8 @@ def write_bootloader(self):
def flash_bootloader_emmc(self, progress_bar):
"""Flashes the bootloader to the eMMC memory."""

# pylint: disable=locally-disabled, fixme
# TODO: Wait for '>' instead of just time based.
self.flash_erase_emmc()
self.setup_emmc_flash()
progress_bar.update(1)
self.flash_bl2_image_emmc()
progress_bar.update(1)
Expand All @@ -277,38 +276,18 @@ def flash_fip_image_emmc(self):
None
"""

time.sleep(2)
self.__serial_port.write("\rEM_W\r".encode())
self.write_serial_cmd("EM_W")

time.sleep(1)
self.__serial_port.write("1\r".encode())

time.sleep(1)
self.__serial_port.write("100\r".encode())

time.sleep(1)
self.__serial_port.write("00000\r".encode())
self.wait_for_serial_read(")>", print_buffer=self.__args.debug)
self.write_serial_cmd("1")
self.wait_for_serial_read(":", print_buffer=self.__args.debug)
self.write_serial_cmd("100")
self.wait_for_serial_read(":", print_buffer=self.__args.debug)
self.write_serial_cmd("00000")

time.sleep(2)
self.wait_for_serial_read("please send !", print_buffer=self.__args.debug)
self.write_file_to_serial(self.fip_image)

time.sleep(2)
self.__serial_port.write("\rEM_SECSD\r".encode())

time.sleep(1)
self.__serial_port.write("B1\r".encode())

time.sleep(1)
self.__serial_port.write("2\r".encode())

time.sleep(2)
self.__serial_port.write("\rEM_SECSD\r".encode())

time.sleep(1)
self.__serial_port.write("B3\r".encode())

time.sleep(1)
self.__serial_port.write("8\r".encode())
self.wait_for_serial_read("EM_W Complete!", print_buffer=self.__args.debug)

def flash_bl2_image_emmc(self):
"""
Expand All @@ -318,20 +297,18 @@ def flash_bl2_image_emmc(self):
None
"""

time.sleep(1)
self.__serial_port.write("\rEM_W\r".encode())

time.sleep(1)
self.__serial_port.write("1\r".encode())
self.write_serial_cmd("EM_W")

time.sleep(1)
self.__serial_port.write("1\r".encode())

time.sleep(1)
self.__serial_port.write("11E00\r".encode())
self.wait_for_serial_read(">", print_buffer=self.__args.debug)
self.write_serial_cmd("1")
self.wait_for_serial_read(":", print_buffer=self.__args.debug)
self.write_serial_cmd("1")
self.wait_for_serial_read(":", print_buffer=self.__args.debug)
self.write_serial_cmd("11E00")

time.sleep(2)
self.wait_for_serial_read("please send !", print_buffer=self.__args.debug)
self.write_file_to_serial(self.bl2_image)
self.wait_for_serial_read("EM_W Complete!", print_buffer=self.__args.debug)

def flash_flash_writer(self):
"""
Expand All @@ -343,17 +320,36 @@ def flash_flash_writer(self):
"""

self.write_file_to_serial(self.flash_writer_image)
time.sleep(1)
self.wait_for_serial_read(">", print_buffer=self.__args.debug)

def setup_emmc_flash(self):
"""
Modify EXT_CSD register of eMMC to enable eMMC boot
Note
----
Prerequisite for eMMC flashing bootloaders.
"""
self.write_serial_cmd("EM_SECSD")
self.wait_for_serial_read(":", print_buffer=self.__args.debug)
self.write_serial_cmd("b1")
self.wait_for_serial_read(":", print_buffer=self.__args.debug)
self.write_serial_cmd("2")
self.wait_for_serial_read(">", print_buffer=self.__args.debug)
self.write_serial_cmd("EM_SECSD")
self.wait_for_serial_read(":", print_buffer=self.__args.debug)
self.write_serial_cmd("b3")
self.wait_for_serial_read(":", print_buffer=self.__args.debug)
self.write_serial_cmd("8")

def flash_erase_emmc(self):
"""
Erases the eMMC flash memory.
"""
time.sleep(2)
self.__serial_port.write("\rEM_E\r".encode())

time.sleep(1)
self.__serial_port.write("1\r".encode())
self.write_serial_cmd("EM_E")
self.wait_for_serial_read(">", print_buffer=self.__args.debug)
self.write_serial_cmd("1")
self.wait_for_serial_read(">", print_buffer=self.__args.debug)

def flash_bootloader_qspi(self, progress_bar):
"""
Expand Down Expand Up @@ -435,7 +431,6 @@ def write_system_image(self):
if not os.path.isfile(self.rootfs_image):
die(f"Missing system image: {self.rootfs_image}")

# Extract ADB tools
self.__extract_adb()

print("Power on board. Make sure boot2 strap is NOT on.")
Expand All @@ -445,7 +440,6 @@ def write_system_image(self):
self.__serial_port.read_until("Hit any key to stop autoboot:".encode())
self.write_serial_cmd("y")

# Wait a bit
time.sleep(1)

# Set static ip or attempt to get ip from dhcp
Expand Down
8 changes: 5 additions & 3 deletions flash_utils/tests/test_flash_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,10 @@ def test_flashing_emmc_bootloader(
assert "100%" in output.err

mock_serial_port.assert_called_once_with(port=DEFAULT_SERIAL_PORT, baudrate=DEFAULT_BAUD_RATE)
mock_serial_port.return_value.write.assert_any_call("\rEM_E\r".encode())
mock_serial_port.return_value.write.assert_any_call("\rEM_W\r".encode())
mock_serial_port.return_value.write.assert_any_call("\rEM_SECSD\r".encode())
mock_serial_port.return_value.write.assert_any_call("EM_E\r".encode())
mock_serial_port.return_value.write.assert_any_call("EM_SECSD\r".encode())
mock_serial_port.return_value.write.assert_any_call("EM_W\r".encode())
mock_serial_port.return_value.read_until.assert_any_call(">".encode())

mock_file_write.assert_has_calls(
[call(str(flash_writer_image)), call(str(bl2_image)), call(str(fip_image))]
Expand Down Expand Up @@ -270,6 +271,7 @@ def test_flashing_qspi_bootloader(

# assert QSPI Being written to
mock_serial_port.return_value.write.assert_any_call("XLS2\r".encode())
mock_serial_port.return_value.read_until.assert_any_call(">".encode())

mock_file_write.assert_has_calls(
[call(str(flash_writer_image)), call(str(bl2_image)), call(str(fip_image))]
Expand Down

0 comments on commit e95bb75

Please sign in to comment.