0

Today I have a question which may be a little uncertain. How would you "port" the Linux OS to a new platform? For example; The nintendo 3ds or the PS4, are consoles which have been recently "hacked", this means you can run your own unsigned code. So basically, hackers usually port Linux to demonstrate they have full control over the software (usually this is a "Live" version of linux since they still can't sign it so even though they can write it to the NAND the bootloader won't load it, since it only runs signed code.

I guess, I may be wrong, they just get a very stripped, linux kernel source code, modify things like the video output (since PC output is completely different from those consoles obviously) and compile it with a cross-compiler for that platform (well the same one they use to compile their programs), and they create some kind of "loader" which will load the OS into memory. Actually I'm just making assumptions from what I've seen, so obviously I'm blind in lots of things.

Your help is greatly appreciated

Cheers, Pedro.

1

Your question could be split into two:

  1. How do people load a new OS on a closed platform that has been "hacked"?
  2. How is Linux ported to new systems? (your actual title)

Answers below:

  1. In order to run custom OS on a closed device, you need to somehow execute a loader code on a highest possible privilege level. What is a loader? Loader is a small program that performs initial CPU and peripherals configuration, copies some from an external memory device into memory and passes control to it. In case of Linux on game consoles, loader must copy a Linux image to memory, set boot parameters (boot device, available memory ranges — varies with the platform) and run the kernel. Usually loaders operate in privileged mode. On most CPUs with memory protection it's only enabled by OS kernel after the loader has already run.

  2. The process of porting Linux can be different depending on whether or not the processor is already supported by the kernel. If the processor is not supported, you'll need to start from the basics — implement base functions such as memory setup, context save/restore, hardware timer support and so on.

    If the processor is supported and there is a Linux kernel for a similar device, the process is a bit easier since it's likely you'll only need to implement a specific platform support — the device you plan to run Linux on likely has a power management controller, various low-speed buses (I2C, SPI) connected to sensors and controllers. Modern Linux kernels use device trees to describe the configuration of the specific platform. Device trees provide a way to instantiate existing device drivers and connect them to a specific hardware configuration.

  • Great answer @johndoe . I'll probably accept it, I just have a few questions; Can you point me to some resources that describe all that process of copying into memory, setting boot parameters etc (if it is a "teachable" thing). Also, what do you mean with "On most CPUs with memory protection it's only enabled by OS kernel after the loader has already run." What is enabled? Thanks. – Pedro Javier Fernández Nov 15 '16 at 14:20
  • @PedroJavierFernández 1. Regarding boot process: it highly depends on a hardware platform. For embedded devices, look up u-boot (in many cases it acts as a second stage bootloader after the very initial ROM code is executed by the chip). In modern PCs, UEFI firmware loads a bootloader EFI image into memory. 2. I should have worded that better. Memory protection is initially disabled and the bootloader puts the boot image to an absolute offset in memory. – John Doe Nov 15 '16 at 19:15
  • thanks. I still have some questions. 1. You are talking about a kind of bootloader (u boot) this is interesting to learn how to code your own loader, but what linux version shall it load? I'm not too much into Linux, I know there are different versions. Which one would be the one that best fits a system with small resources like those mentioned above? 2. Can you point to to some general information about how Linux works? I would like to learn about it. The aim of this comes from the question, shall I only load the Linux kernel or something else too? Since I don't know too much Im lost – Pedro Javier Fernández Nov 20 '16 at 21:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.