Skip to content

RFC: Use quote filters for base-uboot.jijna2's setenv bootargs

Igor Ponomarev requested to merge base-uboot-template-quote-setenv-args into master

Currently that template only puts the boot args in to single quotes and the setenv command in to double quotes. However, this is not enough. For example, if your job's extra_kernel_args contains double quotes the produced YAML will be invalid and the job will fail.

Instead of manual quoting use the new filter functions shlex_quote and yaml_quotes. This way the produced YAML is always valid.

Example:

The job definition contains following lines:

context:
  extra_kernel_args: console_msg_format=syslog earlycon deferred_probe_timeout=60 debug dyndbg="file dd.c +p" ignore_loglevel

As you can see it contains the double quotes.

Without this patch this would result invalid YAML (because double quotes are not escaped):

        nfs:
          commands:
          - "setenv autoload no"
          - "setenv initrd_high 0xffffffffffffffff"
          - "setenv fdt_high 0xffffffffffffffff"
          - "dhcp"
          - "setenv serverip {SERVER_IP}"
          - "tftp {KERNEL_ADDR} {KERNEL}"
          - "tftp {RAMDISK_ADDR} {RAMDISK}"
          - "tftp {TEE_ADDR} {TEE}"
          - "setenv initrd_size ${filesize}"
          - "tftp {DTB_ADDR} {DTB}"
          # Always quote the entire string if the command includes a colon to support correct YAML.
          - "setenv bootargs 'console=ttySC0,115200n8 root=/dev/nfs rw nfsroot={NFS_SERVER_IP}:{NFSROOTFS},tcp,hard console_msg_format=syslog earlycon deferred_probe_timeout=60 debug dyndbg="file dd.c +p" ignore_loglevel ip=dhcp'"
          - "{BOOTX}"

With this patch the double quotes are properly escaped:

        nfs:
          commands:
          - "setenv autoload no"
          - "setenv initrd_high 0xffffffffffffffff"
          - "setenv fdt_high 0xffffffffffffffff"
          - "dhcp"
          - "setenv serverip {SERVER_IP}"
          - "tftp {KERNEL_ADDR} {KERNEL}"
          - "tftp {RAMDISK_ADDR} {RAMDISK}"
          - "tftp {TEE_ADDR} {TEE}"
          - "setenv initrd_size ${filesize}"
          - "tftp {DTB_ADDR} {DTB}"
          - "setenv bootargs 'console=ttySC0,115200n8 root=/dev/nfs rw nfsroot={NFS_SERVER_IP}:{NFSROOTFS},tcp,hard console_msg_format=syslog earlycon deferred_probe_timeout=60 debug dyndbg=\"file dd.c +p\" ignore_loglevel ip=dhcp'"
          - "{BOOTX}"

You can even add single quotes to the kernel args and it will get properly escaped in both shell and yaml:

- "setenv bootargs 'console=ttySC0,115200n8 rw nbd.server={NBDSERVERIP} nbd.port={NBDSERVERPORT} root=/dev/ram0 ramdisk_size=16384 rootdelay=7  '\"'\"'console_msg_format=syslog'\"'\"' earlycon deferred_probe_timeout=60 debug dyndbg=\"file dd.c +p\" ignore_loglevel ip=dhcp verbose earlyprintk systemd.log_color=false ${extraargs} rw'"
Edited by Igor Ponomarev

Merge request reports