Recommended

Rooting the KORG Kronos

Disclaimer: The following file is provided without any warranties. Backup all your settings before using it - maybe you'll need to ...

Search

Dienstag, 23. Januar 2018

Playing with the Aurora LED Panels

I recently got my hands on a bunch of Nanoleaf Light Panels for a decent price. To be honest, I have been thinking about buying some for some time now, but IMHO they are quite expensive at about 20 Euros per piece.
There is a nice Teardown on EEVblog, but it stops just where things get interesting from a hacker's point of view: the communication protocol you need if you want to control the tiles yourself. I decided to reverse engineer this protocol and to document it in this post.

Physical Layer

Let's first look at the physical layer. Each tile is connected to it's neighbors via a 4 pin connector. The 4 Pins are:
  1. Power Supply (24V)
  2. Ground
  3. Select (3.3V active high)
  4. Comm (24V active low, open collector)
Pins 1, 2 and 4 are physically connected between the three connectors on the tile's edges. Pin 3 is of each edge is connected to the tile's microcontroller and can be controlled individually for each edge of the tile.

The Comm Pin

The Comm Pin is used for data communication between the tiles. It is a open collector bus which can be driven to low by any tile. The protocol must take care of collision avoidance. RS232 at 115200 Baud, 8N1 is used for the communication on this pin. Inactive level is 24V, Active level is 0V. The signal is pulled to 24V by the controller. The tiles drive the signal to GND via a open collector circuit.

The Select Pin

The Select Pin is used to enumerate the tiles and to discover topology. Usually the Select Pin is a Ground level, but it can be pulled to 3.3V for each edge of a tile separately if requested by the controller. 

Protocol on Comm Pin

The protocol on the comm pin is not too complicated. The first byte in each command is always the command type. The second byte is always the short id of the addressed tile (0xFF addresses all tiles). The rest of the bytes are the optional command payload. Some commands are followed by two bytes checksum (CRC16 CCIT). Some commands trigger a response by the addressed tile which follows immediately after the command. Some responses also are followed by a CRC16.

Short and long tile IDs

Each tile has a unique 8 Byte long ID that uniquely identifies this specific tile. This long ID is used in the enumeration phase and for topology discovery. In the enumeration phase each tile is assigned a 1 Byte short ID that from then on used to address the tile.

Commands known so far

0x01 - Assign short ID by long ID

This command is used to assign a tile a short ID if it's long ID is known. If the long ID of the tile matches the long ID in the message, the tile sets i't short ID to the short ID in the message (Byte 11) and responds. The message looks like this:
ByteExplanation
1Command Byte (0x01)
2Short ID byte (always 0xFF since addressing is done via Long ID)
3-10Long ID of addressed tile
11Short ID to be assigned to this tile
12-13CRC16 of bytes 1-11
The tile with the Long ID matching the Long ID in the message responds with 80 00 00 if present.

0x02 - Set Edge Pin

This command is used to set the Edge Pins of the addressed tile. The only payload byte is a bitmask of the levels to be set on the three Edge Pins (0x01 / 0x02 / 0x04). There is no CRC for this command.
ByteExplanation
1Command Byte (0x02)
2Short ID byte 
3Edge Pin configuration
The tile with the Short ID matching the Short ID in the message sets it's Edge Pins according to the message and responds with 80 00 00 if present.

0x03 - Read Long ID if selected

This command is used to read the long ID from a tile that is selected by pulling one of it's Edge Pins high from a neighbor tile. A tile only responds to this message if one of it's Edge Pins is pulled high from the outside.
ByteExplanation
1Command Byte (0x03)
2Short ID byte (always 0xFF since addressing is done via Edge Pin) 
The tile responds with the following sequence:
ByteExplanation
1Response Byte (0x83)
2-3Unknown
4-11Long ID of responding tile
12-13CRC16 of bytes 1-11

0x08 - Fade Tile to Color

This command is used to set the Color of a specific tile or all tiles. A fade time can be given. There is no CRC and no response for this command.
ByteExplanation
1Command Byte (0x08)
2Short ID byte (or 0xFF for all tiles)
3Red color value from 0x00 to 0xFF
4Green color value from 0x00 to 0xFF
5Blue color value from 0x00 to 0xFF
6White color value from 0x00 to 0xFF
7-8Fade time MSB first 0x0000 to 0xFFFF

0x09 - Call for unconfigured tiles

This command is used to check if new tiles have been added to the network. Only tiles which have not been assigned a short ID will respond to this command with 80 00 00. There is no CRC for command or response.
ByteExplanation
1Command Byte (0x09)
2Short ID byte (always 0xFF)

0x0A - Check tile presence

This command is used to check if a specific tiles has been removed from the network. The addressed tile will respond to the command with 80 00 00. There is no CRC for command or response.
ByteExplanation
1Command Byte (0x09)
2Short ID byte

0x0B - Set Brightness

This command is used to set the brightness of a specific tile or all tiles.
ByteExplanation
1Command Byte (0x0B)
2Short ID byte
3Brightness Value from 0x00 to 0xFF

0x0C - Read tile info

This command is used to read some version information from the tile. The version numbers are encoded in ASCII, unused bytes are set to 0x00. The addressed tile responds with its version information and the CRC.
ByteExplanation
1Command Byte (0x0C)
2Short ID byte
The tile responds with the following sequence:
ByteExplanation
1Response Byte (0x8C)
2-20Version Information
21-22CRC16 of bytes 1-20

Sonntag, 5. Juni 2016

Kronos hacking for a broader audience - Step 1: User Interface

In the last few days, the interest in this kronos hacking has increased significantly. Unfortunately this blog isn't worth much to someone without deep knowledge about Linux and other stuff. And on top of that, there is no structure since I just wrote down stuff as I researched.

Marcan (whom I deeply respect for his work on the Wii) just filled this gap with a very nice blog post that summarizes my research and adds a proper introduction for the beginners as well as some detailed background.

As he wrote in this thread, the possibility to provide feedback and to interact with the user is the foundation for a safe and clean way to bring whatever Kronos modifications we might come up with to a broader and less technical audience.

Fortunately Korg's original drivers provide some basic functionality.

The framebuffer /dev/fb1
The kernel module OmapVideoModule.ko provides a framebuffer device that interfaces the Kronos' LCD display. The resolution is 800x600 pixels and it has to be used in 8bpp palette mode. This means that you can choose up to 256 colors that can be shown on the display at the same time.

Since the display is connected to the NKS4 board, the real framebuffer is on the OMAP. This means that all changes in the fake framebuffer on the PC must be sent to the OMAP via USB. There is a special ioctl (OMAPFB_IOCTL_PIXELREGION) to trigger this update for a specific rectangle on the display. Without this ioctl, you will see nothing on the display. Unfortunately, this means that standard applications that work on /dev/fbX will not work.

There is also a ioctl to setup the palette (OMAPFB_IOCTL_PIXELREGION). Up to 256 palette entries can be populated with RGB colors.

Then, there are some less important ioctls:

  • OMAPFB_IOCTL_FILLDATA is an accelerated fill command that fills a rectangle with a specified color
  • OMAPFB_IOCTL_GETPROGRESS, OMAPFB_IOCTL_SETPROGRESS, OMAPFB_IOCTL_INCPROGRES, OMAPFB_IOCTL_ADDTOPROGRESS are helpers to draw the progress bar that you see when the Kronos is booting. This progress bar is actually handled by the OMAP so that early boot stages can increment it without knowing about graphics.
  • OMAPFB_IOCTL_INITLCDREGS, OMAPFB_IOCTL_XAXISBYTESIZE can be used to configure the LCD configuration registers in the OMAP. As the OMAP configures those registers independently of the PC when showing the title screen, we do not need to do that.
  • OMAPFB_IOCTL_GETTITLESCREENVERSION returns some version number that is probably used by the updater to determine where to draw it's messages so that they look nice with different versions of the OMAP software.
The keypad /proc/OmapNKS4
The kernel module OmapNKS4.ko creates a proc file that can be used to read part of the control surface (Keys 0-9, Enter, Exit and the scrollwheel). The interface is ugly - you can only read one keypress each time you open the file, but at least it works...

A demo application
I have hacked together a simple demo that shows working framebuffer and control surface access here. If you read through the source, you'll find definitions and wrapper for the ioctls and the keypad interface.



Dienstag, 31. Mai 2016

Kronos encrypted file systems

Korg uses Cryptoloop to hide the important parts of it's Kronos firmware from prying eyes. The mount mechanism is somewhat obfuscated and hidden in loadmod.ko and loadoa. Here is a brief description:
  1. loadoa loads the kernel module loadmod.ko
  2. loadmod.ko replaces the kernel's mount syscall with it's own implementation (but only if filesystem check, kernel check and communication with the security chip are ok).
  3. loadmod.ko reads and decrypts /.pairFact3 to retrieve the Cryptoloop keys. The Cryptoloop keys are the same for all devices, but the keys to decrypt /.pairFact3 are individual for each device. When you "authorize" your Kronos, you actually get the Cryptoloop keys encrypted with your individual device keys.
  4. loadoa mounts issues a mount command that looks like this:
    /bin/mount -n -t ignoreType ignoreDev /korg/rw/PCM/WaveMotion
  5. loadmod.ko gets the syscall and recognizes the "magic" mount point name (/korg/rw/PCM/WaveMotion). Now it initializes the Cryptoloop device and calls the kernel's normal mount syscall handler to mount the loop device.
Now, it would be nice to have the Cryptoloop keys for the encrypted file systems inside the Kronos firmware. You can easily extract the encrypted files from the Kronos firmware updates published by Korg. If we just had the keys, we could mount and examine them on any PC around.

The possibility to boot our own kernel helps a lot, here. One could just add some printk() to a function that handles the cryptoloop keys (for example loop_set_status).

This is the kernel patch. Let's see what happens...

loop_set_status(0): lo_file_name=/korg/ro/Eva.img lo_encrypt_type=18 lo_crypt_name=aes lo_encrypt_key=342ee59d549c7d329d835537be0540d
loop_set_status(1): lo_file_name=/korg/ro/WaveMotion.img lo_encrypt_type=18 lo_crypt_name=aes lo_encrypt_key=3e72c0e59fc017a9eb7d7e1168a4cdb
loop_set_status(2): lo_file_name=/korg/ro/Mod.img lo_encrypt_type=18 lo_crypt_name=aes lo_encrypt_key=a336a15cd841ec8926b99e7c3884eaa


Crazy keys

Looking at struct loop_info64 it is pretty clear that the simple printk("... lo_encrypt_key=%s ...", status->lo_encrypt_key) should not have worked. lo_encrypt_key should be binary, not a null terminated string!

Someone had no real clue about how to use loop_set_status() and used 31 (plus a \0 byte for string termination) hex digits (containing only 124 bits of information) as AES256 key.

I am still wondering if this is just a stupid mistake or just one more strange obfuscation. 

Montag, 23. Mai 2016

A short look into the past: OASYS

The Kronos' history actually began more than ten years ago with the OASYS. Back then, when the OASYS was released, I really wanted to have one, but I also really could not afford it. So I decided to hack other stuff and kind of forgot about the OASYS.

Now, ten years later, I got the chance to look into the architecture and the software of the OASYS and the similarities to the Kronos are astonishing. The architecture is almost the same and I would be tempted to say that the Kronos is in fact a "OASYS Lite V2".

Why "Lite"? Because the Kronos misses many expensive parts (LEDs around knobs/sliders, trigger buttons, large screen, CD drive, ...). It looks like the goal set for the Kronos product engineering was to build a more affordable version of the OASYS (which makes perfect sence, if you look at the price tag of the OASYS).

Why "V2"? Because the Kronos has some features (more engines, sample streaming) that the OASYS lacks. I am wondering why Korg did not upgrade the OASYS software to include those features. Maybe hardware limitations were the reason. The OASYS has no SSD, so disk access latency might be the reason there is no sample streaming. Also, the OASYS has a single core CPU (Pentium 4) while the Kronos has a dual core (Atom). It would be interesting to benchmark the single core P4 against the dual core Atom... (Update: Comparison between OASYS and Kronos CPUs. Looks like the P4 is faster in single core workloads, but the Atom is faster in multi core workloads. A synthesizer is almost a perfect multi core workload, so the Kronos is in fact more powerful than the OASYS).

However, the software and hardware architecture between OASYS and Kronos are so similar that most articles in this blog are - to a certain degree - also valid for the OASYS.

Here are - in no particular order - some things I noticed while comparing OASYS and Kronos:


  • Both use Linux with RTAI realtime extensions. However, OASYS uses Linux 2.4, Kronos uses Linux 2.6
  • Security stuff (filesystem integrity check, security ic, authorization file) is almost identical
  • The OASYS uses the VGA output of the mainboard for it's display while the Kronos uses a display connected to the OMAP. This means that the Kronos has to transfer all display data over USB. I am unsure why they did this - the Kronos mainboard also has a VGA connector, but it is unused.
  • In the OASYS the whole control surface (including the keybed) is connected via USB. On the Kronos, the keybed is connected to the mainboard via RS232 - the rest of the controls are still connected via USB. Maybe latency reduction?
  • The OASYS uses a custom PCI sound card while the Kronos uses a custom USB sound card for Audio/Midi I/O
Looking at all this, I am wondering why Korg sticks to meaningless upgrades like different colors or different end-plates for it's new/special editions. How about a bigger screen, LEDs for knobs and sliders and some pressure sensitive drum pads? Add a decent mainboard for increased polyphony and call it "platinum edition". KORG, are you listening???



Donnerstag, 5. Mai 2016

Streamlining the Kronos boot process / what does loadmod.ko do?

I have already sched some light on the Kronos boot process in an older article (What does /sbin/loadoa do?). There you can see that a kernel module called "loadmod.ko" is loaded just before the encrypted loop files are mounted.

loadmod.ko plays a vital role in booting the Kronos and is the center of Korg's attempts to protect the Kronos from hacking.

So, what does loadmod.ko do?


  1. First, loadmod.ko performs a file system integrity check. It opens and reads a lot of files and hashes them using MD5. The hash is then compared to a constant value encoded in loadmod.ko. If the values do not match, loadmod.ko will bail out with error code 1.
  2. Next, the Linux kernel is checked. loadmod.ko calls the functions register_cdrom() and init_cdrom_command() with some magic values. A normal Linux kernel will just return error codes because the parameters make no sense. The Linux kernel delivered by Korg has modified versions of this functions that return other magic values to signal loadmod.ko that the kernel is "genuine".

    Korg has not published the source code for those modifications to the Linux kernel even though they are distributing a binary version of Linux with those modifications. This is a clear violation of the GPL.

    You can find a more detailed description of the kernel authentication mechanism in About the Linux kernel used in KORG Kronos.

    I provide a patch that reimplements the modified register_cdrom()/init_cdrom_command() functions here. With this patch you can compile your own kernel that will be accepted by loadmod.ko.

    If the kernel check fails, loadmod.ko will bail out with error code 3.
  3. After filesystem and kernel have been checked, loadmod.ko tries to read the authorization file called "pairFact". This file contains the encryption keys for the encrypted file systems in the Kronos (detailed explanation). If loadmod.ko cannot read that authorization data, it will bail
    out with error code 4.
  4. The contents of "pairFact" are encrypted with a key stored in the security IC. So, the next step for loadmod.ko is to talk to the security IC (the primitives for the communication are provided by OmapNKS4Module.ko. The Public ID of the Kronos is read and the key needed to decrypt the authorization data is read. If communication with the security IC fails, loadmod.ko will bail out with error code 5.
  5. If all checks were successful, a magic value (0x22FB39CC) is stored at a certain address in kernel memory. This magic value will be checked by the synthesizer module (OA.ko) later. If it is not there, OA.ko will skip some important initializations which will cause the sound output to be bad. So even if you do not need loadmod.ko anymore because you have copied the synthesizer files out of the encrypted file systems, you still need to run loadmod.ko (or at least write this magic value) to have useful sound output.
  6. The error code (or zero if there were no errors) from the checks above is written to "/tmp/stgStatus". This is used by /sbin/loadoa to display a more or less useful error message (or the reauthentication screen) if one of the integrity checks failed.
  7. Now, things are getting crazy: loadmod.ko replaces some of the kernel's syscalls by overwriting sys_call_table. The following syscalls are overwritten: sys_mount, sys_ioctl, sys_oldumount, sys_umount, sys_create_module, sys_init_module.

    The syscalls sys_mount and sys_oldumount are replaced with versions that "magically" mount a cryptoloop filesystem if one of the magic paths (/korg/Eva, /korg/Mod, /korg/WaveMotion) is mounted.

    The other syscall replacements don't do anything but call the original handlers. It looks like Korg wanted to prevent users from loading additional modules (maybe to prevent access to the kernel memory), but that mechanism was not finished.
  8. Finally, a kernel thread is started. This kernel thread will handle system updates by listening on /proc/.update and running /sbin/UpdateOS or /tmp/UpdateOS as a usermode helper if necessary.


So, why is that interesting?

From a users point of view, loadmod.ko doesn't do many useful things. The filesystem integrity checks take precious boot time and prevent you from changing your file system. The encrypted loop file systems also degrade system performance and you can easily copy their contents onto the unencrypted file system, 

However, if you decide to save boot time and trouble by getting rid of loadmod.ko, you still have to write the magic value or else the Kronos' sound will be crippled.

I have updated my kernel patches and my precompiled kernel to do that, Using this kernel, you do not need to load loadmod.ko. You can get rid of the filesystem/kernel integrity check and still OA.ko will work perfectly.



Samstag, 2. April 2016

Kronos Polyphony and Performance

As explained in many discussions, the Kronos has no fixed polyphony. The number of sounding voices differs depending on the engine used for each voice and even depending on which effects are currently active.

But how does the sound engine know how many voices can be active? 

The answer is a file called CostProfile in /korg/rw/Startup on your Kronos (this file is not included in the filesystem integrity check, so you can modify this file via FTP/SCP after rooting your Kronos. In this file, the resource cost is stored for each engine and for each effect. The engine uses this file to constantly keep track of the current resource usage. As soon as there are not enough resources for all voices and effects that should be running, some algorithm carefully selects the least audible voices and drops them to make room for new (probably more audible voices).

So, if you upgrade the CPU power of your synthesizer, you still need to patch CostProfile to get increased polyphony. I have prepared a CostProfile for my hardware upgrade here. The proposed setup has enough power to archive 200 note polyphony across all engines and regardless of the active effects,

Patching CostProfile to reduce the resource cost on the original main board (i.e. without additional CPU power) leads to some interesting behavior when too many voices are triggered: instead of stuttering and/or clicking, single voices drop out at random. This is because of a second mechanism called EmergencyVoiceStealer that seems to just drop one or more voices as a last measure to prevent a complete audio dropout. It looks like Korg spent a lot of effort to make sure there are no hard audio dropouts. Wow!

Finally, there is a hard limit of 200 voices. This limit is probably a #define in the synthesizer source code and was set arbitrarily by Korg.

Freitag, 1. April 2016

Precompiled kernel for the Kronos with XHCI support

If you want to roll your own hardware upgrade, and don't want to dive into the details of compiling the Linux kernel, use this precompiled Kronos-compatible kernel with XHCI support.

The kernel was compiled from the ingredients explained here. All patches applied to the Linux kernel 2.6.32.11 to compile the binary linked above are available here.

Update (April 3rd 2016):

  • Enabled IPv6 in kernel config (required for Intel NIC drivers)
  • Fixed problem with selecting OA.ko's heap memory size (orig_mem_size)
  • Driver modules for both Intel NICs on the Supermicro X11SSV-Q (Compiled from e1000e-3.3.3.tar and igb-5.3.4.4.tar.gz).
Driver Modules for Intel NICs on Supermicro X11SSV-Q (extract to /lib/modules/2.6.32.11-korg)

Update (May 5th 2016):

  • Added magic value to register_cdrom() so that OA.ko still works properly if loadmod.ko was not loaded.


Have fun!

Montag, 28. März 2016

Kronos Keybed Communication

While most knobs, buttons and LEDs on the Kronos are connected to the OMAP , the Keybed with the two switches SW1/SW2 and the Pitch Bend Controller "Joystick" are connected to the PC Mainboard.

The communication between Keybed and PC works via the PC's serial port COM1. This serial port is provided by a 16550A compatible UART inside the mainboard's Super-IO chip (Winbond W83627).

The Keybed sends short (1-4 bytes) commands to the PC when keys are pressed or the analog joystick is moved.

There are some oddities:

  • The serial baud rate is 62500 bits/s.
  • The voltage levels between keybed and PC don't match: The PC is using RS232 levels (-10V/+10V) and the keybed is using TTL levels (0V/+5V). It is a strange thing that the connection even works under those circumstances.
  • The synthesizer kernel module (OA.ko) completely bypasses the kernel's serial driver. There is a minimal serial driver embedded in OA.ko
  • The UART baud rate generator is not used with it's default clock of 1.8461 MHz but with an alternative clock of 24 MHz. The baud rate generator clock is switched using the configuration registers of the Super-IO chip. This is also done by OA.ko.
  • OA.ko also reads the ChipID register of the W83627 and refuses to start if this specific Super-IO chip is not present.
Update: The Kronos 2 mainboard (ASRock IMB-140) has a different Super-IO chip: the NCT6627UD. This is a brother of the NCT6776 which is used on my brand new Supermicro X11SSV-Q. The registers required to configure and use the first UART (COM1) are identical on both chips.


Montag, 29. Februar 2016

More power for the Kronos

Let's assume I'd want to replace the Kronos mainboard with something a little more state-of-the-art. Maybe cost is not my main concern (Kronos was expensive enough, a few more spent bucks don't really matter).

Here are some thoughts:

  • Mainboard should be Mini-ITX to fit into the Kronos
  • CPU must support at least the Intel Atom instruction set (Kronos binaries are optimized for Atom)
  • There is no point in having more than 4 GB RAM since OA.ko and the other proprietary kernel modules are 32 Bit only. Update: 8 GB RAM will allow the kernel and userspace applications to live in high memory while OA can use almost all of the low memory. This will squeeze out 200-300 extra MBs of sample memory.
  • There is no point in having more than 2 CPU cores since the signal processing chain is optimized for 2 cores. Each CPU core should be as fast as possible to archive maximum signal processing performance.
  • Hardware needs at least one USB port to connect the NKS4 module (probably not hard).
  • Hardware needs a RS232 port to connect the Keybed, should be 16550 compatible (might be problematic, because most modern mainboards have no serial ports anymore)
Here is what I came up with:
Obstacles to overcome (updated again):
  • Skylake chipsets are XHCI only. XHCI-Driver in Kernel 2.6.32 does not support isochronous transfers. Solved by backporting a newer XHCI-Driver.
  • Memory map is not continuous. There are holes for ACPI NVS. Problematic with KORG's way of allocating the synthesizer's heap in ioremapped memory. Solved by setting TOLUD (Top Of Low Usable DRAM) in BIOS settings to 3.5 GB. ACPI stuff is then out of the way.
  • SuperIO-Driver embedded in OA.ko for serial port doesn't work (no keybed yet). Works with the latest OA.ko versions since SuperIO-Chip in Kronos 2 is similar to the one on the X11SSV-Q. Connection cable inside Kronos needs some soldering since the supermicro board has a SUB-D connector and no pin-header for RS232.
  • Kernel 2.6.32 does not support the ethernet MACs on the SX11SSV-Q. Not a real problem since the mainboard's ethernet connection is unused in the original Kronos design. Backporting a driver from a newer kernel should be possible. Intel provides drivers for both NICs that compile as modules against 2.6.32-11. Get prebuilt modules here.
Results (updated):
  • Kronos boot time < 20s
  • 200 voice polyphony accross all engines (even STR-1 and MS-20). 
  • Total cost: ~ $520


Sonntag, 28. Februar 2016

Need help from experienced Kronos users

I am working on a way to increase the Kronos' performance (polyphony, simulatneous effects, boot time, etc.) significantly. To test the effectivity and reliability of my modifications, I need some test cases.

Ideally, you could provide me configuration examples that drive the Kronos into it's limits. The limitations (e.g. voice stealing, missing effects, etc.) should be easy to hear. I cannot rely on the Kronos' performance meters.

Please leave your examples in the comments or contact me via mail (kronoshacking@gmail.com).

Sneak preview:



Thanks!

Samstag, 12. September 2015

Compiling a Linux kernel for the KORG Kronos

It is not a secret that the KORG Kronos is running Linux with RTAI extensions.

To understand how the Kronos software works and also for development of custom software, it would certainly be useful to be able to compile our own kernel that loads and runs KORG's proprietary modules and the Kronos software.

The Version Magic String of the kernel distributed with the Kronos is "2.6.32.11-korg SMP preempt mod_unload ATOM". Futhermore, /proc/version tells us that the kernel was compiled using GCC 4.5.0.

Let us have a look at the kernel log output related to RTAI:
RTAI[hal]: <3.8.1> mounted over IPIPE-NOTHREADS 2.6-03.
RTAI[hal]: compiled with gcc version 4.5.0 (GCC) .
RTAI[hal]: mounted (IPIPE-NOTHREADS, IMMEDIATE (INTERNAL IRQs VECTORED), ISOL_CPUS_MASK: 0).
RTAI[malloc]: global heap size = 2097152 bytes, <BSD>.
RTAI[sched]: IMMEDIATE, MP, USER/KERNEL SPACE: <with RTAI OWN KTASKs>, <uses LINUX SYSCALLs>, kstacks pool size = 524288 bytes.
RTAI[sched]: hard timer type/freq = APIC/10416873(Hz); default timing: periodic; linear timed lists.
RTAI[sched]: Linux timer freq = 1000 (Hz), TimeBase freq = 1666440000 hz.
RTAI[sched]: timer setup = 999 ns, resched latency = 2944 ns.

Since the kernel and RTAI are distributed under the GPL, KORG should deliver all sources necessary to build the kernel together with the compiled binary file (or include a written offer to send the sources on request).

In some documentation, it says that the sources for GPLed code would ship on "Accessory Disk 2". 

Since KORG is distributing the compiled Linux kernel online in the Kronos Firmware Update downloads, the Kernel sources should also be available online. I have not been able to find them, so this is probably a GPL violation.

Since I have bought a Kronos, I also own the Accessory Disks and - indeed - on Accessory Disk 2, there are the sources for the Linux kernel version 2.6.32.11 and RTAI 3.8.1 together with two patches (scroll to the bottom of this post to see the patches in detail).

If you do not have the Accessory Disks, the sources are of course also available for download:


So, we should have everything to build our own kernel for the Kronos, right?

Unfortunately, we are still missing one crucial part of information: the kernel configuration. Usually, this configuration is compiled into the kernel and available under /proc/config.gz, but KORG has disabled that feature. So, we need to find the kernel configuration by trial and error. It is important to get this right if you want to load the proprietary modules from KORG. The rely on sizes of data structures that may differ if the kernel configuration differs. In that case, the system will behave strange and/or just crash.

Download the kernel configuration I have found by trial and error here. It is not perfect, but matches close enough.

Now, we can boot our own kernel on the synthesizer. But something is strange - the proprietary modules will not load. loadmod.ko which is supposed to mount the encrypted loop filesystems with the synthesizer software just errors out. I have already explained the reason for that behavior.

What KORG did here is a clear violation of the Linux kernel's software license - the GPL. All sources necessary to build the software must be made available with the distributed binary.

To remedy this problem (I really want my own kernel on my Kronos), I have developed a set of patches that imitate the behaviour of the kernel distributed by KORG close enough, so that loadmod.ko works:

hal-linux-2.6.32.11-x86-2.6-03.patch
This patch is taken directly and unmodified out of the RTAI archive (RTAI 3.8.1). It implements lots of changes and hooks that the RTAI modules need to integrate themselves into the kernel.

kronos-provide-meminfo.patch
This patch exports two symbols (orig_mem_size and orig_mem_start). orig_mem_size is used by OA.ko (the actual synthesizer running in kernel mode) to determine how much memory is available on the system. This is important because OA.ko bypasses the kernel's dynamic memory management by ioremapping physical memory that is not used by the kernel.

kronos-cryptostuff.patch
This patch implements some cryptographic helpers that KORG hid inside the generic cdrom driver. Those functions are used by loadmod.ko to calculate the keys required to the security IC. If they are not implemented properly in the kernel, loadmod.ko cannot read the secret per-device key that is used to decrypt the authorization file (detailed explanation).

kronos-export-do_generic_file_read.patch
This patch exports do_generic_file_read() which is required by KORG's proprietary modules.

kronos-fix-kconfigs.patch
This patch enables FB_DEFERED_IO which is required by KORG's framebuffer driver (the Kronos' screen is actually a framebuffer which is sent to the OMAP via USB). Also it enables support for the legacy firewire driver which is used by KORG, but masked by BROKEN in the kernel.

kronos-backport-xhci-driver.patch
This patch backports the XHCI driver from a later kernel version as the experimental driver in 2.6.32.11 does not support isochronous transfers (which are required by the NKS4 board).
The patch is required only if you want to upgrade your synthesizer with a XHCI-only mainboard.

kronos-increase-mlock-limit.patch
Eva (the userspace part of the Kronos firmware responsible for the UI) communicates with OA.ko (the kernel part of the Kronos firmware) via mmapped memory ranges. This patch removes the kernel's default limit on mmapped memory to accommodate Eva's requirements.

kronos-kernel-config.patch
This patch replaces the stock .config (kernel configuration file) with the kernel config I researched for the Kronos. There are some small additions (USB debugging, XHCI support) that do not forfeit binary compatibility between Korg's proprietary kernel modules and the compiled kernel.

KorgHwmonPermsPatch
This patch is actually published by Korg on their rescue CD. Changes permissions for hardware sensor access.

load_module_patch
This patch is actually published by Korg on their rescue CD. Patches module loading to trade memory usage for system startup time.

The latest set of patches (2016-04-02) is available here.

Using those patches, you can now compile your own bzImage for the Kronos and use it as a starting point for your own development. Have fun!

Donnerstag, 3. September 2015

Installing EXs using '/sbin/InstallEXs' form the command line

Installing EXs files is not done by Eva (the userspace GUI) or OA (the kernel engine). Instead, Eva calls a helper binary: /sbin/InstallEXs If you have installed the extensions for ssh access to your Kronos, you can also run the helper directly. Use the following syntax:
/sbin/InstallEXs -m VFAT -t disk -f exins-file -p exs-directory
where disk is 0 for install on first SSD or 1 for install on second SSD exins-file is the name of the install info file (without path name) exs-directory is the directory where the EXs files are located
An example:
# /sbin/InstallEXs -m VFAT -t 0 -f EXs13.exsins -p /mnt/usbdisk0/EXs13/
InstallEXs will now count to 100 (this is the percentage shown in the GUI). After the installation is finished, there is debug info in /tmp/installer_debug.

Samstag, 13. Juni 2015

Rooting the KORG Kronos

Disclaimer:

The following file is provided without any warranties. Backup all your settings before using it - maybe you'll need to reinstall your Kronos. You might even break it beyond repair (unlikely). Whatever happens - you are responsible - I am not liable in any way. Everything you do, you do on your own risk!

After the update, you can login into your Kronos as "root" and look around. The update also installs a busybox for your convinience. Be careful and do not change anything or you will likely end up with a non-bootable system.


How to install:
  1. Make sure that your Kronos is updated to software version 3.0.2
  2. Copy the files in the archive on a USB drive - just like a real update
  3. Insert the USB drive into the Kronos and start the update process
  4. Wait until the update is reported as successful
  5. Power cycle the Kronos
How to access your Kronos:
  1. Connect a compatible USB network adapter (or use the mainboard's ethernet connector).
  2. Set a FTP password in the settings
  3. Make sure the network settings are correct and look up the IP address of your Kronos
  4. Use ssh/scp/putty/winscp/... to connect as user "root" with the passwort set in the network settings as FTP password
Have fun!


Filesystem Integrity Check by loadmod.ko

When the Kronos is booting, the contents of the following files is hashed (MD5). The MD5 sum is compared to a static value compiled into loadmod.ko. If the values do not match, loadmod.ko will bail out. Do not change the files in this list on your Kronos or it will not boot anymore!

/
/bin
/bin/sync
/bin/awk
/bin/touch
/bin/grep
/bin/test
/bin/ls
/bin/mount
/bin/cut
/bin/setterm
/bin/gzip
/bin/echo
/bin/false
/bin/dc
/bin/stat
/bin/chown
/bin/mv
/bin/bash
/bin/bar
/bin/dd
/bin/cp
/bin/RunGrub.sh
/bin/env
/bin/tar
/bin/fanctrld
/bin/usleep
/bin/sed
/bin/vmstat
/bin/kill
/bin/gawk
/bin/ipcalc
/bin/sleep
/bin/umount
/bin/hostname
/bin/df
/bin/ShowReauthScreen
/bin/expr
/bin/date
/bin/vi
/bin/rm
/bin/mkdir
/bin/chmod
/bin/true
/bin/cat
/bin/sh
/bin/uname
/sbin
/sbin/ifconfig
/sbin/OmapNKS4Module.ko
/sbin/init
/sbin/insmod.static
/sbin/loadoa
/sbin/e2fsck
/sbin/hwclock
/sbin/dhclient-script
/sbin/insmod
/sbin/killall5
/sbin/MIDID
/sbin/GetPubIdMod.ko
/sbin/dosfsck
/sbin/hdparm
/sbin/modprobe
/sbin/shutdown
/sbin/grub
/sbin/UpdateOS
/sbin/mkswap
/sbin/iptables
/sbin/sysctl
/sbin/ip
/sbin/ifup.lite
/sbin/loadmod.ko
/sbin/tune2fs
/sbin/arping
/sbin/rmmod
/sbin/poweroff
/sbin/losetup
/sbin/runlevel
/sbin/reboot
/sbin/swapoff
/sbin/mke2fs
/sbin/ifdown.lite
/sbin/swapon
/sbin/halt
/sbin/pidof
/sbin/OmapVideoModule.ko
/sbin/STGEnabler.ko
/etc
/etc/sysconfig
/etc/sysconfig/network
/etc/sysconfig/network-scripts
/etc/sysconfig/network-scripts/ifcfg-eth0
/etc/sysconfig/network-scripts/ifcfg-lo
/etc/modprobe.conf
/etc/sysctl.conf
/etc/OA.rc
/etc/ld.so.conf
/etc/mtab
/etc/OA.si
/etc/inittab
/etc/fstab
/sys
/korg
/korg/ro
/korg/Eva
/korg/rw
/korg/Mod
/tmp
/mnt
/var
/usr
/usr/realtime
/usr/realtime/modules
/usr/realtime/modules/rtai_hal.ko
/usr/realtime/modules/rtai_fifos.ko
/usr/realtime/modules/rtai_sched.ko
/usr/realtime/modules/rtai_sem.ko
/usr/realtime/modules/rtai_ndbg.ko
/usr/realtime/modules/rtai_smp.ko
/usr/share
/usr/share/fonts
/usr/share/fonts/truetype
/usr/share/fonts/truetype/Arialbd.ttf
/usr/share/fonts/truetype/Geneva.ttf
/usr/share/fonts/truetype/Arial.ttf
/usr/share/fonts/truetype/Geneva_Bold.ttf
/usr/share/terminfo
/usr/share/terminfo/a
/usr/share/terminfo/a/ansi
/usr/share/terminfo/l
/usr/share/terminfo/l/linux
/boot
/dev
/lib
/lib/libcrypto.so.6
/lib/libresolv.so.2
/lib/modules
/lib/modules/2.6.32.11-korg
/lib/modules/2.6.32.11-korg/modules.pcimap
/lib/modules/2.6.32.11-korg/modules.dep
/lib/modules/2.6.32.11-korg/modules.inputmap
/lib/modules/2.6.32.11-korg/modules.ofmap
/lib/modules/2.6.32.11-korg/modules.ieee1394map
/lib/modules/2.6.32.11-korg/modules.usbmap
/lib/modules/2.6.32.11-korg/kernel
/lib/modules/2.6.32.11-korg/kernel/drivers
/lib/modules/2.6.32.11-korg/kernel/drivers/net
/lib/modules/2.6.32.11-korg/kernel/drivers/net/mii.ko
/lib/modules/2.6.32.11-korg/kernel/drivers/net/r8169.ko
/lib/modules/2.6.32.11-korg/kernel/drivers/scsi
/lib/modules/2.6.32.11-korg/kernel/drivers/scsi/scsi_wait_scan.ko
/lib/modules/2.6.32.11-korg/modules.isapnpmap
/lib/modules/2.6.32.11-korg/modules.ccwmap
/lib/modules/2.6.32.11-korg/source
/lib/modules/2.6.32.11-korg/modules.order
/lib/modules/2.6.32.11-korg/modules.seriomap
/lib/modules/2.6.32.11-korg/build
/lib/modules/2.6.32.11-korg/modules.symbols
/lib/modules/2.6.32.11-korg/modules.alias
/lib/libcom_err.so.2
/lib/ld-linux.so.2
/lib/libfreetype.so.6
/lib/libtinfo.so.5
/lib/libsepol.so.1
/lib/libext2fs.so.2
/lib/libattr.so.1
/lib/libdl.so.2
/lib/libpcre.so.0
/lib/libgssapi_krb5.so.2
/lib/libaudit.so.0
/lib/libpthread.so.0
/lib/libe2p.so.2
/lib/libstdc++.so.6
/lib/libgmp.so.10
/lib/libkrb5support.so.0
/lib/libselinux.so.1
/lib/librt.so.1
/lib/libz.so.1
/lib/libsysfs.so.2
/lib/libkrb5.so.3
/lib/libc.so.6
/lib/libblkid.so.1
/lib/libm.so.6
/lib/libncurses.so.5
/lib/libpopt.so.0
/lib/libssl.so.6
/lib/libkeyutils.so.1
/lib/libproc-3.2.7.so
/lib/libk5crypto.so.3
/lib/libuuid.so.1
/lib/libacl.so.1
/lib/libgcc_s.so.1
/lib/libdevmapper.so.1.02
/proc

The anatomy of a Kronos firmware update

The ZIP file contains some files that should be copied to a USB stick which is to be inserted into the Kronos. Let's have a look at the files:

bc
X86 32 Bit Linux Binary - a calculator

md5sum
X86 32 Bit Linux Binary - calculates MD5 checksums of files

DisplayUpdaterMessage
X86 32 Bit Linux Binary - opens a linux frame buffer device (/dev/fb1) that represents the Kronos' display (managed by the OMAP).

install.info
Holds information about the update itself. This is the first file that the Kronos reads when updating. Contains references to 3 other files (KRONOS_Update_3_0_2.tar.gz, pretar.sh, posttar.sh) and a signature.

The signature is the SHA1 of the following data (concatenated in the mentioned order):

  • the contents of the pretar script (if given in the install.info)
  • the contents of the posttar script (if given in the install.info)
  • the following 16 "magic bytes": 13h, D0h, AFh, EFh, E0h, 3Ch, 9Bh, 92h, 16h, 2Fh, AEh, FFh, 77h, 53h, 55h, E1h

The updater (UpdateOS) will only accept the update if the signature in install.info is correct.

pretar.sh
A shell script (bash) that is called in the upgrade progress before the actual firmware is extracted. This script does the following things:


  • Call DisplayUpdaterMessage to show "Verifying install media..."
  • Call md5sum to calculate the MD5-Checksum of "KRONOS_Update_3_0_2.tar.gz" and compare it to a known value
  • Call md5sum to calculate the MD5-Checksum of "DisplayUpdaterMessage" and compare it to a known value (pointless since DisplayUpdaterMessage has already been called before)
  • Call md5sum to calculate the MD5-Checksum of "bc" and compare it to a known value
  • Make sure (via kill and kill -9) that the following processes are not running: vsftpd, avahi-daemon, messagebus, ifplugd
  • Make sure that the date is at least 1.12.2014

posttar.sh
A shell script (bash) that is called in the upgrade progress after the actual firmware is extracted. This script checks all extracted files' checkusms against the checksums stored in "KRONOS_Update_3_0_2.csum". It displays a progress bar by using "bc" to calulate the percentage of finished files and writing it to "writing to /proc/OmapNKS4ProgressBar"

KRONOS_Update_3_0_2.tar.gz
Contains the Kronos' root file system. This is the acutal firmware update. I will look into it and explain it's contents later in this post.

KRONOS_Update_3_0_2.csum
Contains checksums for all files in "KRONOS_Update_3_0_2.tar.gz". Used by posttar.sh to make sure that the firmware update was properly installed

Mittwoch, 3. Juni 2015

And one more GPL violation: vsftpd

The FTP service on the KORG Kronos is actually a vsftpd. Parts of the configuration have been patched into the binary. Here is part of the output of "strings vsftpd":
/SSD1
/korg/rw/HD%s/%s
/SSD2
/korg/rw2/HD%s/%s
/korg/ftp/%s
/korg/rw/HD
According to vsftpd's website, vsftp is licensed under the GPL. However, the changed sources for vsftpd are not provided on the recovery DVD. There is also no written offer to deliver the sources on request. This makes vsftpd the third GPL violation inside the Kronos...


Freitag, 29. Mai 2015

Another GPL violation: loadmod.ko / STGGmp.ko

The KORG Kronos software contains yet another GPL violation in the proprietary kernel module loadmod.ko that is delivered with the recovery images on the support page.

The module is statically linked with the gmplib that is distributed under GPL/LGPL dual licensing. KORG does not provide the source code for loadmod.ko as required by the GPL.

In newer firmware versions, gmplib is no longer included in loadmod.ko, but in a different module called STGGmp.ko. So it looks like KORG is aware of the licensing problem but does not fix their old binaries.

Update: The statically linking version of loadmod.ko was not present in firmware version 3.0.2. It was then again distributed with firmware version 3.0.3. On 2015-12-25 firmware version 3.0.3 was replaced with a firmware that is internally branded as 3.0.3B - the only change between 3.0.3 and 3.0.3B was to replace the statically linking loadmod.ko with the dynamically linking version.


What does /sbin/loadoa do?

=== increment progress ===
fopen("/proc/progress")
fscanf("%d")
add 1
fprintf("%d")
fflush()
fclose()

=== load modules (1st batch) ===
/sbin/insmod /usr/realtime/modules/rtai_hal.ko
/sbin/insmod /usr/realtime/modules/rtai_smp.ko
/sbin/insmod /usr/realtime/modules/rtai_sem.ko
/sbin/insmod /usr/realtime/modules/rtai_ndbg.ko
/sbin/insmod /usr/realtime/modules/rtai_fifos.ko

/sbin/insmod /sbin/STGEnabler.ko
/sbin/insmod /sbin/STGGmp.ko


=== set smp affinity ===
search "ehci_hcd" in /proc/interrupts
write '4' to "/proc/irq/%d/smp_affinity"


=== load modules (2nd batch) ===
/sbin/insmod /sbin/OmapNKS4Module.ko
/sbin/insmod /sbin/OmapVideoModule.ko
/sbin/insmod /sbin/GetPubIdMod.ko
/sbin/insmod /sbin/loadmod.ko


=== check if STG modules are alive ===
open /tmp/stgStatus
check if value is '1'


=== mount crypto FS (1st batch) ===
/bin/mount -n -t ignoreType ignoreDev /korg/rw/PCM/WaveMotion > /dev/null
/bin/mount -n -t ignoreType ignoreDev /korg/Mod > /dev/null

=== load modules (3rd batch, from cryptoFS) ===
/sbin/insmod /korg/Mod/KorgUsbAudioDriver.ko
/sbin/insmod /sbin/USBMidiAccessory.ko

=== fork ===
fork()
 => child stays and will update /proc/progress

parent writes progress child PID to "/tmp/progress.pid":
fopen("/tmp/progress.pid")
fprintf("%d")
fflush()
fclose()

=== mount 2nd disk if present ===
call "Has2ndInternalDisk":
 ls /sys/block | grep sdb
 udevinfo -a -p /sys/block/sdb | grep DRIVERS | grep usb

mount -t ext3 -o commit=1,noatime /dev/sdb1 /korg/rw2
mv -f /korg/rw2/Options/* /korg/rw/Options
mount --bind /korg/rw/HD /korg/ftp/SSD1

=== load modules (4th bath, from cryptoFS) ===
/sbin/insmod /korg/Mod/OA.ko Has2ndInternalDisk=?

=== mount more stuff ===
/bin/umount -n /korg/Mod
/bin/mount -n -t ignoreType ignoreDev /korg/Eva > /dev/null
/bin/mount -n -t ignoreType ignoreDev /korg/rw/PCM/WaveMotion > /dev/null

=== run fanctrld ===
/bin/fanctrld > /dev/null

=== run Eva ===
/korg/Eva/Eva > /dev/null

Why do you need to "authorize" your Synthesizer?

When you "authorize" your Kronos (for example after recovery), the authorization file actually contains the crypto keys necessary to access proprietary kernel modules, the actual synthesizer software and some "WaveMotion" data.

The keys are not there in plain, but encrypted with another key that is stored in the Kronos' security chip. The encryption key is probably different for each device so that one authorization file is only valid for one synth.

To access the security chip, you need a different key (see authorization and encryption in the AT88's datasheet) which is calculated from the Public ID and some magic numbers in the driver module.

So, when you "authorize" your Kronos, you get the crypto keys to access to the synthesizer software on it.

Donnerstag, 28. Mai 2015

Notes from inside the Kronos - Part II: The OMAP (NKS4)






The AM1806B is connected to the Kronos' PC as a USB 2.0 Device. It is used as an I/O helper for the PC with (at least) the following tasks:
  • LCD Display Interface - the OMAP exports it's display interface via USB to the PC where one of KORG's proprietary drivers installs it as a framebuffer device. So the contents you see on the display are (except for the startup screen) rendered by the PC and sent to the OMAP via USB.
  • Touch Screen Interface
  • Audio Interface(s) and audio mixing / routing
  • MIDI Interfaces(s)
  • Interface to the PSOC which handles the mechanical user interface
  • Interface to the Security IC
  • USB Device Interface (The Kronos' USB Host Ports are provided by the Intel Mainboard)
  • Effects processing. Probably the OMAP handles the IFX and MFX (to be confirmed...) there is no effect processing on the OMAP. All effect processing is done on the PC.
So, one could say, that the OMAP is a very fancy sound card for the Kronos' Intel mainboard - nothing more - nothing less. There is a software update available from KORG which probably contains the OMAPs firmware.

The OMAP is often referred as "NKS4".