Raspberry PI SD Card Provisioning with Windows 10 IoT Core 

If you've installed Windows 10 IoT Core OS on your Raspberry Pi, make sure you learn next about SD Card Provisioning and how to set up your Raspberry PIs for a production environment.

Sibeesh Venu
A Raspberry PI Card
Illustration: © IoT For All

In my previous article, we’ve seen how to Set Up Your Raspberry PI with Microsoft Windows 10 IoT Core. Yes, we were successful in flashing the Microsoft Windows 10 IoT Core OS to our Raspberry PI, but let’s try something very handy this time. The main topic we’re going to discuss here  is SD Card Provisioning. Let’s say you have a Raspberry PI with a working OS on it, whether it’s a Microsoft IoT OS or Raspbian. And you might also have an application which runs on your Raspberry Pi. That’s good. But what if you have 100 Raspberry PIs and you need to set up your Raspberry PIs for a production environment? In this article, we’re going to start a series of articles on SD Card Provisioning. For now, let’s just start doing some amazing things.

Background

I’m glad that you have a Raspberry PI with Windows 10 IoT core OS. While setting up your OS, you might have downloaded the IoT Dashboard and flashed the IoT OS to your SD card manually. As I mentioned in the introduction, this isn’t a normal scenario when you want to connect multiple (let’s say 100) Raspberry PIs. Flashing the OS by using the Dashboard application might not be a good idea in this case. What should we do, then? That’s where PowerShell comes into play. We’re going to try out some PowerShell commands to do all those mentioned jobs for us.

(Above: Raspberry PI)

Prerequisites

First, we always need some prerequisites. You can see all the prerequisites here. In this part, we’re only going to need the following tools:


    1. Windows Assessment and Deployment Kit (Windows ADK)
    2. Windows Driver Kit (WDK) 10
    3. IoT Core ADK Add-Ons
    4. Windows 10 IoT Core Package
    5. The Raspberry Pi BSP

Creating the Base Windows IoT FFU Image

I assume that you’ve already gone through the Prerequisites and followed the instructions. If not, please check again.

Create a Workspace

To get started, please go to the cloned location of the repository iot-adk-addonkit, where you will find a Windows Command Script IoTCorePShell.cmd. Double click on the same file and it will open a PowerShell with administrative privilege. Now, this is where the game starts. Once it opens, it will do some initial processes for us.

Running IoTCorePShell.cmd

Now let’s create a workspace.

New-IoTWorkspace C:Workspacefolder oemname arm
(or) new-ws C:workspacefolder oemname arm
new-ws command

Now we’ve successfully created a workspace. Please note that the BSPPKG_DIR is “C:Program Files (x86)Windows Kits10MSPackagesretailarmfre”. I strongly recommend you to check if you have the contents in the folder. If not, you might not have installed the packages mentioned in the prerequisites.

Build BSP

Now it’s time to think about the BSP, aka the Board Support Package. Since we’re using a Raspberry PI, we can directly download the RPi_BSP.zip file from the GitHub release page. Then you can perform the below commands.

Import-IoTBSP RPi2 C:DownloadsRPi_BSP.zip
(or) importbsp RPi2 C:DownloadsRPi_BSP.zip
buildpkg RPi2

If everything is correct, you should see an output like the one below.

Import Raspberry BSP

Build Packages

Once you’ve created the workspace and extracted the BSP, it’s time to build all of our packages.

New-IoTCabPackage All
(or) buildpkg all

If you miss this step before you go to the next step, you will get an error when you build your image like the one below.

info: Trying to load file 'C:OEEWorkspaceBuildarmInputFMsOEMFMFileList.xml' as a FM file list ... fatal error : Error: Missing package: C:OEEWorkspaceBuildarmpkgstest.OEM.Sample.cab
info: Trying to load file 'C:OEEWorkspaceBuildarmInputFMsRPi2FMFileList.xml' as a FM file list ... fatal error : Error: Missing package:

You will also end up with an issue similar to this one: GitHub issue. Trust me, finding the root cause of this issue took me some hours and, at the end, I provided my findings here in StackOverflow.

Building all the packages

Once the build is successful, you should be able to see the cab files in your workspace location, in my case, it’s in C:OEEBuildarmpkgs.

Create a Product

Now, let’s create a new Product; consider this the device we’re building an image for. We’ll be using the BSP we have extracted for this step.

Add-IoTProduct ProductA RPi2
(or) newproduct MyProductA RPi2

You’ll be asked the Manufacturer Name (OEM Name), Family, SKU, BaseboardManufacturer and BaseboardProduct. You can get the BaseProductName from your Workspace location, in my case, C:OEESource-armBSP. You can see the sample command here in the preceding image.

Creating a new Product

The command shown in the image will generate a new Product in the Workspace location C:OEESource-armProductsOEEIoTCore.

Add-IoTProduct Output

Build the Image

We’re almost done, so let’s eject all the removable devices from the system and then run the below command.

New-IoTFFUImage <product name> Test
(or)buildimage <product name> Test

This command will give you the FFU image with your base image.

Building Image and Generate FFU File

You can also see the logs in your workspace location in the build folder. The generated FFU image(Flash.ffu) will be available at C:OEEBuildarmOEEIoTCoreTest folder.

Writing/Flashing the FFU Image to an SD Card

Now that we have a fully functional FFU image and the only thing left is to write some bat commands to flash it to SD card, which you can do using the DISM. Let’s create a text file called format.txt and write some commands like the following.

select disk 1
clean
create partition primary
select partition 1
active
format fs=fat32 quick
assign
exit

We’re selecting disk 1, considering the fact that only one removable disk has been connected to your machine. Then we format the disk. This format.txt file will be used in our bat file write.bat.

echo off
REM Start formatting
diskpart /s format.txt >log.txt
REM Start flashing
dism.exe /Apply-Image /ImageFile:Flash.ffu /ApplyDrive:.PhysicalDrive1 /SkipPlatformCheck /Quiet
ECHO Finish

The logs will be added to the file called log.txt. The command ImageFile:Flash.ffu is the place where we assign our FFU image. Let’s go to the folder where these three files have been placed and open a command prompt in administrative power.

  • write.bat
  • format.txt
  • flash.ffu
Flash IoT Core by Commands

Connect SD Card to Raspberry PI and Then Raspberry PI to the Network

Now that our OS is flashed, it’s time to connect the SD card to the Raspberry PI and connect a monitor, mouse, keyboard and ethernet to the Raspberry PI. You will see the default IoT core application running. You can also check in the device portal using the IoT Dashboard application. If you’re not sure how, please read my previous post.

Conclusion

Now we have learned:

  • How to generate the IoT core FFU image using PowerShell
  • How to write this to an SD card.

In the next article we’ll learn:

  • How to add our app package to an FFU image which can be used on many Raspberry PIs.
  • How to generate an FFU image on-demand with some chained PowerShell commands.
  • How to use other mechanisms to write the FFU image to the disk.
Author
Sibeesh Venu
Sibeesh Venu
An engineer by profession and writer by passion. I love programming and have a strong relationship with C#, Asp.Net, Asp.Net Core, Web Api, Angular, Node JS, SQL, Mongo DB, Azure, JavaScript. I don't like the personality of Vb.Net, so my answer wa...
An engineer by profession and writer by passion. I love programming and have a strong relationship with C#, Asp.Net, Asp.Net Core, Web Api, Angular, Node JS, SQL, Mongo DB, Azure, JavaScript. I don't like the personality of Vb.Net, so my answer wa...