├── .gitignore ├── snap ├── hooks │ └── configure └── gui │ └── icon.png ├── configs ├── cmdline.txt └── config.txt ├── gadget.yaml ├── uboot.patch ├── README.md ├── uboot.env.in └── snapcraft.yaml /.gitignore: -------------------------------------------------------------------------------- 1 | parts/ 2 | prime/ 3 | stage/ 4 | pi3_*.snap 5 | -------------------------------------------------------------------------------- /snap/hooks/configure: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # do nothing for now 4 | -------------------------------------------------------------------------------- /snap/gui/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/canonical/pi3-gadget/HEAD/snap/gui/icon.png -------------------------------------------------------------------------------- /configs/cmdline.txt: -------------------------------------------------------------------------------- 1 | dwc_otg.lpm_enable=0 console=ttyS0,115200 console=tty0 elevator=deadline rng_core.default_quality=700 2 | -------------------------------------------------------------------------------- /gadget.yaml: -------------------------------------------------------------------------------- 1 | device-tree: bcm2710-rpi-3-b.dtb 2 | volumes: 3 | pi3: 4 | schema: mbr 5 | bootloader: u-boot 6 | structure: 7 | - type: 0C 8 | filesystem: vfat 9 | filesystem-label: system-boot 10 | size: 128M 11 | content: 12 | - source: boot-assets/ 13 | target: / 14 | -------------------------------------------------------------------------------- /uboot.patch: -------------------------------------------------------------------------------- 1 | diff --git a/include/configs/rpi.h b/include/configs/rpi.h 2 | index 9ce41767a9..fbec105a11 100644 3 | --- a/include/configs/rpi.h 4 | +++ b/include/configs/rpi.h 5 | @@ -71,9 +71,14 @@ 6 | #define CONFIG_SYS_CBSIZE 1024 7 | 8 | /* Environment */ 9 | -#define CONFIG_ENV_SIZE SZ_16K 10 | +#define CONFIG_ENV_SIZE SZ_128K 11 | #define CONFIG_SYS_LOAD_ADDR 0x1000000 12 | -#define CONFIG_PREBOOT "usb start" 13 | +#define CONFIG_SYS_REDUNDAND_ENVIRONMENT 14 | +/* Load environment from USB if no SD card */ 15 | +#define CONFIG_PREBOOT "usb start; if test ! \"mmc dev 0\"; then " \ 16 | + "fatload usb 0:1 0x3000000 "CONFIG_ENV_FAT_FILE"; " \ 17 | + "env import -b 0x3000000; " \ 18 | + "fi;" 19 | 20 | /* Shell */ 21 | 22 | @@ -81,6 +86,7 @@ 23 | #define CONFIG_SETUP_MEMORY_TAGS 24 | #define CONFIG_CMDLINE_TAG 25 | #define CONFIG_INITRD_TAG 26 | +#define CONFIG_SUPPORT_RAW_INITRD 27 | 28 | /* Environment */ 29 | #define ENV_DEVICE_SETTINGS \ 30 | -------------------------------------------------------------------------------- /configs/config.txt: -------------------------------------------------------------------------------- 1 | # For more options and information see 2 | # http://www.raspberrypi.org/documentation/configuration/config-txt.md 3 | # Some settings may impact device functionality. See link above for details 4 | 5 | kernel=uboot.bin 6 | 7 | # uncomment if you get no picture on HDMI for a default "safe" mode 8 | #hdmi_safe=1 9 | 10 | # uncomment this if your display has a black border of unused pixels visible 11 | # and your display can output without overscan 12 | #disable_overscan=1 13 | 14 | # uncomment the following to adjust overscan. Use positive numbers if console 15 | # goes off screen, and negative if there is too much border 16 | #overscan_left=16 17 | #overscan_right=16 18 | #overscan_top=16 19 | #overscan_bottom=16 20 | 21 | # uncomment to force a console size. By default it will be display's size minus 22 | # overscan. 23 | #framebuffer_width=1280 24 | #framebuffer_height=720 25 | 26 | # uncomment if hdmi display is not detected and composite is being output 27 | #hdmi_force_hotplug=1 28 | 29 | # uncomment to force a specific HDMI mode (this will force VGA) 30 | #hdmi_group=1 31 | #hdmi_mode=1 32 | 33 | # uncomment to force a HDMI mode rather than DVI. This can make audio work in 34 | # DMT (computer monitor) modes 35 | #hdmi_drive=2 36 | 37 | # uncomment to increase signal to HDMI, if you have interference, blanking, or 38 | # no display 39 | #config_hdmi_boost=4 40 | 41 | # uncomment for composite PAL 42 | #sdtv_mode=2 43 | 44 | #uncomment to overclock the arm. 700 MHz is the default. 45 | #arm_freq=800 46 | 47 | dtparam=i2c_arm=on 48 | dtparam=i2c_vc=on 49 | #i2s=on 50 | dtparam=spi=on 51 | dtparam=act_led_trigger=heartbeat 52 | dtparam=pwr_led_trigger=mmc0 53 | dtparam=audio=on 54 | 55 | device_tree_address=0x02000000 56 | core_freq=250 57 | enable_uart=1 58 | 59 | dtoverlay=vc4-kms-v3d 60 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Raspberry Pi 3 Gadget Snap 2 | 3 | This repository contains the source for an Ubuntu Core gadget snap for the Raspberry Pi 3. 4 | 5 | Building it with snapcraft will automatically pull, configure, patch and build 6 | the git.denx.de/u-boot.git upstream source for rpi_3_32b_defconfig at release v2017.05, 7 | produce a u-boot.bin binary and put it inside the gadget. 8 | 9 | It will then download the latest stable binary boot firmware 10 | from https://github.com/raspberrypi/firmware/tree/stable/boot and add it to the gadget. 11 | 12 | Last it will pull the latest linux-image-raspi2 from the xenial-updates archive, extract the 13 | devicetree and overlay files from it and add them to the gadget as well. 14 | 15 | 16 | ## Gadget Snaps 17 | 18 | Gadget snaps are a special type of snaps that contain device specific support 19 | code and data. You can read more about them in the snapd wiki 20 | https://github.com/snapcore/snapd/wiki/Gadget-snap 21 | 22 | ## Reporting Issues 23 | 24 | Please report all issues on the Launchpad project page 25 | https://bugs.launchpad.net/snap-pi3/+filebug 26 | 27 | We use Launchpad to track issues as this allows us to coordinate multiple 28 | projects better than what is available with Github issues. 29 | 30 | ## Building 31 | 32 | To build the gadget snap locally on an armhf system please use `snapcraft`. 33 | 34 | To cross build this gadget snap on a PC please run `snapcraft --target-arch=armhf` 35 | 36 | ## Launchpad Mirror and Automatic Builds. 37 | 38 | All commits from the master branch of https://github.com/snapcore/pi3 are 39 | automatically mirrored by Launchpad to the https://launchpad.net/snap-pi3 40 | project. 41 | 42 | The master branch is automatically built from the launchpad mirror and 43 | published into the snap store to the edge channel. 44 | 45 | You can find build history and other controls here: 46 | https://code.launchpad.net/~canonical-foundations/+snap/pi3 47 | -------------------------------------------------------------------------------- /uboot.env.in: -------------------------------------------------------------------------------- 1 | arch=arm 2 | baudrate=115200 3 | boot_a_script=load ${devtype} ${devnum}:${bootpart} ${scriptaddr} ${prefix}${script}; source ${scriptaddr} 4 | boot_extlinux=sysboot ${devtype} ${devnum}:${bootpart} any ${scriptaddr} ${prefix}extlinux/extlinux.conf 5 | boot_prefixes=/ /boot/ 6 | boot_script_dhcp=boot.scr.uimg 7 | boot_scripts=boot.scr.uimg boot.scr 8 | boot_targets=mmc usb pxe dhcp 9 | bootcmd=run distro_bootcmd 10 | bootcmd_dhcp=usb start; if dhcp ${scriptaddr} ${boot_script_dhcp}; then source ${scriptaddr}; fi 11 | bootcmd_mmc=setenv devnum 0; run dev_boot 12 | bootcmd_pxe=usb start; dhcp; if pxe get; then pxe boot; fi 13 | bootcmd_usb=setenv devnum 0; usb start; run dev_boot 14 | bootdelay=2 15 | bootenv=uEnv.txt 16 | cpu=armv7 17 | devnum=0 18 | devtype=mmc 19 | dhcpuboot=usb start; dhcp u-boot.uimg; bootm 20 | distro_bootcmd=for target in ${boot_targets}; do run bootcmd_${target}; done 21 | fdt_addr_r=0x00000100 22 | fdtaddr=0x02000000 23 | fdtfile=bcm2709-rpi-2-b.dtb 24 | filesize=1c5 25 | importbootenv=echo Importing environment from ${target} ...; env import -t -r $loadaddr $filesize 26 | initrd_addr=0x02100000 27 | initrd_file=initrd.img 28 | kernel_addr_r=0x01000000 29 | kernel_file=kernel.img 30 | loadaddr=0x00200000 31 | loadbootenv=echo LOADBOOTENV; load ${devtype} ${devnum} ${loadaddr} ${bootenv} 32 | loadfdt=fdt addr 0x02000000; fdt get value args /chosen bootargs 33 | loadfiles=run loadkernel; run loadinitrd; run loadfdt 34 | loadinitrd=load ${target} ${devnumber}:${partition} ${initrd_addr} ${snap_kernel}/${initrd_file}; setenv initrd_size ${filesize} 35 | loadkernel=load ${target} ${devnumber}:${partition} ${loadaddr} ${snap_kernel}/${kernel_file} 36 | dev_boot=if ${target} dev ${devnum}; then setenv devtype ${target}; if run loadbootenv; then echo Loaded environment from ${bootenv}; run importbootenv; fi; if test -n "$uenvcmd"; then echo Running uenvcmd ...; run uenvcmd; fi; run scan_dev_for_boot_part; fi 37 | allargs=setenv bootargs "${args} root=${devroot}" 38 | devnumber=0 39 | partition=1 40 | mmcrootfstype=ext4 41 | pxefile_addr_r=0x00100000 42 | ramdisk_addr_r=0x02100000 43 | scan_dev_for_boot=echo Scanning ${devtype} ${devnum}:${bootpart}...; for prefix in ${boot_prefixes}; do run scan_dev_for_extlinux; run scan_dev_for_scripts; done 44 | scan_dev_for_boot_part=part list ${devtype} ${devnum} devplist; for bootpart in ${devplist}; do if fstype ${devtype} ${devnum}:${bootpart} bootfstype; then run scan_dev_for_boot; fi; done 45 | scan_dev_for_extlinux=if test -e ${devtype} ${devnum}:${bootpart} ${prefix}extlinux/extlinux.conf; then echo Found ${prefix}extlinux/extlinux.conf; run boot_extlinux; echo SCRIPT FAILED: continuing...; fi 46 | scan_dev_for_scripts=for script in ${boot_scripts}; do if test -e ${devtype} ${devnum}:${bootpart} ${prefix}${script}; then echo Found U-Boot script ${prefix}${script}; run boot_a_script; echo SCRIPT FAILED: continuing...; fi; done 47 | scriptaddr=0x00000000 48 | snappy_boot=if test "${snap_mode}" = "try"; then setenv snap_mode "trying"; saveenv; if test "${snap_try_core}" != ""; then setenv snap_core "${snap_try_core}"; fi; if test "${snap_try_kernel}" != ""; then setenv snap_kernel "${snap_try_kernel}"; fi; elif test "${snap_mode}" = "trying"; then setenv snap_mode ""; saveenv; fi; run loadfiles; setenv devroot "/dev/disk/by-label/writable ${snappy_cmdline} snap_core=${snap_core} snap_kernel=${snap_kernel}"; run allargs; bootz ${loadaddr} ${initrd_addr}:${initrd_size} 0x02000000 49 | snappy_cmdline=net.ifnames=0 init=/lib/systemd/systemd ro panic=-1 fixrtc 50 | snappy_mode= 51 | soc=bcm2835 52 | stderr=serial,lcd 53 | stdin=serial,usbkbd 54 | stdout=serial,lcd 55 | uenvcmd=echo ENVCMD; run snappy_boot 56 | vendor=raspberrypi 57 | -------------------------------------------------------------------------------- /snapcraft.yaml: -------------------------------------------------------------------------------- 1 | name: pi3 2 | version: 16.04-0.7 3 | summary: Raspberry Pi 3 support package 4 | description: | 5 | Support files for booting Raspberry Pi 6 | type: gadget 7 | architectures: 8 | - armhf 9 | confinement: strict 10 | grade: stable 11 | parts: 12 | uboot: 13 | plugin: nil 14 | source: git://git.denx.de/u-boot.git 15 | source-branch: v2019.04 16 | prepare: | 17 | git apply ../../../uboot.patch 18 | make rpi_3_32b_defconfig 19 | build: | 20 | if [ "$(arch)" = "x86_64" ]; then 21 | CROSS_COMPILE=arm-linux-gnueabihf- make 22 | else 23 | make 24 | fi 25 | install: | 26 | mkdir -p $SNAPCRAFT_PART_INSTALL/boot-assets 27 | cp u-boot.bin $SNAPCRAFT_PART_INSTALL/boot-assets/uboot.bin 28 | tools/mkenvimage -r -s 131072 -o $SNAPCRAFT_PART_INSTALL/uboot.env ../../../uboot.env.in 29 | ln -s uboot.env $SNAPCRAFT_PART_INSTALL/uboot.conf 30 | build-packages: 31 | - bc 32 | - bison 33 | - build-essential 34 | - device-tree-compiler 35 | - flex 36 | - libpython2.7-dev 37 | - python-minimal 38 | - on amd64 to armhf: 39 | - gcc-arm-linux-gnueabihf:amd64 40 | boot-firmware: 41 | plugin: nil 42 | source: . 43 | after: 44 | - uboot 45 | prepare: | 46 | git clone --depth=1 https://github.com/raspberrypi/firmware.git -b "1.20190215" 47 | install: | 48 | mkdir -p $SNAPCRAFT_PART_INSTALL/boot-assets 49 | for file in fixup start bootcode LICENCE COPYING; do 50 | cp firmware/boot/${file}* $SNAPCRAFT_PART_INSTALL/boot-assets 51 | done 52 | configs: 53 | plugin: dump 54 | source: configs 55 | after: 56 | - boot-firmware 57 | organize: 58 | config.txt: boot-assets/config.txt 59 | cmdline.txt: boot-assets/cmdline.txt 60 | devicetrees: 61 | plugin: nil 62 | source: . 63 | after: 64 | - configs 65 | prepare: | 66 | PACKAGES="http://ports.ubuntu.com/ubuntu-ports/dists/xenial-updates/universe/binary-armhf/Packages.gz" 67 | PKGPATH="$(wget -q -O- $PACKAGES|zcat|grep-dctrl linux-raspi2 |\ 68 | grep linux-modules|grep Filename|tail -1| sed 's/^Filename: //')" 69 | wget http://ports.ubuntu.com/ubuntu-ports/$PKGPATH 70 | dpkg -x $(basename $PKGPATH) unpack/ 71 | install: | 72 | mkdir -p $SNAPCRAFT_PART_INSTALL/boot-assets 73 | cp -a unpack/lib/firmware/*/device-tree/* $SNAPCRAFT_PART_INSTALL/boot-assets 74 | rm -rf unpack 75 | build-packages: 76 | - coreutils 77 | - dctrl-tools 78 | - sed 79 | - wget 80 | 81 | slots: 82 | bcm-gpio-0: 83 | interface: gpio 84 | number: 0 85 | bcm-gpio-1: 86 | interface: gpio 87 | number: 1 88 | bcm-gpio-2: 89 | interface: gpio 90 | number: 2 91 | bcm-gpio-3: 92 | interface: gpio 93 | number: 3 94 | bcm-gpio-4: 95 | interface: gpio 96 | number: 4 97 | bcm-gpio-5: 98 | interface: gpio 99 | number: 5 100 | bcm-gpio-6: 101 | interface: gpio 102 | number: 6 103 | bcm-gpio-7: 104 | interface: gpio 105 | number: 7 106 | bcm-gpio-8: 107 | interface: gpio 108 | number: 8 109 | bcm-gpio-9: 110 | interface: gpio 111 | number: 9 112 | bcm-gpio-10: 113 | interface: gpio 114 | number: 10 115 | bcm-gpio-11: 116 | interface: gpio 117 | number: 11 118 | bcm-gpio-12: 119 | interface: gpio 120 | number: 12 121 | bcm-gpio-13: 122 | interface: gpio 123 | number: 13 124 | bcm-gpio-14: 125 | interface: gpio 126 | number: 14 127 | bcm-gpio-15: 128 | interface: gpio 129 | number: 15 130 | bcm-gpio-16: 131 | interface: gpio 132 | number: 16 133 | bcm-gpio-17: 134 | interface: gpio 135 | number: 17 136 | bcm-gpio-18: 137 | interface: gpio 138 | number: 18 139 | bcm-gpio-19: 140 | interface: gpio 141 | number: 19 142 | bcm-gpio-20: 143 | interface: gpio 144 | number: 20 145 | bcm-gpio-21: 146 | interface: gpio 147 | number: 21 148 | bcm-gpio-22: 149 | interface: gpio 150 | number: 22 151 | bcm-gpio-23: 152 | interface: gpio 153 | number: 23 154 | bcm-gpio-24: 155 | interface: gpio 156 | number: 24 157 | bcm-gpio-25: 158 | interface: gpio 159 | number: 25 160 | bcm-gpio-26: 161 | interface: gpio 162 | number: 26 163 | bcm-gpio-27: 164 | interface: gpio 165 | number: 27 166 | i2c-0: 167 | interface: i2c 168 | path: /dev/i2c-0 169 | i2c-1: 170 | interface: i2c 171 | path: /dev/i2c-1 172 | i2c-2: 173 | interface: i2c 174 | path: /dev/i2c-2 175 | bt-serial: 176 | interface: serial-port 177 | path: /dev/ttyAMA0 178 | spidev0: 179 | interface: spi 180 | path: /dev/spidev0.0 181 | spidev1: 182 | interface: spi 183 | path: /dev/spidev0.1 184 | --------------------------------------------------------------------------------