The contract is a legal agreement, but O2 will let you upgrade a little early depending on how much you spend over your tariff each month. If you never go over your monthly tariff then you can upgrade one month early. There is nothing stopping you from buying your own handset though.
I think if you want to cancel you have to pay off the amount remaining of your contract i.e. if it was a 12 month contract at £25 a month and you have 6 months left you would have to pay £150 to cancel.