fix alignment bug on erase blocks for usb_update.py

This commit is contained in:
bunnie 2021-05-25 03:54:37 +08:00
parent c483581716
commit 40b4f26dcb
2 changed files with 11 additions and 3 deletions

View file

@ -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) * `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 * 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 ### Installation: Windows 10
* You will need to install python3 from the Windows App store * You will need to install python3 from the Windows App store

View file

@ -253,7 +253,7 @@ class PrecursorUsb:
erased = 0 erased = 0
while erased < len(data): while erased < len(data):
self.ping_wdt() self.ping_wdt()
if len(data) - erased >= 65536: if (len(data) - erased >= 65536) and ((addr & 0xFFFF) == 0):
blocksize = 65536 blocksize = 65536
else: else:
blocksize = 4096 blocksize = 4096
@ -264,7 +264,7 @@ class PrecursorUsb:
if status & 0x02 != 0: if status & 0x02 != 0:
break break
if blocksize <= 4096: if blocksize == 4096:
self.flash_se4b(addr + erased) self.flash_se4b(addr + erased)
else: else:
self.flash_be4b(addr + erased) self.flash_be4b(addr + erased)