From 40b4f26dcb5dd2eb8a4a80d18a28f385578efcce Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 25 May 2021 03:54:37 +0800 Subject: [PATCH] fix alignment bug on erase blocks for usb_update.py --- tools/README_UPDATE.md | 10 +++++++++- tools/usb_update.py | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/tools/README_UPDATE.md b/tools/README_UPDATE.md index 66f51f90f..f79a36d1d 100644 --- a/tools/README_UPDATE.md +++ b/tools/README_UPDATE.md @@ -11,8 +11,16 @@ Maintainer's note: this is a mirror of the README.md file found in [betrusted-ec * `sudo pip3 install pyusb progressbar2` (you need `pyusb` and `progressbar2` in the sudo environment) * you probably need to run as `sudo`: `sudo ./usb_update.py [args]` to access the USB port; add the appropriate command line arguments -If you don't like/can't use `sudo`, I hear something involving udev can solve this problem, but I've never been able to get it to work. If someone can contribute a simple, robust cross-distro guide to USB `udev` rules that ages well, I'm guessing the Internet would appreciate it. +In order to get `xtask` to work (it calls `usb_update.py`) you will need to add a udev rule to eliminate the need for sudo privs. Under +Ubuntu 18.04LTS, it looks something like this: +1. Add a file called `99-precursor-usb.rules` to /etc/udev/rules.d/ with the following content as a single line terminated by a carriage return: +`SUBSYSTEM=="usb", ATTRS{idVendor}=="1209", ATTRS{idProduct}=="5bf0", GROUP="plugdev", TAG+="uaccess"` +2. Run `sudo udevadm control --reload-rules` +3. If the device was plugged in, you'll have to unplug it and plug it back in again for the new rules +to take effect. + +We would appreciate any improvements/suggestions for alternate Linux distros. `udev` rules seem very distro-specific and change with time. ### Installation: Windows 10 * You will need to install python3 from the Windows App store diff --git a/tools/usb_update.py b/tools/usb_update.py index 877c6232b..57cfc4830 100755 --- a/tools/usb_update.py +++ b/tools/usb_update.py @@ -253,7 +253,7 @@ class PrecursorUsb: erased = 0 while erased < len(data): self.ping_wdt() - if len(data) - erased >= 65536: + if (len(data) - erased >= 65536) and ((addr & 0xFFFF) == 0): blocksize = 65536 else: blocksize = 4096 @@ -264,7 +264,7 @@ class PrecursorUsb: if status & 0x02 != 0: break - if blocksize <= 4096: + if blocksize == 4096: self.flash_se4b(addr + erased) else: self.flash_be4b(addr + erased)