You can do it but that doesn’t mean you should.
Throwing away a phone whose hardware may be perfectly working, but its manufacturer decided to be too cheap to use anything but walled-garden components, feels like an utter waste of resources.
(By walled-garden components, I mean chips whose suppliers make it difficult or impossible to develop an open-source driver.)