pmeerw's blog

Sat, 13 Mar 2021

Lenovo X13 color loop

I found my Lenovo X13 laptop non-functional; after wakeup, it was just cycling through 5 flat color screens displayed on the LCD (red, green, blue, white, etc.) repeatedly. Slight panic...

The service manual (there is such a thing for Lenovo laptops) mentioned pressing FN + Ctrl + Power to enter the LCD self test (which consists of those cycling color screens). Well, I didn't intend to trigger that test. Anyway, turning off the system, pressing FN + Ctrl + Power and the laptop boots normally again. Puuh!

posted at: 17:45 | path: / | permanent link

Thu, 26 Nov 2020

QEMU user-mode emulation

qemu can emulate all kind of architectures and processors, including x86 and x86_64, it has presets for a long list of CPUs ([1], 486, pentium, Haswell, etc.)

I've tried this using qemu 4.2.1 on Ubuntu 20.04, latest is 5.1.0.

qemu does full-system emulation AND user-mode emulation. While the former allows to run a wide range of operating systems on any supported architecture [2], the later runs programs for another Linux or BSD target.

       Full-system                     User-mode
+---------------------+         +---------------------+
| Userspace emulation |         | Userspace emulation |
+----------+----------+         +----------+----------+
           |                               |
 +---------+--------+              +-------+-------+
 | Kernel emulation |              | Kernel native |
 +---------+--------+              +-------+-------+
           |                               |
+----------+---------+            +--------+--------+
| Hardware emulation |            | Hardware native |
+--------------------+            +-----------------+

Let's compile the following simple program (hello.c):

#include <stdio.h>
int main() {
  printf("hello world %p\n", main);
  return 0;
And link statically to be self-contained; qemu can handle dynamically linked executables just fine as well.

To compile and link for 32-bit ARM [3]: arm-linux-gnueabihf-gcc -static -o hello-arm hello.c
For 64-bit x86: gcc -static -o hello-x86_x64 hello.c

Let's check:
$ file hello-arm
hello-arm: ELF 32-bit LSB executable, ARM, EABI5 version 1 (GNU/Linux), statically linked, for GNU/Linux 3.2.0, not stripped
$ file hello-x86_x64
hello-x86_x64: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, for GNU/Linux 3.2.0, not stripped

On Ubuntu, we need qemu-user [4], and can then execute both binaries:
$ qemu-arm -- ./hello-arm
hello world 0x10425
$ qemu-x86_64 -- ./hello-x86_64
hello world 0x401ce5

qemu translates the input binary to run on the native CPU, also in case the architectures match. It uses internal micro ops (some intermediate representation), these can be observed before and after optimization:
qemu-x86_64 -d op -- ./hello-x86_64
qemu-x86_64 -d op_opt -- ./hello-x86_64

For example:

 mov_i64 tmp0,r13
 mov_i64 tmp1,r13
 and_i64 cc_dst,tmp0,tmp1
 discard cc_src
 discard loc10

Also the input and output assembler code can be seen:
qemu-x86_64 -d in_asm -- ./hello-x86_x64
qemu-x86_64 -d out_asm -- ./hello-x86_x64

[1] qemu -cpu help
[2] arm, m64k, mips, mips64, ppc, sparc, sparc64, etc.
[3] apt install gcc-arm-linux-gnueabihf
[4] apt install qemu-user
[5] To show log items: qemu-x86_64 -d help

posted at: 23:45 | path: /programming | permanent link

Tue, 06 Oct 2020

Flashing a 10 GBit NIC: Aquantia AQC107

Checking the current version:
$ ethtool -i enp3s0

driver: atlantic
version: 5.4.0-49-generic-kern
firmware-version: 3.0.33
bus-info: 0000:03:00.0
supports-statistics: yes
supports-test: no
supports-eeprom-access: no
supports-register-dump: yes
supports-priv-flags: no

I had some difficulties to locate firmware and Linux flash tool, here is my local copy: atlflashupdate-1.8.0_AQC107-FW-3.1.109.tgz (FW 3.1.109, flash tool 1.8.0 for x64). The official one might be here (Windows).

Flashing new firmware: $ sudo ./atlflashupdate

Aquantia AQtion Firmware Update Tool [Version 1.8.0]

*** Important notice ***
Update utility is only supported for certain systems.
Please refer README file for supported systems.

Proceed with update? (y/n): y
No  Name    Firmware  Update status        Device         MAC address
1   enp3s0  3.0.33    Available: 3.1.109   07B1-07B11BAA  24:5e:be:xx:xx:xx

*** Important notice ***
The network connection may be dropped during the update process.
Please complete all network activity before updating.
Enter adapter number or 'q' for quit without update

+ Adapter: enp3s0
|-- Backing up... [OK]
|-- Updating... [OK]
|-- New firmware version: 3.1.109
|-- Trying to reload firmware... [OK]
|-- Restarting device driver... [OK]

Firmware update finished!

posted at: 23:26 | path: /configuration | permanent link

Thu, 01 Oct 2020

ssh: Too many authentication failures

SSHing to a remote host and get Too many authentication failures?

Perhaps beause you have a number of private keys (in .ssh, in your keychain, forwarded by your ssh agent) that all are tried and thus exceed the number of authentication tries (configurable via MaxAuthTries server-side). All you want is type the damn password.

Solution: ssh -o PubkeyAuthentication=no host

posted at: 22:46 | path: / | permanent link

Tue, 26 May 2020

Finally: LaTeX.css

CSS library that turns your HTML document into a website that looks like a LaTeX document. Write semantic HTML, add <link rel="stylesheet" href=""> to the <head> and...

posted at: 00:18 | path: /fun | permanent link

Made with PyBlosxom