mmgen / mmgen-geek-tools

Random scripts to make a geek’s life easier
GNU General Public License v3.0
15 stars 5 forks source link

Doesn't seem to work on BPI-M2 Zero #5

Closed Kodmod closed 3 years ago

Kodmod commented 3 years ago

The script executes fine and appears to create the partitions and FS properly. But after inserting the SD card into the device, the LED turns on for 1-2 seconds and then turns off completely, instead of the typical armbian heartbeat pattern. I also cannot communicate with it via the serial console.

Any idea why this might be the case? I've attached the verbose terminal output. terminal.txt

mmgen commented 3 years ago

You should be getting some output on the serial console, at least from u-boot, even if the kernel fails to start. Do you have your USB-UART dongle wired up correctly? Are you seeing the u-boot messages on the serial console when booting the stock image?

Kodmod commented 3 years ago

USB-UART dongle? Could this not work over USB, like as it does normally with the g_serial module?

mmgen commented 3 years ago

No, of course, that's all configured much later, during system bootup. The serial console will start giving you output as soon as U-Boot starts, before the kernel is even loaded.

Here's some info to get you started:

Info on using the serial console (for Orange Pi, but generally applicable): https://linux-sunxi.org/UART

Hardware info for your board: https://wiki.banana-pi.org/Banana_Pi_BPI-M2_ZERO

Pinouts for Raspberry Pi (Banana Pi uses the same ones): https://pinout.xyz

You'll be connecting to pins 6,8 and 10 on the GPIO. Note that RX goes to TX and TX to RX. And ground to ground, of course.

Kodmod commented 3 years ago

Yep, thats the problem. I got spoiled by armbian and thought it would be from USB :P Although, do you think this functionality could be made to work un uboot? This mailing list hints that it is possible but I'm not sure if it's a matter of just loading a driver (usbtty) or recompiling everything. I have no knowledge of how uboot works.

mmgen commented 3 years ago

From the mailing list:

There is usbtty support in u-boot but only for some OMAP1 devices (although it is broken in the current release) and for some MPC devices. Unfortunately, I don't believe that this is currently supported for OMAP3. Therefore, I think that you are going to need an RS232-to-USB dongle for your PC in order to interact with u-boot.

Very unlikely you could get this to work. Much simpler to just buy a dongle.

It's also possible to compile in the g_serial module (described here: https://linux-sunxi.org/USB_Gadget/Serial), but that means recompiling the kernel, and you won't see the early U-Boot messages before the kernel is loaded.

Another option might be to compile in g_ether to give you your USB network interface in the initrd, and then you could unlock via SSH, but that would probably require some additional trickery to make it work.

I'd recommend just getting the dongle. It's well worth it.

Kodmod commented 3 years ago

My armbian image is actually a custom build with g_ether and g_serial added as modules. Are you saying that if I compile in g_serial (not as a module), I could access the USB serial console and decrypt it that way?

At what point does the decryption happen? If it's after the kernel is loaded, then surely I should be able the load the g_serial module before the decryption prompt, right?

g_ether is out of the question because it requires a lot of setup and dependance on other things like DHCP.

BTW you can close the issue of you'd like since this is probably outside the scope for this script.

mmgen commented 3 years ago

Yes, you're right, compiling in g_serial would be the easiest approach. Since it's part of the kernel, it would already be loaded before the decryption prompt, which happens in the initrd userspace. The downside with using g_serial is that you might not be able to reconfigure your USB link as a network link once you've booted up, if that's what you intend to do.

Kodmod commented 3 years ago

The downside with g_serial is that you might not be able to reconfigure your USB link as a network link once you've booted up, if that's what you intend to do.

I completely forgot about that. Is there a way I can load g_serial as a module before the decryption prompt (so I can then rmmod it)?

mmgen commented 3 years ago

You can add it to /etc/initramfs-tools/modules, run update-initramfs and it will be included in the initrd. That might just work. You need to add all the mods on which it depends as well.

Kodmod commented 3 years ago

Just chrooted into the fs and found that g_serial was already there. Not sure what I could do at this point. I appreciate all your help though.

mmgen commented 3 years ago

Oh that's right. I see it in the terminal printout you sent me.

I'd recommend testing whether you can get the serial console working over USB with the stock image, trying with g_serial both compiled-in and as a module. Then take it from there.

mmgen commented 3 years ago

New feature, tested on the Orange Pi PC2. Don't know whether it will work on your board, but you might give it a shot:

Commit cf93a045 - disk unlocking via SSH over USB (USB gadget, g_ether)

Kodmod commented 3 years ago

Whoa, no way. I'll give this a shot soon. You might want to mention in the documentation that the armbian image itself must have g_ether built as a module.

mmgen commented 3 years ago

All the prebuilt images (the script is really designed to be used with them) have g_ether as a module, don't they?

And if g_ether is compiled in, I think everything should work anyway.

Kodmod commented 3 years ago

I wasn't aware that they added the g_ether module to the prebuilt images. This might be a recent inclusion, and a welcome one at that.

mmgen commented 3 years ago

I'm testing on only 2 boards, the Rock Pi 4 and the Orange Pi PC2, but both of them have the USB gadget modules, so I'm guessing that all images for boards with OTG ports do.

Kodmod commented 3 years ago

I tried the update but unfortunately, I couldn't get it to work. The issue is that the device doesn't even appear to boot properly. As before, the LED lights up for 1 second and then turns off indefinitely. My computer doesn't even detect it as a USB device either. So the problem likely isn't even g_serial or g_ether but the booting. Maybe I could try to do this manually (as you posted on the armbian forum) instead of using the script and see where things go wrong.

mmgen commented 3 years ago

Yep, looks like the problem's very early on in the boot process. With a USB dongle you could get some useful diagnostics, by the way, so you might look into acquiring one. I also plan to get my hands on some more boards to expand the range of hardware my script supports.

Kodmod commented 3 years ago

I highly recommend the BPI-M2 Zero. It's cheap, has the form factor of Rasp-pi zero, has wireless, and is quad-core with 512 MB of RAM. Its only problem is that it doesn't have a lot of software support. BTW I got these messages (warnings?) when I ran the latest version of the script: ./armbian_rootenc_setup.sh: line 491: [: ==: unary operator expected

mmgen commented 3 years ago

Thanks, I'll put the M2 Zero on my buy list. And thanks for the error report. That was a bug in the script. I just pushed the fix to the repository.