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.
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)
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:
- Windows Assessment and Deployment Kit (Windows ADK)
- Windows Driver Kit (WDK) 10
- IoT Core ADK Add-Ons
- Windows 10 IoT Core Package
- 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.
Now let’s create a workspace.
New-IoTWorkspace C:Workspacefolder oemname arm (or) new-ws C:workspacefolder oemname arm
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.
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.
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:
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.
The command shown in the image will generate a new Product in the Workspace location C:OEESource-armProductsOEEIoTCore.
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.
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
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.
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.
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.