{# device_type: juno #}
{% extends 'base-uboot.jinja2' %}

{% set console_device = console_device | default('ttyAMA0') %}
{% set baud_rate = baud_rate | default('115200') %}
{% set juno_kernel_args = 'ip=dhcp rw rootwait earlycon=pl011,0x7ff80000 debug systemd.log_target=null user_debug=31 androidboot.hardware=juno loglevel=9' %}

{% set uboot_initrd_high = '0xffffffffffffffff' %}
{% set uboot_fdt_high = '0xffffffffffffffff' %}

{% set base_uboot_commands_juno_extras =
"          - setenv bootdelay 1
          - setenv ethact smc911x-0" -%}

{% set base_load_commands = load_commands | default(
"          - setenv loadkernel 'afs load ${kernel_name} {KERNEL_ADDR}'
          - setenv loadfdt 'afs load ${fdtfile} {DTB_ADDR} ; fdt addr {DTB_ADDR}; fdt resize'
          - setenv loadinitrd 'afs load ${initrd_name} {RAMDISK_ADDR}; setenv initrd_param {RAMDISK_ADDR}'") -%}

{% block body %}

board_id: '{{ board_id|default('0000000000') }}'
usb_vendor_id: '{{ usb_vendor_id|default('0000') }}'
usb_product_id: '{{ usb_product_id|default('0000') }}'
usb_filesystem_label: '{{ usb_filesystem_label|default('JUNO') }}'

{% block parameters -%}
parameters:
  booti:
    kernel: '{{ booti_kernel_addr|default('0x80080000') }}'
    ramdisk: '{{ booti_ramdisk_addr|default('0x84000000') }}'
    dtb: '{{ booti_dtb_addr|default('0x83000000') }}'
  interfaces:
{% if device_ip or device_mac %}
    target:
      ip: {{ device_ip|default('') }}
      mac: '{{ device_mac|default('') }}'
{% endif %}
{% if interfaces %}
{% for interface in interfaces %}
    {{ interface }}:
      sysfs: "{{ sysfs.get(interface) }}"
      mac: "{{ mac_addr.get(interface) }}"
{% for switch, port in map.get(interface).items() %}
      switch: "{{ switch }}"
      port: {{ port }}
{% endfor %}
      tags:
{% if tags.get(interface) %}
{% for tag in tags.get(interface) %}
      - {{ tag }}
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
  media:  # four USB slots.
    usb:
      UUID-required: True
      {{ usb_label|default('SanDisk_Ultra') }}:
        uuid: "{{ usb_uuid }}"
        device_id: {{ usb_device_id|default(0) }}  # the bootloader device id for this media on the 'usb' interface
{% endblock parameters -%}

actions:
  deploy:
    parameters:
      mkimage_arch: arm64
      add_header: u-boot
    # list of deployment methods which this device supports
    methods:
      lxc:
      nfs:
      tftp:
      usb:
      ssh:
        options:
{{ ssh_options }}
        host: '{{ ssh_host|default('') }}'
        user: {{ ssh_user|default('root') }}
        port: {{ ssh_port|default(22) }}
        identity_file: {{ ssh_identity_file }}
      vemsd:
        parameters:
          mcc_prompt: '{{ mcc_prompt|default('Cmd>') }}'
          msd_mount_cmd: '{{ msd_mount_cmd|default('usb_on') }}'
          flash_prompt: '{{ flash_prompt|default('Flash>') }}'
          flash_enter_cmd: '{{ flash_enter_cmd|default('flash') }}'
          flash_erase_cmd: '{{ flash_erase_cmd|default('eraseall') }}'
          flash_erase_msg: '{{ flash_erase_msg|default('Erasing Flash') }}'
          flash_exit_cmd: '{{ flash_exit_cmd|default('exit') }}'
          autorun_prompt: '{{ autorun_prompt|default('Press Enter to stop auto boot...') }}'
    connections:
      adb:
      lxc:
      serial:
  boot:
    # list of connection methods which this device supports
    connections:
      adb:
      lxc:
      serial:
      ssh:
    # list of boot methods which this device supports.
    methods:
      lxc:
      ssh:
      u-boot:
        parameters:
          bootloader_prompt: VExpress64
          boot_message: {{ boot_message|default('Linux version') }}
          mkimage_arch: arm64
        ramdisk-local:
          commands:
{{ base_uboot_commands }}
{{ base_uboot_commands_juno_extras }}
          - setenv fdtfile board.dtb
          - setenv initrd_name ramdisk.img
          - setenv kernel_name norkern
{{ base_load_commands }}
          - setenv bootargs 'console={{ console_device }},{{ baud_rate }}n8 root=/dev/sda2 {{ juno_kernel_args }}'
{{ base_uboot_bootcmd }}
        nfs-local:
          commands:
{{ base_uboot_commands }}
{{ base_uboot_commands_juno_extras }}
          - setenv fdtfile board.dtb
          - setenv initrd_name ramdisk.img
          - setenv kernel_name norkern
{{ base_load_commands }}
          - setenv bootargs 'console={{ console_device }},{{ baud_rate }}n8 root=/dev/nfs {{ base_nfsroot_args }} {{ juno_kernel_args }}'
{{ base_uboot_nfs_bootcmd }}
        ramdisk-tftp:
          commands:
{{ base_uboot_commands }}
{{ base_uboot_commands_juno_extras }}
{{ base_uboot_addr_commands }}
{{ base_uboot_tftp_commands }}
          - setenv bootargs 'console={{ console_device }},{{ baud_rate }}n8 root=/dev/nfs {{ base_nfsroot_args}} {{ juno_kernel_args }}'
{{ base_uboot_tftp_bootcmd }}
        ramdisk-tftp-usb:
          commands:
{{ base_uboot_commands }}
{{ base_uboot_commands_juno_extras }}
{{ base_uboot_addr_commands }}
{{ base_uboot_tftp_commands }}
          - setenv bootargs 'console={{ console_device }},{{ baud_rate }}n8 root=/dev/sda2 {{ juno_kernel_args }}'
{{ base_uboot_tftp_bootcmd }}
        tftp-local-ramdisk-nfsroot:
          commands:
{{ base_uboot_commands }}
          - setenv initrd_name ramdisk.img
          - setenv loadfdt 'tftp {DTB_ADDR} {DTB}'
          - setenv loadkernel 'tftp {KERNEL_ADDR} {KERNEL}'
          - setenv loadinitrd 'afs load ramdisk.img {RAMDISK_ADDR}; setenv initrd_param {RAMDISK_ADDR}'
          - setenv bootargs 'console={{ console_device }},{{ baud_rate }}n8 root=/dev/nfs {{ base_nfsroot_args }} {{ juno_kernel_args }}'
{{ base_tftp_uboot_bootcmd }}
        usb:
          commands:
          - usb start
          - usb info
{{ base_uboot_commands }}
          - setenv kernel_addr_r '{KERNEL_ADDR}'
          - setenv initrd_addr_r '{RAMDISK_ADDR}'
          - setenv fdt_addr_r '{DTB_ADDR}'
          - setenv loadkernel 'load usb 0:{ROOT_PART} ${kernel_addr_r} {KERNEL}'
          - setenv loadinitrd 'load usb 0:{ROOT_PART} ${initrd_addr_r} {RAMDISK}; setenv initrd_size ${filesize}'
          - setenv loadfdt 'load usb 0:{ROOT_PART} ${fdt_addr_r} {DTB}'
          - setenv bootargs 'console={{ console_device }},{{ baud_rate }}n8 root={ROOT} {{ juno_kernel_args }}'
{{ base_uboot_bootcmd }}
        use-defaults:
          commands:
          - boot
{% endblock body -%}

{% block timeouts %}
timeouts:
  actions:
    apply-overlay-image:
      minutes: {{ action_timeout_apply_overlay_image | default(2) }}
    dd-image:
      minutes: {{ action_timeout_dd_image | default(20) }}
    download-retry:
      minutes: {{ action_timeout_download_retry | default(5) }}
    http-download:
      minutes: {{ action_timeout_http_download | default(10) }} # large due to android images etc
    lava-test-shell:
      minutes: {{ action_timeout_lava_test_shell | default(3) }}
    nfs-deploy:
      minutes: {{ action_timeout_nfs_deploy | default(10) }}
    power-off:
      seconds: {{ action_timeout_power_off | default(5) }}
    bootloader-commands:
      minutes: {{ action_timeout_bootloader_commands | default(3) }}
    bootloader-interrupt:
      seconds: {{ action_timeout_bootloader_interrupt | default(30) }}
    u-boot-interrupt:
      minutes: {{ action_timeout_u_boot_interrupt | default(2) }}
    u-boot-commands:
      minutes: {{ action_timeout_u_boot_commands | default(2) }}
    umount-retry:
      seconds: {{ action_timeout_umount_retry | default(45) }}
    auto-login-action:
      minutes: {{ action_timeout_auto_login | default(5) }}
    bootloader-action:
      minutes: {{ action_timeout_bootloader_action | default(3)}}
    uboot-action:
      minutes: {{ action_timeout_uboot_action | default(3)}}
    uboot-retry:
      minutes: {{ action_timeout_uboot_retry | default(3)}}
    bootloader-retry:
      minutes: {{ action_timeout_bootloader_retry | default(3)}}
    boot-qemu-image:
      minutes: {{ action_timeout_boot_qemu_image | default(2) }}
    boot-image-retry:
      minutes: {{ action_timeout_boot_image_retry | default(2) }}
  connections:
    dd-image:
      minutes: {{ connection_timeout_dd_image | default(20) }}
    u-boot-interrupt:
      minutes: {{ action_timeout_u_boot_interrupt | default(2) }}
    uboot-retry:
      minutes: {{ action_timeout_u_boot_retry | default(3) }}
    u-boot-commands:
      minutes: {{ action_timeout_u_boot_commands | default(2) }}
    bootloader-commands:
      seconds: {{ connection_timeout_bootloader_commands | default(30) }}
    auto-login-action:
      minutes: {{ connection_timeout_auto_login | default(5) }}
    bootloader-interrupt:
      seconds: {{ connection_timeout_bootloader_interrupt | default(30) }}
    http-download:
      minutes: {{ action_timeout_http_download | default(10) }} # large due to android images etc
    u-boot-interrupt:
      minutes: {{ connection_timeout_u_boot_interrupt | default(2) }}
{% endblock timeouts -%}
