I want to build a robot using some mini-computers like Raspberry-Pi, and using Linux OS upon. I think those boards (RPi, NanoPi, etc) have external SD card to boot OS from, and my code will go there (on SD card). So, how can I protect my code from someone who wants to copy it?

From my code, I mean my programs that are written using CMUsphinx, Opencv, etc.

Are there anyways to specify each SD card for one specified board? I mean the SD card nom.1 only runs on board nom.1.

Or maybe put a hidden code on boards and SD cards that use one algorithm and should be match to run?

  • 1
    protect from what? someone pulling out your sd card? someone connection to a wifi and stealing them from your server?
    – msrd0
    Sep 24, 2016 at 10:20
  • Someone Copying my SD card and buy a raspberry and use it! I want to know is there anyway to write a code that only runs on one specified device? I mean each SD card only runs in one specified raspberry board for example! Sep 24, 2016 at 11:21
  • there are ways of encrypting your sd card partially - which means you have to enter a specific password at boot. but keep in mind that you need at least an ssh connection to your raspberry pi to enter the password, a screen and a keyboard would work too
    – msrd0
    Sep 24, 2016 at 11:31

2 Answers 2


You can't protect someone who has physical access to the device from copying your code. If the board can read your code then so can anyone else.

To protect the code from copying, you would need to use a device which has some tamper-resistant storage. Such hardware exists, but it's in a higher price range.

You can put a test in your code to verify some hardware identifier and refuse to start if running on a different hardware device. This makes it impossible to run an exact copy directly, but it's still easy to either change the code to bypass the check or run it in a virtualized environment which feeds your code the hardware identification that it expects. Basically, it's a way to keep honest people honest but it won't deter anyone who wants to copy the code.

  • Gilles, +1. A bit confused with tamper-resistant storage that protects code from copying. How does the storage protects from copying?
    – heemayl
    Sep 24, 2016 at 19:48
  • @heemayl There are devices with tamper-resistant storage inside them: the storage and the processor are inside the same tamper-resistant enclosure, and it's difficult to access the storage without breaking the device and possibly triggering a countermeasure that wipes the storage. You probably have a few in your wallet: smartcards. In a Pi-sized device, the main storage might be outside the tamper-resistant enclosure; it's enough for the enclosure to contain enough storage some ROM code and a secret key, some RAM, and then read the encrypted application code from external storage. Sep 24, 2016 at 19:59

To protect your data you have to have key, of any sort, which you can guard and control physically and be separately from your secret data. Password in your brains is example of such solution - it is physically guarded by owner, by memorizing it.

As password there might be some visual token for your super robot, like piece of paper with barcode which decrypts your software and allows it to run that way. It may worth to consider, as same piece of paper might be used to shutdown your creation, with help of openvc and scripts of course.

Less practical but easier way to implement, is to have 2 sd cards, one contains key and is used to boot the system and waits until you change sdcard and will continue to boot after that.

you should look in to how initramfs is used to boot whole system. You should look how to create custom initramfs, and be able to modify init script for waiting and decrypting mounting your second card with main system.

System is not perfect, but dirty and cheap.

It also do not have to be initramfs solution, you might use solutions like copying your executable codes to ramdisk from some usbdrive, which you insert just for purposes to launch your creation, and remove it when it begins to be alive.

When you have secret and key on one media(is that smart trick, hidden something etc) it can be reversengineered.

As for me initramfs solution needs less effort to make, plenty of information how to make custom initramfs's.

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.