How Linux was ported to the Apple Silicon M1 Mac mini

Posted:
in macOS edited January 2021
Linux now works on the Mac mini with M1 processor -- but Apple did not make it easy for the team to port the OS with its custom firmware and unique data paths. Here's how Corellium got it done.

Firefox running on Linux Ubuntu
Firefox running on Linux Ubuntu


Now that Linux is fully usable on Macs with M1 processors the team at Corellium has detailed their process for porting the OS.

In Thursday's post, Corellium says that they have been studying Apple's custom processors since the iPhone 6 released in 2014. The company used some exploits and the previous study to build a kernel port to the A10 processor in early 2020.

Apple released the Macs with M1 processor in November 2020. A follow-on OS update enabled users to install custom kernels. Following the addition of that ability, the Corellium team began working on a Linux port.

Corellium says that the M1 shares a lot of components with Apple's A-series processors. However, that only helps insomuch that Apple doesn't use the standards set forth by other ARM manufacturers.

The Corellium team broke down the exact challenges they faced when porting Linux.

The technical details

The Corellium team says Apple doesn't boot its CPUs using traditional means. First, the bootloader runs an executable called Mach object file format (Mach-O) wrapped in a signed wrapper format called IMG4. It gets even more complicated as more CPU cores are brought up, as they start at an address specified by a Memory-mapped I/O (MMIO) register then begin running the kernel.

Apple designed its own controller that was outside the usual ARM Generic Interrupt Controller (GIC) standards. The timer interrupts are routed to the Fast Interrupt Request (FIQ), which is not standard and reflects an older 32-bit ARM system. The team says that you have to provide a set of inter-processor interrupts (IPIs) to get multiple processors to communicate.

The Corellium team had experience dealing with FIQ support and were prepared for most of Apple's non-standard approaches. In the end, the team added a pre-loader that acts as a wrapper for Linux, which led to the OS booting on the M1 processor.

The team did not have an interface cable for the M1 Mac and had to find an alternate input route. Out of the three options -- Bluetooth, the USB Host, or the xHCI USB host on PCIe -- they chose the USB host and had to interact with a chip on I2C.

After they had a proper USB connection they could connect a keyboard, mouse, and flash drive. This opened up the possibility for running a normal desktop Linux distribution.
razorpit

Comments

  • Reply 1 of 11
    rcfarcfa Posts: 1,124member
    I assume this leaves the neural processors completely unused? What about the GPU? Are graphics done just with the CPU thanks to the shared memory architecture? Or is there sufficient documentation/reverse engineering around, to allow for using that?

    Apple should just document their hardware properly, after all, they sell hardware, not software. If people want to run Linux or some other OS on their hardware shouldn’t bother them, it’s not like documenting some instruction sets and boot sequence details allows anyone to clone their chip designs or something like that; and security should never rely on obscurity, but on well documented processes.
    edited January 2021 beeble42elijahgtechconccaladanian
  • Reply 2 of 11
    A pointless intellectual exercise. You can run a full blown ARM Linux as a VM inside Parallels,VMWare  etc. 
    Rayz2016watto_cobracaladanian
  • Reply 3 of 11
    loopless said:
    A pointless intellectual exercise. You can run a full blown ARM Linux as a VM inside Parallels,VMWare  etc. 
    No, it isn't.
    A lot of people (including me) want to run Linux on the bare metal. Yes, using a VM is 'a' solution but it is not the only solution. A hypervisor (VMware etc) also requires maintenance. If you can run it on the bare metal, that's one less thing to go wrong, keep updated.

    9secondkox2auxio
  • Reply 4 of 11
    rcfa said:
    I assume this leaves the neural processors completely unused? What about the GPU? Are graphics done just with the CPU thanks to the shared memory architecture? Or is there sufficient documentation/reverse engineering around, to allow for using that?

    Apple should just document their hardware properly, after all, they sell hardware, not software. If people want to run Linux or some other OS on their hardware shouldn’t bother them, it’s not like documenting some instruction sets and boot sequence details allows anyone to clone their chip designs or something like that; and security should never rely on obscurity, but on well documented processes.
    Yeah, I was thinking the exact same thing.  Getting Linux to boot is one thing, leveraging custom components like the Neural Engine, AMX, ISP, etc. is another.  Even the GPU, how can they possibly get optimized drivers, etc?
    watto_cobracaladanian
  • Reply 5 of 11
    dewmedewme Posts: 5,391member
    rcfa said:
    I assume this leaves the neural processors completely unused? What about the GPU? Are graphics done just with the CPU thanks to the shared memory architecture? Or is there sufficient documentation/reverse engineering around, to allow for using that?

    Apple should just document their hardware properly, after all, they sell hardware, not software. If people want to run Linux or some other OS on their hardware shouldn’t bother them, it’s not like documenting some instruction sets and boot sequence details allows anyone to clone their chip designs or something like that; and security should never rely on obscurity, but on well documented processes.
    No. Apple sells systems. 

    What you’re describing is applicable to Intel and its NUCs. Apple isn’t Intel and Apple isn’t selling NUCs or anything remotely similar to a NUC. 
    rezwitsroundaboutnowwatto_cobracaladanian
  • Reply 6 of 11
    Apple wants to sell Apple devices. 

    They aren’t Microsoft trying to get their is everywhere. 

    They aren’t AMD or Intel trying to get OEMs to use their hardware. 

    They are more akin to selling embedded systems. 

    Apple hardware, software, and services all rolled into one convenient and powerful package. 

    Until Apple decides they want to provide tools for developers outside of the usual scope, The Linux team is just going to have to write from scratch if the want full M series SOC benefits. 

    Currently, this is barely a port and more like a launcher. 
    watto_cobra
  • Reply 7 of 11
    auxioauxio Posts: 2,730member
    rcfa said:
    I assume this leaves the neural processors completely unused? What about the GPU? Are graphics done just with the CPU thanks to the shared memory architecture? Or is there sufficient documentation/reverse engineering around, to allow for using that?
    This article left out the part where Corellium talked about the state of graphics:
    After working out a few more hardware quirks, and adding a pre-loader that acts as a wrapper for Linux and provides a trampoline for starting processor cores, we could set a framebuffer and were greeted with the sight of eight penguins representing the eight cores of the M1.
    So it sounds like they can show a static image on the screen, but there's still work to be done to get a full blown desktop environment (or even a terminal for that matter).  That said, if they know how to use the framebuffer, it shouldn't take too long to get CPU-based graphics up and running.  Which will be good enough for the Linux server market.
    rcaf said:
    Apple should just document their hardware properly, after all, they sell hardware, not software. If people want to run Linux or some other OS on their hardware shouldn’t bother them, it’s not like documenting some instruction sets and boot sequence details allows anyone to clone their chip designs or something like that; and security should never rely on obscurity, but on well documented processes.
    I'm sure they have everything documented internally for their engineers.  However, publishing takes time and resources.  Which Apple certainly has, but the question is where those resources are best spent.  Especially since everything shared with the Linux community will eventually make its way into Android, and thus into competing products.  I really wish I could be as idealistic about Linux as I was 20 years ago since it's a great platform for budding engineers.  But I just can't stomach seeing what's happened to it in the hands of opportunistic people who have no ethics.
    watto_cobra
  • Reply 8 of 11
    dewmedewme Posts: 5,391member
    Getting Linux running on M1 is an interesting science/hobby project but I doubt there are many people queued up and anxiously waiting for this capability. Linux runs on so many platforms already. Finding a spare computer, an inexpensive single board computer, or some disk & memory space for a VM to run Linux on is not even a trivial challenge. We all know what real people are actually waiting for - Windows on the M1.

    So the real question is: Does getting Linux running on the M1 move us any closer to getting Windows running on M1? The answer to that question is the only thing that really matters to me. The follow up question of course is if we get Windows running on M1, what does that mean for the x86 Windows apps that I need to run on it? If the answer to my second question is “none of your x86 apps will be supported” then I’m going to step out of the queue and buy a Windows PC that’s good enough to run the few x86 Windows apps I need to run. That’s not a huge burden.

    The only real sticking point I now have with the fallback of buying a “good enough” PC to handle my legacy needs, which include 4K @ 60 Hz support, is that I’m staring at the new M1 Mac Mini and realizing what a high quality beast it represents for the money. I know I can go the Intel NUC route, but I’ve worked with NUCs and they just aren’t as refined or as stable as a Mac. With M1, the performance of the lowest cost Mini rivals the higher end, fan crazy, sketchy driver, integrated graphics NUCs. Yeah, I can snatch an Intel Mini before they disappear, but the price-performance ratio (bang for the buck) pales against the M1 Mini. The M1 changed the dynamic and forever skewed my expectations. Perhaps a compromise solution is to be had from one of the newer AMD Ryzen small form factor units like the ASUS PC PN50. Who knows? But these M1 Macs, even this first round lower end offerings , have raised the bar and diminished the perceived value of a lot of competitors in the same market segment. The next round of second generation and “Pro” Apple Silicon Macs will undoubtedly do the same thing to their market segment. 
    MisterKitmuthuk_vanalingamwatto_cobra
  • Reply 9 of 11
    auxioauxio Posts: 2,730member
    dewme said:
    We all know what real people are actually waiting for - Windows on the M1.
    huh?  Aside from the latest games, I can run everything on Mac that I can on Windows.  The only industries I've found which still cling to archaic, Windows-only apps are the financial and health care industries.  Typically because they contracted a lowest bidder at some point in the past to build a custom, in-house solution that they're stuck with.  Everyone else has moved to more modern, cross-platform solutions.
    watto_cobra
  • Reply 10 of 11
    auxioauxio Posts: 2,730member
    loopless said:
    A pointless intellectual exercise. You can run a full blown ARM Linux as a VM inside Parallels,VMWare  etc. 
    No, it isn't.
    A lot of people (including me) want to run Linux on the bare metal. Yes, using a VM is 'a' solution but it is not the only solution. A hypervisor (VMware etc) also requires maintenance. If you can run it on the bare metal, that's one less thing to go wrong, keep updated. 
    Not to mention most in the Linux community want to use open source technologies.  There are open source VMs, but I don't believe any of them have been ported to M1 yet.
    watto_cobra
  • Reply 11 of 11
    dewmedewme Posts: 5,391member
    auxio said:
    dewme said:
    We all know what real people are actually waiting for - Windows on the M1.
    huh?  Aside from the latest games, I can run everything on Mac that I can on Windows.  The only industries I've found which still cling to archaic, Windows-only apps are the financial and health care industries.  Typically because they contracted a lowest bidder at some point in the past to build a custom, in-house solution that they're stuck with.  Everyone else has moved to more modern, cross-platform solutions.
    If what you're saying was true in all cases I would not need a Windows PC. But I have non-business applications that I use everyday that require Windows 10. 

    The vast majority of domain specific (vertical) applications that I have encountered in (non tactical) military/aerospace, retail automation, manufacturing, industrial automation, and industrial networking over the past 30 years are Windows based. It had nothing to do with finding the lowest bidder. It had everything to do with the availability of development resources (programmers, platforms, languages, development and deployment tools, etc.) and the availability of commodity computers to run them on, including hardened/industrialized versions of WinTel computers configured as clients, servers, desktops, and embedded. I have never seen a Mac/Apple computer used in a vertical application but I'm sure they do exist. Linux and Unix, yes, but Macs? Nope. I've used Macs for high level design and business productivity, office apps, but never deployed in a vertical application. 

    Outside of platform-specific, or in the case of Apple, brand specific enthusiast groups like AppleInsider a lot of folks see computers as simply being appliances and tools to help them do a job or perform a certain set of tasks.  The tools they need to use determines their choice of computer, not the other way around. I happen to need a Windows PC to run some of the tools I need to run. I can either stand up a Windows box, physical or virtual, to meet my need, develop the tool I need from scratch, or go without. There's nothing archaic about having to make choices.
    edited January 2021 muthuk_vanalingamseanr1
Sign In or Register to comment.