Create setup/ardrone2 authored by Guillaume Sanahuja's avatar Guillaume Sanahuja
# Definitions
* **original ardrone2**: UAV with stock firmware
* **modified ardrone2**: UAV with modified kernel and rootfs
* **plf** : Parrot's proprietary format to pack datas (rootfs, kernel, kernel command line, etc). This format hab been more and less reverse engineered. Tools exist to read/write plf files (they are included in robomap3)
* **ardrone2**: machine (poky definition) in robomap3; the production rootfs, we fly with it; it installs in the flash (mtd3 for rootfs, mtd1 "main_boot" for kernel)
* **ardrone2-updater**: machine (poky definition) in robomap3; allows flashing the production rootfs; it installs in the flash (mtd2 for rootfs, mtd1 "alt_boot" for kernel)
* **ardrone2-installer**: machine (poky definition) in robomap3; allows to entirely flash the system (production or updater); it is a ramfs
# Original ardrone2 memory layout
* **mtd0** : 0x000000000000-0x000000080000 : "Pbootloader" 512Ko
* **mtd1** : 0x000000080000-0x000000880000 : "Pmain_boot" 8 Mo
* **mtd2** : 0x000000880000-0x000001080000 : "Pfactory" 8Mo
* **mtd3** : 0x000001080000-0x000003080000 : "Psystem" 32 Mo
* **mtd4** : 0x000003080000-0x000008000000 : "Pupdate" 81408 Ko
**mtd1** : has 2 kernels on 2 ubifs partitions
* "main_boot" (4,1 Mo) main kernel, plf format
* "alt_boot" (2,9 Mo) alternative kernel, plf format
**mtd2** : contains some product information (mac address, serial number, etc), ubifs ("factory") mounted on */factory*
**mtd3** : rootfs, ubifs ("system") mounted on */*
**mtd4** : 2 ubifs partitions
* "update" (16.1 Mo) mounted on */update*
* "data" (59,7 Mo) mounted on */data*
**bootparams**
```
mtdparts=omap2-nand.0:512K(Pbootloader),8M(Pmain_boot),8M(Pfactory),32M(Psystem),81408K(Pupdate) console=ttyO3,115200 loglevel=4 ubi.mtd=Pfactory,2048 ubi.mtd=Psystem,2048 ubi.mtd=Pupdate,2048 root=ubi1:system rootfstype=ubifs parrot5.low_latency=1 androidboot.bootloader=ecos-bootloader-omap3630-start-65-g6a040b5
```
# Modified ardrone2 memory layout
* **mtd0** : 0x000000000000-0x000000080000 : "Pbootloader" 512Ko
* **mtd1** : 0x000000080000-0x000000880000 : "Pmain_boot" 8 Mo
* **mtd2** : 0x000000880000-0x000001080000 : "Pfactory" 8Mo
* **mtd3** : 0x000001080000-0x000008000000 : "Psystem" 114176Ko
**mtd1** : has 2 kernels on 2 ubifs partitions
* "main_boot" (4,1 Mo) production kernel (ardrone2), plf format
* "alt_boot" (2,9 Mo) updater kernel (ardrone2-updater), plf format
**mtd2** : ardrone2-updater roots
**mtd3** : 2 ubifs partitions
* "rootfs" (58 Mo) mounted on */*
* "home" (45 Mo) mounted on */home/root*
**bootparams** :
```
mtdparts=omap2-nand.0:512K(Pbootloader),8M(Pmain_boot),8M(Pfactory),114176K(Psystem) console=ttyO3,115200 loglevel=8 earlyprintk=ttyO3,115200 ubi.mtd=Pfactory,2048 ubi.mtd=Psystem,2048 root=ubi1:rootfs rootfstype=ubifs parrot5.low_latency=1 mem=80M mpurate=1000
```
# Parrot Bootloader
We do not have source code of this proprietary program. There is no open source alternative for the moment.
It could be replaced by xloader (TI) and u-boot.
By default, the bootloader loads the plf kernel from the *main_boot* partition of mtd1. To load another kernel (from the other mtd1 partition, *alt_boot*), labels of these partitions must firstly be swapped:
`# ubiattach -p /dev/mtd1` (note the ubi partition number)
`# ubirename /dev/ubix main_boot alt_boot alt_boot main_boot` (replace x by the partition number)
`# ubidetach -p /dev/mtd1`
Note that a script called *launch_update.sh* is provided in the rootfs in order to do this swap (see [update a modified adrone2 rootfs](#update-a-modified-ardrone2-rootfs)).
If the adrone2 is USB plugged to a computer, the bootloader can load and run another bootloader (see [flash an original ardrone2 with USB cable](#flash-an-original-ardrone-2-with-usb-cable)).
# Prerequisite for flashing with a USB cable
* Install a serial port communications program: cutecom, minicom, etc
* Install the x86_64 [toolchain](install-toolchains).
* *inst_usb_bootldr.bin*: Parrot proprietary bootloader, loads from USB. It allows to load from USB a plf file (kernel+bootcmd+ramfs) and to run the kernel from that plf. Get it [here](https://devel.hds.utc.fr/svn/uav_dev/trunk/bin/i686/unix/mykonos2_flash/bin/inst_usb_bootldr.bin)
* Add an udev rule for the USB connection with the adrone2 (or do the USB operations as root):
```
SUBSYSTEM=="usb", ATTRS{idVendor}=="0451", ATTRS{idProduct}=="d00e", ACTION=="add", GROUP="youruser", MODE="0664"
SUBSYSTEM=="usb", ATTRS{idVendor}=="19cf", ATTRS{idProduct}=="1111", ACTION=="add", GROUP="youruser", MODE="0664"
```
replace *youruser* by your user name.
# Flash an original ardrone2 with usb cable
Plug USB and serial (115200bps) cables, send the [ardrone2-installer](https://uav.hds.utc.fr/src/ardrone2-installer/robomap3/core-image-minimal-mtdutils-ardrone2-installer.plf) with the following commands:
`$ source /opt/robomap3/2.1.3/armv7a-neon/environment-setup-armv7a-neon-poky-linux-gnueabi`
`$ ardrone2-usbload inst_usb_bootldr.bin core-image-minimal-mtdutils-ardrone2-installer.plf`
You should get:
```
* Bootloader *
Trying to connect to VID: 0x0451 PID: 0xd000 .....
```
You can now power up the ardrone2. If everything goes well you should get:
```
* Bootloader *
Trying to connect to VID: 0x0451 PID: 0xd000 ......
Found device:
- Manufacturer: Texas Instruments
- Product: OMAP3630
Uploading parrot/mykonos2_flash/bin/inst_usb_bootldr.bin, size = 21440
Upload ok!
* Payload *
Trying to connect to VID: 0x19cf PID: 0x1111 ....
Found device:
- Manufacturer: Parrot SA
- Product: USB Stage 1
Uploading /home/poky/poky-robomap3_ros/build/tmp/deploy/images/ardrone2-installer/core-image-minimal-mtdutils-ardrone2-installer.plf, size = 7974932
Upload ok!
```
The ardrone2 will create a network interface over USB, connect to it with:
`$ ssh root@192.168.7.2`
créer les partitions pour recevoir le système hds :
`# create_partitions.sh`
copier les éléments de ardrone2-updater ([https://uav.hds.utc.fr/src/ardrone2-updater/robomap3/zImage.plf zImage.plf] et [https://uav.hds.utc.fr/src/ardrone2-updater/robomap3/core-image-minimal-mtdutils-ardrone2-updater.tar.gz core-image-minimal-mtdutils-ardrone2-updater.tar.gz]) sur le drone
flasher le updater :
{{{
# update_kernel.sh zImage.plf (doit afficher found an updater kernel)
# install_updater_rootfs.sh core-image-minimal-mtdutils-ardrone2-updater.tar.gz
}}}
copier les éléments de ardrone2 ([https://uav.hds.utc.fr/src/ardrone2/robomap3/zImage.plf zImage.plf] et [https://uav.hds.utc.fr/src/ardrone2/robomap3/core-image-flair-ardrone2.tar.bz2 core-image-flair-ardrone2.tar.bz2]) sur le drone
flasher le système :
{{{
# update_kernel.sh zImage.plf (doit afficher found a production kernel)
# flash_rootfs.sh core-image-flair-ardrone2.tar.bz2 (choisir l’option 1 : production)
}}}
reboot !
# Flash original ardrone2 without USB cable
__TODO__: retester car dernière tentive a brické le drone
Boot the original ardrone2 system and connect to it:
ssid ardrone2_011152 (last 6 numbers depends on ardrone2's serial number)
ip pc : 192.168.1.2 (given by uav's dhcp)
ip uav : 192.168.1.1
We are going to flash the updater in the mtd2 partition from original system. Then we reboot to the updater and flash the final system in the mtd3 partition.
Copy with ftp the ardrone2-installer.tar.gz, in /data/video/installer then uncompress it:
{{{
# cd /data/video/installer
# tar -xzf core-image-minimal-mtdutils-ardrone2-installer.tar.gz
}}}
Create a chroot script and execute it:
{{{
umount /factory
mount -o bind /dev /data/video/installer/dev/
mount -t sysfs sys /data/video/installer/sys/
mount -t proc proc /data/video/installer/proc/
mount devpts /data/video/installer/dev/pts -t devpts
chroot /data/video/installer /bin/sh
}}}
Copy with ftp the ardrone2-updater.plf and its kernel, in /data/video/installer then install it from the chroot:
{{{
# update_kernel.sh zImage.plf
# install_updater_rootfs.sh core-image-minimal-mtdutils-ardrone2-updater.tar.gz
}}}
Change ubi names to reboot to updater:
{{{
# ubiattach -p /dev/mtd1
# ubirename /dev/ubix main_boot alt_boot alt_boot main_boot (x donné par ubittach)
# ubidetach -p /dev/mtd1
# reboot
}}}
# Flasher ardrone2 original sans câble USB
TODO : scripter un peu plus tout ça !
se connecter en wifi au drone :
ssid ardrone2_011152 (les 6 derniers chiffres dépendent du numéro de série, voir sur l’étiquette du drone)
ip pc : 192.168.1.2 (donné par le dhcp du drone)
ip drone : 192.168.1.1
On ne peut pas flasher d’un coup le système final hds. On commence par mettre le ardrone-updater ; puis on bootera sur celui la pour installer le reste.
Copier par ftp les scripts de flashage (dans ''robomap3-rt/meta-poky/recipes-hds/ardrone-tools/ardrone2-flash-scripts'') et les outils mtd/ubi (ubiattach, ubidetach, etc). Sur le drone, les fichiers envoyés en ftp sont dans /data/video par défaut. Mettre tout ca dans /usr/bin.
copier les éléments de ardrone2-updater ([https://uav.hds.utc.fr/src/ardrone2-updater/robomap3/zImage.plf zImage.plf] et [https://uav.hds.utc.fr/src/ardrone2-updater/robomap3/core-image-minimal-mtdutils-ardrone2-updater.tar.gz core-image-minimal-mtdutils-ardrone2-updater.tar.gz]) sur le drone par ftp. Flasher le noyau et le rootfs de ardrone2-updater
{{{
# update_kernel.sh zImage.plf
# install_updater_rootfs.sh core-image-minimal-mtdutils-ardrone2-updater.tar.gz
}}}
rebooter sur le système ardrone2-updater
{{{
# ubiattach -p /dev/mtd1
# ubirename /dev/ubix main_boot alt_boot alt_boot main_boot (x donné par ubittach)
# ubidetach -p /dev/mtd1
# reboot
}}}
une fois sur le ardrone2-updater : (en port série car procédure à automatiser)
{{{
# create_partitions.sh
# flash_rootfs core-image-flair-uav-ardrone.tar.bz2
# swap kernel ubi labels
# flash_kernel.sh zImage.plf
}}}
# Mettre à jour le noyau sur adrones2 hds
{{{
# flash_kernel.sh zImage.plf
}}}
# Update a modified ardrone2 rootfs
# Tester un noyau sans le flasher (avec câble USB)
Procédure identique au flash avec câble usb. On créé ici le plf avec noyau+rootfs à mettre en ram
faire un fichier image.ini (adapter le chemin des 3 fichiers, le !EntryPoint et le !LoadAddr du zImage) :
{{{
[file]
Type=kernel
EntryPoint=0x81588004
HdrVersion=11
VersionMajor=5
VersionMinor=8
VersionBugfix=0x1b
TargetPlat=0x5
TargetAppl=0x59
HwCompatibility=0x1d400a4e
LanguageZone=0
[zImage]
LoadAddr=0x81588004
File=/home/gsanahuj/HDS/igep/ardrone2_src/linux-ardrone2-2.6.32-9/arch/arm/boot/zImage
[InitRD]
LoadAddr=0x81000000
File=/home/poky/poky-robomap3/build/tmp/deploy/images/ardrone2-installer/core-image-minimal-mtdutils-ardrone2-installer.cpio
[BootParams]
LoadAddr=0x80700000
File=/home/gsanahuj/HDS/igep/ardrone2_src_svn/trunk/linux-ardrone2-2.6.32-9/bootparams.txt
}}}
créer un plf avec le noyau et le rootfs :
{{{
# /opt/robomap3/2.1.3/armv7a-neon/sysroots/x86_64-pokysdk-linux/usr/bin/plftool -b ./image.ini -o ./image.plf
}}}
brancher le câble USB et le série (115200bps), envoyer le ardrone2-installer :
{{{
# source /opt/robomap3/2.1.3/armv7a-neon/environment-setup-armv7a-neon-poky-linux-gnueabi
# ardrone2-usbload inst_usb_bootldr.bin image.plf
}}}
une fois le programme en attente, allumer le drone
# Flasher ardrone2 briqué (avec câble USB)
suivre la procédure ardrone2 original avec câble USB.
Envoyer le ardrone2-installer par USB, puis flasher le nécessaire pour dé-briquer (normalement le noyau).
# Compiling everything from scratch
If you want to compile all by yourself:
robomap3 : https://sourcesup.renater.fr/projects/robomap3-rt/
''bitbake core-image-minimal-mtdutils'' pour la machine ardrone2-installer (se lance en ram depuis l’usb)
''bitbake core-image-minimal-mtdutils'' pour la machine ardrone2-updater (se met en flash)
''bitbake core-image-flair-uav'' pour la machine ardrone2 (se met en flash)
\ No newline at end of file