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

Get only the first CONFIG_ENV_SECT_SIZE #815

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

amdrsantos
Copy link

In the u-boot, some platforms configs have the "CONFIG_ENV_SECT_SIZE" referenced more than once in its .h.
This can causes the "build-config/scripts/onie-mk-bin.sh" to fail.

In my use case:
++ grep CONFIG_ENV_SECT_SIZE /home/build/src/onie/build/_-r0/u-boot/u-boot-2013.01.01/include/configs/.h
++ awk '{print $3}'

  • env_sector_size='0x20000
    (CONFIG_SYS_MONITOR_BASE
    "\0"'
    /home/build/src/onie/build-config/scripts/onie-mk-bin.sh: line 80: 0x20000
    (CONFIG_SYS_MONITOR_BASE
    "\0" + 0 : syntax error in expression (error token is "(CONFIG_SYS_MONITOR_BASE
    "\0" + 0 ")
  • '[' '0x20000
    (CONFIG_SYS_MONITOR_BASE
    "\0"' = '' ']'
  • '[' '0x20000
    (CONFIG_SYS_MONITOR_BASE
    "\0"' = 0 ']'

Therefore I suggest adding the "-m 1" parameter to grep, in order to get only the first match.

Cheers,
Alex

@ehdoyle
Copy link
Collaborator

ehdoyle commented Feb 28, 2019

Hi - thanks for pointing this issue out, and the pull request makes it a lot clearer what the code would look like.
As I'm starting to dig into it, my initial thought is: should those platforms be defining it more than once? Seems like that would be a bug that those platforms should fix, unless I (quite possibly) am missing something there.
That said, I still think it'd be a good idea to catch and call out multiple definitions, rather than having the code fail with multiple matches.
Do you have an example or two of the platforms where this happens? (I'm looking at a slew of patch files for different platforms so I can only really be sure what the final state will be by building them one at a time)
Thanks!

@ehdoyle
Copy link
Collaborator

ehdoyle commented Mar 29, 2019

Hmm. For a minor change, there's a surprising amount of corner cases.
What was the system(s) you were building for, so that I can test against them.
I'm thinking this should cover it, or fail if there's multiple definitions: Thoughts?

`if [ -z "$env_sector_size" ] ; then
# try to figure it out from the $MACHINE_CONIFG

# find all #defines                                                                    
env_sector_define=$(grep -E \#define[[:space:]]*CONFIG_ENV_SECT_SIZE $MACHINE_CONFIG ) 
# Not found at all, or found more than once                                            
if [ $(echo "$env_sector_define" | wc -l ) != 1 ];then                                 
    echo "ERROR: #define CONFIG_ENV_SECT_SIZE was found\                               

$(echo "$env_sector_define" | wc -l ) times in $MACHINE_CONFIG. $env_sector_define"
exit 1
else
env_sector_size=$( echo "$env_sector_define" | awk '{print $3}' )
echo "Got $env_sector_size"
fi
# env_sector_size=$(grep CONFIG_ENV_SECT_SIZE $MACHINE_CONFIG | awk '{print $3}')
fi
# falls through to existing code
env_sector_size=$(( $env_sector_size + 0 ))
if [ "$env_sector_size" = "" ] || [ "$env_sector_size" = "0" ] ; then
echo "ERROR: Unable to find #define CONFIG_ENV_SECT_SIZE in $MACHINE_CONFIG."
exit 1
fi `

@amdrsantos
Copy link
Author

I would include one more test, for the case that grep returns no results:

`if [ -z "$env_sector_size" ] ; then
# try to figure it out from the $MACHINE_CONIFG

# find all #defines                                                                    
env_sector_define=$(grep -E \#define[[:space:]]*CONFIG_ENV_SECT_SIZE $MACHINE_CONFIG ) 
# Not found at all, or found more than once
if [ -z "$env_sector_define" ] ; then 
    echo "ERROR: #define CONFIG_ENV_SECT_SIZE was not found in $MACHINE_CONFIG."  
    exit 1
elif [ $(echo "$env_sector_define" | wc -l ) != 1 ]; then                                 
    echo "ERROR: #define CONFIG_ENV_SECT_SIZE was found\                               
    $(echo "$env_sector_define" | wc -l ) times in $MACHINE_CONFIG. $env_sector_define"
    exit 1
else
    env_sector_size=$( echo "$env_sector_define" | awk '{print $3}' )
    echo "Got $env_sector_size"
fi
env_sector_size=$(grep CONFIG_ENV_SECT_SIZE $MACHINE_CONFIG | awk '{print $3}')

fi `

I am working on a Linux debian9x64bit 4.9.0-8-amd64 #1 SMP Debian 4.9.130-2 (2018-10-27) x86_64 GNU/Linux.

The platform I am tring to integrated is similar to Accton AS6700-32X, can not disclosure yet.

@ehdoyle
Copy link
Collaborator

ehdoyle commented Apr 11, 2019

Nice catch on the empty value. I'd have thought the wc would have reported 0, but of course it's counting lines.
With this patch in I'll try rebuilding the machines listed where this may be an issue, and then do some other platform builds to make sure it doesn't break anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants