From fe5b096891b5e6f03af9b96e473b1143caf42ea7 Mon Sep 17 00:00:00 2001 From: david_yang Date: Thu, 21 Dec 2017 16:05:57 +0800 Subject: [PATCH] machine.conf: generated automatically during ONIE booting In commit 3cbcb9e, it introduced a new machanism to identify machines with common CPU module. The machine.conf was changed to source other configuration files to calculate the real `onie_machine` and `onie_platform` at ONIE runtime. Some NOSes such as SONiC would copy machine.conf to its partition and use it at its runtime. The new machine.conf needs other files and has to be put in /etc directory or it cannot be sourced correctly. Besides SONiC other NOSes also have similar issues. The patch intends to expand all variables from machine-build.conf and machine-live.conf to machine.conf directly. That would be like the previous one: ONIE:/ # cat /etc/machine.conf # /etc/machine.conf for onie # Copyright (C) 2017 Curt Brune # Copyright (C) 2017 david_yang # # SPDX-License-Identifier: GPL-2.0 onie_version=2017.12.12.20-dirty onie_vendor_id=259 onie_build_machine=accton_as7712_32x onie_machine_rev=0 onie_arch=x86_64 onie_build_platform=x86_64-accton_as7712_32x-r0 onie_config_version=1 onie_build_date="2017-12-20T13:43+0800" onie_partition_type=gpt onie_kernel_version=4.1.38 onie_firmware=auto onie_switch_asic=bcm onie_skip_ethmgmt_macs=no onie_grub_image_name=grubx64.efi onie_machine=accton_as7712_32x onie_platform="x86_64-accton_as7712_32x-r0" ONIE:/ # This patch has been tested on Accton AS7712_32X with SONiC environment. Signed-off-by: Curt Brune --- rootconf/default/etc/init.d/gen-config.sh | 37 ++++++++++++++++++++++- rootconf/default/etc/machine.conf | 16 ---------- 2 files changed, 36 insertions(+), 17 deletions(-) delete mode 100644 rootconf/default/etc/machine.conf diff --git a/rootconf/default/etc/init.d/gen-config.sh b/rootconf/default/etc/init.d/gen-config.sh index 1890f97ce..62511252c 100755 --- a/rootconf/default/etc/init.d/gen-config.sh +++ b/rootconf/default/etc/init.d/gen-config.sh @@ -1,6 +1,7 @@ #!/bin/sh # Copyright (C) 2017 Curt Brune +# Copyright (C) 2017 david_yang # # SPDX-License-Identifier: GPL-2.0 @@ -17,9 +18,43 @@ gen_live_config() [ -r /lib/onie/gen-config-platform ] && . /lib/onie/gen-config-platform +gen_machine_config() +{ + local build_conf=/etc/machine-build.conf + local live_conf=/etc/machine-live.conf + local machine_conf=/etc/machine.conf + + gen_live_config > $live_conf + + cat < $machine_conf +# /etc/machine.conf for onie + +# Copyright (C) 2017 Curt Brune +# Copyright (C) 2017 david_yang +# +# SPDX-License-Identifier: GPL-2.0 + +EOF + + cat $build_conf $live_conf >> $machine_conf + sed -i -e '/onie_machine=/d' $machine_conf + sed -i -e '/onie_platform=/d' $machine_conf + + # Use onie_machine if set, otherwise use build_machine + . $build_conf + . $live_conf + local onie_machine=${onie_machine:-$onie_build_machine} + local onie_platform="${onie_arch}-${onie_machine}-r${onie_machine_rev}" + cat <> $machine_conf +onie_machine=$onie_machine +onie_platform="$onie_platform" +EOF + +} + case $cmd in start) - gen_live_config > /etc/machine-live.conf + gen_machine_config ;; *) diff --git a/rootconf/default/etc/machine.conf b/rootconf/default/etc/machine.conf deleted file mode 100644 index 5f93edc3b..000000000 --- a/rootconf/default/etc/machine.conf +++ /dev/null @@ -1,16 +0,0 @@ -# /etc/machine.conf for onie - -# Copyright (C) 2017 Curt Brune -# -# SPDX-License-Identifier: GPL-2.0 - -# Source build-time machine configuration -. /etc/machine-build.conf - -# Source run-time machine configuration if available -[ -r /etc/machine-live.conf ] && . /etc/machine-live.conf - -# Use onie_machine if set, otherwise use build_machine -onie_machine=${onie_machine:-$onie_build_machine} - -onie_platform="${onie_arch}-${onie_machine}-r${onie_machine_rev}"