Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify syncd init script for supporting yml #1411

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions syncd/scripts/brcm_common_config_ut.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/bin/bash
geans-pin marked this conversation as resolved.
Show resolved Hide resolved
###BRCM Common config UT####
PLATFORM_COMMON_DIR=/usr/share/sonic/device/x86_64-broadcom_common
PLT_CONFIG_BCM=$(find $HWSKU_DIR -name '*.bcm' -not -path "*/phy/*")
PLT_CONFIG_YML=$(find $HWSKU_DIR -name '*.yml')
PLATFORM_DIR=/usr/share/sonic/platform

if [ ! -z "$PLT_CONFIG_BCM" ] && [ -f $PLATFORM_DIR/common_config_support ] ; then
CONFIG_BCM=$(find /tmp -name '*.bcm')

#Get first three characters of chip id
readline=$(grep '0x14e4' /proc/linux-kernel-bde)
chip_id=${readline#*0x14e4:0x}
chip_id=${chip_id::3}
COMMON_CONFIG_BCM=$(find $PLATFORM_COMMON_DIR/x86_64-broadcom_${chip_id} -maxdepth 1 -name '*.bcm')
check_override=false
check_pass=false

#Check if common config does apply to config bcm correctly
while read line
do
line=$( echo $line | xargs )
if [ ! -z "$line" ];then
if [ "${line::1}" == '#' ];then
echo "Skip checking line starting with #"
elif [ "$line" == "[High Inheritance Precedence]" ];then
echo "Checking High Inheritance property..."
check_override=true
elif [ "$line" == "[Low Inheritance Precedence]" ];then
echo "Checking Low Inheritance property..."
check_override=false
else
if $check_override ;then
if grep -q $line $CONFIG_BCM ;then
check_pass=true
else
echo "Fail: Checking overwite properties not existing.."
return
fi
else
sedline=${line%=*}
if grep -q $sedline $CONFIG_BCM ;then
check_pass=true
else
echo "Fail: Checking properties not existing.."
return
fi
fi
fi
fi
done < $COMMON_CONFIG_BCM
if $check_pass ;then
echo "PASS: Checking Common config merged Success"
fi
fi

if [ ! -z "$PLT_CONFIG_YML" ] && [ -f $PLATFORM_DIR/common_config_support ]; then
CONFIG_YML=$(find /tmp -name '*.yml')

#Get first three characters of chip id
readline=$(grep '0:14e4' /proc/linux_ngbde)
chip_id=${readline#*0:14e4:}
chip_id=${chip_id::3}
COMMON_CONFIG_BCM=$(find $PLATFORM_COMMON_DIR/x86_64-broadcom_${chip_id} -maxdepth 1 -name '*.bcm')
check_override=false
check_pass=false

#Check if common config does apply to config bcm correctly
while read line
do
line=$( echo $line | xargs )
if [ ! -z "$line" ];then
if [ "${line::1}" == '#' ];then
echo "Skip checking line starting with #"
elif [ "$line" == "[High Inheritance Precedence]" ];then
echo "Checking High Inheritance property..."
check_override=true
elif [ "$line" == "[Low Inheritance Precedence]" ];then
echo "Checking Low Inheritance property..."
check_override=true
else
if $check_override ;then
if grep -q $line $CONFIG_BCM ;then
check_pass=true
else
echo "Fail: Checking overwite properties not existing.."
return
fi
else
sedline=${line%=*}
if grep -q $sedline $CONFIG_BCM ;then
check_pass=true
else
echo "Fail: Checking properties not existing.."
return
fi
fi
fi
fi

if $check_pass ;then
echo "PASS: Checking Common config merged Success"
fi

done < $COMMON_CONFIG_BCM

fi

229 changes: 168 additions & 61 deletions syncd/scripts/syncd_init_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -119,74 +119,181 @@ config_syncd_cisco_8000()
fi
}

config_syncd_bcm()
function merge_config_bcm_files()
{
to_file=$1
from_file=$2
message=$3
override=false
echo "" >> $to_file
echo "# Start of $message" >> $to_file
while read line
do
line=$( echo $line | xargs )
if [ ! -z "$line" ];then
if [ "${line::1}" == '#' ];then
echo $line >> $to_file
elif [ "$line" == "[Low Inheritance Precedence]" ];then
override=false
echo $line >> $to_file
elif [ "$line" == "[High Inheritance Precedence]" ];then
override=true
echo "# $line" >> $to_file
echo "Merge properties with override $override"
else
sedline=${line%=*}
if grep -q $sedline $to_file ;then
geans-pin marked this conversation as resolved.
Show resolved Hide resolved
if $override ;then
echo "Override the config $(grep $sedline $to_file) with $line in $to_file"
prop=${line:0:`expr index $line =`}
sed -i "/$prop/d" $to_file
echo $line >> $to_file
else
grepline=$(grep $sedline $to_file)
if [ "${grepline::1}" == '#' ];then
echo $line >> $to_file
else
echo "Keep the config $(grep $sedline $to_file) in $to_file"
fi
fi
else
echo $line >> $to_file
fi
fi
fi
done < $from_file
echo "# End of $message" >> $to_file
echo "Merged $from_file to $to_file"
}

if [ -f $PLATFORM_DIR/common_config_support ];then

PLATFORM_COMMON_DIR=/usr/share/sonic/device/x86_64-broadcom_common

cp -f $HWSKU_DIR/*.config.bcm /tmp
cp -f /etc/sai.d/sai.profile /tmp
CONFIG_BCM=$(find /tmp -name '*.bcm')
PLT_CONFIG_BCM=$(find $HWSKU_DIR -name '*.bcm')
SAI_PROFILE=$(find /tmp -name 'sai.profile')
sed -i 's+/usr/share/sonic/hwsku+/tmp+g' $SAI_PROFILE

#Get first three characters of chip id
readline=$(grep '0x14e4' /proc/linux-kernel-bde)
chip_id=${readline#*0x14e4:0x}
chip_id=${chip_id::3}
COMMON_CONFIG_BCM=$(find $PLATFORM_COMMON_DIR/x86_64-broadcom_${chip_id} -name '*.bcm')

if [ -f $PLATFORM_COMMON_DIR/x86_64-broadcom_${chip_id}/*.bcm ]; then
for file in $CONFIG_BCM; do
echo "" >> $file
echo "# Start of chip common properties" >> $file
while read line
do
line=$( echo $line | xargs )
if [ ! -z "$line" ];then
if [ "${line::1}" == '#' ];then
echo $line >> $file
function merge_config_yml_files()
{
to_file=$1
from_file=$2
message=$3
override=false
merged_cnt=0
echo "" >> $to_file
echo "# Start of $message" >> $to_file
while read line
do
line=$( echo $line | xargs )
if [ ! -z "$line" ];then
if [ "${line::1}" == '#' ];then
echo " $line" >> $to_file
elif [ "$line" == "[Low Inheritance Precedence]" ];then
override=false
echo " $line" >> $to_file
elif [ "$line" == "[High Inheritance Precedence]"];then
override=true
echo " # $line" >> $to_file
echo "Merge properties with override $override"
else
sedline=${line%:*}
if grep -q $sedline $to_file ;then
if $override ;then
echo "Override the config $(grep $sedline $to_file) with $line in $to_file"
prop=${line:0:`expr index "$line" :`}
sed -i "/$prop/d" $to_file
echo " $line" >> $to_file
merged_cnt+=1
else
sedline=${line%=*}
if grep -q $sedline $file ;then
echo "Keep the config $(grep $sedline $file) in $file"
else
echo $line >> $file
fi
grepline=$(grep $sedline $to_file)
grepline="${grepline#"${grepline%%[![:space:]]*}"}"
if [ "${grepline::1}" == '#' ];then
echo " $line" >> $to_file
merged_cnt+=1
else
echo "Keep the config $(grep $sedline $to_file) in $to_file"
fi
fi
fi
done < $COMMON_CONFIG_BCM
echo "# End of chip common properties" >> $file
done
echo "Merging $PLT_CONFIG_BCM with $COMMON_CONFIG_BCM, merge files stored in $CONFIG_BCM"
fi

#sync the file system
sync

# copy the final config.bcm and sai.profile to the shared folder for 'show tech'
cp -f /tmp/sai.profile /var/run/sswsyncd/
cp -f /tmp/*.bcm /var/run/sswsyncd/

if [ -f "/tmp/sai.profile" ]; then
CMD_ARGS+=" -p /tmp/sai.profile"
elif [ -f "/etc/sai.d/sai.profile" ]; then
CMD_ARGS+=" -p /etc/sai.d/sai.profile"
else
CMD_ARGS+=" -p $HWSKU_DIR/sai.profile"
fi
else
echo " $line" >> $to_file
merged_cnt+=1
fi
fi
fi
done < $from_file

else
if [ $merged_cnt -gt 0 ]; then
sed -i "/# Start of/a \ global:" $to_file
sed -i "/# Start of/a \ 0:" $to_file
sed -i "/# Start of/a \bcm_device:" $to_file
sed -i "/# Start of/a \---" $to_file
fi
echo "# End of $message" >> $to_file
if [ $merged_cnt -gt 0 ]; then
sed -i "/# End of/i \..." $to_file
fi
echo "Merged $from_file to $to_file"
}

if [ -f "/etc/sai.d/sai.profile" ]; then
CMD_ARGS+=" -p /etc/sai.d/sai.profile"
else
CMD_ARGS+=" -p $HWSKU_DIR/sai.profile"
fi
config_syncd_bcm()
{
PLATFORM_COMMON_DIR=/usr/share/sonic/device/x86_64-broadcom_common
PLT_CONFIG_BCM=$(find $HWSKU_DIR -name '*.bcm' -not -path "*/phy/*")
PLT_CONFIG_YML=$(find $HWSKU_DIR -name '*.yml')

if [ ! -z "$PLT_CONFIG_BCM" ] && [ -f $PLATFORM_DIR/common_config_support ] ; then
cp -f $HWSKU_DIR/*.config.bcm /tmp
geans-pin marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there is no *.config.bcm doesn't exist, this command will fail. Need to check /etc/said.d/profile and find out where is the config.bcm file then copy it to /tmp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far the script does search the sai.profile to find platform config.
The following copied escaped from the fix.

Can you try the following change for line#250 to see if works ? I will fix it in the PR.

cp -f $HWSKU_DIR/*.config.bcm /tmp => cp -f $PLT_CONFIG_BCM /tmp

Geans

cp -f /etc/sai.d/sai.profile /tmp
CONFIG_BCM=$(find /tmp -name '*.bcm')
SAI_PROFILE=$(find /tmp -name 'sai.profile')
sed -i 's+/usr/share/sonic/hwsku+/tmp+g' $SAI_PROFILE

#Get first three characters of chip id
readline=$(grep '0x14e4' /proc/linux-kernel-bde)
chip_id=${readline#*0x14e4:0x}
chip_id=${chip_id::3}
COMMON_CONFIG_BCM=$(find $PLATFORM_COMMON_DIR/x86_64-broadcom_${chip_id} -maxdepth 1 -name '*.bcm')

if [ -f $PLATFORM_COMMON_DIR/x86_64-broadcom_${chip_id}/*.bcm ]; then
for file in $CONFIG_BCM; do
merge_config_bcm_files $file $COMMON_CONFIG_BCM "chip common properties"
done
echo "Merging $PLT_CONFIG_BCM with $COMMON_CONFIG_BCM, merge files stored in $CONFIG_BCM"
geans-pin marked this conversation as resolved.
Show resolved Hide resolved

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For 7260 hwsku, no config.bcm, just config.bcm.j2.
The merged file doesn't exist, and caused syncd can't boot up.

2024 Nov 14 05:02:27.495014 str2-7260cx3-acs-9 INFO syncd#supervisord: syncd Merging /etc/sai.d/config.bcm with /usr/share/sonic/device/x86_64-broadcom_common/x86_64-broadcom_b97/broadcom-sonic-th2.config.bcm, merge files stored in 
2024 Nov 14 05:02:27.505237 str2-7260cx3-acs-9 INFO syncd#supervisord: syncd cp: cannot stat '/tmp/*.bcm': No such file or directory

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far the script does search the sai.profile to find platform config.
The following copied escaped from the fix.

Can you try the following change for line#250 to see if works ? I will fix it in the PR.

cp -f $HWSKU_DIR/*.config.bcm /tmp => cp -f $PLT_CONFIG_BCM /tmp

Geans

fi
#sync the file system
sync

# copy the final config.bcm and sai.profile to the shared folder for 'show tech'
cp -f /tmp/sai.profile /var/run/sswsyncd/
cp -f /tmp/*.bcm /var/run/sswsyncd/
fi

if [ ! -z "$PLT_CONFIG_YML" ] && [ -f $PLATFORM_DIR/common_config_support ]; then
cp -f $HWSKU_DIR/*.config.yml /tmp
cp -f /etc/sai.d/sai.profile /tmp
CONFIG_YML=$(find /tmp -name '*.yml')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use the file name .yml suffix to identify the file format. Can you change the sai.profile and *.config.bcm to *.yml as following BRCM SDK rule ?

SAI_PROFILE=$(find /tmp -name 'sai.profile')
sed -i 's+/usr/share/sonic/hwsku+/tmp+g' $SAI_PROFILE

#Get first three characters of chip id
readline=$(grep '0:14e4' /proc/linux_ngbde)
chip_id=${readline#*0:14e4:}
chip_id=${chip_id::3}
COMMON_CONFIG_BCM=$(find $PLATFORM_COMMON_DIR/x86_64-broadcom_${chip_id} -maxdepth 1 -name '*.bcm')

if [ -f $PLATFORM_COMMON_DIR/x86_64-broadcom_${chip_id}/*.bcm ]; then
for file in $CONFIG_YML; do
merge_config_yml_files $file $COMMON_CONFIG_BCM "chip common properties"
done
echo "Merging $PLT_CONFIG_YML with $COMMON_CONFIG_BCM, merge files stored in $CONFIG_YML "
fi
#sync the file system
sync

# copy the final config.bcm and sai.profile to the shared folder for 'show tech'
cp -f /tmp/sai.profile /var/run/sswsyncd/
cp -f /tmp/*.yml /var/run/sswsyncd/
fi

if [ -f "/tmp/sai.profile" ]; then
CMD_ARGS+=" -p /tmp/sai.profile"
elif [ -f "/etc/sai.d/sai.profile" ]; then
CMD_ARGS+=" -p /etc/sai.d/sai.profile"
else
CMD_ARGS+=" -p $HWSKU_DIR/sai.profile"
fi

if [ -f "$HWSKU_DIR/context_config.json" ]; then
Expand Down
Loading